org.eclipse.jdt.core.dom.ASTNode#setProperty ( )源码实例Demo

下面列出了org.eclipse.jdt.core.dom.ASTNode#setProperty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: junion   文件: BaseTranslator.java
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;
	}
 
/**
 * End of visit the variable declaration fragment list.
 *
 * @param fragments the fragments (element type: <code>VariableDeclarationFragment</code>)
 * @param type the type of the fragments
 * @param parent the parent of the fragment list
 */
private void endVisit(final List<VariableDeclarationFragment> fragments, final Type type, final ASTNode parent) {
	final ConstraintVariable2 ancestor= (ConstraintVariable2) type.getProperty(PROPERTY_CONSTRAINT_VARIABLE);
	if (ancestor != null) {
		IVariableBinding binding= null;
		ConstraintVariable2 descendant= null;
		VariableDeclarationFragment fragment= null;
		for (int index= 0; index < fragments.size(); index++) {
			fragment= fragments.get(index);
			descendant= (ConstraintVariable2) fragment.getProperty(PROPERTY_CONSTRAINT_VARIABLE);
			if (descendant != null)
				fModel.createSubtypeConstraint(descendant, ancestor);
			binding= fragment.resolveBinding();
			if (binding != null) {
				descendant= fModel.createVariableVariable(binding);
				if (descendant != null)
					fModel.createEqualityConstraint(ancestor, descendant);
			}
		}
		parent.setProperty(PROPERTY_CONSTRAINT_VARIABLE, ancestor);
	}
}
 
源代码3 项目: compiler   文件: TreedBuilder.java
@Override
public void preVisit(ASTNode node) {
	node.setProperty(PROPERTY_INDEX, index++);
	tree.put(node, new ArrayList<ASTNode>());
	if (node != root) {
		ASTNode p = node.getParent();
		treeDepth.put(node, treeDepth.get(p) + 1);
	}
}
 
源代码4 项目: compiler   文件: TreedMapper.java
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 final CopySourceInfo createRangeCopy(ASTNode parent, StructuralPropertyDescriptor childProperty, ASTNode first, ASTNode last, boolean isMove, ASTNode internalPlaceholder, ASTNode replacingNode, TextEditGroup editGroup) {
	CopySourceInfo copyInfo= createCopySourceInfo(null, internalPlaceholder, isMove);
	internalPlaceholder.setProperty(INTERNAL_PLACEHOLDER_PROPERTY, internalPlaceholder);

	NodeRangeInfo copyRangeInfo= new NodeRangeInfo(parent, childProperty, first, last, copyInfo, replacingNode, editGroup);

	ListRewriteEvent listEvent= getListEvent(parent, childProperty, true);

	int indexFirst= listEvent.getIndex(first, ListRewriteEvent.OLD);
	if (indexFirst == -1) {
		throw new IllegalArgumentException("Start node is not a original child of the given list"); //$NON-NLS-1$
	}
	int indexLast= listEvent.getIndex(last, ListRewriteEvent.OLD);
	if (indexLast == -1) {
		throw new IllegalArgumentException("End node is not a original child of the given list"); //$NON-NLS-1$
	}

	if (indexFirst > indexLast) {
		throw new IllegalArgumentException("Start node must be before end node"); //$NON-NLS-1$
	}

	if (this.nodeRangeInfos == null) {
		this.nodeRangeInfos= new HashMap();
	}
	PropertyLocation loc= new PropertyLocation(parent, childProperty);
	List innerList= (List) this.nodeRangeInfos.get(loc);
	if (innerList == null) {
		innerList= new ArrayList(2);
		this.nodeRangeInfos.put(loc, innerList);
	} else {
		assertNoOverlap(listEvent, indexFirst, indexLast, innerList);
	}
	innerList.add(copyRangeInfo);


	return copyInfo;
}
 
源代码6 项目: junion   文件: BaseTranslator.java
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);
		}		
	}
 
源代码7 项目: compiler   文件: TreedMapper.java
private void markChanges(ArrayList<ASTNode> nodes, ArrayList<ASTNode> mappedNodes) {
	int len = nodes.size(), lenN = mappedNodes.size();
	int[][] d = new int[2][lenN + 1];
	char[][] p = new char[len + 1][lenN + 1];
	d[1][0] = 0;
	for (int j = 1; j <= lenN; j++)
		d[1][j] = 0;
	for (int i = 1; i <= len; i++) {
		ASTNode node = nodes.get(i - 1);
		HashMap<ASTNode, Double> maps = treeMap.get(node);
		for (int j = 0; j <= lenN; j++)
			d[0][j] = d[1][j];
		for (int j = 1; j <= lenN; j++) {
			ASTNode nodeN = mappedNodes.get(j - 1);
			if (maps.containsKey(nodeN)) {
				d[1][j] = d[0][j - 1] + 1;
				p[i][j] = 'D';
			} else if (d[0][j] >= d[1][j - 1]) {
				d[1][j] = d[0][j];
				p[i][j] = 'U';
			} else {
				d[1][j] = d[1][j - 1];
				p[i][j] = 'L';
			}
		}
	}
	int i = len, j = lenN;
	while (i > 0 && j > 0) {
		if (p[i][j] == 'D') {
			ASTNode node = nodes.get(i-1), node2 = mappedNodes.get(j-1);
			if (TreedUtils.buildLabelForVector(node) == TreedUtils.buildLabelForVector(node2)) {
				node.setProperty(PROPERTY_STATUS, ChangeKind.UNCHANGED);
				node2.setProperty(PROPERTY_STATUS, ChangeKind.UNCHANGED);
			} else {
				node.setProperty(PROPERTY_STATUS, ChangeKind.RENAMED);
				node2.setProperty(PROPERTY_STATUS, ChangeKind.RENAMED);
				numOfChanges += 2;
			}
			i--;
			j--;
		} else if (p[i][j] == 'U') {
			i--;
		}
		else {
			j--;
		}
	}
}
 
public void registerRemovedNode(ASTNode removed) {
	fHasRemovedNodes= true;
	removed.setProperty(PROPERTY_KEY, REMOVED);
}
 
public void registerRetainedNode(ASTNode retained) {
	retained.setProperty(PROPERTY_KEY, RETAINED);
}
 
/**
 * @param node the ASTNode
 * @param constraintVariable the {@link ConstraintVariable2} to be associated with node
 */
protected static void setConstraintVariable(ASTNode node, ConstraintVariable2 constraintVariable) {
	node.setProperty(CV_PROP, constraintVariable);
}