Java Code Examples for org.eclipse.xtext.common.types.JvmGenericType#setSimpleName()
The following examples show how to use
org.eclipse.xtext.common.types.JvmGenericType#setSimpleName() .
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: ClasspathTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testJvmTypeSimple_Issue145() { Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring")); JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType(); expected.setSimpleName("SimpleName"); expected.setPackageName("package.name"); resource.getContents().add(expected); JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName"); assertEquals(expected, actual); resource.getContents().remove(expected); ((InternalEObject)expected).eSetProxyURI(EcoreUtil.getURI(expected)); JvmGenericType expected2 = TypesFactory.eINSTANCE.createJvmGenericType(); expected2.setSimpleName("SimpleName"); expected2.setPackageName("package.name"); resource.getContents().add(expected2); JvmType actual2 = getTypeProvider().findTypeByName("package.name.SimpleName"); assertEquals(expected2, actual2); }
Example 2
Source File: ClasspathTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testJvmTypeNoPackage() { Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring")); JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType(); expected.setSimpleName("SimpleName"); resource.getContents().add(expected); JvmType actual = getTypeProvider().findTypeByName("SimpleName"); assertEquals(expected, actual); }
Example 3
Source File: XtendJvmModelInferrer.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
/** * Anonymous classes are not inferred in the type inference phase, but later during type resolution. */ public void inferLocalClass( AnonymousClass anonymousClass, String localClassName, JvmFeature container) { final JvmGenericType inferredType = typesFactory.createJvmGenericType(); inferredType.setSimpleName(localClassName); inferredType.setAnonymous(!hasAdditionalMembers(anonymousClass)); inferredType.setFinal(true); inferredType.setVisibility(JvmVisibility.DEFAULT); inferredType.getSuperTypes().add(jvmTypesBuilder.inferredType(anonymousClass)); container.getLocalClasses().add(inferredType); associator.associatePrimary(anonymousClass, inferredType); for (XtendMember member : anonymousClass.getMembers()) { if (member instanceof XtendField || (member instanceof XtendFunction && ((XtendFunction) member).getName() != null) || member instanceof XtendConstructor) { transform(member, inferredType, true); } } appendSyntheticDispatchMethods(anonymousClass, inferredType); nameClashResolver.resolveNameClashes(inferredType); final XConstructorCall constructorCall = anonymousClass.getConstructorCall(); for (XExpression actualParameter : constructorCall.getArguments()) { associator.associateLogicalContainer(actualParameter, container); } }
Example 4
Source File: AbstractConstructorScopeTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testGetElementByInstance_01() { JvmConstructor constructor = TypesFactory.eINSTANCE.createJvmConstructor(); JvmGenericType type = TypesFactory.eINSTANCE.createJvmGenericType(); type.setPackageName("java.lang"); type.setSimpleName("Object"); constructor.setSimpleName("Object"); type.getMembers().add(constructor); IEObjectDescription element = getConstructorScope().getSingleElement(constructor); assertNotNull(element); assertEquals(new IQualifiedNameConverter.DefaultImpl().toQualifiedName("java.lang.Object"), element.getName()); assertEquals(new IQualifiedNameConverter.DefaultImpl().toQualifiedName("java.lang.Object"), element.getQualifiedName()); }
Example 5
Source File: XbaseResourceDescriptionStrategyTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testInterfaceDescription_02() { JvmGenericType interfaceType = TypesFactory.eINSTANCE.createJvmGenericType(); interfaceType.setInterface(false); interfaceType.setPackageName("foo"); interfaceType.setSimpleName("MyType"); List<IEObjectDescription> list = new ArrayList<>(); descriptionStrategy.createEObjectDescriptions(interfaceType, it -> list.add(it)); Assert.assertFalse(list.stream().anyMatch( it -> "true".equals(it.getUserData(JvmTypesResourceDescriptionStrategy.IS_INTERFACE)))); }
Example 6
Source File: XbaseResourceDescriptionStrategyTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testInterfaceDescription_01() { JvmGenericType interfaceType = TypesFactory.eINSTANCE.createJvmGenericType(); interfaceType.setInterface(true); interfaceType.setPackageName("foo"); interfaceType.setSimpleName("MyType"); List<IEObjectDescription> list = new ArrayList<>(); descriptionStrategy.createEObjectDescriptions(interfaceType, it -> list.add(it)); Assert.assertTrue( list.stream().anyMatch(it -> "true".equals(it.getUserData(JvmTypesResourceDescriptionStrategy.IS_INTERFACE)))); }
Example 7
Source File: ClasspathTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testJvmTypeArray() { Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring")); JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType(); expected.setSimpleName("SimpleName"); expected.setPackageName("package.name"); resource.getContents().add(expected); JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName[]"); assertTrue(actual instanceof JvmArrayType); assertEquals(expected, ((JvmArrayType) actual).getComponentType()); }
Example 8
Source File: ClasspathTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testJvmTypeNestedClassWithDot_02() { Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring")); JvmGenericType container = TypesFactory.eINSTANCE.createJvmGenericType(); container.setSimpleName("SimpleName"); container.setPackageName("package.name"); JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType(); expected.setSimpleName("Child"); container.getMembers().add(expected); resource.getContents().add(container); JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName.Child", true); assertNull(actual); }
Example 9
Source File: PyGenerator.java From sarl with Apache License 2.0 | 5 votes |
/** Create a JvmType for a Python type. * * @param pythonName the python type name. * @return the type. */ @SuppressWarnings("static-method") protected JvmType newType(String pythonName) { final JvmGenericType type = TypesFactory.eINSTANCE.createJvmGenericType(); final int index = pythonName.indexOf("."); //$NON-NLS-1$ if (index <= 0) { type.setSimpleName(pythonName); } else { type.setPackageName(pythonName.substring(0, index - 1)); type.setSimpleName(pythonName.substring(index + 1)); } return type; }
Example 10
Source File: JvmTypesBuilder.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected JvmGenericType createJvmGenericType(/* @Nullable */ EObject sourceElement, /* @Nullable */ String name) { if (sourceElement == null || name == null) return null; Pair<String, String> fullName = splitQualifiedName(name); final JvmGenericType result = typesFactory.createJvmGenericType(); result.setSimpleName(fullName.getSecond()); if (fullName.getFirst() != null) result.setPackageName(fullName.getFirst()); result.setVisibility(JvmVisibility.PUBLIC); return result; }
Example 11
Source File: ClasspathTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testJvmTypeSimple() { Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring")); JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType(); expected.setSimpleName("SimpleName"); expected.setPackageName("package.name"); resource.getContents().add(expected); JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName"); assertEquals(expected, actual); }
Example 12
Source File: ReflectionTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testJvmTypeArray() { Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring")); JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType(); expected.setSimpleName("SimpleName"); expected.setPackageName("package.name"); resource.getContents().add(expected); JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName[]"); assertTrue(actual instanceof JvmArrayType); assertEquals(expected, ((JvmArrayType) actual).getComponentType()); }
Example 13
Source File: ReflectionTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testJvmTypeNestedClassWithDot_02() { Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring")); JvmGenericType container = TypesFactory.eINSTANCE.createJvmGenericType(); container.setSimpleName("SimpleName"); container.setPackageName("package.name"); JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType(); expected.setSimpleName("Child"); container.getMembers().add(expected); resource.getContents().add(container); JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName.Child", true); assertNull(actual); }
Example 14
Source File: ReflectionTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testJvmTypeNestedClassWithDot_01() { Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring")); JvmGenericType container = TypesFactory.eINSTANCE.createJvmGenericType(); container.setSimpleName("SimpleName"); container.setPackageName("package.name"); JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType(); expected.setSimpleName("Child"); container.getMembers().add(expected); resource.getContents().add(container); JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName.Child", false); assertEquals(expected, actual); }
Example 15
Source File: ReflectionTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testJvmTypeNestedClass() { Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring")); JvmGenericType container = TypesFactory.eINSTANCE.createJvmGenericType(); container.setSimpleName("SimpleName"); container.setPackageName("package.name"); JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType(); expected.setSimpleName("Child"); container.getMembers().add(expected); resource.getContents().add(container); JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName$Child"); assertEquals(expected, actual); }
Example 16
Source File: ReflectionTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testJvmTypeNoPackage() { Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring")); JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType(); expected.setSimpleName("SimpleName"); resource.getContents().add(expected); JvmType actual = getTypeProvider().findTypeByName("SimpleName"); assertEquals(expected, actual); }
Example 17
Source File: ReflectionTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testJvmTypeSimple() { Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring")); JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType(); expected.setSimpleName("SimpleName"); expected.setPackageName("package.name"); resource.getContents().add(expected); JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName"); assertEquals(expected, actual); }
Example 18
Source File: AbstractConstructorScopeTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testGetElementByInstance_01() { JvmConstructor constructor = TypesFactory.eINSTANCE.createJvmConstructor(); JvmGenericType type = TypesFactory.eINSTANCE.createJvmGenericType(); type.setPackageName("java.lang"); type.setSimpleName("Object"); constructor.setSimpleName("Object"); type.getMembers().add(constructor); IEObjectDescription element = getConstructorScope().getSingleElement(constructor); assertNotNull(element); assertEquals(new IQualifiedNameConverter.DefaultImpl().toQualifiedName("java.lang.Object"), element.getName()); assertEquals(new IQualifiedNameConverter.DefaultImpl().toQualifiedName("java.lang.Object"), element.getQualifiedName()); }
Example 19
Source File: SARLJvmModelInferrer.java From sarl with Apache License 2.0 | 4 votes |
/** Initialize the SARL capacity context-aware wrapper. * * @param source the source. * @param inferredJvmType the JVM type. * @since 0.6 */ protected void appendCapacityContextAwareWrapper(SarlCapacity source, JvmGenericType inferredJvmType) { final JvmGenericType innerType = this.typesFactory.createJvmGenericType(); innerType.setInterface(false); innerType.setAbstract(false); innerType.setVisibility(JvmVisibility.PUBLIC); innerType.setStatic(true); innerType.setStrictFloatingPoint(false); innerType.setFinal(false); final String innerTypeName = Capacity.ContextAwareCapacityWrapper.class.getSimpleName(); innerType.setSimpleName(innerTypeName); inferredJvmType.getMembers().add(innerType); this.typeBuilder.setDocumentation(innerType, "@ExcludeFromApidoc"); //$NON-NLS-1$ final JvmTypeParameter typeParameter = this.typesFactory.createJvmTypeParameter(); typeParameter.setName("C"); //$NON-NLS-1$ final JvmUpperBound constraint = this.typesFactory.createJvmUpperBound(); constraint.setTypeReference(this._typeReferenceBuilder.typeRef(inferredJvmType)); typeParameter.getConstraints().add(constraint); innerType.getTypeParameters().add(typeParameter); final Iterator<JvmTypeReference> extendedTypeIterator = inferredJvmType.getExtendedInterfaces().iterator(); if (extendedTypeIterator.hasNext()) { final JvmTypeReference extendedType = extendedTypeIterator.next(); final JvmTypeReference superType = this._typeReferenceBuilder.typeRef( extendedType.getQualifiedName() + "$" + innerTypeName, //$NON-NLS-1$ this._typeReferenceBuilder.typeRef(typeParameter)); innerType.getSuperTypes().add(superType); } innerType.getSuperTypes().add(this._typeReferenceBuilder.typeRef(inferredJvmType)); final JvmConstructor constructor = this.typesFactory.createJvmConstructor(); constructor.setVisibility(JvmVisibility.PUBLIC); innerType.getMembers().add(constructor); final JvmFormalParameter parameter1 = this.typesFactory.createJvmFormalParameter(); parameter1.setName("capacity"); //$NON-NLS-1$ parameter1.setParameterType(this._typeReferenceBuilder.typeRef(typeParameter)); constructor.getParameters().add(parameter1); final JvmFormalParameter parameter2 = this.typesFactory.createJvmFormalParameter(); parameter2.setName("caller"); //$NON-NLS-1$ parameter2.setParameterType(this._typeReferenceBuilder.typeRef(AgentTrait.class)); constructor.getParameters().add(parameter2); setBody(constructor, it -> { it.append("super(capacity, caller);"); //$NON-NLS-1$ }); final Set<ActionPrototype> createdActions = new TreeSet<>(); for (final JvmGenericType sourceType : Iterables.concat( Collections.singletonList(inferredJvmType), Iterables.transform(Iterables.skip(inferredJvmType.getExtendedInterfaces(), 1), it -> { return (JvmGenericType) it.getType(); }))) { copyNonStaticPublicJvmOperations(sourceType, innerType, createdActions, (operation, it) -> { it.append("try {"); //$NON-NLS-1$ it.newLine(); it.append(" ensureCallerInLocalThread();"); //$NON-NLS-1$ it.newLine(); it.append(" "); //$NON-NLS-1$ if (operation.getReturnType() != null && !Objects.equal("void", operation.getReturnType().getIdentifier())) { //$NON-NLS-1$ it.append("return "); //$NON-NLS-1$ } it.append("this.capacity."); //$NON-NLS-1$ it.append(operation.getSimpleName()); it.append("("); //$NON-NLS-1$ boolean first = true; for (final JvmFormalParameter fparam : operation.getParameters()) { if (first) { first = false; } else { it.append(", "); //$NON-NLS-1$ } it.append(fparam.getName()); } it.append(");"); //$NON-NLS-1$ it.newLine(); it.append("} finally {"); //$NON-NLS-1$ it.newLine(); it.append(" resetCallerInLocalThread();"); //$NON-NLS-1$ it.newLine(); it.append("}"); //$NON-NLS-1$ }); } }
Example 20
Source File: Bug92Test.java From sarl with Apache License 2.0 | 4 votes |
protected static JvmType createType(Class<?> t) { JvmGenericType result = TypesFactory.eINSTANCE.createJvmGenericType(); result.setSimpleName(t.getSimpleName()); result.setPackageName(t.getPackage().getName()); return result; }