Java Code Examples for org.eclipse.jdt.core.IJavaElement#COMPILATION_UNIT

The following examples show how to use org.eclipse.jdt.core.IJavaElement#COMPILATION_UNIT . 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: FileTransferDragAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean isDragable(ISelection s) {
	if (!(s instanceof IStructuredSelection))
		return false;
	IStructuredSelection selection= (IStructuredSelection)s;
	for (Iterator<?> iter= selection.iterator(); iter.hasNext();) {
		Object element= iter.next();
		if (element instanceof IJavaElement) {
			IJavaElement jElement= (IJavaElement)element;
			int type= jElement.getElementType();
			// valid elements are: roots, units and types. Don't allow dragging
			// projects outside of eclipse
			if (type != IJavaElement.PACKAGE_FRAGMENT_ROOT &&
				type != IJavaElement.COMPILATION_UNIT && type != IJavaElement.TYPE)
				return false;
			IPackageFragmentRoot root= (IPackageFragmentRoot)jElement.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
			if (root != null && (root.isArchive() || root.isExternal()))
				return false;
		} else if (element instanceof IProject) {
			return false;
		}
	}
	List<IResource> resources= convertIntoResources(selection);
	return resources.size() == selection.size();
}
 
Example 2
Source File: RenameResourceElementsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see MultiOperation
 */
protected void verify(IJavaElement element) throws JavaModelException {
	super.verify(element);

	int elementType = element.getElementType();

	if (!(elementType == IJavaElement.COMPILATION_UNIT || elementType == IJavaElement.PACKAGE_FRAGMENT)) {
		error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
	}
	if (elementType == IJavaElement.COMPILATION_UNIT) {
		CompilationUnit cu = (CompilationUnit)element;
		if (cu.isWorkingCopy() && !cu.isPrimary()) {
			error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
		}
	}
	verifyRenaming(element);
}
 
Example 3
Source File: SearchUtils.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @param match the search match
 * @return the enclosing {@link ICompilationUnit} of the given match, or null iff none
 */
public static ICompilationUnit getCompilationUnit(SearchMatch match) {
	IJavaElement enclosingElement = getEnclosingJavaElement(match);
	if (enclosingElement != null){
		if (enclosingElement instanceof ICompilationUnit)
			return (ICompilationUnit) enclosingElement;
		ICompilationUnit cu= (ICompilationUnit) enclosingElement.getAncestor(IJavaElement.COMPILATION_UNIT);
		if (cu != null)
			return cu;
	}

	IJavaElement jElement= JavaCore.create(match.getResource());
	if (jElement != null && jElement.exists() && jElement.getElementType() == IJavaElement.COMPILATION_UNIT)
		return (ICompilationUnit) jElement;
	return null;
}
 
Example 4
Source File: JavaSearchScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IPath getPath(IJavaElement element, boolean relativeToRoot) {
	switch (element.getElementType()) {
		case IJavaElement.JAVA_MODEL:
			return Path.EMPTY;
		case IJavaElement.JAVA_PROJECT:
			return element.getPath();
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			if (relativeToRoot)
				return Path.EMPTY;
			return element.getPath();
		case IJavaElement.PACKAGE_FRAGMENT:
			String relativePath = Util.concatWith(((PackageFragment) element).names, '/');
			return getPath(element.getParent(), relativeToRoot).append(new Path(relativePath));
		case IJavaElement.COMPILATION_UNIT:
		case IJavaElement.CLASS_FILE:
			return getPath(element.getParent(), relativeToRoot).append(new Path(element.getElementName()));
		default:
			return getPath(element.getParent(), relativeToRoot);
	}
}
 
Example 5
Source File: GenericRefactoringHandleTransplanter.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
protected IType transplantHandle(IJavaElement parent, IType element) {
	switch (parent.getElementType()) {
		case IJavaElement.COMPILATION_UNIT:
			return ((ICompilationUnit) parent).getType(element.getElementName());
		case IJavaElement.CLASS_FILE:
			if (parent instanceof IOrdinaryClassFile) {
				return ((IOrdinaryClassFile) parent).getType();
			}
			throw new IllegalStateException(element.toString());
		case IJavaElement.METHOD:
			return ((IMethod) parent).getType(element.getElementName(), element.getOccurrenceCount());
		case IJavaElement.FIELD:
			return ((IField) parent).getType(element.getElementName(), element.getOccurrenceCount());
		case IJavaElement.INITIALIZER:
			return ((IInitializer) parent).getType(element.getElementName(), element.getOccurrenceCount());
		case IJavaElement.TYPE:
			return ((IType) parent).getType(element.getElementName(), element.getOccurrenceCount());
		default:
			throw new IllegalStateException(element.toString());
	}
}
 
Example 6
Source File: RenameCompilationUnitProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RefactoringStatus initialize(JavaRefactoringArguments extended) {
	final String handle= extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT);
	if (handle == null) {
		return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT));
	}

	final IJavaElement element= JavaRefactoringDescriptorUtil.handleToElement(extended.getProject(), handle, false);
	if (element == null || !element.exists() || element.getElementType() != IJavaElement.COMPILATION_UNIT)
		return JavaRefactoringDescriptorUtil.createInputFatalStatus(element, getProcessorName(), IJavaRefactorings.RENAME_COMPILATION_UNIT);

	final String name= extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME);
	if (name == null || name.length() == 0)
		return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME));

	fCu= (ICompilationUnit) element;
	try {
		computeRenameTypeRefactoring();
		setNewElementName(name);
	} catch (CoreException exception) {
		JavaPlugin.log(exception);
		return JavaRefactoringDescriptorUtil.createInputFatalStatus(element, getProcessorName(), IJavaRefactorings.RENAME_COMPILATION_UNIT);
	}
	return new RefactoringStatus();
}
 
Example 7
Source File: NewWizardsActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean isNewTarget(Object element) {
	if (element == null)
		return true;
	if (element instanceof IResource) {
		return true;
	}
	if (element instanceof IJavaElement) {
		int type= ((IJavaElement)element).getElementType();
		return type == IJavaElement.JAVA_PROJECT ||
			type == IJavaElement.PACKAGE_FRAGMENT_ROOT ||
			type == IJavaElement.PACKAGE_FRAGMENT ||
			type == IJavaElement.COMPILATION_UNIT ||
			type == IJavaElement.TYPE;
	}
	if (element instanceof IWorkingSet) {
		String workingSetId= ((IWorkingSet)element).getId();
		return
			IWorkingSetIDs.JAVA.equals(workingSetId) ||
			IWorkingSetIDs.RESOURCE.equals(workingSetId) ||
			IWorkingSetIDs.OTHERS.equals(workingSetId);
	}
	return false;
}
 
Example 8
Source File: JavaElementResourceMapping.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static ResourceMapping create(IJavaElement element) {
	switch (element.getElementType()) {
		case IJavaElement.TYPE:
			return create((IType)element);
		case IJavaElement.COMPILATION_UNIT:
			return create((ICompilationUnit)element);
		case IJavaElement.CLASS_FILE:
			return create((IClassFile)element);
		case IJavaElement.PACKAGE_FRAGMENT:
			return create((IPackageFragment)element);
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			return create((IPackageFragmentRoot)element);
		case IJavaElement.JAVA_PROJECT:
			return create((IJavaProject)element);
		case IJavaElement.JAVA_MODEL:
			return create((IJavaModel)element);
		default:
			return null;
	}

}
 
Example 9
Source File: JavaOutlinePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Checks whether a given Java element is an inner type.
 *
 * @param element the java element
 * @return <code>true</code> iff the given element is an inner type
 */
private boolean isInnerType(IJavaElement element) {

	if (element != null && element.getElementType() == IJavaElement.TYPE) {
		IType type= (IType)element;
		try {
			return type.isMember();
		} catch (JavaModelException e) {
			IJavaElement parent= type.getParent();
			if (parent != null) {
				int parentElementType= parent.getElementType();
				return (parentElementType != IJavaElement.COMPILATION_UNIT && parentElementType != IJavaElement.CLASS_FILE);
			}
		}
	}

	return false;
}
 
Example 10
Source File: ResourceMacro.java    From ContentAssist with MIT License 6 votes vote down vote up
/**
 * Obtains the name of the specified element.
 * @param elem the element
 * @param type the type of the element
 * @return the name string
 */
public static String getName(IJavaElement elem) {
    int type = elem.getElementType();
    if (type == IJavaElement.JAVA_PROJECT) {
        return elem.getResource().getName();
        
    } else if (type == IJavaElement.PACKAGE_DECLARATION) {
        IPackageFragment jpackage = (IPackageFragment)elem;
        return jpackage.getElementName();
        
    } else if (type == IJavaElement.COMPILATION_UNIT) {
        return elem.getResource().getName();
    }
    
    return "";
}
 
Example 11
Source File: RefactoringExecutionStarter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static RenameSupport createRenameSupport(IJavaElement element, String newName, int flags) throws CoreException {
	switch (element.getElementType()) {
		case IJavaElement.JAVA_PROJECT:
			return RenameSupport.create((IJavaProject) element, newName, flags);
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			return RenameSupport.create((IPackageFragmentRoot) element, newName);
		case IJavaElement.PACKAGE_FRAGMENT:
			return RenameSupport.create((IPackageFragment) element, newName, flags);
		case IJavaElement.COMPILATION_UNIT:
			return RenameSupport.create((ICompilationUnit) element, newName, flags);
		case IJavaElement.TYPE:
			return RenameSupport.create((IType) element, newName, flags);
		case IJavaElement.METHOD:
			final IMethod method= (IMethod) element;
			if (method.isConstructor())
				return createRenameSupport(method.getDeclaringType(), newName, flags);
			else
				return RenameSupport.create((IMethod) element, newName, flags);
		case IJavaElement.FIELD:
			return RenameSupport.create((IField) element, newName, flags);
		case IJavaElement.TYPE_PARAMETER:
			return RenameSupport.create((ITypeParameter) element, newName, flags);
		case IJavaElement.LOCAL_VARIABLE:
			return RenameSupport.create((ILocalVariable) element, newName, flags);
	}
	return null;
}
 
Example 12
Source File: JavaOutlineInformationControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isInnerType(IJavaElement element) {
	if (element != null && element.getElementType() == IJavaElement.TYPE) {
		IType type= (IType)element;
		try {
			return type.isMember();
		} catch (JavaModelException e) {
			IJavaElement parent= type.getParent();
			if (parent != null) {
				int parentElementType= parent.getElementType();
				return (parentElementType != IJavaElement.COMPILATION_UNIT && parentElementType != IJavaElement.CLASS_FILE);
			}
		}
	}
	return false;
}
 
Example 13
Source File: ResourceUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static IResource getResource(IJavaElement element){
	if (element.getElementType() == IJavaElement.COMPILATION_UNIT)
		return ((ICompilationUnit) element).getResource();
	else if (element instanceof IOpenable)
		return element.getResource();
	else
		return null;
}
 
Example 14
Source File: CopyModifications.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void copy(IJavaElement element, CopyArguments javaArgs, CopyArguments resourceArgs) throws CoreException {
	switch(element.getElementType()) {
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			copy((IPackageFragmentRoot)element, javaArgs, resourceArgs);
			break;
		case IJavaElement.PACKAGE_FRAGMENT:
			copy((IPackageFragment)element, javaArgs, resourceArgs);
			break;
		case IJavaElement.COMPILATION_UNIT:
			copy((ICompilationUnit)element, javaArgs, resourceArgs);
			break;
		default:
			add(element, javaArgs, null);
	}
}
 
Example 15
Source File: CopyModifications.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public void copy(IJavaElement element, CopyArguments javaArgs, CopyArguments resourceArgs) throws CoreException {
	switch(element.getElementType()) {
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			copy((IPackageFragmentRoot)element, javaArgs, resourceArgs);
			break;
		case IJavaElement.PACKAGE_FRAGMENT:
			copy((IPackageFragment)element, javaArgs, resourceArgs);
			break;
		case IJavaElement.COMPILATION_UNIT:
			copy((ICompilationUnit)element, javaArgs, resourceArgs);
			break;
		default:
			add(element, javaArgs, null);
	}
}
 
Example 16
Source File: CleanUpAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void collectCompilationUnits(Object element, Collection<IJavaElement> result) {
	try {
		if (element instanceof IJavaElement) {
			IJavaElement elem= (IJavaElement)element;
			if (elem.exists()) {
				switch (elem.getElementType()) {
					case IJavaElement.TYPE:
						if (elem.getParent().getElementType() == IJavaElement.COMPILATION_UNIT) {
							result.add(elem.getParent());
						}
						break;
					case IJavaElement.COMPILATION_UNIT:
						result.add(elem);
						break;
					case IJavaElement.IMPORT_CONTAINER:
						result.add(elem.getParent());
						break;
					case IJavaElement.PACKAGE_FRAGMENT:
						collectCompilationUnits((IPackageFragment)elem, result);
						break;
					case IJavaElement.PACKAGE_FRAGMENT_ROOT:
						collectCompilationUnits((IPackageFragmentRoot)elem, result);
						break;
					case IJavaElement.JAVA_PROJECT:
						IPackageFragmentRoot[] roots= ((IJavaProject)elem).getPackageFragmentRoots();
						for (int k= 0; k < roots.length; k++) {
							collectCompilationUnits(roots[k], result);
						}
						break;
				}
			}
		} else if (element instanceof LogicalPackage) {
			IPackageFragment[] packageFragments= ((LogicalPackage)element).getFragments();
			for (int k= 0; k < packageFragments.length; k++) {
				IPackageFragment pack= packageFragments[k];
				if (pack.exists()) {
					collectCompilationUnits(pack, result);
				}
			}
		} else if (element instanceof IWorkingSet) {
			IWorkingSet workingSet= (IWorkingSet) element;
			IAdaptable[] elements= workingSet.getElements();
			for (int j= 0; j < elements.length; j++) {
				collectCompilationUnits(elements[j], result);
			}
		}
	} catch (JavaModelException e) {
		if (JavaModelUtil.isExceptionToBeLogged(e))
			JavaPlugin.log(e);
	}
}
 
Example 17
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 18
Source File: JavaElementLabelComposer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Appends the label for a Java element with the flags as defined by this class.
 *
 * @param element the element to render
 * @param flags the rendering flags.
 */
public void appendElementLabel(IJavaElement element, long flags) {
	int type= element.getElementType();
	IPackageFragmentRoot root= null;

	if (type != IJavaElement.JAVA_MODEL && type != IJavaElement.JAVA_PROJECT && type != IJavaElement.PACKAGE_FRAGMENT_ROOT) {
		root= JavaModelUtil.getPackageFragmentRoot(element);
	}
	if (root != null && getFlag(flags, JavaElementLabels.PREPEND_ROOT_PATH)) {
		appendPackageFragmentRootLabel(root, JavaElementLabels.ROOT_QUALIFIED);
		fBuilder.append(JavaElementLabels.CONCAT_STRING);
	}

	switch (type) {
	case IJavaElement.METHOD:
		appendMethodLabel((IMethod) element, flags);
		break;
	case IJavaElement.FIELD:
		appendFieldLabel((IField) element, flags);
		break;
	case IJavaElement.LOCAL_VARIABLE:
		appendLocalVariableLabel((ILocalVariable) element, flags);
		break;
	case IJavaElement.TYPE_PARAMETER:
		appendTypeParameterLabel((ITypeParameter) element, flags);
		break;
	case IJavaElement.INITIALIZER:
		appendInitializerLabel((IInitializer) element, flags);
		break;
	case IJavaElement.TYPE:
		appendTypeLabel((IType) element, flags);
		break;
	case IJavaElement.CLASS_FILE:
		appendClassFileLabel((IClassFile) element, flags);
		break;
	case IJavaElement.COMPILATION_UNIT:
		appendCompilationUnitLabel((ICompilationUnit) element, flags);
		break;
	case IJavaElement.PACKAGE_FRAGMENT:
		appendPackageFragmentLabel((IPackageFragment) element, flags);
		break;
	case IJavaElement.PACKAGE_FRAGMENT_ROOT:
		appendPackageFragmentRootLabel((IPackageFragmentRoot) element, flags);
		break;
	case IJavaElement.IMPORT_CONTAINER:
	case IJavaElement.IMPORT_DECLARATION:
	case IJavaElement.PACKAGE_DECLARATION:
		appendDeclarationLabel(element, flags);
		break;
	case IJavaElement.JAVA_PROJECT:
	case IJavaElement.JAVA_MODEL:
		fBuilder.append(element.getElementName());
		break;
	default:
		fBuilder.append(element.getElementName());
	}

	if (root != null && getFlag(flags, JavaElementLabels.APPEND_ROOT_PATH)) {
		fBuilder.append(JavaElementLabels.CONCAT_STRING);
		appendPackageFragmentRootLabel(root, JavaElementLabels.ROOT_QUALIFIED);
	}
}
 
Example 19
Source File: GenericRefactoringHandleTransplanter.java    From eclipse.jdt.ls with Eclipse Public License 2.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: 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());
	}

}