Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2017-02-10 12:33:18 +0000
committerManoj Palat2017-02-10 12:33:18 +0000
commitd76154e046336931f0547276854788024c0de29e (patch)
treee4f317bd04178fadc6fcc139a409e1fe7b0df958
parent5b985a80c268f70b5a6f9778d88c8c05a1714e21 (diff)
downloadeclipse.jdt.core-d76154e046336931f0547276854788024c0de29e.tar.gz
eclipse.jdt.core-d76154e046336931f0547276854788024c0de29e.tar.xz
eclipse.jdt.core-d76154e046336931f0547276854788024c0de29e.zip
Fix for bug 512023 [1.9][dom] wrong source position info for qualified
names in module-info.java (plus some cleanup)
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java57
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java2
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java65
-rw-r--r--org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java2
5 files changed, 97 insertions, 33 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java
index 9d727d4557..c9f5e95a53 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2016 IBM Corporation and others.
+ * Copyright (c) 2016, 2017 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
@@ -20,7 +20,10 @@ import org.eclipse.jdt.core.dom.*;
import java.util.List;
+import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
@SuppressWarnings({"rawtypes"})
@@ -40,7 +43,7 @@ public class ASTConverter9Test extends ConverterTestSetup {
static {
// TESTS_NUMBERS = new int[] { 19 };
// TESTS_RANGE = new int[] { 1, -1 };
-// TESTS_NAMES = new String[] {"testBug497719_0001"};
+// TESTS_NAMES = new String[] {"testBug512023_0001"};
}
public static Test suite() {
return buildModelTestSuite(ASTConverter9Test.class);
@@ -175,5 +178,55 @@ public class ASTConverter9Test extends ConverterTestSetup {
type = impls.get(0);
checkSourceRange(type, "pack11.packinternal.Z11", content);
}
+
+ public void testBug512023_0001() throws Exception {
+ try {
+ IJavaProject project1 = createJavaProject("ConverterTests9", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "9");
+ project1.open(null);
+ addClasspathEntry(project1, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.MODULE_PATH")));
+ String content =
+ "module first {\n" +
+ " requires second.third;\n" +
+ " exports pack1.X11 to org.eclipse.jdt;\n" +
+ "}";
+ createFile("/ConverterTests9/src/module-info.java", content);
+ createFolder("/ConverterTests9/src/pack1");
+ createFile("/ConverterTests9/src/pack1/X11.java",
+ "package pack1;\n" +
+ "public class X11 {}\n");
+ this.workingCopy = getWorkingCopy("/ConverterTests9/src/module-info.java", false);
+ ASTNode node = buildAST(content, this.workingCopy, false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ ModuleDeclaration moduleDecl = unit.getModule();
+
+ checkSourceRange(moduleDecl, content, content);
+ List<ModuleStatement> stmts = moduleDecl.moduleStatements();
+ assertTrue(stmts.size() > 0);
+
+ QualifiedName qName;
+ RequiresStatement req = (RequiresStatement) stmts.get(0);
+ qName = (QualifiedName) req.getName();
+ checkSourceRange(qName, "second.third", content);
+ checkSourceRange(qName.getName(), "third", content);
+ checkSourceRange(qName.getQualifier(), "second", content);
+
+ ExportsStatement exp = (ExportsStatement) stmts.get(1);
+ checkSourceRange(exp, "exports pack1.X11 to org.eclipse.jdt;", content);
+ qName = (QualifiedName) exp.getName();
+ checkSourceRange(qName, "pack1.X11", content);
+ checkSourceRange(qName.getName(), "X11", content);
+ checkSourceRange(qName.getQualifier(), "pack1", content);
+
+ List<Name> modules = exp.modules();
+ qName = (QualifiedName) modules.get(0);
+ checkSourceRange(qName, "org.eclipse.jdt", content);
+ checkSourceRange(qName.getName(), "jdt", content);
+ checkSourceRange(qName.getQualifier(), "org.eclipse", content);
+ } finally {
+ deleteProject("ConverterTests9");
+ }
+ }
+
// Add new tests here
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java
index bc4ef136b2..0a7811256f 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java
@@ -1902,6 +1902,7 @@ public class ExternalAnnotations18Test extends ModifyingResourceTests {
"Pb(149) Dead code"
}, new int[] { 7 });
}
+ @SuppressWarnings("deprecation")
public void testBug507256() throws Exception {
myCreateJavaProject("TestLibs");
addLibraryWithExternalAnnotations(this.project, "lib1.jar", "annots", new String[] {
@@ -1982,6 +1983,7 @@ public class ExternalAnnotations18Test extends ModifyingResourceTests {
* Assert that external annotations configured for project A's library are considered also while compiling dependent project B.
* Reconcile.
*/
+ @SuppressWarnings("deprecation")
public void testBug509715reconcile() throws Exception {
try {
setupJavaProject("Bug509715ProjA");
@@ -2002,6 +2004,7 @@ public class ExternalAnnotations18Test extends ModifyingResourceTests {
}
}
+ @SuppressWarnings("deprecation")
public void testBug500024dir() throws CoreException, IOException {
try {
String projectName = "Bug500024";
@@ -2040,6 +2043,7 @@ public class ExternalAnnotations18Test extends ModifyingResourceTests {
}
}
+ @SuppressWarnings("deprecation")
public void testBug500024jar() throws CoreException, IOException {
try {
String projectName = "Bug500024";
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java
index f947c246fa..03c342d706 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java
@@ -185,11 +185,9 @@ private void checkAndSetModifiersForMethod(MethodBinding methodBinding) {
int expectedModifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccAbstract;
boolean isDefaultMethod = (modifiers & ExtraCompilerModifiers.AccDefaultMethod) != 0; // no need to check validity, is done by the parser
boolean reportIllegalModifierCombination = false;
- boolean isJDK18orGreater = false;
if (sourceLevel >= ClassFileConstants.JDK1_8 && !declaringClass.isAnnotationType()) {
expectedModifiers |= ClassFileConstants.AccStrictfp
| ExtraCompilerModifiers.AccDefaultMethod | ClassFileConstants.AccStatic;
- isJDK18orGreater = true;
if (!methodBinding.isAbstract()) {
reportIllegalModifierCombination = isDefaultMethod && methodBinding.isStatic();
} else {
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
index 3598acc02f..55e073b775 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 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
@@ -1694,12 +1694,16 @@ class ASTConverter {
org.eclipse.jdt.internal.compiler.ast.PackageVisibilityStatement pvsStmt, ModulePackageAccess stmt) {
int sourceEnd = pvsStmt.declarationSourceEnd;
if (pvsStmt.declarationEnd > sourceEnd) sourceEnd = pvsStmt.declarationEnd; // TODO: working around a compiler issue
- stmt.setName(getUpdatedName(pvsStmt.pkgName, pvsStmt.pkgRef.sourceStart, pvsStmt.pkgRef.sourceEnd));
+ Name name = getImportName(pvsStmt.pkgRef);
+ stmt.setName(name);
+ if (this.resolveBindings) {
+ recordNodes(name, pvsStmt.pkgRef);
+ }
int tmp = sourceEnd;
if (pvsStmt.targets != null && pvsStmt.targets.length > 0) {
List<Name> modules = stmt.modules();
for (ModuleReference moduleRef : pvsStmt.getTargetedModules()) {
- modules.add(getUpdatedName(moduleRef.moduleName, moduleRef.sourceStart, moduleRef.sourceEnd));
+ modules.add(getName(moduleRef, CharOperation.splitOn('.', moduleRef.moduleName), moduleRef.sourcePositions));
if (tmp < moduleRef.sourceEnd) tmp = moduleRef.sourceEnd;
}
}
@@ -3125,24 +3129,9 @@ class ASTConverter {
public ImportDeclaration convertImport(org.eclipse.jdt.internal.compiler.ast.ImportReference importReference) {
final ImportDeclaration importDeclaration = new ImportDeclaration(this.ast);
+ Name name = getImportName(importReference);
+ importDeclaration.setName(name);
final boolean onDemand = (importReference.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.OnDemand) != 0;
- final char[][] tokens = importReference.tokens;
- int length = importReference.tokens.length;
- final long[] positions = importReference.sourcePositions;
- if (length > 1) {
- importDeclaration.setName(setQualifiedNameNameAndSourceRanges(tokens, positions, importReference));
- } else {
- final SimpleName name = new SimpleName(this.ast);
- name.internalSetIdentifier(new String(tokens[0]));
- final int start = (int)(positions[0]>>>32);
- final int end = (int)(positions[0] & 0xFFFFFFFF);
- name.setSourceRange(start, end - start + 1);
- name.index = 1;
- importDeclaration.setName(name);
- if (this.resolveBindings) {
- recordNodes(name, importReference);
- }
- }
importDeclaration.setSourceRange(importReference.declarationSourceStart, importReference.declarationEnd - importReference.declarationSourceStart + 1);
importDeclaration.setOnDemand(onDemand);
int modifiers = importReference.modifiers;
@@ -3165,6 +3154,30 @@ class ASTConverter {
return importDeclaration;
}
+ public Name getImportName(org.eclipse.jdt.internal.compiler.ast.ImportReference importReference) {
+ return getName(importReference, importReference.tokens, importReference.sourcePositions);
+ }
+
+ private Name getName(org.eclipse.jdt.internal.compiler.ast.ASTNode node, final char[][] tokens,
+ final long[] positions) {
+ Name name;
+ int length = tokens != null ? tokens.length : 0;
+ if (length > 1) {
+ name = setQualifiedNameNameAndSourceRanges(tokens, positions, node);
+ } else {
+ name = new SimpleName(this.ast);
+ ((SimpleName)name).internalSetIdentifier(new String(tokens[0]));
+ final int start = (int)(positions[0]>>>32);
+ final int end = (int)(positions[0] & 0xFFFFFFFF);
+ name.setSourceRange(start, end - start + 1);
+ name.index = 1;
+ if (this.resolveBindings) {
+ recordNodes(name, node);
+ }
+ }
+ return name;
+ }
+
public PackageDeclaration convertPackage(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration compilationUnitDeclaration) {
org.eclipse.jdt.internal.compiler.ast.ImportReference importReference = compilationUnitDeclaration.currentPackage;
final PackageDeclaration packageDeclaration = new PackageDeclaration(this.ast);
@@ -3286,10 +3299,13 @@ class ASTConverter {
ModuleDeclaration moduleDecl = this.ast.newModuleDeclaration();
convert(moduleDeclaration.javadoc, moduleDecl);
setModifiers(moduleDecl, moduleDeclaration);
- Name moduleName = getUpdatedName(moduleDeclaration.moduleName, moduleDeclaration.sourceStart, moduleDeclaration.sourceEnd);
+ Name moduleName = getName(moduleDeclaration, CharOperation.splitOn('.', moduleDeclaration.moduleName), moduleDeclaration.sourcePositions);
moduleDecl.setName(moduleName);
moduleDecl.setSourceRange(moduleDeclaration.declarationSourceStart, moduleDeclaration.declarationSourceEnd - moduleDeclaration.declarationSourceStart + 1);
+ if (this.resolveBindings) {
+ this.recordNodes(moduleDecl, moduleDeclaration);
+ }
List<ModuleStatement> stmts = moduleDecl.moduleStatements();
TreeSet<ModuleStatement> tSet = new TreeSet<> (new Comparator() {
public int compare(Object o1, Object o2) {
@@ -3308,7 +3324,7 @@ class ASTConverter {
org.eclipse.jdt.internal.compiler.ast.RequiresStatement req = moduleDeclaration.requires[i];
ModuleReference moduleRef = req.module;
RequiresStatement stmt = new RequiresStatement(this.ast);
- Name name = getUpdatedName(moduleRef.moduleName, moduleRef.sourceStart, moduleRef.sourceEnd);
+ Name name = getName(moduleRef, CharOperation.splitOn('.', moduleRef.moduleName), moduleRef.sourcePositions);
stmt.setName(name);
addModifierToRequires(req, req.isTransitive(), Modifier.ModifierKeyword.TRANSIENT_KEYWORD, stmt);
@@ -4373,11 +4389,6 @@ class ASTConverter {
}
return false;
}
- private Name getUpdatedName(char[] s, int sourceStart, int sourceEnd) {
- Name name = this.ast.newName(new String(s));
- name.setSourceRange(sourceStart, sourceEnd - sourceStart + 1);
- return name;
- }
private void lookupForScopes() {
if (this.pendingNameScopeResolution != null) {
for (Iterator iterator = this.pendingNameScopeResolution.iterator(); iterator.hasNext(); ) {
diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java
index 321a569e9d..fb30c547b0 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java
@@ -2927,10 +2927,8 @@ private void reportMatching(ProvidesStatement[] provides, ModuleDeclaration modu
private void reportMatching(UsesStatement[] uses, ModuleDeclaration module, MatchingNodeSet nodeSet, IModuleDescription moduleDesc) {
if (uses != null && uses.length > 0) {
try {
- String[] usedServices = moduleDesc.getUsedServices();
for (int i = 0, l = uses.length; i < l; ++i) {
UsesStatement service = uses[i];
- String usedService = usedServices[i];
TypeReference intf = service.serviceInterface;
if (intf != null) {

Back to the top