List of usage examples for org.eclipse.jdt.core.dom Assignment LEFT_HAND_SIDE_PROPERTY
ChildPropertyDescriptor LEFT_HAND_SIDE_PROPERTY
To view the source code for org.eclipse.jdt.core.dom Assignment LEFT_HAND_SIDE_PROPERTY.
Click Source Link
From source file:org.autorefactor.refactoring.rules.VariableDefinitionsUsesVisitor.java
License:Open Source License
@Override public boolean visit(SimpleName node) { if (isSameLocalVariable(variableBinding, node)) { switch (node.getParent().getNodeType()) { case ASSIGNMENT: addDefinitionOrUse(node, Assignment.LEFT_HAND_SIDE_PROPERTY); break; case VARIABLE_DECLARATION_FRAGMENT: addDefinitionOrUse(node, VariableDeclarationFragment.NAME_PROPERTY); break; case SINGLE_VARIABLE_DECLARATION: addDefinitionOrUse(node, SingleVariableDeclaration.NAME_PROPERTY); break; default:/*from w ww. java 2 s. c o m*/ uses.add(node); break; } } return VISIT_SUBTREE; }
From source file:org.eclipse.wb.core.model.JavaInfo.java
License:Open Source License
/** * @return the {@link ASTNode} that should be used to display given related {@link ASTNode}. *///from w ww . ja v a 2 s. c om public static ASTNode getRelatedNodeForSource(ASTNode node) { ASTNode sourceNode = node; // part of invocation if (node.getLocationInParent() == MethodInvocation.EXPRESSION_PROPERTY) { sourceNode = node.getParent(); } if (node.getLocationInParent() == MethodInvocation.ARGUMENTS_PROPERTY) { sourceNode = node.getParent(); } if (node.getLocationInParent() == SuperConstructorInvocation.ARGUMENTS_PROPERTY) { sourceNode = node.getParent(); } if (node.getLocationInParent() == SuperMethodInvocation.ARGUMENTS_PROPERTY) { sourceNode = node.getParent(); } if (node.getLocationInParent() == ClassInstanceCreation.ARGUMENTS_PROPERTY) { sourceNode = node.getParent(); } // javaInfo.foo = something if (node.getLocationInParent() == QualifiedName.QUALIFIER_PROPERTY) { QualifiedName qualifiedName = (QualifiedName) node.getParent(); sourceNode = qualifiedName; if (qualifiedName.getLocationInParent() == Assignment.LEFT_HAND_SIDE_PROPERTY) { sourceNode = qualifiedName.getParent(); } } // done return sourceNode; }
From source file:org.eclipse.wb.core.model.JavaInfo.java
License:Open Source License
/** * Adds {@link ASTNode}'s that represent this {@link JavaInfo} in subtree of given {@link ASTNode} * .//w w w . j a v a 2 s . c om */ public final void addRelatedNodes(ASTNode start) { start.accept(new ASTVisitor() { @Override public void postVisit(ASTNode node) { // ignore "button" in "button = new JButton()" if (node.getLocationInParent() == VariableDeclarationFragment.NAME_PROPERTY || node.getLocationInParent() == Assignment.LEFT_HAND_SIDE_PROPERTY) { return; } if (isRepresentedBy(node)) { addRelatedNode(node); } } @Override public void endVisit(MethodInvocation node) { // support for invocation for "this" component if (node.getExpression() == null && isRepresentedBy(null)) { addRelatedNode(node); } } }); }
From source file:org.eclipse.wb.internal.core.model.util.MorphingSupport.java
License:Open Source License
@Override protected void morph_properties(T newComponent) throws Exception { ComponentDescription newComponentDescription = newComponent.getDescription(); // move related nodes for (ASTNode node : m_component.getRelatedNodes()) { // check if method invocation can exist in new component if (node.getLocationInParent() == MethodInvocation.EXPRESSION_PROPERTY) { MethodInvocation invocation = (MethodInvocation) node.getParent(); String signature = AstNodeUtils.getMethodSignature(invocation); if (newComponentDescription.getMethod(signature) == null) { m_editor.removeEnclosingStatement(invocation); continue; }//from w ww. ja va2 s . co m } // check if assignment can exist in new component if (node.getLocationInParent() == QualifiedName.QUALIFIER_PROPERTY) { QualifiedName fieldAccess = (QualifiedName) node.getParent(); if (fieldAccess.getLocationInParent() == Assignment.LEFT_HAND_SIDE_PROPERTY) { String fieldName = fieldAccess.getName().getIdentifier(); if (ReflectionUtils.getFieldByName(newComponentDescription.getComponentClass(), fieldName) == null) { m_editor.removeEnclosingStatement(node); continue; } } } // OK, we can add this related node newComponent.addRelatedNode(node); } }
From source file:org.eclipse.wb.internal.core.model.variable.LocalReuseVariableSupport.java
License:Open Source License
@Override public void setType(String newTypeName) throws Exception { // if old declaration is with our initializer, split it on declaration and assignment if (m_declaration.getName() == m_variable) { splitVariable();// w ww . j a v a2 s .c o m } // check that existing assignment is part of ExpressionStatement Assignment oldAssignment; ExpressionStatement oldStatement; { Assert.isTrue(m_variable.getLocationInParent() == Assignment.LEFT_HAND_SIDE_PROPERTY && m_variable.getParent().getLocationInParent() == ExpressionStatement.EXPRESSION_PROPERTY, "Variable should be part of Assignment in ExpressionStatement, for " + AstNodeUtils.getEnclosingStatement(m_variable)); oldAssignment = (Assignment) m_variable.getParent(); oldStatement = (ExpressionStatement) AstNodeUtils.getEnclosingStatement(oldAssignment); } // convert Assignment into VariableDeclarationStatement with required Type { AstEditor editor = m_javaInfo.getEditor(); AST ast = m_variable.getAST(); // initial values int position = oldStatement.getStartPosition(); String source = ""; // add type Type newType; { newType = editor.getParser().parseQualifiedType(position, newTypeName); source += newTypeName + " "; } // add variable SimpleName newVariable; { // prepare identifier String identifier; { identifier = AstNodeUtils.getVariableName(m_variable); identifier = editor.getUniqueVariableName(position, identifier, null); replaceComponentReferences(identifier); } // prepare variable newVariable = editor.getParser().parseVariable(position + source.length(), identifier, null, AstNodeUtils.getTypeBinding(newType), false, Modifier.NONE); source += identifier; } // add " = " { source += " = "; } // add initializer Expression newInitializer; { newInitializer = oldAssignment.getRightHandSide(); oldAssignment.setRightHandSide(ast.newSimpleName("__bar__")); String initializerSource = editor.getSource(newInitializer); AstNodeUtils.moveNode(newInitializer, position + source.length()); source += initializerSource; } // create fragment VariableDeclarationFragment newFragment; { newFragment = ast.newVariableDeclarationFragment(); newFragment.setName(newVariable); newFragment.setInitializer(newInitializer); AstNodeUtils.setSourceRange(newFragment, newVariable, newInitializer); } // create statement VariableDeclarationStatement newStatement; { newStatement = ast.newVariableDeclarationStatement(newFragment); newStatement.setType(newType); AstNodeUtils.setSourceRange(newStatement, newType, newFragment, 1); source += ";"; } // replace old statement with new statement { List<Statement> statements = DomGenerics.statements((Block) oldStatement.getParent()); int index = statements.indexOf(oldStatement); // replace without "oldStatement", so its parts are not moved statements.remove(index); editor.replaceSubstring(oldStatement, source); // now we can add "newStatement", we created it already with correct positions statements.add(index, newStatement); // finalize source modifications editor.resolveImports(newStatement); } // now our JavaInfo uses LocalUniqueVariableSupport m_javaInfo.setVariableSupport(new LocalUniqueVariableSupport(m_javaInfo, newVariable)); } }
From source file:org.eclipse.wb.internal.core.utils.ast.AstNodeUtils.java
License:Open Source License
/** * @param node//from www. ja v a 2 s . co m * the {@link ASTNode} that represents should be qualifier of field. * * @return the {@link Expression} ({@link QualifiedName} or {@link FieldAccess}) used as left side * of {@link Assignment} to some field. May return <code>null</code>, if given node is not * left part of {@link Assignment}. */ public static Expression getFieldAssignment(ASTNode node) { // FieldAccess = value if (node.getLocationInParent() == FieldAccess.EXPRESSION_PROPERTY) { FieldAccess fieldAccess = (FieldAccess) node.getParent(); if (fieldAccess.getLocationInParent() == Assignment.LEFT_HAND_SIDE_PROPERTY) { return fieldAccess; } } // QualifiedName = value if (node.getLocationInParent() == QualifiedName.QUALIFIER_PROPERTY) { QualifiedName qualifiedName = (QualifiedName) node.getParent(); if (qualifiedName.getLocationInParent() == Assignment.LEFT_HAND_SIDE_PROPERTY) { return qualifiedName; } } // not an Assignment part return null; }