org.eclipse.xtext.common.types.JvmAnyTypeReference Java Examples

The following examples show how to use org.eclipse.xtext.common.types.JvmAnyTypeReference. 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: UIStrings.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.4
 */
public String referenceToString(JvmTypeReference typeRef, String defaultLabel) {
	if (typeRef == null)
		return defaultLabel;
	
	if (typeRef.eResource() == null) {
		if (typeRef instanceof JvmAnyTypeReference) {
			return "Object";
		}
		return typeRef.getSimpleName();
	}
	
	StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(services, typeRef);
	LightweightTypeReference reference = owner.toLightweightTypeReference(typeRef);
	return referenceToString(reference);
}
 
Example #2
Source File: XbaseDeclarativeHoverSignatureProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected String _signature(JvmOperation jvmOperation, boolean typeAtEnd) {
		String returnTypeString = "void";
		// TODO resolved operations?
		JvmTypeReference returnType = jvmOperation.getReturnType();
		if (returnType != null) {
			if (returnType instanceof JvmAnyTypeReference) {
				throw new IllegalStateException();
//				returnTypeString = "Object";
			} else {
				returnTypeString = returnType.getSimpleName();
			}
		}

		String signature = jvmOperation.getSimpleName() + hoverUiStrings.parameters(jvmOperation)
				+ getThrowsDeclaration(jvmOperation);
		String typeParameter = uiStrings.typeParameters(jvmOperation.getTypeParameters());
		if(typeParameter != null && typeParameter.length() > 0){
			if (typeAtEnd)
				return signature + " " + typeParameter + " : " + returnTypeString;
			return typeParameter + " " + returnTypeString + " " + signature;
		}
		if (typeAtEnd)
			return signature + " : " + returnTypeString;
		return returnTypeString + " " + enrichWithDeclarator(signature, jvmOperation);
	}
 
Example #3
Source File: XtendHoverSignatureProvider.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected String _signature(XtendFunction function, boolean typeAtEnd) {
	JvmOperation inferredOperation = associations.getDirectlyInferredOperation(function);
	if (inferredOperation != null) {
		String returnTypeString = "void";
		JvmTypeReference returnType = inferredOperation.getReturnType();
		if (returnType != null) {
			if (returnType instanceof JvmAnyTypeReference) {
				throw new IllegalStateException();
			} else {
				returnTypeString = getTypeName(returnType);
			}
		}
		StringBuilder signature = new StringBuilder();
		String typeParameter = uiStrings.typeParameters(function.getTypeParameters());
		if (typeParameter != null && typeParameter.length() > 0){
			signature.append(typeParameter).append(" ");
		}
		signature.append(returnTypeString).append(" ");
		signature.append(function.getName()).append(hoverUiStrings.parameters(inferredOperation));
		signature.append(getThrowsDeclaration(inferredOperation));
		return signature.toString();
	}
	return function.getName() + "()";
}
 
Example #4
Source File: SARLHoverSignatureProvider.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
protected String _signature(JvmOperation jvmOperation, boolean typeAtEnd) {
	String returnTypeString = this.keywords.getVoidKeyword();
	final JvmTypeReference returnType = jvmOperation.getReturnType();
	if (returnType != null) {
		if (returnType instanceof JvmAnyTypeReference) {
			throw new IllegalStateException();
		}
		returnTypeString = returnType.getSimpleName();
	}

	final String signature = jvmOperation.getSimpleName() + this.hoverUiStrings.parameters(jvmOperation);
	final String postSignature = getThrowsDeclaration(jvmOperation);
	final String typeParameter = this.uiStrings.typeParameters(jvmOperation.getTypeParameters());
	if (typeParameter != null && typeParameter.length() > 0) {
		if (typeAtEnd) {
			return signature + " " + typeParameter + " " //$NON-NLS-1$ //$NON-NLS-2$
				+ this.keywords.getColonKeyword() + " " + returnTypeString + postSignature; //$NON-NLS-1$
		}
		return typeParameter + " " + returnTypeString + " " + signature + postSignature; //$NON-NLS-1$ //$NON-NLS-2$
	}
	if (typeAtEnd) {
		return signature + " " + this.keywords.getColonKeyword() + " " + returnTypeString + postSignature; //$NON-NLS-1$ //$NON-NLS-2$
	}
	return returnTypeString + " " + enrichWithDeclarator(signature, jvmOperation) + postSignature; //$NON-NLS-1$
}
 
Example #5
Source File: TypeReferences.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @return a fresh {@link JvmAnyTypeReference} or null if {@link Object} is not on the context's classpath
 */
public JvmAnyTypeReference createAnyTypeReference(Notifier context) {
	if (context == null)
		throw new NullPointerException("context");
	JvmAnyTypeReference result = factory.createJvmAnyTypeReference();
	final JvmType objectType = findDeclaredType(Object.class, context);
	if (objectType == null)
		return null;
	result.setType(objectType);
	return result;
}
 
Example #6
Source File: AbstractBuilder.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the type reference for the given name in the given context.
 */
public JvmParameterizedTypeReference newTypeRef(Notifier context, String typeName) {
	JvmTypeReference typeReference;
	try {
		typeReference = findType(context, typeName);
		getImportManager().addImportFor(typeReference.getType());
		return (JvmParameterizedTypeReference) typeReference;
	} catch (TypeNotPresentException exception) {
	}
	final JvmParameterizedTypeReference pref = ExpressionBuilderImpl.parseType(context, typeName, this);
	final JvmTypeReference baseType = findType(context, pref.getType().getIdentifier());
	final int len = pref.getArguments().size();
	final JvmTypeReference[] args = new JvmTypeReference[len];
	for (int i = 0; i < len; ++i) {
		final JvmTypeReference original = pref.getArguments().get(i);
		if (original instanceof JvmAnyTypeReference) {
			args[i] = EcoreUtil.copy(original);
		} else if (original instanceof JvmWildcardTypeReference) {
			final JvmWildcardTypeReference wc = EcoreUtil.copy((JvmWildcardTypeReference) original);
			for (final JvmTypeConstraint c : wc.getConstraints()) {
				c.setTypeReference(newTypeRef(context, c.getTypeReference().getIdentifier()));
			}
			args[i] = wc;
		} else {
			args[i] = newTypeRef(context, original.getIdentifier());
		}
	}
	final TypeReferences typeRefs = getTypeReferences();
	return typeRefs.createTypeRef(baseType.getType(), args);
}
 
Example #7
Source File: ProxyAwareUIStrings.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public StringBuilder doVisitAnyTypeReference(JvmAnyTypeReference reference, StringBuilder param) {
	return doVisitTypeReference(reference, param);
}
 
Example #8
Source File: LightweightTypeReferenceFactory.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public LightweightTypeReference doVisitAnyTypeReference(JvmAnyTypeReference reference) {
	return owner.newAnyTypeReference();
}
 
Example #9
Source File: AbstractTypeReferenceVisitor.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Result doVisitAnyTypeReference(JvmAnyTypeReference reference) {
	return doVisitTypeReference(reference);
}
 
Example #10
Source File: AbstractTypeReferenceVisitorWithParameter.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Result doVisitAnyTypeReference(JvmAnyTypeReference reference, Parameter param) {
	return doVisitTypeReference(reference, param);
}
 
Example #11
Source File: ITypeReferenceVisitorWithParameter.java    From xtext-extras with Eclipse Public License 2.0 votes vote down vote up
Result doVisitAnyTypeReference(JvmAnyTypeReference reference, Parameter param); 
Example #12
Source File: ITypeReferenceVisitor.java    From xtext-extras with Eclipse Public License 2.0 votes vote down vote up
Result doVisitAnyTypeReference(JvmAnyTypeReference reference);