Java Code Examples for org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation#getOverriddenAndImplementedMethods()

The following examples show how to use org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation#getOverriddenAndImplementedMethods() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XtendValidator.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected void doCheckFunctionOverrides(IResolvedOperation operation, Set<EObject> flaggedOperations) {
	EObject sourceElement = findPrimarySourceElement(operation);
	if (sourceElement != null) {
		List<IResolvedOperation> allInherited = operation.getOverriddenAndImplementedMethods();
		if (allInherited.isEmpty()) {
			if (sourceElement instanceof XtendFunction && flaggedOperations.add(sourceElement)) {
				XtendFunction function = (XtendFunction) sourceElement;
				if (function.isOverride()) {
					error("The method "+ operation.getSimpleSignature() +" of type "+getDeclaratorName(operation.getDeclaration())+" must override a superclass method.", 
							function, XTEND_MEMBER__MODIFIERS, function.getModifiers().indexOf("override"), OBSOLETE_OVERRIDE);
				} else {
					for (XAnnotation anno : function.getAnnotations()) {
						if (anno != null && anno.getAnnotationType() != null && Override.class.getName().equals(anno.getAnnotationType().getIdentifier())) {
							error("Superfluous @Override annotation", anno, null, OBSOLETE_ANNOTATION_OVERRIDE);
						}
					}
				}
			}
		} else if (flaggedOperations.add(sourceElement)) {
			doCheckFunctionOverrides(sourceElement, operation, allInherited);
		}
	}
}
 
Example 2
Source File: ResolvedOperationTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testListToArrayInheritsOne() {
  final IResolvedOperation operation = this.toOperation("(null as java.util.List<String>).toArray(null)");
  final List<IResolvedOperation> overridden = operation.getOverriddenAndImplementedMethods();
  Assert.assertEquals(1, overridden.size());
  final JvmTypeParameter typeParameter = IterableExtensions.<JvmTypeParameter>head(IterableExtensions.<IResolvedOperation>head(overridden).getResolvedTypeParameters());
  Assert.assertEquals(operation.getDeclaration(), typeParameter.getDeclarator());
}
 
Example 3
Source File: ResolvedOperationTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testArrayListToArrayInheritsTwo() {
  final IResolvedOperation operation = this.toOperation("(null as java.util.ArrayList<String>).toArray(null)");
  final List<IResolvedOperation> overridden = operation.getOverriddenAndImplementedMethods();
  Assert.assertEquals(2, overridden.size());
  final JvmTypeParameter typeParameter = IterableExtensions.<JvmTypeParameter>head(IterableExtensions.<IResolvedOperation>head(overridden).getResolvedTypeParameters());
  Assert.assertEquals(operation.getDeclaration(), typeParameter.getDeclarator());
  final JvmTypeParameter typeParameterOfLast = IterableExtensions.<JvmTypeParameter>head(IterableExtensions.<IResolvedOperation>last(overridden).getResolvedTypeParameters());
  Assert.assertEquals(operation.getDeclaration(), typeParameterOfLast.getDeclarator());
}
 
Example 4
Source File: ResolvedOperationTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testInheritedAbstractCollectionIteratorIsNotBottom() {
  final IResolvedOperation operation = this.toOperation("newHashSet(\"\").iterator");
  final List<IResolvedOperation> candidates = operation.getOverriddenAndImplementedMethods();
  Assert.assertFalse(IterableExtensions.<IResolvedOperation>head(candidates).isBottomInContext());
  Assert.assertEquals("AbstractCollection<String>", IterableExtensions.<IResolvedOperation>head(candidates).getAsBottom().getContextType().getSimpleName());
}
 
Example 5
Source File: XtendMethodDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<? extends MethodDeclaration> getOverriddenOrImplementedMethods() {
  boolean _isOverride = this.getDelegate().isOverride();
  if (_isOverride) {
    final JvmOperation jvmOperation = this.getCompilationUnit().getJvmModelAssociations().getDirectlyInferredOperation(this.getDelegate());
    final ResolvedFeatures resolvedFeatures = this.getCompilationUnit().getOverrideHelper().getResolvedFeatures(jvmOperation.getDeclaringType());
    final IResolvedOperation resolvedOperation = resolvedFeatures.getResolvedOperation(jvmOperation);
    final List<IResolvedOperation> overriddenOrImplemented = resolvedOperation.getOverriddenAndImplementedMethods();
    final Function1<IResolvedOperation, MemberDeclaration> _function = (IResolvedOperation it) -> {
      return this.getCompilationUnit().toMemberDeclaration(it.getDeclaration());
    };
    return Iterables.<MethodDeclaration>filter(ListExtensions.<IResolvedOperation, MemberDeclaration>map(overriddenOrImplemented, _function), MethodDeclaration.class);
  }
  return CollectionLiterals.<MethodDeclaration>emptyList();
}
 
Example 6
Source File: JvmMethodDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<? extends MethodDeclaration> getOverriddenOrImplementedMethods() {
  final ResolvedFeatures resolvedFeatures = this.getCompilationUnit().getOverrideHelper().getResolvedFeatures(this.getDelegate().getDeclaringType());
  final IResolvedOperation resolvedOperation = resolvedFeatures.getResolvedOperation(this.getDelegate());
  final List<IResolvedOperation> overriddenOrImplemented = resolvedOperation.getOverriddenAndImplementedMethods();
  final Function1<IResolvedOperation, MemberDeclaration> _function = (IResolvedOperation it) -> {
    return this.getCompilationUnit().toMemberDeclaration(it.getDeclaration());
  };
  return Iterables.<MethodDeclaration>filter(ListExtensions.<IResolvedOperation, MemberDeclaration>map(overriddenOrImplemented, _function), MethodDeclaration.class);
}
 
Example 7
Source File: ResolvedOperationTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected IResolvedOperation candidatesAndOverrides(final IResolvedOperation operation, final int overrides) {
  final List<IResolvedOperation> actualOverrides = operation.getOverriddenAndImplementedMethods();
  Assert.assertEquals("overrides", overrides, actualOverrides.size());
  return operation;
}