diff options
author | Stephan Herrmann | 2012-02-23 20:19:32 +0000 |
---|---|---|
committer | Stephan Herrmann | 2012-02-23 20:19:32 +0000 |
commit | 18694f76180b9eaf5bef02a427e44916705b784b (patch) | |
tree | 55f42bc0d63c9ad4ddb9718011958408fe93e90d /org.eclipse.jdt.core | |
parent | ecaf9cbac125e05b992e9ad56d60313dad574102 (diff) | |
download | org.eclipse.objectteams-18694f76180b9eaf5bef02a427e44916705b784b.tar.gz org.eclipse.objectteams-18694f76180b9eaf5bef02a427e44916705b784b.tar.xz org.eclipse.objectteams-18694f76180b9eaf5bef02a427e44916705b784b.zip |
Test & fix for Bug 370273 - [compiler][otjld] consider allowing base
imported types as the return type of a team method
Diffstat (limited to 'org.eclipse.jdt.core')
8 files changed, 42 insertions, 22 deletions
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionOnParameterizedSingleTypeReference.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionOnParameterizedSingleTypeReference.java index 08acfc2c0..0af1cb8f0 100644 --- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionOnParameterizedSingleTypeReference.java +++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionOnParameterizedSingleTypeReference.java @@ -34,8 +34,8 @@ public class SelectionOnParameterizedSingleTypeReference extends ParameterizedSi } //{ObjectTeams: one more method to override: @Override - public TypeBinding checkResolveUsingBaseImportScope(Scope scope) { - TypeBinding result = super.checkResolveUsingBaseImportScope(scope); + public TypeBinding checkResolveUsingBaseImportScope(Scope scope, boolean tolerate) { + TypeBinding result = super.checkResolveUsingBaseImportScope(scope, tolerate); if (this.resolvedType != null) throw new SelectionNodeFound(this.resolvedType); return result; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java index 771e687ad..31ce9271f 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java @@ -110,7 +110,9 @@ public abstract class Expression extends Statement { ALLOWED { public boolean isAllowed() { return true; }}, /** This node is either a playedBy reference for which decapsulation has been reported, * or some other (generated) base reference for which decapsulation shall not be reported. */ - REPORTED { public boolean isAllowed() { return true; }}; + REPORTED { public boolean isAllowed() { return true; }}, + /** This mode is for team method return types: prefer local resolution, but tolerate base class as a fallback. */ + TOLERATED { public boolean isAllowed() { return false; }}; abstract public boolean isAllowed(); } public DecapsulationState getBaseclassDecapsulation() {return DecapsulationState.NONE;} diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java index 4c9276586..c0e16b846 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java @@ -449,9 +449,10 @@ public class ParameterizedSingleTypeReference extends ArrayTypeReference { //{ObjectTeams: resolve helpers // for base-imported types (only single is supported): @Override - public TypeBinding checkResolveUsingBaseImportScope(Scope scope) { + public TypeBinding checkResolveUsingBaseImportScope(Scope scope, boolean tolerate) { // same as in SingleTypeReference: if ( this.getBaseclassDecapsulation().isAllowed() + || tolerate || scope.isBaseGuard()) { TypeBinding problem = this.resolvedType; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleTypeReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleTypeReference.java index 0e5b6bea9..5f8c0e13d 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleTypeReference.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleTypeReference.java @@ -107,8 +107,9 @@ public class SingleTypeReference extends TypeReference { //{ObjectTeams: for base-imported types (only single is supported): @Override - public TypeBinding checkResolveUsingBaseImportScope(Scope scope) { + public TypeBinding checkResolveUsingBaseImportScope(Scope scope, boolean tolerate) { if ( this.getBaseclassDecapsulation().isAllowed() + || tolerate || scope.isBaseGuard()) { TypeBinding problem = this.resolvedType; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.java index 89eba305a..0a3053510 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.java @@ -167,7 +167,7 @@ protected TypeBinding internalResolveType(Scope scope) { CompilationResult compilationResult = scope.referenceCompilationUnit().compilationResult(); CompilationResult.CheckPoint cp = compilationResult.getCheckPoint(scope.referenceContext()); try { - type = checkResolveUsingBaseImportScope(scope); + type = checkResolveUsingBaseImportScope(scope, false); // apply TOLERATE strategy only as a last resort below // copied from below: if (type != null && type.isValidBinding()) { type = scope.environment().convertToRawType(type, false /*do not force conversion of enclosing types*/); @@ -199,8 +199,8 @@ protected TypeBinding internalResolveType(Scope scope) { throw snf; // found a valid node. caughtException = snf; } - try { // a third chance trying an anchored type: + try { if ( (caughtException != null) || (this.resolvedType.problemId() == ProblemReasons.NotFound)) { @@ -211,11 +211,25 @@ protected TypeBinding internalResolveType(Scope scope) { } } catch (SelectionNodeFound snf2) { caughtException = snf2; // throw the newer exception instead. - } finally { + } +//a forth chance trying a TOLERATED base imported type: + try { + if ( (caughtException != null) + || (this.resolvedType.problemId() == ProblemReasons.NotFound)) + { + if (this.baseclassDecapsulation == DecapsulationState.TOLERATED) { + TypeBinding result = checkResolveUsingBaseImportScope(scope, true); + if (result != null) // did we do any better than before? + type = this.resolvedType = result; // if non-null but ProblemBinding report below. + } + } + } catch (SelectionNodeFound snf2) { + caughtException = snf2; // throw the newer exception instead. + } finally { // the attempt to prevent an exception failed: if (caughtException != null) throw caughtException; - } + } // SH} if ((hasError = !type.isValidBinding()) == true) { reportInvalidType(scope); @@ -258,7 +272,7 @@ public TypeBinding checkResolvedType(TypeBinding type, Scope scope, boolean hasE //{ObjectTeams: alternative strategies for resolving: /** Try to resolve this reference from base imports. */ -public TypeBinding checkResolveUsingBaseImportScope(Scope scope) { +public TypeBinding checkResolveUsingBaseImportScope(Scope scope, boolean tolerate) { return null; // override to do something useful (only in SingleTypeReference). } /** diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java index 5a693105b..b82025b21 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java @@ -2369,7 +2369,7 @@ public class ClassScope extends Scope { */ typeReference.deprecationProblemId = IProblem.DeprecatedBaseclass; ReferenceBinding superType; - if (typeReference.checkResolveUsingBaseImportScope(this) != null) { + if (typeReference.checkResolveUsingBaseImportScope(this, false) != null) { superType = (ReferenceBinding)typeReference.resolvedType; } else { superType = (ReferenceBinding) typeReference.resolveSuperType(this); diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java index 46f0bf128..07d1434a1 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java @@ -2268,6 +2268,8 @@ public MethodBinding resolveTypesFor(MethodBinding method, boolean fromSynthetic } else { //{ObjectTeams: option to roll back problems: CheckPoint cp = this.scope.referenceContext.compilationResult.getCheckPoint(methodDecl); + if (this.isTeam() && !method.isPrivate() && returnType.getBaseclassDecapsulation() == DecapsulationState.NONE) + returnType.setBaseclassDecapsulation(DecapsulationState.TOLERATED); // SH} // https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 boolean deferRawTypeCheck = !reportUnavoidableGenericTypeProblems && (returnType.bits & ASTNode.IgnoreRawTypeCheck) == 0; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/IAlienScopeTypeReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/IAlienScopeTypeReference.java index 7d2ccb56d..15be70e01 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/IAlienScopeTypeReference.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/IAlienScopeTypeReference.java @@ -51,8 +51,8 @@ public interface IAlienScopeTypeReference { } public Scope getAlienScope() { return this.alienScope; } @Override - public TypeBinding checkResolveUsingBaseImportScope(Scope scope) { - return super.checkResolveUsingBaseImportScope(this.alienScope); + public TypeBinding checkResolveUsingBaseImportScope(Scope scope, boolean tolerate) { + return super.checkResolveUsingBaseImportScope(this.alienScope, tolerate); } @Override public TypeBinding resolveType(ClassScope scope) { @@ -87,8 +87,8 @@ public interface IAlienScopeTypeReference { } public Scope getAlienScope() { return this.alienScope; } @Override - public TypeBinding checkResolveUsingBaseImportScope(Scope scope) { - return super.checkResolveUsingBaseImportScope(this.alienScope); + public TypeBinding checkResolveUsingBaseImportScope(Scope scope, boolean tolerate) { + return super.checkResolveUsingBaseImportScope(this.alienScope, tolerate); } @Override public TypeBinding resolveType(ClassScope scope) { @@ -124,15 +124,15 @@ public interface IAlienScopeTypeReference { } public Scope getAlienScope() { return this.alienScope; } @Override - public TypeBinding checkResolveUsingBaseImportScope(Scope scope) { + public TypeBinding checkResolveUsingBaseImportScope(Scope scope, boolean tolerate) { // `scope` may be stronger then `alienScope`, try it first: // (see 1.1.22-otjld-layered-teams-5) - TypeBinding result= super.checkResolveUsingBaseImportScope(scope); + TypeBinding result= super.checkResolveUsingBaseImportScope(scope, tolerate); if (result != null && result.isValidBinding()) return result; // remove problem binding if any: this.resolvedType = null; - return super.checkResolveUsingBaseImportScope(this.alienScope); + return super.checkResolveUsingBaseImportScope(this.alienScope, tolerate); } @Override public TypeBinding resolveType(ClassScope scope) { @@ -168,8 +168,8 @@ public interface IAlienScopeTypeReference { } public Scope getAlienScope() { return this.alienScope; } @Override - public TypeBinding checkResolveUsingBaseImportScope(Scope scope) { - return super.checkResolveUsingBaseImportScope(this.alienScope); + public TypeBinding checkResolveUsingBaseImportScope(Scope scope, boolean tolerate) { + return super.checkResolveUsingBaseImportScope(this.alienScope, tolerate); } @Override public TypeBinding resolveType(ClassScope scope) { @@ -208,8 +208,8 @@ public interface IAlienScopeTypeReference { } public Scope getAlienScope() { return this.alienScope; } @Override - public TypeBinding checkResolveUsingBaseImportScope(Scope scope) { - return super.checkResolveUsingBaseImportScope(this.alienScope); + public TypeBinding checkResolveUsingBaseImportScope(Scope scope, boolean tolerate) { + return super.checkResolveUsingBaseImportScope(this.alienScope, tolerate); } @Override public TypeBinding resolveType(ClassScope scope) { |