Example usage for org.eclipse.jdt.internal.core JavaElementDelta JavaElementDelta

List of usage examples for org.eclipse.jdt.internal.core JavaElementDelta JavaElementDelta

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core JavaElementDelta JavaElementDelta.

Prototype

public JavaElementDelta(IJavaElement element) 

Source Link

Document

Creates the root delta.

Usage

From source file:com.redhat.ceylon.eclipse.core.classpath.CeylonClasspathContainer.java

License:Apache License

void notifyUpdateClasspathEntries() {
    // Changes to resolved classpath are not announced by JDT Core
    // and so PackageExplorer does not properly refresh when we update
    // the classpath container.
    // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=154071
    DeltaProcessingState s = JavaModelManager.getJavaModelManager().deltaState;
    synchronized (s) {
        IElementChangedListener[] listeners = s.elementChangedListeners;
        for (int i = 0; i < listeners.length; i++) {
            if (listeners[i] instanceof PackageExplorerContentProvider) {
                JavaElementDelta delta = new JavaElementDelta(javaProject);
                delta.changed(IJavaElementDelta.F_RESOLVED_CLASSPATH_CHANGED);
                listeners[i].elementChanged(new ElementChangedEvent(delta, ElementChangedEvent.POST_CHANGE));
            }/*w  w w.  j  ava 2  s  . c o  m*/
        }
    }
    //I've disabled this because I don't really like having it, but
    //it does seem to help with the issue of archives appearing
    //empty in the package manager
    /*try {
      javaProject.getProject().refreshLocal(IResource.DEPTH_ONE, null);
    } 
    catch (CoreException e) {
      e.printStackTrace();
    }*/
}

From source file:com.redhat.ceylon.eclipse.core.classpath.CeylonProjectModulesContainer.java

License:Apache License

void notifyUpdateClasspathEntries() {
    // Changes to resolved classpath are not announced by JDT Core
    // and so PackageExplorer does not properly refresh when we update
    // the classpath container.
    // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=154071
    DeltaProcessingState s = JavaModelManager.getJavaModelManager().deltaState;
    synchronized (s) {
        IElementChangedListener[] listeners = s.elementChangedListeners;
        for (int i = 0; i < listeners.length; i++) {
            if (listeners[i] instanceof PackageExplorerContentProvider) {
                JavaElementDelta delta = new JavaElementDelta(javaProject);
                delta.changed(IJavaElementDelta.F_RESOLVED_CLASSPATH_CHANGED);
                listeners[i].elementChanged(new ElementChangedEvent(delta, ElementChangedEvent.POST_CHANGE));
            }/*www  .  j  a  v  a 2s.  co  m*/
        }
    }
    //I've disabled this because I don't really like having it, but
    //it does seem to help with the issue of archives appearing
    //empty in the package manager
    /*try {
    javaProject.getProject().refreshLocal(IResource.DEPTH_ONE, null);
    } 
    catch (CoreException e) {
    e.printStackTrace();
    }*/
}

From source file:org.codehaus.jdt.groovy.model.GroovyReconcileWorkingCopyOperation.java

License:Open Source License

public org.eclipse.jdt.core.dom.CompilationUnit makeConsistent(CompilationUnit workingCopy)
        throws JavaModelException {
    if (!workingCopy.isConsistent()) {
        // make working copy consistent
        if (this.problems == null)
            this.problems = new HashMap();
        this.resolveBindings = this.requestorIsActive;
        this.ast = workingCopy.makeConsistent(this.astLevel, this.resolveBindings, this.reconcileFlags,
                this.problems, this.progressMonitor);
        this.deltaBuilder.buildDeltas();
        if (this.ast != null && this.deltaBuilder.delta != null)
            this.deltaBuilder.delta.changedAST(this.ast);
        return this.ast;
    }// w w  w  . j av a  2s .  c  o  m
    if (this.ast != null)
        return this.ast; // no need to recompute AST if known already

    CompilationUnitDeclaration unit = null;
    try {
        JavaModelManager.getJavaModelManager().abortOnMissingSource.set(Boolean.TRUE);
        CompilationUnit source = workingCopy.cloneCachingContents();
        // find problems if needed
        if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject())
                && (this.reconcileFlags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0) {
            this.resolveBindings = this.requestorIsActive;
            if (this.problems == null)
                this.problems = new HashMap();
            unit = CompilationUnitProblemFinder.process(source, this.workingCopyOwner, this.problems,
                    this.astLevel != ICompilationUnit.NO_AST/* creating AST if level is not NO_AST */,
                    this.reconcileFlags, this.progressMonitor);
            // GROOVY cache the ModuleNode in the ModuleNodeMapper
            if (unit instanceof GroovyCompilationUnitDeclaration) {
                // should always be true
                ModuleNodeMapper.getInstance().maybeCacheModuleNode(workingCopy.getPerWorkingCopyInfo(),
                        (GroovyCompilationUnitDeclaration) unit);
            }
            // GROOVY end

            if (this.progressMonitor != null)
                this.progressMonitor.worked(1);
        }

        // create AST if needed
        if (this.astLevel != ICompilationUnit.NO_AST && unit != null/*
                                                                    * unit is null if working copy is consistent && (problem
                                                                    * detection not forced || non-Java project) -> don't create
                                                                    * AST as per API
                                                                    */) {
            Map options = workingCopy.getJavaProject().getOptions(true);
            // convert AST
            this.ast = AST.convertCompilationUnit(this.astLevel, unit, options, this.resolveBindings, source,
                    this.reconcileFlags, this.progressMonitor);
            if (this.ast != null) {
                if (this.deltaBuilder.delta == null) {
                    this.deltaBuilder.delta = new JavaElementDelta(workingCopy);
                }
                this.deltaBuilder.delta.changedAST(this.ast);
            }
            if (this.progressMonitor != null)
                this.progressMonitor.worked(1);
        }
    } catch (JavaModelException e) {
        if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject()))
            throw e;
        // else JavaProject has lost its nature (or most likely was closed/deleted) while reconciling -> ignore
        // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=100919)
    } finally {
        JavaModelManager.getJavaModelManager().abortOnMissingSource.set(null);
        if (unit != null) {
            unit.cleanUp();
        }
    }
    return this.ast;
}

From source file:org.eclipse.ajdt.core.reconcile.AJReconcileWorkingCopyOperation.java

License:Open Source License

public org.eclipse.jdt.core.dom.CompilationUnit makeConsistent(CompilationUnit workingCopy)
        throws JavaModelException {
    if (!workingCopy.isConsistent()) {
        // make working copy consistent
        if (this.problems == null)
            this.problems = new HashMap();
        this.resolveBindings = this.requestorIsActive;
        this.ast = workingCopy.makeConsistent(this.astLevel, this.resolveBindings, reconcileFlags,
                this.problems, this.progressMonitor);
        this.deltaBuilder.buildDeltas();
        if (this.ast != null && this.deltaBuilder.delta != null)
            this.deltaBuilder.delta.changedAST(this.ast);
        return this.ast;
    }/*from   w w w  .  ja  v a  2 s  .  c  o  m*/
    if (this.ast != null)
        return this.ast; // no need to recompute AST if known already

    CompilationUnitDeclaration unit = null;
    try {
        JavaModelManager.getJavaModelManager().abortOnMissingSource.set(Boolean.TRUE);
        CompilationUnit source;
        if (workingCopy instanceof AJCompilationUnit) {
            source = ((AJCompilationUnit) workingCopy).ajCloneCachingContents();
        } else {
            source = workingCopy.cloneCachingContents();
        }
        // find problems if needed
        if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject())
                && (this.reconcileFlags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0) {
            this.resolveBindings = this.requestorIsActive;
            if (this.problems == null)
                this.problems = new HashMap();
            unit = AJCompilationUnitProblemFinder.processAJ(source, this.workingCopyOwner, this.problems,
                    this.astLevel != ICompilationUnit.NO_AST/*creating AST if level is not NO_AST */,
                    reconcileFlags, this.progressMonitor);
            if (this.progressMonitor != null)
                this.progressMonitor.worked(1);
        }

        // create AST if needed
        if (this.astLevel != ICompilationUnit.NO_AST
                && unit != null/*unit is null if working copy is consistent && (problem detection not forced || non-Java project) -> don't create AST as per API*/) {
            Map options = workingCopy.getJavaProject().getOptions(true);
            // convert AST
            this.ast = AST.convertCompilationUnit(this.astLevel, unit, options, this.resolveBindings, source,
                    reconcileFlags, this.progressMonitor);
            if (this.ast != null) {
                if (this.deltaBuilder.delta == null) {
                    this.deltaBuilder.delta = new JavaElementDelta(workingCopy);
                }
                this.deltaBuilder.delta.changedAST(this.ast);
            }
            if (this.progressMonitor != null)
                this.progressMonitor.worked(1);
        }
    } catch (JavaModelException e) {
        if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject()))
            throw e;
        // else JavaProject has lost its nature (or most likely was closed/deleted) while reconciling -> ignore
        // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=100919)
    } finally {
        JavaModelManager.getJavaModelManager().abortOnMissingSource.set(null);
        if (unit != null) {
            unit.cleanUp();
        }
    }
    return this.ast;
}

From source file:org.eclipse.jdt.internal.core.CopyResourceElementsOperation.java

License:Open Source License

/**
 * Returns the <code>JavaElementDelta</code> for <code>javaProject</code>,
 * creating it and putting it in <code>fDeltasPerProject</code> if
 * it does not exist yet./* w ww .  j  a v  a 2 s .c  o  m*/
 */
private JavaElementDelta getDeltaFor(IJavaProject javaProject) {
    JavaElementDelta delta = (JavaElementDelta) this.deltasPerProject.get(javaProject);
    if (delta == null) {
        delta = new JavaElementDelta(javaProject);
        this.deltasPerProject.put(javaProject, delta);
    }
    return delta;
}

From source file:org.jboss.tools.pde.sourcelookup.core.internal.utils.ClasspathUtils.java

License:Open Source License

public static void attachSource(final IPackageFragmentRoot fragment, final IPath newSourcePath,
        IProgressMonitor monitor) {//w  w  w. j  a va 2 s.  c  om
    try {
        if (fragment == null || fragment.getKind() != IPackageFragmentRoot.K_BINARY) {
            return;
        }
        if (!Objects.equals(fragment.getSourceAttachmentPath(), newSourcePath)) {
            // would be so cool if it refreshed the UI automatically
            fragment.attachSource(newSourcePath, null, monitor);
            // close the root so that source attachment cache is flushed. Else UI
            // won't update
            fragment.close();
            // we have to manually fire a delta to notify the UI about the source
            // attachment.
            JavaModelManager manager = JavaModelManager.getJavaModelManager();
            JavaElementDelta attachedSourceDelta = new JavaElementDelta(fragment.getJavaModel());
            attachedSourceDelta.sourceAttached(fragment);
            manager.getDeltaProcessor().fire(attachedSourceDelta, ElementChangedEvent.POST_CHANGE);
        }
    } catch (CoreException e) {
        // ignore
    }
}

From source file:org.maven.ide.eclipse.embedder.BuildPathManager.java

License:Apache License

void setClasspathContainer(Map resolved, IProgressMonitor monitor) throws CoreException {
    monitor.setTaskName("Setting classpath containers");
    for (Iterator it = resolved.entrySet().iterator(); it.hasNext();) {
        Map.Entry entry = (Map.Entry) it.next();
        IJavaProject javaProject = JavaCore.create((IProject) entry.getKey());
        IClasspathContainer container = (IClasspathContainer) entry.getValue();
        if (javaProject != null && container != null) {

            JavaCore.setClasspathContainer(container.getPath(), new IJavaProject[] { javaProject },
                    new IClasspathContainer[] { container }, monitor);

            // XXX In Eclipse 3.3, changes to resolved classpath are not announced by JDT Core
            // and PackageExplorer does not properly refresh when we update Maven
            // classpath container.
            // As a temporary workaround, send F_CLASSPATH_CHANGED notifications
            // to all PackageExplorerContentProvider instances listening to
            // java ElementChangedEvent. 
            // Note that even with this hack, build clean is sometimes necessary to
            // reconcile PackageExplorer with actual classpath
            // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=154071
            if (getJDTVersion().startsWith("3.3")) {
                DeltaProcessingState state = JavaModelManager.getJavaModelManager().deltaState;
                synchronized (state) {
                    IElementChangedListener[] listeners = state.elementChangedListeners;
                    for (int i = 0; i < listeners.length; i++) {
                        if (listeners[i] instanceof PackageExplorerContentProvider) {
                            JavaElementDelta delta = new JavaElementDelta(javaProject);
                            delta.changed(IJavaElementDelta.F_CLASSPATH_CHANGED);
                            listeners[i].elementChanged(
                                    new ElementChangedEvent(delta, ElementChangedEvent.POST_CHANGE));
                        }//from ww w  .j a v  a2 s  .  c  o m
                    }
                }
            }
        }
    }
}