本文整理汇总了Java中org.eclipse.xtext.common.types.JvmTypeParameter.getConstraints方法的典型用法代码示例。如果您正苦于以下问题:Java JvmTypeParameter.getConstraints方法的具体用法?Java JvmTypeParameter.getConstraints怎么用?Java JvmTypeParameter.getConstraints使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.xtext.common.types.JvmTypeParameter
的用法示例。
在下文中一共展示了JvmTypeParameter.getConstraints方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doCheckTypeParameterForwardReference
import org.eclipse.xtext.common.types.JvmTypeParameter; //导入方法依赖的package包/类
/**
* Java 5 does not allow forward references in type parameters, so we have to validate this, too
*/
public void doCheckTypeParameterForwardReference(List<JvmTypeParameter> sourceTypeParameters) {
if (sourceTypeParameters.size() >= 1) {
final Set<JvmTypeParameter> allowed = newHashSet();
for(int i = 0; i < sourceTypeParameters.size(); i++) {
JvmTypeParameter current = sourceTypeParameters.get(i);
for(JvmTypeConstraint constraint: current.getConstraints()) {
JvmTypeReference constraintRef = constraint.getTypeReference();
if (constraintRef != null) {
JvmType constraintType = constraintRef.getType();
if (constraintType.eClass() == TypesPackage.Literals.JVM_TYPE_PARAMETER) {
EObject sourceElement = associations.getPrimarySourceElement(constraintType);
if (sourceElement!=null && sourceElement.eContainer() == current.eContainer() && !allowed.contains(sourceElement)) {
error("Illegal forward reference to type parameter " + ((JvmTypeParameter)constraintType).getSimpleName(),
constraintRef, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, -1, TYPE_PARAMETER_FORWARD_REFERENCE);
}
}
}
}
allowed.add(current);
}
}
}
示例2: getRawTypesFromConstraints
import org.eclipse.xtext.common.types.JvmTypeParameter; //导入方法依赖的package包/类
protected List<JvmType> getRawTypesFromConstraints(ITypeReferenceOwner owner, JvmTypeParameter typeParameter, ResourceSet resourceSet) {
if (visited.add(typeParameter)) {
List<JvmTypeConstraint> constraints = typeParameter.getConstraints();
if (!constraints.isEmpty()) {
List<JvmType> result = Lists.newArrayList();
for(JvmTypeConstraint constraint: constraints) {
if (constraint instanceof JvmUpperBound && constraint.getTypeReference() != null) {
result.addAll(owner.toLightweightTypeReference(constraint.getTypeReference()).accept(this, resourceSet));
}
}
if (!result.isEmpty())
return result;
}
}
return createObjectReference(resourceSet);
}
示例3: getStricterConstraint
import org.eclipse.xtext.common.types.JvmTypeParameter; //导入方法依赖的package包/类
protected LightweightTypeReference getStricterConstraint(final UnboundTypeReference typeParameter, LightweightTypeReference hint) {
final JvmTypeParameter parameter = typeParameter.getTypeParameter();
List<JvmTypeConstraint> constraints = parameter.getConstraints();
for(JvmTypeConstraint constraint: constraints) {
JvmTypeReference constraintReference = constraint.getTypeReference();
if (constraintReference != null) {
final boolean[] recursive = new boolean[] { false };
LightweightTypeReferenceFactory factory = new LightweightTypeReferenceFactory(hint.getOwner()) {
@Override
public LightweightTypeReference doVisitParameterizedTypeReference(JvmParameterizedTypeReference reference) {
JvmType type = reference.getType();
if (type == parameter) {// recursively bound
recursive[0] = true;
}
return super.doVisitParameterizedTypeReference(reference);
}
};
LightweightTypeReference lightweightReference = factory.toLightweightReference(constraintReference);
if (!recursive[0] && hint.isAssignableFrom(lightweightReference)) {
hint = lightweightReference;
}
}
}
return hint;
}
示例4: checkTypeParameterConstraintIsValid
import org.eclipse.xtext.common.types.JvmTypeParameter; //导入方法依赖的package包/类
@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);
}
}
}
示例5: toString
import org.eclipse.xtext.common.types.JvmTypeParameter; //导入方法依赖的package包/类
public String toString(Iterable<? extends JvmTypeParameter> elements) {
StringBuilder buffer = new StringBuilder();
boolean needsSeparator = false;
for (JvmTypeParameter type : elements) {
if (needsSeparator)
buffer.append(", ");
needsSeparator = true;
if (type != null) {
buffer.append(type.getSimpleName());
List<String> upper = newArrayList();
String lower = null;
for (JvmTypeConstraint constr : type.getConstraints()) {
String simpleName = constr.getTypeReference().getSimpleName();
if (constr instanceof JvmUpperBound) {
upper.add(simpleName);
} else {
lower = simpleName;
}
}
if(!upper.isEmpty()) {
buffer.append(" extends ");
buffer.append(Strings.concat(" & ", upper));
}
if(lower!=null) {
buffer.append(" super ");
buffer.append(lower);
}
} else
buffer.append("[null]");
}
return buffer.toString();
}
示例6: initializeConstraintMapping
import org.eclipse.xtext.common.types.JvmTypeParameter; //导入方法依赖的package包/类
protected void initializeConstraintMapping(JvmTypeParameter typeParameter, UnboundTypeParameterPreservingSubstitutor substitutor, UnboundTypeReference typeReference) {
if (!typeReference.internalIsResolved()) {
List<JvmTypeConstraint> constraints = typeParameter.getConstraints();
for(JvmTypeConstraint constraint: constraints) {
JvmTypeReference constraintReference = constraint.getTypeReference();
if (constraintReference != null) {
LightweightTypeReference substitute = substitutor.substitute(constraintReference);
if (!substitute.isType(Object.class) && !substitute.isPrimitiveVoid()) {
typeReference.acceptHint(substitute, BoundTypeArgumentSource.CONSTRAINT, constraint, VarianceInfo.OUT, VarianceInfo.OUT);
}
}
}
}
}
示例7: isRawType
import org.eclipse.xtext.common.types.JvmTypeParameter; //导入方法依赖的package包/类
private boolean isRawType(JvmTypeParameter current, RecursionGuard<JvmTypeParameter> guard) {
if (guard.tryNext(current)) {
List<JvmTypeConstraint> constraints = current.getConstraints();
for(int i = 0, size = constraints.size(); i < size; i++) {
JvmTypeConstraint constraint = constraints.get(i);
if (constraint.eClass() == TypesPackage.Literals.JVM_UPPER_BOUND && constraint.getTypeReference() != null) {
JvmTypeReference superType = constraint.getTypeReference();
JvmType rawSuperType = superType.getType();
if (rawSuperType != null) {
if (rawSuperType.eClass() == TypesPackage.Literals.JVM_TYPE_PARAMETER) {
if (isRawType((JvmTypeParameter) rawSuperType, guard)) {
return true;
}
}
if (rawSuperType.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) {
if (!((JvmGenericType) rawSuperType).getTypeParameters().isEmpty()) {
if (superType.eClass() == TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE) {
JvmParameterizedTypeReference casted = (JvmParameterizedTypeReference) superType;
if (casted.getArguments().isEmpty()) {
return true;
}
}
}
}
}
}
}
}
return false;
}
示例8: getPrimitiveKind
import org.eclipse.xtext.common.types.JvmTypeParameter; //导入方法依赖的package包/类
private Primitive getPrimitiveKind(JvmTypeParameter type, /* @Nullable */ RecursionGuard<JvmTypeParameter> guard) {
if (type.eIsProxy())
return null;
for(JvmTypeConstraint constraint: type.getConstraints()) {
if (constraint.eClass() == TypesPackage.Literals.JVM_UPPER_BOUND) {
JvmTypeReference upperBound = constraint.getTypeReference();
if (upperBound != null) {
JvmType upperBoundType = upperBound.getType();
if (upperBoundType.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) {
return getPrimitiveKind((JvmGenericType) upperBoundType);
}
if (type == upperBoundType) {
return null;
}
// guard against recursive deps
if (upperBoundType.eClass() == TypesPackage.Literals.JVM_TYPE_PARAMETER) {
JvmTypeParameter upperBoundTypeParameter = (JvmTypeParameter) upperBoundType;
if (guard == null) {
guard = new RecursionGuard<JvmTypeParameter>();
guard.tryNext(type);
}
if (guard.tryNext(upperBoundTypeParameter)) {
return getPrimitiveKind(upperBoundTypeParameter, guard);
}
return null;
}
}
}
}
return null;
}
示例9: isWrapper
import org.eclipse.xtext.common.types.JvmTypeParameter; //导入方法依赖的package包/类
private boolean isWrapper(JvmTypeParameter typeParameter, /* @Nullable */ RecursionGuard<JvmTypeParameter> stack) {
for(JvmTypeConstraint constraint: typeParameter.getConstraints()) {
if (constraint.eClass() == TypesPackage.Literals.JVM_UPPER_BOUND) {
JvmTypeReference upperBound = constraint.getTypeReference();
if (upperBound != null) {
JvmType upperBoundType = upperBound.getType();
if (upperBoundType == null) {
return false;
}
if (upperBoundType.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) {
return isWrapper((JvmGenericType)upperBoundType);
}
// guard against recursive deps
if (upperBoundType.eClass() == TypesPackage.Literals.JVM_TYPE_PARAMETER) {
if (typeParameter == upperBoundType || stack != null && !stack.tryNext((JvmTypeParameter) upperBoundType)) {
return false;
}
if (stack == null) {
stack = new RecursionGuard<JvmTypeParameter>();
stack.tryNext(typeParameter);
stack.tryNext((JvmTypeParameter) upperBoundType);
}
return isWrapper((JvmTypeParameter) upperBoundType, stack);
}
}
}
}
return false;
}
示例10: getResolvedTypeParameterConstraints
import org.eclipse.xtext.common.types.JvmTypeParameter; //导入方法依赖的package包/类
@Override
public List<LightweightTypeReference> getResolvedTypeParameterConstraints(int idx) throws IndexOutOfBoundsException {
JvmTypeParameter typeParameter = getResolvedTypeParameters().get(idx);
List<JvmTypeConstraint> constraints = typeParameter.getConstraints();
List<JvmTypeReference> constraintReferences = Lists.newArrayListWithCapacity(constraints.size());
for(JvmTypeConstraint constraint: constraints) {
constraintReferences.add(constraint.getTypeReference());
}
List<LightweightTypeReference> result = getResolvedReferences(constraintReferences);
return result;
}
示例11: _format
import org.eclipse.xtext.common.types.JvmTypeParameter; //导入方法依赖的package包/类
protected void _format(final JvmTypeParameter ref, @Extension final IFormattableDocument document) {
EList<JvmTypeConstraint> _constraints = ref.getConstraints();
for (final JvmTypeConstraint c : _constraints) {
{
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
document.<JvmTypeConstraint>prepend(c, _function);
document.<JvmTypeConstraint>format(c);
}
}
}
示例12: _format
import org.eclipse.xtext.common.types.JvmTypeParameter; //导入方法依赖的package包/类
protected void _format(final JvmTypeParameter ref, final FormattableDocument document) {
EList<JvmTypeConstraint> _constraints = ref.getConstraints();
for (final JvmTypeConstraint c : _constraints) {
{
final Procedure1<FormattingDataInit> _function = (FormattingDataInit it) -> {
it.oneSpace();
};
Function1<? super FormattableDocument, ? extends Iterable<FormattingData>> _prepend = this._formattingDataFactory.prepend(this._nodeModelAccess.nodeForEObject(c), _function);
document.operator_add(_prepend);
this.format(c, document);
}
}
}
示例13: createTypeParameter
import org.eclipse.xtext.common.types.JvmTypeParameter; //导入方法依赖的package包/类
protected JvmTypeParameter createTypeParameter(TypeVariable<?> variable, JvmMember container) {
JvmTypeParameter result = TypesFactory.eINSTANCE.createJvmTypeParameter();
result.setName(variable.getName());
Type[] bounds = variable.getBounds();
if (bounds.length != 0) {
InternalEList<JvmTypeConstraint> constraints = (InternalEList<JvmTypeConstraint>)result.getConstraints();
for (Type bound : variable.getBounds()) {
JvmUpperBound upperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
((JvmTypeConstraintImplCustom) upperBound).internalSetTypeReference(createTypeReference(bound));
constraints.addUnique(upperBound);
}
}
return result;
}