Example usage for org.eclipse.jdt.core ICompilationUnit reconcile

List of usage examples for org.eclipse.jdt.core ICompilationUnit reconcile

Introduction

In this page you can find the example usage for org.eclipse.jdt.core ICompilationUnit reconcile.

Prototype

CompilationUnit reconcile(int astLevel, boolean forceProblemDetection, boolean enableStatementsRecovery,
        WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;

Source Link

Document

Reconciles the contents of this working copy, sends out a Java delta notification indicating the nature of the change of the working copy since the last time it was either reconciled or made consistent ( IOpenable#makeConsistent(IProgressMonitor) ), and returns a compilation unit AST if requested.

Usage

From source file:org.eclipse.che.jdt.quickfix.QuickFixTest.java

License:Open Source License

protected static final ArrayList collectCorrections2(ICompilationUnit cu, int nProblems) throws CoreException {

    final ArrayList problemsList = new ArrayList();
    final IProblemRequestor requestor = new IProblemRequestor() {
        public void acceptProblem(IProblem problem) {
            problemsList.add(problem);/*from w  w  w. j a  v  a 2  s. c  o m*/
        }

        public void beginReporting() {
            problemsList.clear();
        }

        public void endReporting() {
        }

        public boolean isActive() {
            return true;
        }
    };

    WorkingCopyOwner workingCopyOwner = new WorkingCopyOwner() {
        public IProblemRequestor getProblemRequestor(ICompilationUnit workingCopy) {
            return requestor;
        }
    };
    ICompilationUnit wc = cu.getWorkingCopy(workingCopyOwner, null);
    try {
        wc.reconcile(ICompilationUnit.NO_AST, true, true, wc.getOwner(), null);
    } finally {
        wc.discardWorkingCopy();
    }

    IProblem[] problems = (IProblem[]) problemsList.toArray(new IProblem[problemsList.size()]);
    assertNumberOfProblems(nProblems, problems);

    return collectCorrections(cu, problems[0], null);
}

From source file:org.eclipse.pde.api.tools.ui.internal.completion.APIToolsJavadocCompletionProposalComputer.java

License:Open Source License

/**
 * Collects the existing tags on the {@link IJavaElement} we have been
 * activated on/*from  ww  w .  ja v  a2 s  .c  o  m*/
 * 
 * @param element
 * @param jcontext
 * @throws JavaModelException
 * @throws BadLocationException
 */
private void collectExistingTags(IJavaElement element, JavaContentAssistInvocationContext jcontext)
        throws JavaModelException {
    if (element instanceof IMember) {
        IMember member = (IMember) element;
        ICompilationUnit cunit = jcontext.getCompilationUnit();
        if (cunit != null) {
            if (cunit.isWorkingCopy()) {
                cunit.reconcile(ICompilationUnit.NO_AST, false, false, null, null);
            }
            fParser.setSource(member.getSource().toCharArray());
            fParser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
            Map<String, String> options = element.getJavaProject().getOptions(true);
            options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
            fParser.setCompilerOptions(options);
            fParser.setStatementsRecovery(false);
            fParser.setResolveBindings(false);
            fParser.setBindingsRecovery(false);
            ASTNode ast = fParser.createAST(null);
            TagCollector collector = new TagCollector();
            if (ast.getNodeType() == ASTNode.TYPE_DECLARATION) {
                TypeDeclaration typeDeclaration = (TypeDeclaration) ast;
                List<BodyDeclaration> bodyDeclarations = typeDeclaration.bodyDeclarations();
                if (bodyDeclarations.size() == 1) {
                    // only one element should be there as we are parsing a
                    // specific member
                    BodyDeclaration bodyDeclaration = bodyDeclarations.iterator().next();
                    Javadoc javadoc = bodyDeclaration.getJavadoc();
                    if (javadoc != null) {
                        javadoc.accept(collector);
                    }
                }
            }
        }
    }
}