use of org.eclipse.xtext.xbase.XAbstractFeatureCall in project xtext-xtend by eclipse.
the class XtendHoverGenericsResolverTest method testGenerics_2.
@Test
public void testGenerics_2() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package testPackage");
_builder.newLine();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("def bar(){");
_builder.newLine();
_builder.append("\t\t");
_builder.append("something(newArrayList(\"zonk\"), new Foo(),\"42\")");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("def <T,Y,E extends RuntimeException> Y something(Iterable<T> iterable, Y type1, T type2) throws E");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
final Iterable<XtendClass> clazz = Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class);
XtendMember _get = IterableExtensions.<XtendClass>head(clazz).getMembers().get(0);
final XtendFunction function = ((XtendFunction) _get);
XExpression _expression = function.getExpression();
final XBlockExpression expression = ((XBlockExpression) _expression);
XExpression _get_1 = expression.getExpressions().get(0);
final XAbstractFeatureCall call = ((XAbstractFeatureCall) _get_1);
final String resolvedSignature = this.signatureProvider.getSignature(call);
Assert.assertEquals("<String, Foo, RuntimeException> Foo Foo.something(Iterable<String> iterable, Foo type1, String type2) throws RuntimeException", resolvedSignature);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.XAbstractFeatureCall in project xtext-xtend by eclipse.
the class SuspiciousOverloadValidationTest method assertSuspicious.
protected void assertSuspicious(final CharSequence contents, final String... messageParts) {
final XtendFile file = this.getParsedXtendFile(contents);
final EList<Resource.Diagnostic> errors = file.eResource().getErrors();
Assert.assertEquals(errors.toString(), 1, errors.size());
Resource.Diagnostic _head = IterableExtensions.<Resource.Diagnostic>head(errors);
final AbstractDiagnostic singleError = ((AbstractDiagnostic) _head);
Assert.assertEquals(singleError.getMessage(), IssueCodes.SUSPICIOUSLY_OVERLOADED_FEATURE, singleError.getCode());
final Function1<String, String> _function = (String it) -> {
return Strings.toUnixLineSeparator(it);
};
final Consumer<String> _function_1 = (String it) -> {
final String message = singleError.getMessage();
boolean _contains = message.contains(it);
boolean _not = (!_contains);
if (_not) {
Assert.assertEquals(it, message);
}
};
ListExtensions.<String, String>map(((List<String>) Conversions.doWrapArray(messageParts)), _function).forEach(_function_1);
final XtendTypeDeclaration firstType = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
XtendMember _head_1 = IterableExtensions.<XtendMember>head(firstType.getMembers());
final XtendFunction firstMember = ((XtendFunction) _head_1);
XExpression _expression = firstMember.getExpression();
final XBlockExpression block = ((XBlockExpression) _expression);
final Function1<XAbstractFeatureCall, Boolean> _function_2 = (XAbstractFeatureCall it) -> {
return Boolean.valueOf(((!Objects.equal(it.eContainingFeature(), XbasePackage.Literals.XABSTRACT_FEATURE_CALL__IMPLICIT_RECEIVER)) && (it.getFeature() instanceof JvmOperation)));
};
final XAbstractFeatureCall featureCall = IteratorExtensions.<XAbstractFeatureCall>findLast(Iterators.<XAbstractFeatureCall>filter(block.eAllContents(), XAbstractFeatureCall.class), _function_2);
final IFeatureLinkingCandidate linkingCandidate = this._iBatchTypeResolver.resolveTypes(file).getLinkingCandidate(featureCall);
Assert.assertTrue((linkingCandidate instanceof ISuspiciouslyOverloadedCandidate));
}
use of org.eclipse.xtext.xbase.XAbstractFeatureCall in project xtext-xtend by eclipse.
the class SuspiciousOverloadValidationTest method assertSuspiciousInInnerClass.
protected void assertSuspiciousInInnerClass(final CharSequence contents, final String... messageParts) {
final XtendFile file = this.getParsedXtendFile(contents);
final EList<Resource.Diagnostic> errors = file.eResource().getErrors();
Assert.assertEquals(errors.toString(), 1, errors.size());
Resource.Diagnostic _head = IterableExtensions.<Resource.Diagnostic>head(errors);
final AbstractDiagnostic singleError = ((AbstractDiagnostic) _head);
Assert.assertEquals(singleError.getMessage(), IssueCodes.SUSPICIOUSLY_OVERLOADED_FEATURE, singleError.getCode());
final Function1<String, String> _function = (String it) -> {
return Strings.toUnixLineSeparator(it);
};
final Consumer<String> _function_1 = (String it) -> {
final String message = singleError.getMessage();
boolean _contains = message.contains(it);
boolean _not = (!_contains);
if (_not) {
Assert.assertEquals(it, message);
}
};
ListExtensions.<String, String>map(((List<String>) Conversions.doWrapArray(messageParts)), _function).forEach(_function_1);
final XtendTypeDeclaration firstType = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
XtendMember _head_1 = IterableExtensions.<XtendMember>head(firstType.getMembers());
final XtendClass innerType = ((XtendClass) _head_1);
XtendMember _head_2 = IterableExtensions.<XtendMember>head(innerType.getMembers());
final XtendFunction firstMember = ((XtendFunction) _head_2);
XExpression _expression = firstMember.getExpression();
final XBlockExpression block = ((XBlockExpression) _expression);
final Function1<XAbstractFeatureCall, Boolean> _function_2 = (XAbstractFeatureCall it) -> {
return Boolean.valueOf(((!Objects.equal(it.eContainingFeature(), XbasePackage.Literals.XABSTRACT_FEATURE_CALL__IMPLICIT_RECEIVER)) && (it.getFeature() instanceof JvmOperation)));
};
final XAbstractFeatureCall featureCall = IteratorExtensions.<XAbstractFeatureCall>findLast(Iterators.<XAbstractFeatureCall>filter(block.eAllContents(), XAbstractFeatureCall.class), _function_2);
final IFeatureLinkingCandidate linkingCandidate = this._iBatchTypeResolver.resolveTypes(file).getLinkingCandidate(featureCall);
Assert.assertTrue((linkingCandidate instanceof ISuspiciouslyOverloadedCandidate));
}
use of org.eclipse.xtext.xbase.XAbstractFeatureCall in project xtext-xtend by eclipse.
the class XtendHoverSerializer method computeUnsugaredExpression.
public String computeUnsugaredExpression(EObject object) {
if (object instanceof XAbstractFeatureCall) {
StringBuilder stringBuilder = new StringBuilder();
XAbstractFeatureCall featureCall = (XAbstractFeatureCall) object;
JvmIdentifiableElement feature = featureCall.getFeature();
if (feature != null && !feature.eIsProxy()) {
// Static extensions which are no expliciteOperationCalls
if (featureCall instanceof XMemberFeatureCall && feature instanceof JvmOperation && !((XMemberFeatureCall) featureCall).isExplicitOperationCall()) {
JvmOperation jvmOperation = (JvmOperation) feature;
if (jvmOperation.isStatic()) {
return stringBuilder.append(getStaticCallDesugaredVersion(featureCall, jvmOperation)).toString();
}
}
// Static calls with implicit receiver or implicit first argument
if (featureCall.getImplicitReceiver() != null || featureCall.getImplicitFirstArgument() != null) {
if (featureCall.isStatic()) {
return stringBuilder.append(getStaticCallDesugaredVersion(featureCall, (JvmMember) feature)).toString();
}
XExpression receiver = featureCall.getActualReceiver();
if (receiver instanceof XMemberFeatureCall) {
stringBuilder.append(THIS).append(DELIMITER);
stringBuilder.append(((XMemberFeatureCall) receiver).getFeature().getSimpleName()).append(DELIMITER);
} else if (receiver instanceof XAbstractFeatureCall) {
JvmIdentifiableElement receiverFeature = ((XAbstractFeatureCall) receiver).getFeature();
if (receiverFeature == feature.eContainer()) {
stringBuilder.append(THIS).append(DELIMITER);
} else {
stringBuilder.append(receiverFeature.getSimpleName()).append(DELIMITER);
}
}
stringBuilder.append(feature.getSimpleName());
if (feature instanceof JvmExecutable)
stringBuilder.append(computeArguments(featureCall));
return stringBuilder.toString();
}
}
}
return "";
}
use of org.eclipse.xtext.xbase.XAbstractFeatureCall in project xtext-xtend by eclipse.
the class CreateMemberQuickfixes method isThis.
protected boolean isThis(XAssignment assigment) {
XExpression assignable = assigment.getAssignable();
if (!(assignable instanceof XAbstractFeatureCall)) {
return false;
}
XAbstractFeatureCall featureCall = (XAbstractFeatureCall) assignable;
return featureCall.getFeature() instanceof JvmDeclaredType && !featureCall.isExplicitOperationCallOrBuilderSyntax() && !featureCall.isTypeLiteral();
}
Aggregations