org.eclipse.jdt.core.ElementChangedEvent Java Examples

The following examples show how to use org.eclipse.jdt.core.ElementChangedEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JFaceCompletionProposalComputer.java    From saneclipse with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void elementChanged(ElementChangedEvent event) {
	final IJavaProject javaProject = getCachedJavaProject();
	if (javaProject == null) {
		return;
	}

	final IJavaElementDelta[] children = event.getDelta().getChangedChildren();
	for (int i = 0; i < children.length; i++) {
		final IJavaElementDelta child = children[i];
		if (javaProject.equals(child.getElement())) {
			if (isClasspathChange(child)) {
				setCachedJavaProject(null);
			}
		}
	}
}
 
Example #2
Source File: JavaWorkingSetUpdater.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void elementChanged(ElementChangedEvent event) {
	IWorkingSet[] workingSets;
	synchronized(fWorkingSets) {
		workingSets= fWorkingSets.toArray(new IWorkingSet[fWorkingSets.size()]);
	}
	for (int w= 0; w < workingSets.length; w++) {
		WorkingSetDelta workingSetDelta= new WorkingSetDelta(workingSets[w]);
		processJavaDelta(workingSetDelta, event.getDelta());
		IResourceDelta[] resourceDeltas= event.getDelta().getResourceDeltas();
		if (resourceDeltas != null) {
			for (int r= 0; r < resourceDeltas.length; r++) {
				processResourceDelta(workingSetDelta, resourceDeltas[r]);
			}
		}
		workingSetDelta.process();
	}
}
 
Example #3
Source File: DefaultJavaFoldingStructureProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void elementChanged(ElementChangedEvent e) {
	IJavaElementDelta delta= findElement(fInput, e.getDelta());
	if (delta != null && (delta.getFlags() & (IJavaElementDelta.F_CONTENT | IJavaElementDelta.F_CHILDREN)) != 0) {

		if (shouldIgnoreDelta(e.getDelta().getCompilationUnitAST(), delta))
			return;

		fUpdatingCount++;
		try {
			update(createContext(false));
		} finally {
			fUpdatingCount--;
		}
	}
}
 
Example #4
Source File: JavaElementContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void elementChanged(final ElementChangedEvent event) {
	try {
		processDelta(event.getDelta());
	} catch(JavaModelException e) {
		JavaPlugin.log(e);
	}
}
 
Example #5
Source File: EventManager.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
public void enableListeners() {

		JavaCore.addElementChangedListener(new ClasspathChangeListener(), ElementChangedEvent.POST_CHANGE);

		subscribeResourceListener();
		subscribeWindowListener();
		subscribeEclipseCloseListener();
		subscribeLaunchListener();
	}
 
Example #6
Source File: PackageExplorerContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void elementChanged(final ElementChangedEvent event) {
	final ArrayList<Runnable> runnables= new ArrayList<Runnable>();
	try {
		// 58952 delete project does not update Package Explorer [package explorer]
		// if the input to the viewer is deleted then refresh to avoid the display of stale elements
		if (inputDeleted(runnables))
			return;

		processDelta(event.getDelta(), runnables);
	} catch (JavaModelException e) {
		JavaPlugin.log(e);
	} finally {
		executeRunnables(runnables);
	}
}
 
Example #7
Source File: AbstractJavaElementLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void elementChanged(ElementChangedEvent event) {
	List<IJavaElement> changed= new ArrayList<IJavaElement>();
	processDelta(event.getDelta(), changed);
	if (changed.size() == 0)
		return;

	fireChange(changed.toArray(new IJavaElement[changed.size()]));
}
 
Example #8
Source File: SearchResultUpdater.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void elementChanged(ElementChangedEvent event) {
	//long t0= System.currentTimeMillis();
	IJavaElementDelta delta= event.getDelta();
	Set<IAdaptable> removedElements= new HashSet<IAdaptable>();
	Set<IAdaptable> potentiallyRemovedElements= new HashSet<IAdaptable>();
	collectRemoved(potentiallyRemovedElements, removedElements, delta);
	if (removedElements.size() > 0)
		handleRemoved(removedElements);
	if (potentiallyRemovedElements.size() > 0)
		handleRemoved(potentiallyRemovedElements);
	//System.out.println(this+"handled delta in: "+(System.currentTimeMillis()-t0));
}
 
Example #9
Source File: JavaOutlinePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void elementChanged(final ElementChangedEvent e) {

					if (getControl() == null)
						return;

					Display d= getControl().getDisplay();
					if (d != null) {
						d.asyncExec(new Runnable() {
							public void run() {
								ICompilationUnit cu= (ICompilationUnit) fInput;
								IJavaElement base= cu;
								if (fTopLevelTypeOnly) {
									base= cu.findPrimaryType();
									if (base == null) {
										if (fOutlineViewer != null)
											fOutlineViewer.refresh(true);
										return;
									}
								}
								IJavaElementDelta delta= findElement(base, e.getDelta());
								if (delta != null && fOutlineViewer != null) {
									fOutlineViewer.reconcile(delta);
								}
							}
						});
					}
				}
 
Example #10
Source File: JavaEditorBreadcrumb.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void elementChanged(ElementChangedEvent event) {
	if (fViewer == null)
		return;

	Object input= fViewer.getInput();
	if (!(input instanceof IJavaElement))
		return;

	if (fRunnable != null)
		return;

	final IJavaElement changedElement= getChangedParentElement((IJavaElement) input, event.getDelta());
	if (changedElement == null)
		return;

	fRunnable= new Runnable() {
		public void run() {
			if (fViewer == null)
				return;

			Object newInput= getCurrentInput();
			if (newInput instanceof IJavaElement)
				newInput= getInput((IJavaElement) newInput);

			fViewer.setInput(newInput);
			fRunnable= null;
		}
	};
	fViewer.getControl().getDisplay().asyncExec(fRunnable);
}
 
Example #11
Source File: TypeHierarchyLifeCycle.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void elementChanged(ElementChangedEvent event) {
	if (fChangeListeners.isEmpty()) {
		return;
	}

	if (fHierarchyRefreshNeeded) {
		return;
	} else {
		ArrayList<IType> changedTypes= new ArrayList<IType>();
		processDelta(event.getDelta(), changedTypes);
		if (changedTypes.size() > 0) {
			fireChange(changedTypes.toArray(new IType[changedTypes.size()]));
		}
	}
}
 
Example #12
Source File: SWTTemplateCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void elementChanged(ElementChangedEvent event) {
	IJavaProject javaProject= getCachedJavaProject();
	if (javaProject == null)
		return;

	IJavaElementDelta[] children= event.getDelta().getChangedChildren();
	for (int i= 0; i < children.length; i++) {
		IJavaElementDelta child= children[i];
		if (javaProject.equals(child.getElement())) {
			if (isClasspathChange(child)) {
				setCachedJavaProject(null);
			}
		}
	}
}
 
Example #13
Source File: JavaReconciler.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void elementChanged(ElementChangedEvent event) {
	if (isRunningInReconcilerThread())
		return;

	if (event.getDelta().getFlags() == IJavaElementDelta.F_AST_AFFECTED || canIgnore(event.getDelta().getAffectedChildren()))
		return;

	setJavaModelChanged(true);
	if (isEditorActive())
		JavaReconciler.this.forceReconciling();
}
 
Example #14
Source File: JavaStructureDiffViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void elementChanged(ElementChangedEvent event) {
	ITypedElement[] elements= findAffectedElement(event);
	for (int i= 0; i < elements.length; i++) {
		ITypedElement e= elements[i];
		if (e == null || !(e instanceof IContentChangeNotifier))
			continue;
		contentChanged((IContentChangeNotifier)e);
	}
}
 
Example #15
Source File: JavaStructureDiffViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Tells which elements of the comparison are affected by the change.
 * 
 * @param event element changed event
 * @return array of typed elements affected by the event. May return an empty array.
 * @since 3.5
 */
private ITypedElement[] findAffectedElement(ElementChangedEvent event) {
	Object input= getInput();
	if (!(input instanceof ICompareInput))
		return new ITypedElement[0];

	Set<ITypedElement> affectedElements= new HashSet<ITypedElement>();
	ICompareInput ci= (ICompareInput)input;
	IJavaElementDelta delta= event.getDelta();
	addAffectedElement(ci.getAncestor(), delta, affectedElements);
	addAffectedElement(ci.getLeft(), delta, affectedElements);
	addAffectedElement(ci.getRight(), delta, affectedElements);

	return affectedElements.toArray(new ITypedElement[affectedElements.size()]);
}
 
Example #16
Source File: LogicalPackagesProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void elementChanged(ElementChangedEvent event) {
	try {
		processDelta(event.getDelta());
	} catch (JavaModelException e) {
		JavaPlugin.log(e);
	}
}
 
Example #17
Source File: JavaBrowsingContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void elementChanged(final ElementChangedEvent event) {
	try {
		processDelta(event.getDelta());
	} catch(JavaModelException e) {
		JavaPlugin.log(e.getStatus());
	}
}
 
Example #18
Source File: OthersWorkingSetUpdater.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void init(WorkingSetModel model) {
	fWorkingSetModel= model;
	fResourceChangeListener= new ResourceChangeListener();
	ResourcesPlugin.getWorkspace().addResourceChangeListener(fResourceChangeListener, IResourceChangeEvent.POST_CHANGE);
	fWorkingSetListener= new WorkingSetListener();
	PlatformUI.getWorkbench().getWorkingSetManager().addPropertyChangeListener(fWorkingSetListener);
	fJavaElementChangeListener= new JavaElementChangeListener();
	JavaCore.addElementChangedListener(fJavaElementChangeListener, ElementChangedEvent.POST_CHANGE);
}
 
Example #19
Source File: DuplicatedCode.java    From JDeodorant with MIT License 5 votes vote down vote up
public void elementChanged(ElementChangedEvent event) {
	final IJavaElementDelta delta = event.getDelta();
	Display.getDefault().syncExec(new Runnable() {
	    public void run() {
	    	processDelta(delta);
	    }
	});
}
 
Example #20
Source File: ElementChangeListener.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public void elementChanged(ElementChangedEvent event) {
  final Map<IJavaElement, IJavaElementDelta> changedElements = new HashMap<IJavaElement, IJavaElementDelta>();

  JavaModelSearch.visitJavaElementDelta(event.getDelta(),
      new IJavaElementDeltaVisitor() {
        public boolean visit(IJavaElementDelta delta) {
          IJavaElement element = delta.getElement();

          /*
           * We care about packages being only added or removed because if we
           * called the change listeners on a change to a package, any change
           * to any file in that package will cause all ui.xml files that
           * reference that package (say with xmlns urn imports) to be
           * revalidated. Some projects end up having hundreds of ui.xml files
           * referencing a package, and then saving any change in that package
           * ends up taking tens of seconds.
           */
          int type = element.getElementType();
          if (type == IJavaElement.PACKAGE_FRAGMENT
              && delta.getKind() == IJavaElementDelta.CHANGED) {
            return true;
          }

          Set<IReference> references = referenceManager.getReferencesWithMatchingJavaElement(
              element, EnumSet.of(ReferenceLocationType.TARGET));
          if (references != null && references.size() > 0) {
            changedElements.put(element, delta);
          }
          return true;
        }
      });

  if (changedElements.size() > 0) {
    callReferenceChangeListeners(changedElements);
  }
}
 
Example #21
Source File: ClasspathChangedListener.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public void elementChanged(ElementChangedEvent event) {
  for (IJavaElementDelta delta : event.getDelta().getChangedChildren()) {
    int flags = delta.getFlags();
    if ((flags & IJavaElementDelta.F_CLASSPATH_CHANGED) != 0) {
      IJavaElement element = delta.getElement();
      if (element.getElementType() != IJavaElement.JAVA_PROJECT) {
        continue;
      }

      classpathChanged((IJavaProject) element);
    }
  }
}
 
Example #22
Source File: JavaEditorExtension.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public String waitForElementChangedEvent(final int eventMask, final Procedure0 producer) {
  String _xblockexpression = null;
  {
    if ((JavaEditorExtension.VERBOSE).booleanValue()) {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("start waiting for an element changed event: ");
      _builder.append(eventMask);
      InputOutput.<String>println(_builder.toString());
    }
    final ArrayList<Boolean> changed = CollectionLiterals.<Boolean>newArrayList(Boolean.valueOf(false));
    final IElementChangedListener _function = new IElementChangedListener() {
      @Override
      public void elementChanged(final ElementChangedEvent it) {
        JavaCore.removeElementChangedListener(this);
        Boolean _head = IterableExtensions.<Boolean>head(changed);
        boolean _not = (!(_head).booleanValue());
        if (_not) {
          changed.set(0, Boolean.valueOf(true));
          if ((JavaEditorExtension.VERBOSE).booleanValue()) {
            InputOutput.<ElementChangedEvent>println(it);
          }
        }
      }
    };
    JavaCore.addElementChangedListener(_function, eventMask);
    producer.apply();
    while ((!(IterableExtensions.<Boolean>head(changed)).booleanValue())) {
    }
    String _xifexpression = null;
    if ((JavaEditorExtension.VERBOSE).booleanValue()) {
      StringConcatenation _builder_1 = new StringConcatenation();
      _builder_1.append("end waiting for an element changed event: ");
      _builder_1.append(eventMask);
      _xifexpression = InputOutput.<String>println(_builder_1.toString());
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example #23
Source File: AbstractQueuedBuildDataTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();
  JdtQueuedBuildData _jdtQueuedBuildData = new JdtQueuedBuildData();
  this.queuedBuildDataContribution = _jdtQueuedBuildData;
  QueuedBuildData _queuedBuildData = new QueuedBuildData(this.mapper, this.queuedBuildDataContribution);
  this.queuedBuildData = _queuedBuildData;
  JavaChangeQueueFiller _javaChangeQueueFiller = new JavaChangeQueueFiller(this.queuedBuildData, this.converter);
  this.queueFiller = _javaChangeQueueFiller;
  JavaCore.addElementChangedListener(this.queueFiller, ElementChangedEvent.POST_CHANGE);
}
 
Example #24
Source File: ClasspathUpdateHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void elementChanged(ElementChangedEvent event) {
	// Collect project names which have classpath changed.
	Set<String> uris = processDelta(event.getDelta(), null);
	if (connection != null && uris != null && !uris.isEmpty()) {
		for (String uri : uris) {
			EventNotification notification = new EventNotification().withType(EventType.ClasspathUpdated).withData(uri);
			this.connection.sendEventNotification(notification);
		}
	}
}
 
Example #25
Source File: TypeResourceUnloaderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Wait explicitly for an {@link ElementChangedEvent} that is propagated when the given Callable is executed.
 * May also be used to assert that no such event occurred. 
 */
protected <T> T waitForElementChangedEvent(Callable<T> callMe, boolean expectEvent) throws Exception {
	class Listener implements IElementChangedListener {
		private volatile boolean eventSeen = false;
		@Override
		public void elementChanged(ElementChangedEvent event) {
			eventSeen = true;
			JavaCore.removeElementChangedListener(this);
		}
	}
	Listener listener = new Listener();
	JavaCore.addElementChangedListener(listener);
	try {
		return callMe.call();
	} finally {
		// usually a counter of 100 is way more than enough, but on the CI server we see a longer
		// delay, maybe the threading model on linux is slightly different. Anyway, the overall runtime
		// on dev boxes is not affected but the test is green on the server
		long before = System.currentTimeMillis();
		int counter = expectEvent ? 350 : 150;
		while(!listener.eventSeen && counter > 0) {
			counter--;
			Thread.sleep(15);
		}
		long timeWaited = System.currentTimeMillis() - before;
		assertEquals("Waited "+timeWaited+"ms.", expectEvent, listener.eventSeen);
	}
}
 
Example #26
Source File: AbstractJavaProjectsState.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void elementChanged(ElementChangedEvent event) {
	if (event.getDelta() != null) {
		if (isAffectingPackageFragmentRoots(event.getDelta())) {
			initialize();
		}
	}
}
 
Example #27
Source File: JavaChangeQueueFiller.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void elementChanged(ElementChangedEvent event) {
	List<Delta> deltas = deltaConverter.convert(event.getDelta());
	if (deltas != null && !deltas.isEmpty()) {
		queue.queueChanges(deltas);
	}
}
 
Example #28
Source File: ListenerRegistrar.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void initialize() {
	typeResourceUnloader.addListener(eventBroker);
	JavaCore.addElementChangedListener(
			typeResourceUnloader,
			ElementChangedEvent.POST_RECONCILE);

	JavaCore.addElementChangedListener(
			javaChangeQueueFiller,
			ElementChangedEvent.POST_CHANGE);
}
 
Example #29
Source File: ElementChangeListener.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Starts tracking element changes.
 */
void start() {
  JavaCore.addElementChangedListener(this, ElementChangedEvent.POST_CHANGE);
}
 
Example #30
Source File: Activator.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
@Override
public void elementChanged(ElementChangedEvent event) {
  visit(event.getDelta());
}