Java Code Examples for org.eclipse.jdt.core.dom.ASTNode#setProperty()

The following examples show how to use org.eclipse.jdt.core.dom.ASTNode#setProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseTranslator.java    From junion with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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;
	}
 
Example 2
Source File: SuperTypeConstraintsCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 3
Source File: TreedBuilder.java    From compiler with Apache License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example 4
Source File: TreedMapper.java    From compiler with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 5
Source File: RewriteEventStore.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example 6
Source File: BaseTranslator.java    From junion with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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);
		}		
	}
 
Example 7
Source File: TreedMapper.java    From compiler with Apache License 2.0 4 votes vote down vote up
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--;
		}
	}
}
 
Example 8
Source File: ImportRemover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void registerRemovedNode(ASTNode removed) {
	fHasRemovedNodes= true;
	removed.setProperty(PROPERTY_KEY, REMOVED);
}
 
Example 9
Source File: ImportRemover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void registerRetainedNode(ASTNode retained) {
	retained.setProperty(PROPERTY_KEY, RETAINED);
}
 
Example 10
Source File: InferTypeArgumentsConstraintCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * @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);
}