Example usage for org.eclipse.jdt.core IJavaElementDelta getCompilationUnitAST

List of usage examples for org.eclipse.jdt.core IJavaElementDelta getCompilationUnitAST

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaElementDelta getCompilationUnitAST.

Prototype

public CompilationUnit getCompilationUnitAST();

Source Link

Document

Returns the compilation unit AST created by the last reconcile operation on this delta's element.

Usage

From source file:org.eclipse.jpt.jpa.core.internal.AbstractJpaProject.java

License:Open Source License

protected void processJavaCompilationUnitDelta(IJavaElementDelta delta) {
    if (javaCompilationUnitDeltaIsRelevant(delta)) {
        ICompilationUnit compilationUnit = (ICompilationUnit) delta.getElement();
        for (JavaResourceCompilationUnit jrcu : this.getCombinedJavaResourceCompilationUnits()) {
            if (jrcu.getCompilationUnit().equals(compilationUnit)) {
                CompilationUnit astRoot = delta.getCompilationUnitAST(); //this will be null for POST_CHANGE jdt events
                //I don't think we can guarantee hasResolvedBindings() is true, so check for this and don't pass it in if false.
                if (astRoot != null && astRoot.getAST().hasResolvedBindings()) {

                    jrcu.synchronizeWithJavaSource(astRoot);
                } else {
                    jrcu.synchronizeWithJavaSource();
                }//from  w  ww.  ja  v a  2 s  .c  om
                // TODO ? this.resolveJavaTypes();  // might have new member types now...
                break; // there *shouldn't* be any more...
            }
        }
    }
    // ignore the java compilation unit's children
}

From source file:org.eclipse.recommenders.internal.rcp.CachingAstProvider.java

License:Open Source License

@Override
public void elementChanged(final ElementChangedEvent event) {
    final IJavaElementDelta delta = event.getDelta();
    final CompilationUnit ast = delta.getCompilationUnitAST();
    if (ast == null) {
        return;//from   w ww  .j a  va  2  s .  c o  m
    }
    final ICompilationUnit cu = cast(ast.getJavaElement());
    if (cu == null) {
        return;
    }
    cache.put(cu, ast);
}

From source file:org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JavaElementDeltaScanner.java

License:Open Source License

/**
 * Returns the {@link CompilationUnit} associated with the
 * {@link IJavaElement} of the given {@link IJavaElementDelta}.
 * /* w  w  w  .ja va 2  s .  c om*/
 * @param delta the given Java Element Delta
 * @return the associated Compilation Unit AST or null
 * @throws JavaModelException
 */
private CompilationUnit getCompilationUnitAST(final IJavaElementDelta delta) throws JavaModelException {
    CompilationUnit compilationUnitAST = null;
    final IJavaElement element = delta.getElement();
    compilationUnitAST = delta.getCompilationUnitAST();
    if (compilationUnitAST == null) {
        //compilationUnitAST = compilationUnitsRepository.getAST(compilationUnit);
        compilationUnitAST = JdtUtils.parse(element, new NullProgressMonitor());
    }
    return compilationUnitAST;
}