use of org.eclipse.xtext.common.types.JvmEnumerationType in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreter method findVisibleFeatures.
/**
* looks up the static final fields which are accessible in unqualified form for the given expression.
* That essentially includes static imports and the fields declared in the containing types
*/
protected Map<String, JvmIdentifiableElement> findVisibleFeatures(final XExpression expression) {
HashMap<String, JvmIdentifiableElement> _xblockexpression = null;
{
Resource _eResource = expression.eResource();
final Resource res = _eResource;
boolean _matched = false;
if (res instanceof StorageAwareResource) {
boolean _isLoadedFromStorage = ((StorageAwareResource) res).isLoadedFromStorage();
if (_isLoadedFromStorage) {
_matched = true;
return CollectionLiterals.<String, JvmIdentifiableElement>newHashMap();
}
}
JvmDeclaredType _switchResult_1 = null;
JvmIdentifiableElement _nearestLogicalContainer = this.containerProvider.getNearestLogicalContainer(expression);
final JvmIdentifiableElement cont = _nearestLogicalContainer;
boolean _matched_1 = false;
if (cont instanceof JvmGenericType) {
_matched_1 = true;
_switchResult_1 = ((JvmGenericType) cont);
}
if (!_matched_1) {
if (cont instanceof JvmMember) {
_matched_1 = true;
_switchResult_1 = ((JvmMember) cont).getDeclaringType();
}
}
final JvmDeclaredType container = _switchResult_1;
Pair<String, JvmDeclaredType> _mappedTo = Pair.<String, JvmDeclaredType>of("visibleFeaturesForAnnotationValues", container);
final Provider<HashMap<String, JvmIdentifiableElement>> _function = () -> {
final HashMap<String, JvmIdentifiableElement> result = CollectionLiterals.<String, JvmIdentifiableElement>newHashMap();
Resource _eResource_1 = expression.eResource();
final XImportSection section = this.importSectionLocator.getImportSection(((XtextResource) _eResource_1));
if ((section != null)) {
EList<XImportDeclaration> _importDeclarations = section.getImportDeclarations();
for (final XImportDeclaration imp : _importDeclarations) {
boolean _isStatic = imp.isStatic();
if (_isStatic) {
final String importedTypeName = imp.getImportedTypeName();
if ((importedTypeName != null)) {
final JvmType type = this.findTypeByName(imp, importedTypeName);
boolean _matched_2 = false;
if (type instanceof JvmGenericType) {
_matched_2 = true;
this.collectAllVisibleFields(((JvmDeclaredType) type), result);
}
if (!_matched_2) {
if (type instanceof JvmEnumerationType) {
_matched_2 = true;
EList<JvmEnumerationLiteral> _literals = ((JvmEnumerationType) type).getLiterals();
for (final JvmEnumerationLiteral feature : _literals) {
result.put(feature.getSimpleName(), feature);
}
}
}
}
}
}
}
this.collectAllVisibleFields(container, result);
return result;
};
_xblockexpression = this.cache.<HashMap<String, JvmIdentifiableElement>>get(_mappedTo, expression.eResource(), _function);
}
return _xblockexpression;
}
use of org.eclipse.xtext.common.types.JvmEnumerationType in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreter method _internalEvaluate.
protected Object _internalEvaluate(final XMemberFeatureCall it, final Context ctx) {
Object _eGet = it.eGet(XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, this.isResolveProxies(it));
final EObject feature = ((EObject) _eGet);
boolean _eIsProxy = feature.eIsProxy();
boolean _not = (!_eIsProxy);
if (_not) {
Object _switchResult = null;
boolean _matched = false;
if (feature instanceof JvmEnumerationLiteral) {
_matched = true;
_switchResult = feature;
}
if (!_matched) {
if (feature instanceof JvmField) {
_matched = true;
_switchResult = this.evaluateField(it, ((JvmField) feature), ctx);
}
}
if (!_matched) {
if (feature instanceof JvmType) {
_matched = true;
_switchResult = this.toTypeReference(((JvmType) feature), 0);
}
}
return _switchResult;
}
final String featureName = it.getConcreteSyntaxFeatureName();
try {
final Object receiver = this.evaluate(it.getMemberCallTarget(), ctx);
boolean _matched_1 = false;
if (receiver instanceof JvmTypeReference) {
_matched_1 = true;
JvmType _type = ((JvmTypeReference) receiver).getType();
final JvmType type = _type;
boolean _matched_2 = false;
if (type instanceof JvmEnumerationType) {
_matched_2 = true;
final Function1<JvmEnumerationLiteral, Boolean> _function = (JvmEnumerationLiteral it_1) -> {
String _simpleName = it_1.getSimpleName();
return Boolean.valueOf(Objects.equal(_simpleName, featureName));
};
final JvmEnumerationLiteral enumValue = IterableExtensions.<JvmEnumerationLiteral>findFirst(((JvmEnumerationType) type).getLiterals(), _function);
if ((enumValue == null)) {
String _simpleName = ((JvmTypeReference) receiver).getSimpleName();
String _plus = ((("Couldn\'t find enum value " + featureName) + " on enum ") + _simpleName);
throw new ConstantExpressionEvaluationException(_plus, it);
}
this.resolveFeature(it, enumValue);
return enumValue;
}
if (!_matched_2) {
if (type instanceof JvmGenericType) {
_matched_2 = true;
final Function1<JvmField, Boolean> _function = (JvmField it_1) -> {
String _simpleName = it_1.getSimpleName();
return Boolean.valueOf(Objects.equal(_simpleName, featureName));
};
final JvmField field = IterableExtensions.<JvmField>findFirst(Iterables.<JvmField>filter(((JvmGenericType) type).getAllFeatures(), JvmField.class), _function);
if ((field == null)) {
String _simpleName = ((JvmTypeReference) receiver).getSimpleName();
String _plus = ((("Couldn\'t find field " + featureName) + " on type ") + _simpleName);
throw new ConstantExpressionEvaluationException(_plus, it);
}
this.resolveFeature(it, field);
return this.evaluateField(it, field, ctx);
}
}
}
throw new UnresolvableFeatureException(((("Unresolvable feature " + featureName) + " on ") + receiver), it);
} catch (final Throwable _t) {
if (_t instanceof UnresolvableFeatureException) {
final String typeName = this.getFullName(it);
final JvmType type = this.findTypeByName(it, typeName);
if ((type != null)) {
this.resolveType(it, type);
return this.toTypeReference(type, 0);
} else {
throw new UnresolvableFeatureException(("Unresolvable type " + typeName), it);
}
} else {
throw Exceptions.sneakyThrow(_t);
}
}
}
use of org.eclipse.xtext.common.types.JvmEnumerationType in project xtext-xtend by eclipse.
the class CompilationUnitImpl method toTypeDeclaration.
public TypeDeclaration toTypeDeclaration(final JvmDeclaredType delegate) {
final Function1<JvmDeclaredType, TypeDeclaration> _function = (JvmDeclaredType it) -> {
JvmTypeDeclarationImpl<? extends JvmDeclaredType> _switchResult = null;
boolean _matched = false;
if (delegate instanceof JvmGenericType) {
boolean _isInterface = ((JvmGenericType) delegate).isInterface();
if (_isInterface) {
_matched = true;
JvmInterfaceDeclarationImpl _xifexpression = null;
boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
if (_isBelongedToCompilationUnit) {
MutableJvmInterfaceDeclarationImpl _mutableJvmInterfaceDeclarationImpl = new MutableJvmInterfaceDeclarationImpl();
final Procedure1<MutableJvmInterfaceDeclarationImpl> _function_1 = (MutableJvmInterfaceDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmGenericType) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<MutableJvmInterfaceDeclarationImpl>operator_doubleArrow(_mutableJvmInterfaceDeclarationImpl, _function_1);
} else {
JvmInterfaceDeclarationImpl _jvmInterfaceDeclarationImpl = new JvmInterfaceDeclarationImpl();
final Procedure1<JvmInterfaceDeclarationImpl> _function_2 = (JvmInterfaceDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmGenericType) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<JvmInterfaceDeclarationImpl>operator_doubleArrow(_jvmInterfaceDeclarationImpl, _function_2);
}
_switchResult = _xifexpression;
}
}
if (!_matched) {
if (delegate instanceof JvmGenericType) {
_matched = true;
JvmClassDeclarationImpl _xifexpression = null;
boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
if (_isBelongedToCompilationUnit) {
MutableJvmClassDeclarationImpl _mutableJvmClassDeclarationImpl = new MutableJvmClassDeclarationImpl();
final Procedure1<MutableJvmClassDeclarationImpl> _function_1 = (MutableJvmClassDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmGenericType) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<MutableJvmClassDeclarationImpl>operator_doubleArrow(_mutableJvmClassDeclarationImpl, _function_1);
} else {
JvmClassDeclarationImpl _jvmClassDeclarationImpl = new JvmClassDeclarationImpl();
final Procedure1<JvmClassDeclarationImpl> _function_2 = (JvmClassDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmGenericType) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<JvmClassDeclarationImpl>operator_doubleArrow(_jvmClassDeclarationImpl, _function_2);
}
_switchResult = _xifexpression;
}
}
if (!_matched) {
if (delegate instanceof JvmAnnotationType) {
_matched = true;
JvmAnnotationTypeDeclarationImpl _xifexpression = null;
boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
if (_isBelongedToCompilationUnit) {
MutableJvmAnnotationTypeDeclarationImpl _mutableJvmAnnotationTypeDeclarationImpl = new MutableJvmAnnotationTypeDeclarationImpl();
final Procedure1<MutableJvmAnnotationTypeDeclarationImpl> _function_1 = (MutableJvmAnnotationTypeDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmAnnotationType) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<MutableJvmAnnotationTypeDeclarationImpl>operator_doubleArrow(_mutableJvmAnnotationTypeDeclarationImpl, _function_1);
} else {
JvmAnnotationTypeDeclarationImpl _jvmAnnotationTypeDeclarationImpl = new JvmAnnotationTypeDeclarationImpl();
final Procedure1<JvmAnnotationTypeDeclarationImpl> _function_2 = (JvmAnnotationTypeDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmAnnotationType) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<JvmAnnotationTypeDeclarationImpl>operator_doubleArrow(_jvmAnnotationTypeDeclarationImpl, _function_2);
}
_switchResult = _xifexpression;
}
}
if (!_matched) {
if (delegate instanceof JvmEnumerationType) {
_matched = true;
JvmEnumerationTypeDeclarationImpl _xifexpression = null;
boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
if (_isBelongedToCompilationUnit) {
MutableJvmEnumerationTypeDeclarationImpl _mutableJvmEnumerationTypeDeclarationImpl = new MutableJvmEnumerationTypeDeclarationImpl();
final Procedure1<MutableJvmEnumerationTypeDeclarationImpl> _function_1 = (MutableJvmEnumerationTypeDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmEnumerationType) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<MutableJvmEnumerationTypeDeclarationImpl>operator_doubleArrow(_mutableJvmEnumerationTypeDeclarationImpl, _function_1);
} else {
JvmEnumerationTypeDeclarationImpl _jvmEnumerationTypeDeclarationImpl = new JvmEnumerationTypeDeclarationImpl();
final Procedure1<JvmEnumerationTypeDeclarationImpl> _function_2 = (JvmEnumerationTypeDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmEnumerationType) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<JvmEnumerationTypeDeclarationImpl>operator_doubleArrow(_jvmEnumerationTypeDeclarationImpl, _function_2);
}
_switchResult = _xifexpression;
}
}
return ((TypeDeclaration) _switchResult);
};
return this.<JvmDeclaredType, TypeDeclaration>getOrCreate(delegate, _function);
}
use of org.eclipse.xtext.common.types.JvmEnumerationType in project xtext-xtend by eclipse.
the class AnnotationValidation method isValidAnnotationValueType.
public boolean isValidAnnotationValueType(final JvmTypeReference reference) {
JvmTypeReference _switchResult = null;
boolean _matched = false;
if (reference instanceof JvmGenericArrayTypeReference) {
_matched = true;
_switchResult = ((JvmGenericArrayTypeReference) reference).getComponentType();
}
if (!_matched) {
_switchResult = reference;
}
final JvmTypeReference toCheck = _switchResult;
if ((toCheck == null)) {
return true;
}
JvmType _type = toCheck.getType();
if ((_type instanceof JvmPrimitiveType)) {
return true;
}
JvmType _type_1 = toCheck.getType();
if ((_type_1 instanceof JvmEnumerationType)) {
return true;
}
JvmType _type_2 = toCheck.getType();
if ((_type_2 instanceof JvmAnnotationType)) {
return true;
}
if ((Objects.equal(toCheck.getType().getQualifiedName(), "java.lang.String") || Objects.equal(toCheck.getType().getQualifiedName(), "java.lang.Class"))) {
return true;
}
return false;
}
use of org.eclipse.xtext.common.types.JvmEnumerationType in project xtext-xtend by eclipse.
the class JvmModelTests method testEnumImplicitSuperType.
@Test
public void testEnumImplicitSuperType() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("enum Foo {");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final JvmEnumerationType inferred = this._iXtendJvmAssociations.getInferredEnumerationType(this.enumeration(_builder.toString()));
Assert.assertEquals(1, inferred.getSuperTypes().size());
Assert.assertEquals("java.lang.Enum<Foo>", IterableExtensions.<JvmTypeReference>head(inferred.getSuperTypes()).getIdentifier());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations