parser.setKind(ASTParser.K_COMPILATION_UNIT); final CompilationUnit cu = (CompilationUnit) parser.createAST(null); cu.accept(new ASTVisitor() { MethodDeclaration currentMethod = null;
private void performSearch() { if (fResult == null) { fResult= new ArrayList<>(); fWriteUsages= new HashSet<>(); fRoot.accept(this); } }
public static ExistingMethodsVisitor getMethodCollection(final CompilationUnit unit) { final ExistingMethodsVisitor visitor = new ExistingMethodsVisitor(); unit.accept(visitor); return visitor; }
private static Set<ASTNode> getRemovedNodes(final List<ASTNode> removed, final CompilationUnitRewrite rewrite) { final Set<ASTNode> result= new HashSet<>(); rewrite.getRoot().accept(new GenericVisitor(true) { @Override protected boolean visitNode(ASTNode node) { if (removed.contains(node)) result.add(node); return true; } }); return result; }
public void perform() { CompilationUnit cuNode= ASTNodes.getParent(fTempDeclaration, CompilationUnit.class); cuNode.accept(this); }
private static Set<ASTNode> getRemovedNodes(final List<ASTNode> removed, final CompilationUnitRewrite rewrite) { final Set<ASTNode> result= new HashSet<>(); rewrite.getRoot().accept(new GenericVisitor(true) { @Override protected boolean visitNode(ASTNode node) { if (removed.contains(node)) result.add(node); return true; } }); return result; }
private boolean tempHasAssignmentsOtherThanInitialization() { TempAssignmentFinder assignmentFinder= new TempAssignmentFinder(fTempDeclarationNode); fCompilationUnitNode.accept(assignmentFinder); return assignmentFinder.hasAssignments(); }
public static ExistingMethodsVisitor getMethodCollection(final String source) { final CompilationUnit unit = getCompilationUnit(source); final ExistingMethodsVisitor visitor = new ExistingMethodsVisitor(); unit.accept(visitor); return visitor; }
private boolean tempHasAssignmentsOtherThanInitialization() { TempAssignmentFinder assignmentFinder= new TempAssignmentFinder(fTempDeclarationNode); fCompilationUnitNode.accept(assignmentFinder); return assignmentFinder.hasAssignments(); }
/** * Parse given java file and return method visitor (ExistingMethodsVisitor) * * @param path path to java file * @return ExistingMethodsVisitor instance */ public static ExistingMethodsVisitor getMethodCollection(final Path path) { final CompilationUnit unit = getCompilationUnit(path); final ExistingMethodsVisitor visitor = new ExistingMethodsVisitor(); unit.accept(visitor); return visitor; }
/** * Parse given java file and return method visitor (ExistingMethodsVisitor) * * @param path path to java file * @return ExistingMethodsVisitor instance */ public static ExistingMethodsVisitor getMethodCollection(final Path path) { final CompilationUnit unit = getCompilationUnit(path); final ExistingMethodsVisitor visitor = new ExistingMethodsVisitor(); unit.accept(visitor); return visitor; }
public void run() { if (null == warningHandler() || null == _ast) { throw new IllegalStateException(); } _ast.accept(this); visit(_ast.getCommentList()); }
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { // Create the Java parser and parse the source code into an abstract syntax tree ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(aJCas.getDocumentText().toCharArray()); CompilationUnit result = (CompilationUnit) parser.createAST(null); // Generate JavaDoc related annotations result.accept(new JavaDocVisitor(aJCas)); // Generate Java code related annotations result.accept(new CodeVisitor(aJCas)); }
public ASTNode search() throws JavaModelException { ISourceRange range = null; if (this.element instanceof IMember && !(this.element instanceof IInitializer)) range = ((IMember) this.element).getNameRange(); else range = this.element.getSourceRange(); this.rangeStart = range.getOffset(); this.rangeLength = range.getLength(); this.ast.accept(this); return this.foundNode; }
private static ASTNode findNode(ISourceRange range, CompilationUnit cuNode){ NodeFinder nodeFinder= new NodeFinder(range.getOffset(), range.getLength()); cuNode.accept(nodeFinder); ASTNode coveredNode= nodeFinder.getCoveredNode(); if (coveredNode != null) return coveredNode; else return nodeFinder.getCoveringNode(); }
public boolean accept(IType type) { IResource resource = type.getResource(); ICompilationUnit cu = JDTUtil.getJavaElement((IFile) resource); CompilationUnit astRoot = JUnitConverterQuickAssistProcessor.createCompilationUnit(cu); JUnitVisitor visitor = new JUnitVisitor(); astRoot.accept(visitor); return visitor.needsConversion(); }
public RefactoringStatus checkActivationBasics(CompilationUnit rootNode) throws CoreException { RefactoringStatus result = new RefactoringStatus(); fRootNode = rootNode; fAnalyzer = new SurroundWithTryCatchAnalyzer(fCUnit, fSelection); fRootNode.accept(fAnalyzer); result.merge(fAnalyzer.getStatus()); ITypeBinding[] exceptions = fAnalyzer.getExceptions(); if (fIsMultiCatch && (exceptions == null || exceptions.length <= 1)) { result.merge(RefactoringStatus.createWarningStatus(RefactoringCoreMessages.SurroundWithTryCatchRefactoring_notMultipleexceptions)); } return result; }
public RefactoringStatus checkActivationBasics(CompilationUnit rootNode) throws CoreException { RefactoringStatus result= new RefactoringStatus(); fRootNode= rootNode; fAnalyzer= new SurroundWithTryCatchAnalyzer(fCUnit, fSelection); fRootNode.accept(fAnalyzer); result.merge(fAnalyzer.getStatus()); ITypeBinding[] exceptions= fAnalyzer.getExceptions(); if (fIsMultiCatch && (exceptions == null || exceptions.length <= 1)) { result.merge(RefactoringStatus.createWarningStatus(RefactoringCoreMessages.SurroundWithTryCatchRefactoring_notMultipleexceptions)); } return result; }
public static boolean isApplicable(IInvocationContext context) throws JavaModelException { ICompilationUnit unit= context.getCompilationUnit(); CompilationUnit ast= ASTProvider.getASTProvider().getAST(unit, ASTProvider.WAIT_NO, null); if (ast == null) return true; Selection selection= Selection.createFromStartLength(context.getSelectionOffset(), context.getSelectionLength()); SurroundWithAnalyzer analyzer= new SurroundWithAnalyzer(unit, selection); context.getASTRoot().accept(analyzer); return analyzer.getStatus().isOK() && analyzer.hasSelectedNodes(); }
public static RefactoringStatus checkMethodSyntaxErrors(int selectionStart, int selectionLength, CompilationUnit cuNode, String invalidSelectionMessage){ SelectionAnalyzer analyzer= new SelectionAnalyzer(Selection.createFromStartLength(selectionStart, selectionLength), true); cuNode.accept(analyzer); ASTNode coveringNode= analyzer.getLastCoveringNode(); if (! (coveringNode instanceof Block) || ! (coveringNode.getParent() instanceof MethodDeclaration)) return RefactoringStatus.createFatalErrorStatus(invalidSelectionMessage); if (ASTNodes.getMessages(coveringNode, ASTNodes.NODE_ONLY).length == 0) return RefactoringStatus.createFatalErrorStatus(invalidSelectionMessage); MethodDeclaration methodDecl= (MethodDeclaration)coveringNode.getParent(); String message= Messages.format(RefactoringCoreMessages.CodeRefactoringUtil_error_message, BasicElementLabels.getJavaElementName(methodDecl.getName().getIdentifier())); return RefactoringStatus.createFatalErrorStatus(message); }