@Override public String apply(IResolvedOperation from) { return EcoreUtil.getURI(from.getDeclaration()).toString(); } });
protected EObject findPrimarySourceElement(IResolvedOperation operation) { return associations.getPrimarySourceElement(operation.getDeclaration()); }
protected String getDeclaratorName(IResolvedOperation resolved) { return getDeclaratorName(resolved.getDeclaration()); }
protected List<IResolvedOperation> computeAllOperations() { JvmType rawType = getRawType(); if (!(rawType instanceof JvmDeclaredType)) { return Collections.emptyList(); } Multimap<String, AbstractResolvedOperation> processedOperations = LinkedHashMultimap.create(); for (IResolvedOperation resolvedOperation : getDeclaredOperations()) { processedOperations.put(resolvedOperation.getDeclaration().getSimpleName(), (AbstractResolvedOperation) resolvedOperation); } if (targetVersion.isAtLeast(JavaVersion.JAVA8)) { computeAllOperationsFromSortedSuperTypes((JvmDeclaredType) rawType, processedOperations); } else { Set<JvmType> processedTypes = Sets.newHashSet(rawType); computeAllOperationsFromSuperTypes((JvmDeclaredType) rawType, processedOperations, processedTypes); } // make sure the declared operations are the first in the list List<IResolvedOperation> result = new ArrayList<IResolvedOperation>(processedOperations.size()); result.addAll(getDeclaredOperations()); for (AbstractResolvedOperation operation : processedOperations.values()) { if (operation.getDeclaration().getDeclaringType() != rawType) { result.add(operation); } } return Collections.unmodifiableList(result); }
protected OverrideCheckDetails getPrimaryValidDetail(IResolvedOperation overriding, JvmOperation overridden) { OverrideCheckDetails result = OverrideCheckDetails.IMPLEMENTATION; JvmOperation declaration = overriding.getDeclaration(); if (declaration.isStatic()) { result = OverrideCheckDetails.SHADOWED; } else if (declaration.isAbstract()) { if (overridden.isAbstract()) { result = OverrideCheckDetails.REPEATED; } else { result = OverrideCheckDetails.REDECLARATION; } } else if (!overridden.isAbstract()) { result = OverrideCheckDetails.OVERRIDE; } return result; }
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 (flaggedOperations.add(source)) { if (operation.getDeclaration().isStatic() && !localOperation.getDeclaration().isStatic()) { error("The instance method " + localOperation.getSimpleSignature() + " cannot override the static method " + operation.getSimpleSignature() + " of type " + getDeclaratorName(operation.getDeclaration()) + ".", source, nameFeature(source), DUPLICATE_METHOD); } else { + getDeclaratorName(operation.getDeclaration()) + " but does not override it.", source, nameFeature(source), DUPLICATE_METHOD); getDeclaratorName(operation.getDeclaration()) + "|" + EcoreUtil.getURI(operation.getDeclaration()).toString(),
@Override public IResolvedOperation getOverriddenMethod() { if (!getDeclaration().isAbstract() && getDeclaration().getVisibility() != JvmVisibility.PRIVATE) { List<IResolvedOperation> overriddenAndImplemented = getOverriddenAndImplementedMethods(); for(IResolvedOperation candidate: overriddenAndImplemented) { if (!candidate.getDeclaration().isAbstract()) { return candidate; } } } return null; }
/** * Determine whether the given type contributes to the conflict caused by the given default interface implementation. */ private boolean contributesToConflict(JvmGenericType rootType, ConflictingDefaultOperation conflictingDefaultOperation) { Set<JvmDeclaredType> involvedInterfaces = Sets.newHashSet(); involvedInterfaces.add(conflictingDefaultOperation.getDeclaration().getDeclaringType()); for (IResolvedOperation conflictingOperation : conflictingDefaultOperation.getConflictingOperations()) { involvedInterfaces.add(conflictingOperation.getDeclaration().getDeclaringType()); } RecursionGuard<JvmDeclaredType> recursionGuard = new RecursionGuard<JvmDeclaredType>(); if (rootType.isInterface()) { int contributingCount = 0; for (JvmTypeReference typeRef : rootType.getExtendedInterfaces()) { JvmType rawType = typeRef.getType(); if (rawType instanceof JvmDeclaredType && contributesToConflict((JvmDeclaredType) rawType, involvedInterfaces, recursionGuard)) { contributingCount++; } } return contributingCount >= 2; } else { return contributesToConflict(rootType, involvedInterfaces, recursionGuard); } }
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); } } }
/** * Since for fields we generate getter/setter, checking duplicate Java methods * will automatically check for duplicate fields as well. */ private void checkDuplicateSpecifications(final JvmGenericType inferredType) { final ResolvedFeatures inferredFeatures = this._emfParsleyDslGuiceModuleHelper.getJavaResolvedFeatures(inferredType); final List<IResolvedOperation> methods = inferredFeatures.getDeclaredOperations(); final ListMultimap<String, JvmOperation> map = this.<String, JvmOperation>duplicatesMultimap(); final HashSet<EObject> errorSourceSeen = CollectionLiterals.<EObject>newHashSet(); for (final IResolvedOperation m : methods) { map.put(this._emfParsleyDslGuiceModuleHelper.getJavaMethodResolvedErasedSignature(m), m.getDeclaration()); } final Procedure1<JvmOperation> _function = new Procedure1<JvmOperation>() { @Override public void apply(final JvmOperation d) { final EObject source = IterableExtensions.<EObject>head(EmfParsleyDslValidator.this._iJvmModelAssociations.getSourceElements(d)); boolean _add = errorSourceSeen.add(source); if (_add) { EmfParsleyDslValidator.this.error( "Duplicate element", source, null, EmfParsleyDslValidator.DUPLICATE_ELEMENT); } } }; this.<JvmOperation>checkDuplicates(map, _function); }
return null; IResolvedOperation overriddenMethod = overriddenMethods.get(0); JvmOperation declaration = overriddenMethod.getDeclaration(); XExpression inferredFrom = getInferredFrom(declaration.getReturnType());