use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.
the class XtendReentrantTypeResolver method computeTypes.
protected void computeTypes(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, XtendMember member) {
XExpression expression = null;
if (member instanceof XtendFunction) {
XtendFunction function = (XtendFunction) member;
expression = function.getExpression();
CreateExtensionInfo createInfo = function.getCreateExtensionInfo();
if (createInfo != null) {
computeDanglingExpressionType(resolvedTypes, featureScopeSession, function, createInfo.getCreateExpression());
}
for (XtendParameter parameter : function.getParameters()) {
computeXtendAnnotationTypes(resolvedTypes, featureScopeSession, parameter.getAnnotations());
}
} else if (member instanceof XtendConstructor) {
XtendConstructor constructor = (XtendConstructor) member;
expression = constructor.getExpression();
for (XtendParameter parameter : constructor.getParameters()) {
computeXtendAnnotationTypes(resolvedTypes, featureScopeSession, parameter.getAnnotations());
}
} else if (member instanceof XtendField) {
expression = ((XtendField) member).getInitialValue();
}
if (expression != null) {
computeDanglingExpressionType(resolvedTypes, featureScopeSession, member, expression);
}
computeXtendAnnotationTypes(resolvedTypes, featureScopeSession, member.getAnnotations());
}
use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.
the class XtendValidator method checkAnnotationTarget.
@Check
public void checkAnnotationTarget(XAnnotation annotation) {
JvmType annotationType = annotation.getAnnotationType();
if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType)) {
return;
}
Set<ElementType> targets = annotationUtil.getAnnotationTargets((JvmAnnotationType) annotationType);
if (targets.isEmpty())
return;
final EObject eContainer = getContainingAnnotationTarget(annotation);
Class<? extends EObject> clazz = eContainer.getClass();
if (eContainer instanceof XtendField && eContainer.eContainer() instanceof XtendAnnotationType) {
clazz = XtendFunction.class;
}
for (Entry<Class<?>, Collection<ElementType>> mapping : targetInfos.asMap().entrySet()) {
if (mapping.getKey().isAssignableFrom(clazz)) {
targets.retainAll(mapping.getValue());
if (targets.isEmpty()) {
error("The annotation @" + annotation.getAnnotationType().getSimpleName() + " is disallowed for this location.", annotation, null, INSIGNIFICANT_INDEX, ANNOTATION_WRONG_TARGET);
}
}
}
}
use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method inferLocalClass.
/**
* Anonymous classes are not inferred in the type inference phase, but later during type resolution.
*/
public void inferLocalClass(AnonymousClass anonymousClass, String localClassName, JvmFeature container) {
final JvmGenericType inferredType = typesFactory.createJvmGenericType();
inferredType.setSimpleName(localClassName);
inferredType.setAnonymous(!hasAdditionalMembers(anonymousClass));
inferredType.setFinal(true);
inferredType.setVisibility(JvmVisibility.DEFAULT);
inferredType.getSuperTypes().add(jvmTypesBuilder.inferredType(anonymousClass));
container.getLocalClasses().add(inferredType);
associator.associatePrimary(anonymousClass, inferredType);
for (XtendMember member : anonymousClass.getMembers()) {
if (member instanceof XtendField || (member instanceof XtendFunction && ((XtendFunction) member).getName() != null) || member instanceof XtendConstructor) {
transform(member, inferredType, true);
}
}
appendSyntheticDispatchMethods(anonymousClass, inferredType);
nameClashResolver.resolveNameClashes(inferredType);
final XConstructorCall constructorCall = anonymousClass.getConstructorCall();
for (XExpression actualParameter : constructorCall.getArguments()) {
associator.associateLogicalContainer(actualParameter, container);
}
}
use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.
the class InsertionOffsets method getNewFieldInsertOffset.
public int getNewFieldInsertOffset(final EObject call, final XtendTypeDeclaration ownerType) {
boolean _isEmpty = ownerType.getMembers().isEmpty();
if (_isEmpty) {
return this.inEmpty(ownerType);
}
final XtendField callingMember = EcoreUtil2.<XtendField>getContainerOfType(call, XtendField.class);
if (((callingMember != null) && ownerType.getMembers().contains(callingMember))) {
return this.before(callingMember);
}
final XtendField lastDefinedField = IterableExtensions.<XtendField>last(Iterables.<XtendField>filter(ownerType.getMembers(), XtendField.class));
if ((lastDefinedField == null)) {
return this.before(IterableExtensions.<XtendMember>head(ownerType.getMembers()));
} else {
return this.after(lastDefinedField);
}
}
use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.
the class XtendUIValidationTests method testDiscouragedConstructorCall.
@Test
public void testDiscouragedConstructorCall() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import org.eclipse.xtend.core.tests.internal.InternalClass");
_builder.newLine();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("InternalClass x = new InternalClass");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile xtendFile = this.testHelper.xtendFile("Clazz.xtend", _builder.toString());
this.helper.assertWarning(xtendFile.getImportSection().getImportDeclarations().get(0), XtypePackage.Literals.XIMPORT_DECLARATION, org.eclipse.xtext.xbase.validation.IssueCodes.DISCOURAGED_REFERENCE);
XtendMember _head = IterableExtensions.<XtendMember>head(IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class)).getMembers());
final XtendField field = ((XtendField) _head);
this.helper.assertWarning(field.getType(), TypesPackage.Literals.JVM_TYPE_REFERENCE, org.eclipse.xtext.xbase.validation.IssueCodes.DISCOURAGED_REFERENCE);
this.helper.assertWarning(field.getInitialValue(), XbasePackage.Literals.XCONSTRUCTOR_CALL, org.eclipse.xtext.xbase.validation.IssueCodes.DISCOURAGED_REFERENCE);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations