use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class XtendReentrantTypeResolver method getReturnTypeOfOverriddenOperation.
@Override
protected LightweightTypeReference getReturnTypeOfOverriddenOperation(JvmOperation operation, ResolvedTypes resolvedTypes, IFeatureScopeSession session) {
if (operation.getVisibility() == JvmVisibility.PRIVATE)
return null;
if (InferredTypeIndicator.isInferred(operation.getReturnType())) {
LightweightTypeReference declaringType = resolvedTypes.getActualType(operation.getDeclaringType());
if (declaringType == null) {
throw new IllegalStateException("Cannot determine declaring type of operation: " + operation);
}
BottomResolvedOperation resolvedOperation = new BottomResolvedOperation(operation, declaringType, overrideTester);
List<IResolvedOperation> overriddenMethods = resolvedOperation.getOverriddenAndImplementedMethods();
if (overriddenMethods.isEmpty())
return null;
IResolvedOperation overriddenMethod = overriddenMethods.get(0);
JvmOperation declaration = overriddenMethod.getDeclaration();
XExpression inferredFrom = getInferredFrom(declaration.getReturnType());
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=439535
if (inferredFrom != null && (inferredFrom == getInferredFrom(operation.getReturnType()) || isHandled(inferredFrom))) {
return null;
}
LightweightTypeReference result = overriddenMethod.getResolvedReturnType();
return result;
}
return null;
}
use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class XtendValidator method checkDefaultSuperConstructor.
@Check
public void checkDefaultSuperConstructor(XtendClass xtendClass) {
JvmGenericType inferredType = associations.getInferredType(xtendClass);
if (inferredType == null)
return;
Iterable<JvmConstructor> constructors = filter(inferredType.getMembers(), JvmConstructor.class);
if (inferredType.getExtendedClass() != null) {
JvmType superType = inferredType.getExtendedClass().getType();
if (superType instanceof JvmGenericType) {
Iterable<JvmConstructor> superConstructors = ((JvmGenericType) superType).getDeclaredConstructors();
for (JvmConstructor superConstructor : superConstructors) {
if (superConstructor.getParameters().isEmpty())
// there is a default super constructor. nothing more to check
return;
}
if (size(constructors) == 1 && typeExtensions.isSingleSyntheticDefaultConstructor(constructors.iterator().next())) {
List<String> issueData = newArrayList();
for (JvmConstructor superConstructor : superConstructors) {
issueData.add(EcoreUtil.getURI(superConstructor).toString());
issueData.add(doGetReadableSignature(xtendClass.getName(), superConstructor.getParameters()));
}
error("No default constructor in super type " + superType.getSimpleName() + "." + xtendClass.getName() + " must define an explicit constructor.", xtendClass, XTEND_TYPE_DECLARATION__NAME, MISSING_CONSTRUCTOR, toArray(issueData, String.class));
} else {
for (JvmConstructor constructor : constructors) {
XExpression expression = containerProvider.getAssociatedExpression(constructor);
if (expression instanceof XBlockExpression) {
List<XExpression> expressions = ((XBlockExpression) expression).getExpressions();
if (expressions.isEmpty() || !isDelegateConstructorCall(expressions.get(0))) {
EObject source = associations.getPrimarySourceElement(constructor);
error("No default constructor in super type " + superType.getSimpleName() + ". Another constructor must be invoked explicitly.", source, null, MUST_INVOKE_SUPER_CONSTRUCTOR);
}
}
}
}
}
}
}
use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class XtendValidator method checkImplicitReturn.
@Check
protected void checkImplicitReturn(final XtendFunction method) {
if (isIgnored(IMPLICIT_RETURN))
return;
JvmOperation jvmOperation = associations.getDirectlyInferredOperation(method);
IResolvedTypes types = batchTypeResolver.resolveTypes(method);
if (jvmOperation != null && types.getActualType(jvmOperation).isPrimitiveVoid())
return;
implicitReturnFinder.findImplicitReturns(method.getExpression(), new Acceptor() {
@Override
public void accept(XExpression implicitReturn) {
if (method.getExpression() == implicitReturn)
return;
addIssue("Implicit return", implicitReturn, IMPLICIT_RETURN);
}
});
}
use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class XtendHighlightingCalculator method highlightElement.
protected void highlightElement(XtendFunction function, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) {
highlightFeature(acceptor, function, XtendPackage.Literals.XTEND_FUNCTION__NAME, METHOD);
XExpression rootExpression = function.getExpression();
highlightRichStrings(rootExpression, acceptor);
CreateExtensionInfo createExtensionInfo = function.getCreateExtensionInfo();
if (createExtensionInfo != null) {
highlightRichStrings(createExtensionInfo.getCreateExpression(), acceptor);
}
}
use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class XtendHighlightingCalculator method highlightElement.
protected void highlightElement(XtendField field, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) {
highlightFeature(acceptor, field, XtendPackage.Literals.XTEND_FIELD__NAME, FIELD);
if (field.isStatic()) {
highlightFeature(acceptor, field, XtendPackage.Literals.XTEND_FIELD__NAME, STATIC_FIELD);
if (field.isFinal()) {
highlightFeature(acceptor, field, XtendPackage.Literals.XTEND_FIELD__NAME, STATIC_FINAL_FIELD);
}
}
XExpression initializer = field.getInitialValue();
highlightRichStrings(initializer, acceptor);
}
Aggregations