Package org.eclipse.jdt.core.dom

Examples of org.eclipse.jdt.core.dom.ASTParser.createAST()


        ASTParser parser = ASTParser.newParser(AST.JLS4);
        parser.setKind(ASTParser.K_COMPILATION_UNIT);
        parser.setSource(cunit);
        parser.setResolveBindings(true);
        return (CompilationUnit) parser.createAST(null);
    }

    List<MarkerData> generateAddedMethodMarker(IJavaProject javaProject, String className, final String methodName, final Delta requiresDelta) throws JavaModelException {
        final List<MarkerData> markers = new LinkedList<MarkerData>();
        final CompilationUnit ast = createAST(javaProject, className);
View Full Code Here


    parser.setStatementsRecovery(true);
    parser.setSource(content);
    parser.setUnitName(fCompilationUnit.getElementName());
    parser.setProject(fCompilationUnit.getJavaProject());

    return (CompilationUnit) parser.createAST(new NullProgressMonitor());
  }
}
View Full Code Here

    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setSource(unit);
    parser.setProject(unit.getJavaProject());
    parser.setResolveBindings(true);
    parser.setStatementsRecovery(true);
    return (CompilationUnit) parser.createAST(mon); // parse
  }

  @SuppressWarnings("unchecked")
  public static <T extends ASTNode> T findAncestor(final ASTNode node, final Class<T> clazz)
  {
View Full Code Here

            }
            String typeDeclaration = "class " + typeNameWithParameters + " {}"; //$NON-NLS-1$//$NON-NLS-2$
            ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
            parser.setSource(typeDeclaration.toCharArray());
            parser.setProject(project);
            CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null);
            IProblem[] problems = compilationUnit.getProblems();
            if (problems.length > 0) {
                status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, problems[0].getMessage()));
                return status;
            }
View Full Code Here

    private CompilationUnit createASTForImports(ICompilationUnit cu) {
        ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
        parser.setSource(cu);
        parser.setResolveBindings(false);
        parser.setFocalPosition(0);
        return (CompilationUnit) parser.createAST(null);
    }

    private Set<String> getExistingImports(CompilationUnit root) {
        @SuppressWarnings("unchecked")
        List<ImportDeclaration> imports = root.imports();
View Full Code Here

    private void removeUnusedImports(ICompilationUnit cu, Set<String> existingImports, boolean needsSave) throws CoreException {
        ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
        parser.setSource(cu);
        parser.setResolveBindings(true);

        CompilationUnit root = (CompilationUnit) parser.createAST(null);
        if (root.getProblems().length == 0) {
            return;
        }

        @SuppressWarnings("unchecked")
View Full Code Here

        String content = CodeGeneration.getCompilationUnitContent(cu, fileComment, typeComment, typeContent, lineDelimiter);
        if (content != null) {
            ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
            parser.setProject(cu.getJavaProject());
            parser.setSource(content.toCharArray());
            CompilationUnit unit = (CompilationUnit) parser.createAST(null);
            if ((pack.isDefaultPackage() || unit.getPackage() != null) && !unit.types().isEmpty()) {
                return content;
            }
        }
        StringBuffer buf = new StringBuffer();
View Full Code Here

        CodeGenerationSettings settings = JavaPreferencesSettings.getCodeGenerationSettings(type.getJavaProject());
        settings.createComments = isAddComments();
        ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
        parser.setResolveBindings(true);
        parser.setSource(cu);
        CompilationUnit unit = (CompilationUnit) parser.createAST(new SubProgressMonitor(monitor, 1));
        final ITypeBinding binding = ASTNodes.getTypeBinding(unit, type);
        if (binding != null) {
            if (doUnimplementedMethods) {
                AddUnimplementedMethodsOperation operation = new AddUnimplementedMethodsOperation(unit, binding, null, -1, false, true, false);
                operation.setCreateComments(isAddComments());
View Full Code Here

    parser.setCompilerOptions(options);

    parser.setEnvironment(classPathEntries.toArray(new String[classPathEntries.size()]),
        sourcePathEntries.toArray(new String[sourcePathEntries.size()]), null, true);

    CompilationUnit cu = (CompilationUnit) parser.createAST(null);

    return cu;
  }

  private char[] getFileContents(ISourceLocation loc, IEvaluatorContext ctx) throws IOException {
View Full Code Here

        parser.setSource(readFileToString().toCharArray());
        parser.setKind(ASTParser.K_COMPILATION_UNIT);

        // For now we only care about the package, parse more data as need
        // arises
        final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
        javaPackage = cu.getPackage();
    }

    private String readFileToString() throws IOException {
        final FileInputStream in = new FileInputStream(javaFile);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.