use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class CompilationUnitImpl method toType.
public Type toType(final JvmType delegate) {
final Function1<JvmType, Type> _function = (JvmType it) -> {
Type _switchResult = null;
boolean _matched = false;
if (delegate instanceof JvmDeclaredType) {
_matched = true;
_switchResult = this.toTypeDeclaration(((JvmDeclaredType) delegate));
}
if (!_matched) {
if (delegate instanceof JvmTypeParameter) {
_matched = true;
_switchResult = this.toTypeParameterDeclaration(((JvmTypeParameter) delegate));
}
}
if (!_matched) {
if (delegate instanceof JvmVoid) {
_matched = true;
VoidTypeImpl _voidTypeImpl = new VoidTypeImpl();
final Procedure1<VoidTypeImpl> _function_1 = (VoidTypeImpl it_1) -> {
it_1.setDelegate(((JvmVoid) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<VoidTypeImpl>operator_doubleArrow(_voidTypeImpl, _function_1);
}
}
if (!_matched) {
if (delegate instanceof JvmPrimitiveType) {
_matched = true;
PrimitiveTypeImpl _primitiveTypeImpl = new PrimitiveTypeImpl();
final Procedure1<PrimitiveTypeImpl> _function_1 = (PrimitiveTypeImpl it_1) -> {
it_1.setDelegate(((JvmPrimitiveType) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<PrimitiveTypeImpl>operator_doubleArrow(_primitiveTypeImpl, _function_1);
}
}
return _switchResult;
};
return this.<JvmType, Type>getOrCreate(delegate, _function);
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method testInnerEnumType.
@Test
public void testInnerEnumType() throws Exception {
JvmDeclaredType declaredType = (JvmDeclaredType) getTypeProvider().findTypeByName(TypeWithInnerEnum.class.getName());
assertEquals(2, declaredType.getMembers().size());
// default constructor
assertTrue(Iterables.any(declaredType.getMembers(), new Predicate<JvmMember>() {
@Override
public boolean apply(JvmMember input) {
return (input instanceof JvmConstructor) && input.getSimpleName().equals(TypeWithInnerEnum.class.getSimpleName());
}
}));
// inner enum type
assertTrue(Iterables.any(declaredType.getMembers(), new Predicate<JvmMember>() {
@Override
public boolean apply(JvmMember input) {
return (input instanceof JvmEnumerationType) && input.getIdentifier().equals(TypeWithInnerEnum.MyEnum.class.getName()) && input.getVisibility() == JvmVisibility.PUBLIC;
}
}));
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method test_arrayParameterized_02.
@Test
public void test_arrayParameterized_02() {
JvmOperation arrayParameterized = getMethodFromParameterizedMethods("arrayParameterized(java.util.List[])");
JvmTypeReference paramType = arrayParameterized.getParameters().get(0).getParameterType();
assertEquals("java.util.List<T>[]", paramType.getIdentifier());
assertTrue(paramType.getType() instanceof JvmArrayType);
JvmArrayType arrayType = (JvmArrayType) paramType.getType();
assertTrue(arrayType.getComponentType() instanceof JvmDeclaredType);
assertTrue(paramType instanceof JvmGenericArrayTypeReference);
assertTrue(((JvmGenericArrayTypeReference) paramType).getComponentType() instanceof JvmParameterizedTypeReference);
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method testAnnotatedParameter_03.
@Test
public void testAnnotatedParameter_03() throws Exception {
String typeName = TestAnnotation.Annotated.class.getName();
JvmAnnotationType annotationType = (JvmAnnotationType) getTypeProvider().findTypeByName(TestAnnotation.NestedAnnotation.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(2);
assertEquals(1, target.getAnnotations().size());
JvmAnnotationReference annotationReference = target.getAnnotations().get(0);
assertSame(annotationType, annotationReference.getAnnotation());
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-eclipse by eclipse.
the class SourceBasedJdtTypeProviderTest method testClassAnnotationValue_09.
@Test
public void testClassAnnotationValue_09() throws Exception {
IJavaProject project = projectProvider.getJavaProject(null);
String typeName = EmptyAbstractClass.class.getName();
IFile javaFile = (IFile) project.getProject().findMember(new Path("src/" + typeName.replace('.', '/') + ".java"));
assertNotNull(javaFile);
String content = Files.readStreamIntoString(javaFile.getContents());
try {
String newContent = content.replace("public abstract ", "@TestAnnotation( classArray = ) public abstract ");
javaFile.setContents(new StringInputStream(newContent), IResource.NONE, new NullProgressMonitor());
JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
List<JvmAnnotationReference> annotations = type.getAnnotations();
assertEquals(1, annotations.size());
JvmAnnotationReference annotation = annotations.get(0);
assertEquals(1, annotation.getExplicitValues().size());
JvmAnnotationValue value = annotation.getExplicitValues().get(0);
assertTrue(value instanceof JvmTypeAnnotationValue);
List<JvmTypeReference> typeLiterals = ((JvmTypeAnnotationValue) value).getValues();
assertEquals(0, typeLiterals.size());
} finally {
javaFile.setContents(new StringInputStream(content), IResource.NONE, new NullProgressMonitor());
}
}
Aggregations