Search in sources :

Example 1 with JvmTypeReference

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);
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmField(org.eclipse.xtext.common.types.JvmField) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Example 2 with JvmTypeReference

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);
    }
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) XCasePart(org.eclipse.xtext.xbase.XCasePart) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 3 with JvmTypeReference

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());
    }
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) InternalEList(org.eclipse.emf.ecore.util.InternalEList)

Example 4 with JvmTypeReference

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));
        }
    }
}
Also used : SegmentSequence(org.eclipse.emf.common.util.SegmentSequence) JvmExecutableImplCustom(org.eclipse.xtext.common.types.impl.JvmExecutableImplCustom) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) InternalEList(org.eclipse.emf.ecore.util.InternalEList) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint)

Example 5 with JvmTypeReference

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;
}
Also used : JvmGenericArrayTypeReference(org.eclipse.xtext.common.types.JvmGenericArrayTypeReference) JvmInnerTypeReference(org.eclipse.xtext.common.types.JvmInnerTypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) InternalEList(org.eclipse.emf.ecore.util.InternalEList) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint)

Aggregations

JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)193 Test (org.junit.Test)98 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)67 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)47 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)46 JvmType (org.eclipse.xtext.common.types.JvmType)43 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)41 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)36 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)27 XExpression (org.eclipse.xtext.xbase.XExpression)21 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)18 JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)18 EObject (org.eclipse.emf.ecore.EObject)17 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)17 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)16 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)14 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)13 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)12 JvmField (org.eclipse.xtext.common.types.JvmField)12 JvmWildcardTypeReference (org.eclipse.xtext.common.types.JvmWildcardTypeReference)12