@Override public LightweightTypeReference doVisitInnerTypeReference(JvmInnerTypeReference reference) { JvmType type = getType(reference); if (type == null || type.eIsProxy()) { return createUnknownTypeReference(reference); } if (!isInner(type)) { return doVisitParameterizedTypeReference(reference); } JvmParameterizedTypeReference outer = reference.getOuter(); if (outer == null) return doVisitParameterizedTypeReference(reference); ParameterizedTypeReference lightweightOuter = (ParameterizedTypeReference) outer.accept(this); // constructor call instead of owner.newParameterized to avoid second check for isInner(..) InnerTypeReference result = new InnerTypeReference(owner, lightweightOuter, type); for(JvmTypeReference argument: reference.getArguments()) { result.addTypeArgument(visit(argument).getWrapperTypeIfPrimitive()); } return result; }
@Override public LightweightTypeReference doVisitFunctionTypeReference(XFunctionTypeRef reference) { JvmTypeReference equivalent = reference.getEquivalent(); if (equivalent == null) { return super.doVisitFunctionTypeReference(reference); } FunctionTypeReference result; // constructors used below to avoid subsequent checks for isInner which was supposed to be done by // the computation of the equivalent if (equivalent.eClass() == TypesPackage.Literals.JVM_INNER_TYPE_REFERENCE) { JvmParameterizedTypeReference outer = ((JvmInnerTypeReference) equivalent).getOuter(); LightweightTypeReference outerEquivalent = outer.accept(this); result = new InnerFunctionTypeReference(owner, outerEquivalent, reference.getType()); } else { result = new FunctionTypeReference(owner, reference.getType()); } if (equivalent instanceof JvmParameterizedTypeReference) { for(JvmTypeReference argument: ((JvmParameterizedTypeReference)equivalent).getArguments()) { result.addTypeArgument(visit(argument)); } } for(JvmTypeReference parameter: reference.getParamTypes()) { result.addParameterType(visit(parameter)); } if (reference.getReturnType() != null) { result.setReturnType(visit(reference.getReturnType())); } return result; }
public IScope createTypeScope(EObject context, EReference reference) { if (context.eClass() == TypesPackage.Literals.JVM_INNER_TYPE_REFERENCE) { JvmInnerTypeReference casted = (JvmInnerTypeReference) context; JvmParameterizedTypeReference outerType = casted.getOuter(); JvmType outerRawType = outerType.getType(); if (outerRawType instanceof JvmDeclaredType) { Iterable<JvmDeclaredType> nestedTypes = ((JvmDeclaredType) outerRawType).getAllNestedTypes(); List<IEObjectDescription> descriptions = Lists.newArrayList(); for(JvmDeclaredType nestedType: nestedTypes) { descriptions.add(EObjectDescription.create(nestedType.getSimpleName(), nestedType)); } return new SimpleScope(descriptions); } return IScope.NULLSCOPE; } else { final IScope delegateScope = getDelegate().getScope(context, reference); return delegateScope; } }
private static void computeFor(JvmParameterizedTypeReference typeReference, char innerClassDelimiter, NameType nameType, StringBuilder result) { if (typeReference.eClass() == TypesPackage.Literals.JVM_INNER_TYPE_REFERENCE) { JvmParameterizedTypeReference outer = ((JvmInnerTypeReference) typeReference).getOuter(); if (outer != null) { computeFor(outer, innerClassDelimiter, nameType, result); if (result.length() != 0) { JvmType type = typeReference.getType(); result.append(innerClassDelimiter); result.append(type.getSimpleName()); } else { appendType(typeReference, innerClassDelimiter, nameType, result); } } else { appendType(typeReference, innerClassDelimiter, nameType, result); } } else { appendType(typeReference, innerClassDelimiter, nameType, result); } if (typeReference.eIsSet(TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__ARGUMENTS)) { result.append("<"); appendArguments(result, typeReference.getArguments(), innerClassDelimiter, nameType); result.append(">"); } }
@Test public void test_ParameterizedTypes_inner_param_01() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation operation = getMethodFromType(type, ParameterizedTypes.class, "plainInner(org.eclipse.xtext.common.types.testSetups.ParameterizedTypes$Inner)"); JvmTypeReference parameterType = operation.getParameters().get(0).getParameterType(); assertTrue(parameterType.getIdentifier(), parameterType instanceof JvmInnerTypeReference); assertEquals("ParameterizedTypes<S, T, U, V, W>$Inner<W, List<W>, List<W>>", parameterType.getSimpleName()); }
@Test public void test_ParameterizedTypes_inner_return_01() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation operation = getMethodFromType(type, ParameterizedTypes.class, "plainInner(org.eclipse.xtext.common.types.testSetups.ParameterizedTypes$Inner)"); JvmTypeReference returnType = operation.getReturnType(); assertTrue(returnType.getIdentifier(), returnType instanceof JvmInnerTypeReference); assertEquals("ParameterizedTypes<S, T, U, V, W>$Inner<W, List<W>, List<W>>", returnType.getSimpleName()); }
@Test public void test_ParameterizedTypes_inner_return_02() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation operation = getMethodFromType(type, ParameterizedTypes.class, "concreteInner()"); JvmTypeReference returnType = operation.getReturnType(); assertTrue(returnType.getIdentifier(), returnType instanceof JvmInnerTypeReference); assertEquals( "ParameterizedTypes<String, String, List<String>, V, String>$Inner<String, List<String>, List<String>>", returnType.getSimpleName()); }
@Test public void test_ParameterizedTypes2_inner_return_01() { String typeName = ParameterizedTypes2.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation operation = getMethodFromType(type, ParameterizedTypes2.class, "plainInner()"); JvmTypeReference returnType = operation.getReturnType(); assertTrue(returnType.getIdentifier(), returnType instanceof JvmInnerTypeReference); assertEquals("ParameterizedTypes2<P>$Inner<String>", returnType.getSimpleName()); }
@Test public void test_ParameterizedTypes2_inner_return_02() { String typeName = ParameterizedTypes2.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation operation = getMethodFromType(type, ParameterizedTypes2.class, "concreteInner()"); JvmTypeReference returnType = operation.getReturnType(); assertTrue(returnType.getIdentifier(), returnType instanceof JvmInnerTypeReference); assertEquals("ParameterizedTypes2<Number>$Inner<String>", returnType.getSimpleName()); }
@Override public StringBuilder doVisitInnerTypeReference(JvmInnerTypeReference reference, StringBuilder param) { JvmType type = reference.getType(); if (type == null || type.eIsProxy()) { return null; } param = reference.getOuter().accept(this, param); if (param == null) return null; param.append("."); return doVisitParameterizedTypeReference(reference, param); }
@Override public JvmTypeReference getEquivalentTypeReference() { JvmInnerTypeReference result = getTypesFactory().createJvmInnerTypeReference(); result.setType(getType()); result.setOuter((JvmParameterizedTypeReference) outer.toTypeReference()); for(LightweightTypeReference typeArgument: getTypeArguments()) { result.getArguments().add(typeArgument.toTypeReference()); } return result; }
@Override public JvmTypeReference toJavaCompliantTypeReference(IVisibilityHelper visibilityHelper) { if (isTypeVisible(visibilityHelper)) { JvmInnerTypeReference result = getTypesFactory().createJvmInnerTypeReference(); result.setType(getType()); result.setOuter((JvmParameterizedTypeReference) outer.toJavaCompliantTypeReference()); for(LightweightTypeReference typeArgument: getTypeArguments()) { result.getArguments().add(typeArgument.toJavaCompliantTypeReference()); } return result; } else { return toJavaCompliantTypeReference(getSuperTypes(), visibilityHelper); } }
@Override public JvmTypeReference toTypeReference() { JvmInnerTypeReference result = getTypesFactory().createJvmInnerTypeReference(); result.setType(getType()); result.setOuter((JvmParameterizedTypeReference) outer.toTypeReference()); for(LightweightTypeReference typeArgument: getTypeArguments()) { result.getArguments().add(typeArgument.toTypeReference()); } return result; }
@Override public void sequence(ISerializationContext context, EObject semanticObject) { EPackage epackage = semanticObject.eClass().getEPackage(); ParserRule rule = context.getParserRule(); Action action = context.getAssignedAction(); Set<Parameter> parameters = context.getEnabledBooleanParameters(); if (epackage == TypesPackage.eINSTANCE) switch (semanticObject.eClass().getClassifierID()) { case TypesPackage.JVM_GENERIC_ARRAY_TYPE_REFERENCE: sequence_JvmTypeReference(context, (JvmGenericArrayTypeReference) semanticObject); return; case TypesPackage.JVM_INNER_TYPE_REFERENCE: sequence_JvmParameterizedTypeReference(context, (JvmInnerTypeReference) semanticObject); return; case TypesPackage.JVM_LOWER_BOUND: if (rule == grammarAccess.getJvmLowerBoundAndedRule()) { sequence_JvmLowerBoundAnded(context, (JvmLowerBound) semanticObject); return; } else if (rule == grammarAccess.getJvmLowerBoundRule()) { sequence_JvmLowerBound(context, (JvmLowerBound) semanticObject); return; } else break; case TypesPackage.JVM_PARAMETERIZED_TYPE_REFERENCE: if (action == grammarAccess.getJvmParameterizedTypeReferenceAccess().getJvmInnerTypeReferenceOuterAction_1_4_0_0_0()) { sequence_JvmParameterizedTypeReference_JvmInnerTypeReference_1_4_0_0_0(context, (JvmParameterizedTypeReference) semanticObject); return; } else if (rule == grammarAccess.getJvmTypeReferenceRule() || action == grammarAccess.getJvmTypeReferenceAccess().getJvmGenericArrayTypeReferenceComponentTypeAction_0_1_0_0() || rule == grammarAccess.getJvmParameterizedTypeReferenceRule() || rule == grammarAccess.getJvmArgumentTypeReferenceRule()) { sequence_JvmParameterizedTypeReference(context, (JvmParameterizedTypeReference) semanticObject); return; } else break; case TypesPackage.JVM_TYPE_PARAMETER: sequence_JvmTypeParameter(context, (JvmTypeParameter) semanticObject); return; case TypesPackage.JVM_UPPER_BOUND: if (rule == grammarAccess.getJvmUpperBoundAndedRule()) { sequence_JvmUpperBoundAnded(context, (JvmUpperBound) semanticObject); return; } else if (rule == grammarAccess.getJvmUpperBoundRule()) { sequence_JvmUpperBound(context, (JvmUpperBound) semanticObject); return; } else break; case TypesPackage.JVM_WILDCARD_TYPE_REFERENCE: sequence_JvmWildcardTypeReference(context, (JvmWildcardTypeReference) semanticObject); return; } else if (epackage == XtypePackage.eINSTANCE) switch (semanticObject.eClass().getClassifierID()) { case XtypePackage.XFUNCTION_TYPE_REF: sequence_XFunctionTypeRef(context, (XFunctionTypeRef) semanticObject); return; case XtypePackage.XIMPORT_DECLARATION: sequence_XImportDeclaration(context, (XImportDeclaration) semanticObject); return; case XtypePackage.XIMPORT_SECTION: sequence_XImportSection(context, (XImportSection) semanticObject); return; } if (errorAcceptor != null) errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context)); }
@Deprecated protected void sequence_JvmParameterizedTypeReference(EObject context, JvmInnerTypeReference semanticObject) { sequence_JvmParameterizedTypeReference(createContext(context, semanticObject), semanticObject); }
@Override public Result doVisitInnerTypeReference(JvmInnerTypeReference reference) { return doVisitParameterizedTypeReference(reference); }
/** * @return a fresh {@link JvmParameterizedTypeReference} for the given {@link JvmType} parameterized with the given * typeArgs. This method does not check whether the given type can handle the given type arguments. */ public JvmParameterizedTypeReference createTypeRef(JvmType type, JvmTypeReference... typeArgs) { if (type == null) throw new NullPointerException("type"); List<JvmTypeReference> typeReferences = Collections.emptyList(); if (typeArgs != null && typeArgs.length > 0) { typeReferences = Lists.newArrayListWithCapacity(typeArgs.length); for (int i = 0; i < typeArgs.length; i++) { JvmTypeReference jvmTypeReference = typeArgs[i]; typeReferences.add(EcoreUtil2.cloneIfContained(jvmTypeReference)); } } JvmParameterizedTypeReference reference; if (type instanceof JvmGenericType) { JvmGenericType casted = (JvmGenericType) type; List<JvmTypeParameter> list = casted.getTypeParameters(); if (!typeReferences.isEmpty() && list.size() != typeReferences.size()) { throw new IllegalArgumentException("The type " + type.getIdentifier() + " expects " + list.size() + " type arguments, but was " + typeReferences.size() + ". Either pass zero arguments (raw type) or the correct number."); } // Raw type -> create type references to type param if (typeReferences.isEmpty() && !list.isEmpty()) { typeReferences = Lists.newArrayListWithCapacity(list.size()); for (JvmTypeParameter typeParameter : list) { typeReferences.add(createTypeRef(typeParameter)); } } if (!casted.isStatic() && casted.eContainer() instanceof JvmType) { JvmParameterizedTypeReference outer = createTypeRef((JvmType)casted.eContainer()); reference = factory.createJvmInnerTypeReference(); ((JvmInnerTypeReference) reference).setOuter(outer); } else { reference = factory.createJvmParameterizedTypeReference(); } } else { reference = factory.createJvmParameterizedTypeReference(); } reference.setType(type); if (!typeReferences.isEmpty()) reference.getArguments().addAll(typeReferences); return reference; }
@Override public Result doVisitInnerTypeReference(JvmInnerTypeReference reference, Parameter param) { return doVisitParameterizedTypeReference(reference, param); }
/** * Contexts: * JvmTypeReference returns JvmInnerTypeReference * JvmTypeReference.JvmGenericArrayTypeReference_0_1_0_0 returns JvmInnerTypeReference * JvmParameterizedTypeReference returns JvmInnerTypeReference * JvmParameterizedTypeReference.JvmInnerTypeReference_1_4_0_0_0 returns JvmInnerTypeReference * JvmArgumentTypeReference returns JvmInnerTypeReference * * Constraint: * ( * outer=JvmParameterizedTypeReference_JvmInnerTypeReference_1_4_0_0_0 * type=[JvmType|ValidID] * (arguments+=JvmArgumentTypeReference arguments+=JvmArgumentTypeReference*)? * ) */ protected void sequence_JvmParameterizedTypeReference(ISerializationContext context, JvmInnerTypeReference semanticObject) { genericSequencer.createSequence(context, semanticObject); }
Result doVisitInnerTypeReference(JvmInnerTypeReference reference, Parameter param);
Result doVisitInnerTypeReference(JvmInnerTypeReference reference);