Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2018-04-01 19:22:57 +0000
committerStephan Herrmann2018-04-01 19:22:57 +0000
commitb1059ebbb0d1fc00e85480741cfd55ec62905682 (patch)
treeb7375fac3a0b194d8a46518f75127010158ce058
parent90f2397a66e778ee23c69751993acb45a6568b4a (diff)
downloadorg.eclipse.objectteams-b1059ebbb0d1fc00e85480741cfd55ec62905682.tar.gz
org.eclipse.objectteams-b1059ebbb0d1fc00e85480741cfd55ec62905682.tar.xz
org.eclipse.objectteams-b1059ebbb0d1fc00e85480741cfd55ec62905682.zip
Fix regression in OrganizeImportsTest.testCalloutToStatic()
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java33
-rw-r--r--testplugins/org.eclipse.objectteams.otdt.ui.tests/src/org/eclipse/objectteams/otdt/ui/tests/core/OrganizeImportsTest.java4
2 files changed, 35 insertions, 2 deletions
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java
index b84237726..a8d5143bd 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java
@@ -37,11 +37,13 @@ import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
import org.eclipse.jdt.core.dom.AnnotatableType;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.ArrayInitializer;
import org.eclipse.jdt.core.dom.ArrayType;
+import org.eclipse.jdt.core.dom.CalloutMappingDeclaration;
import org.eclipse.jdt.core.dom.CharacterLiteral;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.Dimension;
@@ -66,6 +68,7 @@ import org.eclipse.jdt.core.dom.SimpleType;
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
import org.eclipse.jdt.core.dom.StringLiteral;
import org.eclipse.jdt.core.dom.Type;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.TypeLiteral;
import org.eclipse.jdt.core.dom.WildcardType;
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
@@ -103,6 +106,7 @@ import org.eclipse.text.edits.TextEdit;
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public final class ImportRewrite {
+
/**
* Used to determine how a type will be used, so that unwanted annotations can be filtered,
* which is in particular relevant for avoiding redundant null annotations in the scope of {@code @NonNullByDefault}.
@@ -1171,6 +1175,11 @@ public final class ImportRewrite {
return addStaticImport(getRawQualifiedName(declaringType), binding.getName(), true, context);
}
} else if (binding instanceof IMethodBinding) {
+ //{ObjectTeams: don't import field that can only be accessed by callout (decapsulation):
+ if ( !Flags.isPublic(binding.getModifiers())
+ && isCalloutAccessed((IMethodBinding) binding, context))
+ return null;
+//SH}
ITypeBinding declaringType= ((IMethodBinding) binding).getDeclaringClass();
return addStaticImport(getRawQualifiedName(declaringType), binding.getName(), false, context);
}
@@ -1178,6 +1187,30 @@ public final class ImportRewrite {
throw new IllegalArgumentException("Binding must be a static field or method."); //$NON-NLS-1$
}
+//{ObjectTeams: try to map a method to the rhs of a callout binding
+ private boolean isCalloutAccessed(final IMethodBinding binding, ImportRewriteContext context) {
+ class ASTVisitorExtension extends ASTVisitor {
+ boolean found;
+ public boolean visit(org.eclipse.jdt.core.dom.MethodSpec node) {
+ if (node.getLocationInParent() == CalloutMappingDeclaration.BASE_MAPPING_ELEMENT_PROPERTY && node.resolveBinding() == binding)
+ this.found = true;
+ return false;
+ }
+ }
+
+ for (Object t : this.astRoot.types()) {
+ TypeDeclaration type = (TypeDeclaration) t;
+ if (type.isRole() || type.isTeam()) {
+ ASTVisitorExtension visitor = new ASTVisitorExtension();
+ type.accept(visitor);
+ if (visitor.found)
+ return true;
+ }
+ }
+ return false;
+ }
+// SH}
+
/**
* Adds a new static import to the rewriter's record and returns a name - single member name if
* import is successful, else qualified name.
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests/src/org/eclipse/objectteams/otdt/ui/tests/core/OrganizeImportsTest.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests/src/org/eclipse/objectteams/otdt/ui/tests/core/OrganizeImportsTest.java
index 6b7f2bc31..1bdc0c948 100644
--- a/testplugins/org.eclipse.objectteams.otdt.ui.tests/src/org/eclipse/objectteams/otdt/ui/tests/core/OrganizeImportsTest.java
+++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests/src/org/eclipse/objectteams/otdt/ui/tests/core/OrganizeImportsTest.java
@@ -624,7 +624,7 @@ public class OrganizeImportsTest extends TestCase
buf.append("package teamPkg;\n");
buf.append("public team class T1 {\n");
buf.append(" public class R1 playedBy B1 {\n");
- buf.append(" abstract static void test();");
+ buf.append(" abstract static void test();\n");
buf.append(" void test() -> void testB1();\n");
buf.append(" }\n");
buf.append("}\n");
@@ -648,7 +648,7 @@ public class OrganizeImportsTest extends TestCase
buf.append("\n");
buf.append("public team class T1 {\n");
buf.append(" public class R1 playedBy B1 {\n");
- buf.append(" abstract static void test();");
+ buf.append(" abstract static void test();\n");
buf.append(" void test() -> void testB1();\n");
buf.append(" }\n");
buf.append("}\n");

Back to the top