org.eclipse.xtext.xbase.typesystem.override.IOverrideCheckResult.OverrideCheckDetails Java Examples
The following examples show how to use
org.eclipse.xtext.xbase.typesystem.override.IOverrideCheckResult.OverrideCheckDetails.
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: OverrideTester.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected void addAdditionalDetails(AbstractResolvedOperation overriding, AbstractResolvedOperation overridden, EnumSet<OverrideCheckDetails> result) { addReturnTypeDetails(overriding, overridden, result); addExceptionDetails(overriding, overridden, result); JvmOperation overridingDecl = overriding.getDeclaration(); JvmOperation overriddenDecl = overridden.getDeclaration(); if (isMorePrivateThan(overridingDecl.getVisibility(), overriddenDecl.getVisibility())) { result.add(OverrideCheckDetails.REDUCED_VISIBILITY); } if (overriddenDecl.isFinal()) { result.add(OverrideCheckDetails.IS_FINAL); } if (overridingDecl.isVarArgs() != overriddenDecl.isVarArgs()) { result.add(OverrideCheckDetails.VAR_ARG_MISMATCH); } if (isConflictingDefaultImplementation(overriding, overridden)) { result.add(OverrideCheckDetails.DEFAULT_IMPL_CONFLICT); } if (!overridingDecl.isSynchronized() && overriddenDecl.isSynchronized()) { result.add(OverrideCheckDetails.SYNCHRONIZED_MISMATCH); } }
Example #2
Source File: OverrideTester.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected void addExceptionDetails(AbstractResolvedOperation overriding, AbstractResolvedOperation overridden, EnumSet<OverrideCheckDetails> result) { List<LightweightTypeReference> exceptions = overriding.getResolvedExceptions(); if (exceptions.isEmpty()) { return; } List<LightweightTypeReference> inheritedExceptions = overridden.getResolvedExceptions(); for(LightweightTypeReference exception: exceptions) { if (!exception.isSubtypeOf(RuntimeException.class) && !exception.isSubtypeOf(Error.class)) { boolean isDeclared = false; for(LightweightTypeReference inheritedException: inheritedExceptions) { if (inheritedException.isAssignableFrom(exception)) { isDeclared = true; break; } } if (!isDeclared) { result.add(OverrideCheckDetails.EXCEPTION_MISMATCH); return; } } } }
Example #3
Source File: OverrideTester.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
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; }
Example #4
Source File: AbstractResolvedOperation.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected boolean isIllegallyDeclaredException(LightweightTypeReference exception, List<IResolvedOperation> overriddenAndImplemented) { for(IResolvedOperation operation: overriddenAndImplemented) { if (operation.getOverrideCheckResult().getDetails().contains(OverrideCheckDetails.EXCEPTION_MISMATCH)) { List<LightweightTypeReference> inheritedExceptions = operation.getResolvedExceptions(); if (inheritedExceptions.isEmpty()) { return true; } boolean isDeclared = false; for(LightweightTypeReference inheritedException: inheritedExceptions) { if (inheritedException.isAssignableFrom(exception)) { isDeclared = true; break; } } if (!isDeclared) { return true; } } } return false; }
Example #5
Source File: OverrideTester.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void addReturnTypeDetails(AbstractResolvedOperation overriding, AbstractResolvedOperation overridden, EnumSet<OverrideCheckDetails> result) { LightweightTypeReference overridingReturnType = overriding.getResolvedReturnType(); LightweightTypeReference overriddenReturnType = overridden.getResolvedReturnType(); TypeConformanceComputationArgument conformanceArgument = new TypeConformanceComputationArgument(false, false, false, false, false, false); if (!overriddenReturnType.isAssignableFrom(overridingReturnType, conformanceArgument)) { if (overriding.getTypeParameters().isEmpty() && !overridden.getTypeParameters().isEmpty()) { TypeConformanceComputationArgument rawConformanceArgument = new TypeConformanceComputationArgument(true, false, false, false, false, false); if (!overriddenReturnType.isAssignableFrom(overridingReturnType, rawConformanceArgument)) { result.add(OverrideCheckDetails.RETURN_MISMATCH); } else { result.add(OverrideCheckDetails.UNCHECKED_CONVERSION_REQUIRED); if (overridingReturnType.getRawTypeReference().getType() != overriddenReturnType.getRawTypeReference().getType()) { result.add(OverrideCheckDetails.COVARIANT_RETURN); } } } else { result.add(OverrideCheckDetails.RETURN_MISMATCH); } } else if (!overriddenReturnType.getJavaIdentifier().equals(overridingReturnType.getJavaIdentifier())) { if (!overridden.isRawTypeInheritance() && overriding.getTypeParameters().isEmpty() && !overridden.getTypeParameters().isEmpty()) { if (overridden.getTypeParameters().contains(overridden.getDeclaration().getReturnType().getType())) { result.add(OverrideCheckDetails.UNCHECKED_CONVERSION_REQUIRED); } } result.add(OverrideCheckDetails.COVARIANT_RETURN); } }
Example #6
Source File: BottomResolvedOperation.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public IOverrideCheckResult getOverrideCheckResult() { return new LazyOverrideCheckResult(this, getDeclaration(), OverrideCheckDetails.CURRENT) { @Override public boolean hasProblems() { return false; } @Override public EnumSet<OverrideCheckDetails> getDetails() { return EnumSet.of(OverrideCheckDetails.CURRENT); } }; }
Example #7
Source File: OverrideTester.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
/** * Checks if the overriding method and the given overridden candidate have compatible subsignatures * according to JLS 8.4.2. Uses information about static-ness and visibility for early exits. * * The implemented algorithm pretty much mirrors the one from * class <code>org.eclipse.jdt.internal.corext.util.MethodOverrideTester</code>. * * @param checkInheritance <code>true</code> if it is unknown whether the given operations are declared in a valid type hierarchy. */ public IOverrideCheckResult isSubsignature(AbstractResolvedOperation overriding, JvmOperation overridden, boolean checkInheritance) { JvmOperation declaration = overriding.getDeclaration(); if (declaration == overridden) { return new LazyOverrideCheckResult(overriding, overridden, OverrideCheckDetails.CURRENT); } if (overridden.getDeclaringType() == declaration.getDeclaringType()) { return new LazyOverrideCheckResult(overriding, overridden, OverrideCheckDetails.SAME_DECLARATOR); } ITypeReferenceOwner owner = overriding.getContextType().getOwner(); LightweightTypeReference currentDeclarator = null; if (checkInheritance) { // here we use the raw types intentionally since there is no need to resolve // declarators to concrete bounds to determine the override relationship of types currentDeclarator = owner.newParameterizedTypeReference(declaration.getDeclaringType()); if (!currentDeclarator.isSubtypeOf(overridden.getDeclaringType())) { return new LazyOverrideCheckResult(overriding, overridden, OverrideCheckDetails.NO_INHERITANCE); } } if (!Strings.equal(overridden.getSimpleName(), declaration.getSimpleName())) { return new LazyOverrideCheckResult(overriding, overridden, OverrideCheckDetails.NAME_MISMATCH); } int parameterCount = overridden.getParameters().size(); if (parameterCount != declaration.getParameters().size()) { return new LazyOverrideCheckResult(overriding, overridden, OverrideCheckDetails.ARITY_MISMATCH); } if (currentDeclarator == null) { currentDeclarator = owner.newParameterizedTypeReference(declaration.getDeclaringType()); } if (!(new ContextualVisibilityHelper(visibilityHelper, currentDeclarator).isVisible(overridden))) { return new LazyOverrideCheckResult(overriding, overridden, OverrideCheckDetails.NOT_VISIBLE); } if (declaration.isStatic() != overridden.isStatic()) { return new LazyOverrideCheckResult(overriding, overridden, OverrideCheckDetails.STATIC_MISMATCH); } AbstractResolvedOperation overriddenInHierarchy = new ResolvedOperationInHierarchy(overridden, overriding.getBottom()); if (parameterCount != 0 && !isMatchingParameterList(overriding, overriddenInHierarchy)) { return new LazyOverrideCheckResult(overriding, overridden, OverrideCheckDetails.PARAMETER_TYPE_MISMATCH); } if (!isMatchingTypeParameters(overriding, overriddenInHierarchy)) return new LazyOverrideCheckResult(overriding, overridden, OverrideCheckDetails.TYPE_PARAMETER_MISMATCH); return new LazyOverrideCheckResult(overriding, overridden, getPrimaryValidDetail(overriding, overridden)); }
Example #8
Source File: OverrideTester.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected EnumSet<OverrideCheckDetails> getAllDetails(AbstractResolvedOperation overriding, JvmOperation overridden, OverrideCheckDetails primary) { EnumSet<OverrideCheckDetails> result = EnumSet.of(primary); AbstractResolvedOperation overriddenInHierarchy = new ResolvedOperationInHierarchy(overridden, overriding.getBottom()); switch(primary) { case CURRENT: case NO_INHERITANCE: case NAME_MISMATCH: case ARITY_MISMATCH: return result; case SAME_DECLARATOR: case TYPE_PARAMETER_MISMATCH: case PARAMETER_TYPE_MISMATCH: { if (isSameErasure(overriding, overriddenInHierarchy)) { result.add(OverrideCheckDetails.SAME_ERASURE); if (isConflictingDefaultImplementation(overriding, overriddenInHierarchy)) { result.add(OverrideCheckDetails.DEFAULT_IMPL_CONFLICT); } } return result; } case NOT_VISIBLE: case STATIC_MISMATCH: if (!overriding.getResolvedParameterTypes().isEmpty() && !isMatchingParameterList(overriding, overriddenInHierarchy)) { result.add(OverrideCheckDetails.PARAMETER_TYPE_MISMATCH); return result; } if (!isMatchingTypeParameters(overriding, overriddenInHierarchy)) { result.add(OverrideCheckDetails.TYPE_PARAMETER_MISMATCH); return result; } case REPEATED: case SHADOWED: case IMPLEMENTATION: case REDECLARATION: case OVERRIDE: { addAdditionalDetails(overriding, overriddenInHierarchy, result); return result; } default: throw new IllegalArgumentException("Unexpected primary detail: " + primary); } }