Java Code Examples for org.eclipse.jdt.core.Signature#getIntersectionTypeBounds()

The following examples show how to use org.eclipse.jdt.core.Signature#getIntersectionTypeBounds() . 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: JavaElementHyperlinkDeclaredTypeDetector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 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.FIELD || element.getElementType() == IJavaElement.LOCAL_VARIABLE) {
			String typeSignature= getTypeSignature(element);
			if (!JavaModelUtil.isPrimitive(typeSignature) && SelectionConverter.canOperateOn(editor)) {
				if (Signature.getTypeSignatureKind(typeSignature) == Signature.INTERSECTION_TYPE_SIGNATURE) {
					String[] bounds= Signature.getIntersectionTypeBounds(typeSignature);
					qualify|= bounds.length >= 2;
					for (int i= 0; i < bounds.length; i++) {
						hyperlinksCollector.add(new JavaElementDeclaredTypeHyperlink(wordRegion, openAction, element, bounds[i], qualify));
					}
				} else {
					hyperlinksCollector.add(new JavaElementDeclaredTypeHyperlink(wordRegion, openAction, element, qualify));
				}
			}
		}
	} catch (JavaModelException e) {
		JavaPlugin.log(e);
	}
}
 
Example 2
Source File: JavaElementLabelComposer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
protected void appendTypeSignatureLabel(IJavaElement enclosingElement, String typeSig, long flags) {
	int sigKind= Signature.getTypeSignatureKind(typeSig);
	switch (sigKind) {
	case Signature.BASE_TYPE_SIGNATURE:
		fBuilder.append(Signature.toString(typeSig));
		break;
	case Signature.ARRAY_TYPE_SIGNATURE:
		appendTypeSignatureLabel(enclosingElement, Signature.getElementType(typeSig), flags);
		for (int dim= Signature.getArrayCount(typeSig); dim > 0; dim--) {
			fBuilder.append('[').append(']');
		}
		break;
	case Signature.CLASS_TYPE_SIGNATURE:
		String baseType= getSimpleTypeName(enclosingElement, typeSig);
		fBuilder.append(baseType);

		String[] typeArguments= Signature.getTypeArguments(typeSig);
		appendTypeArgumentSignaturesLabel(enclosingElement, typeArguments, flags);
		break;
	case Signature.TYPE_VARIABLE_SIGNATURE:
		fBuilder.append(getSimpleTypeName(enclosingElement, typeSig));
		break;
	case Signature.WILDCARD_TYPE_SIGNATURE:
		char ch= typeSig.charAt(0);
		if (ch == Signature.C_STAR) { //workaround for bug 85713
			fBuilder.append('?');
		} else {
			if (ch == Signature.C_EXTENDS) {
				fBuilder.append("? extends "); //$NON-NLS-1$
				appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags);
			} else if (ch == Signature.C_SUPER) {
				fBuilder.append("? super "); //$NON-NLS-1$
				appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags);
			}
		}
		break;
	case Signature.CAPTURE_TYPE_SIGNATURE:
		appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags);
		break;
	case Signature.INTERSECTION_TYPE_SIGNATURE:
		String[] typeBounds= Signature.getIntersectionTypeBounds(typeSig);
		appendTypeBoundsSignaturesLabel(enclosingElement, typeBounds, flags);
		break;
	default:
		// unknown
	}
}
 
Example 3
Source File: JavaElementLabelComposer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
protected void appendTypeSignatureLabel(IJavaElement enclosingElement, String typeSig, long flags) {
	int sigKind= Signature.getTypeSignatureKind(typeSig);
	switch (sigKind) {
		case Signature.BASE_TYPE_SIGNATURE:
			fBuffer.append(Signature.toString(typeSig));
			break;
		case Signature.ARRAY_TYPE_SIGNATURE:
			appendTypeSignatureLabel(enclosingElement, Signature.getElementType(typeSig), flags);
			for (int dim= Signature.getArrayCount(typeSig); dim > 0; dim--) {
				fBuffer.append('[').append(']');
			}
			break;
		case Signature.CLASS_TYPE_SIGNATURE:
			String baseType= getSimpleTypeName(enclosingElement, typeSig);
			fBuffer.append(baseType);

			String[] typeArguments= Signature.getTypeArguments(typeSig);
			appendTypeArgumentSignaturesLabel(enclosingElement, typeArguments, flags);
			break;
		case Signature.TYPE_VARIABLE_SIGNATURE:
			fBuffer.append(getSimpleTypeName(enclosingElement, typeSig));
			break;
		case Signature.WILDCARD_TYPE_SIGNATURE:
			char ch= typeSig.charAt(0);
			if (ch == Signature.C_STAR) { //workaround for bug 85713
				fBuffer.append('?');
			} else {
				if (ch == Signature.C_EXTENDS) {
					fBuffer.append("? extends "); //$NON-NLS-1$
					appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags);
				} else if (ch == Signature.C_SUPER) {
					fBuffer.append("? super "); //$NON-NLS-1$
					appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags);
				}
			}
			break;
		case Signature.CAPTURE_TYPE_SIGNATURE:
			appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags);
			break;
		case Signature.INTERSECTION_TYPE_SIGNATURE:
			String[] typeBounds= Signature.getIntersectionTypeBounds(typeSig);
			appendTypeBoundsSignaturesLabel(enclosingElement, typeBounds, flags);
			break;
		default:
			// unknown
	}
}