List of usage examples for org.eclipse.jdt.core.dom Assignment RIGHT_HAND_SIDE_PROPERTY
ChildPropertyDescriptor RIGHT_HAND_SIDE_PROPERTY
To view the source code for org.eclipse.jdt.core.dom Assignment RIGHT_HAND_SIDE_PROPERTY.
Click Source Link
From source file:org.autorefactor.refactoring.rules.UseDiamondOperatorRefactoring.java
License:Open Source License
private boolean parentAllowsDiamondOperator(ClassInstanceCreation node) { final ASTNode parentInfo = getFirstParentOfType(node, ParenthesizedExpression.class); final StructuralPropertyDescriptor locationInParent = parentInfo.getLocationInParent(); switch (parentInfo.getParent().getNodeType()) { case ASSIGNMENT: return Assignment.RIGHT_HAND_SIDE_PROPERTY.equals(locationInParent); case METHOD_INVOCATION: return false; // FIXME some of them can be refactored case RETURN_STATEMENT: return ReturnStatement.EXPRESSION_PROPERTY.equals(locationInParent); case VARIABLE_DECLARATION_FRAGMENT: return VariableDeclarationFragment.INITIALIZER_PROPERTY.equals(locationInParent); default:// ww w. j a v a 2 s . com return false; } }
From source file:org.eclipse.wb.internal.swing.model.property.editor.models.tree.TreeModelEvaluator.java
License:Open Source License
public Object evaluate(EvaluationContext context, Expression expression, ITypeBinding typeBinding, String typeQualifiedName) throws Exception { AnonymousClassDeclaration rootDeclaration = findRootNodeDeclaration(expression); if (rootDeclaration != null) { // create root node final DefaultMutableTreeNode rootNode; {//from w ww . ja v a2 s .c o m ClassInstanceCreation rootNodeCreation = (ClassInstanceCreation) rootDeclaration.getParent(); StringLiteral rootTextLiteral = (StringLiteral) rootNodeCreation.arguments().get(0); rootNode = new DefaultMutableTreeNode(rootTextLiteral.getLiteralValue()); } // create nodes final Map<String, DefaultMutableTreeNode> nameToNode = Maps.newTreeMap(); rootDeclaration.accept(new ASTVisitor() { private DefaultMutableTreeNode m_lastNode; @Override public void endVisit(ClassInstanceCreation creation) { if (AstNodeUtils.getFullyQualifiedName(creation, false) .equals("javax.swing.tree.DefaultMutableTreeNode") && creation.arguments().size() == 1 && creation.arguments().get(0) instanceof StringLiteral) { StringLiteral stringLiteral = (StringLiteral) creation.arguments().get(0); DefaultMutableTreeNode node = new DefaultMutableTreeNode(stringLiteral.getLiteralValue()); if (creation.getLocationInParent() == VariableDeclarationFragment.INITIALIZER_PROPERTY) { String name = ((VariableDeclarationFragment) creation.getParent()).getName() .getIdentifier(); nameToNode.put(name, node); } else if (creation.getLocationInParent() == Assignment.RIGHT_HAND_SIDE_PROPERTY && ((Assignment) creation.getParent()).getLeftHandSide() instanceof SimpleName) { Assignment assignment = (Assignment) creation.getParent(); SimpleName variable = (SimpleName) assignment.getLeftHandSide(); String name = variable.getIdentifier(); nameToNode.put(name, node); } else { m_lastNode = node; } } } @Override public void endVisit(MethodInvocation invocation) { if (AstNodeUtils.getMethodSignature(invocation) .equals("add(javax.swing.tree.MutableTreeNode)")) { // prepare node DefaultMutableTreeNode node = null; { Object argument = invocation.arguments().get(0); if (argument instanceof SimpleName) { SimpleName variable = (SimpleName) argument; node = nameToNode.get(variable.getIdentifier()); } else if (argument instanceof ClassInstanceCreation) { node = m_lastNode; } } // prepare parent DefaultMutableTreeNode parentNode = null; if (invocation.getExpression() instanceof SimpleName) { SimpleName variable = (SimpleName) invocation.getExpression(); parentNode = nameToNode.get(variable.getIdentifier()); } else if (invocation.getExpression() == null) { parentNode = rootNode; } // add node to parent if (parentNode != null && node != null) { parentNode.add(node); } // clear last node m_lastNode = null; } } }); // OK, return model return new DefaultTreeModel(rootNode); } // we don't understand given expression return AstEvaluationEngine.UNKNOWN; }