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

The following examples show how to use org.eclipse.jdt.core.IJavaElement#PACKAGE_DECLARATION . 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: 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 2
Source File: ASTNodeSearchUtil.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public static ASTNode[] getDeclarationNodes(IJavaElement element, CompilationUnit cuNode) throws JavaModelException {
	switch(element.getElementType()){
		case IJavaElement.FIELD:
			return new ASTNode[]{getFieldOrEnumConstantDeclaration((IField) element, cuNode)};
		case IJavaElement.IMPORT_CONTAINER:
			return getImportNodes((IImportContainer)element, cuNode);
		case IJavaElement.IMPORT_DECLARATION:
			return new ASTNode[]{getImportDeclarationNode((IImportDeclaration)element, cuNode)};
		case IJavaElement.INITIALIZER:
			return new ASTNode[]{getInitializerNode((IInitializer)element, cuNode)};
		case IJavaElement.METHOD:
			return new ASTNode[]{getMethodOrAnnotationTypeMemberDeclarationNode((IMethod) element, cuNode)};
		case IJavaElement.PACKAGE_DECLARATION:
			return new ASTNode[]{getPackageDeclarationNode((IPackageDeclaration)element, cuNode)};
		case IJavaElement.TYPE:
			return new ASTNode[]{getAbstractTypeDeclarationNode((IType) element, cuNode)};
		default:
			Assert.isTrue(false, String.valueOf(element.getElementType()));
			return null;
	}
}
 
Example 3
Source File: ResourceMacro.java    From ContentAssist with MIT License 6 votes vote down vote up
/**
 * Returns the target of this resource change.
 * @param elem the changed element
 * @return the target of the change, or an empty string if the target is not either a project, package, or file
 */
private String getTarget(IJavaElement elem) {
    if (elem == null) {
        return "";
    }
    
    int type = elem.getElementType();
    if (type == IJavaElement.JAVA_PROJECT) {
        return "Project";
        
    } else if (type == IJavaElement.PACKAGE_DECLARATION) {
        return "Package";
        
    } else if (type == IJavaElement.COMPILATION_UNIT) {
        return "File";
    }
    
    return elem.getElementName() + "@" + elem.getElementType();
}
 
Example 4
Source File: OpenAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Selects the openable elements out of the given ones.
 *
 * @param elements the elements to filter
 * @return the openable elements
 * @since 3.4
 */
private IJavaElement[] selectOpenableElements(IJavaElement[] elements) {
	List<IJavaElement> result= new ArrayList<IJavaElement>(elements.length);
	for (int i= 0; i < elements.length; i++) {
		IJavaElement element= elements[i];
		switch (element.getElementType()) {
			case IJavaElement.PACKAGE_DECLARATION:
			case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			case IJavaElement.JAVA_PROJECT:
			case IJavaElement.JAVA_MODEL:
				break;
			default:
				result.add(element);
				break;
		}
	}
	return result.toArray(new IJavaElement[result.size()]);
}
 
Example 5
Source File: JavaElementHyperlinkDetector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Selects the openable elements out of the given ones.
 *
 * @param elements the elements to filter
 * @return the openable elements
 * @since 3.4
 */
private IJavaElement[] selectOpenableElements(IJavaElement[] elements) {
	List<IJavaElement> result= new ArrayList<IJavaElement>(elements.length);
	for (int i= 0; i < elements.length; i++) {
		IJavaElement element= elements[i];
		switch (element.getElementType()) {
			case IJavaElement.PACKAGE_DECLARATION:
			case IJavaElement.PACKAGE_FRAGMENT:
			case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			case IJavaElement.JAVA_PROJECT:
			case IJavaElement.JAVA_MODEL:
				break;
			default:
				result.add(element);
				break;
		}
	}
	return result.toArray(new IJavaElement[result.size()]);
}
 
Example 6
Source File: JavaCompareUtilities.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
static ImageDescriptor getImageDescriptor(int type) {
	switch (type) {
	case IJavaElement.INITIALIZER:
	case IJavaElement.METHOD:
		return getImageDescriptor("obj16/compare_method.gif"); //$NON-NLS-1$
	case IJavaElement.FIELD:
		return getImageDescriptor("obj16/compare_field.gif"); //$NON-NLS-1$
	case IJavaElement.PACKAGE_DECLARATION:
		return JavaPluginImages.DESC_OBJS_PACKDECL;
	case IJavaElement.IMPORT_DECLARATION:
		return JavaPluginImages.DESC_OBJS_IMPDECL;
	case IJavaElement.IMPORT_CONTAINER:
		return JavaPluginImages.DESC_OBJS_IMPCONT;
	case IJavaElement.COMPILATION_UNIT:
		return JavaPluginImages.DESC_OBJS_CUNIT;
	}
	return ImageDescriptor.getMissingImageDescriptor();
}
 
Example 7
Source File: JavadocView.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private long getHeaderFlags(IJavaElement element) {
	switch (element.getElementType()) {
		case IJavaElement.PACKAGE_FRAGMENT:
		case IJavaElement.PACKAGE_DECLARATION:
			return LABEL_FLAGS ^ JavaElementLabels.ALL_FULLY_QUALIFIED;
		default:
			return LABEL_FLAGS;
	}
}
 
Example 8
Source File: DeleteChangeCreator.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static Change createDeleteChange(IJavaElement javaElement) throws JavaModelException {
	Assert.isTrue(! ReorgUtils.isInsideCompilationUnit(javaElement));

	switch(javaElement.getElementType()){
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			return createPackageFragmentRootDeleteChange((IPackageFragmentRoot)javaElement);

		case IJavaElement.PACKAGE_FRAGMENT:
			return createSourceManipulationDeleteChange((IPackageFragment)javaElement);

		case IJavaElement.COMPILATION_UNIT:
			return createSourceManipulationDeleteChange((ICompilationUnit)javaElement);

		case IJavaElement.CLASS_FILE:
			//if this assert fails, it means that a precondition is missing
			Assert.isTrue(((IClassFile)javaElement).getResource() instanceof IFile);
			return createDeleteChange(((IClassFile)javaElement).getResource());

		case IJavaElement.JAVA_MODEL: //cannot be done
			Assert.isTrue(false);
			return null;

		case IJavaElement.JAVA_PROJECT: //handled differently
			Assert.isTrue(false);
			return null;

		case IJavaElement.TYPE:
		case IJavaElement.FIELD:
		case IJavaElement.METHOD:
		case IJavaElement.INITIALIZER:
		case IJavaElement.PACKAGE_DECLARATION:
		case IJavaElement.IMPORT_CONTAINER:
		case IJavaElement.IMPORT_DECLARATION:
			Assert.isTrue(false);//not done here
			return new NullChange();
		default:
			Assert.isTrue(false);//there's no more kinds
			return new NullChange();
	}
}
 
Example 9
Source File: MatchLocator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public SearchMatch newDeclarationMatch(
		IJavaElement element,
		Binding binding,
		int accuracy,
		int offset,
		int length,
		SearchParticipant participant,
		IResource resource) {
	switch (element.getElementType()) {
		case IJavaElement.PACKAGE_FRAGMENT:
			return new PackageDeclarationMatch(element, accuracy, offset, length, participant, resource);
		case IJavaElement.TYPE:
			return new TypeDeclarationMatch(binding == null ? element : ((JavaElement) element).resolved(binding), accuracy, offset, length, participant, resource);
		case IJavaElement.FIELD:
			return new FieldDeclarationMatch(binding == null ? element : ((JavaElement) element).resolved(binding), accuracy, offset, length, participant, resource);
		case IJavaElement.METHOD:
			return new MethodDeclarationMatch(binding == null ? element : ((JavaElement) element).resolved(binding), accuracy, offset, length, participant, resource);
		case IJavaElement.LOCAL_VARIABLE:
			return new LocalVariableDeclarationMatch(element, accuracy, offset, length, participant, resource);
		case IJavaElement.PACKAGE_DECLARATION:
			return new PackageDeclarationMatch(element, accuracy, offset, length, participant, resource);
		case IJavaElement.TYPE_PARAMETER:
			return new TypeParameterDeclarationMatch(element, accuracy, offset, length, participant, resource);
		default:
			return null;
	}
}
 
Example 10
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void copyToDestination(IJavaElement element, CompilationUnitRewrite targetRewriter, CompilationUnit sourceCuNode, CompilationUnit targetCuNode) throws CoreException {
	final ASTRewrite rewrite= targetRewriter.getASTRewrite();
	switch (element.getElementType()) {
		case IJavaElement.FIELD:
			copyMemberToDestination((IMember) element, targetRewriter, sourceCuNode, targetCuNode, createNewFieldDeclarationNode(((IField) element), rewrite, sourceCuNode));
			break;
		case IJavaElement.IMPORT_CONTAINER:
			copyImportsToDestination((IImportContainer) element, rewrite, sourceCuNode, targetCuNode);
			break;
		case IJavaElement.IMPORT_DECLARATION:
			copyImportToDestination((IImportDeclaration) element, rewrite, sourceCuNode, targetCuNode);
			break;
		case IJavaElement.INITIALIZER:
			copyInitializerToDestination((IInitializer) element, targetRewriter, sourceCuNode, targetCuNode);
			break;
		case IJavaElement.METHOD:
			copyMethodToDestination((IMethod) element, targetRewriter, sourceCuNode, targetCuNode);
			break;
		case IJavaElement.PACKAGE_DECLARATION:
			copyPackageDeclarationToDestination((IPackageDeclaration) element, rewrite, sourceCuNode, targetCuNode);
			break;
		case IJavaElement.TYPE:
			copyTypeToDestination((IType) element, targetRewriter, sourceCuNode, targetCuNode);
			break;

		default:
			Assert.isTrue(false);
	}
}
 
Example 11
Source File: DeleteChangeCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static Change createDeleteChange(IJavaElement javaElement) throws JavaModelException {
	Assert.isTrue(! ReorgUtils.isInsideCompilationUnit(javaElement));

	switch(javaElement.getElementType()){
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			return createPackageFragmentRootDeleteChange((IPackageFragmentRoot)javaElement);

		case IJavaElement.PACKAGE_FRAGMENT:
			return createSourceManipulationDeleteChange((IPackageFragment)javaElement);

		case IJavaElement.COMPILATION_UNIT:
			return createSourceManipulationDeleteChange((ICompilationUnit)javaElement);

		case IJavaElement.CLASS_FILE:
			//if this assert fails, it means that a precondition is missing
			Assert.isTrue(((IClassFile)javaElement).getResource() instanceof IFile);
			return createDeleteChange(((IClassFile)javaElement).getResource());

		case IJavaElement.JAVA_MODEL: //cannot be done
			Assert.isTrue(false);
			return null;

		case IJavaElement.JAVA_PROJECT: //handled differently
			Assert.isTrue(false);
			return null;

		case IJavaElement.TYPE:
		case IJavaElement.FIELD:
		case IJavaElement.METHOD:
		case IJavaElement.INITIALIZER:
		case IJavaElement.PACKAGE_DECLARATION:
		case IJavaElement.IMPORT_CONTAINER:
		case IJavaElement.IMPORT_DECLARATION:
			Assert.isTrue(false);//not done here
			return new NullChange();
		default:
			Assert.isTrue(false);//there's no more kinds
			return new NullChange();
	}
}
 
Example 12
Source File: JavaSearchPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
final static boolean isSearchableType(IJavaElement element) {
	switch (element.getElementType()) {
		case IJavaElement.PACKAGE_FRAGMENT:
		case IJavaElement.PACKAGE_DECLARATION:
		case IJavaElement.IMPORT_DECLARATION:
		case IJavaElement.TYPE:
		case IJavaElement.FIELD:
		case IJavaElement.METHOD:
			return true;
	}
	return false;
}
 
Example 13
Source File: OpenTypeHierarchyUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Converts the input to a possible input candidates
 * @param input input
 * @return the possible candidates
 */
public static IJavaElement[] getCandidates(Object input) {
	if (!(input instanceof IJavaElement)) {
		return null;
	}
	try {
		IJavaElement elem= (IJavaElement) input;
		switch (elem.getElementType()) {
			case IJavaElement.INITIALIZER:
			case IJavaElement.METHOD:
			case IJavaElement.FIELD:
			case IJavaElement.TYPE:
			case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			case IJavaElement.JAVA_PROJECT:
				return new IJavaElement[] { elem };
			case IJavaElement.PACKAGE_FRAGMENT:
				if (((IPackageFragment)elem).containsJavaResources())
					return new IJavaElement[] {elem};
				break;
			case IJavaElement.PACKAGE_DECLARATION:
				return new IJavaElement[] { elem.getAncestor(IJavaElement.PACKAGE_FRAGMENT) };
			case IJavaElement.IMPORT_DECLARATION:
				IImportDeclaration decl= (IImportDeclaration) elem;
				if (decl.isOnDemand()) {
					elem= JavaModelUtil.findTypeContainer(elem.getJavaProject(), Signature.getQualifier(elem.getElementName()));
				} else {
					elem= elem.getJavaProject().findType(elem.getElementName());
				}
				if (elem == null)
					return null;
				return new IJavaElement[] {elem};

			case IJavaElement.CLASS_FILE:
				return new IJavaElement[] { ((IClassFile)input).getType() };
			case IJavaElement.COMPILATION_UNIT: {
				ICompilationUnit cu= (ICompilationUnit) elem.getAncestor(IJavaElement.COMPILATION_UNIT);
				if (cu != null) {
					IType[] types= cu.getTypes();
					if (types.length > 0) {
						return types;
					}
				}
				break;
			}
			default:
		}
	} catch (JavaModelException e) {
		JavaPlugin.log(e);
	}
	return null;
}
 
Example 14
Source File: OpenTypeHierarchyAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static IStatus compileCandidates(List<IJavaElement> result, List<IJavaElement> elements) {
	IStatus ok= Status.OK_STATUS;
	boolean onlyContainers= true;
	for (Iterator<IJavaElement> iter= elements.iterator(); iter.hasNext();) {
		IJavaElement elem= iter.next();
		try {
			switch (elem.getElementType()) {
				case IJavaElement.INITIALIZER:
				case IJavaElement.METHOD:
				case IJavaElement.FIELD:
				case IJavaElement.TYPE:
					onlyContainers= false;
					//$FALL-THROUGH$
				case IJavaElement.PACKAGE_FRAGMENT_ROOT:
				case IJavaElement.JAVA_PROJECT:
					result.add(elem);
					break;
				case IJavaElement.PACKAGE_FRAGMENT:
					if (((IPackageFragment)elem).containsJavaResources())
						result.add(elem);
					break;
				case IJavaElement.PACKAGE_DECLARATION:
					result.add(elem.getAncestor(IJavaElement.PACKAGE_FRAGMENT));
					break;
				case IJavaElement.IMPORT_DECLARATION:
					IImportDeclaration decl= (IImportDeclaration)elem;
					if (decl.isOnDemand())
						elem= JavaModelUtil.findTypeContainer(elem.getJavaProject(), Signature.getQualifier(elem.getElementName()));
					else
						elem= elem.getJavaProject().findType(elem.getElementName());
					if (elem != null) {
						onlyContainers= false;
						result.add(elem);
					}
					break;
				case IJavaElement.CLASS_FILE:
					onlyContainers= false;
					result.add(((IClassFile)elem).getType());
					break;
				case IJavaElement.COMPILATION_UNIT:
					ICompilationUnit cu= (ICompilationUnit)elem;
					IType[] types= cu.getTypes();
					if (types.length > 0) {
						onlyContainers= false;
						result.addAll(Arrays.asList(types));
					}
			}
		} catch (JavaModelException e) {
			return e.getStatus();
		}
	}
	int size= result.size();
	if (size == 0 || (size > 1 && !onlyContainers))
		return createStatus(ActionMessages.OpenTypeHierarchyAction_messages_no_valid_java_element);
	return ok;
}
 
Example 15
Source File: PasteAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static boolean canPasteToCu(int elementType) {
	return	elementType == IJavaElement.PACKAGE_DECLARATION ||
			elementType == IJavaElement.TYPE ||
			elementType == IJavaElement.IMPORT_DECLARATION;
}
 
Example 16
Source File: JavaCompareUtilities.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns a name for the given Java element that uses the same conventions
 * as the JavaNode name of a corresponding element.
 */
static String getJavaElementID(IJavaElement je) {

	if (je instanceof IMember && ((IMember)je).isBinary())
		return null;

	StringBuffer sb= new StringBuffer();

	switch (je.getElementType()) {
	case IJavaElement.COMPILATION_UNIT:
		sb.append(COMPILATIONUNIT);
		break;
	case IJavaElement.TYPE:
		sb.append(TYPE);
		sb.append(je.getElementName());
		break;
	case IJavaElement.FIELD:
		sb.append(FIELD);
		sb.append(je.getElementName());
		break;
	case IJavaElement.METHOD:
		sb.append(METHOD);
		sb.append(JavaElementLabels.getElementLabel(je, JavaElementLabels.M_PARAMETER_TYPES));
		break;
	case IJavaElement.INITIALIZER:
		String id= je.getHandleIdentifier();
		int pos= id.lastIndexOf(INITIALIZER);
		if (pos >= 0)
			sb.append(id.substring(pos));
		break;
	case IJavaElement.PACKAGE_DECLARATION:
		sb.append(PACKAGEDECLARATION);
		break;
	case IJavaElement.IMPORT_CONTAINER:
		sb.append(IMPORT_CONTAINER);
		break;
	case IJavaElement.IMPORT_DECLARATION:
		sb.append(IMPORTDECLARATION);
		sb.append(je.getElementName());
		break;
	default:
		return null;
	}
	return sb.toString();
}
 
Example 17
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 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: ReorgUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.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 20
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());
	}

}