-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip classes from introspection generation that are postponed (#11155)
Currently if a class is postponed the introspection is still generated. This means that in the next round the introspection is recreated and an exception is thrown because there was an attempt to rewrite the some class. Without this change it is impossible to use @wither and @introspected together. Unclear how to create a test for it here. Will have to upgrade SourceGen and add a test there. --------- Co-authored-by: Denis Stepanov <[email protected]>
- Loading branch information
1 parent
2ca4ab4
commit 4640ece
Showing
11 changed files
with
208 additions
and
10 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
46 changes: 46 additions & 0 deletions
46
...essor/src/main/java/io/micronaut/inject/visitor/ElementPostponedToNextRoundException.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,46 @@ | ||
/* | ||
* 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.inject.visitor; | ||
|
||
import io.micronaut.core.annotation.Internal; | ||
import io.micronaut.core.annotation.NonNull; | ||
import io.micronaut.inject.ast.Element; | ||
|
||
/** | ||
* Exception is thrown when the visitor is attempted to create a new file but the originated element is postponed to the next round. | ||
* | ||
* @author Denis Stepanov | ||
* @since 4.7 | ||
*/ | ||
@Internal | ||
public final class ElementPostponedToNextRoundException extends RuntimeException { | ||
|
||
private final Element originatingElement; | ||
|
||
/** | ||
* @param originatingElement The originating element | ||
*/ | ||
public ElementPostponedToNextRoundException(@NonNull Element originatingElement) { | ||
super("Original element: " + originatingElement.getName() + " is postponed to the next round!"); | ||
this.originatingElement = originatingElement; | ||
} | ||
|
||
@NonNull | ||
public Element getOriginatingElement() { | ||
return originatingElement; | ||
} | ||
|
||
} |
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
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
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
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
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
31 changes: 31 additions & 0 deletions
31
inject-java/src/test/groovy/io/micronaut/visitors/PostponedVisitorsSpec.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,31 @@ | ||
package io.micronaut.visitors | ||
|
||
|
||
import io.micronaut.annotation.processing.test.AbstractTypeElementSpec | ||
|
||
class PostponedVisitorsSpec extends AbstractTypeElementSpec { | ||
|
||
void 'test'() { | ||
when: | ||
def definition = buildBeanIntrospection('test.Walrus', ''' | ||
package test; | ||
import io.micronaut.core.annotation.Introspected; | ||
import io.micronaut.core.annotation.NonNull; | ||
import io.micronaut.visitors.Wither; | ||
@Introspected | ||
@Wither | ||
public record Walrus ( | ||
@NonNull | ||
String name, | ||
int age, | ||
byte[] chipInfo | ||
) implements WalrusWither { | ||
} | ||
''') | ||
then: | ||
definition | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
inject-java/src/test/groovy/io/micronaut/visitors/Wither.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,8 @@ | ||
package io.micronaut.visitors; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Wither { | ||
} |
Oops, something went wrong.