List of usage examples for org.eclipse.jdt.core.dom ASTNode setProperty
public final void setProperty(String propertyName, Object data)
null
to clear it. From source file:ca.uvic.chisel.javasketch.internal.ast.groups.ASTLoopGroupCalculator.java
License:Open Source License
public static ASTMessageGroupingTree calculateGroups(IActivation activationElement) { //find the AST and define the groups IActivation activation = (IActivation) activationElement; IJavaElement element;// w ww. jav a2 s.com try { HashMap<IOriginMessage, ASTNode> mappings = new HashMap<IOriginMessage, ASTNode>(); element = JavaSearchUtils.findElement(activation, new NullProgressMonitor()); if (element instanceof IMethod) { IMethod method = (IMethod) element; IDocument document = getDocumentFor(method); ASTNode root = ASTUTils.getASTFor(method.getDeclaringType()); if (root != null) { MethodDeclaration methodDeclaration = ASTUTils.findMethodDeclaration(root, method); if (methodDeclaration != null) { try { List<IOriginMessage> children = activation.getOriginMessages(); //a list of messages that aren't associated with an AST node: //they are pre-cursors to something else that must occur due to //reflection. List<IOriginMessage> unassociated = new LinkedList<IOriginMessage>(); for (IOriginMessage child : children) { ASTMessageFinder finder; if (child instanceof ICall) { finder = new ASTMessageFinder((ICall) child, document); } else if (child instanceof IReply) { finder = new ASTMessageFinder((IReply) child, document); } else { return null; } methodDeclaration.accept(finder); ASTNode messageNode = finder.getNode(); if (messageNode == null) { if (child instanceof IReply) { ASTMessageGroupingTree methodGroup = getGrouping(methodDeclaration); if (methodGroup != null) { methodGroup.addMessage(child, unassociated); unassociated.clear(); } //sometimes returns don't have line numbers continue; } unassociated.add((IOriginMessage) child); continue; } mappings.put((IOriginMessage) child, messageNode); ASTNode blockNode = findBlockParent(messageNode); if (blockNode == null) return null; ASTMessageGroupingTree grouping = getGrouping(blockNode); if (grouping == null) return null; IOriginMessage lastMessage = grouping.getLastMessage(); ASTNode lastNode = mappings.get(lastMessage); ASTNode thisNode = mappings.get(child); if (grouping.getLastCodeLine() <= child.codeLine()) { //if the called methods are different, then //assume that they are different methods on the //same line of code. Otherwise, it is a loop if (lastNode != null && thisNode != null) { //first, check to see if the last node is a child of this node //because if it is, than the evaluation will be opposite if (isChild(lastNode, thisNode)) { // if (lastNode.getStartPosition() < thisNode.getStartPosition()) { // grouping = resetGrouping(blockNode); // } } else if (isChild(thisNode, lastNode)) { if (lastNode.getStartPosition() <= thisNode.getStartPosition()) { grouping = resetGrouping(blockNode); } } else if (lastNode.getStartPosition() >= thisNode.getStartPosition()) { grouping = resetGrouping(blockNode); } } else if (similarMessages((IOriginMessage) grouping.getLastMessage(), (IOriginMessage) child)) { grouping = resetGrouping(blockNode); } } else if (grouping.getLastCodeLine() > child.codeLine()) { if (grouping.getNode() != methodDeclaration) { if (lastNode != null && thisNode != null) { if (!isChild(lastNode, thisNode)) { grouping = resetGrouping(blockNode); } } else { grouping = resetGrouping(blockNode); } } } grouping.addMessage(child, unassociated); unassociated.clear(); } //return the node left on the method declaration ASTMessageGroupingTree tree = (ASTMessageGroupingTree) methodDeclaration .getProperty(CURRENT_GROUPING); return tree; } finally { //make sure to clean up if (methodDeclaration != null) { methodDeclaration.accept(new GenericVisitor() { /* (non-Javadoc) * @see ca.uvic.chisel.javasketch.internal.ast.GenericVisitor#visitNode(org.eclipse.jdt.core.dom.ASTNode) */ @Override protected boolean visitNode(ASTNode node) { node.setProperty(CURRENT_GROUPING, null); return true; } }); } } } } } } catch (InterruptedException e) { //ignore and continue } catch (CoreException e) { SketchPlugin.getDefault().log(e); } return null; }
From source file:ca.uvic.chisel.javasketch.internal.ast.groups.ASTLoopGroupCalculator.java
License:Open Source License
/** * @param blockNode/*from ww w .ja v a 2 s . c o m*/ * @param child * @param i * @param groupings * @return */ private static ASTMessageGroupingTree getGrouping(ASTNode blockNode) { ASTMessageGroupingTree currentGrouping = (ASTMessageGroupingTree) blockNode.getProperty(CURRENT_GROUPING); if (currentGrouping == null) { //first: if this blockNode is a method declaration, create a root group if (blockNode.getNodeType() == ASTNode.METHOD_DECLARATION) { currentGrouping = new ASTMessageGroupingTree(null, blockNode); blockNode.setProperty(CURRENT_GROUPING, currentGrouping); return currentGrouping; } else { ASTMessageGroupingTree parentGrouping = getGrouping(findBlockParent(blockNode)); currentGrouping = new ASTMessageGroupingTree(parentGrouping, blockNode); blockNode.setProperty(CURRENT_GROUPING, currentGrouping); return currentGrouping; } // // ASTMessageGroupingTree parentGrouping = // //create a new grouping for this node and all of its parents. // LinkedList<IMessageGrouping> created = new LinkedList<IMessageGrouping>(); // currentGrouping = new ASTMessageGroupingTree(activation, blockNode); // currentGrouping.setStartIndex(i); // currentGrouping.setEndIndex(i); // blockNode.setProperty(CURRENT_GROUPING, currentGrouping); // updateGrouping(currentGrouping); // created.addFirst(currentGrouping); // ASTNode parent = findBlockParent(blockNode); // while (parent != null) { // ASTMessageGroupingTree newGrouping = (ASTMessageGroupingTree) parent.getProperty(CURRENT_GROUPING); // if (newGrouping != null) { // //update it to include the new index // if (newGrouping.getEndIndex() < i) { // newGrouping.setEndIndex(i); // } // } else { // newGrouping = new ASTMessageGroupingTree(activation, parent); // parent.setProperty(CURRENT_GROUPING, newGrouping); // newGrouping.setStartIndex(i); // newGrouping.setEndIndex(i); // updateGrouping(newGrouping); // created.addFirst(newGrouping); // } // parent = findBlockParent(parent); // } // groupings.addAll(created); } return currentGrouping; }
From source file:ca.uvic.chisel.javasketch.internal.ast.groups.ASTLoopGroupCalculator.java
License:Open Source License
/** * Clears the current grouping for the block node, and all of its children. * @param blockNode/*w w w . jav a2 s. c o m*/ * @param child * @param i * @param groupings * @return */ private static ASTMessageGroupingTree resetGrouping(ASTNode blockNode) { ASTNode loop = findLoopingParent(blockNode); if (loop != null) { ASTMessageGroupingTree loopGroup = (ASTMessageGroupingTree) loop.getProperty(CURRENT_GROUPING); int currentIteration = loopGroup.getIteration(); //clear the children loop.accept(new GenericVisitor() { /* (non-Javadoc) * @see ca.uvic.chisel.javasketch.internal.ast.groups.GenericVisitor#visitNode(org.eclipse.jdt.core.dom.ASTNode) */ @Override protected boolean visitNode(ASTNode node) { node.setProperty(CURRENT_GROUPING, null); return true; } }); //create a new group for the loop ASTMessageGroupingTree newLoop = getGrouping(loop); newLoop.setIteration(currentIteration + 1); return getGrouping(blockNode); } return (ASTMessageGroupingTree) blockNode.getProperty(CURRENT_GROUPING); }
From source file:org.eclipse.wb.core.eval.ExecutionFlowUtils.java
License:Open Source License
/** * When variable {@link ASTNode} is dangling, we will not able to visit it on execution flow, so * have to clear cached information manually. * /* w w w . ja va 2 s . c om*/ * @return <code>true</code> if node is dangling, so no need to visit execution flow. */ private static boolean clearCachedValuesForDanglingNode(ASTNode variable) { if (isDanglingNode(variable)) { for (Field field : ExecutionFlowUtils.class.getDeclaredFields()) { String fieldName = field.getName(); if (fieldName.startsWith("KEY_")) { variable.setProperty(fieldName, null); } } return true; } return false; }
From source file:org.eclipse.wb.core.eval.ExecutionFlowUtils2.java
License:Open Source License
public static void ensureValues(ExecutionFlowDescription flowDescription) { ASTNode rootNode = flowDescription.getCompilationUnit(); long stampAST = rootNode.getAST().modificationCount(); long stampFlow = flowDescription.modificationCount(); Long cache_stampAST = (Long) rootNode.getProperty(STAMP_AST); Long cache_stampFlow = (Long) rootNode.getProperty(STAMP_FLOW); if (cache_stampAST == null || cache_stampAST.longValue() != stampAST || cache_stampFlow == null || cache_stampFlow.longValue() != stampFlow) { rootNode.setProperty(STAMP_AST, stampAST); rootNode.setProperty(STAMP_FLOW, stampFlow); trackValues(flowDescription, rootNode); }//www . j a va 2 s. c om }
From source file:org.eclipse.wb.internal.core.model.creation.ThisCreationSupport.java
License:Open Source License
/** * @return <code>true</code> if currently invoked {@link Method} was from * {@link SuperMethodInvocation}. Removes this flag. *///w w w . j av a2 s . c o m private boolean isSuperMethodInvocation() { ASTNode root = m_constructor.getRoot(); try { return root.getProperty(InvocationEvaluator.SUPER_MI_KEY) == Boolean.TRUE; } finally { root.setProperty(InvocationEvaluator.SUPER_MI_KEY, null); } }
From source file:org.eclipse.wb.internal.core.model.util.PlaceholderUtils.java
License:Open Source License
/** * Removes information associated with given {@link ASTNode}. *//*ww w. jav a 2 s . c o m*/ public static void clear(ASTNode node) { node.setProperty(KEY_EXCEPTIONS, null); node.setProperty(KEY_PLACEHOLDER, null); }
From source file:org.eclipse.wb.internal.core.model.util.PlaceholderUtils.java
License:Open Source License
/** * Adds new exception associated with given {@link ASTNode}. */// ww w . jav a2 s .c om public static void addException(ASTNode node, Throwable e) { // prepare List for exceptions List<Throwable> exceptions = getExceptions0(node); if (exceptions == null) { exceptions = Lists.newArrayList(); node.setProperty(KEY_EXCEPTIONS, exceptions); } // add new exception exceptions.add(e); }
From source file:org.eclipse.wb.internal.core.model.util.PlaceholderUtils.java
License:Open Source License
/** * Marks that given {@link ASTNode} was evaluated as placeholder. */// w w w. j a v a2 s .co m public static void markPlaceholder(ASTNode node) { node.setProperty(KEY_PLACEHOLDER, Boolean.TRUE); }
From source file:org.eclipse.wb.internal.core.utils.ast.AstEditor.java
License:Open Source License
/** * Replaces {@link IMethodBinding} in of existing {@link ASTNode} by using {@link IMethodBinding} * from equivalent parsed {@link ASTNode}. *//*from ww w. j a v a 2 s.c o m*/ private void replaceMethodBinding(ASTNode oldNode, ASTNode parsedNode) { IMethodBinding parsedBinding = (IMethodBinding) parsedNode.getProperty(AstParser.KEY_METHOD_BINDING); Assert.isTrue(parsedBinding instanceof DesignerMethodBinding); oldNode.setProperty(AstParser.KEY_METHOD_BINDING, parsedBinding); }