private boolean isControlStatement(ASTNode node) { int type= node.getNodeType(); return type == ASTNode.IF_STATEMENT || type == ASTNode.FOR_STATEMENT || type == ASTNode.ENHANCED_FOR_STATEMENT || type == ASTNode.WHILE_STATEMENT || type == ASTNode.DO_STATEMENT; } }
private static boolean needsInnerParantheses(ASTNode nodeToCast) { int nodeType= nodeToCast.getNodeType(); // nodes have weaker precedence than cast return nodeType == ASTNode.INFIX_EXPRESSION || nodeType == ASTNode.CONDITIONAL_EXPRESSION || nodeType == ASTNode.ASSIGNMENT || nodeType == ASTNode.INSTANCEOF_EXPRESSION; }
private static boolean isControlStatementWithBlock(ASTNode node) { switch (node.getNodeType()) { case ASTNode.IF_STATEMENT: case ASTNode.WHILE_STATEMENT: case ASTNode.FOR_STATEMENT: case ASTNode.ENHANCED_FOR_STATEMENT: case ASTNode.DO_STATEMENT: return true; default: return false; } }
@Override protected boolean isConstructor() { ASTNode node= getInvocationNode(); return node.getNodeType() != ASTNode.METHOD_INVOCATION && node.getNodeType() != ASTNode.SUPER_METHOD_INVOCATION; }
@Override protected boolean isConstructor() { ASTNode node= getInvocationNode(); return node.getNodeType() != ASTNode.METHOD_INVOCATION && node.getNodeType() != ASTNode.SUPER_METHOD_INVOCATION; }
private static boolean isMultiDeclarationFragment(ASTNode node) { int nodeType= node.getNodeType(); if (nodeType == ASTNode.VARIABLE_DECLARATION_FRAGMENT) { node= node.getParent(); if (node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT) { VariableDeclarationStatement vs= (VariableDeclarationStatement)node; return vs.fragments().size() > 1; } } return false; }
private static boolean isMultiDeclarationFragment(ASTNode node) { int nodeType= node.getNodeType(); if (nodeType == ASTNode.VARIABLE_DECLARATION_FRAGMENT) { node= node.getParent(); if (node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT) { VariableDeclarationStatement vs= (VariableDeclarationStatement)node; return vs.fragments().size() > 1; } } return false; }
public static ASTNode findAncestor(ASTNode node, int nodeType) { while ((node != null) && (node.getNodeType() != nodeType)) { node= node.getParent(); } return node; }
private boolean isPropertyNode(ASTNode node) { if (node.getNodeType() != ASTNode.METHOD_DECLARATION) { return false; } return isProperty((MethodDeclaration) node); }
private void initializeTargetNode() { ASTNode parent= fInvocation.getParent(); int nodeType= parent.getNodeType(); if (nodeType == ASTNode.EXPRESSION_STATEMENT || nodeType == ASTNode.RETURN_STATEMENT) { fTargetNode= parent; } else { fTargetNode= fInvocation; } }
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); }
@Override public boolean preVisit2(final ASTNode node) { int _nodeType = node.getNodeType(); boolean _tripleEquals = (_nodeType == 86); if (_tripleEquals) { this.preVisit(node); this.handleLambdaExpression(node); return false; } return super.preVisit2(node); }
public IMethodBinding getDeclaringMethod() { ASTNode parent = this.variableDeclaration.getParent(); while (parent != null && parent.getNodeType() != ASTNode.METHOD_DECLARATION) { parent = parent.getParent(); } if (parent != null) { return ((MethodDeclaration) parent).resolveBinding(); } return null; }
private Expression getQualifier(ASTNode parent) { switch (parent.getNodeType()) { case ASTNode.FIELD_ACCESS: return ((FieldAccess) parent).getExpression(); case ASTNode.QUALIFIED_NAME: return ((QualifiedName)parent).getQualifier(); case ASTNode.SUPER_FIELD_ACCESS: return ((SuperFieldAccess)parent).getQualifier(); default: return null; } }
@Override protected ASTNode generateElementAST(ASTRewrite rewriter, ICompilationUnit cu) throws JavaModelException { ASTNode node = super.generateElementAST(rewriter, cu); if (node.getNodeType() != ASTNode.FIELD_DECLARATION) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_CONTENTS)); return node; } /**
protected ASTNode generateElementAST(ASTRewrite rewriter, ICompilationUnit cu) throws JavaModelException { ASTNode node = super.generateElementAST(rewriter, cu); if (node.getNodeType() != ASTNode.INITIALIZER) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_CONTENTS)); return node; } /**
@Override public void updateNode() throws JavaModelException { int start= fNode.getStartPosition(); int length= fNode.getLength(); String msg= "Cannot update found node: nodeType=" + fNode.getNodeType() + "; " //$NON-NLS-1$//$NON-NLS-2$ + fNode.toString() + "[" + start + ", " + length + "] in " + fCuRewrite.getCu(); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ JavaPlugin.log(new Exception(msg + ":\n" + fCuRewrite.getCu().getSource().substring(start, start + length))); //$NON-NLS-1$ fResult.addError(msg, JavaStatusContext.create(fCuRewrite.getCu(), fNode)); } @Override
@Override public void updateNode() throws JavaModelException { int start= fNode.getStartPosition(); int length= fNode.getLength(); String msg= "Cannot update found node: nodeType=" + fNode.getNodeType() + "; " //$NON-NLS-1$//$NON-NLS-2$ + fNode.toString() + "[" + start + ", " + length + "] in " + fCuRewrite.getCu(); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ JavaPlugin.log(new Exception(msg + ":\n" + fCuRewrite.getCu().getSource().substring(start, start + length))); //$NON-NLS-1$ fResult.addError(msg, JavaStatusContext.create(fCuRewrite.getCu(), fNode)); } @Override
private static String findAffectedParameterName(ASTNode selectedNode) { VariableDeclaration argDecl= (selectedNode instanceof VariableDeclaration) ? (VariableDeclaration) selectedNode : (VariableDeclaration) ASTNodes.getParent(selectedNode, VariableDeclaration.class); if (argDecl != null) return argDecl.getName().getIdentifier(); if (selectedNode.getNodeType() == ASTNode.SIMPLE_NAME) { IBinding binding= ((SimpleName) selectedNode).resolveBinding(); if (binding.getKind() == IBinding.VARIABLE && ((IVariableBinding) binding).isParameter()) return ((SimpleName) selectedNode).getIdentifier(); } return null; }
protected static ASTNode moveNode(CompilationUnitRewrite cuRewrite, ASTNode node) { ASTRewrite rewrite= cuRewrite.getASTRewrite(); if (rewrite.getAST() != node.getAST()) { String str= ASTNodes.getNodeSource(node, true, true); if (str != null) { return rewrite.createStringPlaceholder(str, node.getNodeType()); } return ASTNode.copySubtree(rewrite.getAST(), node); } return rewrite.createMoveTarget(node); } /**