protected void addOperationCandidates(final ResolvedFeatures resolvedFeatures, final IVisibilityHelper visibilityHelper, final List<IResolvedExecutable> result) { List<IResolvedOperation> allOperations = resolvedFeatures.getAllOperations(); LightweightTypeReference inferredType = resolvedFeatures.getType(); for (final IResolvedOperation operation : allOperations) { boolean _isCandidate = this.isCandidate(inferredType, operation, visibilityHelper); if (_isCandidate) { result.add(operation); } } }
@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)); }
@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)); }
@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))); }
@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)); }
@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)); }
@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); }
@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()); }
public IResolvedOperation toOperation(final String expression) { try { XExpression _expression = this.expression(expression); final XMemberFeatureCall featureCall = ((XMemberFeatureCall) _expression); final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(featureCall); final LightweightTypeReference receiverType = resolvedTypes.getActualType(featureCall.getMemberCallTarget()); JvmIdentifiableElement _feature = featureCall.getFeature(); final JvmOperation operation = ((JvmOperation) _feature); Assert.assertFalse(operation.eIsProxy()); return new BottomResolvedOperation(operation, receiverType, this.overrideTester); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void testArrayListIteratorIsBottom() { final IResolvedOperation operation = this.toOperation("newArrayList.iterator"); Assert.assertTrue(operation.isBottomInContext()); Assert.assertEquals("ArrayList<Object>", operation.getContextType().getSimpleName()); Assert.assertEquals("iterator", operation.getDeclaration().getSimpleName()); }
@Test public void testTypeParameterConstraints() { final IResolvedOperation operation = this.toOperation("(null as overrides.AbstractForCharSequence).method"); Assert.assertTrue(operation.isBottomInContext()); Assert.assertEquals("AbstractForCharSequence", operation.getContextType().getSimpleName()); Assert.assertEquals("method", operation.getDeclaration().getSimpleName()); final List<JvmTypeParameter> typeParameters = operation.getResolvedTypeParameters(); Assert.assertEquals(2, typeParameters.size()); final List<LightweightTypeReference> firstConstraints = operation.getResolvedTypeParameterConstraints(0); Assert.assertEquals(1, firstConstraints.size()); Assert.assertEquals("CharSequence", IterableExtensions.<LightweightTypeReference>head(firstConstraints).getSimpleName()); final List<LightweightTypeReference> secondConstraints = operation.getResolvedTypeParameterConstraints(1); Assert.assertEquals(1, secondConstraints.size()); Assert.assertEquals("V", IterableExtensions.<LightweightTypeReference>head(secondConstraints).getSimpleName()); }
@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()); }
@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()); }
@Test public void testHashSetInheritsIterator() { final IResolvedOperation operation = this.toOperation("newHashSet(\"\").iterator"); final List<JvmOperation> candidates = operation.getOverriddenAndImplementedMethodCandidates(); Assert.assertEquals(2, candidates.size()); Assert.assertEquals("AbstractCollection", IterableExtensions.<JvmOperation>head(candidates).getDeclaringType().getSimpleName()); Assert.assertEquals("Set", IterableExtensions.<JvmOperation>last(candidates).getDeclaringType().getSimpleName()); }
@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()); }
protected void withExactDetails(final IResolvedOperation operation, final IOverrideCheckResult.OverrideCheckDetails... details) { Assert.assertEquals(1, operation.getOverriddenAndImplementedMethodCandidates().size()); final JvmOperation candidate = IterableExtensions.<JvmOperation>head(operation.getOverriddenAndImplementedMethodCandidates()); final EnumSet<IOverrideCheckResult.OverrideCheckDetails> expectation = EnumSet.<IOverrideCheckResult.OverrideCheckDetails>copyOf(((Collection<IOverrideCheckResult.OverrideCheckDetails>)Conversions.doWrapArray(details))); final IOverrideCheckResult checkResult = operation.isOverridingOrImplementing(candidate); final EnumSet<IOverrideCheckResult.OverrideCheckDetails> actual = checkResult.getDetails(); Assert.assertEquals(expectation.toString(), actual.toString()); }
protected void withDetails(final IResolvedOperation operation, final IOverrideCheckResult.OverrideCheckDetails... details) { final Consumer<JvmOperation> _function = (JvmOperation it) -> { final IOverrideCheckResult checkResult = operation.isOverridingOrImplementing(it); final EnumSet<IOverrideCheckResult.OverrideCheckDetails> actual = checkResult.getDetails(); StringConcatenation _builder = new StringConcatenation(); _builder.append("Failed: "); _builder.append(actual); _builder.append(".containsAll("); List<IOverrideCheckResult.OverrideCheckDetails> _list = IterableExtensions.<IOverrideCheckResult.OverrideCheckDetails>toList(((Iterable<IOverrideCheckResult.OverrideCheckDetails>)Conversions.doWrapArray(details))); _builder.append(_list); _builder.append(")"); Assert.assertTrue(_builder.toString(), actual.containsAll(((Collection<?>)Conversions.doWrapArray(details)))); }; operation.getOverriddenAndImplementedMethodCandidates().forEach(_function); }
protected void withDetail(final IResolvedOperation operation, final IOverrideCheckResult.OverrideCheckDetails detail) { final Consumer<JvmOperation> _function = (JvmOperation it) -> { final IOverrideCheckResult checkResult = operation.isOverridingOrImplementing(it); final EnumSet<IOverrideCheckResult.OverrideCheckDetails> actual = checkResult.getDetails(); StringConcatenation _builder = new StringConcatenation(); _builder.append("Failed: "); _builder.append(actual); _builder.append(".contains("); _builder.append(detail); _builder.append(")"); Assert.assertTrue(_builder.toString(), actual.contains(detail)); }; operation.getOverriddenAndImplementedMethodCandidates().forEach(_function); }
@Test public void testOverrideMethodResolution_14() { IResolvedOperation _operation = this.toOperation("(null as testdata.MethodOverrides4).m10()"); final Procedure1<IResolvedOperation> _function = (IResolvedOperation it) -> { final JvmOperation candidate = IterableExtensions.<JvmOperation>head(it.getOverriddenAndImplementedMethodCandidates()); Assert.assertEquals(1, candidate.getTypeParameters().size()); Assert.assertEquals(1, it.getDeclaration().getTypeParameters().size()); it.getDeclaration().getTypeParameters().clear(); this.withDetail(this.candidatesAndOverrides(this.has(it, 1), 0), IOverrideCheckResult.OverrideCheckDetails.TYPE_PARAMETER_MISMATCH); }; ObjectExtensions.<IResolvedOperation>operator_doubleArrow(_operation, _function); }
@Test public void testOverrideMethodResolution_15() { IResolvedOperation _operation = this.toOperation("(null as overrides.ConcreteForCharSequence).method"); final Procedure1<IResolvedOperation> _function = (IResolvedOperation it) -> { final JvmOperation candidate = IterableExtensions.<JvmOperation>head(it.getOverriddenAndImplementedMethodCandidates()); Assert.assertEquals(2, candidate.getTypeParameters().size()); Assert.assertEquals(2, it.getDeclaration().getTypeParameters().size()); this.withDetails(this.candidatesAndOverrides(this.has(it, 1), 1), IOverrideCheckResult.OverrideCheckDetails.IMPLEMENTATION); }; ObjectExtensions.<IResolvedOperation>operator_doubleArrow(_operation, _function); }
@Test public void testVarArgsMismatch_01() { final IResolvedOperation operation = this.toOperation("(null as testdata.MethodOverrides4).withVarArgs(null)"); JvmOperation _declaration = operation.getDeclaration(); _declaration.setVisibility(JvmVisibility.PROTECTED); final Consumer<JvmOperation> _function = (JvmOperation it) -> { it.setVisibility(JvmVisibility.PUBLIC); }; operation.getOverriddenAndImplementedMethodCandidates().forEach(_function); this.withDetails(this.candidatesAndOverrides(this.has(operation, 1), 1), IOverrideCheckResult.OverrideCheckDetails.REDUCED_VISIBILITY, IOverrideCheckResult.OverrideCheckDetails.VAR_ARG_MISMATCH); }
@Test public void testVarArgsMismatch_02() { final IResolvedOperation operation = this.toOperation("(null as testdata.MethodOverrides4).withArray(null)"); JvmOperation _declaration = operation.getDeclaration(); _declaration.setVisibility(JvmVisibility.PROTECTED); final Consumer<JvmOperation> _function = (JvmOperation it) -> { it.setVisibility(JvmVisibility.DEFAULT); }; operation.getOverriddenAndImplementedMethodCandidates().forEach(_function); this.withDetails(this.candidatesAndOverrides(this.has(operation, 1), 1), IOverrideCheckResult.OverrideCheckDetails.VAR_ARG_MISMATCH); }
protected ImageDescriptor imageDescriptor(final Object at) { if (at instanceof JvmConstructor) { return _imageDescriptor((JvmConstructor)at); } else if (at instanceof JvmOperation) { return _imageDescriptor((JvmOperation)at); } else if (at instanceof JvmAnnotationType) { return _imageDescriptor((JvmAnnotationType)at); } else if (at instanceof JvmEnumerationType) { return _imageDescriptor((JvmEnumerationType)at); } else if (at instanceof JvmField) { return _imageDescriptor((JvmField)at); } else if (at instanceof JvmGenericType) { return _imageDescriptor((JvmGenericType)at); } else if (at instanceof JvmTypeParameter) { return _imageDescriptor((JvmTypeParameter)at); } else if (at instanceof JvmFormalParameter) { return _imageDescriptor((JvmFormalParameter)at); } else if (at instanceof XVariableDeclaration) { return _imageDescriptor((XVariableDeclaration)at); } else if (at instanceof AlgorithmType) { return _imageDescriptor((AlgorithmType)at); } else if (at instanceof GraphPolicies) { return _imageDescriptor((GraphPolicies)at); } else if (at instanceof Model) { return _imageDescriptor((Model)at); } else if (at instanceof PathGeneratorStopCondition) { return _imageDescriptor((PathGeneratorStopCondition)at); } else if (at instanceof Policies) { return _imageDescriptor((Policies)at); } else if (at instanceof Severity) { return _imageDescriptor((Severity)at); } else if (at instanceof StopCondition) { return _imageDescriptor((StopCondition)at); } else if (at instanceof IResolvedConstructor) { return _imageDescriptor((IResolvedConstructor)at); } else if (at instanceof IResolvedOperation) { return _imageDescriptor((IResolvedOperation)at); } else if (at instanceof XImportDeclaration) { return _imageDescriptor((XImportDeclaration)at); } else if (at instanceof XImportSection) { return _imageDescriptor((XImportSection)at); } else if (at instanceof IResolvedField) { return _imageDescriptor((IResolvedField)at); } else if (at != null) { return _imageDescriptor(at); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(at).toString()); } }
@Test public void testArrayListOfStringIteratesStrings() { final IResolvedOperation operation = this.toOperation("newArrayList(\"\").iterator"); Assert.assertEquals("ArrayList<String>", operation.getContextType().getSimpleName()); Assert.assertEquals("Iterator<String>", operation.getResolvedReturnType().getSimpleName()); }
@Test public void testIterableOfStringsIteratesStrings() { final IResolvedOperation operation = this.toOperation("(null as Iterable<? extends String>).iterator"); Assert.assertEquals("Iterator<? extends String>", operation.getResolvedReturnType().getSimpleName()); }
@Test public void testListOfStringToArray() { final IResolvedOperation operation = this.toOperation("newArrayList(\"\").toArray(null)"); Assert.assertEquals("T[]", operation.getResolvedReturnType().getSimpleName()); }
@Test public void testListToArrayHasTwoCandidates() { final IResolvedOperation operation = this.toOperation("(null as java.util.List<String>).toArray(null)"); final List<JvmOperation> candidates = operation.getOverriddenAndImplementedMethodCandidates(); Assert.assertEquals(2, candidates.size()); }
@Test public void testArrayListOfStringAcceptsStrings() { final IResolvedOperation operation = this.toOperation("newArrayList(\"\").addAll(null)"); Assert.assertEquals(1, operation.getResolvedParameterTypes().size()); Assert.assertEquals("Collection<? extends String>", IterableExtensions.<LightweightTypeReference>head(operation.getResolvedParameterTypes()).getSimpleName()); }
protected IResolvedOperation has(final IResolvedOperation operation, final int candidates) { final List<JvmOperation> actualCandidates = operation.getOverriddenAndImplementedMethodCandidates(); Assert.assertEquals("candidates", candidates, actualCandidates.size()); return operation; }
protected IResolvedOperation candidatesAndOverrides(final IResolvedOperation operation, final int overrides) { final List<IResolvedOperation> actualOverrides = operation.getOverriddenAndImplementedMethods(); Assert.assertEquals("overrides", overrides, actualOverrides.size()); return operation; }
@Test public void testOverrideMethodResolution_01() { final IResolvedOperation operation = this.toOperation("(null as testdata.MethodOverrides2).m1(null as Object)"); this.withDetail(this.candidatesAndOverrides(this.has(operation, 2), 0), IOverrideCheckResult.OverrideCheckDetails.PARAMETER_TYPE_MISMATCH); }
@Test public void testOverrideMethodResolution_02() { final IResolvedOperation operation = this.toOperation("(null as testdata.MethodOverrides2).m1(null /* as String */)"); this.candidatesAndOverrides(this.has(operation, 0), 0); }
@Test public void testOverrideMethodResolution_03() { final IResolvedOperation operation = this.toOperation("(null as testdata.MethodOverrides4).m1(null)"); this.withDetail(this.candidatesAndOverrides(this.has(operation, 1), 1), IOverrideCheckResult.OverrideCheckDetails.OVERRIDE); }
@Test public void testOverrideMethodResolution_04() { final IResolvedOperation operation = this.toOperation("(null as testdata.MethodOverrides4).m2(null)"); this.candidatesAndOverrides(this.has(operation, 1), 1); }
@Test public void testOverrideMethodResolution_05() { final IResolvedOperation operation = this.toOperation("(null as testdata.MethodOverrides4).m3(null)"); this.withExactDetails(this.candidatesAndOverrides(this.has(operation, 1), 1), IOverrideCheckResult.OverrideCheckDetails.OVERRIDE, IOverrideCheckResult.OverrideCheckDetails.COVARIANT_RETURN, IOverrideCheckResult.OverrideCheckDetails.UNCHECKED_CONVERSION_REQUIRED); }
@Test public void testOverrideMethodResolution_06() { final IResolvedOperation operation = this.toOperation("(null as testdata.MethodOverrides4).m4(null)"); this.withExactDetails(this.candidatesAndOverrides(this.has(operation, 1), 1), IOverrideCheckResult.OverrideCheckDetails.OVERRIDE, IOverrideCheckResult.OverrideCheckDetails.COVARIANT_RETURN, IOverrideCheckResult.OverrideCheckDetails.UNCHECKED_CONVERSION_REQUIRED); }
@Test public void testOverrideMethodResolution_07() { final IResolvedOperation operation = this.toOperation("(null as testdata.MethodOverrides4).m5(null)"); this.candidatesAndOverrides(this.has(operation, 1), 1); }
@Test public void testOverrideMethodResolution_08() { final IResolvedOperation operation = this.toOperation("(null as testdata.MethodOverrides4).m6()"); this.candidatesAndOverrides(this.has(operation, 1), 1); }
@Test public void testOverrideMethodResolution_09() { final IResolvedOperation operation = this.toOperation("(null as testdata.MethodOverrides4).m7()"); this.candidatesAndOverrides(this.has(operation, 2), 1); }
@Test public void testOverrideMethodResolution_10() { final IResolvedOperation operation = this.toOperation("(null as testdata.MethodOverrides4).m7(null, null, null, null)"); this.candidatesAndOverrides(this.has(operation, 2), 1); }