Java Code Examples for org.eclipse.xtext.common.types.JvmTypeReference#getSimpleName()

The following examples show how to use org.eclipse.xtext.common.types.JvmTypeReference#getSimpleName() . 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: XtendJvmLabelProvider.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected String text(final JvmGenericType element) {
  String _xblockexpression = null;
  {
    final boolean local = element.isLocal();
    if (local) {
      final JvmTypeReference supertype = IterableExtensions.<JvmTypeReference>last(element.getSuperTypes());
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("new ");
      String _simpleName = supertype.getSimpleName();
      _builder.append(_simpleName);
      _builder.append("() {...}");
      return _builder.toString();
    }
    String _simpleName_1 = element.getSimpleName();
    String _xifexpression = null;
    boolean _isEmpty = element.getTypeParameters().isEmpty();
    if (_isEmpty) {
      _xifexpression = "";
    } else {
      _xifexpression = this.uiStrings.typeParameters(element.getTypeParameters());
    }
    _xblockexpression = (_simpleName_1 + _xifexpression);
  }
  return _xblockexpression;
}
 
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: JvmDelegateTypeReferenceImplCustom.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String getSimpleName() {
	JvmTypeReference resolvedDelegate = getDelegate();
	if (resolvedDelegate == null || resolvedDelegate.eIsProxy())
		return null;
	return resolvedDelegate.getSimpleName();
}
 
Example 6
Source File: JvmGenericArrayTypeReferenceImplCustom.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String getSimpleName() {
	JvmTypeReference componentType = getComponentType();
	if (componentType != null)
		return componentType.getSimpleName() + "[]";
	return null;
}
 
Example 7
Source File: JvmSpecializedTypeReferenceImplCustom.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String getSimpleName() {
	JvmTypeReference equivalent = getEquivalent();
	if (equivalent != null)
		return equivalent.getSimpleName();
	return super.getSimpleName();
}
 
Example 8
Source File: XbaseLabelProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected String text(JvmFormalParameter parameter) {
	JvmTypeReference parameterType = parameter.getParameterType();
	if (parameterType == null) {
		return parameter.getName();
	} else {
		return parameterType.getSimpleName() + " " + parameter.getName();
	}
}
 
Example 9
Source File: XbaseDeclarativeHoverSignatureProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected String _signature(JvmField jvmField, boolean typeAtEnd) {
	JvmTypeReference type = jvmField.getType();
	if (type != null) {
		String signature = jvmField.getSimpleName();
		if (typeAtEnd)
			return signature + " : " + type.getSimpleName();
		return type.getSimpleName() + " " + enrichWithDeclarator(signature, jvmField);
	}
	return "";
}
 
Example 10
Source File: XbaseDeclarativeHoverSignatureProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected String getThrowsDeclaration(JvmExecutable executable) {
	String result = "";
	EList<JvmTypeReference> exceptions = executable.getExceptions();
	if (exceptions.size() > 0) {
		result += " throws ";
		Iterator<JvmTypeReference> iterator = exceptions.iterator();
		while (iterator.hasNext()) {
			JvmTypeReference next = iterator.next();
			result += next.getSimpleName();
			if (iterator.hasNext())
				result += ", ";
		}
	}
	return result;
}
 
Example 11
Source File: XtendHoverSignatureProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected String getTypeName(JvmTypeReference typeReference) {
	JvmType type = typeReference.getType();
	if (type instanceof JvmDeclaredType) {
		ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, type);
		return owner.toLightweightTypeReference(typeReference).getHumanReadableName();
	}
	return typeReference.getSimpleName();
}
 
Example 12
Source File: XtendHoverSignatureProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected String _signature(XtendParameter parameter, boolean typeAtEnd) {
	EObject container = parameter.eContainer();
	JvmTypeReference type = parameter.getParameterType();
	if (type != null) {
		String signature = parameter.getName();
		String signatureOfFather = getSimpleSignature(container);
		if(signatureOfFather != null){
			signature += JavaElementLabels.CONCAT_STRING + signatureOfFather;
		}
		if (typeAtEnd)
			return signature + " : " + type.getSimpleName();
		return type.getSimpleName() + " " + signature;
	}
	return parameter.getName();
}
 
Example 13
Source File: CheckLabelProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * A text for context labels.
 * 
 * @param context
 *          any context
 * @return a textual representation of the context
 */
public String text(final Context context) {
  ContextVariable var = context.getContextVariable();
  if (var != null) {
    JvmTypeReference type = var.getType();
    if (type != null) {
      return type.getSimpleName();
    }
  }
  return null;
}
 
Example 14
Source File: XbaseIdeCrossrefProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void addNameAndDescription(ContentAssistEntry entry, JvmFeature feature, boolean withParents,
		int insignificantParameters, String shortName, LightweightTypeReferenceFactory converter) {
	StringBuilder labelBuilder = new StringBuilder(shortName);
	StringBuilder descriptionBuilder = new StringBuilder();
	if (feature instanceof JvmOperation) {
		if (withParents) {
			labelBuilder.append("(");
			appendParameters(labelBuilder, (JvmExecutable) feature, insignificantParameters, converter);
			labelBuilder.append(")");
		}
		JvmOperation jvmOperation = (JvmOperation) feature;
		JvmTypeReference returnType = jvmOperation.getReturnType();
		if (returnType != null && returnType.getSimpleName() != null) {
			labelBuilder.append(" : ");
			labelBuilder.append(converter.toLightweightReference(returnType).getHumanReadableName());
		}
		descriptionBuilder.append(
				converter.toPlainTypeReference(jvmOperation.getDeclaringType()).getHumanReadableName());
		if (!withParents) {
			descriptionBuilder.append(".");
			descriptionBuilder.append(jvmOperation.getSimpleName());
			descriptionBuilder.append("()");
		}
	} else {
		if (feature instanceof JvmField) {
			labelBuilder.append(" : ");
			JvmField jvmField = (JvmField) feature;
			if (jvmField.getType() != null) {
				String fieldType = converter.toLightweightReference(jvmField.getType())
						.getHumanReadableName();
				if (fieldType != null) {
					labelBuilder.append(fieldType);
				}
			}
			descriptionBuilder.append(
					converter.toPlainTypeReference(jvmField.getDeclaringType()).getHumanReadableName());
		} else if (feature instanceof JvmConstructor) {
			if (withParents) {
				labelBuilder.append("(");
				appendParameters(labelBuilder, ((JvmExecutable) feature), insignificantParameters, converter);
				labelBuilder.append(")");
			}
		}
	}
	entry.setLabel(labelBuilder.toString());
	entry.setDescription(descriptionBuilder.toString());
}
 
Example 15
Source File: XtypeProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected StyledString getStyledDisplayString(JvmFeature feature, boolean withParents, int insignificantParameters, String qualifiedNameAsString, String shortName,
		LightweightTypeReferenceFactory converter) {
	StyledString result = new StyledString(shortName);
	if (feature instanceof JvmOperation) {
		JvmOperation operation = (JvmOperation) feature;
		if (withParents) {
			result.append('(');
			appendParameters(result, (JvmExecutable)feature, insignificantParameters, converter);
			result.append(')');
		}
		JvmTypeReference returnType = operation.getReturnType();
		if (returnType != null && returnType.getSimpleName() != null) {
			result.append(" : ");
			result.append(converter.toLightweightReference(returnType).getHumanReadableName());
		}
		result.append(" - ", StyledString.QUALIFIER_STYLER);
		result.append(converter.toPlainTypeReference(feature.getDeclaringType()).getHumanReadableName(), StyledString.QUALIFIER_STYLER);
		if (!withParents) {
			result.append(".", StyledString.QUALIFIER_STYLER);
			result.append(feature.getSimpleName(), StyledString.QUALIFIER_STYLER);
			result.append("()", StyledString.QUALIFIER_STYLER);
		}
	} else if (feature instanceof JvmField) {
		JvmField field = (JvmField) feature;
		result.append(" : ");
		if (field.getType() != null) {
			String fieldType = converter.toLightweightReference(field.getType()).getHumanReadableName();
			if (fieldType != null)
				result.append(fieldType);
		}
		result.append(" - ", StyledString.QUALIFIER_STYLER);
		result.append(converter.toPlainTypeReference(feature.getDeclaringType()).getHumanReadableName(), StyledString.QUALIFIER_STYLER);
	} else if (feature instanceof JvmConstructor) {
		if (withParents) {
			result.append('(');
			appendParameters(result, (JvmExecutable)feature, insignificantParameters, converter);
			result.append(')');
		}
	}
	return result;
}