Fix for Bug 518401: [9] DOM AST directive nodes in ModuleDeclaration:
Use Name instead of Type
Change-Id: I06aa858a3b95d598ff0a0fa245ba876720902f2a
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 e0ddc00..c389b68 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
@@ -179,20 +179,20 @@
assertTrue(modules.size() == 2);
checkSourceRange(modules.get(0), "third", content);
checkSourceRange(modules.get(1), "fourth", content);
-
+
UsesDirective u = (UsesDirective) stmts.get(2);
checkSourceRange(u, "uses NewType;", content);
- Type type = u.getType();
- checkSourceRange(type, "NewType", content);
-
+ Name name = u.getName();
+ checkSourceRange(name, "NewType", content);
+
ProvidesDirective p = (ProvidesDirective) stmts.get(3);
checkSourceRange(p, "provides pack22.I22 with pack11.packinternal.Z11;", content);
- type = p.getType();
- checkSourceRange(type, "pack22.I22", content);
- List<Type> impls = p.implementations();
+ name = p.getName();
+ checkSourceRange(name, "pack22.I22", content);
+ List<Name> impls = p.implementations();
assertTrue(impls.size() > 0);
- type = impls.get(0);
- checkSourceRange(type, "pack11.packinternal.Z11", content);
+ name = impls.get(0);
+ checkSourceRange(name, "pack11.packinternal.Z11", content);
}
public void testBug512023_0001() throws Exception {
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingModuleDeclarationTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingModuleDeclarationTest.java
index d697bb7..37941e9 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingModuleDeclarationTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingModuleDeclarationTest.java
@@ -113,8 +113,7 @@
// uses MyType -> uses MyNewType;
UsesDirective usesStatement = (UsesDirective) moduleStatements.get(index++);
Name newName = ast.newSimpleName("MyNewType");
- SimpleType type = ast.newSimpleType(newName);
- rewrite.replace(usesStatement.getType(), type, null);
+ rewrite.replace(usesStatement.getName(), newName, null);
// uses Type.Remove - remove the uses
listRewrite.remove(moduleStatements.get(index++), null);
@@ -122,24 +121,20 @@
// uses MyNewFoundType - add the uses
usesStatement = ast.newUsesDirective();
newName = ast.newSimpleName("MyNewFoundType");
- type = ast.newSimpleType(newName);
- usesStatement.setType(type);
+ usesStatement.setName(newName);
listRewrite.insertLast(usesStatement, null);
}
{
// provides pack22.I22 with pack11.packinternal.Z11 -> provides pack22.INew22 with pack11.packinternal.NewZ11, pack11.Y11
ProvidesDirective providesStatement = (ProvidesDirective) moduleStatements.get(index++);
Name newName = ast.newName("pack22.INew22");
- SimpleType type = ast.newSimpleType(newName);
- rewrite.replace(providesStatement.getType(), type, null);
+ rewrite.replace(providesStatement.getName(), newName, null);
newName = ast.newName("pack11.packinternal.NewZ11");
- type = ast.newSimpleType(newName);
ListRewrite pListRewrite = rewrite.getListRewrite(providesStatement, ProvidesDirective.IMPLEMENTATIONS_PROPERTY);
- pListRewrite.replace((ASTNode) providesStatement.implementations().get(0), type ,null);
+ pListRewrite.replace((ASTNode) providesStatement.implementations().get(0), newName ,null);
newName = ast.newName("pack11.Y11");
- type = ast.newSimpleType(newName);
- pListRewrite.insertLast(type, null);
+ pListRewrite.insertLast(newName, null);
// provides pack23.I23 with pack11.Z23, pack12.ZZ23 -> provides pack23.I23 with pack12.ZZ23
providesStatement = (ProvidesDirective) moduleStatements.get(index++);
pListRewrite = rewrite.getListRewrite(providesStatement, ProvidesDirective.IMPLEMENTATIONS_PROPERTY);
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 e2b0858..3a713e6 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
@@ -3347,17 +3347,18 @@
org.eclipse.jdt.internal.compiler.ast.UsesStatement usesStatement = moduleDeclaration.uses[i];
UsesDirective stmt = new UsesDirective(this.ast);
TypeReference usesRef = usesStatement.serviceInterface;
- stmt.setType(convertType(usesRef));
+ Name name = convert(usesRef);
+ stmt.setName(name);
stmt.setSourceRange(usesStatement.declarationSourceStart, usesStatement.declarationSourceEnd - usesStatement.declarationSourceStart + 1);
tSet.add(stmt);
}
for (int i = 0; i < moduleDeclaration.servicesCount; ++i) {
org.eclipse.jdt.internal.compiler.ast.ProvidesStatement pStmt = moduleDeclaration.services[i];
ProvidesDirective stmt = new ProvidesDirective(this.ast);
- stmt.setType(convertType(pStmt.serviceInterface));
+ stmt.setName(convert(pStmt.serviceInterface));
TypeReference[] impls = pStmt.implementations;
for (TypeReference impl : impls) {
- stmt.implementations().add(convertType(impl));
+ stmt.implementations().add(convert(impl));
}
stmt.setSourceRange(pStmt.declarationSourceStart, pStmt.declarationSourceEnd - pStmt.declarationSourceStart + 1);
tSet.add(stmt);
@@ -3366,7 +3367,7 @@
if (this.resolveBindings) {
recordNodes(moduleDecl, moduleDeclaration);
recordNodes(moduleName, moduleDeclaration);
- // moduleDecl.resolveBinding(); TODO: Implement resolveBinding
+ moduleDecl.resolveBinding();
}
stmts.addAll(tSet);
return moduleDecl;
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTMatcher.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTMatcher.java
index ec48794..5f142fa 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTMatcher.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTMatcher.java
@@ -1907,7 +1907,7 @@
}
ProvidesDirective o = (ProvidesDirective) other;
return (
- safeSubtreeMatch(node.getType(), o.getType())
+ safeSubtreeMatch(node.getName(), o.getName())
&& safeSubtreeListMatch(node.implementations(), o.implementations()));
}
@@ -2628,7 +2628,7 @@
return false;
}
UsesDirective o = (UsesDirective) other;
- return safeSubtreeMatch(node.getType(), o.getType());
+ return safeSubtreeMatch(node.getName(), o.getName());
}
/**
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ProvidesDirective.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ProvidesDirective.java
index 479ee2e..6ccd591 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ProvidesDirective.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ProvidesDirective.java
@@ -32,16 +32,16 @@
public class ProvidesDirective extends ModuleDirective {
/**
- * The "interface type" structural property of this node type (child type: {@link Type}).
+ * The "interface name" structural property of this node type (child type: {@link Name}).
*/
- public static final ChildPropertyDescriptor TYPE_PROPERTY =
- new ChildPropertyDescriptor(ProvidesDirective.class, "type", Type.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$
+ public static final ChildPropertyDescriptor SERVICES_PROPERTY =
+ new ChildPropertyDescriptor(ProvidesDirective.class, "name", Name.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$
/**
- * The "implementation type" structural property of this node type (element type: {@link Type}).
+ * The "implementations name" structural property of this node type (element type: {@link Name}).
*/
public static final ChildListPropertyDescriptor IMPLEMENTATIONS_PROPERTY =
- new ChildListPropertyDescriptor(ProvidesDirective.class, "implementations", Type.class, NO_CYCLE_RISK); //$NON-NLS-1$
+ new ChildListPropertyDescriptor(ProvidesDirective.class, "implementations", Name.class, NO_CYCLE_RISK); //$NON-NLS-1$
/**
* A list of property descriptors (element type:
@@ -53,7 +53,7 @@
static {
List properyList = new ArrayList(3);
createPropertyList(ProvidesDirective.class, properyList);
- addProperty(TYPE_PROPERTY, properyList);
+ addProperty(SERVICES_PROPERTY, properyList);
addProperty(IMPLEMENTATIONS_PROPERTY, properyList);
PROPERTY_DESCRIPTORS_9_0 = reapPropertyList(properyList);
}
@@ -76,10 +76,10 @@
* The interface name; lazily initialized; defaults to a unspecified,
* legal Java identifier.
*/
- private Type type = null;
+ private Name name = null;
/**
- * The implementation names
+ * The implementations names
* (element type: {@link Name}).
* Defaults to an empty list.
*/
@@ -109,11 +109,11 @@
@Override
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
- if (property == TYPE_PROPERTY) {
+ if (property == SERVICES_PROPERTY) {
if (get) {
- return getType();
+ return getName();
} else {
- setType((Type) child);
+ setName((Name) child);
return null;
}
}
@@ -140,7 +140,7 @@
ASTNode clone0(AST target) {
ProvidesDirective result = new ProvidesDirective(target);
result.setSourceRange(getStartPosition(), getLength());
- result.setType((Type) getType().clone(target));
+ result.setName((Name) getName().clone(target));
result.implementations().addAll(ASTNode.copySubtrees(target, implementations()));
return result;
}
@@ -155,7 +155,7 @@
void accept0(ASTVisitor visitor) {
boolean visitChildren = visitor.visit(this);
if (visitChildren) {
- acceptChild(visitor, getType());
+ acceptChild(visitor, getName());
acceptChildren(visitor, this.implementations);
}
visitor.endVisit(this);
@@ -163,42 +163,43 @@
/**
- * Returns the type name in this directive.
+ * Returns the name of the service in this directive.
*
- * @return the type name
+ * @return the services name
*/
- public Type getType() {
- if (this.type == null) {
+ public Name getName() {
+ if (this.name == null) {
// lazy init must be thread-safe for readers
synchronized (this) {
- if (this.type == null) {
+ if (this.name == null) {
preLazyInit();
- this.type =this.ast.newPrimitiveType(PrimitiveType.INT);
- postLazyInit(this.type, TYPE_PROPERTY);
+ this.name = this.ast.newQualifiedName(
+ new SimpleName(this.ast), new SimpleName(this.ast));
+ postLazyInit(this.name, SERVICES_PROPERTY);
}
}
}
- return this.type;
+ return this.name;
}
/**
- * Sets the target module name in exports declaration to the given name.
+ * Sets the name of the service.
*
- * @param type the new target module name
+ * @param name the new service name
* @exception IllegalArgumentException if:
* <ul>
* <li>the node belongs to a different AST</li>
* <li>the node already has a parent</li>
* </ul>
*/
- public void setType(Type type) {
- if (type == null) {
+ public void setName(Name name) {
+ if (name == null) {
throw new IllegalArgumentException();
}
- ASTNode oldChild = this.type;
- preReplaceChild(oldChild, type, TYPE_PROPERTY);
- this.type = type;
- postReplaceChild(oldChild, type, TYPE_PROPERTY);
+ ASTNode oldChild = this.name;
+ preReplaceChild(oldChild, name, SERVICES_PROPERTY);
+ this.name = name;
+ postReplaceChild(oldChild, name, SERVICES_PROPERTY);
}
/**
@@ -220,7 +221,7 @@
int treeSize() {
return
memSize()
- + (this.type == null ? 0 : getType().treeSize())
+ + (this.name == null ? 0 : getName().treeSize())
+ this.implementations.listSize();
}
}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/UsesDirective.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/UsesDirective.java
index d699cdb..373a578 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/UsesDirective.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/UsesDirective.java
@@ -24,7 +24,7 @@
* </pre>
*
* @since 3.13 BETA_JAVA9
- *
+ *
* @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
*/
@@ -32,10 +32,10 @@
public class UsesDirective extends ModuleDirective {
/**
- * The "type" structural property of this node type (child type: {@link Name}).
+ * The "name" structural property of this node type (child type: {@link Name}).
*/
- public static final ChildPropertyDescriptor TYPE_PROPERTY =
- new ChildPropertyDescriptor(UsesDirective.class, "type", Type.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$
+ public static final ChildPropertyDescriptor NAME_PROPERTY =
+ new ChildPropertyDescriptor(UsesDirective.class, "name", Name.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$
/**
* A list of property descriptors (element type:
@@ -47,7 +47,7 @@
static {
List properyList = new ArrayList(2);
createPropertyList(UsesDirective.class, properyList);
- addProperty(TYPE_PROPERTY, properyList);
+ addProperty(NAME_PROPERTY, properyList);
PROPERTY_DESCRIPTORS_9_0 = reapPropertyList(properyList);
}
@@ -69,7 +69,7 @@
* The module name; lazily initialized; defaults to a unspecified,
* legal Java identifier.
*/
- private Type type = null;
+ private Name name = null;
/**
* Creates a new AST node for an uses directive owned by the
@@ -94,11 +94,11 @@
@Override
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
- if (property == TYPE_PROPERTY) {
+ if (property == NAME_PROPERTY) {
if (get) {
- return getType();
+ return getName();
} else {
- setType((Type) child);
+ setName((Name) child);
return null;
}
}
@@ -116,7 +116,7 @@
ASTNode clone0(AST target) {
UsesDirective result = new UsesDirective(target);
result.setSourceRange(getStartPosition(), getLength());
- result.setType((Type) getType().clone(target));
+ result.setName((Name) getName().clone(target));
return result;
}
@@ -130,49 +130,50 @@
void accept0(ASTVisitor visitor) {
boolean visitChildren = visitor.visit(this);
if (visitChildren) {
- acceptChild(visitor, getType());
+ acceptChild(visitor, getName());
}
visitor.endVisit(this);
}
/**
- * Returns the type in this directive
+ * Returns the name in this directive
*
- * @return the type
+ * @return the name
*/
- public Type getType() {
- if (this.type == null) {
+ public Name getName() {
+ if (this.name == null) {
// lazy init must be thread-safe for readers
synchronized (this) {
- if (this.type == null) {
+ if (this.name == null) {
preLazyInit();
- this.type = this.ast.newPrimitiveType(PrimitiveType.INT);
- postLazyInit(this.type, TYPE_PROPERTY);
+ this.name = this.ast.newQualifiedName(
+ new SimpleName(this.ast), new SimpleName(this.ast));
+ postLazyInit(this.name, NAME_PROPERTY);
}
}
}
- return this.type;
+ return this.name;
}
/**
- * Sets the type in uses directive
+ * Sets the name in uses directive
*
- * @param type the new type in uses
+ * @param name the new name in uses
* @exception IllegalArgumentException if:
* <ul>
* <li>the node belongs to a different AST</li>
* <li>the node already has a parent</li>
* </ul>
*/
- public void setType(Type type) {
- if (type == null) {
+ public void setName(Name name) {
+ if (name == null) {
throw new IllegalArgumentException();
}
- ASTNode oldChild = this.type;
- preReplaceChild(oldChild, type, TYPE_PROPERTY);
- this.type = type;
- postReplaceChild(oldChild, type, TYPE_PROPERTY);
+ ASTNode oldChild = this.name;
+ preReplaceChild(oldChild, name, NAME_PROPERTY);
+ this.name = name;
+ postReplaceChild(oldChild, name, NAME_PROPERTY);
}
@Override
@@ -184,7 +185,7 @@
int treeSize() {
return
memSize()
- + (this.type == null ? 0 : getType().treeSize());
+ + (this.name == null ? 0 : getName().treeSize());
}
}
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java
index c366ffe..c3f0dbb 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java
@@ -1402,7 +1402,7 @@
printIndent();
this.buffer.append("provides");//$NON-NLS-1$
this.buffer.append(" ");//$NON-NLS-1$
- node.getType().accept(this);
+ node.getName().accept(this);
printTypes(node.implementations(), "with"); //$NON-NLS-1$
this.buffer.append(";\n");//$NON-NLS-1$
return false;
@@ -1945,7 +1945,7 @@
printIndent();
this.buffer.append("uses");//$NON-NLS-1$
this.buffer.append(" ");//$NON-NLS-1$
- node.getType().accept(this);
+ node.getName().accept(this);
this.buffer.append(";\n");//$NON-NLS-1$
return false;
}
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java
index e1925ab..b504cc2 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java
@@ -3294,7 +3294,7 @@
if (!hasChildrenChanges(node)) {
return doVisitUnchangedChildren(node);
}
- int pos = rewriteRequiredNode(node, ProvidesDirective.TYPE_PROPERTY);
+ int pos = rewriteRequiredNode(node, ProvidesDirective.SERVICES_PROPERTY);
pos= rewriteNodeList(node, ProvidesDirective.IMPLEMENTATIONS_PROPERTY, pos, " with ", ", "); //$NON-NLS-1$ //$NON-NLS-2$
return false;
}
@@ -3769,7 +3769,7 @@
if (!hasChildrenChanges(node)) {
return doVisitUnchangedChildren(node);
}
- rewriteRequiredNode(node,UsesDirective.TYPE_PROPERTY);
+ rewriteRequiredNode(node,UsesDirective.NAME_PROPERTY);
return false;
}
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java
index 8510d19..3a080f5 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java
@@ -901,7 +901,7 @@
@Override
public boolean visit(ProvidesDirective node) {
this.result.append("provides "); //$NON-NLS-1$
- getChildNode(node, ProvidesDirective.TYPE_PROPERTY).accept(this);
+ getChildNode(node, ProvidesDirective.SERVICES_PROPERTY).accept(this);
this.result.append(" with "); //$NON-NLS-1$
visitList(node, ProvidesDirective.IMPLEMENTATIONS_PROPERTY, Util.EMPTY_STRING, Util.COMMA_SEPARATOR, Util.EMPTY_STRING);
this.result.append(';');
@@ -1214,11 +1214,11 @@
visitList(node, UnionType.TYPES_PROPERTY, " | ", Util.EMPTY_STRING, Util.EMPTY_STRING); //$NON-NLS-1$
return false;
}
-
+
@Override
public boolean visit(UsesDirective node) {
this.result.append("uses "); //$NON-NLS-1$
- getChildNode(node, UsesDirective.TYPE_PROPERTY).accept(this);
+ getChildNode(node, UsesDirective.NAME_PROPERTY).accept(this);
this.result.append(';');
return false;
}