Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
239 additions
and
55 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
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
24 changes: 0 additions & 24 deletions
24
value-fixture/src-java-17/org/immutables/fixture/RecordTests.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...ture/HasTypeAnnotationWithAttributes.java → .../j17/HasTypeAnnotationWithAttributes.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
6 changes: 6 additions & 0 deletions
6
value-fixture/src-java-17/org/immutables/fixture/j17/RecordOne.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,6 @@ | ||
package org.immutables.fixture.j17; | ||
|
||
import org.immutables.builder.Builder; | ||
|
||
@Builder | ||
public record RecordOne(int aa, String bb) {} |
11 changes: 11 additions & 0 deletions
11
value-fixture/src-java-17/org/immutables/fixture/j17/Recs.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,11 @@ | ||
package org.immutables.fixture.j17; | ||
|
||
import org.immutables.builder.Builder; | ||
import org.immutables.value.Value; | ||
|
||
@Value.Enclosing | ||
public sealed interface Recs { | ||
@Builder record One(int aaa) implements Recs {} | ||
|
||
@Builder record Two(String bbb) implements Recs {} | ||
} |
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 @@ | ||
import org.immutables.fixture.j17.ImmutableRecs; | ||
import org.junit.Test; | ||
|
||
public class RecordTest { | ||
@Test public void rec1() { | ||
|
||
} | ||
} |
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
114 changes: 114 additions & 0 deletions
114
value-processor/src/org/immutables/value/processor/meta/RecordComponentCollector.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,114 @@ | ||
/* | ||
Copyright 2014 Immutables Authors and Contributors | ||
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 | ||
http://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 org.immutables.value.processor.meta; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import javax.annotation.Nullable; | ||
import javax.lang.model.element.*; | ||
import javax.lang.model.type.TypeMirror; | ||
import com.google.common.base.Functions; | ||
import com.google.common.base.Throwables; | ||
import com.google.common.collect.FluentIterable; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.Lists; | ||
import org.immutables.value.processor.encode.Instantiator; | ||
import org.immutables.value.processor.encode.Instantiator.InstantiationCreator; | ||
import org.immutables.value.processor.meta.Proto.Protoclass; | ||
|
||
final class RecordComponentCollector { | ||
private final Protoclass protoclass; | ||
private final ValueType type; | ||
private final List<ValueAttribute> attributes = Lists.newArrayList(); | ||
private final Styles styles; | ||
private final Reporter reporter; | ||
|
||
RecordComponentCollector(Protoclass protoclass, ValueType type) { | ||
this.protoclass = protoclass; | ||
this.styles = protoclass.styles(); | ||
this.type = type; | ||
this.reporter = protoclass.report(); | ||
} | ||
|
||
void collect() { | ||
TypeElement recordType = (TypeElement) protoclass.sourceElement(); | ||
|
||
for (ExecutableElement accessor : recordComponentAssessors(recordType)) { | ||
TypeMirror returnType = accessor.getReturnType(); | ||
|
||
ValueAttribute attribute = new ValueAttribute(); | ||
attribute.isGenerateAbstract = true; | ||
attribute.reporter = reporter; | ||
attribute.returnType = returnType; | ||
|
||
attribute.element = accessor; | ||
String parameterName = accessor.getSimpleName().toString(); | ||
attribute.names = styles.forAccessorWithRaw(parameterName, parameterName); | ||
|
||
attribute.containingType = type; | ||
attributes.add(attribute); | ||
} | ||
|
||
Instantiator encodingInstantiator = protoclass.encodingInstantiator(); | ||
|
||
@Nullable InstantiationCreator instantiationCreator = | ||
encodingInstantiator.creatorFor(recordType); | ||
|
||
for (ValueAttribute attribute : attributes) { | ||
attribute.initAndValidate(instantiationCreator); | ||
} | ||
|
||
if (instantiationCreator != null) { | ||
type.additionalImports(instantiationCreator.imports); | ||
} | ||
|
||
type.attributes.addAll(attributes); | ||
} | ||
|
||
// we reflectively access newer annotation processing APIs by still compiling | ||
// to an older version. | ||
private List<ExecutableElement> recordComponentAssessors(TypeElement type) { | ||
type = CachingElements.getDelegate(type); | ||
List<ExecutableElement> accessors = new ArrayList<ExecutableElement>(); | ||
|
||
try { | ||
List<?> components = (List<?>) type.getClass() | ||
.getMethod("getRecordComponents").invoke(type); | ||
|
||
for (Object c : components) { | ||
ExecutableElement accessor = (ExecutableElement) c.getClass().getMethod("getAccessor").invoke(c); | ||
accessors.add(accessor); | ||
} | ||
} catch (IllegalAccessException | ||
| InvocationTargetException | ||
| ClassCastException | ||
| NoSuchMethodException e) { | ||
reporter.withElement(type) | ||
.error("Problem with `TypeElement.getRecordComponents.*.getAccessors`" | ||
+ " from record type mirror, compiler mismatch.\n" | ||
+ Throwables.getStackTraceAsString(e)); | ||
} | ||
return accessors; | ||
} | ||
|
||
private static ImmutableList<String> extractThrowsClause(ExecutableElement factoryMethodElement) { | ||
return FluentIterable.from(factoryMethodElement.getThrownTypes()) | ||
.transform(Functions.toStringFunction()) | ||
.toList(); | ||
} | ||
} |
Oops, something went wrong.