Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorssankaran2013-03-02 06:20:38 +0000
committerssankaran2013-03-02 06:20:38 +0000
commitc35f48a470f9475e0b73c6c14c2a26ca2378ab58 (patch)
tree8fe112b08f71e7267c2cf4f39c44fd2e4c54f7e9 /org.eclipse.jdt.core/compiler/org/eclipse/jdt
parent11ac720cf12c89391a32ed5e56750070174f7f3f (diff)
downloadeclipse.jdt.core-c35f48a470f9475e0b73c6c14c2a26ca2378ab58.tar.gz
eclipse.jdt.core-c35f48a470f9475e0b73c6c14c2a26ca2378ab58.tar.xz
eclipse.jdt.core-c35f48a470f9475e0b73c6c14c2a26ca2378ab58.zip
Fixed Bug 402198 - [1.8][compiler][infrastructure] Enhance
IErrorHandlingPolicy to support a new policy: ignore all errors.
Diffstat (limited to 'org.eclipse.jdt.core/compiler/org/eclipse/jdt')
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/DefaultErrorHandlingPolicies.java35
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/IErrorHandlingPolicy.java10
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FunctionalExpression.java12
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java86
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java13
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java10
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java16
7 files changed, 111 insertions, 71 deletions
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/DefaultErrorHandlingPolicies.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/DefaultErrorHandlingPolicies.java
index f374c4c0ec..f5acdaeb20 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/DefaultErrorHandlingPolicies.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/DefaultErrorHandlingPolicies.java
@@ -1,9 +1,13 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 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
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
*
* Contributors:
* IBM Corporation - initial API and implementation
@@ -27,6 +31,9 @@ public static IErrorHandlingPolicy exitAfterAllProblems() {
public boolean proceedOnErrors(){
return false;
}
+ public boolean ignoreAllErrors() {
+ return false;
+ }
};
}
/*
@@ -42,6 +49,9 @@ public static IErrorHandlingPolicy exitOnFirstError() {
public boolean proceedOnErrors(){
return false;
}
+ public boolean ignoreAllErrors() {
+ return false;
+ }
};
}
/*
@@ -56,6 +66,9 @@ public static IErrorHandlingPolicy proceedOnFirstError() {
public boolean proceedOnErrors(){
return true;
}
+ public boolean ignoreAllErrors() {
+ return false;
+ }
};
}
/*
@@ -70,6 +83,26 @@ public static IErrorHandlingPolicy proceedWithAllProblems() {
public boolean proceedOnErrors(){
return true;
}
+ public boolean ignoreAllErrors() {
+ return false;
+ }
+ };
+}
+/*
+ * Accumulate all problems, then proceed with them, but never report them.
+ *
+ */
+public static IErrorHandlingPolicy ignoreAllProblems() {
+ return new IErrorHandlingPolicy() {
+ public boolean stopOnFirstError() {
+ return false;
+ }
+ public boolean proceedOnErrors(){
+ return true;
+ }
+ public boolean ignoreAllErrors() {
+ return true;
+ }
};
}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/IErrorHandlingPolicy.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/IErrorHandlingPolicy.java
index f8afdf2ca0..de68aba850 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/IErrorHandlingPolicy.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/IErrorHandlingPolicy.java
@@ -1,21 +1,26 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 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
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.compiler;
/*
- * Handler policy is responsible to answer the 2 following
+ * Handler policy is responsible to answer the 3 following
* questions:
* 1. should the handler stop on first problem which appears
* to be a real error (that is, not a warning),
* 2. should it proceed once it has gathered all problems
+ * 3. Should problems be reported at all ?
*
* The intent is that one can supply its own policy to implement
* some interactive error handling strategy where some UI would
@@ -25,4 +30,5 @@ package org.eclipse.jdt.internal.compiler;
public interface IErrorHandlingPolicy {
boolean proceedOnErrors();
boolean stopOnFirstError();
+ boolean ignoreAllErrors();
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FunctionalExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FunctionalExpression.java
index 35e98ae3b6..8a5e300985 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FunctionalExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FunctionalExpression.java
@@ -18,6 +18,8 @@ package org.eclipse.jdt.internal.compiler.ast;
import org.eclipse.jdt.core.compiler.CategorizedProblem;
import org.eclipse.jdt.internal.compiler.CompilationResult;
+import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
+import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
import org.eclipse.jdt.internal.compiler.impl.Constant;
@@ -48,13 +50,10 @@ public abstract class FunctionalExpression extends Expression implements Problem
protected CompilationResult compilationResult;
protected BlockScope enclosingScope;
protected boolean ellipsisArgument;
- protected static CompilationResult devNullCompilationResult;
+ protected static IErrorHandlingPolicy silentErrorHandlingPolicy = DefaultErrorHandlingPolicies.ignoreAllProblems();
public FunctionalExpression(CompilationResult compilationResult) {
this.compilationResult = compilationResult;
- if (devNullCompilationResult == null) {
- devNullCompilationResult = new CompilationResult(this.compilationResult.getCompilationUnit(), 0, 0, Integer.MAX_VALUE /* maximum problems per unit */);
- }
}
public void setExpectedType(TypeBinding expectedType) {
@@ -209,12 +208,7 @@ public abstract class FunctionalExpression extends Expression implements Problem
return this.ignoreFurtherInvestigation;
}
- private boolean shouldShutup() {
- return this.compilationResult == devNullCompilationResult;
- }
-
public void tagAsHavingErrors() {
- if (shouldShutup()) return;
this.ignoreFurtherInvestigation = true;
Scope parent = this.enclosingScope.parent;
while (parent != null) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java
index fb1df1d502..e0aa4b3dc1 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java
@@ -21,6 +21,7 @@ package org.eclipse.jdt.internal.compiler.ast;
import org.eclipse.jdt.internal.compiler.ASTVisitor;
import org.eclipse.jdt.internal.compiler.CompilationResult;
+import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
import org.eclipse.jdt.internal.compiler.flow.ExceptionHandlingFlowContext;
@@ -80,8 +81,11 @@ public class LambdaExpression extends FunctionalExpression {
* @see org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(ClassScope)
*/
public TypeBinding resolveType(BlockScope blockScope) {
+
this.constant = Constant.NotAConstant;
this.enclosingScope = blockScope;
+ this.scope = new MethodScope(blockScope, this, blockScope.methodScope().isStatic);
+
if (this.expectedType == null && this.expressionContext == INVOCATION_CONTEXT) {
if (this.body instanceof Block) {
// Gather shape information for potential applicability analysis.
@@ -129,8 +133,6 @@ public class LambdaExpression extends FunctionalExpression {
if (!haveDescriptor && argumentsTypeElided)
return null; // FUBAR, bail out...
- this.scope = new MethodScope(blockScope, this, blockScope.methodScope().isStatic);
-
this.binding = new MethodBinding(ClassFileConstants.AccPublic | ExtraCompilerModifiers.AccUnresolved,
haveDescriptor ? this.descriptor.selector : TypeConstants.ANONYMOUS_METHOD,
haveDescriptor ? this.descriptor.returnType : null,
@@ -421,58 +423,52 @@ public class LambdaExpression extends FunctionalExpression {
return false;
}
- LambdaExpression copy = copy();
- copy.setExpressionContext(this.expressionContext);
- copy.setExpectedType(left);
- copy.resolveType(this.enclosingScope);
-
- if (!argumentsTypeElided()) {
- for (int i = 0, length = sam.parameters.length; i < length; i++) {
- TypeBinding argumentType = copy.arguments[i].binding.type;
- if (sam.parameters[i] != argumentType)
- return false;
- }
- }
-
+ IErrorHandlingPolicy oldPolicy = this.scope.problemReporter().switchErrorHandlingPolicy(silentErrorHandlingPolicy);
try {
- final TypeBinding returnType = sam.returnType;
- if (this.body instanceof Block) {
- ASTVisitor visitor = new ASTVisitor() {
- public boolean visit(ReturnStatement returnStatement, BlockScope blockScope) {
- Expression expression = returnStatement.expression;
- if (expression != null && !expression.isAssignmentCompatible(returnType, blockScope))
- throw new NoncongruentLambdaException();
+ LambdaExpression copy = copy();
+ copy.setExpressionContext(this.expressionContext);
+ copy.setExpectedType(left);
+ copy.resolveType(this.enclosingScope);
+
+ if (!argumentsTypeElided()) {
+ for (int i = 0, length = sam.parameters.length; i < length; i++) {
+ TypeBinding argumentType = copy.arguments[i].binding.type;
+ if (sam.parameters[i] != argumentType)
return false;
- }
- };
- copy.body.traverse(visitor, copy.scope);
- } else {
- Expression expression = (Expression) copy.body;
- if (!expression.isAssignmentCompatible(returnType, copy.scope))
- throw new NoncongruentLambdaException();
+ }
}
- } catch (NoncongruentLambdaException e) {
- return false;
+
+ try {
+ final TypeBinding returnType = sam.returnType;
+ if (this.body instanceof Block) {
+ ASTVisitor visitor = new ASTVisitor() {
+ public boolean visit(ReturnStatement returnStatement, BlockScope blockScope) {
+ Expression expression = returnStatement.expression;
+ if (expression != null && !expression.isAssignmentCompatible(returnType, blockScope))
+ throw new NoncongruentLambdaException();
+ return false;
+ }
+ };
+ copy.body.traverse(visitor, copy.scope);
+ } else {
+ Expression expression = (Expression) copy.body;
+ if (!expression.isAssignmentCompatible(returnType, copy.scope))
+ throw new NoncongruentLambdaException();
+ }
+ } catch (NoncongruentLambdaException e) {
+ return false;
+ }
+ } finally {
+ this.scope.problemReporter().switchErrorHandlingPolicy(oldPolicy);
}
return true;
}
LambdaExpression copy() {
- final Parser parser = new Parser(this.enclosingScope.problemReporter(), false);
+ final Parser parser = new Parser(this.scope.problemReporter(), false);
final char[] source = this.compilationResult.getCompilationUnit().getContents();
- LambdaExpression copy;
-
- CompilationUnitDeclaration unit = this.enclosingScope.referenceCompilationUnit();
- CompilationResult original = unit.compilationResult;
- unit.compilationResult = devNullCompilationResult;
-
- try {
- copy = (LambdaExpression) parser.parseExpression(source, this.sourceStart, this.sourceEnd - this.sourceStart + 1, unit);
- } finally {
- unit.compilationResult = original;
- }
- copy.compilationResult = devNullCompilationResult;
- return copy;
+ return (LambdaExpression) parser.parseExpression(source, this.sourceStart, this.sourceEnd - this.sourceStart + 1,
+ this.scope.referenceCompilationUnit(), false /* record line separators */);
}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java
index d16be966e4..f88b274b0c 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java
@@ -23,6 +23,7 @@ package org.eclipse.jdt.internal.compiler.ast;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.ASTVisitor;
import org.eclipse.jdt.internal.compiler.CompilationResult;
+import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.codegen.ConstantPool;
import org.eclipse.jdt.internal.compiler.flow.FlowContext;
@@ -366,17 +367,17 @@ public class ReferenceExpression extends FunctionalExpression implements Invocat
final MethodBinding sam = left.getSingleAbstractMethod(scope);
if (sam == null || !sam.isValidBinding())
return false;
- this.method.binding = this.binding = null;
+ boolean isCompatible;
setExpectedType(left);
- CompilationResult original = this.compilationResult;
+ IErrorHandlingPolicy oldPolicy = this.enclosingScope.problemReporter().switchErrorHandlingPolicy(silentErrorHandlingPolicy);
try {
- this.compilationResult = devNullCompilationResult;
+ this.method.binding = this.binding = null;
resolveType(this.enclosingScope);
} finally {
- this.compilationResult = original;
+ this.enclosingScope.problemReporter().switchErrorHandlingPolicy(oldPolicy);
+ isCompatible = this.binding != null && this.binding.isValidBinding();
+ this.method.binding = this.binding = null;
}
- boolean isCompatible = this.binding != null && this.binding.isValidBinding();
- this.method.binding = this.binding = null;
return isCompatible;
}
} \ No newline at end of file
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 9b5c41c429..0002634817 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
@@ -10228,11 +10228,11 @@ public void goForCompilationUnit(){
this.scanner.foundTaskCount = 0;
this.scanner.recordLineSeparator = true;
}
-public void goForExpression() {
+public void goForExpression(boolean recordLineSeparator) {
//tells the scanner to go for an expression parsing
this.firstToken = TokenNameREMAINDER;
- this.scanner.recordLineSeparator = true; // recovery goals must record line separators
+ this.scanner.recordLineSeparator = recordLineSeparator; // recovery goals must record line separators
}
public void goForFieldDeclaration(){
//tells the scanner to go for field declaration parsing
@@ -11040,7 +11040,7 @@ public void parse(
//convert bugs into parse error
initialize();
- goForExpression();
+ goForExpression(true /* record line separators */);
this.nestedMethod[this.nestedType]++;
this.referenceContext = type;
@@ -11376,10 +11376,10 @@ public ASTNode[] parseClassBodyDeclarations(char[] source, int offset, int lengt
}
return result;
}
-public Expression parseExpression(char[] source, int offset, int length, CompilationUnitDeclaration unit) {
+public Expression parseExpression(char[] source, int offset, int length, CompilationUnitDeclaration unit, boolean recordLineSeparators) {
initialize();
- goForExpression();
+ goForExpression(recordLineSeparators);
this.nestedMethod[this.nestedType]++;
this.referenceContext = unit;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java
index 1ea540f005..2d51b8f59d 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java
@@ -1,9 +1,13 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 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
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
*
* Contributors:
* IBM Corporation - initial API and implementation
@@ -35,7 +39,7 @@ public class ProblemHandler {
public final static String[] NoArgument = CharOperation.NO_STRINGS;
- final public IErrorHandlingPolicy policy;
+ public IErrorHandlingPolicy policy;
public final IProblemFactory problemFactory;
public final CompilerOptions options;
/*
@@ -114,7 +118,7 @@ public void handle(
ReferenceContext referenceContext,
CompilationResult unitResult) {
- if (severity == ProblemSeverities.Ignore)
+ if (severity == ProblemSeverities.Ignore || this.policy.ignoreAllErrors())
return;
if ((severity & ProblemSeverities.Optional) != 0 && problemId != IProblem.Task && !this.options.ignoreSourceFolderWarningOption) {
@@ -212,4 +216,10 @@ public void handle(
public void record(CategorizedProblem problem, CompilationResult unitResult, ReferenceContext referenceContext, boolean optionalError) {
unitResult.record(problem, referenceContext, optionalError);
}
+/** @return old policy. */
+public IErrorHandlingPolicy switchErrorHandlingPolicy(IErrorHandlingPolicy newPolicy) {
+ IErrorHandlingPolicy presentPolicy = this.policy;
+ this.policy = newPolicy;
+ return presentPolicy;
+}
}

Back to the top