use of org.eclipse.xtext.xbase.XMemberFeatureCall in project xtext-xtend by eclipse.
the class XtendResourceDescription method getImportedNames.
@Override
public Iterable<QualifiedName> getImportedNames() {
if ((this.importedNames != null)) {
return this.importedNames;
}
final HashSet<QualifiedName> result = CollectionLiterals.<QualifiedName>newHashSet();
final EObject astRoot = IterableExtensions.<EObject>head(this.getResource().getContents());
if ((astRoot != null)) {
final IResolvedTypes types = this.typeResolver.resolveTypes(astRoot);
Iterable<XExpression> _filter = Iterables.<XExpression>filter(IteratorExtensions.<Object>toIterable(EcoreUtil.<Object>getAllContents(astRoot, true)), XExpression.class);
for (final XExpression expression : _filter) {
{
boolean _matched = false;
if (expression instanceof XMemberFeatureCall) {
if ((((((XMemberFeatureCall) expression).getFeature() != null) && ((XMemberFeatureCall) expression).getFeature().eIsProxy()) && (!((XMemberFeatureCall) expression).isExplicitOperationCallOrBuilderSyntax()))) {
_matched = true;
final XExpression receiver = ((XMemberFeatureCall) expression).getActualReceiver();
boolean _matched_1 = false;
if (receiver instanceof XAbstractFeatureCall) {
boolean _isTypeLiteral = ((XAbstractFeatureCall) receiver).isTypeLiteral();
if (_isTypeLiteral) {
_matched_1 = true;
final JvmIdentifiableElement type = ((XAbstractFeatureCall) receiver).getFeature();
String _identifier = type.getIdentifier();
String _plus = (_identifier + "$");
String _concreteSyntaxFeatureName = ((XMemberFeatureCall) expression).getConcreteSyntaxFeatureName();
String _plus_1 = (_plus + _concreteSyntaxFeatureName);
QualifiedName _lowerCase = this.nameConverter.toQualifiedName(_plus_1).toLowerCase();
result.add(_lowerCase);
}
}
}
}
if (!_matched) {
if (expression instanceof XAbstractFeatureCall) {
boolean _isTypeLiteral = ((XAbstractFeatureCall) expression).isTypeLiteral();
if (_isTypeLiteral) {
_matched = true;
final JvmIdentifiableElement type = ((XAbstractFeatureCall) expression).getFeature();
if ((type instanceof JvmDeclaredType)) {
final Function1<String, Boolean> _function = (String it) -> {
QualifiedName _lowerCase = this.nameConverter.toQualifiedName(it).toLowerCase();
return Boolean.valueOf(result.add(_lowerCase));
};
this.registerAllTypes(((JvmType) type), _function);
}
}
}
}
final LightweightTypeReference typeRef = types.getActualType(expression);
if ((typeRef != null)) {
final Function1<String, Boolean> _function = (String it) -> {
QualifiedName _lowerCase = this.nameConverter.toQualifiedName(it).toLowerCase();
return Boolean.valueOf(result.add(_lowerCase));
};
this.registerAllTypes(typeRef.getType(), _function);
}
}
}
EList<EObject> _contents = this.getResource().getContents();
for (final EObject eobject : _contents) {
{
final Function1<JvmIdentifiableElement, LightweightTypeReference> _function = (JvmIdentifiableElement it) -> {
LightweightTypeReference _xifexpression = null;
if (((!(it instanceof JvmType)) || (it instanceof JvmDeclaredType))) {
_xifexpression = types.getActualType(it);
}
return _xifexpression;
};
final Iterable<LightweightTypeReference> typesOfIdentifiables = IteratorExtensions.<LightweightTypeReference>toIterable(IteratorExtensions.<JvmIdentifiableElement, LightweightTypeReference>map(Iterators.<JvmIdentifiableElement>filter(EcoreUtil.<Object>getAllContents(eobject, true), JvmIdentifiableElement.class), _function));
for (final LightweightTypeReference typeRef : typesOfIdentifiables) {
if ((typeRef != null)) {
final Function1<String, Boolean> _function_1 = (String it) -> {
QualifiedName _lowerCase = this.nameConverter.toQualifiedName(it).toLowerCase();
return Boolean.valueOf(result.add(_lowerCase));
};
this.registerAllTypes(typeRef.getType(), _function_1);
}
}
}
}
}
Iterables.<QualifiedName>addAll(result, super.getImportedNames());
final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> {
boolean _contains = XtendResourceDescription.primitivesFilter.contains(it.getLastSegment());
return Boolean.valueOf((!_contains));
};
this.importedNames = IterableExtensions.<QualifiedName>toSet(IterableExtensions.<QualifiedName>filter(result, _function));
return this.importedNames;
}
use of org.eclipse.xtext.xbase.XMemberFeatureCall in project xtext-xtend by eclipse.
the class LinkingTest method testExplicitStaticInvocation_01.
@Test
public void testExplicitStaticInvocation_01() throws Exception {
XtendFile file = file("class C {\n" + " static def void getFields() {\n" + " C::fields" + " }" + "}\n");
XtendClass c = (XtendClass) file.getXtendTypes().get(0);
XtendFunction m = (XtendFunction) c.getMembers().get(0);
XBlockExpression body = (XBlockExpression) m.getExpression();
XMemberFeatureCall featureCall = (XMemberFeatureCall) body.getExpressions().get(0);
JvmIdentifiableElement method = featureCall.getFeature();
assertEquals("C.getFields()", method.getIdentifier());
}
use of org.eclipse.xtext.xbase.XMemberFeatureCall in project xtext-xtend by eclipse.
the class LinkingTest method testOverloadedMethods_15.
@Test
public void testOverloadedMethods_15() throws Exception {
XtendFile file = file("import java.util.Collection\n" + "class X {\n" + " def <T> foo(Collection<T> collection, Iterable<? extends T> elements) {\n" + " collection.addAll(elements)\n" + " }\n" + "}");
XtendClass clazz = (XtendClass) file.getXtendTypes().get(0);
XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
JvmIdentifiableElement addAll = featureCall.getFeature();
assertNotNull(addAll);
assertFalse(addAll.eIsProxy());
assertEquals("org.eclipse.xtext.xbase.lib.CollectionExtensions.addAll(java.util.Collection,java.lang.Iterable)", addAll.getIdentifier());
}
use of org.eclipse.xtext.xbase.XMemberFeatureCall in project xtext-xtend by eclipse.
the class LinkingTest method testMemberFeatureScope_0.
@Test
public void testMemberFeatureScope_0() throws Exception {
XtendFile file = file("import java.lang.String class X { def String foo(String foo) {foo.length()}}");
XtendClass xClass = (XtendClass) file.getXtendTypes().get(0);
XtendFunction func = (XtendFunction) xClass.getMembers().get(0);
XMemberFeatureCall call = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
assertEquals("length", ((JvmOperation) call.getFeature()).getSimpleName());
}
use of org.eclipse.xtext.xbase.XMemberFeatureCall in project xtext-xtend by eclipse.
the class LinkingTest method testBug345433_02.
@Test
public void testBug345433_02() throws Exception {
String classAsString = "import static extension org.eclipse.xtext.GrammarUtil.*\n" + "class Foo {" + " org.eclipse.xtext.Grammar grammar\n" + " def function1() {\n" + " grammar.containedRuleCalls.filter(e0 | " + " !e0.isAssigned() && !e0.isEObjectRuleCall()" + " ).map(e1 | e1.rule)\n" + " }\n" + "}";
XtendClass clazz = clazz(classAsString);
IResourceValidator validator = ((XtextResource) clazz.eResource()).getResourceServiceProvider().getResourceValidator();
List<Issue> issues = validator.validate(clazz.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
XtendFunction function = (XtendFunction) clazz.getMembers().get(1);
XExpression body = function.getExpression();
LightweightTypeReference bodyType = getType(body);
assertEquals("java.lang.Iterable<org.eclipse.xtext.AbstractRule>", bodyType.getIdentifier());
XBlockExpression block = (XBlockExpression) body;
XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(0);
XClosure closure = (XClosure) featureCall.getMemberCallArguments().get(0);
JvmFormalParameter e1 = closure.getFormalParameters().get(0);
assertEquals("e1", e1.getSimpleName());
assertEquals("org.eclipse.xtext.RuleCall", getType(e1).getIdentifier());
}
Aggregations