use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class XtendCompiler method internalCanCompileToJavaExpression.
@Override
protected boolean internalCanCompileToJavaExpression(XExpression expression, ITreeAppendable appendable) {
if (expression instanceof AnonymousClass) {
AnonymousClass anonymousClass = (AnonymousClass) expression;
JvmGenericType inferredLocalClass = associations.getInferredType(anonymousClass);
return inferredLocalClass.isAnonymous();
} else
return super.internalCanCompileToJavaExpression(expression, appendable);
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class AnonymousClassUtil method getSuperType.
/* @Nullable */
public JvmGenericType getSuperType(AnonymousClass anonymousClass) {
JvmConstructor constructor = anonymousClass.getConstructorCall().getConstructor();
if (constructor != null && !constructor.eIsProxy()) {
JvmDeclaredType declaringType = constructor.getDeclaringType();
JvmType superType = Iterables.getLast(declaringType.getSuperTypes()).getType();
if (superType instanceof JvmGenericType)
return (JvmGenericType) superType;
}
return null;
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method initialize.
protected void initialize(XtendClass source, JvmGenericType inferredJvmType) {
inferredJvmType.setVisibility(source.getVisibility());
boolean isStatic = source.isStatic() && !isTopLevel(source);
if (!isStatic) {
JvmDeclaredType declaringType = inferredJvmType.getDeclaringType();
if (declaringType instanceof JvmGenericType) {
if (((JvmGenericType) declaringType).isInterface())
isStatic = true;
} else if (declaringType instanceof JvmAnnotationType) {
isStatic = true;
}
}
inferredJvmType.setStatic(isStatic);
inferredJvmType.setAbstract(source.isAbstract());
inferredJvmType.setStrictFloatingPoint(source.isStrictFloatingPoint());
if (!inferredJvmType.isAbstract()) {
inferredJvmType.setFinal(source.isFinal());
}
translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
JvmTypeReference extendsClause = source.getExtends();
if (extendsClause == null || extendsClause.getType() == null) {
JvmTypeReference typeRefToObject = typeReferences.getTypeForName(Object.class, source);
if (typeRefToObject != null)
inferredJvmType.getSuperTypes().add(typeRefToObject);
} else {
inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(extendsClause));
}
for (JvmTypeReference intf : source.getImplements()) {
inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(intf));
}
fixTypeParameters(inferredJvmType);
addDefaultConstructor(source, inferredJvmType);
for (XtendMember member : source.getMembers()) {
if (member instanceof XtendField || (member instanceof XtendFunction && ((XtendFunction) member).getName() != null) || member instanceof XtendConstructor) {
transform(member, inferredJvmType, true);
}
}
appendSyntheticDispatchMethods(source, inferredJvmType);
jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
nameClashResolver.resolveNameClashes(inferredJvmType);
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class AbstractReusableActiveAnnotationTests method testMarkReadAndInitialized.
@Test
public void testMarkReadAndInitialized() {
Pair<String, String> _mappedTo = Pair.<String, String>of("myannotation/InitAnnotation.xtend", "\n\t\t\t\tpackage myannotation\n\t\t\t\t\n\t\t\t\timport java.util.List\n\t\t\t\timport org.eclipse.xtend.lib.macro.Active\n\t\t\t\timport org.eclipse.xtend.lib.macro.TransformationContext\n\t\t\t\timport org.eclipse.xtend.lib.macro.TransformationParticipant\n\t\t\t\timport org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration\n\t\t\t\timport org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration\n\n\t\t\t\t@Active(InitProcessor)\n\t\t\t\tannotation Init { }\n\t\t\t\tclass InitProcessor implements TransformationParticipant<MutableFieldDeclaration> {\n\t\t\t\t\t\n\t\t\t\t\toverride doTransform(List<? extends MutableFieldDeclaration> annotatedTargetFields, extension TransformationContext context) {\n\t\t\t\t\t\tval ctor = annotatedTargetFields.head.declaringType.addConstructor [\n\t\t\t\t\t\t\tprimarySourceElement = declaringType\n\t\t\t\t\t\t\tbody = [\'\'\'\n\t\t\t\t\t\t\t\t�FOR f : annotatedTargetFields�\n\t\t\t\t\t\t\t\t\tthis.�f.simpleName� = \"foo\";\n\t\t\t\t\t\t\t\t�ENDFOR�\n\t\t\t\t\t\t\t\'\'\']\n\t\t\t\t\t\t]\n\t\t\t\t\t\tannotatedTargetFields.forEach [ field |\n\t\t\t\t\t\t\tfield.setFinal(true)\n\t\t\t\t\t\t\tfield.markAsRead\n\t\t\t\t\t\t\tfield.markAsInitializedBy(ctor)\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t");
StringConcatenation _builder = new StringConcatenation();
_builder.append("package myusercode");
_builder.newLine();
_builder.newLine();
_builder.append("class MyClass {");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@myannotation.Init String myField");
_builder.newLine();
_builder.append("}");
_builder.newLine();
Pair<String, String> _mappedTo_1 = Pair.<String, String>of("myusercode/MyClass.xtend", _builder.toString());
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
MutableClassDeclaration _findClass = it.getTypeLookup().findClass("myusercode.MyClass");
final JvmGenericType clazz = ((MutableJvmClassDeclarationImpl) _findClass).getDelegate();
this.validator.assertNoIssues(clazz);
};
this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class NonOverridableTypesProviderTest method testInheritMiddle_02.
@Test
public void testInheritMiddle_02() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.newLine();
_builder.append("import types.OuterClass");
_builder.newLine();
_builder.newLine();
_builder.append("class Foo extends OuterClass.MiddleClass {");
_builder.newLine();
_builder.append("\t");
_builder.append("def foo() ");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendClass xtendClass = this.clazz(_builder.toString());
final JvmGenericType inferredType = this.associations.getInferredType(xtendClass);
this.assertTypeInScope("Foo", inferredType);
this.assertTypeInScope("InnerMostClass", inferredType);
this.assertNotInScope("OuterClass.MiddleClass", inferredType);
this.assertNotInScope("MiddleClass", inferredType);
this.assertNotInScope("OuterClass", inferredType);
this.assertNotInScope("PrivateMiddleClass", inferredType);
final XtendMember method = xtendClass.getMembers().get(0);
final JvmOperation operation = this.associations.getDirectlyInferredOperation(((XtendFunction) method));
this.assertTypeInScope("Foo", operation);
this.assertTypeInScope("InnerMostClass", operation);
this.assertNotInScope("OuterClass.MiddleClass", operation);
this.assertNotInScope("MiddleClass", operation);
this.assertNotInScope("OuterClass", operation);
this.assertNotInScope("PrivateMiddleClass", inferredType);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations