Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorssankaran2014-11-05 09:18:29 +0000
committerssankaran2014-11-05 09:18:29 +0000
commitcccafe00dbf29f156949d8f0d0aec370b02aa048 (patch)
tree5378743d80cd556e516282e431216cac486419b4
parent1de8e2f6bc728cee690d70795383b83c1f0d652a (diff)
downloadeclipse.jdt.core-cccafe00dbf29f156949d8f0d0aec370b02aa048.tar.gz
eclipse.jdt.core-cccafe00dbf29f156949d8f0d0aec370b02aa048.tar.xz
eclipse.jdt.core-cccafe00dbf29f156949d8f0d0aec370b02aa048.zip
Fixed Bug 423987 - [1.8][assist] Follow up tasks from Bug 422468
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java6
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java79
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java3
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/CommitRollbackParser.java113
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java16
5 files changed, 93 insertions, 124 deletions
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java
index c745f5e09a..8c21b04460 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java
@@ -4682,7 +4682,7 @@ public void initialize(boolean parsingCompilationUnit) {
this.labelPtr = -1;
initializeForBlockStatements();
}
-public void copyState(CommitRollbackParser from) {
+public void copyState(Parser from) {
super.copyState(from);
@@ -5049,7 +5049,7 @@ public void recoveryTokenCheck() {
}
}
-protected CommitRollbackParser createSnapShotParser() {
+protected CompletionParser createSnapShotParser() {
return new CompletionParser(this.problemReporter, this.storeSourceEnds);
}
/*
@@ -5197,7 +5197,7 @@ protected void updateRecoveryState() {
this.currentElement.updateFromParserState();
// completionIdentifierCheck && attachOrphanCompletionNode pops various stacks to construct astNodeParent and enclosingNode. This does not gel well with extended recovery.
- CommitRollbackParser parser = null;
+ AssistParser parser = null;
if (lastIndexOfElement(K_LAMBDA_EXPRESSION_DELIMITER) >= 0) {
parser = createSnapShotParser();
parser.copyState(this);
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java
index 9d083f4b7f..555bdcfc8e 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java
@@ -17,6 +17,7 @@ package org.eclipse.jdt.internal.codeassist.impl;
import java.util.HashSet;
+import org.eclipse.jdt.core.compiler.InvalidInputException;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration;
@@ -42,7 +43,6 @@ import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
-import org.eclipse.jdt.internal.compiler.parser.CommitRollbackParser;
import org.eclipse.jdt.internal.compiler.parser.Parser;
import org.eclipse.jdt.internal.compiler.parser.RecoveredBlock;
import org.eclipse.jdt.internal.compiler.parser.RecoveredElement;
@@ -110,6 +110,9 @@ public abstract class AssistParser extends Parser {
protected boolean isFirst = false;
+ public AssistParser snapShot;
+ private static final int[] RECOVERY_TOKENS = new int [] { TokenNameSEMICOLON, TokenNameRPAREN,};
+
public AssistParser(ProblemReporter problemReporter) {
super(problemReporter, true);
@@ -121,7 +124,7 @@ public AssistParser(ProblemReporter problemReporter) {
public abstract char[] assistIdentifier();
-public void copyState(CommitRollbackParser from) {
+public void copyState(Parser from) {
super.copyState(from);
@@ -1871,6 +1874,78 @@ public void recoveryTokenCheck() {
public void reset(){
flushAssistState();
}
+
+protected void commit() {
+ if (this.snapShot == null) {
+ this.snapShot = createSnapShotParser();
+ }
+ this.snapShot.copyState(this);
+}
+
+protected boolean assistNodeNeedsStacking() {
+ return false;
+}
+
+protected void shouldStackAssistNode() {
+ // Not relevant here.
+}
+
+protected int getNextToken() {
+ try {
+ return this.scanner.getNextToken();
+ } catch (InvalidInputException e) {
+ return TokenNameEOF;
+ }
+}
+
+protected abstract AssistParser createSnapShotParser();
+
+// We get here on real syntax error or syntax error triggered by fake EOF at completion site, never due to triggered recovery.
+protected int fallBackToSpringForward(Statement unused) {
+ int nextToken;
+ int automatonState = automatonState();
+
+ // If triggered fake EOF at completion site, see if the real next token would have passed muster.
+ if (this.currentToken == TokenNameEOF) {
+ if (this.scanner.eofPosition < this.scanner.source.length) {
+ shouldStackAssistNode();
+ this.scanner.eofPosition = this.scanner.source.length;
+ nextToken = getNextToken();
+ if (automatonWillShift(nextToken, automatonState)) {
+ this.currentToken = nextToken;
+ return RESUME;
+ }
+ this.scanner.ungetToken(nextToken); // spit out what has been bitten more than we can chew.
+ } else {
+ return HALT; // don't know how to proceed.
+ }
+ } else {
+ nextToken = this.currentToken;
+ this.scanner.ungetToken(nextToken);
+ if (nextToken == TokenNameRBRACE)
+ ignoreNextClosingBrace(); // having ungotten it, recoveryTokenCheck will see this again.
+ }
+ // OK, next token is no good to resume "in place", attempt some local repair. FIXME: need to make sure we don't get stuck keep reducing empty statements !!
+ for (int i = 0, length = RECOVERY_TOKENS.length; i < length; i++) {
+ if (automatonWillShift(RECOVERY_TOKENS[i], automatonState)) {
+ this.currentToken = RECOVERY_TOKENS[i];
+ return RESUME;
+ }
+ }
+ // OK, no in place resumption, no local repair, fast forward to next statement.
+ if (this.snapShot == null)
+ return RESTART;
+
+ this.copyState(this.snapShot);
+ if (assistNodeNeedsStacking()) {
+ this.currentToken = TokenNameSEMICOLON;
+ return RESUME;
+ }
+ this.currentToken = this.scanner.fastForward(unused);
+ return RESUME;
+}
+
+
/*
* Reset context so as to resume to regular parse loop
* If unable to reset for resuming, answers false.
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java
index d72c51aabd..964ab8528b 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java
@@ -59,7 +59,6 @@ import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
-import org.eclipse.jdt.internal.compiler.parser.CommitRollbackParser;
import org.eclipse.jdt.internal.compiler.parser.JavadocParser;
import org.eclipse.jdt.internal.compiler.parser.RecoveredType;
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
@@ -1240,7 +1239,7 @@ protected void consumeTypeImportOnDemandDeclarationName() {
this.restartRecovery = true; // used to avoid branching back into the regular automaton
}
}
-protected CommitRollbackParser createSnapShotParser() {
+protected SelectionParser createSnapShotParser() {
return new SelectionParser(this.problemReporter);
}
public ImportReference createAssistImportReference(char[][] tokens, long[] positions, int mod){
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/CommitRollbackParser.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/CommitRollbackParser.java
deleted file mode 100644
index ac09e687d5..0000000000
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/CommitRollbackParser.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jdt.internal.compiler.parser;
-
-import org.eclipse.jdt.core.compiler.InvalidInputException;
-import org.eclipse.jdt.internal.compiler.ast.Statement;
-
-public abstract class CommitRollbackParser implements TerminalTokens, ParserBasicInformation {
-
- // resumeOnSyntaxError codes:
- protected static final int HALT = 0; // halt and throw up hands.
- protected static final int RESTART = 1; // stacks adjusted, alternate goal from check point.
- protected static final int RESUME = 2; // stacks untouched, just continue from where left off.
-
- public Scanner scanner;
- public int currentToken;
-
- public CommitRollbackParser snapShot;
- private static final int[] RECOVERY_TOKENS = new int [] { TokenNameSEMICOLON, TokenNameRPAREN,};
-
- protected CommitRollbackParser createSnapShotParser() {
- return new Parser();
- }
-
- protected void commit() {
- if (this.snapShot == null) {
- this.snapShot = createSnapShotParser();
- }
- this.snapShot.copyState(this);
- }
-
- public void copyState(CommitRollbackParser commitRollbackParser) {
- // Subclasses should implement.
- }
-
- protected int getNextToken() {
- try {
- return this.scanner.getNextToken();
- } catch (InvalidInputException e) {
- return TokenNameEOF;
- }
- }
-
- protected void shouldStackAssistNode() {
- // Not relevant here.
- }
-
- // We get here on real syntax error or syntax error triggered by fake EOF at completion site, never due to triggered recovery.
- protected int fallBackToSpringForward(Statement unused) {
- int nextToken;
- int automatonState = automatonState();
-
- // If triggered fake EOF at completion site, see if the real next token would have passed muster.
- if (this.currentToken == TokenNameEOF) {
- if (this.scanner.eofPosition < this.scanner.source.length) {
- shouldStackAssistNode();
- this.scanner.eofPosition = this.scanner.source.length;
- nextToken = getNextToken();
- if (automatonWillShift(nextToken, automatonState)) {
- this.currentToken = nextToken;
- return RESUME;
- }
- this.scanner.ungetToken(nextToken); // spit out what has been bitten more than we can chew.
- } else {
- return HALT; // don't know how to proceed.
- }
- } else {
- nextToken = this.currentToken;
- this.scanner.ungetToken(nextToken);
- if (nextToken == TokenNameRBRACE)
- ignoreNextClosingBrace(); // having ungotten it, recoveryTokenCheck will see this again.
- }
- // OK, next token is no good to resume "in place", attempt some local repair. FIXME: need to make sure we don't get stuck keep reducing empty statements !!
- for (int i = 0, length = RECOVERY_TOKENS.length; i < length; i++) {
- if (automatonWillShift(RECOVERY_TOKENS[i], automatonState)) {
- this.currentToken = RECOVERY_TOKENS[i];
- return RESUME;
- }
- }
- // OK, no in place resumption, no local repair, fast forward to next statement.
- if (this.snapShot == null)
- return RESTART;
-
- this.copyState(this.snapShot);
- if (assistNodeNeedsStacking()) {
- this.currentToken = TokenNameSEMICOLON;
- return RESUME;
- }
- this.currentToken = this.scanner.fastForward(unused);
- return RESUME;
- }
-
- protected void ignoreNextClosingBrace() {
- return;
- }
-
- protected boolean assistNodeNeedsStacking() {
- return false;
- }
-
- public abstract int automatonState();
-
- public abstract boolean automatonWillShift(int nextToken, int lastAction);
-}
-
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
index 8c4d9d8eb2..e814ddc2eb 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
@@ -155,7 +155,7 @@ import org.eclipse.jdt.internal.compiler.util.Messages;
import org.eclipse.jdt.internal.compiler.util.Util;
@SuppressWarnings({"rawtypes", "unchecked"})
-public class Parser extends CommitRollbackParser implements ConflictedParser, OperatorIds, TypeIds {
+public class Parser implements TerminalTokens, ParserBasicInformation, ConflictedParser, OperatorIds, TypeIds {
protected static final int THIS_CALL = ExplicitConstructorCall.This;
protected static final int SUPER_CALL = ExplicitConstructorCall.Super;
@@ -231,6 +231,14 @@ public class Parser extends CommitRollbackParser implements ConflictedParser, Op
METHOD_REFERENCE,
LAMBDA,
}
+
+ // resumeOnSyntaxError codes:
+ protected static final int HALT = 0; // halt and throw up hands.
+ protected static final int RESTART = 1; // stacks adjusted, alternate goal from check point.
+ protected static final int RESUME = 2; // stacks untouched, just continue from where left off.
+
+ public Scanner scanner;
+ public int currentToken;
static {
try{
@@ -10550,10 +10558,10 @@ public boolean hasLeadingTagComment(char[] commentPrefixTag, int rangeEnd) {
return false;
}
-@Override
protected void ignoreNextClosingBrace() {
this.ignoreNextClosingBrace = true;
}
+
protected void ignoreExpressionAssignment() {
// Assignment ::= InvalidArrayInitializerAssignement
// encoded operator would be: this.intStack[this.intPtr]
@@ -12493,9 +12501,9 @@ protected void updateSourcePosition(Expression exp) {
exp.sourceEnd = this.intStack[this.intPtr--];
exp.sourceStart = this.intStack[this.intPtr--];
}
-public void copyState(CommitRollbackParser from) {
+public void copyState(Parser from) {
- Parser parser = (Parser) from;
+ Parser parser = from;
// Stack pointers.

Back to the top