org.eclipse.xtext.xbase.typesystem.override.ResolvedFeatures Java Examples

The following examples show how to use org.eclipse.xtext.xbase.typesystem.override.ResolvedFeatures. 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: OverrideProposalUtil.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void addConstructorCandidates(ResolvedFeatures resolvedFeatures, IVisibilityHelper visibilityHelper,
		List<IResolvedExecutable> result) {
	LightweightTypeReference typeReference = resolvedFeatures.getType();
	List<LightweightTypeReference> superTypes = typeReference.getSuperTypes();
	for (LightweightTypeReference superType : superTypes) {
		if (!superType.isInterfaceType()) {
			List<IResolvedConstructor> declaredConstructors = resolvedFeatures.getDeclaredConstructors();
			Set<String> erasedSignatures = Sets.<String>newHashSet();
			for (IResolvedConstructor constructor : declaredConstructors) {
				erasedSignatures.add(constructor.getResolvedErasureSignature());
			}
			ResolvedFeatures superClass = overrideHelper.getResolvedFeatures(superType);
			for (IResolvedConstructor superclassConstructor : superClass.getDeclaredConstructors()) {
				IResolvedConstructor overriddenConstructor = new ResolvedConstructor(
						superclassConstructor.getDeclaration(), typeReference);
				if (isCandidate(typeReference, overriddenConstructor, visibilityHelper)) {
					if (erasedSignatures.add(superclassConstructor.getResolvedErasureSignature())) {
						result.add(overriddenConstructor);
					}
				}
			}
			return;
		}
	}
}
 
Example #2
Source File: ResolvedFeaturesTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public ResolvedFeatures toResolvedOperations(final Class<?> type) {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("typeof(");
    String _canonicalName = type.getCanonicalName();
    _builder.append(_canonicalName);
    _builder.append(")");
    XExpression _expression = this.expression(_builder);
    final XTypeLiteral typeLiteral = ((XTypeLiteral) _expression);
    JvmType _type = typeLiteral.getType();
    final ResolvedFeatures result = this.overrideHelper.getResolvedFeatures(((JvmDeclaredType) _type));
    return result;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #3
Source File: ResolvedFeaturesTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testSoftReferenceOfString() {
  final ResolvedFeatures resolvedOperations = this.toResolvedOperations("null as java.lang.ref.SoftReference<String>");
  Assert.assertEquals(1, resolvedOperations.getDeclaredOperations().size());
  Assert.assertEquals(2, resolvedOperations.getDeclaredConstructors().size());
  final Consumer<IResolvedConstructor> _function = (IResolvedConstructor it) -> {
    int _size = it.getDeclaration().getParameters().size();
    switch (_size) {
      case 1:
        Assert.assertEquals("SoftReference(java.lang.String)", it.getResolvedSignature());
        Assert.assertEquals("SoftReference(java.lang.String)", it.getResolvedErasureSignature());
        break;
      case 2:
        Assert.assertEquals("SoftReference(java.lang.String,java.lang.ref.ReferenceQueue<? super java.lang.String>)", it.getResolvedSignature());
        Assert.assertEquals("SoftReference(java.lang.String,java.lang.ref.ReferenceQueue)", it.getResolvedErasureSignature());
        break;
      default:
        Assert.fail(("Unexpected constructor: " + it));
        break;
    }
  };
  resolvedOperations.getDeclaredConstructors().forEach(_function);
}
 
Example #4
Source File: ResolvedFeaturesTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testSoftReferenceConstructors() {
  final ResolvedFeatures resolvedOperations = this.toResolvedOperations(SoftReference.class);
  Assert.assertEquals(1, resolvedOperations.getDeclaredOperations().size());
  Assert.assertEquals(2, resolvedOperations.getDeclaredConstructors().size());
  final Consumer<IResolvedConstructor> _function = (IResolvedConstructor it) -> {
    int _size = it.getDeclaration().getParameters().size();
    switch (_size) {
      case 1:
        Assert.assertEquals("SoftReference(T)", it.getResolvedSignature());
        Assert.assertEquals("SoftReference(java.lang.Object)", it.getResolvedErasureSignature());
        break;
      case 2:
        Assert.assertEquals("SoftReference(T,java.lang.ref.ReferenceQueue<? super T>)", it.getResolvedSignature());
        Assert.assertEquals("SoftReference(java.lang.Object,java.lang.ref.ReferenceQueue)", it.getResolvedErasureSignature());
        break;
      default:
        Assert.fail(("Unexpected constructor: " + it));
        break;
    }
  };
  resolvedOperations.getDeclaredConstructors().forEach(_function);
}
 
Example #5
Source File: XbaseCopyQualifiedNameService.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private IResolvedExecutable findDeclaredConstructor(JvmConstructor constructor, LightweightTypeReference actualType) {
	ResolvedFeatures resolvedFeatures = overrideHelper.getResolvedFeatures(actualType);
	for (IResolvedConstructor declaredConstructor : resolvedFeatures.getDeclaredConstructors()) {
		if (declaredConstructor.getDeclaration().equals(constructor)) {
			return declaredConstructor;
		}
	}
	return null;
}
 
Example #6
Source File: Bug621ResolvedFeatures.java    From sarl with Apache License 2.0 5 votes vote down vote up
private boolean _handleOverridesAndConflicts(JvmOperation operation, Multimap<String, AbstractResolvedOperation> processedOperations) {
	try {
		Method meth = ResolvedFeatures.class.getDeclaredMethod("handleOverridesAndConflicts", JvmOperation.class, Multimap.class);
		meth.setAccessible(true);
		return ((Boolean) meth.invoke(this, operation, processedOperations)).booleanValue();
	} catch (Throwable exception) {
		throw new Error(exception);
	}
}
 
Example #7
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 #8
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 #9
Source File: XtendValidator.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkDuplicateAndOverriddenFunctions(XtendTypeDeclaration xtendType) {
	final JvmDeclaredType inferredType = associations.getInferredType(xtendType);
	if (inferredType instanceof JvmGenericType) {
		JavaVersion targetVersion = getGeneratorConfig(xtendType).getJavaSourceVersion();
		ResolvedFeatures resolvedFeatures = overrideHelper.getResolvedFeatures(inferredType, targetVersion);
		
		Set<EObject> flaggedOperations = Sets.newHashSet();
		doCheckDuplicateExecutables((JvmGenericType) inferredType, resolvedFeatures, flaggedOperations);
		doCheckOverriddenMethods(xtendType, (JvmGenericType) inferredType, resolvedFeatures, flaggedOperations);
		doCheckFunctionOverrides(resolvedFeatures, flaggedOperations);
	}
}
 
Example #10
Source File: XtendQuickfixProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void doOverrideMethods(final Issue issue, IssueResolutionAcceptor acceptor, String label, final String[] operationUris) {
	acceptor.accept(issue, label, label, "fix_indent.gif",
			new ISemanticModification() {
				@Override
				public void apply(EObject element, IModificationContext context) throws Exception {
					XtendTypeDeclaration clazz = (XtendTypeDeclaration) element;
					JvmGenericType inferredType = (JvmGenericType) associations.getInferredType(clazz);
					ResolvedFeatures resolvedOperations = overrideHelper.getResolvedFeatures(inferredType);
					IXtextDocument document = context.getXtextDocument();
					final int offset = insertionOffsets.getNewMethodInsertOffset(null, clazz);
					int currentIndentation = appendableFactory.getIndentationLevelAtOffset(offset, document, (XtextResource) clazz.eResource());
					final int indentationToUse = clazz.getMembers().isEmpty() ? currentIndentation + 1 : currentIndentation;
					ReplacingAppendable appendable = appendableFactory.create(document, (XtextResource) clazz.eResource(),
							offset, 0, new OptionalParameters() {{ 
								ensureEmptyLinesAround = true;
								baseIndentationLevel = indentationToUse;	
							}});
					boolean isFirst = true;
					for (String operationUriAsString : operationUris) {
						URI operationURI = URI.createURI(operationUriAsString);
						EObject overridden = clazz.eResource().getResourceSet().getEObject(operationURI, true);
						if (overridden instanceof JvmOperation) {
							if(!isFirst) 
								appendable.newLine().newLine();
							isFirst = false;
							
							superMemberImplementor.appendOverrideFunction(clazz, resolvedOperations.getResolvedOperation((JvmOperation) overridden),
									appendable);
						}
					}
					appendable.commitChanges();
				}
			});
}
 
Example #11
Source File: XtendQuickfixProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(IssueCodes.MISSING_CONSTRUCTOR)
public void addConstuctorFromSuper(final Issue issue, IssueResolutionAcceptor acceptor) {
	if (issue.getData() != null) {
		for(int i=0; i<issue.getData().length; i+=2) {
			final URI constructorURI = URI.createURI(issue.getData()[i]);
			String javaSignature = issue.getData()[i+1];
			String xtendSignature = "new" + javaSignature.substring(javaSignature.indexOf('('));
			acceptor.accept(issue, "Add constructor " + xtendSignature, "Add constructor " + xtendSignature, "fix_indent.gif",
				new ISemanticModification() {
					@Override
					public void apply(EObject element, IModificationContext context) throws Exception {
						XtendClass clazz = (XtendClass) element;
						JvmGenericType inferredType = associations.getInferredType(clazz);
						ResolvedFeatures features = overrideHelper.getResolvedFeatures(inferredType);
						ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) clazz.eResource(),
								insertionOffsets.getNewConstructorInsertOffset(null, clazz), 0, new OptionalParameters() {{ 
									ensureEmptyLinesAround = true;
									baseIndentationLevel = 1;	
								}});
						EObject constructor = clazz.eResource().getResourceSet().getEObject(constructorURI, true);
						if (constructor instanceof JvmConstructor) {
							superMemberImplementor.appendConstructorFromSuper(
									clazz,
									new ResolvedConstructor((JvmConstructor) constructor, features.getType()),
									appendable);
						}
						appendable.commitChanges();
					}
				});
		}
	}
}
 
Example #12
Source File: XbaseCopyQualifiedNameService.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected IResolvedExecutable _resolveExecutable(JvmOperation operation, XAbstractFeatureCall featureCall,
		IResolvedTypes resolvedTypes) {
	XExpression actualReceiver = featureCall.getActualReceiver();
	if (actualReceiver != null) {
		LightweightTypeReference actualType = resolvedTypes.getActualType(actualReceiver);
		ResolvedFeatures resolvedFeatures = overrideHelper.getResolvedFeatures(actualType);
		for (IResolvedOperation resolvedOperation : resolvedFeatures.getAllOperations()) {
			if (resolvedOperation.getDeclaration().equals(operation)) {
				return resolvedOperation;
			}
		}
	}
	return null;
}
 
Example #13
Source File: OverrideProposalUtil.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public List<IResolvedExecutable> getImplementationCandidates(JvmDeclaredType type, boolean isAnonymous) {
	if (type == null || !(type instanceof JvmGenericType)) {
		return Collections.emptyList();
	}
	JavaVersion sourceVersion = generatorConfigProvider.get(type).getJavaSourceVersion();
	ResolvedFeatures resolvedFeatures = overrideHelper.getResolvedFeatures(type, sourceVersion);
	List<IResolvedExecutable> result = new ArrayList<>();
	ContextualVisibilityHelper contextualVisibilityHelper = new ContextualVisibilityHelper(visibilityHelper,
			resolvedFeatures.getType());
	addOperationCandidates(resolvedFeatures, contextualVisibilityHelper, result);
	if (!isAnonymous && !((JvmGenericType) type).isInterface()) {
		addConstructorCandidates(resolvedFeatures, contextualVisibilityHelper, result);
	}
	return result;
}
 
Example #14
Source File: ResolvedFeaturesTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testIterableIterator() {
  final ResolvedFeatures resolvedOperations = this.toResolvedOperations(Iterable.class);
  final List<IResolvedOperation> all = resolvedOperations.getAllOperations();
  Assert.assertFalse(all.isEmpty());
  final Function1<IResolvedOperation, Boolean> _function = (IResolvedOperation it) -> {
    return Boolean.valueOf(it.getDeclaration().isAbstract());
  };
  final IResolvedOperation iterator = Iterables.<IResolvedOperation>getOnlyElement(IterableExtensions.<IResolvedOperation>filter(all, _function));
  Assert.assertEquals("java.lang.Iterable.iterator()", iterator.getDeclaration().getIdentifier());
}
 
Example #15
Source File: ResolvedFeaturesTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testArrayListHasNoAbstractMethods() {
  final ResolvedFeatures resolvedOperations = this.toResolvedOperations(ArrayList.class);
  final List<IResolvedOperation> all = resolvedOperations.getAllOperations();
  Assert.assertFalse(all.isEmpty());
  final Consumer<IResolvedOperation> _function = (IResolvedOperation it) -> {
    Assert.assertFalse(it.getDeclaration().isAbstract());
  };
  all.forEach(_function);
}
 
Example #16
Source File: ResolvedFeaturesTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAllOperationsErasedSignatureIncludeDeclaredOperations() {
  final ResolvedFeatures resolvedOperations = this.toResolvedOperations(ResolvedFeaturesTest.DerivedClass.class);
  final List<IResolvedOperation> declared = resolvedOperations.getDeclaredOperations(ResolvedFeaturesTest.DERIVED_CLASS_METHOD_ERASED_SIGNATURE);
  final List<IResolvedOperation> all = resolvedOperations.getAllOperations(ResolvedFeaturesTest.DERIVED_CLASS_METHOD_ERASED_SIGNATURE);
  Assert.assertFalse(all.isEmpty());
  Assert.assertEquals(1, declared.size());
  Assert.assertSame(IterableExtensions.<IResolvedOperation>head(declared), IterableExtensions.<IResolvedOperation>head(all));
}
 
Example #17
Source File: ResolvedFeaturesTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDeclaredOperationsErasedSignatureAreIncludedInAllOperations() {
  final ResolvedFeatures resolvedOperations = this.toResolvedOperations(ResolvedFeaturesTest.DerivedClass.class);
  final List<IResolvedOperation> all = resolvedOperations.getAllOperations(ResolvedFeaturesTest.DERIVED_CLASS_METHOD_ERASED_SIGNATURE);
  final List<IResolvedOperation> declared = resolvedOperations.getDeclaredOperations(ResolvedFeaturesTest.DERIVED_CLASS_METHOD_ERASED_SIGNATURE);
  Assert.assertFalse(all.isEmpty());
  Assert.assertEquals(1, declared.size());
  Assert.assertSame(IterableExtensions.<IResolvedOperation>head(declared), IterableExtensions.<IResolvedOperation>head(all));
}
 
Example #18
Source File: ResolvedFeaturesTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDeclaredAndAllOperationsErasedSignature() {
  final ResolvedFeatures resolvedOperations = this.toResolvedOperations(ResolvedFeaturesTest.DerivedClass.class);
  Assert.assertNotNull(
    IterableExtensions.<IResolvedOperation>head(resolvedOperations.getAllOperations(ResolvedFeaturesTest.BASE_CLASS_METHOD_ERASED_SIGNATURE)));
  Assert.assertNull(
    IterableExtensions.<IResolvedOperation>head(resolvedOperations.getDeclaredOperations(ResolvedFeaturesTest.BASE_CLASS_METHOD_ERASED_SIGNATURE)));
}
 
Example #19
Source File: ResolvedFeaturesTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDeclaredOperationsAreIncludedInAllOperations() {
  final ResolvedFeatures resolvedOperations = this.toResolvedOperations(ResolvedFeaturesTest.DerivedClass.class);
  final List<IResolvedOperation> all = resolvedOperations.getAllOperations();
  final List<IResolvedOperation> declared = resolvedOperations.getDeclaredOperations();
  Assert.assertFalse(all.isEmpty());
  Assert.assertEquals(1, declared.size());
  Assert.assertSame(IterableExtensions.<IResolvedOperation>head(declared), IterableExtensions.<IResolvedOperation>head(all));
}
 
Example #20
Source File: ResolvedFeaturesTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAllOperationsIncludeDeclaredOperations() {
  final ResolvedFeatures resolvedOperations = this.toResolvedOperations(ResolvedFeaturesTest.DerivedClass.class);
  final List<IResolvedOperation> declared = resolvedOperations.getDeclaredOperations();
  final List<IResolvedOperation> all = resolvedOperations.getAllOperations();
  Assert.assertFalse(all.isEmpty());
  Assert.assertEquals(1, declared.size());
  Assert.assertSame(IterableExtensions.<IResolvedOperation>head(declared), IterableExtensions.<IResolvedOperation>head(all));
}
 
Example #21
Source File: ResolvedFeaturesTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public ResolvedFeatures toResolvedOperations(final String castExpression) {
  try {
    XExpression _expression = this.expression(castExpression);
    final XCastedExpression cast = ((XCastedExpression) _expression);
    final ResolvedFeatures result = this.overrideHelper.getResolvedFeatures(cast.getType());
    return result;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #22
Source File: OverrideProposalUtil.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void addOperationCandidates(ResolvedFeatures resolvedFeatures, IVisibilityHelper visibilityHelper,
		List<IResolvedExecutable> result) {
	List<IResolvedOperation> allOperations = resolvedFeatures.getAllOperations();
	LightweightTypeReference inferredType = resolvedFeatures.getType();
	for (IResolvedOperation operation : allOperations) {
		if (isCandidate(inferredType, operation, visibilityHelper)) {
			result.add(operation);
		}
	}
}
 
Example #23
Source File: AbstractXtendOutlineTreeBuilder.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
protected void buildInheritedMembers(final JvmDeclaredType inferredType, final IXtendOutlineContext context) {
  ResourceSet _resourceSet = inferredType.eResource().getResourceSet();
  final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, _resourceSet);
  final LightweightTypeReference typeReference = owner.toLightweightTypeReference(inferredType);
  final List<LightweightTypeReference> superTypes = typeReference.getAllSuperTypes();
  IXtendOutlineContext superTypeContext = context;
  for (final LightweightTypeReference superTypeRef : superTypes) {
    {
      superTypeContext = superTypeContext.increaseInheritanceDepth();
      final ResolvedFeatures resolvedFeatures = new ResolvedFeatures(superTypeRef);
      List<IResolvedField> _declaredFields = resolvedFeatures.getDeclaredFields();
      for (final IResolvedField jvmField : _declaredFields) {
        boolean _skipFeature = this.skipFeature(jvmField.getDeclaration());
        boolean _not = (!_skipFeature);
        if (_not) {
          this.xtendOutlineNodeBuilder.buildResolvedFeatureNode(inferredType, jvmField, superTypeContext);
        }
      }
      List<IResolvedConstructor> _declaredConstructors = resolvedFeatures.getDeclaredConstructors();
      for (final IResolvedConstructor constructor : _declaredConstructors) {
        boolean _skipFeature_1 = this.skipFeature(constructor.getDeclaration());
        boolean _not_1 = (!_skipFeature_1);
        if (_not_1) {
          this.xtendOutlineNodeBuilder.buildResolvedFeatureNode(inferredType, constructor, superTypeContext);
        }
      }
      List<IResolvedOperation> _declaredOperations = resolvedFeatures.getDeclaredOperations();
      for (final IResolvedOperation operation : _declaredOperations) {
        if (((!this.skipFeature(operation.getDeclaration())) && (!superTypeContext.isProcessed(operation.getDeclaration())))) {
          this.xtendOutlineNodeBuilder.buildResolvedFeatureNode(inferredType, operation, superTypeContext);
        }
      }
      final JvmType declaredType = superTypeRef.getType();
      if ((declaredType instanceof JvmDeclaredType)) {
        final IXtendOutlineContext nestedTypeContext = superTypeContext.hideInherited();
        final Consumer<JvmDeclaredType> _function = (JvmDeclaredType it) -> {
          this.buildJvmType(it, nestedTypeContext);
        };
        Iterables.<JvmDeclaredType>filter(((JvmDeclaredType)declaredType).getMembers(), JvmDeclaredType.class).forEach(_function);
      }
    }
  }
}
 
Example #24
Source File: XtendValidator.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
protected void doCheckOverriddenMethods(XtendTypeDeclaration xtendType, JvmGenericType inferredType, ResolvedFeatures resolvedFeatures,
		Set<EObject> flaggedOperations) {
	List<IResolvedOperation> operationsMissingImplementation = null;
	boolean doCheckAbstract = !inferredType.isAbstract();
	if (doCheckAbstract) {
		operationsMissingImplementation = Lists.newArrayList();
	}
	IVisibilityHelper visibilityHelper = new ContextualVisibilityHelper(this.visibilityHelper, resolvedFeatures.getType());
	boolean flaggedType = false;
	for (IResolvedOperation operation : resolvedFeatures.getAllOperations()) {
		JvmDeclaredType operationDeclaringType = operation.getDeclaration().getDeclaringType();
		if (operationDeclaringType != inferredType) {
			if (operationsMissingImplementation != null && operation.getDeclaration().isAbstract()) {
				operationsMissingImplementation.add(operation);
			}
			if (visibilityHelper.isVisible(operation.getDeclaration())) {
				String erasureSignature = operation.getResolvedErasureSignature();
				List<IResolvedOperation> declaredOperationsWithSameErasure = resolvedFeatures.getDeclaredOperations(erasureSignature);
				for (IResolvedOperation localOperation : declaredOperationsWithSameErasure) {
					if (!localOperation.isOverridingOrImplementing(operation.getDeclaration()).isOverridingOrImplementing()) {
						EObject source = findPrimarySourceElement(localOperation);
						if (operation.getDeclaration().isStatic() && !localOperation.getDeclaration().isStatic()) {
							if (!isInterface(operationDeclaringType)) {
								if (flaggedOperations.add(source)) {
									error("The instance method "
											+ localOperation.getSimpleSignature()
											+ " cannot override the static method "
											+ operation.getSimpleSignature() + " of type "
											+ getDeclaratorName(operation.getDeclaration()) + ".",
											source, nameFeature(source), DUPLICATE_METHOD);
								}
							}
						} else if (!operation.getDeclaration().isStatic() && localOperation.getDeclaration().isStatic()) {
							if (flaggedOperations.add(source)) {
								error("The static method "
										+ localOperation.getSimpleSignature()
										+ " cannot hide the instance method "
										+ operation.getSimpleSignature() + " of type "
										+ getDeclaratorName(operation.getDeclaration()) + ".",
										source, nameFeature(source), DUPLICATE_METHOD);
							}
						} else if (flaggedOperations.add(source)) {
							error("Name clash: The method "
									+ localOperation.getSimpleSignature() + " of type "
									+ inferredType.getSimpleName()
									+ " has the same erasure as "
									+ operation.getSimpleSignature() + " of type "
									+ getDeclaratorName(operation.getDeclaration()) + " but does not override it.",
									source, nameFeature(source), DUPLICATE_METHOD);
						}
					}
				}
				if (operation instanceof ConflictingDefaultOperation
						&& contributesToConflict(inferredType, (ConflictingDefaultOperation) operation) && !flaggedType) {
					IResolvedOperation conflictingOperation = ((ConflictingDefaultOperation) operation).getConflictingOperations()
							.get(0);
					// Include the declaring class in the issue code in order to give better quick fixes
					String[] uris = new String[] {
							getDeclaratorName(operation.getDeclaration()) + "|"
									+ EcoreUtil.getURI(operation.getDeclaration()).toString(),
							getDeclaratorName(conflictingOperation.getDeclaration()) + "|"
									+ EcoreUtil.getURI(conflictingOperation.getDeclaration()).toString() };
					if (!operation.getDeclaration().isAbstract() && !conflictingOperation.getDeclaration().isAbstract()) {
						error("The type " + inferredType.getSimpleName() + " inherits multiple implementations of the method "
								+ conflictingOperation.getSimpleSignature() + " from "
								+ getDeclaratorName(conflictingOperation.getDeclaration()) + " and "
								+ getDeclaratorName(operation.getDeclaration()) + ".", xtendType,
								XtendPackage.Literals.XTEND_TYPE_DECLARATION__NAME, CONFLICTING_DEFAULT_METHODS, uris);
					} else {
						// At least one of the operations is non-abstract
						IResolvedOperation abstractOp, nonabstractOp;
						if (operation.getDeclaration().isAbstract()) {
							abstractOp = operation;
							nonabstractOp = conflictingOperation;
						} else {
							abstractOp = conflictingOperation;
							nonabstractOp = operation;
						}
						error("The non-abstract method " + nonabstractOp.getSimpleSignature() + " inherited from "
								+ getDeclaratorName(nonabstractOp.getDeclaration()) + " conflicts with the method "
								+ abstractOp.getSimpleSignature() + " inherited from " + getDeclaratorName(abstractOp.getDeclaration())
								+ ".", xtendType, XtendPackage.Literals.XTEND_TYPE_DECLARATION__NAME, CONFLICTING_DEFAULT_METHODS,
								uris);
					}
					flaggedType = true;
				}
			}
		}
	}
	if (operationsMissingImplementation != null && !operationsMissingImplementation.isEmpty() && !flaggedType) {
		reportMissingImplementations(xtendType, inferredType, operationsMissingImplementation);
	}
}
 
Example #25
Source File: XtendValidator.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
protected void doCheckFunctionOverrides(ResolvedFeatures resolvedFeatures, Set<EObject> flaggedOperations) {
	for(IResolvedOperation operation: resolvedFeatures.getDeclaredOperations()) {
		doCheckFunctionOverrides(operation, flaggedOperations);
	}
}
 
Example #26
Source File: Bug621Validator.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
protected void doCheckOverriddenMethods(XtendTypeDeclaration xtendType, JvmGenericType inferredType,
		ResolvedFeatures resolvedFeatures, Set<EObject> flaggedOperations) {
	super.doCheckOverriddenMethods(xtendType, inferredType, resolvedFeatures, flaggedOperations);
}
 
Example #27
Source File: Bug621OverrideHelper.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
public ResolvedFeatures getResolvedFeatures(LightweightTypeReference contextType) {
	return new Bug621ResolvedFeatures(contextType, this.overrideTester);
}
 
Example #28
Source File: Bug621OverrideHelper.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
public ResolvedFeatures getResolvedFeatures(LightweightTypeReference contextType, JavaVersion targetVersion) {
	return new Bug621ResolvedFeatures(contextType, this.overrideTester, targetVersion);
}