public static boolean isGenerated(org.eclipse.jdt.core.dom.ASTNode node) { boolean result = false; try { result = ((Boolean)node.getClass().getField("$isGenerated").get(node)).booleanValue(); if (!result && node.getParent() != null && node.getParent() instanceof org.eclipse.jdt.core.dom.QualifiedName) { result = isGenerated(node.getParent()); } } catch (Exception e) { // better to assume it isn't generated } return result; }
private boolean isDestinationReachable(MethodDeclaration methodDeclaration) { ASTNode start = methodDeclaration; while (start != null && start != fDestination) { start = start.getParent(); } return start == fDestination; }
private void checkParent(ASTNode node) { ASTNode parent= node.getParent(); if (!(parent instanceof ExpressionStatement)) fSetterMustReturnValue= true; }
private static ASTNode getContainingTypeDeclaration(ASTNode node) { while (node != null && !(node instanceof AbstractTypeDeclaration) && !(node instanceof AnonymousClassDeclaration)) { node= node.getParent(); } return node; }
private static ASTNode[] getParents(ASTNode node) { ASTNode current = node; List<ASTNode> parents = new ArrayList<>(); do { parents.add(current.getParent()); current = current.getParent(); } while (current.getParent() != null); Collections.reverse(parents); return parents.toArray(new ASTNode[parents.size()]); }
public static <T extends ASTNode> T ancestorOf(ASTNode node, Class<T> ancestorType) { ASTNode parent = node.getParent(); do { if (ancestorType.isInstance(parent)) return (T) parent; parent = parent.getParent(); } while (parent != null); throw new IllegalArgumentException(node + " has no ancestor of type " + ancestorType.getName()); }
private static ASTNode[] getParents(ASTNode node) { ASTNode current= node; List parents= new ArrayList(); do { parents.add(current.getParent()); current= current.getParent(); } while (current.getParent() != null); Collections.reverse(parents); return (ASTNode[]) parents.toArray(new ASTNode[parents.size()]); }
protected void postProcessSelectedNodes(List selectedNodes) { if (selectedNodes == null || selectedNodes.size() == 0) return; if (selectedNodes.size() == 1) { ASTNode node= (ASTNode)selectedNodes.get(0); if (node instanceof Expression && node.getParent() instanceof ExpressionStatement) { selectedNodes.clear(); selectedNodes.add(node.getParent()); } } }
@Override public void replace(ASTRewrite rewrite, ASTNode replacement, TextEditGroup textEditGroup) { if (replacement instanceof Name && fNode.getParent() instanceof ParenthesizedExpression) { // replace including the parenthesized expression around it rewrite.replace(fNode.getParent(), replacement, textEditGroup); } else { rewrite.replace(fNode, replacement, textEditGroup); } }
private static ParameterizedType getParameterizedType(CompilationUnit compilationUnit, IProblemLocation problem) { ASTNode selectedNode= problem.getCoveringNode(compilationUnit); if (selectedNode == null) return null; while (!(selectedNode instanceof ParameterizedType) && !(selectedNode instanceof Statement)) { selectedNode= selectedNode.getParent(); } if (selectedNode instanceof ParameterizedType) { return (ParameterizedType) selectedNode; } return null; }
public static Initializer getInitializerNode(IInitializer initializer, CompilationUnit cuNode) throws JavaModelException { ASTNode node= findNode(initializer.getSourceRange(), cuNode); if (node instanceof Initializer) return (Initializer) node; if (node instanceof Block && node.getParent() instanceof Initializer) return (Initializer) node.getParent(); return null; }
public static ASTNode findAncestor(ASTNode node, int nodeType) { while ((node != null) && (node.getNodeType() != nodeType)) { node= node.getParent(); } return node; }
private ITypeBinding getDeclaringType(MethodInvocation node) { ASTNode p= node; while (p != null) { p= p.getParent(); if (p instanceof AbstractTypeDeclaration) { return ((AbstractTypeDeclaration)p).resolveBinding(); } } return null; }
ISourceRange internalGetNewSelectionRange(ISourceRange oldSourceRange, ISourceReference sr, SelectionAnalyzer selAnalyzer) throws JavaModelException{ ASTNode first= selAnalyzer.getFirstSelectedNode(); if (first == null || first.getParent() == null) return getLastCoveringNodeRange(oldSourceRange, sr, selAnalyzer); return getSelectedNodeSourceRange(sr, first.getParent()); } }
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 getAstNode(SearchMatch searchResult, CompilationUnit cuNode) { ASTNode selectedNode= getAstNode(cuNode, searchResult.getOffset(), searchResult.getLength()); if (selectedNode == null) return null; if (selectedNode.getParent() == null) return null; return selectedNode; }
static boolean hasReference(MethodDeclaration node) { try { SuperThisReferenceFinder finder= new SuperThisReferenceFinder(); ClassInstanceCreation cic= (ClassInstanceCreation) node.getParent().getParent(); finder.fFunctionalInterface= cic.getType().resolveBinding(); finder.fMethodDeclaration= node; node.accept(finder); } catch (AbortSearchException e) { return true; } return false; }
private boolean shouldReplaceSelectedExpressionWithTempDeclaration() throws JavaModelException { IExpressionFragment selectedFragment= getSelectedExpression(); return selectedFragment.getAssociatedNode().getParent() instanceof ExpressionStatement && selectedFragment.matches(ASTFragmentFactory.createFragmentForFullSubtree(selectedFragment.getAssociatedNode())); }