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

The following examples show how to use org.eclipse.jdt.core.IJavaElement#TYPE_PARAMETER . 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: 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 2
Source File: RenameSupport.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static RenameSupport create(IJavaElement element, String newName, int flags) throws CoreException {
	switch (element.getElementType()) {
		case IJavaElement.JAVA_PROJECT:
			//return RenameSupport.create((IJavaProject) element, newName, flags);
			return null;
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			//return RenameSupport.create((IPackageFragmentRoot) element, newName);
			return null;
		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 create(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 3
Source File: RefactoringAvailabilityTester.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static boolean isRenameElementAvailable(IJavaElement element) throws CoreException {
	switch (element.getElementType()) {
		case IJavaElement.JAVA_PROJECT:
			return isRenameAvailable((IJavaProject) element);
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			return isRenameAvailable((IPackageFragmentRoot) element);
		case IJavaElement.PACKAGE_FRAGMENT:
			return isRenameAvailable((IPackageFragment) element);
		case IJavaElement.COMPILATION_UNIT:
			return isRenameAvailable((ICompilationUnit) element);
		case IJavaElement.TYPE:
			return isRenameAvailable((IType) element);
		case IJavaElement.METHOD:
			final IMethod method = (IMethod) element;
			if (method.isConstructor()) {
				return isRenameAvailable(method.getDeclaringType());
			} else {
				return isRenameAvailable(method);
			}
		case IJavaElement.FIELD:
			final IField field = (IField) element;
			if (Flags.isEnum(field.getFlags())) {
				return isRenameEnumConstAvailable(field);
			} else {
				return isRenameFieldAvailable(field);
			}
		case IJavaElement.TYPE_PARAMETER:
			return isRenameAvailable((ITypeParameter) element);
		case IJavaElement.LOCAL_VARIABLE:
			return isRenameAvailable((ILocalVariable) element);
	}
	return false;
}
 
Example 4
Source File: RefactoringAvailabilityTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isRenameElementAvailable(IJavaElement element) throws CoreException {
	switch (element.getElementType()) {
		case IJavaElement.JAVA_PROJECT:
			return isRenameAvailable((IJavaProject) element);
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			return isRenameAvailable((IPackageFragmentRoot) element);
		case IJavaElement.PACKAGE_FRAGMENT:
			return isRenameAvailable((IPackageFragment) element);
		case IJavaElement.COMPILATION_UNIT:
			return isRenameAvailable((ICompilationUnit) element);
		case IJavaElement.TYPE:
			return isRenameAvailable((IType) element);
		case IJavaElement.METHOD:
			final IMethod method= (IMethod) element;
			if (method.isConstructor())
				return isRenameAvailable(method.getDeclaringType());
			else
				return isRenameAvailable(method);
		case IJavaElement.FIELD:
			final IField field= (IField) element;
			if (Flags.isEnum(field.getFlags()))
				return isRenameEnumConstAvailable(field);
			else
				return isRenameFieldAvailable(field);
		case IJavaElement.TYPE_PARAMETER:
			return isRenameAvailable((ITypeParameter) element);
		case IJavaElement.LOCAL_VARIABLE:
			return isRenameAvailable((ILocalVariable) element);
	}
	return false;
}
 
Example 5
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 6
Source File: JavadocHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static long getHeaderFlags(IJavaElement element) {
	switch (element.getElementType()) {
		case IJavaElement.LOCAL_VARIABLE:
			return LOCAL_VARIABLE_FLAGS;
		case IJavaElement.TYPE_PARAMETER:
			return TYPE_PARAMETER_FLAGS;
		case IJavaElement.PACKAGE_FRAGMENT:
			return PACKAGE_FLAGS;
		default:
			return LABEL_FLAGS;
	}
}
 
Example 7
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 8
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 9
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 10
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 11
Source File: JavaElementLabelComposer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.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);
		fBuffer.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:
			fBuffer.append(element.getElementName());
			break;
		default:
			fBuffer.append(element.getElementName());
	}

	if (root != null && getFlag(flags, JavaElementLabels.APPEND_ROOT_PATH)) {
		int offset= fBuffer.length();
		fBuffer.append(JavaElementLabels.CONCAT_STRING);
		appendPackageFragmentRootLabel(root, JavaElementLabels.ROOT_QUALIFIED);

		if (getFlag(flags, JavaElementLabels.COLORIZE)) {
			fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE);
		}

	}
}
 
Example 12
Source File: TypeParameterLocator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
protected int referenceType() {
	return IJavaElement.TYPE_PARAMETER;
}