use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-eclipse by eclipse.
the class XbaseLabelProvider method signature.
protected StyledString signature(final String simpleName, final JvmIdentifiableElement element) {
JvmTypeReference _xifexpression = null;
if ((element instanceof JvmOperation)) {
_xifexpression = ((JvmOperation) element).getReturnType();
} else {
JvmTypeReference _xifexpression_1 = null;
if ((element instanceof JvmField)) {
_xifexpression_1 = ((JvmField) element).getType();
} else {
_xifexpression_1 = null;
}
_xifexpression = _xifexpression_1;
}
final JvmTypeReference returnType = _xifexpression;
final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, element);
String _xifexpression_2 = null;
if ((returnType == null)) {
_xifexpression_2 = "void";
} else {
_xifexpression_2 = owner.toLightweightTypeReference(returnType).getHumanReadableName();
}
final String returnTypeString = _xifexpression_2;
String decoratedPart = (" : " + returnTypeString);
String _elvis = null;
String _typeParameters = this.uiStrings.typeParameters(element);
if (_typeParameters != null) {
_elvis = _typeParameters;
} else {
_elvis = "";
}
final String typeParam = _elvis;
boolean _notEquals = (!Objects.equal(typeParam, ""));
if (_notEquals) {
decoratedPart = (((" " + typeParam) + " : ") + returnTypeString);
}
String _parameters = this.uiStrings.parameters(element);
String _plus = (simpleName + _parameters);
StyledString _styledString = new StyledString(_plus);
StyledString _styledString_1 = new StyledString(decoratedPart, StyledString.DECORATIONS_STYLER);
return _styledString.append(_styledString_1);
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-eclipse by eclipse.
the class RuleEngineFormatter method _format.
@Override
protected void _format(final XSwitchExpression expr, @Extension final IFormattableDocument document) {
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
it.indent();
};
document.set(this.textRegionExtensions.previousHiddenRegion(expr.getSwitch()), this.textRegionExtensions.nextHiddenRegion(expr), _function);
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
document.append(this.textRegionExtensions.regionFor(expr).keyword("switch"), _function_1);
final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
it.newLine();
};
document.<XExpression>format(document.<XExpression>append(expr.getSwitch(), _function_2));
EList<XCasePart> _cases = expr.getCases();
for (final XCasePart c : _cases) {
{
if (((c.getTypeGuard() != null) && (c.getCase() != null))) {
final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
document.<JvmTypeReference>append(c.getTypeGuard(), _function_3);
final Procedure1<IHiddenRegionFormatter> _function_4 = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
document.<XExpression>append(c.getCase(), _function_4);
} else {
JvmTypeReference _typeGuard = c.getTypeGuard();
boolean _tripleNotEquals = (_typeGuard != null);
if (_tripleNotEquals) {
final Procedure1<IHiddenRegionFormatter> _function_5 = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
document.<JvmTypeReference>append(c.getTypeGuard(), _function_5);
} else {
XExpression _case = c.getCase();
boolean _tripleNotEquals_1 = (_case != null);
if (_tripleNotEquals_1) {
final Procedure1<IHiddenRegionFormatter> _function_6 = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
final Procedure1<IHiddenRegionFormatter> _function_7 = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
document.<XExpression>append(document.<XExpression>prepend(c.getCase(), _function_6), _function_7);
}
}
}
final Procedure1<IHiddenRegionFormatter> _function_8 = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
final Procedure1<IHiddenRegionFormatter> _function_9 = (IHiddenRegionFormatter it) -> {
it.newLine();
};
document.append(document.prepend(this.textRegionExtensions.regionFor(c).feature(XbasePackage.Literals.XCASE_PART__FALL_THROUGH), _function_8), _function_9);
document.<XExpression>format(c.getCase());
if ((Objects.equal(c, IterableExtensions.<XCasePart>last(expr.getCases())) && (expr.getDefault() == null))) {
this.formatBody(c.getThen(), true, document);
} else {
this.formatBodyParagraph(c.getThen(), document);
}
}
}
XExpression _default = expr.getDefault();
boolean _tripleNotEquals = (_default != null);
if (_tripleNotEquals) {
final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
document.append(this.textRegionExtensions.regionFor(expr).keyword("default"), _function_3);
this.formatBody(expr.getDefault(), true, document);
}
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-eclipse by eclipse.
the class JdtBasedTypeFactory method setSuperTypes.
/**
* @since 2.4
*/
protected void setSuperTypes(ITypeBinding binding, String qualifiedName, JvmDeclaredType result) {
ITypeBinding superclass = binding.getSuperclass();
InternalEList<JvmTypeReference> superTypes = (InternalEList<JvmTypeReference>) result.getSuperTypes();
if (superclass != null) {
superTypes.addUnique(createTypeReference(superclass));
}
for (ITypeBinding intf : binding.getInterfaces()) {
superTypes.addUnique(createTypeReference(intf));
}
if (superTypes.isEmpty() && !OBJECT_CLASS_NAME.equals(qualifiedName)) {
superTypes.addUnique(createObjectClassReference());
}
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-eclipse by eclipse.
the class JdtBasedTypeFactory method enhanceExecutable.
/**
* @since 2.4
*/
protected void enhanceExecutable(StringBuilder fqn, String handleIdentifier, String[] path, JvmExecutable result, IMethodBinding method) {
String name = method.getName();
fqn.append(name);
fqn.append('(');
ITypeBinding[] parameterTypes = method.getParameterTypes();
for (int i = 0; i < parameterTypes.length; i++) {
if (i != 0)
fqn.append(',');
fqn.append(getQualifiedName(parameterTypes[i]));
}
fqn.append(')');
result.internalSetIdentifier(fqn.toString());
result.setSimpleName(name);
setVisibility(result, method.getModifiers());
result.setDeprecated(method.isDeprecated());
if (parameterTypes.length > 0) {
result.setVarArgs(method.isVarargs());
String[] parameterNames = null;
// If the method is derived from source, we can efficiently determine the parameter names now.
//
ITypeBinding declaringClass = method.getDeclaringClass();
if (declaringClass.isFromSource()) {
parameterNames = getParameterNamesFromSource(fqn, method);
} else {
// Use the key to determine the signature for the method.
//
SegmentSequence signaturex = getSignatureAsSegmentSequence(method);
ParameterNameInitializer initializer = jdtCompliance.createParameterNameInitializer(method, workingCopyOwner, result, handleIdentifier, path, name, signaturex);
((JvmExecutableImplCustom) result).setParameterNameInitializer(initializer);
}
setParameterNamesAndAnnotations(method, parameterTypes, parameterNames, result);
}
ITypeBinding[] exceptionTypes = method.getExceptionTypes();
if (exceptionTypes.length > 0) {
InternalEList<JvmTypeReference> exceptions = (InternalEList<JvmTypeReference>) result.getExceptions();
for (ITypeBinding exceptionType : exceptionTypes) {
exceptions.addUnique(createTypeReference(exceptionType));
}
}
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-eclipse by eclipse.
the class JdtBasedTypeFactory method createTypeReference.
/**
* Returns a type reference for the given type binding. If the binding is null, an {@link JvmUnknownTypeReference unknown}
* type reference is returned.
*/
// @NonNull
protected JvmTypeReference createTypeReference(/* @Nullable */
ITypeBinding typeBinding) {
if (typeBinding == null) {
return TypesFactory.eINSTANCE.createJvmUnknownTypeReference();
}
if (typeBinding.isArray()) {
ITypeBinding componentType = typeBinding.getComponentType();
JvmTypeReference componentTypeReference = createTypeReference(componentType);
JvmGenericArrayTypeReference typeReference = TypesFactory.eINSTANCE.createJvmGenericArrayTypeReference();
typeReference.setComponentType(componentTypeReference);
return typeReference;
}
ITypeBinding outer = null;
if (typeBinding.isMember() && !Modifier.isStatic(typeBinding.getModifiers())) {
outer = typeBinding.getDeclaringClass();
}
JvmParameterizedTypeReference result;
if (outer != null) {
JvmParameterizedTypeReference outerReference = (JvmParameterizedTypeReference) createTypeReference(outer);
result = TypesFactory.eINSTANCE.createJvmInnerTypeReference();
((JvmInnerTypeReference) result).setOuter(outerReference);
} else {
result = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
}
ITypeBinding[] typeArguments = typeBinding.getTypeArguments();
if (typeArguments.length != 0) {
ITypeBinding erasure = typeBinding.getErasure();
result.setType(createProxy(erasure));
InternalEList<JvmTypeReference> arguments = (InternalEList<JvmTypeReference>) result.getArguments();
for (int i = 0; i < typeArguments.length; i++) {
JvmTypeReference argument = createTypeArgument(typeArguments[i]);
arguments.addUnique(argument);
}
} else {
result.setType(createProxy(typeBinding));
}
return result;
}
Aggregations