protected void computeAllFeatures( JvmDeclaredType type, String name, Multimap<String, AbstractResolvedOperation> processedOperations, Set<String> processedFields, List<JvmFeature> result) { Iterable<JvmFeature> features = type.findAllFeaturesByName(name); for(JvmFeature feature: features) { if (feature instanceof JvmOperation) { JvmOperation operation = (JvmOperation) feature; String simpleName = operation.getSimpleName(); if (processedOperations.containsKey(simpleName)) { if (isOverridden(operation, processedOperations.get(simpleName))) { continue; } } BottomResolvedOperation resolvedOperation = createResolvedOperation(operation); processedOperations.put(simpleName, resolvedOperation); result.add(operation); } else if (feature instanceof JvmField && processedFields.add(feature.getSimpleName())) { result.add(feature); } } }
@Test public void testFindTypeByName_javaLangNumber_02() { String typeName = Number[][].class.getName(); JvmArrayType type = (JvmArrayType) getTypeProvider().findTypeByName(typeName); JvmOperation longValue = (JvmOperation) type.eResource().getEObject("java.lang.Number.longValue()"); assertNotNull(longValue); JvmDeclaredType number = longValue.getDeclaringType(); assertNotNull(number.getArrayType()); assertSame(type, number.getArrayType().getArrayType()); assertNull(type.eGet(TypesPackage.Literals.JVM_COMPONENT_TYPE__ARRAY_TYPE)); // array will created on the fly assertNotNull(type.getArrayType()); diagnose(type); Resource resource = type.eResource(); getAndResolveAllFragments(resource); recomputeAndCheckIdentifiers(resource); }
private boolean isPotentialJavaOperation(XAbstractFeatureCall featureCall) { if (featureCall.isOperation()) { return true; } if (featureCall.eClass() == XbasePackage.Literals.XMEMBER_FEATURE_CALL && featureCall.isStatic() && featureCall.isExtension() && featureCall.getActualArguments().size() == 2) { JvmIdentifiableElement feature = featureCall.getFeature(); if (feature.eClass() == TypesPackage.Literals.JVM_OPERATION) { JvmDeclaredType declarator = ((JvmOperation) feature).getDeclaringType(); if (IntegerExtensions.class.getName().equals(declarator.getIdentifier()) || LongExtensions.class.getName().equals(declarator.getIdentifier())) { String simpleName = feature.getSimpleName(); if (simpleName.startsWith("bitwise") || simpleName.startsWith("shift")) { return true; } } } } return false; }
private void appendTypeParameters(ITreeAppendable b, JvmOperation operation, LightweightTypeReference instantiatedType) { BottomResolvedOperation resolvedOperation = new BottomResolvedOperation(operation, instantiatedType, overrideTester); List<JvmTypeParameter> typeParameters = resolvedOperation.getResolvedTypeParameters(); b.append("<"); for(int i = 0; i < typeParameters.size(); i++) { if (i != 0) { b.append(", "); } JvmTypeParameter typeParameter = typeParameters.get(i); b.append(typeParameter.getName()); List<LightweightTypeReference> constraints = resolvedOperation.getResolvedTypeParameterConstraints(i); if (!constraints.isEmpty()) { b.append(" extends "); for(int j = 0; j < constraints.size(); j++) { if (j != 0) { b.append(" & "); } b.append(constraints.get(j)); } } } b.append("> "); }
private boolean isValidFunction(JvmOperation op) { // TODO we need context here - the op has to be visible if (op.isAbstract()) { if (Object.class.getName().equals(op.getDeclaringType().getIdentifier())) return false; final String name = op.getSimpleName(); if (name.equals("toString") && op.getParameters().isEmpty()) return false; if (name.equals("equals") && op.getParameters().size() == 1) return false; if (name.equals("hashCode") && op.getParameters().isEmpty()) return false; return true; } return false; }
@Test public void test_twoListWildcardsNoResult_03() { JvmOperation twoListWildcardsNoResult = getMethodFromParameterizedMethods( "twoListWildcardsNoResult(java.util.List,java.util.List)"); JvmFormalParameter firstParam = twoListWildcardsNoResult.getParameters().get(0); JvmTypeReference paramType = firstParam.getParameterType(); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) paramType; assertEquals(1, parameterized.getArguments().size()); JvmTypeReference typeParameter = parameterized.getArguments().get(0); assertTrue(typeParameter instanceof JvmWildcardTypeReference); JvmWildcardTypeReference wildcard = (JvmWildcardTypeReference) typeParameter; assertEquals(1, wildcard.getConstraints().size()); assertTrue(wildcard.getConstraints().get(0) instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) wildcard.getConstraints().get(0); assertNotNull(upperBound.getTypeReference()); JvmType upperBoundType = upperBound.getTypeReference().getType(); assertFalse(upperBoundType.eIsProxy()); assertEquals("java.lang.Object", upperBoundType.getIdentifier()); }
@Test public void testMethods_publicAbstractMethod_01() { String typeName = Methods.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation method = getMethodFromType(type, Methods.class, "publicAbstractMethod()"); assertSame(type, method.getDeclaringType()); assertTrue(method.isAbstract()); assertFalse(method.isFinal()); assertFalse(method.isStatic()); assertFalse(method.isSynchronized()); assertFalse(method.isStrictFloatingPoint()); assertFalse(method.isNative()); assertEquals(JvmVisibility.PUBLIC, method.getVisibility()); JvmType methodType = method.getReturnType().getType(); assertEquals("void", methodType.getIdentifier()); }
protected void _toJavaExpression(final XClosure closure, final ITreeAppendable b) { if (b.hasName(closure)) { b.trace(closure, false).append(getVarName(closure, b)); } else { LightweightTypeReference type = getLightweightType(closure); JvmOperation operation = findImplementingOperation(type); if (operation != null) { GeneratorConfig config = b.getGeneratorConfig(); if (config != null && config.getJavaSourceVersion().isAtLeast(JAVA8) && canCompileToJavaLambda(closure, type, operation)) { toLambda(closure, b.trace(closure, false), type, operation, true); } else { toAnonymousClass(closure, b.trace(closure, false), type, operation); } } } }
@SuppressWarnings("unused") protected void _computeTypes(Map<JvmIdentifiableElement, ResolvedTypes> preparedResolvedTypes, ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmOperation operation) { ResolvedTypes childResolvedTypes = preparedResolvedTypes.get(operation); if (childResolvedTypes == null) { if (preparedResolvedTypes.containsKey(operation)) return; throw new IllegalStateException("No resolved type found. Operation was: " + operation.getIdentifier()); } else { preparedResolvedTypes.put(operation, null); } OperationBodyComputationState state = new OperationBodyComputationState(childResolvedTypes, operation.isStatic() ? featureScopeSession : featureScopeSession.toInstanceContext(), operation); addExtensionProviders(state, operation.getParameters()); markComputing(operation.getReturnType()); try { state.computeTypes(); } finally { unmarkComputing(operation.getReturnType()); } computeAnnotationTypes(childResolvedTypes, featureScopeSession, operation); computeLocalTypes(preparedResolvedTypes, childResolvedTypes, featureScopeSession, operation); mergeChildTypes(childResolvedTypes); }
@Test public void publicNativeMethod() { String typeName = Methods.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation method = getMethodFromType(type, Methods.class, "publicStrictFpMethod()"); assertSame(type, method.getDeclaringType()); assertFalse(method.isAbstract()); assertFalse(method.isFinal()); assertFalse(method.isStatic()); assertFalse(method.isSynchronized()); assertTrue(method.isStrictFloatingPoint()); assertFalse(method.isNative()); assertEquals(JvmVisibility.PUBLIC, method.getVisibility()); JvmType methodType = method.getReturnType().getType(); assertEquals("void", methodType.getIdentifier()); }
@Test public void test_ParameterizedTypes_03() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodT = getMethodFromType(type, ParameterizedTypes.class, "methodT(T)"); JvmTypeReference listS = methodT.getReturnType(); assertFalse(listS.toString(), listS.eIsProxy()); assertEquals("java.util.List<? extends java.lang.Object & super T>", listS.getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) listS; assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); assertTrue(typeArgument instanceof JvmWildcardTypeReference); JvmWildcardTypeReference wildcardTypeArgument = (JvmWildcardTypeReference) typeArgument; assertEquals("? extends java.lang.Object & super T", wildcardTypeArgument.getIdentifier()); assertEquals(2, wildcardTypeArgument.getConstraints().size()); JvmUpperBound uperBound = (JvmUpperBound) wildcardTypeArgument.getConstraints().get(0); assertEquals("java.lang.Object", uperBound.getTypeReference().getIdentifier()); JvmLowerBound lowerBound = (JvmLowerBound) wildcardTypeArgument.getConstraints().get(1); JvmTypeParameter t = type.getTypeParameters().get(1); assertSame(t, lowerBound.getTypeReference().getType()); }
@Override public List<JvmOperation> getOverriddenAndImplementedMethodCandidates() { if (overrideCandidates != null) return overrideCandidates; // here we are only interested in the raw type thus the declarator is not substituted // the found operation will be put in the right context by clients, e.g. #getOverriddenAndImplementedMethods ParameterizedTypeReference currentDeclarator = getContextType().getOwner().newParameterizedTypeReference(getDeclaration().getDeclaringType()); List<LightweightTypeReference> superTypes = currentDeclarator.getSuperTypes(); List<JvmOperation> result = Lists.newArrayListWithCapacity(5); for(LightweightTypeReference superType: superTypes) { if (superType.getType() instanceof JvmDeclaredType) { JvmDeclaredType declaredSuperType = (JvmDeclaredType) superType.getType(); if (declaredSuperType != null) { Iterable<JvmFeature> equallyNamedFeatures = declaredSuperType.findAllFeaturesByName(getDeclaration().getSimpleName()); for(JvmFeature equallyNamedFeature: equallyNamedFeatures) { if (equallyNamedFeature instanceof JvmOperation) { result.add((JvmOperation) equallyNamedFeature); } } } } } return overrideCandidates = Collections.unmodifiableList(result); }
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); } }
@Test public void test_ParameterizedTypes_Inner_07() { String typeName = ParameterizedTypes.Inner.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodV = getMethodFromType(type, ParameterizedTypes.Inner.class, "methodZArray_01()"); JvmTypeReference listZ = methodV.getReturnType(); assertEquals("java.util.List<Z[][]>", listZ.getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) listZ; assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); JvmType argumentType = typeArgument.getType(); assertTrue(argumentType instanceof JvmArrayType); assertTrue(((JvmArrayType) argumentType).getComponentType() instanceof JvmArrayType); JvmComponentType componentType = ((JvmArrayType) ((JvmArrayType) argumentType).getComponentType()) .getComponentType(); JvmTypeParameter z = type.getTypeParameters().get(2); assertSame(z, componentType); }
@Test public void testIntegerAnnotation() { try { final XAnnotationsFactory f = XAnnotationsFactory.eINSTANCE; final XExpression e = this.expression("\'Foo\'"); final XAnnotation anno = f.createXAnnotation(); JvmType _findDeclaredType = this.references.findDeclaredType(TestAnnotation3.class, e); final JvmAnnotationType annotatiomType = ((JvmAnnotationType) _findDeclaredType); anno.setAnnotationType(annotatiomType); final XAnnotationElementValuePair pair = f.createXAnnotationElementValuePair(); pair.setElement(IterableExtensions.<JvmOperation>head(annotatiomType.getDeclaredOperations())); pair.setValue(this.expression("10")); EList<XAnnotationElementValuePair> _elementValuePairs = anno.getElementValuePairs(); this._jvmTypesBuilder.<XAnnotationElementValuePair>operator_add(_elementValuePairs, pair); final JvmGenericType type = this.typesFactory.createJvmGenericType(); this._jvmTypesBuilder.addAnnotation(type, anno); Assert.assertEquals(anno.getAnnotationType(), IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getAnnotation()); Assert.assertEquals(1, IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues().size()); JvmAnnotationValue _head = IterableExtensions.<JvmAnnotationValue>head(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues()); final JvmCustomAnnotationValue value = ((JvmCustomAnnotationValue) _head); EObject _head_1 = IterableExtensions.<EObject>head(value.getValues()); Assert.assertTrue((_head_1 instanceof XNumberLiteral)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void test_ParameterizedTypes_Inner_08() { String typeName = ParameterizedTypes.Inner.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodV = getMethodFromType(type, ParameterizedTypes.Inner.class, "methodZArray_02()"); JvmTypeReference listZ = methodV.getReturnType(); assertEquals("java.util.List<Z[]>[]", listZ.getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) ((JvmGenericArrayTypeReference) listZ) .getComponentType(); assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); JvmType argumentType = typeArgument.getType(); assertTrue(argumentType instanceof JvmArrayType); JvmComponentType componentType = ((JvmArrayType) argumentType).getComponentType(); JvmTypeParameter z = type.getTypeParameters().get(2); assertSame(z, componentType); }
protected boolean canCompileToJavaLambda(XClosure closure, LightweightTypeReference typeRef, JvmOperation operation) { if (!typeRef.isInterfaceType()) return false; if (!operation.getTypeParameters().isEmpty()) return false; TreeIterator<EObject> iterator = closure.eAllContents(); JvmType jvmType = typeRef.getType(); while (iterator.hasNext()) { EObject obj = iterator.next(); if (obj instanceof XClosure) { iterator.prune(); } else if (obj instanceof XFeatureCall && isReferenceToSelf((XFeatureCall) obj, jvmType)) { return false; } } return true; }
@Test public void testCompilationStrategy() { try { final XExpression expression = this.expression("null", false); final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> { EList<JvmMember> _members = it.getMembers(); JvmField _field = this.builder.toField(expression, "x", this.typeRef(expression, String.class)); this.builder.<JvmField>operator_add(_members, _field); EList<JvmMember> _members_1 = it.getMembers(); JvmOperation _getter = this.builder.toGetter(expression, "x", this.typeRef(expression, String.class)); this.builder.<JvmOperation>operator_add(_members_1, _getter); EList<JvmMember> _members_2 = it.getMembers(); JvmOperation _setter = this.builder.toSetter(expression, "x", this.typeRef(expression, String.class)); this.builder.<JvmOperation>operator_add(_members_2, _setter); }; final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function); final Class<?> compiled = this.compile(expression.eResource(), clazz); final Object inst = compiled.newInstance(); final Method getter = compiled.getMethod("getX"); final Method setter = compiled.getMethod("setX", String.class); setter.invoke(inst, "FOO"); Assert.assertEquals("FOO", getter.invoke(inst)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void testMethods_defaultStaticMethod_01() { String typeName = Methods.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation method = getMethodFromType(type, Methods.class, "defaultStaticMethod()"); assertSame(type, method.getDeclaringType()); assertFalse(method.isAbstract()); assertFalse(method.isFinal()); assertTrue(method.isStatic()); assertFalse(method.isSynchronized()); assertFalse(method.isStrictFloatingPoint()); assertFalse(method.isNative()); assertEquals(JvmVisibility.DEFAULT, method.getVisibility()); JvmType methodType = method.getReturnType().getType(); assertEquals("void", methodType.getIdentifier()); }
@Test public void testDefaultAnnotationAnnotationValueByReference() throws Exception { String typeName = Bug334943Client.class.getName(); JvmDeclaredType client = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); JvmOperation operation = Iterables.get(client.getDeclaredOperations(), 0); List<JvmAnnotationReference> annotations = operation.getAnnotations(); assertEquals(1, annotations.size()); JvmAnnotationReference annotation = annotations.get(0); for (JvmAnnotationValue value : annotation.getValues()) { if ("enumValue".equals(value.getValueName())) { JvmEnumAnnotationValue enumValue = (JvmEnumAnnotationValue) value; assertEquals(1, enumValue.getValues().size()); assertEquals("FirstValue", enumValue.getValues().get(0).getSimpleName()); } } }
@Test @Override public void testFindTypeByName_AbstractMultimap_02() { String typeName = "com.google.common.collect.AbstractMultimap"; JvmType _findTypeByName = this.getTypeProvider().findTypeByName(typeName); JvmGenericType type = ((JvmGenericType) _findTypeByName); JvmFeature _onlyElement = Iterables.<JvmFeature>getOnlyElement(type.findAllFeaturesByName("containsValue")); JvmOperation containsValue = ((JvmOperation) _onlyElement); Assert.assertNotNull(containsValue); JvmFormalParameter firstParam = containsValue.getParameters().get(0); Assert.assertEquals(1, firstParam.getAnnotations().size()); JvmAnnotationReference annotationReference = firstParam.getAnnotations().get(0); JvmAnnotationType annotationType = annotationReference.getAnnotation(); Assert.assertTrue(annotationType.eIsProxy()); Assert.assertEquals("java:/Objects/javax.annotation.Nullable", EcoreUtil.getURI(annotationType).trimFragment().toString()); }
@Test public void testMethods_protectedFinalMethod_01() { String typeName = Methods.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation method = getMethodFromType(type, Methods.class, "protectedFinalMethod()"); assertSame(type, method.getDeclaringType()); assertFalse(method.isAbstract()); assertTrue(method.isFinal()); assertFalse(method.isStatic()); assertFalse(method.isSynchronized()); assertFalse(method.isStrictFloatingPoint()); assertFalse(method.isNative()); assertEquals(JvmVisibility.PROTECTED, method.getVisibility()); JvmType methodType = method.getReturnType().getType(); assertEquals("void", methodType.getIdentifier()); }
protected void checkIsValidConstructorArgument(XExpression argument, JvmType containerType) { TreeIterator<EObject> iterator = EcoreUtil2.eAll(argument); while(iterator.hasNext()) { EObject partOfArgumentExpression = iterator.next(); if (partOfArgumentExpression instanceof XFeatureCall || partOfArgumentExpression instanceof XMemberFeatureCall) { XAbstractFeatureCall featureCall = (XAbstractFeatureCall) partOfArgumentExpression; XExpression actualReceiver = featureCall.getActualReceiver(); if(actualReceiver instanceof XFeatureCall && ((XFeatureCall)actualReceiver).getFeature() == containerType) { JvmIdentifiableElement feature = featureCall.getFeature(); if (feature != null && !feature.eIsProxy()) { if (feature instanceof JvmField) { if (!((JvmField) feature).isStatic()) error("Cannot refer to an instance field " + feature.getSimpleName() + " while explicitly invoking a constructor", partOfArgumentExpression, null, INVALID_CONSTRUCTOR_ARGUMENT); } else if (feature instanceof JvmOperation) { if (!((JvmOperation) feature).isStatic()) error("Cannot refer to an instance method while explicitly invoking a constructor", partOfArgumentExpression, null, INVALID_CONSTRUCTOR_ARGUMENT); } } } } else if(isLocalClassSemantics(partOfArgumentExpression)) { iterator.prune(); } } }
@Test public void testNestedAnnotationType() { try { final XExpression expression = this.expression("42"); final JvmGenericType outerClass = this.builder.toClass(expression, "my.outer.Clazz"); EList<JvmMember> _members = outerClass.getMembers(); final Procedure1<JvmAnnotationType> _function = (JvmAnnotationType it) -> { EList<JvmMember> _members_1 = it.getMembers(); final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> { this.builder.setBody(it_1, expression); }; JvmOperation _method = this.builder.toMethod(expression, "theTruth", this.references.getTypeForName(int.class, expression), _function_1); this.builder.<JvmOperation>operator_add(_members_1, _method); }; JvmAnnotationType _annotationType = this.builder.toAnnotationType(expression, "MyAnnotation", _function); this.builder.<JvmAnnotationType>operator_add(_members, _annotationType); final Class<?> compiled = IterableExtensions.<Class<?>>head(((Iterable<Class<?>>)Conversions.doWrapArray(this.compile(expression.eResource(), outerClass).getDeclaredClasses()))); Assert.assertEquals("my.outer.Clazz.MyAnnotation", compiled.getCanonicalName()); Assert.assertEquals(Integer.valueOf(42), IterableExtensions.<Method>head(((Iterable<Method>)Conversions.doWrapArray(compiled.getDeclaredMethods()))).getDefaultValue()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
public JvmAnnotationValue getConstructorParameterAnnotationValue(String name, boolean defaultValue) { String typeName = TestAnnotation.Annotated.class.getName(); JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class, "Annotated(java.lang.String,java.lang.String,java.lang.String)"); JvmAnnotationTarget target = constructor.getParameters().get(0); JvmAnnotationValue result = getDefaultOrExplicitAnnotationValue(name, target); if (defaultValue) { if (isDefaultValueSupported()) { assertTrue(result.eContainer() instanceof JvmOperation); } else { assertFalse(result.eContainer() instanceof JvmOperation); } } else { assertFalse(result.eContainer() instanceof JvmOperation); } return result; }
protected void assertMembers(String typeName, Set<String> memberNames) { JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); assertEquals(memberNames.size(), type.getMembers().size()); for (org.eclipse.xtext.common.types.JvmMember member : type.getMembers()) { assertTrue(member.getIdentifier(), member instanceof JvmOperation); JvmOperation op = (JvmOperation) member; assertTrue(op.getSimpleName(), memberNames.remove(op.getSimpleName())); } assertTrue(memberNames.isEmpty()); }
@Test public void testFindTypeByName_javaLangCharSequence_03() { String typeName = CharSequence.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation length = (JvmOperation) type.eResource().getEObject("java.lang.CharSequence.length()"); assertNotNull(length); JvmType returnType = length.getReturnType().getType(); assertNotNull(returnType); assertFalse(returnType.eIsProxy()); assertEquals("int", returnType.getIdentifier()); }
@Override protected ITypeComputationResult createNoTypeResult() { JvmOperation operation = (JvmOperation) getMember(); LightweightTypeReference expectedType = ((LogicalContainerAwareReentrantTypeResolver)getResolver()).getReturnTypeOfOverriddenOperation(operation, resolvedTypes, getFeatureScopeSession()); if (expectedType != null) { InferredTypeIndicator.resolveTo(operation.getReturnType(), expectedType.toJavaCompliantTypeReference()); } return new NoTypeResult(getMember(), resolvedTypes.getReferenceOwner()); }
@Test public void testFindTypeByName_javaUtilList_06() { String typeName = List.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation containsAll = (JvmOperation) type.eResource() .getEObject("java.util.List.containsAll(java.util.Collection)"); assertEquals(1, containsAll.getParameters().size()); assertEquals(getCollectionParamName(), containsAll.getParameters().get(0).getName()); JvmType parameterType = containsAll.getParameters().get(0).getParameterType().getType(); assertFalse(parameterType.toString(), parameterType.eIsProxy()); }
protected boolean isSimpleFeatureCall(XExpression switch1) { if (switch1 instanceof XFeatureCall) { XFeatureCall featureCall = (XFeatureCall) switch1; return !(featureCall.getFeature() instanceof JvmOperation); } return false; }
@Test public void test_twoListParamsNoResult_02() { JvmOperation twoListParamsNoResult = getMethodFromParameterizedMethods( "twoListParamsNoResult(java.util.List,java.util.List)"); JvmFormalParameter firstParam = twoListParamsNoResult.getParameters().get(0); JvmTypeReference paramType = firstParam.getParameterType(); assertNotNull(paramType); assertFalse(paramType.getType().eIsProxy()); assertEquals("java.util.List<T>", paramType.getIdentifier()); assertTrue(paramType instanceof JvmParameterizedTypeReference); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) paramType; JvmType rawType = parameterized.getType(); assertFalse(rawType.eIsProxy()); assertEquals("java.util.List", rawType.getIdentifier()); }
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 testToGetterWithNullTypeRef() { try { final XExpression e = this.expression("\'\'"); final JvmOperation getter = this._jvmTypesBuilder.toGetter(e, "foo", null); this.expectBody(getter, "return this.foo;"); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void testVarArgs_02() { String typeName = ClassWithVarArgs.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation method = getMethodFromType(type, ClassWithVarArgs.class, "method(java.lang.String[])"); assertTrue(method.isVarArgs()); assertEquals(1, method.getParameters().size()); assertTrue(method.getParameters().get(0).getParameterType() instanceof JvmGenericArrayTypeReference); }
@Test public void testFeatureCall_9() throws Exception { XBlockExpression block = (XBlockExpression) expression( "{\n" + " val list = newArrayList\n" + " list.addAll(null as Integer, null as String[])\n" + " list\n" + "}"); XMemberFeatureCall memberFeatureCall = (XMemberFeatureCall) block.getExpressions().get(1); assertEquals("java.util.ArrayList.addAll(int,java.util.Collection)", ((JvmOperation)memberFeatureCall.getFeature()).getIdentifier()); }
@Test public void testAbstractMethod() throws Exception { String typeName = AbstractMethods.class.getName(); JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); assertEquals(3, size(type.getDeclaredOperations())); for (JvmOperation op : type.getDeclaredOperations()) { if (op.getSimpleName().startsWith("abstract")) { assertTrue(op.isAbstract()); } else { assertFalse(op.isAbstract()); } } }
@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); }