Infers a JVM model from the source model.
11 | * 12 | *The JVM model should contain all elements that would appear in the Java code 13 | * which is generated from the source model. Other models link against the JVM model rather than the source model.
14 | */ 15 | class Structs4JavaDslJvmModelInferrer extends AbstractModelInferrer { 16 | 17 | /** 18 | * The dispatch method {@code infer} is called for each instance of the 19 | * given element's type that is contained in a resource. 20 | * 21 | * @param element 22 | * the model to create one or more 23 | * {@link org.eclipse.xtext.common.types.JvmDeclaredType declared 24 | * types} from. 25 | * @param acceptor 26 | * each created 27 | * {@link org.eclipse.xtext.common.types.JvmDeclaredType type} 28 | * without a container should be passed to the acceptor in order 29 | * get attached to the current resource. The acceptor's 30 | * {@link IJvmDeclaredTypeAcceptor#accept(org.eclipse.xtext.common.types.JvmDeclaredType) 31 | * accept(..)} method takes the constructed empty type for the 32 | * pre-indexing phase. This one is further initialized in the 33 | * indexing phase using the lambda you pass as the last argument. 34 | * @param isPreIndexingPhase 35 | * whether the method is called in a pre-indexing phase, i.e. 36 | * when the global index is not yet fully updated. You must not 37 | * rely on linking using the index if isPreIndexingPhase is 38 | *true
.
39 | */
40 | def dispatch void infer(org.structs4java.structs4JavaDsl.StructsFile element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
41 | // Here you explain how your model is mapped to Java elements, by writing the actual translation code.
42 |
43 | // An implementation for the initial hello world example could look like this:
44 | // acceptor.accept(element.toClass("my.company.greeting.MyGreetings")) [
45 | // for (greeting : element.greetings) {
46 | // members += greeting.toMethod("hello" + greeting.name, typeRef(String)) [
47 | // body = '''
48 | // return "Hello «greeting.name»";
49 | // '''
50 | // ]
51 | // }
52 | // ]
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/org.structs4java.parent/org.structs4java/src/org/structs4java/scoping/MyImportedNamespaceAwareLocalScopeProvider.java:
--------------------------------------------------------------------------------
1 | package org.structs4java.scoping;
2 |
3 | import java.util.List;
4 |
5 | import org.eclipse.emf.ecore.EObject;
6 | import org.eclipse.xtext.naming.QualifiedName;
7 | import org.eclipse.xtext.scoping.impl.ImportNormalizer;
8 | import org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider;
9 | import org.structs4java.structs4JavaDsl.StructsFile;
10 |
11 | /**
12 | * @see https://nittka.github.io/2011/08/07/scoping3.html
13 | * @author azrael
14 | *
15 | */
16 | public class MyImportedNamespaceAwareLocalScopeProvider extends ImportedNamespaceAwareLocalScopeProvider {
17 |
18 | @Override
19 | protected List