org.eclipse.xtext.xbase.typesystem.references.ArrayTypeReference Java Examples
The following examples show how to use
org.eclipse.xtext.xbase.typesystem.references.ArrayTypeReference.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SarlParameterBuilder.java From sarl with Apache License 2.0 | 6 votes |
@Override public ISourceAppender build(ISourceAppender appendable) { final ISourceAppender mAppender; if (appendable instanceof SourceAppenderWithTypeMapping) { mAppender = appendable; } else { mAppender = new SourceAppenderWithTypeMapping(appendable, this.keywords); } appendModifiers(mAppender); mAppender.append(this.keywords.protectKeyword(getName())).append(" "); //$NON-NLS-1$ mAppender.append(this.keywords.getColonKeyword()).append(" "); //$NON-NLS-1$ if (isVarArgsFlag()) { appendType(mAppender, ((ArrayTypeReference) getType()).getComponentType(), Object.class.getSimpleName()); mAppender.append(this.keywords.getWildcardAsteriskKeyword()); } else { appendType(mAppender, getType(), Object.class.getName()); final String defaultVal = getDefaultValue(); if (!Strings.isEmpty(defaultVal)) { mAppender.append(" ").append(this.keywords.getEqualsSignKeyword()); //$NON-NLS-1$ mAppender.append(" ").append(defaultVal); //$NON-NLS-1$ } } return mAppender; }
Example #2
Source File: RawTypeConformanceComputer.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected int doIsConformant(ParameterizedTypeReference left, ArrayTypeReference right, int flags) { if (left.isType(Object.class) || left.isType(Serializable.class) || left.isType(Cloneable.class)) { return flags | SUCCESS | SUBTYPE; } if ((flags & ALLOW_SYNONYMS) != 0) { // Arrays are generally assignable to List and its supertypes if (left.isType(List.class) || left.isType(Collection.class) || left.isType(Iterable.class)) { List<LightweightTypeReference> arguments = left.getTypeArguments(); if (arguments.isEmpty()) { // type argument is bound to Object return flags | SUCCESS | DEMAND_CONVERSION; } LightweightTypeReference componentType = right.getComponentType().getWrapperTypeIfPrimitive(); int result = doIsConformant(arguments.get(0).getInvariantBoundSubstitute(), componentType, flags); if ((result & SUCCESS) != 0) { return result | DEMAND_CONVERSION; } } } return flags; }
Example #3
Source File: LightweightTypeReferenceSerializerTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testFunctionType7() { FunctionTypeReference _newFunctionTypeReference = this.getOwner().newFunctionTypeReference(this.type(Procedure3.class)); final Procedure1<FunctionTypeReference> _function = (FunctionTypeReference it) -> { it.addParameterType(this.typeRef(String.class)); it.addTypeArgument(this.typeRef(String.class)); ParameterizedTypeReference _typeRef = this.typeRef(List.class); final Procedure1<ParameterizedTypeReference> _function_1 = (ParameterizedTypeReference it_1) -> { WildcardTypeReference _newWildcardTypeReference = it_1.getOwner().newWildcardTypeReference(); final Procedure1<WildcardTypeReference> _function_2 = (WildcardTypeReference it_2) -> { it_2.setLowerBound(this.typeRef(CharSequence.class)); }; WildcardTypeReference _doubleArrow = ObjectExtensions.<WildcardTypeReference>operator_doubleArrow(_newWildcardTypeReference, _function_2); it_1.addTypeArgument(_doubleArrow); }; final ParameterizedTypeReference listOfCharSequence = ObjectExtensions.<ParameterizedTypeReference>operator_doubleArrow(_typeRef, _function_1); it.addParameterType(listOfCharSequence); it.addTypeArgument(listOfCharSequence); final ArrayTypeReference arrayOfObject = it.getOwner().newArrayTypeReference(this.typeRef(Object.class)); it.addParameterType(arrayOfObject); it.addTypeArgument(arrayOfObject); }; this.assertInJava(this.assertInXtend(ObjectExtensions.<FunctionTypeReference>operator_doubleArrow(_newFunctionTypeReference, _function), "(java.lang.String, java.util.List<? super java.lang.CharSequence>, java.lang.Object[])=>void"), "org.eclipse.xtext.xbase.lib.Procedures$Procedure3<java.lang.String, java.util.List<? super java.lang.CharSequence>, java.lang.Object[]>"); }
Example #4
Source File: DeferredTypeParameterHintCollector.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override protected void doVisitArrayTypeReference(ArrayTypeReference reference, ParameterizedTypeReference declaration) { JvmType type = declaration.getType(); if (type instanceof JvmTypeParameter) { if (shouldProcess((JvmTypeParameter) type)) { JvmTypeParameter typeParameter = (JvmTypeParameter) type; processTypeParameter(typeParameter, reference); } } else { if (!declaration.isRawType() && (declaration.isType(List.class) || declaration.isType(Collection.class) || declaration.isType(Iterable.class))) { LightweightTypeReference elementType = declaration.getTypeArguments().get(0); LightweightTypeReference componentType = reference.getComponentType(); outerVisit(componentType.getInvariantBoundSubstitute(), elementType); } } }
Example #5
Source File: LightweightTypeReferenceSerializerTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testFunctionType4() { FunctionTypeReference _newFunctionTypeReference = this.getOwner().newFunctionTypeReference(this.type(Function3.class)); final Procedure1<FunctionTypeReference> _function = (FunctionTypeReference it) -> { it.setReturnType(this.typeRef(Object.class)); it.addTypeArgument(this.typeRef(Object.class)); it.addParameterType(this.typeRef(String.class)); it.addTypeArgument(this.typeRef(String.class)); ParameterizedTypeReference _typeRef = this.typeRef(List.class); final Procedure1<ParameterizedTypeReference> _function_1 = (ParameterizedTypeReference it_1) -> { WildcardTypeReference _newWildcardTypeReference = it_1.getOwner().newWildcardTypeReference(); final Procedure1<WildcardTypeReference> _function_2 = (WildcardTypeReference it_2) -> { it_2.setLowerBound(this.typeRef(CharSequence.class)); }; WildcardTypeReference _doubleArrow = ObjectExtensions.<WildcardTypeReference>operator_doubleArrow(_newWildcardTypeReference, _function_2); it_1.addTypeArgument(_doubleArrow); }; final ParameterizedTypeReference listOfCharSequence = ObjectExtensions.<ParameterizedTypeReference>operator_doubleArrow(_typeRef, _function_1); it.addParameterType(listOfCharSequence); it.addTypeArgument(listOfCharSequence); final ArrayTypeReference arrayOfObject = it.getOwner().newArrayTypeReference(this.typeRef(Object.class)); it.addParameterType(arrayOfObject); it.addTypeArgument(arrayOfObject); }; this.assertInJava(this.assertInXtend(ObjectExtensions.<FunctionTypeReference>operator_doubleArrow(_newFunctionTypeReference, _function), "(java.lang.String, java.util.List<? super java.lang.CharSequence>, java.lang.Object[])=>java.lang.Object"), "org.eclipse.xtext.xbase.lib.Functions$Function3<java.lang.Object, java.lang.String, java.util.List<? super java.lang.CharSequence>, java.lang.Object[]>"); }
Example #6
Source File: ArrayTypesTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testTryConvertToArray_04() throws Exception { LightweightTypeReference typeReference = toTypeReference( "org.eclipse.xtext.xbase.tests.typesystem.ClosureTypeComputerUnitTest.StringIterable"); ArrayTypeReference arrayType = typeReference.tryConvertToArray(); assertEquals("String[]", arrayType.getSimpleName()); }
Example #7
Source File: ArrayTypesTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testTryConvertToArray_05() throws Exception { LightweightTypeReference typeReference = toTypeReference( "org.eclipse.xtext.xbase.tests.typesystem.ClosureTypeComputerUnitTest.CharSequenceIterable"); ArrayTypeReference arrayType = typeReference.tryConvertToArray(); // intuitively one would assume CharSequence[] but Object[] fulfills the raw type contract of Java assertEquals("Object[]", arrayType.getSimpleName()); }
Example #8
Source File: StandardTypeParameterSubstitutorTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected LightweightTypeReference substituteInArrayContext(String componentType) { LightweightTypeReference typeReference = toTypeReference("Iterable<" + componentType + ">"); DeclaratorTypeArgumentCollector collector = new DeclaratorTypeArgumentCollector(); Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> mapping = collector.getTypeParameterMapping(typeReference); Assert.assertEquals(1, mapping.size()); JvmTypeParameter typeParameter = Iterables.getFirst(mapping.keySet(), null); LightweightMergedBoundTypeArgument boundArgument = mapping.get(typeParameter); Assert.assertEquals(componentType, boundArgument.getTypeReference().getSimpleName()); ITypeReferenceOwner owner = typeReference.getOwner(); ArrayTypeReference originalArray = owner.newArrayTypeReference(owner.newParameterizedTypeReference(typeParameter)); Assert.assertEquals("T[]", originalArray.getSimpleName()); LightweightTypeReference substitutedArray = new StandardTypeParameterSubstitutor(mapping, typeReference.getOwner()).substitute(originalArray); return substitutedArray; }
Example #9
Source File: ArrayTypesTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testTryConvertToArray_06() throws Exception { LightweightTypeReference typeReference = toTypeReference( "org.eclipse.xtext.xbase.tests.typesystem.ClosureTypeComputerUnitTest.CharSequenceIterable<StringBuffer>"); ArrayTypeReference arrayType = typeReference.tryConvertToArray(); assertEquals("StringBuffer[]", arrayType.getSimpleName()); }
Example #10
Source File: ArrayTypesTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testTryConvertToArray_07() throws Exception { LightweightTypeReference typeReference = toTypeReference( "org.eclipse.xtext.xbase.tests.typesystem.ClosureTypeComputerUnitTest.StrangeIterable"); ArrayTypeReference arrayType = typeReference.tryConvertToArray(); assertEquals("Object[]", arrayType.getSimpleName()); }
Example #11
Source File: ResolvingTypeParameterHintCollector.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public void doVisitUnboundTypeReference(UnboundTypeReference reference, ArrayTypeReference declaration) { if (reference.internalIsResolved() || getOwner().isResolved(reference.getHandle())) { reference.tryResolve(); outerVisit(reference, declaration); } else { addHint(reference, declaration); } }
Example #12
Source File: AbstractTypeReferencePairWalker.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected void doVisitArrayTypeReference(ArrayTypeReference reference, ParameterizedTypeReference declaration) { JvmType type = declaration.getType(); if (type instanceof JvmTypeParameter) { if (shouldProcess((JvmTypeParameter) type)) { JvmTypeParameter typeParameter = (JvmTypeParameter) type; processTypeParameter(typeParameter, reference); } } }
Example #13
Source File: AbstractTypeReferencePairWalker.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected void doVisitWildcardTypeReference(WildcardTypeReference reference, ArrayTypeReference declaration) { LightweightTypeReference lowerBound = reference.getLowerBound(); if (lowerBound != null) { outerVisit(declaration, lowerBound, declaration, expectedVariance, VarianceInfo.IN); } else { for(LightweightTypeReference upperBound: reference.getUpperBounds()) { outerVisit(declaration, upperBound, declaration, expectedVariance, VarianceInfo.OUT); } } }
Example #14
Source File: ArrayTypesTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testTryConvertToArray_08() throws Exception { LightweightTypeReference typeReference = toTypeReference( "org.eclipse.xtext.xbase.tests.typesystem.ClosureTypeComputerUnitTest.StrangeIterable<String>"); ArrayTypeReference arrayType = typeReference.tryConvertToArray(); assertEquals("Object[]", arrayType.getSimpleName()); }
Example #15
Source File: ArrayTypesTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testTryConvertToArray_09() throws Exception { LightweightTypeReference typeReference = toTypeReference( "org.eclipse.xtext.xbase.tests.typesystem.ClosureTypeComputerUnitTest.StrangeStringIterable"); ArrayTypeReference arrayType = typeReference.tryConvertToArray(); // intuitively one would assume String[] but Object[] fulfills the raw type contract of Java assertEquals("Object[]", arrayType.getSimpleName()); }
Example #16
Source File: ArrayTypesTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testTryConvertToArray_10() throws Exception { LightweightTypeReference typeReference = toTypeReference( "org.eclipse.xtext.xbase.tests.typesystem.ClosureTypeComputerUnitTest.StrangeStringIterable<Integer>"); ArrayTypeReference arrayType = typeReference.tryConvertToArray(); assertEquals("String[]", arrayType.getSimpleName()); }
Example #17
Source File: AbstractTypeReferencePairWalker.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected void doVisitParameterizedTypeReference(ParameterizedTypeReference reference, ArrayTypeReference declaration) { JvmType type = reference.getType(); if (type instanceof JvmTypeParameter) { if (shouldProcess((JvmTypeParameter) type)) { JvmTypeParameter typeParameter = (JvmTypeParameter) type; processTypeParameter(typeParameter, declaration); } } else { LightweightTypeReference declarationAsList = declaration.tryConvertToListType(); outerVisit(declarationAsList, reference); } }
Example #18
Source File: ArrayTypesTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testTryConvertToArray_11() throws Exception { LightweightTypeReference typeReference = toTypeReference( "org.eclipse.xtext.xbase.tests.typesystem.ClosureTypeComputerUnitTest.IterableContainer<String>.Iter"); ArrayTypeReference arrayType = typeReference.tryConvertToArray(); assertEquals("String[]", arrayType.getSimpleName()); }
Example #19
Source File: TypeParameterSubstitutor.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected LightweightTypeReference doVisitArrayTypeReference(ArrayTypeReference reference, Visiting visiting) { if (reference.isResolved() && reference.isOwnedBy(getOwner())) return reference; LightweightTypeReference component = visitTypeArgument(reference.getComponentType(), visiting); component = component.getUpperBoundSubstitute(); return getOwner().newArrayTypeReference(component); }
Example #20
Source File: AbstractParameterBuilder.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public ISourceAppender build(final ISourceAppender appendable) { ISourceAppender _xblockexpression = null; { this.appendModifiers(appendable); if (this.varArgsFlag) { this.appendType(appendable, ((ArrayTypeReference) this.type).getComponentType(), "Object").append("..."); } else { this.appendType(appendable, this.type, "Object"); } _xblockexpression = appendable.append(" ").append(this.name); } return _xblockexpression; }
Example #21
Source File: LocalTypeSubstitutor.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected LocalTypeSubstitutor.SubstitutionResult doVisitArrayTypeReference(ArrayTypeReference reference, VarianceInfo varianceInfo) { SubstitutionResult visited = reference.getComponentType().accept(this, varianceInfo); if (visited.didSubstitute) { return new SubstitutionResult(owner.newArrayTypeReference(visited.typeReference), true); } return new SubstitutionResult(reference, false); }
Example #22
Source File: RawTypeConformanceComputer.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected int doIsConformant(ArrayTypeReference left, ParameterizedTypeReference right, int flags) { if ((flags & AS_TYPE_ARGUMENT) == 0 && (flags & ALLOW_SYNONYMS) != 0) { ArrayTypeReference rightAsArray = right.tryConvertToArray(); if (rightAsArray != null) { LightweightTypeReference leftComponent = left.getComponentType().getWrapperTypeIfPrimitive(); LightweightTypeReference rightComponent = rightAsArray.getComponentType(); int result = doIsConformant(leftComponent, rightComponent, flags & ~(ALLOW_BOXING_UNBOXING | ALLOW_PRIMITIVE_WIDENING | ALLOW_SYNONYMS | ALLOW_FUNCTION_CONVERSION)); if ((result & SUCCESS) != 0) { return result | DEMAND_CONVERSION | SYNONYM; } } } return flags; }
Example #23
Source File: TypeConformanceComputer.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void addComponentType(LightweightTypeReference reference, List<LightweightTypeReference> result) { if (reference.isArray()) { result.add(((ArrayTypeReference) reference).getComponentType()); } else { result.add(reference); } }
Example #24
Source File: TypeConformanceComputer.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected LightweightTypeReference getFirstForRawType(Multimap<JvmType, LightweightTypeReference> all, JvmType rawType) { Iterator<LightweightTypeReference> iterator = all.get(rawType).iterator(); while(iterator.hasNext()) { LightweightTypeReference result = iterator.next(); if (result instanceof ParameterizedTypeReference || result instanceof ArrayTypeReference) { return result; } } throw new IllegalStateException(all.toString() + " does not contain a useful type reference for rawtype " + rawType.getIdentifier()); }
Example #25
Source File: AbstractParameterBuilder.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override public boolean isValid() { return (((this.type != null) && ((!this.varArgsFlag) || (this.type instanceof ArrayTypeReference))) && super.isValid()); }
Example #26
Source File: AbstractTypeReferencePairWalker.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Override protected void doVisitArrayTypeReference(ArrayTypeReference declaredReference, LightweightTypeReference param) { param.accept(arrayTypeReferenceTraverser, declaredReference); }
Example #27
Source File: ArrayTypesTest.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Test public void testTryConvertToArray_03() throws Exception { LightweightTypeReference typeReference = toTypeReference("java.util.Collection"); ArrayTypeReference arrayType = typeReference.tryConvertToArray(); assertEquals("Object[]", arrayType.getSimpleName()); }
Example #28
Source File: ArrayTypesTest.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Test public void testTryConvertToArray_02() throws Exception { LightweightTypeReference typeReference = toTypeReference("Iterable<? extends String>"); ArrayTypeReference arrayType = typeReference.tryConvertToArray(); assertEquals("String[]", arrayType.getSimpleName()); }
Example #29
Source File: ArrayTypesTest.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Test public void testTryConvertToArray_01() throws Exception { LightweightTypeReference typeReference = toTypeReference("Iterable<?>"); ArrayTypeReference arrayType = typeReference.tryConvertToArray(); assertEquals("Object[]", arrayType.getSimpleName()); }
Example #30
Source File: ReferencedInvalidTypeFinder.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Override protected LightweightTypeReference doVisitArrayTypeReference(final ArrayTypeReference reference) { return reference.getComponentType().<LightweightTypeReference>accept(this); }