use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class XtendValidator method doCheckFunctionOverrides.
protected void doCheckFunctionOverrides(EObject sourceElement, IResolvedOperation resolved, List<IResolvedOperation> allInherited) {
boolean overrideProblems = false;
List<IResolvedOperation> exceptionMismatch = null;
for (IResolvedOperation inherited : allInherited) {
if (inherited.getOverrideCheckResult().hasProblems()) {
overrideProblems = true;
EnumSet<OverrideCheckDetails> details = inherited.getOverrideCheckResult().getDetails();
if (details.contains(OverrideCheckDetails.IS_FINAL)) {
error("Attempt to override final method " + inherited.getSimpleSignature(), sourceElement, nameFeature(sourceElement), OVERRIDDEN_FINAL);
} else if (details.contains(OverrideCheckDetails.REDUCED_VISIBILITY)) {
error("Cannot reduce the visibility of the overridden method " + inherited.getSimpleSignature(), sourceElement, nameFeature(sourceElement), OVERRIDE_REDUCES_VISIBILITY);
} else if (details.contains(OverrideCheckDetails.EXCEPTION_MISMATCH)) {
if (exceptionMismatch == null)
exceptionMismatch = Lists.newArrayListWithCapacity(allInherited.size());
exceptionMismatch.add(inherited);
} else if (details.contains(OverrideCheckDetails.RETURN_MISMATCH)) {
error("The return type is incompatible with " + inherited.getSimpleSignature(), sourceElement, returnTypeFeature(sourceElement), INCOMPATIBLE_RETURN_TYPE);
} else if (details.contains(OverrideCheckDetails.SYNCHRONIZED_MISMATCH)) {
warning("The overridden method is synchronized, the current one is not synchronized.", sourceElement, nameFeature(sourceElement), MISSING_SYNCHRONIZED);
}
}
}
if (exceptionMismatch != null) {
createExceptionMismatchError(resolved, sourceElement, exceptionMismatch);
}
if (sourceElement instanceof XtendFunction) {
XtendFunction function = (XtendFunction) sourceElement;
if (!overrideProblems && !function.isOverride() && !function.isStatic()) {
error("The method " + resolved.getSimpleSignature() + " of type " + getDeclaratorName(resolved) + " must use override keyword since it actually overrides a supertype method.", function, XTEND_FUNCTION__NAME, MISSING_OVERRIDE);
}
if (!overrideProblems && function.isOverride() && function.isStatic()) {
for (IResolvedOperation inherited : allInherited) {
error("The method " + resolved.getSimpleSignature() + " of type " + getDeclaratorName(resolved) + " shadows the method " + resolved.getSimpleSignature() + " of type " + getDeclaratorName(inherited) + ", but does not override it.", function, XTEND_FUNCTION__NAME, function.getModifiers().indexOf("override"), OBSOLETE_OVERRIDE);
}
}
if (function.isOverride()) {
for (XAnnotation anno : function.getAnnotations()) {
if (anno != null && anno.getAnnotationType() != null && Override.class.getName().equals(anno.getAnnotationType().getIdentifier())) {
warning("Superfluous @Override annotation", anno, null, OBSOLETE_ANNOTATION_OVERRIDE);
}
}
}
}
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class XtendValidator method addDispatchError.
protected void addDispatchError(JvmOperation jvmOperation, String message, String modifier, String ISSUE_ID) {
XtendFunction function = associations.getXtendFunction(jvmOperation);
if (function != null) {
int modifierIndex = -1;
if (modifier != null) {
modifierIndex = function.getModifiers().indexOf(modifier);
} else {
for (int i = 0; i < function.getModifiers().size(); ++i) {
if (visibilityModifers.contains(function.getModifiers().get(i))) {
modifierIndex = i;
break;
}
}
}
if (modifierIndex == -1)
modifierIndex = function.getModifiers().indexOf("dispatch");
error(message, function, XTEND_MEMBER__MODIFIERS, modifierIndex, ISSUE_ID);
}
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class ProblemSupportImpl method getSignificantFeature.
public EStructuralFeature getSignificantFeature(final EObject obj) {
EStructuralFeature _switchResult = null;
boolean _matched = false;
if (obj instanceof XtendTypeDeclaration) {
_matched = true;
_switchResult = XtendPackage.eINSTANCE.getXtendTypeDeclaration_Name();
}
if (!_matched) {
if (obj instanceof XtendField) {
_matched = true;
_switchResult = XtendPackage.eINSTANCE.getXtendField_Name();
}
}
if (!_matched) {
if (obj instanceof XtendFunction) {
_matched = true;
_switchResult = XtendPackage.eINSTANCE.getXtendFunction_Name();
}
}
if (!_matched) {
if (obj instanceof JvmFormalParameter) {
_matched = true;
_switchResult = TypesPackage.eINSTANCE.getJvmFormalParameter_Name();
}
}
if (!_matched) {
if (obj instanceof XAnnotation) {
_matched = true;
_switchResult = XAnnotationsPackage.eINSTANCE.getXAnnotation_AnnotationType();
}
}
return _switchResult;
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreterTest method evaluatesWithException.
protected void evaluatesWithException(final String expression, final Procedure1<? super ConstantExpressionEvaluationException> exceptionAssertions) {
try {
final XtendFunction function = this.function((("def void testFoo() { " + expression) + " }"));
XExpression _expression = function.getExpression();
final XExpression expr = IterableExtensions.<XExpression>head(((XBlockExpression) _expression).getExpressions());
try {
this.interpreter.evaluate(expr, null);
Assert.fail("exception expected");
} catch (final Throwable _t) {
if (_t instanceof ConstantExpressionEvaluationException) {
final ConstantExpressionEvaluationException e = (ConstantExpressionEvaluationException) _t;
exceptionAssertions.apply(e);
} else {
throw Exceptions.sneakyThrow(_t);
}
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreterTest method evaluatesTo.
protected void evaluatesTo(final Pair<String, String> typeAndExpression, final Procedure1<? super Object> assertions) {
try {
final String type = typeAndExpression.getKey();
final String expression = typeAndExpression.getValue();
String _elvis = null;
if (type != null) {
_elvis = type;
} else {
_elvis = "void";
}
String _plus = ("def " + _elvis);
String _plus_1 = (_plus + " testFoo() { ");
String _plus_2 = (_plus_1 + expression);
String _plus_3 = (_plus_2 + " }");
final XtendFunction function = this.function(_plus_3);
XExpression _expression = function.getExpression();
final XExpression expr = IterableExtensions.<XExpression>head(((XBlockExpression) _expression).getExpressions());
JvmTypeReference _xifexpression = null;
if ((type != null)) {
_xifexpression = function.getReturnType();
}
final Object value = this.interpreter.evaluate(expr, _xifexpression);
assertions.apply(value);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations