/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @SuppressWarnings("unchecked") @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case XAnnotationsPackage.XANNOTATION__ELEMENT_VALUE_PAIRS: getElementValuePairs().clear(); getElementValuePairs().addAll((Collection<? extends XAnnotationElementValuePair>)newValue); return; case XAnnotationsPackage.XANNOTATION__ANNOTATION_TYPE: setAnnotationType((JvmType)newValue); return; case XAnnotationsPackage.XANNOTATION__VALUE: setValue((XExpression)newValue); return; } super.eSet(featureID, newValue); }
@Test public void testFindTypeByName_javaLangNumber_01() { String typeName = Number.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); assertFalse("toplevel type is not static", type.isStatic()); assertEquals(type.getSuperTypes().toString(), 2, type.getSuperTypes().size()); JvmType objectType = type.getSuperTypes().get(0).getType(); assertFalse("isProxy: " + objectType, objectType.eIsProxy()); assertEquals(Object.class.getName(), objectType.getIdentifier()); JvmType serializableType = type.getSuperTypes().get(1).getType(); assertFalse("isProxy: " + serializableType, serializableType.eIsProxy()); assertEquals(Serializable.class.getName(), serializableType.getIdentifier()); diagnose(type); Resource resource = type.eResource(); getAndResolveAllFragments(resource); recomputeAndCheckIdentifiers(resource); }
@Test public void testHintsAfterPrepareComputation_01() throws Exception { JvmType iterableType = getTypeForName(Iterable.class, state); JvmTypeParameter typeParameter = createTypeParameter("ELEMENT", state); ParameterizedTypeReference iterableTypeReference = state.getReferenceOwner().newParameterizedTypeReference(iterableType); UnboundTypeReference elementReference = (UnboundTypeReference) createTypeReference(typeParameter, state); iterableTypeReference.addTypeArgument(elementReference); assertTrue(state.getResolvedTypes().getHints(elementReference.getHandle()).isEmpty()); TypeExpectation expectation = new TypeExpectation(iterableTypeReference, state, false); ClosureTypeComputer computer = new ClosureTypeComputer(closure("[|]", getContextResourceSet()), expectation, state); computer.selectStrategy(); FunctionTypeReference closureType = computer.getExpectedClosureType(); assertEquals("java.lang.Iterable.iterator()", computer.getOperation().getIdentifier()); assertEquals("Iterable<Unbound[T]>", getEquivalentSimpleName(closureType)); assertEquals("()=>Iterator<Unbound[T]>", closureType.getSimpleName()); assertEquals(1, state.getResolvedTypes().getHints(elementReference.getHandle()).size()); UnboundTypeReference closureTypeArgument = (UnboundTypeReference) closureType.getTypeArguments().get(0); assertEquals(1, state.getResolvedTypes().getHints(closureTypeArgument.getHandle()).size()); }
@Test public void test_ParameterizedTypes_Inner_06() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodV = getMethodFromType(type, ParameterizedTypes.Inner.class, "methodVArray_02()"); JvmTypeReference listV = methodV.getReturnType(); assertEquals("java.util.List<? extends V[]>", listV.getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) listV; assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); assertTrue(typeArgument instanceof JvmWildcardTypeReference); JvmWildcardTypeReference wildcardTypeArgument = (JvmWildcardTypeReference) typeArgument; assertEquals("? extends V[]", wildcardTypeArgument.getIdentifier()); assertEquals(1, wildcardTypeArgument.getConstraints().size()); JvmUpperBound upperBound = (JvmUpperBound) wildcardTypeArgument.getConstraints().get(0); JvmType upperBoundType = upperBound.getTypeReference().getType(); assertTrue(upperBoundType instanceof JvmArrayType); assertTrue(((JvmArrayType) upperBoundType).getComponentType() instanceof JvmTypeParameter); JvmTypeParameter v = type.getTypeParameters().get(3); assertSame(v, ((JvmArrayType) upperBoundType).getComponentType()); }
@Check public void checkAllAttributesConfigured(XAnnotation annotation) { JvmType annotationType = annotation.getAnnotationType(); if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType)) return; Iterable<JvmOperation> attributes = ((JvmAnnotationType) annotationType).getDeclaredOperations(); for (JvmOperation jvmOperation : attributes) { XExpression value = annotationUtil.findValue(annotation, jvmOperation); if(value == null) { if (jvmOperation.getDefaultValue() == null) { error("The annotation must define the attribute '"+jvmOperation.getSimpleName()+"'.", annotation, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ANNOTATIONS_MISSING_ATTRIBUTE_DEFINITION); } } else annotationValueValidator.validateAnnotationValue(value, this); } }
/** * Read and resolve the EObject from the given description and navigate to its children according * to the given fragment. * @since 2.8 */ protected EObject getAccessibleType(IEObjectDescription description, String fragment, ResourceSet resourceSet) throws UnknownNestedTypeException { EObject typeProxy = description.getEObjectOrProxy(); if (typeProxy.eIsProxy()) { typeProxy = EcoreUtil.resolve(typeProxy, resourceSet); } if (!typeProxy.eIsProxy() && typeProxy instanceof JvmType) { if (fragment != null) { EObject result = resolveJavaObject((JvmType) typeProxy, fragment); if (result != null) return result; } else return typeProxy; } return null; }
@Test public void test_ParameterizedTypes_06() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodMap = getMethodFromType(type, ParameterizedTypes.class, "methodMap(java.util.Map)"); assertEquals(1, methodMap.getParameters().size()); assertEquals(1, methodMap.getTypeParameters().size()); assertEquals("Z", methodMap.getTypeParameters().get(0).getIdentifier()); JvmType z = methodMap.getReturnType().getType(); assertSame(methodMap.getTypeParameters().get(0), z); JvmTypeReference mapType = methodMap.getParameters().get(0).getParameterType(); assertEquals("java.util.Map<? extends java.lang.Object & super Z, ? extends S>", mapType.getIdentifier()); JvmParameterizedTypeReference parameterizedMapType = (JvmParameterizedTypeReference) mapType; assertEquals(2, parameterizedMapType.getArguments().size()); JvmWildcardTypeReference extendsS = (JvmWildcardTypeReference) parameterizedMapType.getArguments().get(1); assertEquals(1, extendsS.getConstraints().size()); JvmType s = type.getTypeParameters().get(0); assertSame(s, extendsS.getConstraints().get(0).getTypeReference().getType()); }
protected int doIsConformantOuter(LightweightTypeReference left, LightweightTypeReference right, int nestedResult, int flags) { if ((nestedResult & SUCCESS) != 0) { JvmType leftType = left.getType(); EObject leftDeclarator = leftType.eContainer(); if (leftDeclarator instanceof JvmDeclaredType) { JvmDeclaredType castedLeftDeclarator = (JvmDeclaredType) leftDeclarator; LightweightTypeReference leftOuter = left.getOuter().getSuperType(castedLeftDeclarator); if (leftOuter != null) { LightweightTypeReference rightOuter = right.getOuter().getSuperType(castedLeftDeclarator); if (rightOuter != null) { int outerResult = doIsConformant(leftOuter, rightOuter, flags); if ((outerResult & SUCCESS) == 0) { return outerResult; } } } } } return nestedResult; }
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); }
@Test public void test_twoListParamsNoResult_03() { JvmOperation twoListParamsNoResult = getMethodFromParameterizedMethods( "twoListParamsNoResult(java.util.List,java.util.List)"); JvmFormalParameter firstParam = twoListParamsNoResult.getParameters().get(0); JvmTypeReference paramType = firstParam.getParameterType(); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) paramType; assertEquals(1, parameterized.getArguments().size()); JvmTypeReference typeParameter = parameterized.getArguments().get(0); JvmType referencedType = typeParameter.getType(); assertFalse(referencedType.eIsProxy()); assertTrue(referencedType instanceof JvmTypeParameter); JvmTypeParameter typeVar = (JvmTypeParameter) referencedType; assertEquals("T", typeVar.getName()); assertSame(twoListParamsNoResult, typeVar.getDeclarator()); }
@Override public boolean validate(IAcceptor<? super AbstractDiagnostic> result) { JvmType type = (JvmType) description.getElementOrProxy(); String typeKind = ""; if (type instanceof JvmPrimitiveType || type instanceof JvmVoid) { typeKind = "primitive type"; } else if (type instanceof JvmAnnotationType) { typeKind = "annotation type"; } else if (type instanceof JvmEnumerationType) { typeKind = "enum type"; } else if (type instanceof JvmGenericType && ((JvmGenericType) type).isInterface()) { typeKind = "interface type"; } else if (type instanceof JvmTypeParameter) { typeKind = "type parameter"; } String message = String.format("Cannot instantiate the %s %s", typeKind, type.getSimpleName()); AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.ILLEGAL_CLASS_INSTANTIATION, message, getExpression(), XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, -1, null); result.accept(diagnostic); return false; }
/** * @return a fresh {@link JvmMultiTypeReference} pointing to the given references or null if {@link Object} is not * on the context's class path */ public JvmMultiTypeReference createMultiTypeReference(Notifier context, JvmTypeReference... references) { if (context == null) throw new NullPointerException("context"); JvmMultiTypeReference result = factory.createJvmMultiTypeReference(); if (references != null && references.length != 0) { for (JvmTypeReference reference : references) { result.getReferences().add(createDelegateTypeReference(reference)); } } final JvmType findDeclaredType = findDeclaredType(Object.class, context); if (findDeclaredType == null) return null; result.setType(findDeclaredType); return result; }
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 test_ParameterizedTypes_Inner_X_01() { String typeName = ParameterizedTypes.Inner.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeParameterX = type.getTypeParameters().get(0); assertEquals("X", typeParameterX.getIdentifier()); assertSame(type, typeParameterX.getDeclarator()); assertEquals(1, typeParameterX.getConstraints().size()); JvmTypeConstraint typeConstraint = typeParameterX.getConstraints().get(0); assertTrue(typeConstraint instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) typeConstraint; assertNotNull(upperBound.getTypeReference()); assertEquals("W", upperBound.getTypeReference().getIdentifier()); JvmType upperBoundType = upperBound.getTypeReference().getType(); assertTrue(upperBoundType instanceof JvmTypeParameter); JvmTypeParameter typeParameterW = (JvmTypeParameter) upperBoundType; assertSame(type.getDeclaringType(), typeParameterW.getDeclarator()); }
@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()); }
public IScope createFeatureCallSerializationScope(EObject context) { if (!(context instanceof XAbstractFeatureCall)) { return IScope.NULLSCOPE; } XAbstractFeatureCall call = (XAbstractFeatureCall) context; JvmIdentifiableElement feature = call.getFeature(); // this and super - logical container aware FeatureScopes if (feature instanceof JvmType) { return getTypeScope(call, (JvmType) feature); } if (feature instanceof JvmConstructor) { return getThisOrSuperScope(call, (JvmConstructor) feature); } if (feature instanceof JvmExecutable) { return getExecutableScope(call, feature); } if (feature instanceof JvmFormalParameter || feature instanceof JvmField || feature instanceof XVariableDeclaration || feature instanceof XSwitchExpression) { return new SingletonScope(EObjectDescription.create(feature.getSimpleName(), feature), IScope.NULLSCOPE); } return IScope.NULLSCOPE; }
@Override public boolean accept(LightweightTypeReference superType, int distance) { if (superType == null) throw new IllegalStateException("superType may not be null"); JvmType type = superType.getType(); if (type != null) { rawTypeToReference.put(type, superType); if (distances.contains(type)) { int currentCount = distances.count(type); if (currentCount < distance + 1) { distances.setCount(type, distance + 1); } } else { distances.add(type, distance + 1); } } return true; }
protected IScope doGetTypeScope(XMemberFeatureCall call, JvmType type) { if (call.isPackageFragment()) { if (type instanceof JvmDeclaredType) { int segmentIndex = countSegments(call); String packageName = ((JvmDeclaredType) type).getPackageName(); List<String> splitted = Strings.split(packageName, '.'); String segment = splitted.get(segmentIndex); return new SingletonScope(EObjectDescription.create(segment, type), IScope.NULLSCOPE); } return IScope.NULLSCOPE; } else { if (type instanceof JvmDeclaredType && ((JvmDeclaredType) type).getDeclaringType() == null) { return new SingletonScope(EObjectDescription.create(type.getSimpleName(), type), IScope.NULLSCOPE); } else { XAbstractFeatureCall target = (XAbstractFeatureCall) call.getMemberCallTarget(); if (target.isPackageFragment()) { String qualifiedName = type.getQualifiedName(); int dot = qualifiedName.lastIndexOf('.'); String simpleName = qualifiedName.substring(dot + 1); return new SingletonScope(EObjectDescription.create(simpleName, type), IScope.NULLSCOPE); } else { return new SingletonScope(EObjectDescription.create(type.getSimpleName(), type), IScope.NULLSCOPE); } } } }
@Test public void testFindTypeByName_int() { String typeName = "int"; JvmType type = getTypeProvider().findTypeByName(typeName); assertNotNull(type); assertTrue(type instanceof JvmPrimitiveType); assertEquals(typeName, type.getIdentifier()); diagnose(type); Resource resource = type.eResource(); getAndResolveAllFragments(resource); recomputeAndCheckIdentifiers(resource); }
@Test public void testFindTypeByName_javaLangCharSequence_04() { String typeName = CharSequence.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation charAt = (JvmOperation) type.eResource().getEObject("java.lang.CharSequence.charAt(int)"); assertNotNull(charAt); JvmType returnType = charAt.getReturnType().getType(); assertNotNull(returnType); assertFalse(returnType.eIsProxy()); assertEquals("char", returnType.getIdentifier()); assertEquals(1, charAt.getParameters().size()); JvmType intType = getTypeProvider().findTypeByName("int"); assertSame(intType, charAt.getParameters().get(0).getParameterType().getType()); }
@Override public List<LightweightTypeReference> getTypeArguments() { JvmType type = (JvmType) getFeature(); if (type == null || type.eIsProxy()) { throw new IllegalStateException(); } ITypeReferenceOwner referenceOwner = getResolvedTypes().getReferenceOwner(); if (type instanceof JvmTypeParameterDeclarator) { List<JvmTypeParameter> typeParameters = ((JvmTypeParameterDeclarator) type).getTypeParameters(); if (!typeParameters.isEmpty()) { List<LightweightTypeReference> result = Lists.newArrayList(); List<LightweightTypeReference> typeArguments = getSyntacticTypeArguments(); int max = Math.min(typeParameters.size(), typeArguments.size()); for(int i = 0; i < max; i++) { result.add(typeArguments.get(i)); } if (max < typeParameters.size()) { TypeParameterByConstraintSubstitutor substitutor = new TypeParameterByConstraintSubstitutor( Collections.<JvmTypeParameter, LightweightMergedBoundTypeArgument> emptyMap(), referenceOwner); for(int i = max; i < typeParameters.size(); i++) { JvmTypeParameter typeParameter = typeParameters.get(i); result.add(substitutor.substitute(typeParameter)); } } return result; } } return Collections.emptyList(); }
@Test public void test_twoListWildcardsListResult_02() { JvmOperation twoListWildcardsListResult = getMethodFromParameterizedMethods( "twoListWildcardsListResult(java.util.List,java.util.List)"); JvmTypeReference returnType = twoListWildcardsListResult.getReturnType(); assertNotNull(returnType); assertFalse(returnType.eIsProxy()); assertEquals("java.util.List<? extends java.lang.Object>", returnType.getIdentifier()); assertTrue(returnType instanceof JvmParameterizedTypeReference); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) returnType; JvmType rawType = parameterized.getType(); assertFalse(rawType.eIsProxy()); assertEquals("java.util.List", rawType.getIdentifier()); }
public ContextualVisibilityHelper(IVisibilityHelper parent, JvmType rawContextType) { this.parent = parent; this.rawContextType = rawContextType; if (rawContextType instanceof JvmDeclaredType) { this.packageName = ((JvmDeclaredType) rawContextType).getPackageName(); } }
@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()); }
@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()); }
@Override public String getQualifiedName(char innerClassDelimiter) { JvmType type = getType(); if (type != null) return type.getQualifiedName(innerClassDelimiter); return null; }
@Test public void test_twoListParamsListResult_02() { JvmOperation twoListParamsListResult = getMethodFromParameterizedMethods( "twoListParamsListResult(java.util.List,java.util.List)"); JvmTypeReference returnType = twoListParamsListResult.getReturnType(); assertNotNull(returnType); assertEquals("java.util.List<T>", returnType.getIdentifier()); assertTrue(returnType instanceof JvmParameterizedTypeReference); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) returnType; JvmType rawType = parameterized.getType(); assertFalse(rawType.eIsProxy()); assertEquals("java.util.List", rawType.getIdentifier()); }
public FunctionTypeKind getFunctionTypeKind(ParameterizedTypeReference typeReference) { JvmType type = typeReference.getType(); if (type.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) { JvmDeclaredType outerType = ((JvmGenericType) type).getDeclaringType(); if (outerType != null) { if (Procedures.class.getName().equals(outerType.getIdentifier())) { return FunctionTypeKind.PROCEDURE; } if (Functions.class.getName().equals(outerType.getIdentifier())) { return FunctionTypeKind.FUNCTION; } } } return FunctionTypeKind.NONE; }
private JvmTypeReference newObjectReference() { JvmType objectType = typesFactory.createJvmGenericType(); String objectClassName = Object.class.getName(); ((InternalEObject) objectType).eSetProxyURI(URIHelperConstants.OBJECTS_URI.appendSegment(objectClassName).appendFragment(objectClassName)); JvmParameterizedTypeReference result = typesFactory.createJvmParameterizedTypeReference(); result.setType(objectType); return result; }
public boolean isFunctionAndProcedureAvailable(ITypeReferenceOwner owner) { JvmType type = typeReferences.findDeclaredType(Procedures.Procedure1.class, owner.getContextResourceSet()); if (type == null) { return false; } if (type instanceof JvmTypeParameterDeclarator) { return !((JvmTypeParameterDeclarator) type).getTypeParameters().isEmpty(); } return false; }
@Test public void test_nestedTypes_Outer_Inner_01() { String typeName = NestedTypes.Outer.Inner.class.getName(); String expectedSuffix = NestedTypes.class.getSimpleName() + "$" + NestedTypes.Outer.class.getSimpleName() + "$" + NestedTypes.Outer.Inner.class.getSimpleName(); assertTrue(typeName + " endsWith " + expectedSuffix, typeName.endsWith(expectedSuffix)); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); assertNotNull(type); assertEquals(typeName, type.getIdentifier()); JvmType outerType = (JvmType) type.eContainer(); assertEquals(NestedTypes.Outer.class.getName(), outerType.getIdentifier()); }
protected JvmTypeParameter findMappedParameter(JvmTypeParameter parameter, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> mapping, Collection<JvmTypeParameter> visited) { for(Map.Entry<JvmTypeParameter, LightweightMergedBoundTypeArgument> entry: mapping.entrySet()) { LightweightMergedBoundTypeArgument reference = entry.getValue(); JvmType type = reference.getTypeReference().getType(); if (parameter == type) { if (visited.add(entry.getKey())) return entry.getKey(); return null; } } return null; }
/** * Determines if this type reference denotes the same type or a subtype of * the given {@code type}. */ public boolean isSubtypeOf(JvmType type) { if (type == null) { throw new IllegalArgumentException("type may not be null"); } // TODO interfaces don't inherit from non-interfaces, primitives, arrays, object // A final type does not have any subtypes // check for type == this.type LightweightTypeReference other = owner.toPlainTypeReference(type); boolean result = other.isAssignableFrom(this); return result; }
@Test public void test_ParameterizedTypes_Inner_03() { String typeName = ParameterizedTypes.Inner.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodX = getMethodFromType(type, ParameterizedTypes.Inner.class, "methodX()"); JvmType x = methodX.getReturnType().getType(); assertFalse(x.toString(), x.eIsProxy()); assertTrue(x instanceof JvmTypeParameter); JvmTypeParameter xParam = (JvmTypeParameter) x; assertSame(type, xParam.getDeclarator()); }
/** * @since 2.4 */ @Override public JvmType findTypeByName(String name, boolean binaryNestedTypeDelimiter) { if (isBinaryNestedTypeDelimiter(name, binaryNestedTypeDelimiter)) { return findTypeByName(name); } return doFindTypeByName(name); }
@Override protected List<JvmType> doVisitSynonymTypeReference(CompoundTypeReference reference, ResourceSet resourceSet) { List<LightweightTypeReference> components = reference.getMultiTypeComponents(); if (components.isEmpty()) throw new IllegalStateException("Components may not be empty"); return components.get(components.size() - 1).accept(this, resourceSet); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setSubtypeReference(JvmType newSubtypeReference) { JvmType oldSubtypeReference = subtypeReference; subtypeReference = newSubtypeReference; if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, ContentAssistTestLanguagePackage.REFERENCE_HOLDER__SUBTYPE_REFERENCE, oldSubtypeReference, subtypeReference)); }
@Test public void testFields_protectedString_01() { String typeName = Fields.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmField field = getFieldFromType(type, Fields.class, "protectedString"); assertSame(type, field.getDeclaringType()); assertEquals(JvmVisibility.PROTECTED, field.getVisibility()); JvmType fieldType = field.getType().getType(); assertEquals("java.lang.String", fieldType.getIdentifier()); }
@Override protected List<JvmType> doVisitParameterizedTypeReference(ParameterizedTypeReference reference, ResourceSet resourceSet) { JvmType type = reference.getType(); if (!type.eIsProxy()) { if (type instanceof JvmTypeParameter) { return getRawTypesFromConstraints(reference.getOwner(), (JvmTypeParameter) type, resourceSet); } return Collections.singletonList(type); } return Collections.emptyList(); }
private boolean isProcedure() { JvmTypeReference returnType = getReturnType(); if (returnType == null) return true; JvmType type = returnType.getType(); if (type == null) return false; if (type.eIsProxy()) return false; if (type instanceof JvmVoid) return true; return false; }