protected void createUserData(EObject eObject, ImmutableMap.Builder<String, String> userData) { if (eObject instanceof JvmDeclaredType) { userData.put(SIGNATURE_HASH_KEY, hashProvider.getHash((JvmDeclaredType) eObject)); if (eObject.eContainer() != null) { userData.put(IS_NESTED_TYPE, Boolean.TRUE.toString()); } } if (eObject instanceof JvmGenericType) { JvmGenericType genericType = (JvmGenericType) eObject; if (genericType.isInterface()) userData.put(IS_INTERFACE, Boolean.TRUE.toString()); if (!genericType.getTypeParameters().isEmpty()) { String result = "<"; for (Iterator<JvmTypeParameter> iterator = genericType.getTypeParameters().iterator(); iterator.hasNext();) { JvmTypeParameter type = iterator.next(); result += type.getSimpleName(); if (iterator.hasNext()) { result += ","; } } result +=">"; userData.put(TYPE_PARAMETERS, result); } } } }
protected boolean hasTypeParameters(JvmGenericType type) { if (!type.getTypeParameters().isEmpty()) { return true; } if (type.eContainer() instanceof JvmGenericType && !type.isStatic()) { return hasTypeParameters((JvmGenericType) type.eContainer()); } return false; }
public JvmTypeReference getArgument(JvmTypeReference left, int index) { if (left.getType() instanceof JvmGenericType) { List<JvmTypeParameter> typeParameters = ((JvmGenericType) left.getType()).getTypeParameters(); if (typeParameters.size() <= index) { throw new IllegalArgumentException("The type " + left.getType().getIdentifier() + " cannot be parameterized with more than " + typeParameters.size() + " type arguments."); } if (left instanceof JvmParameterizedTypeReference) { List<JvmTypeReference> arguments = ((JvmParameterizedTypeReference) left).getArguments(); if (arguments.size() == typeParameters.size()) { return arguments.get(index); } } final JvmTypeParameter jvmTypeParameter = typeParameters.get(index); return createTypeRef(jvmTypeParameter); } throw new IllegalArgumentException(left.getType().getIdentifier() + " is not generic."); }
public JvmTypeReference getArgument(JvmTypeReference left, int index) { if (left.getType() instanceof JvmGenericType) { List<JvmTypeParameter> typeParameters = ((JvmGenericType) left.getType()).getTypeParameters(); if (typeParameters.size() <= index) { throw new IllegalArgumentException("The type " + left.getType().getIdentifier() + " cannot be parameterized with more than " + typeParameters.size() + " type arguments."); } if (left instanceof JvmParameterizedTypeReference) { List<JvmTypeReference> arguments = ((JvmParameterizedTypeReference) left).getArguments(); if (arguments.size() == typeParameters.size()) { return arguments.get(index); } } final JvmTypeParameter jvmTypeParameter = typeParameters.get(index); return createTypeRef(jvmTypeParameter); } throw new IllegalArgumentException(left.getType().getIdentifier() + " is not generic."); }
public JvmParameterizedTypeReference createTypeRef(final JvmType type, final JvmTypeReference... typeArgs) { if ((type == null)) { throw new NullPointerException("type"); } final JvmParameterizedTypeReference reference = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference(); reference.setType(type); for (final JvmTypeReference typeArg : typeArgs) { reference.getArguments().add(EcoreUtil2.<JvmTypeReference>cloneIfContained(typeArg)); } if ((type instanceof JvmGenericType)) { final EList<JvmTypeParameter> list = ((JvmGenericType)type).getTypeParameters(); if (((!reference.getArguments().isEmpty()) && (list.size() != reference.getArguments().size()))) { String _identifier = ((JvmGenericType)type).getIdentifier(); String _plus = ("The type " + _identifier); String _plus_1 = (_plus + " expects "); int _size = list.size(); String _plus_2 = (_plus_1 + Integer.valueOf(_size)); String _plus_3 = (_plus_2 + " type arguments, but was "); int _size_1 = reference.getArguments().size(); String _plus_4 = (_plus_3 + Integer.valueOf(_size_1)); String _plus_5 = (_plus_4 + ". Either pass zero arguments (raw type) or the correct number."); throw new IllegalArgumentException(_plus_5); } } return reference; }
@Check public void checkClassPath(PatternModel modelFile) { final JvmGenericType listType = (JvmGenericType) typeReferences.findDeclaredType(List.class, modelFile); if (listType == null || listType.getTypeParameters().isEmpty()) { error("Couldn't find a JDK 1.5 or higher on the project's classpath.", modelFile, PatternLanguagePackage.Literals.PATTERN_MODEL__PACKAGE_NAME, EMFIssueCodes.JDK_NOT_ON_CLASSPATH); } else if (typeReferences.findDeclaredType(IncQueryEngine.class, modelFile) == null) { error("Couldn't find the mandatory library 'org.eclipse.incquery.runtime' on the project's classpath.", modelFile, PatternLanguagePackage.Literals.PATTERN_MODEL__PACKAGE_NAME, EMFIssueCodes.IQR_NOT_ON_CLASSPATH); } } }
@Override public Iterable<? extends TypeParameterDeclaration> getTypeParameters() { final Function1<JvmTypeParameter, TypeParameterDeclaration> _function = (JvmTypeParameter it) -> { return this.getCompilationUnit().toTypeParameterDeclaration(it); }; return ListExtensions.<JvmTypeParameter, TypeParameterDeclaration>map(this.getDelegate().getTypeParameters(), _function); }
@Override public Iterable<? extends TypeParameterDeclaration> getTypeParameters() { final Function1<JvmTypeParameter, TypeParameterDeclaration> _function = (JvmTypeParameter it) -> { return this.getCompilationUnit().toTypeParameterDeclaration(it); }; return ListExtensions.<JvmTypeParameter, TypeParameterDeclaration>map(this.getDelegate().getTypeParameters(), _function); }
protected void initClosureType(FunctionTypeReference result, boolean isProcedure) { ITypeReferenceOwner owner = result.getOwner(); TypeParameterByUnboundSubstitutor substitutor = new TypeParameterByUnboundSubstitutor(Collections.<JvmTypeParameter, LightweightMergedBoundTypeArgument>emptyMap(), owner) { @Override protected UnboundTypeReference createUnboundTypeReference(JvmTypeParameter type) { UnboundTypeReference result = getExpectation().createUnboundTypeReference(getClosure(), type); return result; } }; JvmGenericType type = (JvmGenericType) result.getType(); List<JvmTypeParameter> typeParameters = type.getTypeParameters(); int max = type.getTypeParameters().size(); if (!isProcedure) max--; for(int i = 0; i < max; i++) { JvmTypeParameter typeParameter = typeParameters.get(i); LightweightTypeReference parameterType = owner.newParameterizedTypeReference(typeParameter); LightweightTypeReference substituted = substitutor.substitute(parameterType); result.addTypeArgument(substituted); } if (!isProcedure) { JvmTypeParameter typeParameter = typeParameters.get(max); LightweightTypeReference parameterType = owner.toLightweightTypeReference(typeParameter); LightweightTypeReference substituted = substitutor.substitute(parameterType); result.addTypeArgument(substituted); } }
protected void setUnboundCollectionType(XCollectionLiteral literal, JvmGenericType collectionType, ITypeExpectation expectation, LightweightTypeReference elementTypeExpectation, ITypeComputationState state) { ParameterizedTypeReference unboundCollectionType = state.getReferenceOwner().newParameterizedTypeReference(collectionType); if (elementTypeExpectation != null) { unboundCollectionType.addTypeArgument(elementTypeExpectation); } else { UnboundTypeReference unboundTypeArgument = expectation.createUnboundTypeReference(literal, collectionType.getTypeParameters().get(0)); unboundCollectionType.addTypeArgument(unboundTypeArgument); } expectation.acceptActualType(unboundCollectionType, ConformanceFlags.UNCHECKED); }
/** * Creates a new {@link JvmTypeReference} pointing to the given class and containing the given type arguments. * * @param type * the type the reference shall point to. * @param typeArgs * type arguments * @return the newly created {@link JvmTypeReference} */ public JvmTypeReference typeRef(JvmType type, JvmTypeReference... typeArgs) { int typeParams = 0; if (type instanceof JvmGenericType) { typeParams = ((JvmGenericType) type).getTypeParameters().size(); } if (typeParams < typeArgs.length) { throw new IllegalArgumentException("The type "+type.getIdentifier()+" only declares "+typeParams+" type parameters. You passed "+typeArgs.length+"."); } LightweightTypeReference reference = typeReferenceOwner.toPlainTypeReference(type); for (JvmTypeReference jvmTypeReference : typeArgs) { ((ParameterizedTypeReference)reference).addTypeArgument(typeReferenceOwner.toLightweightTypeReference(jvmTypeReference)); } return reference.toJavaCompliantTypeReference(); }
@Check public void checkClassPath(XtendFile xtendFile) { TypeReferences typeReferences = getServices().getTypeReferences(); final JvmGenericType listType = (JvmGenericType) typeReferences.findDeclaredType(List.class, xtendFile); if (listType == null || listType.getTypeParameters().isEmpty()) { error("Couldn't find a JDK 1.5 or higher on the project's classpath.", xtendFile, XTEND_FILE__PACKAGE, IssueCodes.JDK_NOT_ON_CLASSPATH); } else if (typeReferences.findDeclaredType(ToStringBuilder.class, xtendFile) == null) { error("Couldn't find the mandatory library 'org.eclipse.xtext.xbase.lib' 2.8.0 or higher on the project's classpath.", xtendFile, XTEND_FILE__PACKAGE, IssueCodes.XBASE_LIB_NOT_ON_CLASSPATH); } }
JvmParameterizedTypeReference candidate = (JvmParameterizedTypeReference) next; JvmType type = candidate.getType(); if (type instanceof JvmGenericType && !((JvmGenericType) type).getTypeParameters().isEmpty()) { if (candidate.getArguments().isEmpty()) { StringBuilder message = new StringBuilder(messagePrefix);
@Check public void checkTypeArgsAgainstTypeParameters(JvmParameterizedTypeReference typeRef) { JvmType type = typeRef.getType(); if(type instanceof JvmGenericType && !type.eIsProxy()) { int numTypeParameters = ((JvmGenericType) type).getTypeParameters().size(); if(typeRef.getArguments().size() > 0) { if (numTypeParameters == 0) { errorTypeIsNotGeneric(type, typeRef); } else if(numTypeParameters != typeRef.getArguments().size()) { StringBuilder message = new StringBuilder(64); message.append("Incorrect number of arguments for type "); message = proxyAwareUIStrings.appendTypeSignature(type, message); message.append("; it cannot be parameterized with arguments "); message = proxyAwareUIStrings.appendTypeArguments(typeRef, message); if (message != null) { error(message.toString(), IssueCodes.INVALID_NUMBER_OF_TYPE_ARGUMENTS, typeRef); } } } else if(numTypeParameters > 0) { warnRawType(type, typeRef); } } else if (type != null && !type.eIsProxy() && !typeRef.getArguments().isEmpty()) { errorTypeIsNotGeneric(type, typeRef); } }
if (!((JvmGenericType) rawSuperType).getTypeParameters().isEmpty()) { if (superType.eClass() == TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE) { JvmParameterizedTypeReference casted = (JvmParameterizedTypeReference) superType;
@Override public LightweightTypeReference doVisitParameterizedTypeReference(ParameterizedTypeReference reference) { DeclaratorTypeArgumentCollector typeArgumentCollector = new ConstraintAwareTypeArgumentCollector(owner); Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> typeParameterMapping = typeArgumentCollector.getTypeParameterMapping(reference); TypeParameterSubstitutor<?> substitutor = new UnboundTypeParameterPreservingSubstitutor(typeParameterMapping, owner); JvmGenericType iterable = (JvmGenericType) owner.getServices().getTypeReferences().findDeclaredType(Iterable.class, owner.getContextResourceSet()); if (iterable == null) { return owner.newReferenceToObject(); } LightweightTypeReference substituteMe = owner.newParameterizedTypeReference(iterable.getTypeParameters().get(0)); LightweightTypeReference substitutedArgument = substitutor.substitute(substituteMe).getUpperBoundSubstitute(); if (substitutedArgument.getType() instanceof JvmTypeParameter && !(owner.getDeclaredTypeParameters().contains(substitutedArgument.getType()))) { return substitutedArgument.getRawTypeReference(); } return substitutedArgument; }
@Override public MutableTypeParameterDeclaration addTypeParameter(final String name, final TypeReference... upperBounds) { this.checkMutable(); ConditionUtils.checkJavaIdentifier(name, "name"); ConditionUtils.checkIterable(((Iterable<?>)Conversions.doWrapArray(upperBounds)), "upperBounds"); ConditionUtils.checkInferredTypeReferences("parameter type", upperBounds); final JvmTypeParameter param = TypesFactory.eINSTANCE.createJvmTypeParameter(); param.setName(name); this.getDelegate().getTypeParameters().add(param); for (final TypeReference upper : upperBounds) { { final JvmTypeReference typeRef = this.getCompilationUnit().toJvmTypeReference(upper); final JvmUpperBound jvmUpperBound = TypesFactory.eINSTANCE.createJvmUpperBound(); jvmUpperBound.setTypeReference(typeRef); param.getConstraints().add(jvmUpperBound); } } TypeParameterDeclaration _typeParameterDeclaration = this.getCompilationUnit().toTypeParameterDeclaration(param); return ((MutableTypeParameterDeclaration) _typeParameterDeclaration); } }
@Override public MutableTypeParameterDeclaration addTypeParameter(final String name, final TypeReference... upperBounds) { this.checkMutable(); ConditionUtils.checkJavaIdentifier(name, "name"); ConditionUtils.checkIterable(((Iterable<?>)Conversions.doWrapArray(upperBounds)), "upperBounds"); ConditionUtils.checkInferredTypeReferences("parameter type", upperBounds); final JvmTypeParameter param = TypesFactory.eINSTANCE.createJvmTypeParameter(); param.setName(name); this.getDelegate().getTypeParameters().add(param); for (final TypeReference upper : upperBounds) { { final JvmTypeReference typeRef = this.getCompilationUnit().toJvmTypeReference(upper); final JvmUpperBound jvmUpperBound = TypesFactory.eINSTANCE.createJvmUpperBound(); jvmUpperBound.setTypeReference(typeRef); param.getConstraints().add(jvmUpperBound); } } TypeParameterDeclaration _typeParameterDeclaration = this.getCompilationUnit().toTypeParameterDeclaration(param); return ((MutableTypeParameterDeclaration) _typeParameterDeclaration); } }
if (element instanceof JvmGenericType) { _matched_1=true; EList<JvmTypeParameter> _typeParameters = ((JvmGenericType)element).getTypeParameters(); for (final JvmTypeParameter child_1 : _typeParameters) { this.unloadRecursively(child_1);
protected ITreeAppendable _generateBody(final JvmGenericType it, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { this.generateJavaDoc(it, appendable, config); final ITreeAppendable childAppendable = appendable.trace(it); this.generateAnnotations(it.getAnnotations(), childAppendable, true, config); this.generateModifier(it, childAppendable, config); boolean _isInterface = it.isInterface(); if (_isInterface) { childAppendable.append("interface "); } else { childAppendable.append("class "); } this._treeAppendableUtil.traceSignificant(childAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName())); this.generateTypeParameterDeclaration(it, childAppendable, config); boolean _isEmpty = it.getTypeParameters().isEmpty(); if (_isEmpty) { childAppendable.append(" "); } this.generateExtendsClause(it, childAppendable, config); this.generateMembersInBody(it, childAppendable, config); ITreeAppendable _xifexpression = null; if (((!it.isAnonymous()) && (!(it.eContainer() instanceof JvmType)))) { _xifexpression = appendable.newLine(); } _xblockexpression = _xifexpression; } return _xblockexpression; }