List of usage examples for org.eclipse.jdt.core.dom MethodDeclaration getProperty
public final Object getProperty(String propertyName)
null if none. 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;//from w ww . j a v a2s . c om 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:org.eclipse.wb.internal.core.model.JavaInfoEvaluationHelper.java
License:Open Source License
/** * @return the value of {@link ReturnStatement} evaluated during AST execution, or * <code>null</code> if returned {@link Expression} was not evaluated. *//*from w ww .j a va2s. c o m*/ public static Object getReturnValue(MethodDeclaration methodDeclaration) { return methodDeclaration.getProperty(KEY_RETURN_VALUE); }
From source file:org.eclipse.wb.internal.core.model.JavaInfoEvaluationHelper.java
License:Open Source License
/** * @return <code>true</code> if {@link ReturnStatement} of given {@link MethodDeclaration} should * be evaluated./* w ww . j a va 2 s . c o m*/ */ private static boolean shouldEvaluateReturnValue(MethodDeclaration methodDeclaration) { return methodDeclaration.getProperty(KEY_EVALUATE_RETURN_VALUE) == Boolean.TRUE; }
From source file:org.eclipse.wb.internal.core.utils.ast.AstNodeUtils.java
License:Open Source License
/** * @param methodDeclaration//from www. j a va 2s. c o m * the not <code>null</code> {@link MethodDeclaration} * * @return the {@link IMethodBinding} for given {@link MethodDeclaration}, may be * <code>null</code> if compilation errors. */ public static IMethodBinding getMethodBinding(MethodDeclaration methodDeclaration) { Assert.isNotNull(methodDeclaration); // try to get binding from property (copy of binding added by DesignerAST) { IMethodBinding binding = (IMethodBinding) methodDeclaration.getProperty(AstParser.KEY_METHOD_BINDING); if (binding != null) { return binding; } } // get standard binding, may be "null" (if compilation errors) return methodDeclaration.resolveBinding(); }
From source file:org.eclipse.wb.internal.core.utils.ast.AstParser.java
License:Open Source License
/** * @return the source for declaring {@link MethodDeclaration}. *///from w w w. ja v a 2 s . c om private String getMethodDeclarationSource(MethodDeclaration method) { IMethodBinding binding = AstNodeUtils.getMethodBinding(method); if (binding == null) { return ""; } // check if should be added if (method.getProperty(KEY_IGNORE_THIS_METHOD) == Boolean.TRUE) { return ""; } if (binding.isConstructor() && isMethodOfTopType(method)) { return ""; } // OK, prepare source String source = ""; // declare method { int sourceBegin = getMethodDeclarationSourceBegin(method); int sourceEnd; if (method.getBody() != null) { sourceEnd = AstNodeUtils.getSourceBegin(method.getBody()); } else { sourceEnd = AstNodeUtils.getSourceEnd(method); } source += m_editor.getSourceBeginEnd(sourceBegin, sourceEnd); source = StringUtilities.normalizeWhitespaces(source); } // abstract or body if (AstNodeUtils.isAbstract(binding)) { // no body source += "\n"; } else { // open method source += "{"; // constructor if (binding.isConstructor()) { source += getConstructorBodySource(method); } // add "return" String returnTypeName = AstNodeUtils.getFullyQualifiedName(binding.getReturnType(), false); if (!"void".equals(returnTypeName)) { source += "return " + getDefaultValue(returnTypeName) + ";"; } // close method source += "}\n"; } // result return source; }