Java Code Examples for org.eclipse.xtext.common.types.JvmGenericType#getMembers()
The following examples show how to use
org.eclipse.xtext.common.types.JvmGenericType#getMembers() .
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: InferredJvmModelTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testInferredFunction_02() throws Exception { XtendFile xtendFile = file("class Foo { def create result: newArrayList(s) newList(String s) {} }"); JvmGenericType inferredType = getInferredType(xtendFile); XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0); EList<JvmMember> jvmMembers = inferredType.getMembers(); assertEquals(4, jvmMembers.size()); JvmMember jvmMember = jvmMembers.get(1); assertTrue(jvmMember instanceof JvmOperation); XtendFunction xtendFunction = (XtendFunction) xtendClass.getMembers().get(0); assertEquals(xtendFunction.getName(), jvmMember.getSimpleName()); assertEquals(JvmVisibility.PUBLIC, jvmMember.getVisibility()); assertEquals("java.util.ArrayList<java.lang.String>", ((JvmOperation) jvmMember).getReturnType().getIdentifier()); JvmField cacheVar = (JvmField) jvmMembers.get(2); assertEquals("_createCache_" + xtendFunction.getName(), cacheVar.getSimpleName()); assertEquals(JvmVisibility.PRIVATE, cacheVar.getVisibility()); assertEquals("java.util.HashMap<java.util.ArrayList<? extends java.lang.Object>, java.util.ArrayList<java.lang.String>>", cacheVar.getType().getIdentifier()); JvmOperation privateInitializer = (JvmOperation) jvmMembers.get(3); assertEquals("_init_"+xtendFunction.getName(), privateInitializer.getSimpleName()); assertEquals(JvmVisibility.PRIVATE, privateInitializer.getVisibility()); assertEquals("java.util.ArrayList<java.lang.String>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier()); assertEquals("java.lang.String", privateInitializer.getParameters().get(1).getParameterType().getIdentifier()); }
Example 2
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_staticNestedTypes_constructor() { String typeName = Bug347739.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); List<JvmMember> members = type.getMembers(); for (JvmMember member : members) { if (member instanceof JvmGenericType) { if ("StackItem".equals(member.getSimpleName())) { JvmGenericType stackItem = (JvmGenericType) member; Iterable<JvmConstructor> constructors = stackItem.getDeclaredConstructors(); for (JvmConstructor constructor : constructors) { assertEquals(2, constructor.getParameters().size()); } return; } } } fail("could not find inner class"); }
Example 3
Source File: InferredJvmModelTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testDispatchFunction_00() throws Exception { XtendFile xtendFile = file("class Foo { def dispatch foo(Object x) {null} def dispatch foo(String x) {null}}"); JvmGenericType inferredType = getInferredType(xtendFile); // one main dispatch Iterable<JvmOperation> operations = inferredType.getDeclaredOperations(); JvmOperation dispatch = findByNameAndFirstParameterType(operations, "foo", Object.class); assertEquals("java.lang.Object", dispatch.getReturnType().getIdentifier()); // two internal case methods findByNameAndFirstParameterType(operations, "_foo", Object.class); findByNameAndFirstParameterType(operations, "_foo", String.class); for(JvmMember member: inferredType.getMembers()) { if (member instanceof JvmExecutable) { if (member.getSimpleName().startsWith("_")) assertEquals(JvmVisibility.PROTECTED, member.getVisibility()); else assertEquals(JvmVisibility.PUBLIC, member.getVisibility()); } else { assertEquals(JvmVisibility.PRIVATE, member.getVisibility()); } } }
Example 4
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_staticNestedTypes_constructor() { String typeName = Bug347739.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); List<JvmMember> members = type.getMembers(); for (JvmMember member : members) { if (member instanceof JvmGenericType) { if ("StackItem".equals(member.getSimpleName())) { JvmGenericType stackItem = (JvmGenericType) member; Iterable<JvmConstructor> constructors = stackItem.getDeclaredConstructors(); for (JvmConstructor constructor : constructors) { assertEquals(2, constructor.getParameters().size()); } return; } } } fail("could not find inner class"); }
Example 5
Source File: InferredJvmModelTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testXtendField_00() throws Exception { XtendFile xtendFile = file("class Foo { @Inject String string }"); JvmGenericType type = getInferredType(xtendFile); Iterable<JvmField> iterable = type.getDeclaredFields(); JvmField next = iterable.iterator().next(); assertEquals("string",next.getSimpleName()); assertEquals(JvmVisibility.PRIVATE, next.getVisibility()); assertEquals("java.lang.String", next.getType().getIdentifier()); for(JvmMember member: type.getMembers()) { if (member instanceof JvmExecutable) { assertEquals(JvmVisibility.PUBLIC, member.getVisibility()); } else { assertEquals(JvmVisibility.PRIVATE, member.getVisibility()); } } }
Example 6
Source File: InferredJvmModelTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testInferredFunction_05() throws Exception { XtendFile xtendFile = file("class Foo { def Iterable<? extends CharSequence> create result: newArrayList(s) newList(String s) {} }"); JvmGenericType inferredType = getInferredType(xtendFile); XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0); EList<JvmMember> jvmMembers = inferredType.getMembers(); assertEquals(4, jvmMembers.size()); JvmMember jvmMember = jvmMembers.get(1); assertTrue(jvmMember instanceof JvmOperation); XtendFunction xtendFunction = (XtendFunction) xtendClass.getMembers().get(0); assertEquals(xtendFunction.getName(), jvmMember.getSimpleName()); assertEquals(JvmVisibility.PUBLIC, jvmMember.getVisibility()); assertEquals("java.lang.Iterable<? extends java.lang.CharSequence>", ((JvmOperation) jvmMember).getReturnType().getIdentifier()); JvmField cacheVar = (JvmField) jvmMembers.get(2); assertEquals("_createCache_" + xtendFunction.getName(), cacheVar.getSimpleName()); assertEquals(JvmVisibility.PRIVATE, cacheVar.getVisibility()); assertEquals("java.util.HashMap<java.util.ArrayList<? extends java.lang.Object>, java.lang.Iterable<? extends java.lang.CharSequence>>", cacheVar.getType().getIdentifier()); JvmOperation privateInitializer = (JvmOperation) jvmMembers.get(3); assertEquals("_init_"+xtendFunction.getName(), privateInitializer.getSimpleName()); assertEquals(JvmVisibility.PRIVATE, privateInitializer.getVisibility()); assertEquals("java.util.ArrayList<java.lang.String>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier()); assertEquals("java.lang.String", privateInitializer.getParameters().get(1).getParameterType().getIdentifier()); }
Example 7
Source File: JvmModelGeneratorTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testCompilationStrategy() { try { final XExpression expression = this.expression("null", false); final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> { EList<JvmMember> _members = it.getMembers(); JvmField _field = this.builder.toField(expression, "x", this.typeRef(expression, String.class)); this.builder.<JvmField>operator_add(_members, _field); EList<JvmMember> _members_1 = it.getMembers(); JvmOperation _getter = this.builder.toGetter(expression, "x", this.typeRef(expression, String.class)); this.builder.<JvmOperation>operator_add(_members_1, _getter); EList<JvmMember> _members_2 = it.getMembers(); JvmOperation _setter = this.builder.toSetter(expression, "x", this.typeRef(expression, String.class)); this.builder.<JvmOperation>operator_add(_members_2, _setter); }; final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function); final Class<?> compiled = this.compile(expression.eResource(), clazz); final Object inst = compiled.getDeclaredConstructor().newInstance(); final Method getter = compiled.getMethod("getX"); final Method setter = compiled.getMethod("setX", String.class); setter.invoke(inst, "FOO"); Assert.assertEquals("FOO", getter.invoke(inst)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 8
Source File: JvmModelGeneratorTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testBug377925No_Nullpointer() { try { final XExpression expression = this.expression("[Object o| null]"); final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> { EList<JvmMember> _members = it.getMembers(); final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> { this.builder.setBody(it_1, expression); }; JvmOperation _method = this.builder.toMethod(expression, "doStuff", this.references.getTypeForName("java.lang.Object", expression), _function_1); this.builder.<JvmOperation>operator_add(_members, _method); }; final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function); this.compile(expression.eResource(), clazz); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 9
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void test_staticNestedTypes_constructor() { String typeName = Bug347739.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); List<JvmMember> members = type.getMembers(); for (JvmMember member : members) { if (member instanceof JvmGenericType) { if ("StackItem".equals(member.getSimpleName())) { JvmGenericType stackItem = (JvmGenericType) member; Iterable<JvmConstructor> constructors = stackItem.getDeclaredConstructors(); for (JvmConstructor constructor : constructors) { assertEquals(2, constructor.getParameters().size()); } return; } } } fail("could not find inner class"); }
Example 10
Source File: InferredJvmModelTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testInferredFunction_06() throws Exception { XtendFile xtendFile = file("class Foo { def Iterable<? super CharSequence> create result: newArrayList(s) newList(String s) {} }"); JvmGenericType inferredType = getInferredType(xtendFile); XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0); EList<JvmMember> jvmMembers = inferredType.getMembers(); assertEquals(4, jvmMembers.size()); JvmMember jvmMember = jvmMembers.get(1); assertTrue(jvmMember instanceof JvmOperation); XtendFunction xtendFunction = (XtendFunction) xtendClass.getMembers().get(0); assertEquals(xtendFunction.getName(), jvmMember.getSimpleName()); assertEquals(JvmVisibility.PUBLIC, jvmMember.getVisibility()); assertEquals("java.lang.Iterable<? extends java.lang.Object & super java.lang.CharSequence>", ((JvmOperation) jvmMember).getReturnType().getIdentifier()); JvmField cacheVar = (JvmField) jvmMembers.get(2); assertEquals("_createCache_" + xtendFunction.getName(), cacheVar.getSimpleName()); assertEquals(JvmVisibility.PRIVATE, cacheVar.getVisibility()); assertEquals("java.util.HashMap<java.util.ArrayList<? extends java.lang.Object>, java.lang.Iterable<? extends java.lang.Object & super java.lang.CharSequence>>", cacheVar.getType().getIdentifier()); JvmOperation privateInitializer = (JvmOperation) jvmMembers.get(3); assertEquals("_init_"+xtendFunction.getName(), privateInitializer.getSimpleName()); assertEquals(JvmVisibility.PRIVATE, privateInitializer.getVisibility()); assertEquals("java.util.ArrayList<java.lang.CharSequence>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier()); assertEquals("java.lang.String", privateInitializer.getParameters().get(1).getParameterType().getIdentifier()); }
Example 11
Source File: JvmModelGeneratorTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testBug426073() { try { final XExpression expression = this.expression("org.eclipse.emf.common.util.URI.createURI(\"dummy\")"); final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> { EList<JvmMember> _members = it.getMembers(); final Procedure1<JvmField> _function_1 = (JvmField it_1) -> { this.builder.setInitializer(it_1, expression); }; JvmField _field = this.builder.toField(expression, "URI", this.typeRef(expression, URI.class), _function_1); this.builder.<JvmField>operator_add(_members, _field); }; final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function); this.compile(expression.eResource(), clazz); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 12
Source File: JvmModelGeneratorTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testNestedAnnotationType() { try { final XExpression expression = this.expression("42"); final JvmGenericType outerClass = this.builder.toClass(expression, "my.outer.Clazz"); EList<JvmMember> _members = outerClass.getMembers(); final Procedure1<JvmAnnotationType> _function = (JvmAnnotationType it) -> { EList<JvmMember> _members_1 = it.getMembers(); final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> { this.builder.setBody(it_1, expression); }; JvmOperation _method = this.builder.toMethod(expression, "theTruth", this.references.getTypeForName(int.class, expression), _function_1); this.builder.<JvmOperation>operator_add(_members_1, _method); }; JvmAnnotationType _annotationType = this.builder.toAnnotationType(expression, "MyAnnotation", _function); this.builder.<JvmAnnotationType>operator_add(_members, _annotationType); final Class<?> compiled = IterableExtensions.<Class<?>>head(((Iterable<Class<?>>)Conversions.doWrapArray(this.compile(expression.eResource(), outerClass).getDeclaredClasses()))); Assert.assertEquals("my.outer.Clazz.MyAnnotation", compiled.getCanonicalName()); Assert.assertEquals(Integer.valueOf(42), IterableExtensions.<Method>head(((Iterable<Method>)Conversions.doWrapArray(compiled.getDeclaredMethods()))).getDefaultValue()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 13
Source File: JvmModelGeneratorTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testBug380754_2() { try { final XExpression expression = this.expression("null"); final JvmAnnotationReferenceBuilder jvmAnnotationReferenceBuilder = this.jvmAnnotationReferenceBuilderFactory.create(expression.eResource().getResourceSet()); final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> { EList<JvmMember> _members = it.getMembers(); final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> { this.builder.setBody(it_1, expression); final JvmFormalParameter parameter = this.builder.toParameter(expression, "s", this.references.getTypeForName(String.class, expression)); EList<JvmFormalParameter> _parameters = it_1.getParameters(); this.builder.<JvmFormalParameter>operator_add(_parameters, parameter); EList<JvmAnnotationReference> _annotations = parameter.getAnnotations(); JvmAnnotationReference _annotationRef = jvmAnnotationReferenceBuilder.annotationRef(TestAnnotation.class); this.builder.<JvmAnnotationReference>operator_add(_annotations, _annotationRef); EList<JvmAnnotationReference> _annotations_1 = parameter.getAnnotations(); JvmAnnotationReference _annotationRef_1 = jvmAnnotationReferenceBuilder.annotationRef(TestAnnotation2.class); this.builder.<JvmAnnotationReference>operator_add(_annotations_1, _annotationRef_1); }; JvmOperation _method = this.builder.toMethod(expression, "doStuff", this.references.getTypeForName("java.lang.Object", expression), _function_1); this.builder.<JvmOperation>operator_add(_members, _method); }; final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function); this.compile(expression.eResource(), clazz); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 14
Source File: AnonymousClassUtil.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
public JvmConstructor getSuperTypeConstructor(AnonymousClass anonymousClass) { JvmGenericType superType = getSuperType(anonymousClass); if(superType != null) { JvmConstructor constructor = anonymousClass.getConstructorCall().getConstructor(); for(JvmMember superMember: superType.getMembers()) { if(superMember instanceof JvmConstructor && isSameSignature(constructor, (JvmConstructor) superMember)) return (JvmConstructor) superMember; } } return null; }
Example 15
Source File: PureXbaseJvmModelInferrer.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void _infer(final Model m, final IJvmDeclaredTypeAcceptor acceptor, final boolean prelinkingPhase) { final XBlockExpression e = m.getBlock(); final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> { EList<JvmMember> _members = it.getMembers(); final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> { EList<JvmTypeReference> _exceptions = it_1.getExceptions(); JvmTypeReference _typeRef = this._typeReferenceBuilder.typeRef(Throwable.class); this._jvmTypesBuilder.<JvmTypeReference>operator_add(_exceptions, _typeRef); this._jvmTypesBuilder.setBody(it_1, e); }; JvmOperation _method = this._jvmTypesBuilder.toMethod(e, "myMethod", this._jvmTypesBuilder.inferredType(), _function_1); this._jvmTypesBuilder.<JvmOperation>operator_add(_members, _method); }; acceptor.<JvmGenericType>accept(this._jvmTypesBuilder.toClass(e, this.name(e.eResource())), _function); }
Example 16
Source File: JvmModelGeneratorTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testBug380754() { try { final XExpression expression = this.expression("null"); final JvmAnnotationReferenceBuilder jvmAnnotationReferenceBuilder = this.jvmAnnotationReferenceBuilderFactory.create(expression.eResource().getResourceSet()); final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> { EList<JvmMember> _members = it.getMembers(); final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> { this.builder.setBody(it_1, expression); final JvmAnnotationReference annotation = jvmAnnotationReferenceBuilder.annotationRef(TestAnnotations.class); final JvmAnnotationAnnotationValue annotationAnnotationValue = this.typesFactory.createJvmAnnotationAnnotationValue(); EList<JvmAnnotationReference> _values = annotationAnnotationValue.getValues(); JvmAnnotationReference _annotationRef = jvmAnnotationReferenceBuilder.annotationRef(TestAnnotation.class); this.builder.<JvmAnnotationReference>operator_add(_values, _annotationRef); EList<JvmAnnotationReference> _values_1 = annotationAnnotationValue.getValues(); JvmAnnotationReference _annotationRef_1 = jvmAnnotationReferenceBuilder.annotationRef(TestAnnotation.class); this.builder.<JvmAnnotationReference>operator_add(_values_1, _annotationRef_1); EList<JvmAnnotationReference> _values_2 = annotationAnnotationValue.getValues(); JvmAnnotationReference _annotationRef_2 = jvmAnnotationReferenceBuilder.annotationRef(TestAnnotation.class); this.builder.<JvmAnnotationReference>operator_add(_values_2, _annotationRef_2); EList<JvmAnnotationValue> _explicitValues = annotation.getExplicitValues(); this.builder.<JvmAnnotationAnnotationValue>operator_add(_explicitValues, annotationAnnotationValue); EList<JvmAnnotationReference> _annotations = it_1.getAnnotations(); this.builder.<JvmAnnotationReference>operator_add(_annotations, annotation); }; JvmOperation _method = this.builder.toMethod(expression, "doStuff", this.references.getTypeForName("java.lang.Object", expression), _function_1); this.builder.<JvmOperation>operator_add(_members, _method); }; final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function); this.compile(expression.eResource(), clazz); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 17
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void assertMembers(String typeName, Set<String> memberNames) { JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); assertEquals(memberNames.size(), type.getMembers().size()); for (JvmMember member : type.getMembers()) { assertTrue(member.getIdentifier(), member instanceof JvmOperation); JvmOperation op = (JvmOperation) member; assertTrue(op.getSimpleName(), memberNames.remove(op.getSimpleName())); } assertTrue(memberNames.isEmpty()); }
Example 18
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void assertMembers(String typeName, Set<String> memberNames) { JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); List<JvmMember> members = type.getMembers(); assertEquals(memberNames.size(), members.size()); for (org.eclipse.xtext.common.types.JvmMember member : members) { assertTrue(member.getIdentifier(), member instanceof JvmOperation); JvmOperation op = (JvmOperation) member; assertTrue(op.getSimpleName(), memberNames.remove(op.getSimpleName())); } assertTrue(memberNames.isEmpty()); }
Example 19
Source File: JvmModelGeneratorTest.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Test public void bug390290InnerClassMemberImport() { try { final XExpression expression = this.expression("null"); final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> { final JvmGenericType innerClass = this.builder.toClass(it, "InnerClass"); final JvmGenericType innerClassString = this.builder.toClass(it, "String"); EList<JvmMember> _members = it.getMembers(); this.builder.<JvmGenericType>operator_add(_members, innerClass); EList<JvmMember> _members_1 = it.getMembers(); this.builder.<JvmGenericType>operator_add(_members_1, innerClassString); EList<JvmMember> _members_2 = it.getMembers(); final Procedure1<JvmOperation> _function_1 = (JvmOperation fooMethod) -> { EList<JvmFormalParameter> _parameters = fooMethod.getParameters(); JvmFormalParameter _parameter = this.builder.toParameter(it, "p1", this.references.createTypeRef(innerClass)); this.builder.<JvmFormalParameter>operator_add(_parameters, _parameter); EList<JvmFormalParameter> _parameters_1 = fooMethod.getParameters(); JvmFormalParameter _parameter_1 = this.builder.toParameter(it, "p2", this.references.createTypeRef(innerClassString)); this.builder.<JvmFormalParameter>operator_add(_parameters_1, _parameter_1); this.builder.setBody(fooMethod, expression); }; JvmOperation _method = this.builder.toMethod(it, "foo", this.references.getTypeForName(String.class, expression), _function_1); this.builder.<JvmOperation>operator_add(_members_2, _method); }; final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Outer", _function); expression.eResource().eSetDeliver(false); EList<EObject> _contents = expression.eResource().getContents(); this.builder.<JvmGenericType>operator_add(_contents, clazz); expression.eResource().eSetDeliver(true); final InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess(); this.generator.doGenerate(expression.eResource(), fsa); Map<String, CharSequence> _textFiles = fsa.getTextFiles(); String _replace = clazz.getIdentifier().replace(".", "/"); String _plus = (IFileSystemAccess.DEFAULT_OUTPUT + _replace); String _plus_1 = (_plus + ".java"); final String code = _textFiles.get(_plus_1).toString(); Assert.assertFalse(code.contains("import")); Assert.assertTrue(code, code.contains("java.lang.String foo")); final Class<?> compiledClass = this.javaCompiler.compileToClass(clazz.getIdentifier(), code); this.helper.assertNoErrors(IterableExtensions.<EObject>head(expression.eResource().getContents())); Assert.assertEquals(2, ((List<Class<?>>)Conversions.doWrapArray(compiledClass.getDeclaredClasses())).size()); Assert.assertNotNull(compiledClass.getMethod("foo", IterableExtensions.<Class<?>>head(((Iterable<Class<?>>)Conversions.doWrapArray(compiledClass.getDeclaredClasses()))), IterableExtensions.<Class<?>>last(((Iterable<Class<?>>)Conversions.doWrapArray(compiledClass.getDeclaredClasses()))))); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 20
Source File: ContentAssistFragmentTestLangJvmModelInferrer.java From xtext-extras with Eclipse Public License 2.0 | 3 votes |
/** * The dispatch method {@code infer} is called for each instance of the * given element's type that is contained in a resource. * * @param element * the model to create one or more * {@link org.eclipse.xtext.common.types.JvmDeclaredType declared * types} from. * @param acceptor * each created * {@link org.eclipse.xtext.common.types.JvmDeclaredType type} * without a container should be passed to the acceptor in order * get attached to the current resource. The acceptor's * {@link IJvmDeclaredTypeAcceptor#accept(org.eclipse.xtext.common.types.JvmDeclaredType) * accept(..)} method takes the constructed empty type for the * pre-indexing phase. This one is further initialized in the * indexing phase using the closure you pass to the returned * {@link org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor.IPostIndexingInitializing#initializeLater(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) * initializeLater(..)}. * @param isPreIndexingPhase * whether the method is called in a pre-indexing phase, i.e. * when the global index is not yet fully updated. You must not * rely on linking using the index if isPreIndexingPhase is * <code>true</code>. */ protected void _infer(final ContentAssistFragmentTestLanguageRoot element, final IJvmDeclaredTypeAcceptor acceptor, final boolean isPreIndexingPhase) { final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> { EList<JvmMember> _members = it.getMembers(); final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> { this._jvmTypesBuilder.setBody(it_1, element.getExpression()); }; JvmOperation _method = this._jvmTypesBuilder.toMethod(element, "hello", this._typeReferenceBuilder.typeRef(Void.class), _function_1); this._jvmTypesBuilder.<JvmOperation>operator_add(_members, _method); }; acceptor.<JvmGenericType>accept(this._jvmTypesBuilder.toClass(element, "my.test.MyClass"), _function); }