Rework Java import tracking 09/70109/23
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 25 Mar 2018 22:52:44 +0000 (00:52 +0200)
committerTom Pantelis <tompantelis@gmail.com>
Sat, 28 Apr 2018 12:06:08 +0000 (12:06 +0000)
commitce1e55484544d25297cb60cdfc6758e9b14945fb
tree57f15f6806471ec4f6faf76b3446a89dbed1ec50
parent87739e6c8f7edfaf977eb9cea86bac32cf016423
Rework Java import tracking

In order to get nested class imports working, we need a proper
layer which understands how references inside Java code are
looked up.

Introduce AbstractJavaGeneratedType, which creates a tree structure
of how the class is layed out, thus it knows which types are declared
in a particular type's scope. There are two implementions:
- TopLevelJavaGeneratedType, which is responsible for managing what
  is imported into the compilation unit
- NestedJavaGeneratedType, which does not know about imports per se
  and delegates decisions to its containing type

Templates are updated to properly hook into the type hierarchy, so
their requests for type resolution are properly scoped.

One remaining wrinkle is BuilderTemplate, which abuses the template
system by using its built type as its type. This is worked around
in this patch and will need to be cleaned up later.

JIRA: MDSAL-327
Change-Id: Ie66a93ba85be26b056f118ba9fe14195e8d5a8ea
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
Signed-off-by: Jie Han <han.jie@zte.com.cn>
17 files changed:
binding/mdsal-binding-generator-api/src/main/java/org/opendaylight/mdsal/binding/model/api/JavaTypeName.java
binding/mdsal-binding-generator-api/src/test/java/org/opendaylight/mdsal/binding/model/api/JavaTypeNameTest.java
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/AbstractTypeGenerator.java
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/AbstractJavaGeneratedType.java [new file with mode: 0644]
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/BaseTemplate.xtend
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/BuilderTemplate.xtend
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/ClassTemplate.xtend
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/EnumTemplate.xtend
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/InterfaceTemplate.xtend
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/JavaFileTemplate.java
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/NestedJavaGeneratedType.java [new file with mode: 0644]
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/TopLevelJavaGeneratedType.java [new file with mode: 0644]
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/UnionTemplate.xtend
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/BuilderGeneratorTest.java
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/test/ClassCodeGeneratorTest.java
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/test/CompilationTest.java
binding/mdsal-binding-java-api-generator/src/test/resources/compilation/mdsal327/test-imports.yang [new file with mode: 0644]