Search in sources :

Example 1 with IResolvedExecutable

use of org.eclipse.xtext.xbase.typesystem.override.IResolvedExecutable in project xtext-xtend by eclipse.

the class XtendValidator method doCheckDuplicateExecutables.

protected <Executable extends IResolvedExecutable> void doCheckDuplicateExecutables(JvmGenericType inferredType, List<Executable> declaredOperations, Function<String, List<Executable>> bySignature, Set<EObject> flaggedOperations) {
    Set<Executable> processed = Sets.newHashSet();
    for (Executable declaredExecutable : declaredOperations) {
        if (!processed.contains(declaredExecutable)) {
            List<Executable> sameErasure = bySignature.apply(declaredExecutable.getResolvedErasureSignature());
            if (sameErasure.size() > 1) {
                Multimap<String, Executable> perSignature = HashMultimap.create(sameErasure.size(), 2);
                outer: for (Executable executable : sameErasure) {
                    for (LightweightTypeReference parameterType : executable.getResolvedParameterTypes()) {
                        if (parameterType.isUnknown())
                            continue outer;
                    }
                    perSignature.put(executable.getResolvedSignature(), executable);
                }
                if (perSignature.size() > 1) {
                    for (Collection<Executable> sameSignature : perSignature.asMap().values()) {
                        for (Executable operationWithSameSignature : sameSignature) {
                            JvmExecutable executable = operationWithSameSignature.getDeclaration();
                            EObject otherSource = associations.getPrimarySourceElement(executable);
                            if (flaggedOperations.add(otherSource)) {
                                if (sameSignature.size() > 1) {
                                    error("Duplicate " + typeLabel(executable) + " " + operationWithSameSignature.getSimpleSignature() + " in type " + inferredType.getSimpleName(), otherSource, nameFeature(otherSource), DUPLICATE_METHOD);
                                } else {
                                    error("The " + typeLabel(executable) + " " + operationWithSameSignature.getSimpleSignature() + " has the same erasure " + operationWithSameSignature.getResolvedErasureSignature() + " as another " + typeLabel(executable) + " in type " + inferredType.getSimpleName(), otherSource, nameFeature(otherSource), DUPLICATE_METHOD);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmExecutable(org.eclipse.xtext.common.types.JvmExecutable) EObject(org.eclipse.emf.ecore.EObject) RichString(org.eclipse.xtend.core.xtend.RichString) IResolvedExecutable(org.eclipse.xtext.xbase.typesystem.override.IResolvedExecutable) JvmExecutable(org.eclipse.xtext.common.types.JvmExecutable) XtendExecutable(org.eclipse.xtend.core.xtend.XtendExecutable)

Example 2 with IResolvedExecutable

use of org.eclipse.xtext.xbase.typesystem.override.IResolvedExecutable in project xtext-xtend by eclipse.

the class ImplementMemberFromSuperAssist method createOverrideProposals.

public void createOverrideProposals(XtendTypeDeclaration model, ContentAssistContext context, ICompletionProposalAcceptor acceptor, IProposalConflictHelper conflictHelper) {
    final JvmDeclaredType inferredType = associations.getInferredType(model);
    List<IResolvedExecutable> overrideables = overrideProposalUtil.getImplementationCandidates(inferredType, model.isAnonymous());
    for (IResolvedExecutable overrideable : overrideables) {
        ICompletionProposal completionProposal = createOverrideMethodProposal(model, overrideable, context, conflictHelper);
        if (completionProposal != null)
            acceptor.accept(completionProposal);
    }
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) IResolvedExecutable(org.eclipse.xtext.xbase.typesystem.override.IResolvedExecutable)

Aggregations

IResolvedExecutable (org.eclipse.xtext.xbase.typesystem.override.IResolvedExecutable)2 EObject (org.eclipse.emf.ecore.EObject)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 RichString (org.eclipse.xtend.core.xtend.RichString)1 XtendExecutable (org.eclipse.xtend.core.xtend.XtendExecutable)1 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)1 JvmExecutable (org.eclipse.xtext.common.types.JvmExecutable)1 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)1