use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class DispatchHelper method getMaxDistanceToObject.
protected int getMaxDistanceToObject(JvmTypeReference type) {
type = primitives.asWrapperTypeIfPrimitive(type);
if (typeRefs.is(type, Object.class))
return 0;
JvmType jvmType = type.getType();
int maxDistance = 1;
if (jvmType instanceof JvmDeclaredType) {
EList<JvmTypeReference> list = ((JvmDeclaredType) jvmType).getSuperTypes();
for (JvmTypeReference jvmTypeReference : list) {
int result = 1 + getMaxDistanceToObject(jvmTypeReference);
if (result > maxDistance)
maxDistance = result;
}
}
return maxDistance;
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class DispatchHelper method getLocalDispatchCases.
/**
* Return the local cases that contribute to the given dispatch operation (in no particular order, but usually as defined in the file).
*/
public List<JvmOperation> getLocalDispatchCases(JvmOperation dispatcherOperation) {
DispatchSignature dispatchSignature = new DispatchSignature(dispatcherOperation.getSimpleName(), dispatcherOperation.getParameters().size());
JvmDeclaredType type = dispatcherOperation.getDeclaringType();
return getLocalDispatchCases(type, dispatchSignature);
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class DispatchHelper method getAllDispatchCases.
/**
* Return all the cases that are associated with the given dispatch operation.
*/
public List<JvmOperation> getAllDispatchCases(JvmOperation dispatcherOperation) {
DispatchSignature dispatchSignature = new DispatchSignature(dispatcherOperation.getSimpleName(), dispatcherOperation.getParameters().size());
JvmDeclaredType type = dispatcherOperation.getDeclaringType();
ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, type);
ContextualVisibilityHelper contextualVisibilityHelper = new ContextualVisibilityHelper(visibilityHelper, owner.newParameterizedTypeReference(type));
return getAllDispatchMethods(dispatchSignature, type, contextualVisibilityHelper);
}
use of org.eclipse.xtext.common.types.JvmDeclaredType 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.JvmDeclaredType in project xtext-xtend by eclipse.
the class AnnotationReferenceProviderImpl method newAnnotationReference.
@Override
public AnnotationReference newAnnotationReference(final Type annotationTypeDelcaration, final Procedure1<AnnotationReferenceBuildContext> initializer) {
Object _xblockexpression = null;
{
this.compilationUnit.checkCanceled();
StringConcatenation _builder = new StringConcatenation();
_builder.append("annotationTypeDelcaration cannot be null");
Preconditions.checkArgument((annotationTypeDelcaration != null), _builder);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("initializer cannot be null");
Preconditions.checkArgument((initializer != null), _builder_1);
JvmDeclaredType _switchResult = null;
boolean _matched = false;
if (annotationTypeDelcaration instanceof JvmAnnotationTypeDeclarationImpl) {
_matched = true;
_switchResult = ((JvmAnnotationTypeDeclarationImpl) annotationTypeDelcaration).getDelegate();
}
if (!_matched) {
if (annotationTypeDelcaration instanceof XtendAnnotationTypeDeclarationImpl) {
_matched = true;
_switchResult = this.compilationUnit.getJvmModelAssociations().getInferredType(((XtendAnnotationTypeDeclarationImpl) annotationTypeDelcaration).getDelegate());
}
}
if (!_matched) {
throw new IllegalArgumentException(("couldn\'t construct type reference for type " + annotationTypeDelcaration));
}
final JvmDeclaredType type = _switchResult;
if ((type instanceof JvmAnnotationType)) {
final JvmAnnotationReference newJvmAnnotationReference = this.createJvmAnnotationReference(type);
AnnotationReferenceBuildContextImpl _annotationReferenceBuildContextImpl = new AnnotationReferenceBuildContextImpl();
final Procedure1<AnnotationReferenceBuildContextImpl> _function = (AnnotationReferenceBuildContextImpl it) -> {
it.setDelegate(newJvmAnnotationReference);
it.setCompilationUnit(this.compilationUnit);
};
final AnnotationReferenceBuildContextImpl buildContext = ObjectExtensions.<AnnotationReferenceBuildContextImpl>operator_doubleArrow(_annotationReferenceBuildContextImpl, _function);
initializer.apply(buildContext);
return this.compilationUnit.toAnnotationReference(newJvmAnnotationReference);
}
_xblockexpression = null;
}
return ((AnnotationReference) _xblockexpression);
}
Aggregations