static CompilationUnit parsePartialCompilationUnit(ICompilationUnit unit) { if (unit == null) { throw new IllegalArgumentException(); } try { ASTParser c= ASTParser.newParser(AST.JLS3); c.setSource(unit); c.setFocalPosition(0); c.setResolveBindings(false); c.setWorkingCopyOwner(null); ASTNode result= c.createAST(null); return (CompilationUnit) result; } catch (IllegalStateException e) { // convert ASTParser's complaints into old form throw new IllegalArgumentException(); } } }
static CompilationUnit parsePartialCompilationUnit(ICompilationUnit unit) { if (unit == null) { throw new IllegalArgumentException(); } try { ASTParser c= ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL); c.setSource(unit); c.setFocalPosition(0); c.setResolveBindings(false); c.setWorkingCopyOwner(null); ASTNode result= c.createAST(null); return (CompilationUnit) result; } catch (IllegalStateException e) { // convert ASTParser's complaints into old form throw new IllegalArgumentException(); } } }
private CompilationUnit createASTForImports(ICompilationUnit cu) { ASTParser parser= ASTParser.newParser(AST.JLS3); parser.setSource(cu); parser.setResolveBindings(false); parser.setFocalPosition(0); return (CompilationUnit) parser.createAST(null); }
static CompilationUnit parsePartialCompilationUnit(ICompilationUnit unit) { if (unit == null) { throw new IllegalArgumentException(); } try { ASTParser c= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL); c.setSource(unit); c.setFocalPosition(0); c.setResolveBindings(false); c.setWorkingCopyOwner(null); ASTNode result= c.createAST(null); return (CompilationUnit) result; } catch (IllegalStateException e) { // convert ASTParser's complaints into old form throw new IllegalArgumentException(); } } }
private CompilationUnit createASTForImports(ICompilationUnit cu) { ASTParser parser= ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL); parser.setSource(cu); parser.setResolveBindings(true); parser.setFocalPosition(0); return (CompilationUnit) parser.createAST(null); }
private CompilationUnit createASTForImports(ICompilationUnit cu) { ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL); parser.setSource(cu); parser.setResolveBindings(true); parser.setFocalPosition(0); return (CompilationUnit) parser.createAST(null); }
private CompilationUnit createASTForImports(ICompilationUnit cu) { ASTParser parser= ASTParser.newParser(AST.JLS3); parser.setSource(cu); parser.setResolveBindings(false); parser.setFocalPosition(0); return (CompilationUnit) parser.createAST(null); }
/** * Creates and AST for the given {@link ITypeRoot} at the given offset * * @param root * @param offset * @return */ private CompilationUnit createAST(ITypeRoot root, int offset) { if (fJavaProject == null) { return null; } ASTParser parser = ASTParser.newParser(AST.JLS10); parser.setFocalPosition(offset); parser.setResolveBindings(false); parser.setSource(root); Map<String, String> options = fJavaProject.getOptions(true); options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); parser.setCompilerOptions(options); return (CompilationUnit) parser.createAST(new NullProgressMonitor()); }
/** * Creates an {@link AST} with the given {@link ICompilationUnit} as source and the * {@link JavaCore#COMPILER_DOC_COMMENT_SUPPORT} options set. * @param unit * @param focalposition * @param resolvebindings * @return a new {@link AST} */ protected CompilationUnit createAST(final ICompilationUnit unit, int focalposition, boolean resolvebindings) { ASTParser parser = ASTParser.newParser(AST.JLS4); parser.setSource(unit); parser.setFocalPosition(focalposition); parser.setResolveBindings(resolvebindings); Map options = unit.getJavaProject().getOptions(true); options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); parser.setCompilerOptions(options); return (CompilationUnit) parser.createAST(new NullProgressMonitor()); }
/** * Creates an {@link AST} with the given {@link ICompilationUnit} as source * and the {@link JavaCore#COMPILER_DOC_COMMENT_SUPPORT} options set. * * @param unit * @param focalposition * @param resolvebindings * @return a new {@link AST} */ protected CompilationUnit createAST(final ICompilationUnit unit, int focalposition, boolean resolvebindings) { ASTParser parser = ASTParser.newParser(AST.JLS10); parser.setSource(unit); parser.setFocalPosition(focalposition); parser.setResolveBindings(resolvebindings); Map<String, String> options = unit.getJavaProject().getOptions(true); options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); parser.setCompilerOptions(options); return (CompilationUnit) parser.createAST(new NullProgressMonitor()); }
private void visitCompilationUnit(IFile file) { ICompilationUnit cu= JavaCore.createCompilationUnitFrom(file); if (cu != null) { ASTParser parser= ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL); parser.setSource(cu); parser.setFocalPosition(0); CompilationUnit root= (CompilationUnit)parser.createAST(null); PackageDeclaration packDecl= root.getPackage(); IPath packPath= file.getParent().getFullPath(); String cuName= file.getName(); if (packDecl == null) { addToMap(fSourceFolders, packPath, new Path(cuName)); } else { IPath relPath= new Path(packDecl.getName().getFullyQualifiedName().replace('.', '/')); IPath folderPath= getFolderPath(packPath, relPath); if (folderPath != null) { addToMap(fSourceFolders, folderPath, relPath.append(cuName)); } } } }
private void visitCompilationUnit(IFile file) { ICompilationUnit cu= JavaCore.createCompilationUnitFrom(file); if (cu != null) { ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL); parser.setSource(cu); parser.setFocalPosition(0); CompilationUnit root= (CompilationUnit)parser.createAST(null); PackageDeclaration packDecl= root.getPackage(); IPath packPath= file.getParent().getFullPath(); String cuName= file.getName(); if (packDecl == null) { addToMap(fSourceFolders, packPath, new Path(cuName)); } else { IPath relPath= new Path(packDecl.getName().getFullyQualifiedName().replace('.', '/')); IPath folderPath= getFolderPath(packPath, relPath); if (folderPath != null) { addToMap(fSourceFolders, folderPath, relPath.append(cuName)); } } } }
parser.setCompilerOptions(compilerOptions); parser.setSource(buffer); parser.setFocalPosition(0); CompilationUnit cu= (CompilationUnit) parser.createAST(monitor); cu.accept(new JavaParseTreeBuilder(root, buffer, true));
parser.setCompilerOptions(compilerOptions); parser.setSource(buffer); parser.setFocalPosition(0); CompilationUnit cu= (CompilationUnit) parser.createAST(monitor); cu.accept(new JavaParseTreeBuilder(root, buffer, true));
parser.setSource(type.getClassFile()); parser.setFocalPosition(0); parser.setResolveBindings(true); CompilationUnit root= (CompilationUnit) parser.createAST(monitor);
private static StubTypeContext createSupertypeStubTypeContext(String typeName, boolean isInterface, IType enclosingType, IPackageFragment packageFragment) { StubTypeContext stubTypeContext; String prolog= "class " + typeName + (isInterface ? " implements " : " extends "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ String epilog= " {} "; //$NON-NLS-1$ if (enclosingType != null) { try { ICompilationUnit cu= enclosingType.getCompilationUnit(); ISourceRange typeSourceRange= enclosingType.getSourceRange(); int focalPosition= typeSourceRange.getOffset() + typeSourceRange.getLength() - 1; // before closing brace ASTParser parser= ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL); parser.setSource(cu); parser.setFocalPosition(focalPosition); CompilationUnit compilationUnit= (CompilationUnit) parser.createAST(null); stubTypeContext= createStubTypeContext(cu, compilationUnit, focalPosition); stubTypeContext= new StubTypeContext(stubTypeContext.getCuHandle(), stubTypeContext.getBeforeString() + prolog, epilog + stubTypeContext.getAfterString()); } catch (CoreException e) { JavaPlugin.log(e); stubTypeContext= new StubTypeContext(null, null, null); } } else if (packageFragment != null) { ICompilationUnit cu= packageFragment.getCompilationUnit(JavaTypeCompletionProcessor.DUMMY_CU_NAME); stubTypeContext= new StubTypeContext(cu, "package " + packageFragment.getElementName() + ";" + prolog, epilog); //$NON-NLS-1$//$NON-NLS-2$ } else { stubTypeContext= new StubTypeContext(null, null, null); } return stubTypeContext; }
parser.setFocalPosition(focalPosition); CompilationUnit compilationUnit= (CompilationUnit) parser.createAST(null);
private static StubTypeContext createSupertypeStubTypeContext(String typeName, boolean isInterface, IType enclosingType, IPackageFragment packageFragment) { StubTypeContext stubTypeContext; String prolog= "class " + typeName + (isInterface ? " implements " : " extends "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ String epilog= " {} "; //$NON-NLS-1$ if (enclosingType != null) { try { ICompilationUnit cu= enclosingType.getCompilationUnit(); ISourceRange typeSourceRange= enclosingType.getSourceRange(); int focalPosition= typeSourceRange.getOffset() + typeSourceRange.getLength() - 1; // before closing brace ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL); parser.setSource(cu); parser.setFocalPosition(focalPosition); CompilationUnit compilationUnit= (CompilationUnit) parser.createAST(null); stubTypeContext= createStubTypeContext(cu, compilationUnit, focalPosition); stubTypeContext= new StubTypeContext(stubTypeContext.getCuHandle(), stubTypeContext.getBeforeString() + prolog, epilog + stubTypeContext.getAfterString()); } catch (CoreException e) { JavaPlugin.log(e); stubTypeContext= new StubTypeContext(null, null, null); } } else if (packageFragment != null) { ICompilationUnit cu= packageFragment.getCompilationUnit(JavaTypeCompletionProcessor.DUMMY_CU_NAME); stubTypeContext= new StubTypeContext(cu, "package " + packageFragment.getElementName() + ";" + prolog, epilog); //$NON-NLS-1$//$NON-NLS-2$ } else { stubTypeContext= new StubTypeContext(null, null, null); } return stubTypeContext; }
parser.setSource(type.getClassFile()); parser.setFocalPosition(0); parser.setResolveBindings(true); CompilationUnit root= (CompilationUnit) parser.createAST(monitor);
parser.setSource(type.getClassFile()); parser.setFocalPosition(0); parser.setResolveBindings(true); CompilationUnit root= (CompilationUnit) parser.createAST(monitor);