下面列出了org.eclipse.jdt.core.dom.ASTNode#getProperty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public ASTNode copySubtree(Object o) {
ASTNode n = (ASTNode)o;
MethodTmp m = null;
if(tmpTranslator != null) {
m = getMethodTmp(n);
if(m != null) {
n.setProperty(TYPEBIND_METHOD_TMP, null);
}
n = tmpTranslator.translate(n);
}
ASTNode copy = ASTNode.copySubtree(ast, n);
Object t = n.getProperty(TYPEBIND_PROP);
if(t != null) copy.setProperty(TYPEBIND_PROP, t);
if(m != null) copy.setProperty(TYPEBIND_METHOD_TMP, m);
// Object t2 = n.getProperty(TYPEBIND_METHOD_TMP);
// if(t2 != null) copy.setProperty(TYPEBIND_METHOD_TMP, t2);
return copy;
}
public ASTNode copy(ASTNode node) {
// copyStack.add(node);
node.accept(this);
// ASTNode n = copyStack.remove(copyStack.size()-1);
ASTNode n = getReplace(node);
if(n != node) {
err("Different");
if(n.getProperty(TYPEBIND_PROP) == null)
throw new CompilerError("Differnet null type: " + node);
return n;
//throw new CompilerError("different");
}
return copySubtree(node);
}
public ASTNode translate(ASTNode node) {
// copyStack.add(node);
node.accept(this);
// ASTNode n = copyStack.remove(copyStack.size()-1);
ASTNode n = getReplace(node);
if(n != node) {
err("Different");
if(n.getProperty(TYPEBIND_PROP) == null)
throw new CompilerError("Differnet null type");
return n;
//throw new CompilerError("different");
}
return node;
}
private void markAstN(ASTNode node) {
if (node.getProperty(PROPERTY_STATUS) == null) {
node.setProperty(PROPERTY_STATUS, ChangeKind.ADDED);
numOfChanges++;
numOfUnmaps++;
if (!(node instanceof SimpleName))
numOfNonNameUnMaps++;
}
ArrayList<ASTNode> children = tree.get(node);
for (ASTNode child : children)
markAstN(child);
}
public void replace(ASTNode old, ASTNode neww) {
// if(!copyStack.isEmpty()) {
// if(copyStack.get(copyStack.size()-1) == old) {
// copyStack.set(copyStack.size()-1, neww);
// Log.err("COPY STACK REPLACE");
// Object oldProp = old.getProperty(TYPEBIND_PROP);
// if(oldProp != null && neww.getProperty(TYPEBIND_PROP) == null) {
// Log.err(" copy old prop");
// neww.setProperty(TYPEBIND_PROP, oldProp);
// }
// Object oldProp2 = old.getProperty(TYPEBIND_METHOD_TMP);
// if(oldProp2 != null && neww.getProperty(TYPEBIND_METHOD_TMP) == null) {
// Log.err(" copy old prop2");
// neww.setProperty(TYPEBIND_METHOD_TMP, oldProp2);
// }
// return;
// }
// }
old.setProperty(IS_REPLACE, neww);
ASTNode parent = old.getParent();
StructuralPropertyDescriptor desc = old.getLocationInParent();
if(desc instanceof ChildListPropertyDescriptor) {
ChildListPropertyDescriptor ch = (ChildListPropertyDescriptor)desc;
List<ASTNode> list = (List)parent.getStructuralProperty(ch);
int index = list.indexOf(old);
list.set(index, neww);
}
else {
if(parent instanceof QualifiedName &&
QualifiedName.QUALIFIER_PROPERTY.getId().equals(desc.getId()) &&
!(neww instanceof SimpleName)) {
if(!(neww instanceof Expression))throw new IllegalArgumentException();
//QualifiedName has to be changed to FieldAccess
// throw new IllegalArgumentException("qual name expression");
FieldAccess fa = ast.newFieldAccess();
fa.setExpression((Expression)neww);
fa.setName((SimpleName)copySubtreeIfHasParent(((QualifiedName)parent).getName()));
// for(Map.Entry ee : (Set<Map.Entry>)parent.properties().entrySet()) {
// Log.err("ee " + ee.getKey());
// }
if(parent.getProperty(TYPEBIND_PROP) == null)
fa.setProperty(TYPEBIND_PROP, parent.getProperty(TYPEBIND_PROP));
replace(parent, fa);
return;
}
parent.setStructuralProperty(desc, neww);
}
}
public MethodTmp getMethodTmp(ASTNode n) {
Object o = n.getProperty(TYPEBIND_METHOD_TMP);
if(o != null) return (MethodTmp)o;
return null;
}
private boolean isUnchanged(ArrayList<ASTNode> children) {
for (ASTNode child : children)
if ((ChangeKind) child.getProperty(PROPERTY_STATUS) != ChangeKind.UNCHANGED)
return false;
return true;
}
boolean checkMalformedNodes(ASTNode node) {
Object property = node.getProperty(CONTAINS_MALFORMED_NODES);
if (property == null) return false;
return ((Boolean) property).booleanValue();
}
public final boolean isRangeCopyPlaceholder(ASTNode node) {
return node.getProperty(INTERNAL_PLACEHOLDER_PROPERTY) != null;
}
/**
* @param node the ASTNode
* @return the {@link ConstraintVariable2} associated with the node, or <code>null</code>
*/
protected static ConstraintVariable2 getConstraintVariable(ASTNode node) {
return (ConstraintVariable2) node.getProperty(CV_PROP);
}
public boolean isReplace(ASTNode n) { return n.getProperty(IS_REPLACE) != null;}