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;
}
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;
}
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);
}
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;
}
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);
}
Aggregations