Java Code Examples for org.eclipse.jdt.core.IJavaElement#getElementType()

The following examples show how to use org.eclipse.jdt.core.IJavaElement#getElementType() . 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: DestinationContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean hasChildren(Object element) {
	IReorgDestination destination= ReorgDestinationFactory.createDestination(element);
	if (!fValidator.canChildrenBeDestinations(destination))
			return false;

	if (element instanceof IJavaElement){
		IJavaElement javaElement= (IJavaElement) element;
		if (javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT) {
			IPackageFragmentRoot root= (IPackageFragmentRoot) javaElement;
			if (root.isArchive() || root.isExternal())
				return false;
		}
	}

	return super.hasChildren(element);
}
 
Example 2
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private ASTNode getDestinationNode(IJavaElement destination, CompilationUnit target) throws JavaModelException {
	switch (destination.getElementType()) {
		case IJavaElement.INITIALIZER:
			return ASTNodeSearchUtil.getInitializerNode((IInitializer) destination, target);
		case IJavaElement.FIELD:
			return ASTNodeSearchUtil.getFieldOrEnumConstantDeclaration((IField) destination, target);
		case IJavaElement.METHOD:
			return ASTNodeSearchUtil.getMethodOrAnnotationTypeMemberDeclarationNode((IMethod) destination, target);
		case IJavaElement.TYPE:
			IType typeDestination= (IType) destination;
			if (typeDestination.isAnonymous()) {
				return ASTNodeSearchUtil.getClassInstanceCreationNode(typeDestination, target).getAnonymousClassDeclaration();
			} else {
				return ASTNodeSearchUtil.getAbstractTypeDeclarationNode(typeDestination, target);
			}
		case IJavaElement.COMPILATION_UNIT:
			IType mainType= JavaElementUtil.getMainType((ICompilationUnit) destination);
			if (mainType != null) {
				return ASTNodeSearchUtil.getAbstractTypeDeclarationNode(mainType, target);
			}
			//$FALL-THROUGH$
		default:
			return null;
	}
}
 
Example 3
Source File: JavaDocLocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static URL getJavadocBaseLocation(IJavaElement element) throws JavaModelException {
	if (element.getElementType() == IJavaElement.JAVA_PROJECT) {
		return getProjectJavadocLocation((IJavaProject) element);
	}

	IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(element);
	if (root == null) {
		return null;
	}

	if (root.getKind() == IPackageFragmentRoot.K_BINARY) {
		IClasspathEntry entry= root.getResolvedClasspathEntry();
		URL javadocLocation= getLibraryJavadocLocation(entry);
		if (javadocLocation != null) {
			return getLibraryJavadocLocation(entry);
		}
		entry= root.getRawClasspathEntry();
		switch (entry.getEntryKind()) {
			case IClasspathEntry.CPE_LIBRARY:
			case IClasspathEntry.CPE_VARIABLE:
				return getLibraryJavadocLocation(entry);
			default:
				return null;
		}
	} else {
		return getProjectJavadocLocation(root.getJavaProject());
	}
}
 
Example 4
Source File: JsniCompletionProposal.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private String computeCtorCompletion() {
  StringBuilder sb = new StringBuilder();
  sb.append(JSNI_CTOR_METHOD);
  sb.append('(');

  try {
    // References to constructors of non-static inner classes must take an
    // instance of their enclosing class as the first parameter.
    String qualifiedTypeName = Signature.toString(new String(
        wrappedProposal.getDeclarationSignature()));
    IType type = javaProject.findType(qualifiedTypeName);
    if (type != null) {
      // See if the type is a non-static inner class
      IJavaElement typeParent = type.getParent();
      if (typeParent.getElementType() == IJavaElement.TYPE
          && !Flags.isStatic(type.getFlags())) {
        // Calculate the (binary) type signature of the enclosing type
        String outerTypeName = ((IType) typeParent).getFullyQualifiedName();
        String outerTypeSig = Signature.createTypeSignature(outerTypeName,
            true).replace('.', '/');

        // Add as first parameter of ctor references
        sb.append(outerTypeSig);
      }
    }
  } catch (JavaModelException e) {
    GWTPluginLog.logError(e);
  }

  sb.append(getParamTypesSignature(wrappedProposal));
  sb.append(')');
  return sb.toString();
}
 
Example 5
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 6
Source File: MembersView.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds the element which has to be selected in this part.
 *
 * @param je	the Java element which has the focus
 * @return the element to select
 */
@Override
protected IJavaElement findElementToSelect(IJavaElement je) {
	if (je == null)
		return null;

	switch (je.getElementType()) {
		case IJavaElement.TYPE:
			if (((IType)je).getDeclaringType() == null)
				return null;
			return je;
		case IJavaElement.METHOD:
		case IJavaElement.INITIALIZER:
		case IJavaElement.FIELD:
		case IJavaElement.PACKAGE_DECLARATION:
		case IJavaElement.IMPORT_CONTAINER:
			return je;
		case IJavaElement.IMPORT_DECLARATION:
			ICompilationUnit cu= (ICompilationUnit)je.getParent().getParent();
			try {
				if (cu.getImports()[0].equals(je)) {
					Object selectedElement= getSingleElementFromSelection(getViewer().getSelection());
					if (selectedElement instanceof IImportContainer)
						return (IImportContainer)selectedElement;
				}
			} catch (JavaModelException ex) {
				// return je;
			}
			return je;
	}
	return null;
}
 
Example 7
Source File: DocumentSymbolHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void collectChildren(ITypeRoot unit, IJavaElement[] elements, ArrayList<SymbolInformation> symbols,
		IProgressMonitor monitor)
		throws JavaModelException {
	for (IJavaElement element : elements) {
		if (monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		if (element instanceof IParent) {
			collectChildren(unit, filter(((IParent) element).getChildren()), symbols, monitor);
		}
		int type = element.getElementType();
		if (type != IJavaElement.TYPE && type != IJavaElement.FIELD && type != IJavaElement.METHOD) {
			continue;
		}

		Location location = JDTUtils.toLocation(element);
		if (location != null) {
			SymbolInformation si = new SymbolInformation();
			String name = JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT);
			si.setName(name == null ? element.getElementName() : name);
			si.setKind(mapKind(element));
			if (element.getParent() != null) {
				si.setContainerName(element.getParent().getElementName());
			}
			location.setUri(ResourceUtils.toClientUri(location.getUri()));
			si.setLocation(location);
			if (!symbols.contains(si)) {
				symbols.add(si);
			}
		}
	}
}
 
Example 8
Source File: JavaElementHyperlinkReturnTypeDetector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void addHyperlinks(List<IHyperlink> hyperlinksCollector, IRegion wordRegion, SelectionDispatchAction openAction, IJavaElement element, boolean qualify, JavaEditor editor) {
	try {
		if (element.getElementType() == IJavaElement.METHOD && !JavaModelUtil.isPrimitive(((IMethod)element).getReturnType()) && SelectionConverter.canOperateOn(editor)) {
			hyperlinksCollector.add(new JavaElementReturnTypeHyperlink(wordRegion, openAction, (IMethod)element, qualify));
		}
	} catch (JavaModelException e) {
		JavaPlugin.log(e);
	}
}
 
Example 9
Source File: JavaElementUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static IJavaElement[] getElementsOfType(IJavaElement[] elements, int type){
	Set<IJavaElement> result= new HashSet<IJavaElement>(elements.length);
	for (int i= 0; i < elements.length; i++) {
		IJavaElement element= elements[i];
		if (element.getElementType() == type)
			result.add(element);
	}
	return result.toArray(new IJavaElement[result.size()]);
}
 
Example 10
Source File: JarPackageReader.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IType getMainClass(Element element) {
	String handleId= element.getAttribute("mainClassHandleIdentifier"); //$NON-NLS-1$
	if (handleId.equals("")) //$NON-NLS-1$
		return null;	// Main-Class entry is optional or can be empty
	IJavaElement je= JavaCore.create(handleId);
	if (je != null && je.getElementType() == IJavaElement.TYPE)
		return (IType)je;
	addWarning(JarPackagerMessages.JarPackageReader_warning_mainClassDoesNotExist, null);
	return null;
}
 
Example 11
Source File: JdtRenameRefactoringProcessorFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public JavaRenameProcessor createRenameProcessor(IJavaElement element) {
	try {
		switch (element.getElementType()) {
			case IJavaElement.TYPE:
				return new RenameTypeProcessor((IType) element);
			case IJavaElement.FIELD:
				if (((IField) element).getDeclaringType().isEnum())
					return new RenameEnumConstProcessor((IField) element);
				else
					return new RenameFieldProcessor((IField) element);
			case IJavaElement.METHOD:
				if(((IMethod)element).isConstructor()) 
					break;
				if (Flags.isStatic(((IMethod) element).getFlags()) || Flags.isPrivate(((IMethod) element).getFlags()))
					return new RenameNonVirtualMethodProcessor((IMethod) element);
				else
					return new RenameVirtualMethodProcessor((IMethod) element);
	        case IJavaElement.TYPE_PARAMETER:
	        	return new RenameTypeParameterProcessor((ITypeParameter)element);
	        case IJavaElement.LOCAL_VARIABLE:
	        	return new RenameLocalVariableProcessor((ILocalVariable)element);

		}
	} catch (JavaModelException exc) {
		LOG.error("Error creating refactoring processor for " + element.getElementName(), exc);
	}
	return null;
}
 
Example 12
Source File: BuilderUtils.java    From JReFrameworker with MIT License 5 votes vote down vote up
/**
 * Returns a collection of K_SOURCE Compilation units in the project's package fragments
 * Reference: https://www.eclipse.org/forums/index.php/t/68072/
 * @param javaproject
 * @return
 */
public static final ICompilationUnit[] getSourceCompilationUnits(IJavaProject jProject) {
	ArrayList<ICompilationUnit> sourceCompilationUnits = new ArrayList<ICompilationUnit>();
	try {
		IPackageFragmentRoot[] roots = jProject.getPackageFragmentRoots();
		for (int i = 0; i < roots.length; i++) {
			IPackageFragmentRoot root = roots[i];
			if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
				IJavaElement[] javaElements = root.getChildren();
				for (int j = 0; j < javaElements.length; j++) {
					IJavaElement javaElement = javaElements[j];
					if (javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
						IPackageFragment pf = (IPackageFragment) javaElement;
						ICompilationUnit[] compilationUnits = pf.getCompilationUnits();
						for (int k = 0; k < compilationUnits.length; k++) {
							ICompilationUnit unit = compilationUnits[k];
							if (unit.isStructureKnown()) {
								sourceCompilationUnits.add(unit);
							}
						}
					}
				}
			}
		}
	} catch (CoreException e) {
		e.printStackTrace();
	}
	ICompilationUnit[] sourceCompilationUnitsArray = new ICompilationUnit[sourceCompilationUnits.size()];
	sourceCompilationUnits.toArray(sourceCompilationUnitsArray);
	return sourceCompilationUnitsArray;
}
 
Example 13
Source File: RecoveredTypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public IJavaElement getJavaElement() {
	IPackageBinding packageBinding = getPackage();
	if (packageBinding != null) {
		final IJavaElement javaElement = packageBinding.getJavaElement();
		if (javaElement != null && javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
			// best effort: we don't know if the recovered binding is a binary or source binding, so go with a simple source type
			return ((PackageFragment) javaElement).getCompilationUnit(getInternalName() + SuffixConstants.SUFFIX_STRING_java).getType(this.getName());
		}
	}
	return null;
}
 
Example 14
Source File: ReferenceFinderUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static Set<IJavaElement> extractElements(SearchMatch[] searchResults, int elementType) {
	Set<IJavaElement> elements= new HashSet<IJavaElement>();
	for (int i= 0; i < searchResults.length; i++) {
		IJavaElement el= SearchUtils.getEnclosingJavaElement(searchResults[i]);
		if (el.exists() && el.getElementType() == elementType)
			elements.add(el);
	}
	return elements;
}
 
Example 15
Source File: ReorgUtils.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static String createNamePattern(IJavaElement element) throws JavaModelException {
	switch(element.getElementType()){
		case IJavaElement.CLASS_FILE:
			return RefactoringCoreMessages.ReorgUtils_3;
		case IJavaElement.COMPILATION_UNIT:
			return RefactoringCoreMessages.ReorgUtils_4;
		case IJavaElement.FIELD:
			return RefactoringCoreMessages.ReorgUtils_5;
		case IJavaElement.IMPORT_CONTAINER:
			return RefactoringCoreMessages.ReorgUtils_6;
		case IJavaElement.IMPORT_DECLARATION:
			return RefactoringCoreMessages.ReorgUtils_7;
		case IJavaElement.INITIALIZER:
			return RefactoringCoreMessages.ReorgUtils_8;
		case IJavaElement.JAVA_PROJECT:
			return RefactoringCoreMessages.ReorgUtils_9;
		case IJavaElement.METHOD:
			if (((IMethod)element).isConstructor())
				return RefactoringCoreMessages.ReorgUtils_10;
			else
				return RefactoringCoreMessages.ReorgUtils_11;
		case IJavaElement.PACKAGE_DECLARATION:
			return RefactoringCoreMessages.ReorgUtils_12;
		case IJavaElement.PACKAGE_FRAGMENT:
			if (JavaElementUtil.isDefaultPackage(element))
				return RefactoringCoreMessages.ReorgUtils_13;
			else
				return RefactoringCoreMessages.ReorgUtils_14;
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			if (((IPackageFragmentRoot) element).isArchive())
				return RefactoringCoreMessages.ReorgUtils_21;
			if (isSourceFolder(element))
				return RefactoringCoreMessages.ReorgUtils_15;
			if (isClassFolder(element))
				return RefactoringCoreMessages.ReorgUtils_16;
			return RefactoringCoreMessages.ReorgUtils_17;
		case IJavaElement.TYPE:
			IType type= (IType)element;
			if (type.isAnonymous())
				return RefactoringCoreMessages.ReorgUtils_20;
			return RefactoringCoreMessages.ReorgUtils_18;
		default:
			Assert.isTrue(false);
			return null;
	}
}
 
Example 16
Source File: ReorgUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private static boolean isOfType(IJavaElement element, int type) {
	return element.getElementType() == type;//this is _not_ a mask
}
 
Example 17
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 18
Source File: ExtractConstantRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private RefactoringStatus initialize(JavaRefactoringArguments arguments) {
	final String selection= arguments.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION);
	if (selection != null) {
		int offset= -1;
		int length= -1;
		final StringTokenizer tokenizer= new StringTokenizer(selection);
		if (tokenizer.hasMoreTokens())
			offset= Integer.valueOf(tokenizer.nextToken()).intValue();
		if (tokenizer.hasMoreTokens())
			length= Integer.valueOf(tokenizer.nextToken()).intValue();
		if (offset >= 0 && length >= 0) {
			fSelectionStart= offset;
			fSelectionLength= length;
		} else
			return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { selection, JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION}));
	} else
		return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION));
	final String handle= arguments.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT);
	if (handle != null) {
		final IJavaElement element= JavaRefactoringDescriptorUtil.handleToElement(arguments.getProject(), handle, false);
		if (element == null || !element.exists() || element.getElementType() != IJavaElement.COMPILATION_UNIT)
			return JavaRefactoringDescriptorUtil.createInputFatalStatus(element, getName(), IJavaRefactorings.EXTRACT_CONSTANT);
		else
			fCu= (ICompilationUnit) element;
	} else
		return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT));
	final String visibility= arguments.getAttribute(ATTRIBUTE_VISIBILITY);
	if (visibility != null && !"".equals(visibility)) {//$NON-NLS-1$
		int flag= 0;
		try {
			flag= Integer.parseInt(visibility);
		} catch (NumberFormatException exception) {
			return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ATTRIBUTE_VISIBILITY));
		}
		fVisibility= JdtFlags.getVisibilityString(flag);
	}
	final String name= arguments.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME);
	if (name != null && !"".equals(name)) //$NON-NLS-1$
		fConstantName= name;
	else
		return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME));
	final String replace= arguments.getAttribute(ATTRIBUTE_REPLACE);
	if (replace != null) {
		fReplaceAllOccurrences= Boolean.valueOf(replace).booleanValue();
	} else
		return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ATTRIBUTE_REPLACE));
	final String declareFinal= arguments.getAttribute(ATTRIBUTE_QUALIFY);
	if (declareFinal != null) {
		fQualifyReferencesWithDeclaringClassName= Boolean.valueOf(declareFinal).booleanValue();
	} else
		return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ATTRIBUTE_QUALIFY));
	return new RefactoringStatus();
}
 
Example 19
Source File: GenericRefactoringHandleTransplanter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public final IJavaElement transplantHandle(IJavaElement element) {
	IJavaElement parent= element.getParent();
	if (parent != null)
		parent= transplantHandle(parent); // recursive

	switch (element.getElementType()) {
		case IJavaElement.JAVA_MODEL:
			return transplantHandle((IJavaModel) element);

		case IJavaElement.JAVA_PROJECT:
			return transplantHandle((IJavaProject) element);

		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			return transplantHandle((IJavaProject) parent, (IPackageFragmentRoot) element);

		case IJavaElement.PACKAGE_FRAGMENT:
			return transplantHandle((IPackageFragmentRoot) parent, (IPackageFragment) element);

		case IJavaElement.COMPILATION_UNIT:
			return transplantHandle((IPackageFragment) parent, (ICompilationUnit) element);

		case IJavaElement.CLASS_FILE:
			return transplantHandle((IPackageFragment) parent, (IClassFile) element);

		case IJavaElement.TYPE:
			return transplantHandle(parent, (IType) element);

		case IJavaElement.FIELD:
			return transplantHandle((IType) parent, (IField) element);

		case IJavaElement.METHOD:
			return transplantHandle((IType) parent, (IMethod) element);

		case IJavaElement.INITIALIZER:
			return transplantHandle((IType) parent, (IInitializer) element);

		case IJavaElement.PACKAGE_DECLARATION:
			return transplantHandle((ICompilationUnit) parent, (IPackageDeclaration) element);

		case IJavaElement.IMPORT_CONTAINER:
			return transplantHandle((ICompilationUnit) parent, (IImportContainer) element);

		case IJavaElement.IMPORT_DECLARATION:
			return transplantHandle((IImportContainer) parent, (IImportDeclaration) element);

		case IJavaElement.LOCAL_VARIABLE:
			return transplantHandle((ILocalVariable) element);

		case IJavaElement.TYPE_PARAMETER:
			return transplantHandle((IMember) parent, (ITypeParameter) element);

		case IJavaElement.ANNOTATION:
			return transplantHandle((IAnnotatable) parent, (IAnnotation) element);

		default:
			throw new IllegalArgumentException(element.toString());
	}

}
 
Example 20
Source File: ReorgUtils.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static boolean isOfType(IJavaElement element, int type) {
	return element.getElementType() == type;//this is _not_ a mask
}