Contribution: Offset quickfixes

Petr Hejl petr.hejl at oracle.com
Fri Jan 4 07:03:52 PST 2013


Here is the patch (at the end of the message).
P.

On 01/04/2013 03:48 PM, Petr Hejl wrote:
> Hi,
> I noticed some issues with offset while using the current Nashorn with
> NetBeans. The patch contains _quickfixes_ for:
> - wrong block offsets
> - wrong literal finish offset
> - wrong case node block finish offset
> - block containing var node ending with semicolon finish
>
> I'm not really sure the solution is the best one. Leaving up to you for
> evaluation.
>
> Thanks,
> P.
>

diff -r 7e1eb46cd092 -r 63d015d13bc9 src/jdk/nashorn/internal/ir/Block.java
--- a/src/jdk/nashorn/internal/ir/Block.java	Thu Jan 03 15:45:05 2013 +0100
+++ b/src/jdk/nashorn/internal/ir/Block.java	Fri Jan 04 15:16:50 2013 +0100
@@ -185,6 +185,9 @@
      public void addStatement(final Node statement) {
          if (statement != null) {
              statements.add(statement);
+            if (getFinish() < statement.getFinish()) {
+                setFinish(statement.getFinish());
+            }
          }
      }

diff -r 7e1eb46cd092 -r 63d015d13bc9 
src/jdk/nashorn/internal/parser/AbstractParser.java
--- a/src/jdk/nashorn/internal/parser/AbstractParser.java	Thu Jan 03 
15:45:05 2013 +0100
+++ b/src/jdk/nashorn/internal/parser/AbstractParser.java	Fri Jan 04 
15:16:50 2013 +0100
@@ -429,6 +429,8 @@

          // Create literal node.
          final Object value = getValue();
+        // move it immediately to have a right finish
+        next();

          LiteralNode<?> node = null;

@@ -452,7 +454,6 @@
              assert false : "unknown type for LiteralNode: " + 
value.getClass();
          }

-        next();
          return node;
      }
  }
diff -r 7e1eb46cd092 -r 63d015d13bc9 
src/jdk/nashorn/internal/parser/Parser.java
--- a/src/jdk/nashorn/internal/parser/Parser.java	Thu Jan 03 15:45:05 
2013 +0100
+++ b/src/jdk/nashorn/internal/parser/Parser.java	Fri Jan 04 15:16:50 
2013 +0100
@@ -934,7 +934,11 @@

          // If is a statement then handle end of line.
          if (isStatement) {
+            boolean semicolon = (type == SEMICOLON);
              endOfLine();
+            if (semicolon) {
+                block.setFinish(finish);
+            }
          }

          return vars;
@@ -950,7 +954,8 @@
       */
      private void emptyStatement() {
          if (context._empty_statements) {
-            block.addStatement(new EmptyNode(source, token, 
Token.descPosition(token)));
+            block.addStatement(new EmptyNode(source, token,
+                    Token.descPosition(token) + Token.descLength(token)));
          }

          // SEMICOLON checked in caller.
@@ -984,6 +989,7 @@

          if (executeNode != null) {
              executeNode.setFinish(finish);
+            block.setFinish(finish);
          }
      }

@@ -1567,6 +1573,7 @@
                  // Get CASE body.
                  final Block statements = getBlock(false);
                  final CaseNode caseNode = new CaseNode(source, 
caseToken, finish, caseExpression, statements);
+                statements.setFinish(finish);

                  if (caseExpression == null) {
                      defaultCase = caseNode;




More information about the nashorn-dev mailing list