Search in sources :

Example 1 with JvmConstructor

use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-eclipse by eclipse.

the class XbaseReferenceProposalCreator method computeImage.

protected Image computeImage(JvmFeature feature) {
    int flags = 0;
    int decorator = 0;
    switch(feature.getVisibility()) {
        case PUBLIC:
            flags = Flags.AccPublic;
            break;
        case PROTECTED:
            flags = Flags.AccProtected;
            break;
        case PRIVATE:
            flags = Flags.AccPrivate;
            break;
        case DEFAULT:
            flags = Flags.AccDefault;
            break;
    }
    JvmDeclaredType declaringType = feature.getDeclaringType();
    boolean interfaceOrAnnotation = false;
    if (declaringType instanceof JvmGenericType) {
        interfaceOrAnnotation = ((JvmGenericType) declaringType).isInterface();
    } else if (declaringType instanceof JvmAnnotationType) {
        interfaceOrAnnotation = true;
    }
    if (feature instanceof JvmConstructor) {
        decorator = JavaElementImageDescriptor.CONSTRUCTOR;
        if (declaringType.isAbstract()) {
            flags |= Flags.AccAbstract;
            decorator |= JavaElementImageDescriptor.ABSTRACT;
        }
        return computeConstructorImage(declaringType.getDeclaringType() != null, interfaceOrAnnotation, flags, decorator);
    } else if (feature instanceof JvmOperation) {
        JvmOperation operation = (JvmOperation) feature;
        if (operation.isStatic()) {
            flags |= Flags.AccStatic;
            decorator |= JavaElementImageDescriptor.STATIC;
        }
        if (operation.isAbstract()) {
            flags |= Flags.AccAbstract;
            decorator |= JavaElementImageDescriptor.ABSTRACT;
        }
        if (operation.isFinal()) {
            flags |= Flags.AccFinal;
            decorator |= JavaElementImageDescriptor.FINAL;
        }
        return computeMethodImage(interfaceOrAnnotation, flags, decorator);
    } else if (feature instanceof JvmField) {
        JvmField field = (JvmField) feature;
        if (field.isStatic()) {
            flags |= Flags.AccStatic;
            decorator |= JavaElementImageDescriptor.STATIC;
        }
        if (field.isFinal()) {
            flags |= Flags.AccFinal;
            decorator |= JavaElementImageDescriptor.FINAL;
        }
        if (declaringType instanceof JvmEnumerationType)
            flags |= Flags.AccEnum;
        return computeFieldImage(interfaceOrAnnotation, flags, decorator);
    }
    return null;
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmField(org.eclipse.xtext.common.types.JvmField) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType)

Example 2 with JvmConstructor

use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-eclipse by eclipse.

the class XtypeProposalProvider method getStyledDisplayString.

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

Example 3 with JvmConstructor

use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-eclipse by eclipse.

the class AbstractTypeProviderTest method testVarArgs_03.

@Test
public void testVarArgs_03() {
    String typeName = ClassWithVarArgs.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmConstructor constructor = getConstructorFromType(type, ClassWithVarArgs.class, "ClassWithVarArgs(int,java.lang.String[])");
    assertTrue(constructor.isVarArgs());
    assertEquals(2, constructor.getParameters().size());
    assertTrue(constructor.getParameters().get(0).getParameterType() instanceof JvmParameterizedTypeReference);
    assertTrue(constructor.getParameters().get(1).getParameterType() instanceof JvmGenericArrayTypeReference);
}
Also used : JvmGenericArrayTypeReference(org.eclipse.xtext.common.types.JvmGenericArrayTypeReference) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) Test(org.junit.Test)

Example 4 with JvmConstructor

use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-eclipse by eclipse.

the class AbstractTypeProviderTest method getConstructorParameterAnnotationValue.

public JvmAnnotationValue getConstructorParameterAnnotationValue(String name, boolean defaultValue) {
    String typeName = TestAnnotation.Annotated.class.getName();
    JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
    JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class, "Annotated(java.lang.String,java.lang.String,java.lang.String)");
    JvmAnnotationTarget target = constructor.getParameters().get(0);
    JvmAnnotationValue result = getDefaultOrExplicitAnnotationValue(name, target);
    if (defaultValue) {
        if (isDefaultValueSupported()) {
            assertTrue(result.eContainer() instanceof JvmOperation);
        } else {
            assertFalse(result.eContainer() instanceof JvmOperation);
        }
    } else {
        assertFalse(result.eContainer() instanceof JvmOperation);
    }
    return result;
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmAnnotationTarget(org.eclipse.xtext.common.types.JvmAnnotationTarget) TestAnnotation(org.eclipse.xtext.common.types.testSetups.TestAnnotation) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationValue)

Example 5 with JvmConstructor

use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-eclipse by eclipse.

the class AbstractTypeProviderTest method testAnnotatedConstructor_04.

@Test
public void testAnnotatedConstructor_04() throws Exception {
    String typeName = TestAnnotation.Annotated.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class, "Annotated(java.lang.String,java.lang.String)");
    assertNotNull(constructor);
    JvmStringAnnotationValue value = (JvmStringAnnotationValue) getExplicitAnnotationValue("value", constructor);
    assertEquals(1, value.getValues().size());
    String s = value.getValues().get(0);
    assertEquals("thirdConstructorWithBody", s);
}
Also used : TestAnnotation(org.eclipse.xtext.common.types.testSetups.TestAnnotation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmStringAnnotationValue(org.eclipse.xtext.common.types.JvmStringAnnotationValue) Test(org.junit.Test)

Aggregations

JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)82 Test (org.junit.Test)42 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)33 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)18 JvmMember (org.eclipse.xtext.common.types.JvmMember)17 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)16 EObject (org.eclipse.emf.ecore.EObject)15 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)15 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)9 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)9 TestAnnotation (org.eclipse.xtext.common.types.testSetups.TestAnnotation)9 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)8 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)7 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)6 JvmField (org.eclipse.xtext.common.types.JvmField)6 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)6 Predicate (com.google.common.base.Predicate)5 JvmAnnotationTarget (org.eclipse.xtext.common.types.JvmAnnotationTarget)5 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)5 JvmEnumerationType (org.eclipse.xtext.common.types.JvmEnumerationType)5