-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KSP: Fix processing elements with a high priority visitor (#10476)
- Loading branch information
Showing
7 changed files
with
198 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
inject-kotlin/src/test/groovy/io/micronaut/kotlin/processing/visitor/order/MyVisitor1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2017-2020 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.kotlin.processing.visitor.order; | ||
|
||
import io.micronaut.inject.ast.ClassElement; | ||
import io.micronaut.inject.visitor.TypeElementVisitor; | ||
import io.micronaut.inject.visitor.VisitorContext; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class MyVisitor1 implements TypeElementVisitor<VisitMyAnnotation, Object> { | ||
|
||
static List<String> ORDER = new ArrayList<>(); | ||
|
||
@Override | ||
public void start(VisitorContext visitorContext) { | ||
ORDER.clear(); | ||
} | ||
|
||
@Override | ||
public void visitClass(ClassElement element, VisitorContext context) { | ||
ORDER.add(getClass().getSimpleName() + " " + element.getName()); | ||
} | ||
|
||
@Override | ||
public int getOrder() { | ||
return 1; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
inject-kotlin/src/test/groovy/io/micronaut/kotlin/processing/visitor/order/MyVisitor2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2017-2020 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.kotlin.processing.visitor.order; | ||
|
||
import io.micronaut.inject.ast.ClassElement; | ||
import io.micronaut.inject.visitor.TypeElementVisitor; | ||
import io.micronaut.inject.visitor.VisitorContext; | ||
|
||
public class MyVisitor2 implements TypeElementVisitor<VisitMyAnnotation, Object> { | ||
|
||
@Override | ||
public void visitClass(ClassElement element, VisitorContext context) { | ||
MyVisitor1.ORDER.add(getClass().getSimpleName() + " " + element.getName()); | ||
} | ||
|
||
@Override | ||
public int getOrder() { | ||
return 2; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
inject-kotlin/src/test/groovy/io/micronaut/kotlin/processing/visitor/order/MyVisitor3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2017-2020 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.kotlin.processing.visitor.order; | ||
|
||
import io.micronaut.inject.ast.ClassElement; | ||
import io.micronaut.inject.visitor.TypeElementVisitor; | ||
import io.micronaut.inject.visitor.VisitorContext; | ||
|
||
public class MyVisitor3 implements TypeElementVisitor<VisitMyAnnotation, Object> { | ||
|
||
@Override | ||
public void visitClass(ClassElement element, VisitorContext context) { | ||
MyVisitor1.ORDER.add(getClass().getSimpleName() + " " + element.getName()); | ||
} | ||
|
||
@Override | ||
public int getOrder() { | ||
return 3; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...otlin/src/test/groovy/io/micronaut/kotlin/processing/visitor/order/VisitMyAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2017-2020 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.kotlin.processing.visitor.order; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.PACKAGE, ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD}) | ||
public @interface VisitMyAnnotation { | ||
} |
30 changes: 30 additions & 0 deletions
30
...tlin/src/test/groovy/io/micronaut/kotlin/processing/visitor/order/VisitorOrderSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.micronaut.kotlin.processing.visitor.order | ||
|
||
import io.micronaut.annotation.processing.test.AbstractKotlinCompilerSpec | ||
|
||
class VisitorOrderSpec extends AbstractKotlinCompilerSpec { | ||
|
||
void 'test annotating'() { | ||
when: | ||
buildBeanDefinition('vis.MyBean1', ''' | ||
package vis | ||
import io.micronaut.kotlin.processing.visitor.order.VisitMyAnnotation | ||
@VisitMyAnnotation | ||
class MyBean1 | ||
@VisitMyAnnotation | ||
class MyBean2 | ||
@VisitMyAnnotation | ||
class MyBean3 | ||
''') | ||
then: | ||
MyVisitor1.ORDER == ["MyVisitor3 vis.MyBean1", "MyVisitor3 vis.MyBean2", "MyVisitor3 vis.MyBean3", | ||
"MyVisitor2 vis.MyBean1", "MyVisitor2 vis.MyBean2", "MyVisitor2 vis.MyBean3", | ||
"MyVisitor1 vis.MyBean1", "MyVisitor1 vis.MyBean2", "MyVisitor1 vis.MyBean3"] | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters