Java Code Examples for org.eclipse.jdt.core.IJavaElementDelta#getFlags()

The following examples show how to use org.eclipse.jdt.core.IJavaElementDelta#getFlags() . 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: ResourceChangedManager.java    From ContentAssist with MIT License 6 votes vote down vote up
/**
 * Creates a macro corresponding to the added delta of the change.
 * @param time the time when the change occurred
 * @param delta the added delta of the change
 * @return the created resource macro
 */
private ResourceMacro createResourceAddedMacro(long time, IJavaElementDelta delta) {
    IJavaElement elem = delta.getElement();
    String path = elem.getPath().toString();
    if (path == null) {
        return null;
    }
    
    String type = "Added";
    if ((delta.getFlags() & IJavaElementDelta.F_MOVED_FROM) != 0) {
        if (isRenamed(delta.getElement(), delta.getMovedFromElement())) {
            type = "RenamedFrom";
        } else {
            type = "MovedFrom";
        }
    }
    
    return new ResourceMacro(time, type, path, elem);
}
 
Example 2
Source File: JFaceCompletionProposalComputer.java    From saneclipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Does the delta indicate a classpath change?
 *
 * @param delta the delta to inspect
 * @return true if classpath has changed
 */
private boolean isClasspathChange(IJavaElementDelta delta) {
	final int flags = delta.getFlags();
	if (isClasspathChangeFlag(flags)) {
		return true;
	}

	if ((flags & IJavaElementDelta.F_CHILDREN) != 0) {
		final IJavaElementDelta[] children = delta.getAffectedChildren();
		for (int i = 0; i < children.length; i++) {
			if (isClasspathChangeFlag(children[i].getFlags())) {
				return true;
			}
		}
	}

	return false;
}
 
Example 3
Source File: DeltaConverter.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.5
 */
protected void convertChangedCompilationUnit(IJavaElementDelta delta, List<IResourceDescription.Delta> result) {
	if ((delta.getFlags() & IJavaElementDelta.F_PRIMARY_WORKING_COPY) != 0) {
		return;
	}
	TypeNames typeNames = getTypeNamesFromIndex(delta);
	
	ICompilationUnit compilationUnit = (ICompilationUnit) delta.getElement();
	try {

		boolean hasDerivedType = doForeachCompilationUnitChildType(compilationUnit, true, type -> {
			String typeName = type.getFullyQualifiedName();
			URI topLevelURI = uriHelper.createResourceURIForFQN(typeName);
			convertChangedTypeAndChildren(result, typeNames, type, topLevelURI);
		});
		
		if (hasDerivedType)
			return;
		
		convertRemovedTypes(typeNames, result);
	} catch (JavaModelException e) {
		if (LOGGER.isDebugEnabled()) {
			LOGGER.debug(e, e);
		}
	}
}
 
Example 4
Source File: JavaProjectClasspathChangeAnalyzer.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * determines if the delta is a relevant change on a IPackageFragmentRoot
 * 
 * @param delta
 *            the IJavaElementDelta to analyze. the deltas element must be an instance of IPackageFragmentRoot
 */
public boolean isRelevantPackageFragmentRootChange(IJavaElementDelta delta) {
	IJavaElement element = delta.getElement();
	assert (element instanceof IPackageFragmentRoot);
	return delta.getKind() == IJavaElementDelta.REMOVED 
			|| delta.getKind() == IJavaElementDelta.ADDED
			|| (delta.getFlags() & IJavaElementDelta.F_REORDER) != 0
			|| (delta.getFlags() & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) != 0
			|| (delta.getFlags() & IJavaElementDelta.F_ADDED_TO_CLASSPATH) != 0
			|| (
					(
						((IPackageFragmentRoot) element).isExternal() 
						|| ((IPackageFragmentRoot) element).isArchive()
					) && 
					(
						delta.getFlags() & // external folders change
						(IJavaElementDelta.F_CONTENT | IJavaElementDelta.F_ARCHIVE_CONTENT_CHANGED)
					) == delta.getFlags()
			);
}
 
Example 5
Source File: Activator.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
private void visit(IJavaElementDelta delta) {
  switch (delta.getElement().getElementType()) {
    case IJavaElement.JAVA_PROJECT:
      if ((delta.getFlags() & IJavaElementDelta.F_CLASSPATH_CHANGED) != 0) {
        final IJavaProject javaProject = (IJavaProject) delta.getElement();
        Job updateContainerStateJob = new WorkspaceJob("Updating Google Cloud libraries") {
          @Override
          public IStatus runInWorkspace(IProgressMonitor monitor) {
            BuildPath.checkLibraryList(javaProject, null);
            return Status.OK_STATUS;
          }
        };
        IWorkspace workspace = javaProject.getProject().getWorkspace();
        ISchedulingRule buildRule = workspace.getRuleFactory().buildRule();
        updateContainerStateJob.setRule(buildRule);
        updateContainerStateJob.setSystem(true);
        updateContainerStateJob.schedule();
      }
      break;
    case IJavaElement.JAVA_MODEL:
      visitChildren(delta);
      break;
    default:
      break;
  }
}
 
Example 6
Source File: ElementChangedListener.java    From JDeodorant with MIT License 5 votes vote down vote up
private void processDelta(IJavaElementDelta delta) {
	IJavaElement javaElement = delta.getElement();
	switch(javaElement.getElementType()) {
	case IJavaElement.JAVA_MODEL:
	case IJavaElement.JAVA_PROJECT:
	case IJavaElement.PACKAGE_FRAGMENT_ROOT:
	case IJavaElement.PACKAGE_FRAGMENT:
		IJavaElementDelta[] affectedChildren = delta.getAffectedChildren();
		for(IJavaElementDelta affectedChild : affectedChildren) {
			processDelta(affectedChild);
		}
		break;
	case IJavaElement.COMPILATION_UNIT:
		ICompilationUnit compilationUnit = (ICompilationUnit)javaElement;
		if(delta.getKind() == IJavaElementDelta.ADDED) {
			CompilationUnitCache.getInstance().compilationUnitAdded(compilationUnit);
		}
		else if(delta.getKind() == IJavaElementDelta.REMOVED) {
			CompilationUnitCache.getInstance().compilationUnitRemoved(compilationUnit);
		}
		else if(delta.getKind() == IJavaElementDelta.CHANGED) {
			if((delta.getFlags() & IJavaElementDelta.F_FINE_GRAINED) != 0) {
				CompilationUnitCache.getInstance().compilationUnitChanged(compilationUnit);
			}
		}
	}
}
 
Example 7
Source File: DeltaConverter.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @return a possibly empty list of converted deltas.
 */
public List<IResourceDescription.Delta> convert(IJavaElementDelta delta) {
	/*
	 * a file was opened or closed or there is no relevant structural change in the delta
	 * - we do not expect an IResourceDescription.Delta
	 * 
	 * Deltas without any affected children or without content changes
	 * are considered to be irrelevant
	 */
	if (delta.getFlags() == IJavaElementDelta.F_AST_AFFECTED
			|| delta.getFlags() == (IJavaElementDelta.F_AST_AFFECTED | IJavaElementDelta.F_CONTENT | IJavaElementDelta.F_FINE_GRAINED)) {
		return Collections.emptyList();
	}
	try {
		List<IResourceDescription.Delta> result = Lists.newArrayListWithExpectedSize(2);
		convertCompilationUnits(delta, result);
		return result;
	} catch (Throwable throwable) {
		if (throwable instanceof VirtualMachineError) {
			throw (VirtualMachineError) throwable;
		}
		if (LOGGER.isEnabledFor(Level.ERROR)) {
			LOGGER.error(throwable.getMessage(), throwable);
		}
		return Collections.emptyList();
	}
}
 
Example 8
Source File: ResourceChangedManager.java    From ContentAssist with MIT License 5 votes vote down vote up
/**
 * Creates a macro corresponding to the changed delta of the change.
 * @param time the time when the change occurred
 * @param delta the changed delta of the change
 * @return the created resource macro
 */
private ResourceMacro createResourceChangedMacro(long time, IJavaElementDelta delta) {
    IJavaElement elem = delta.getElement();
    String path = elem.getPath().toString();
    if (path == null) {
        return null;
    }
    
    if ((delta.getFlags() & IJavaElementDelta.F_CONTENT) != 0) {
        // System.out.println("CONTENT CHANGED" + path);
        return null;
    }
    
    return new ResourceMacro(time, "Changed", path, elem);
}
 
Example 9
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 10
Source File: LogicalPackagesProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected boolean isClassPathChange(IJavaElementDelta delta) {

		// need to test the flags only for package fragment roots
		if (delta.getElement().getElementType() != IJavaElement.PACKAGE_FRAGMENT_ROOT)
			return false;

		int flags= delta.getFlags();
		return (delta.getKind() == IJavaElementDelta.CHANGED &&
			((flags & IJavaElementDelta.F_ADDED_TO_CLASSPATH) != 0) ||
			 ((flags & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) != 0) ||
			 ((flags & IJavaElementDelta.F_REORDER) != 0));
	}
 
Example 11
Source File: JavaWorkingSetUpdater.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void processJavaDelta(WorkingSetDelta result, IJavaElementDelta delta) {
	IJavaElement jElement= delta.getElement();
	int index= result.indexOf(jElement);
	int type= jElement.getElementType();
	int kind= delta.getKind();
	int flags= delta.getFlags();
	if (type == IJavaElement.JAVA_PROJECT && kind == IJavaElementDelta.CHANGED) {
		if (index != -1 && (flags & IJavaElementDelta.F_CLOSED) != 0) {
			result.set(index, ((IJavaProject)jElement).getProject());
		} else if ((flags & IJavaElementDelta.F_OPENED) != 0) {
			index= result.indexOf(((IJavaProject)jElement).getProject());
			if (index != -1)
				result.set(index, jElement);
		}
	}
	if (index != -1) {
		if (kind == IJavaElementDelta.REMOVED) {
			if ((flags & IJavaElementDelta.F_MOVED_TO) != 0) {
				result.set(index, delta.getMovedToElement());
			} else {
				result.remove(index);
			}
		}
	}
	IResourceDelta[] resourceDeltas= delta.getResourceDeltas();
	if (resourceDeltas != null) {
		for (int i= 0; i < resourceDeltas.length; i++) {
			processResourceDelta(result, resourceDeltas[i]);
		}
	}
	IJavaElementDelta[] children= delta.getAffectedChildren();
	for (int i= 0; i < children.length; i++) {
		processJavaDelta(result, children[i]);
	}
}
 
Example 12
Source File: BuildpathIndicatorLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void processDelta(IJavaElementDelta delta, List<IJavaElement> result) {
	IJavaElement elem= delta.getElement();

	boolean isChanged= delta.getKind() == IJavaElementDelta.CHANGED;
	boolean isRemoved= delta.getKind() == IJavaElementDelta.REMOVED;
	int flags= delta.getFlags();

	switch (elem.getElementType()) {
		case IJavaElement.JAVA_MODEL:
			processChildrenDelta(delta, result);
			return;
		case IJavaElement.JAVA_PROJECT:
			if (isRemoved || (isChanged &&
					(flags & IJavaElementDelta.F_CLOSED) != 0)) {
				return;
			}
			processChildrenDelta(delta, result);
			return;
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			if (isRemoved) {
				return;
			}
			try {
				if ((((flags & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) != 0) ||
						((flags & IJavaElementDelta.F_ADDED_TO_CLASSPATH) != 0))
						&& ((IPackageFragmentRoot)elem).getKind() != IPackageFragmentRoot.K_SOURCE) {
					result.add(elem);
				}
			} catch (JavaModelException e) {
				// don't update
			}
			return;
		default:
			return;
	}
}
 
Example 13
Source File: JavaOutlinePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isPossibleStructuralChange(IJavaElementDelta cuDelta) {
	if (cuDelta.getKind() != IJavaElementDelta.CHANGED) {
		return true; // add or remove
	}
	int flags= cuDelta.getFlags();
	if ((flags & IJavaElementDelta.F_CHILDREN) != 0) {
		return true;
	}
	return (flags & (IJavaElementDelta.F_CONTENT | IJavaElementDelta.F_FINE_GRAINED)) == IJavaElementDelta.F_CONTENT;
}
 
Example 14
Source File: InterfaceIndicatorLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void processDelta(IJavaElementDelta delta, List<IJavaElement> result) {
	IJavaElement elem= delta.getElement();

	boolean isChanged= delta.getKind() == IJavaElementDelta.CHANGED;
	boolean isRemoved= delta.getKind() == IJavaElementDelta.REMOVED;
	int flags= delta.getFlags();

	switch (elem.getElementType()) {
		case IJavaElement.JAVA_PROJECT:
			if (isRemoved || (isChanged &&
					(flags & IJavaElementDelta.F_CLOSED) != 0)) {
				return;
			}
			processChildrenDelta(delta, result);
			return;
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			if (isRemoved || (isChanged && (
					(flags & IJavaElementDelta.F_ARCHIVE_CONTENT_CHANGED) != 0 ||
					(flags & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) != 0))) {
				return;
			}
			processChildrenDelta(delta, result);
			return;
		case IJavaElement.PACKAGE_FRAGMENT:
			if (isRemoved)
				return;
			processChildrenDelta(delta, result);
			return;
		case IJavaElement.TYPE:
		case IJavaElement.CLASS_FILE:
			return;
		case IJavaElement.JAVA_MODEL:
			processChildrenDelta(delta, result);
			return;
		case IJavaElement.COMPILATION_UNIT:
			// Not the primary compilation unit. Ignore it
			if (!JavaModelUtil.isPrimary((ICompilationUnit) elem)) {
				return;
			}

			if (isChanged &&  ((flags & IJavaElementDelta.F_CONTENT) != 0 || (flags & IJavaElementDelta.F_FINE_GRAINED) != 0)) {
				if (delta.getAffectedChildren().length == 0)
					return;

				result.add(elem);
			}
			return;
		default:
			// fields, methods, imports ect
			return;
	}
}
 
Example 15
Source File: JavaProjectClasspathChangeAnalyzer.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
private boolean isAttachmentChangeFlagOnly(IJavaElementDelta child) {
	// change is sourceattached or sourcedetached or sourceattached and sourcedetached at the same time
	return child.getFlags() == IJavaElementDelta.F_SOURCEATTACHED
			 || child.getFlags() == IJavaElementDelta.F_SOURCEDETACHED
			|| child.getFlags() == IJavaElementDelta.F_SOURCEDETACHED + IJavaElementDelta.F_SOURCEATTACHED;
}
 
Example 16
Source File: OpenTypeHistory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Computes whether the history needs a consistency check or not.
 *
 * @param delta the Java element delta
 *
 * @return <code>true</code> if consistency must be checked
 *  <code>false</code> otherwise.
 */
private boolean processDelta(IJavaElementDelta delta) {
	IJavaElement elem= delta.getElement();

	boolean isChanged= delta.getKind() == IJavaElementDelta.CHANGED;
	boolean isRemoved= delta.getKind() == IJavaElementDelta.REMOVED;

	switch (elem.getElementType()) {
		case IJavaElement.JAVA_PROJECT:
			if (isRemoved || (isChanged &&
					(delta.getFlags() & IJavaElementDelta.F_CLOSED) != 0)) {
				return true;
			}
			return processChildrenDelta(delta);
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			if (isRemoved || (isChanged && (
					(delta.getFlags() & IJavaElementDelta.F_ARCHIVE_CONTENT_CHANGED) != 0 ||
					(delta.getFlags() & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) != 0))) {
				return true;
			}
			return processChildrenDelta(delta);
		case IJavaElement.TYPE:
			if (isChanged && (delta.getFlags() & IJavaElementDelta.F_MODIFIERS) != 0) {
				return true;
			}
			if (isRemoved) {
				return true;
			}
			return processChildrenDelta(delta);
		case IJavaElement.JAVA_MODEL:
		case IJavaElement.PACKAGE_FRAGMENT:
		case IJavaElement.CLASS_FILE:
			if (isRemoved) {
				return true;
			}
			return processChildrenDelta(delta);
		case IJavaElement.COMPILATION_UNIT:
			// Not the primary compilation unit. Ignore it
			if (!JavaModelUtil.isPrimary((ICompilationUnit) elem)) {
				return false;
			}

			if (isRemoved || (isChanged && isUnknownStructuralChange(delta.getFlags()))) {
				return true;
			}
			return processChildrenDelta(delta);
		default:
			// fields, methods, imports ect
			return false;
	}
}
 
Example 17
Source File: JavaEditorBreadcrumb.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private boolean onlyChildrenChanged(IJavaElementDelta delta) {
	if (delta.getKind() != IJavaElementDelta.CHANGED)
		return false;

	return (delta.getFlags() & ~IJavaElementDelta.F_FINE_GRAINED) == IJavaElementDelta.F_CHILDREN;
}
 
Example 18
Source File: ClassFileDocumentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Recursively check whether the class file has been deleted.
 * 
 * @param input the package fragment root
 * @param delta the Java element delta
 * @return <code>true</code> if delta processing can be stopped
 */
protected boolean check(IPackageFragmentRoot input, IJavaElementDelta delta) {
	IJavaElement element= delta.getElement();

	if ((delta.getKind() & IJavaElementDelta.REMOVED) != 0 || (delta.getFlags() & IJavaElementDelta.F_CLOSED) != 0) {
		// http://dev.eclipse.org/bugs/show_bug.cgi?id=19023
		if (element.equals(input.getJavaProject()) || element.equals(input)) {
			handleDeleted(fInput);
			return true;
		}
	}

	if (((delta.getFlags() & IJavaElementDelta.F_ARCHIVE_CONTENT_CHANGED) != 0) && input.equals(element)) {
		handleDeleted(fInput);
		return true;
	}

	if (((delta.getFlags() & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) != 0) && input.equals(element)) {
		handleDeleted(fInput);
		return true;
	}

	IJavaElementDelta[] subdeltas= delta.getAffectedChildren();
	for (int i= 0; i < subdeltas.length; i++) {
		if (check(input, subdeltas[i]))
			return true;
	}

	if ((delta.getFlags() & IJavaElementDelta.F_SOURCEDETACHED) != 0 ||
		(delta.getFlags() & IJavaElementDelta.F_SOURCEATTACHED) != 0)
	{
		IClassFile file= fInput != null ? fInput.getClassFile() : null;
		IJavaProject project= input != null ? input.getJavaProject() : null;

		boolean isOnClasspath= false;
		if (file != null && project != null)
			isOnClasspath= project.isOnClasspath(file);

		if (isOnClasspath) {
			fireInputChanged(fInput);
			return false;
		} else {
			handleDeleted(fInput);
			return true;
		}
	}

	return false;
}
 
Example 19
Source File: JavaEditorBreadcrumb.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private boolean isStructuralChange(IJavaElementDelta delta) {
	if (delta.getKind() != IJavaElementDelta.CHANGED)
		return true;

	return (delta.getFlags() & IJavaElementDelta.F_CONTENT | IJavaElementDelta.F_FINE_GRAINED) == IJavaElementDelta.F_CONTENT;
}
 
Example 20
Source File: JavaStructureDiffViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Test whether the given delta represents a significant change.
 * 
 * @param cuDelta the Java element delta
 * @return <code>true</code> if the delta represents a content change
 * @since 3.5
 */
private boolean isContentChange(IJavaElementDelta cuDelta) {
	int flags= cuDelta.getFlags();
	return flags != IJavaElementDelta.F_AST_AFFECTED && (cuDelta.getKind() == IJavaElementDelta.CHANGED || (flags & IJavaElementDelta.F_CONTENT) != 0);
}