private boolean isAssigned(ASTNode current) { while (current != null && !(current instanceof Statement)) { if (current.getLocationInParent() == Assignment.LEFT_HAND_SIDE_PROPERTY) return true; if (current instanceof PrefixExpression) return true; if (current instanceof PostfixExpression) return true; current= current.getParent(); } return false; }
private void handleVariableBinding(ASTNode node, IVariableBinding variableBindig) { if (variableBindig == null) { StructuralPropertyDescriptor locationInParent = node.getLocationInParent(); //System.out.println(locationInParent.getId() + " has no variable binding"); } else { this.onVariableAccess(node, variableBindig); } }
protected ReplaceRewrite(ASTRewrite rewrite, ASTNode[] nodes) { Assert.isNotNull(rewrite); Assert.isNotNull(nodes); Assert.isTrue(nodes.length > 0); fRewrite= rewrite; fToReplace= nodes; fDescriptor= fToReplace[0].getLocationInParent(); if (nodes.length > 1) { Assert.isTrue(fDescriptor instanceof ChildListPropertyDescriptor); } }
protected ReplaceRewrite(ASTRewrite rewrite, ASTNode[] nodes) { Assert.isNotNull(rewrite); Assert.isNotNull(nodes); Assert.isTrue(nodes.length > 0); fRewrite= rewrite; fToReplace= nodes; fDescriptor= fToReplace[0].getLocationInParent(); if (nodes.length > 1) { Assert.isTrue(fDescriptor instanceof ChildListPropertyDescriptor); } }
protected ReplaceRewrite(ASTRewrite rewrite, ASTNode[] nodes) { Assert.isNotNull(rewrite); Assert.isNotNull(nodes); Assert.isTrue(nodes.length > 0); fRewrite= rewrite; fToReplace= nodes; fDescriptor= fToReplace[0].getLocationInParent(); if (nodes.length > 1) { Assert.isTrue(fDescriptor instanceof ChildListPropertyDescriptor); } }
static ASTNode[] getSiblingNodes(ASTNode node) { ASTNode parent= node.getParent(); StructuralPropertyDescriptor locationInParent= node.getLocationInParent(); if (locationInParent.isChildListProperty()) { List<? extends ASTNode> siblings= ASTNodes.getChildListProperty(parent, (ChildListPropertyDescriptor) locationInParent); return siblings.toArray(new ASTNode[siblings.size()]); } return null; }
private ASTNode getPreviousNode(ASTNode node) { ArrayType arrayType = (ArrayType) node.getParent(); ASTNode prev = arrayType.getElementType(); List l = (List) node.getParent().getStructuralProperty(node.getLocationInParent()); int size = l.size(); int i = 0; for (; i < size; i++) { ASTNode currNode = (ASTNode) l.get(i); if (node == currNode) break; prev = currNode; } return i < size ? prev : null; }
public static boolean isComplainingAboutReturn(ASTNode selectedNode) { if (selectedNode.getParent().getNodeType() == ASTNode.RETURN_STATEMENT) return true; while (!(selectedNode instanceof Type)) { if (selectedNode == null) return false; selectedNode= selectedNode.getParent(); } return selectedNode.getLocationInParent() == MethodDeclaration.RETURN_TYPE2_PROPERTY; }
private SimpleName getNewName(ASTRewrite rewrite) { AST ast= rewrite.getAST(); String name; if (fInvocationNode.getLocationInParent() == MemberValuePair.NAME_PROPERTY) { name= ((SimpleName) fInvocationNode).getIdentifier(); } else { name= "value"; //$NON-NLS-1$ } SimpleName newNameNode= ast.newSimpleName(name); return newNameNode; }
private void handleMethodBinding(ASTNode node, IMethodBinding methodBinding) { if (methodBinding == null) { StructuralPropertyDescriptor locationInParent = node.getLocationInParent(); //System.out.println(locationInParent.getId() + " has no method binding"); } else { ITypeBinding declaringClass = methodBinding.getDeclaringClass(); if (declaringClass != null && !this.ignoreType(declaringClass)) { this.onMethodAccess(node, methodBinding); } } }
public boolean consumes(SemanticToken token) { IBinding binding= token.getBinding(); if (binding != null && binding.getKind() == IBinding.VARIABLE && !((IVariableBinding) binding).isField()) { ASTNode decl= token.getRoot().findDeclaringNode(binding); return decl != null && decl.getLocationInParent() == MethodDeclaration.PARAMETERS_PROPERTY; } return false; } }
private void checkExpression(RefactoringStatus status) { ASTNode[] nodes= getSelectedNodes(); if (nodes != null && nodes.length == 1) { ASTNode node= nodes[0]; if (node instanceof Type) { status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_type_reference, JavaStatusContext.create(fCUnit, node)); } else if (node.getLocationInParent() == SwitchCase.EXPRESSION_PROPERTY) { status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_switch_case, JavaStatusContext.create(fCUnit, node)); } } }
@Override public boolean consumes(SemanticToken token) { IBinding binding= token.getBinding(); if (binding != null && binding.getKind() == IBinding.VARIABLE && !((IVariableBinding) binding).isField()) { ASTNode decl= token.getRoot().findDeclaringNode(binding); return decl != null && decl.getLocationInParent() == MethodDeclaration.PARAMETERS_PROPERTY; } return false; } }
private void removeStatement(ASTRewrite rewrite, ASTNode statementNode, TextEditGroup group) { if (ASTNodes.isControlStatementBody(statementNode.getLocationInParent())) { rewrite.replace(statementNode, rewrite.getAST().newBlock(), group); } else { rewrite.remove(statementNode, group); } }
@Override public boolean consumes(SemanticToken token) { IBinding binding = token.getBinding(); if (binding != null && binding.getKind() == IBinding.VARIABLE && !((IVariableBinding) binding).isField()) { ASTNode decl = token.getRoot().findDeclaringNode(binding); return decl != null && decl.getLocationInParent() == MethodDeclaration.PARAMETERS_PROPERTY; } return false; } }
private void removeStatement(ASTRewrite rewrite, ASTNode statementNode, TextEditGroup group) { if (ASTNodes.isControlStatementBody(statementNode.getLocationInParent())) { rewrite.replace(statementNode, rewrite.getAST().newBlock(), group); } else { rewrite.remove(statementNode, group); } }
private static boolean isNotInBlock(ASTNode parent) { ASTNode statement= parent.getParent(); boolean isStatement= statement.getNodeType() != ASTNode.EXPRESSION_STATEMENT; ASTNode block= statement.getParent(); boolean isBlock= block.getNodeType() == ASTNode.BLOCK || block.getNodeType() == ASTNode.SWITCH_STATEMENT; boolean isControlStatemenBody= ASTNodes.isControlStatementBody(statement.getLocationInParent()); return isStatement || !(isBlock || isControlStatemenBody); }
private static boolean isNotInBlock(ASTNode parent) { ASTNode statement= parent.getParent(); boolean isStatement= statement.getNodeType() != ASTNode.EXPRESSION_STATEMENT; ASTNode block= statement.getParent(); boolean isBlock= block.getNodeType() == ASTNode.BLOCK || block.getNodeType() == ASTNode.SWITCH_STATEMENT; boolean isControlStatemenBody= ASTNodes.isControlStatementBody(statement.getLocationInParent()); return isStatement || !(isBlock || isControlStatemenBody); }
private boolean updateReference(ITypeBinding[] parameters, ASTNode node, CompilationUnitRewrite rewrite, TextEditGroup group) { if (node.getLocationInParent() == ParameterizedType.TYPE_PROPERTY) { updateParameterizedTypeReference(parameters, (ParameterizedType) node.getParent(), rewrite, group); return updateNameReference(new ITypeBinding[] {}, ((SimpleType) node).getName(), rewrite, group); } else if (node instanceof QualifiedName) return updateNameReference(parameters, (QualifiedName) node, rewrite, group); else if (node instanceof SimpleType) return updateNameReference(parameters, ((SimpleType) node).getName(), rewrite, group); else return false; }
private boolean updateReference(ITypeBinding[] parameters, ASTNode node, CompilationUnitRewrite rewrite, TextEditGroup group) { if (node.getLocationInParent() == ParameterizedType.TYPE_PROPERTY) { updateParameterizedTypeReference(parameters, (ParameterizedType) node.getParent(), rewrite, group); return updateNameReference(new ITypeBinding[] {}, ((SimpleType) node).getName(), rewrite, group); } else if (node instanceof QualifiedName) return updateNameReference(parameters, (QualifiedName) node, rewrite, group); else if (node instanceof SimpleType) return updateNameReference(parameters, ((SimpleType) node).getName(), rewrite, group); else return false; }