use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-eclipse by eclipse.
the class JdtBasedTypeFactory method createType.
/**
* @since 2.4
*/
protected JvmDeclaredType createType(ITypeBinding typeBinding, String handleIdentifier, List<String> path, StringBuilder fqn) {
if (typeBinding.isAnonymous() || typeBinding.isSynthetic())
throw new IllegalStateException("Cannot create type for anonymous or synthetic classes");
// Creates the right type of instance based on the type of binding.
//
JvmGenericType jvmGenericType;
JvmDeclaredType result;
if (typeBinding.isAnnotation()) {
jvmGenericType = null;
result = TypesFactory.eINSTANCE.createJvmAnnotationType();
} else if (typeBinding.isEnum()) {
jvmGenericType = null;
result = TypesFactory.eINSTANCE.createJvmEnumerationType();
} else {
result = jvmGenericType = TypesFactory.eINSTANCE.createJvmGenericType();
jvmGenericType.setInterface(typeBinding.isInterface());
}
// Populate the information computed from the modifiers.
//
int modifiers = typeBinding.getModifiers();
setTypeModifiers(result, modifiers);
result.setDeprecated(typeBinding.isDeprecated());
setVisibility(result, modifiers);
// Determine the simple name and compose the fully qualified name and path, remembering the fqn length and path size so we can reset them.
//
String simpleName = typeBinding.getName();
fqn.append(simpleName);
int length = fqn.length();
int size = path.size();
path.add(simpleName);
String qualifiedName = fqn.toString();
result.internalSetIdentifier(qualifiedName);
result.setSimpleName(simpleName);
// Traverse the nested types using '$' as the qualified name separator.
//
fqn.append('$');
createNestedTypes(typeBinding, result, handleIdentifier, path, fqn);
// Traverse the methods using '.'as the qualifed name separator.
//
fqn.setLength(length);
fqn.append('.');
createMethods(typeBinding, handleIdentifier, path, fqn, result);
createFields(typeBinding, fqn, result);
// Set the super types.
//
setSuperTypes(typeBinding, qualifiedName, result);
//
if (jvmGenericType != null) {
ITypeBinding[] typeParameterBindings = typeBinding.getTypeParameters();
if (typeParameterBindings.length > 0) {
InternalEList<JvmTypeParameter> typeParameters = (InternalEList<JvmTypeParameter>) jvmGenericType.getTypeParameters();
for (ITypeBinding variable : typeParameterBindings) {
typeParameters.addUnique(createTypeParameter(variable, result));
}
}
}
// Populate the annotation values.
//
createAnnotationValues(typeBinding, result);
// Restore the path.
//
path.remove(size);
return result;
}
use of org.eclipse.xtext.common.types.JvmGenericType 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.JvmGenericType in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method publicNativeMethod.
@Test
public void publicNativeMethod() {
String typeName = Methods.class.getName();
JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
JvmOperation method = getMethodFromType(type, Methods.class, "publicStrictFpMethod()");
assertSame(type, method.getDeclaringType());
assertFalse(method.isAbstract());
assertFalse(method.isFinal());
assertFalse(method.isStatic());
assertFalse(method.isSynchronized());
assertTrue(method.isStrictFloatingPoint());
assertFalse(method.isNative());
assertEquals(JvmVisibility.PUBLIC, method.getVisibility());
JvmType methodType = method.getReturnType().getType();
assertEquals("void", methodType.getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method testTypeParamEndsWithDollar_02.
@Test
public void testTypeParamEndsWithDollar_02() {
String typeName = "org.eclipse.xtext.common.types.testSetups.TypeParamEndsWithDollar";
JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
JvmOperation function = (JvmOperation) type.findAllFeaturesByName("function2").iterator().next();
JvmFormalParameter parameter = function.getParameters().get(0);
JvmType parameterType = parameter.getParameterType().getType();
assertEquals(function.getTypeParameters().get(0), parameterType);
JvmFormalParameter secondParameter = function.getParameters().get(1);
JvmType secondParameterType = secondParameter.getParameterType().getType();
assertEquals(type.getTypeParameters().get(0), secondParameterType);
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method doTestConstantValue.
protected JvmField doTestConstantValue(String fieldName, Object fieldValue) {
String typeName = "org.eclipse.xtext.common.types.testSetups.TestConstants";
JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
JvmField field = getFieldFromType(type, TestConstants.class, fieldName);
assertTrue(field.isSetConstant());
assertTrue(field.isConstant());
assertEquals(fieldValue, field.getConstantValue());
return field;
}
Aggregations