@Test public void test_ParameterizedTypes_Inner_05() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodV = getMethodFromType(type, ParameterizedTypes.Inner.class, "methodVArray_01()"); JvmTypeReference listT = methodV.getReturnType(); assertEquals("java.util.List<? extends V>[]", listT.getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) ((JvmGenericArrayTypeReference) listT) .getComponentType(); 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); JvmTypeParameter v = type.getTypeParameters().get(3); assertSame(v, upperBound.getTypeReference().getType()); }
@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 String parametersToString(Iterable<? extends JvmFormalParameter> elements, boolean isVarArgs, boolean includeName) { StringBuilder result = new StringBuilder(); boolean needsSeparator = false; Iterator<? extends JvmFormalParameter> iterator = elements.iterator(); while (iterator.hasNext()) { JvmFormalParameter parameter = iterator.next(); if (needsSeparator) result.append(", "); needsSeparator = true; JvmTypeReference typeRef = parameter.getParameterType(); if (isVarArgs && !iterator.hasNext() && typeRef instanceof JvmGenericArrayTypeReference) { typeRef = ((JvmGenericArrayTypeReference) typeRef).getComponentType(); result.append(referenceToString(typeRef, "[null]")); result.append("..."); } else { result.append(referenceToString(typeRef, "[null]")); } if (includeName) { result.append(" " + parameter.getName()); } } return result.toString(); }
public void generateParameter(final JvmFormalParameter it, final ITreeAppendable appendable, final boolean vararg, final GeneratorConfig config) { final ITreeAppendable tracedAppendable = appendable.trace(it); this.generateAnnotations(it.getAnnotations(), tracedAppendable, false, config); tracedAppendable.append("final "); if (vararg) { JvmTypeReference _parameterType = it.getParameterType(); boolean _not = (!(_parameterType instanceof JvmGenericArrayTypeReference)); if (_not) { tracedAppendable.append("/* Internal Error: Parameter was vararg but not an array type. */"); } else { JvmTypeReference _parameterType_1 = it.getParameterType(); this._errorSafeExtensions.serializeSafely(((JvmGenericArrayTypeReference) _parameterType_1).getComponentType(), "Object", tracedAppendable); } tracedAppendable.append("..."); } else { this._errorSafeExtensions.serializeSafely(it.getParameterType(), "Object", tracedAppendable); } tracedAppendable.append(" "); final String name = tracedAppendable.declareVariable(it, this.makeJavaIdentifier(it.getSimpleName())); this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(name); }
protected JvmTypeReference toTypeReference(final JvmType type, final int arrayDimensions) { if ((type == null)) { return null; } JvmParameterizedTypeReference _createJvmParameterizedTypeReference = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference(); final Procedure1<JvmParameterizedTypeReference> _function = (JvmParameterizedTypeReference it) -> { it.setType(type); }; JvmTypeReference resultTypeRef = ObjectExtensions.<JvmParameterizedTypeReference>operator_doubleArrow(_createJvmParameterizedTypeReference, _function); ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, arrayDimensions, true); for (final Integer i : _doubleDotLessThan) { { final JvmGenericArrayTypeReference arrayRef = TypesFactory.eINSTANCE.createJvmGenericArrayTypeReference(); arrayRef.setComponentType(resultTypeRef); resultTypeRef = arrayRef; } } return resultTypeRef; }
@Override public String getFragment(EObject obj, IFragmentProvider.Fallback fallback) { if (obj instanceof JvmTypeParameter) return getFragment(obj.eContainer(), fallback) + "/" + ((JvmTypeParameter) obj).getName(); if (obj instanceof JvmTypeReference || obj instanceof JvmFormalParameter) return fallback.getFragment(obj); if (obj instanceof JvmIdentifiableElement) { if (obj instanceof JvmArrayType) { if (obj.eContainer() instanceof JvmGenericArrayTypeReference) return fallback.getFragment(obj); if (obj.eContainer() instanceof JvmIdentifiableElement) { return getFragment(obj.eContainer(), fallback) + "[]"; } } return ((JvmIdentifiableElement) obj).getIdentifier(); } return fallback.getFragment(obj); }
/** * Contexts: * JvmTypeReference returns JvmGenericArrayTypeReference * JvmTypeReference.JvmGenericArrayTypeReference_0_1_0_0 returns JvmGenericArrayTypeReference * JvmArgumentTypeReference returns JvmGenericArrayTypeReference * * Constraint: * componentType=JvmTypeReference_JvmGenericArrayTypeReference_0_1_0_0 */ protected void sequence_JvmTypeReference(ISerializationContext context, JvmGenericArrayTypeReference semanticObject) { if (errorAcceptor != null) { if (transientValues.isValueTransient(semanticObject, TypesPackage.Literals.JVM_GENERIC_ARRAY_TYPE_REFERENCE__COMPONENT_TYPE) == ValueTransient.YES) errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, TypesPackage.Literals.JVM_GENERIC_ARRAY_TYPE_REFERENCE__COMPONENT_TYPE)); } SequenceFeeder feeder = createSequencerFeeder(context, semanticObject); feeder.accept(grammarAccess.getJvmTypeReferenceAccess().getJvmGenericArrayTypeReferenceComponentTypeAction_0_1_0_0(), semanticObject.getComponentType()); feeder.finish(); }
@Test public void test_arrayWildcard_02() { JvmOperation arrayWildcard = getMethodFromParameterizedMethods("arrayWildcard(java.util.List[])"); JvmTypeReference paramType = arrayWildcard.getParameters().get(0).getParameterType(); assertEquals("java.util.List<? extends java.lang.Object>[]", paramType.getIdentifier()); assertTrue(paramType.getType() instanceof JvmArrayType); JvmArrayType arrayType = (JvmArrayType) paramType.getType(); assertTrue(arrayType.getComponentType() instanceof JvmDeclaredType); assertTrue(paramType instanceof JvmGenericArrayTypeReference); assertTrue( ((JvmGenericArrayTypeReference) paramType).getComponentType() instanceof JvmParameterizedTypeReference); }
@Test public void test_arrayParameterized_02() { JvmOperation arrayParameterized = getMethodFromParameterizedMethods("arrayParameterized(java.util.List[])"); JvmTypeReference paramType = arrayParameterized.getParameters().get(0).getParameterType(); assertEquals("java.util.List<T>[]", paramType.getIdentifier()); assertTrue(paramType.getType() instanceof JvmArrayType); JvmArrayType arrayType = (JvmArrayType) paramType.getType(); assertTrue(arrayType.getComponentType() instanceof JvmDeclaredType); assertTrue(paramType instanceof JvmGenericArrayTypeReference); assertTrue( ((JvmGenericArrayTypeReference) paramType).getComponentType() instanceof JvmParameterizedTypeReference); }
@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 testVarArgs_03() { String typeName = ClassWithVarArgs.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmConstructor constructor = getConstructorFromType(type, ClassWithVarArgs.class, "ClassWithVarArgs(int,java.lang.String[])"); assertTrue(constructor.isVarArgs()); assertEquals(2, constructor.getParameters().size()); assertTrue(constructor.getParameters().get(0).getParameterType() instanceof JvmParameterizedTypeReference); assertTrue(constructor.getParameters().get(1).getParameterType() instanceof JvmGenericArrayTypeReference); }
@Check public void checkTypeParameterConstraintIsValid(JvmTypeParameter typeParameter) { if(!typeParameter.getConstraints().isEmpty()) { for(JvmTypeConstraint constraint: typeParameter.getConstraints()) { JvmTypeReference typeReference = constraint.getTypeReference(); if(typeReference instanceof JvmGenericArrayTypeReference) error(String.format("The array type %s cannot be used as a type parameter bound", typeReference.getSimpleName()), typeReference, null, INVALID_TYPE_PARAMETER_BOUNDS); else if (typeReference.getType() instanceof JvmTypeParameter && typeParameter.getConstraints().size() > 1) error(String.format("The type parameter %s cannot be used as a type parameter bound with additional bounds", typeReference.getSimpleName()), typeReference, null, INVALID_TYPE_PARAMETER_BOUNDS); } } }
@Override public StringBuilder doVisitGenericArrayTypeReference(JvmGenericArrayTypeReference reference, StringBuilder param) { param = visit(reference.getComponentType(), param); if (param != null) { param.append("[]"); } return param; }
@Override public LightweightTypeReference doVisitGenericArrayTypeReference(JvmGenericArrayTypeReference reference) { JvmTypeReference originalComponentType = reference.getComponentType(); LightweightTypeReference lightweightComponentType = null; if (originalComponentType != null) { lightweightComponentType = visit(originalComponentType); if (lightweightComponentType.isAny()) return lightweightComponentType; } else { lightweightComponentType = getObjectReference(); } return owner.newArrayTypeReference(lightweightComponentType); }
protected void acceptType(JvmTypeReference ref) { if (ref instanceof XFunctionTypeRef || ref instanceof JvmWildcardTypeReference || ref instanceof JvmGenericArrayTypeReference || (ref.eContainer() instanceof XFunctionTypeRef && ref.eContainmentFeature() == JVM_SPECIALIZED_TYPE_REFERENCE__EQUIVALENT) || NodeModelUtils.findActualNodeFor(ref) == null) return; else acceptPreferredType(ref); }
protected void appendParameters(final StringBuilder result, final JvmExecutable executable, final int insignificantParameters, final LightweightTypeReferenceFactory ownedConverter) { final EList<JvmFormalParameter> declaredParameters = executable.getParameters(); final List<JvmFormalParameter> relevantParameters = declaredParameters.subList(Math.min(insignificantParameters, declaredParameters.size()), declaredParameters.size()); for (int i = 0; (i < relevantParameters.size()); i++) { { final JvmFormalParameter parameter = relevantParameters.get(i); if ((i != 0)) { result.append(", "); } if ((((i == (relevantParameters.size() - 1)) && executable.isVarArgs()) && (parameter.getParameterType() instanceof JvmGenericArrayTypeReference))) { JvmTypeReference _parameterType = parameter.getParameterType(); final JvmGenericArrayTypeReference parameterType = ((JvmGenericArrayTypeReference) _parameterType); result.append(ownedConverter.toLightweightReference(parameterType.getComponentType()).getHumanReadableName()); result.append("..."); } else { JvmTypeReference _parameterType_1 = parameter.getParameterType(); boolean _tripleNotEquals = (_parameterType_1 != null); if (_tripleNotEquals) { final String simpleName = ownedConverter.toLightweightReference(parameter.getParameterType()).getHumanReadableName(); if ((simpleName != null)) { result.append(simpleName); } } } result.append(" "); result.append(String.valueOf(parameter.getName())); } } }
protected JvmTypeReference createLocalArrayTypeReference(Type componentType, JvmTypeParameterDeclarator container, GenericDeclaration member) { JvmTypeReference componentTypeReference = createLocalTypeReference(componentType, container, member); JvmGenericArrayTypeReference result = TypesFactory.eINSTANCE.createJvmGenericArrayTypeReference(); result.setComponentType(componentTypeReference); return result; }
@Override public List<JvmType> doVisitGenericArrayTypeReference(JvmGenericArrayTypeReference reference, Resource resource) { JvmTypeReference componentType = reference.getComponentType(); List<JvmType> rawComponentTypes = visit(componentType, resource); List<JvmType> result = Lists.newArrayListWithCapacity(rawComponentTypes.size()); for (JvmType rawComponentType : rawComponentTypes) { if (!rawComponentType.eIsProxy() && rawComponentType instanceof JvmComponentType) { JvmArrayType arrayType = ((JvmComponentType) rawComponentType).getArrayType(); result.add(arrayType); } } return result; }
@Override public JvmTypeReference doVisitGenericArrayTypeReference(JvmGenericArrayTypeReference reference, Resource resource) { JvmTypeReference componentType = reference.getComponentType(); JvmTypeReference rawComponentType = visit(componentType, resource); if (componentType != rawComponentType) { JvmGenericArrayTypeReference result = factory.createJvmGenericArrayTypeReference(); result.setComponentType(rawComponentType); return result; } return reference; }
@Override public JvmTypeReference doVisitGenericArrayTypeReference(JvmGenericArrayTypeReference reference, Pair<Resource, Set<JvmType>> context) { JvmTypeReference componentType = reference.getComponentType(); JvmTypeReference rawComponentType = visit(componentType, context); if (componentType != rawComponentType) { JvmGenericArrayTypeReference result = factory.createJvmGenericArrayTypeReference(); result.setComponentType(rawComponentType); return result; } return reference; }
@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_JvmTypeReference(EObject context, JvmGenericArrayTypeReference semanticObject) { sequence_JvmTypeReference(createContext(context, semanticObject), semanticObject); }
@Override public JvmTypeReference toTypeReference() { JvmGenericArrayTypeReference result = getTypesFactory().createJvmGenericArrayTypeReference(); result.setComponentType(component.toTypeReference()); return result; }
@Override public JvmTypeReference toJavaCompliantTypeReference(IVisibilityHelper visibilityHelper) { JvmGenericArrayTypeReference result = getTypesFactory().createJvmGenericArrayTypeReference(); result.setComponentType(component.toJavaCompliantTypeReference(visibilityHelper)); return result; }
protected void _format(final JvmGenericArrayTypeReference array, @Extension final IFormattableDocument document) { ISemanticRegion _ruleCallTo = this.textRegionExtensions.regionFor(array).ruleCallTo(this.grammar.getArrayBracketsRule()); ArrayBracketsFormattingReplacer _arrayBracketsFormattingReplacer = new ArrayBracketsFormattingReplacer(_ruleCallTo); document.addReplacer(_arrayBracketsFormattingReplacer); document.<JvmTypeReference>format(array.getComponentType()); }
protected JvmTypeReference createArrayTypeReference(Type componentType) { JvmTypeReference componentTypeReference = createTypeReference(componentType); JvmGenericArrayTypeReference result = TypesFactory.eINSTANCE.createJvmGenericArrayTypeReference(); result.setComponentType(componentTypeReference); return result; }
@Override public Result doVisitGenericArrayTypeReference(JvmGenericArrayTypeReference reference) { return doVisitTypeReference(reference); }
public JvmGenericArrayTypeReference createArrayType(JvmTypeReference componentType) { JvmGenericArrayTypeReference result = factory.createJvmGenericArrayTypeReference(); result.setComponentType(EcoreUtil2.cloneIfContained(componentType)); return result; }
public boolean isArray(JvmTypeReference type) { if (isNullOrProxy(type)) return false; return type instanceof JvmGenericArrayTypeReference || type.getType() instanceof JvmArrayType; }
@Override public Result doVisitGenericArrayTypeReference(JvmGenericArrayTypeReference reference, Parameter param) { return doVisitTypeReference(reference, param); }