Skip to content

Commit 41b8f6c

Browse files
authored
Merge pull request #5 from formkiq/v1.2.0
added support for "allowUnsafeAccess" on fields
2 parents 4c4f228 + 1cf494f commit 41b8f6c

File tree

14 files changed

+1154
-33
lines changed

14 files changed

+1154
-33
lines changed

.checkstyle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
4+
<local-check-config name="checks" location="/config/checkstyle/checkstyle.xml" type="project" description="">
5+
<property name="checkstyle.dir" value="/config/checkstyle"/>
6+
<additional-data name="protect-config-file" value="false"/>
7+
</local-check-config>
8+
<fileset name="all" enabled="true" check-config-name="checks" local="true">
9+
<file-match-pattern match-pattern="." include-pattern="true"/>
10+
</fileset>
11+
</fileset-config>
12+

.classpath

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="bin/main" path="src/main/java">
4+
<attributes>
5+
<attribute name="gradle_scope" value="main"/>
6+
<attribute name="gradle_used_by_scope" value="main,test"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry kind="src" output="bin/main" path="src/main/resources">
10+
<attributes>
11+
<attribute name="gradle_scope" value="main"/>
12+
<attribute name="gradle_used_by_scope" value="main,test"/>
13+
</attributes>
14+
</classpathentry>
15+
<classpathentry kind="src" output="bin/test" path="src/test/java">
16+
<attributes>
17+
<attribute name="gradle_scope" value="test"/>
18+
<attribute name="gradle_used_by_scope" value="test"/>
19+
<attribute name="test" value="true"/>
20+
</attributes>
21+
</classpathentry>
22+
<classpathentry kind="src" output="bin/test" path="src/test/resources">
23+
<attributes>
24+
<attribute name="gradle_scope" value="test"/>
25+
<attribute name="gradle_used_by_scope" value="test"/>
26+
<attribute name="test" value="true"/>
27+
</attributes>
28+
</classpathentry>
29+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
30+
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
31+
<classpathentry kind="output" path="bin/default"/>
32+
</classpath>

.project

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>graalvm-annotations-processor</name>
4+
<comment>Project graalvm-annotations-processor created by Buildship.</comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
</buildSpec>
24+
<natures>
25+
<nature>org.eclipse.jdt.core.javanature</nature>
26+
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
27+
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
28+
</natures>
29+
</projectDescription>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
connection.project.dir=
2+
eclipse.preferences.version=1

.settings/org.eclipse.jdt.core.prefs

Lines changed: 496 additions & 0 deletions
Large diffs are not rendered by default.

.settings/org.eclipse.jdt.ui.prefs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
eclipse.preferences.version=1
2+
formatter_profile=_GoogleStyle
3+
formatter_settings_version=16

build.gradle

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ sourceCompatibility = JavaVersion.VERSION_11
2222
targetCompatibility = JavaVersion.VERSION_11
2323

2424
group 'com.formkiq'
25-
version '1.1.1'
25+
version '1.2.0'
2626

2727
dependencies {
2828
annotationProcessor group: 'com.google.auto.service', name: 'auto-service', version: '1.0-rc7'
2929
compileOnly group: 'com.google.auto.service', name: 'auto-service', version: '1.0-rc7'
3030
compileOnly group: 'com.google.auto.service', name: 'auto-service-annotations', version: '1.0-rc7'
3131

32-
implementation group: 'com.formkiq', name: 'graalvm-annotations', version: '1.0.0'
32+
implementation group: 'com.formkiq', name: 'graalvm-annotations', version: '1.1.0'
3333
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
3434
testImplementation group: 'junit', name: 'junit', version:'4.+'
3535
testImplementation group: 'com.google.testing.compile', name: 'compile-testing', version: '0.18'
@@ -73,6 +73,7 @@ tasks.withType(Checkstyle).each { checkstyleTask ->
7373
}
7474

7575
repositories {
76+
mavenLocal()
7677
mavenCentral()
7778
}
7879

@@ -146,3 +147,9 @@ publishing {
146147
signing {
147148
sign publishing.publications.mavenJava
148149
}
150+
151+
check {
152+
dependsOn(tasks.publishToMavenLocal)
153+
}
154+
155+
spotlessJavaCheck.dependsOn spotlessJavaApply

spotless.eclipseformat.xml

Lines changed: 348 additions & 0 deletions
Large diffs are not rendered by default.

src/main/java/com/formkiq/graalvm/processors/GraalvmReflectAnnontationProcessor.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ private String getClassName(final Element element) {
114114
*/
115115
private Reflect getReflect(final String className) {
116116

117-
Reflect reflect = reflects.getOrDefault(className, null);
117+
Reflect reflect = this.reflects.getOrDefault(className, null);
118118

119119
if (reflect == null) {
120120
reflect = new Reflect();
121-
reflects.put(className, reflect);
121+
this.reflects.put(className, reflect);
122122
LOGGER.log(LOGLEVEL, "creating new Element");
123123
} else {
124124
LOGGER.log(LOGLEVEL, "appending to previous Element");
@@ -158,12 +158,12 @@ private Reflect processClass(final Reflect reflect, final Reflectable reflectabl
158158

159159
LOGGER.log(LOGLEVEL, "processClass " + reflect.name());
160160
reflect
161-
.allDeclaredConstructors(reflectable.allDeclaredConstructors())
162-
.allDeclaredFields(reflectable.allDeclaredFields())
163-
.allDeclaredMethods(reflectable.allDeclaredMethods())
164-
.allPublicConstructors(reflectable.allPublicConstructors())
165-
.allPublicFields(reflectable.allPublicFields())
166-
.allPublicMethods(reflectable.allPublicMethods());
161+
.allDeclaredConstructors(Boolean.valueOf(reflectable.allDeclaredConstructors()))
162+
.allDeclaredFields(Boolean.valueOf(reflectable.allDeclaredFields()))
163+
.allDeclaredMethods(Boolean.valueOf(reflectable.allDeclaredMethods()))
164+
.allPublicConstructors(Boolean.valueOf(reflectable.allPublicConstructors()))
165+
.allPublicFields(Boolean.valueOf(reflectable.allPublicFields()))
166+
.allPublicMethods(Boolean.valueOf(reflectable.allPublicMethods()));
167167

168168
return reflect;
169169
}
@@ -179,12 +179,12 @@ private Reflect processClass(final Reflect reflect, final ReflectableClass refle
179179

180180
LOGGER.log(LOGLEVEL, "processClass " + reflect.name());
181181
reflect
182-
.allDeclaredConstructors(reflectable.allDeclaredConstructors())
183-
.allDeclaredFields(reflectable.allDeclaredFields())
184-
.allDeclaredMethods(reflectable.allDeclaredMethods())
185-
.allPublicConstructors(reflectable.allPublicConstructors())
186-
.allPublicFields(reflectable.allPublicFields())
187-
.allPublicMethods(reflectable.allPublicMethods());
182+
.allDeclaredConstructors(Boolean.valueOf(reflectable.allDeclaredConstructors()))
183+
.allDeclaredFields(Boolean.valueOf(reflectable.allDeclaredFields()))
184+
.allDeclaredMethods(Boolean.valueOf(reflectable.allDeclaredMethods()))
185+
.allPublicConstructors(Boolean.valueOf(reflectable.allPublicConstructors()))
186+
.allPublicFields(Boolean.valueOf(reflectable.allPublicFields()))
187+
.allPublicMethods(Boolean.valueOf(reflectable.allPublicMethods()));
188188

189189
return reflect;
190190
}
@@ -208,7 +208,7 @@ private void processImportedClass(final String clazz) {
208208
Reflectable reflection = field.getAnnotation(Reflectable.class);
209209
if (reflection != null) {
210210
LOGGER.log(LOGLEVEL, "adding Field " + field.getName() + " to " + clazz);
211-
reflect.addField(field.getName(), reflectable.allowWrite());
211+
reflect.addField(field.getName(), reflection.allowWrite(), false);
212212
}
213213
}
214214

@@ -305,7 +305,7 @@ private void processImportFiles(final Element element) {
305305
ClassLoader classLoader = getClass().getClassLoader();
306306
URL resource = classLoader.getResource(file);
307307
String data = Files.readString(new File(resource.getFile()).toPath());
308-
List<Map<String, Object>> list = gson.fromJson(data, List.class);
308+
List<Map<String, Object>> list = this.gson.fromJson(data, List.class);
309309

310310
for (Map<String, Object> map : list) {
311311
Reflect reflect = getReflect(map.get("name").toString());
@@ -384,7 +384,7 @@ private void processReflectableClass(final ReflectableClass reflectable) {
384384

385385
for (ReflectableField field : reflectable.fields()) {
386386
LOGGER.log(LOGLEVEL, "adding Field " + field.name() + " to " + className);
387-
reflect.addField(field.name(), field.allowWrite());
387+
reflect.addField(field.name(), field.allowWrite(), field.allowUnsafeAccess());
388388
}
389389

390390
for (ReflectableMethod method : reflectable.methods()) {
@@ -446,7 +446,7 @@ private void processingReflectable(final RoundEnvironment roundEnv) {
446446
case FIELD:
447447
String fieldName = element.getSimpleName().toString();
448448
LOGGER.log(LOGLEVEL, "adding Field " + fieldName + " to " + className);
449-
reflect.addField(fieldName, reflectable.allowWrite());
449+
reflect.addField(fieldName, reflectable.allowWrite(), false);
450450
break;
451451
case CONSTRUCTOR:
452452
case METHOD:
@@ -492,15 +492,15 @@ private void writeOutput() {
492492
try {
493493

494494
FileObject file =
495-
processingEnv
495+
this.processingEnv
496496
.getFiler()
497497
.createResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/graal/reflect.json");
498498

499499
List<Map<String, Object>> data =
500500
this.reflects.values().stream().map(r -> r.data()).collect(Collectors.toList());
501501

502502
try (Writer w = new OutputStreamWriter(file.openOutputStream(), "UTF-8")) {
503-
w.write(gson.toJson(data));
503+
w.write(this.gson.toJson(data));
504504
}
505505

506506
} catch (IOException e) {

src/main/java/com/formkiq/graalvm/processors/Reflect.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ public Reflect() {}
3131
*
3232
* @param fieldName {@link String}
3333
* @param allowWrite boolean
34+
* @param allowUnsafeAccess boolean
3435
*/
3536
@SuppressWarnings("unchecked")
36-
public void addField(final String fieldName, final boolean allowWrite) {
37+
public void addField(
38+
final String fieldName, final boolean allowWrite, final boolean allowUnsafeAccess) {
3739

3840
if (!this.data.containsKey("methods")) {
3941
this.data.put("methods", new ArrayList<>());
@@ -43,7 +45,12 @@ public void addField(final String fieldName, final boolean allowWrite) {
4345
this.data.put("fields", new ArrayList<>());
4446
}
4547

46-
Map<String, Object> map = Map.of("allowWrite", allowWrite, "name", fieldName);
48+
Map<String, Object> map =
49+
new HashMap<>(Map.of("allowWrite", Boolean.valueOf(allowWrite), "name", fieldName));
50+
if (allowUnsafeAccess) {
51+
map.put("allowUnsafeAccess", Boolean.valueOf(allowUnsafeAccess));
52+
}
53+
4754
((List<Map<String, Object>>) this.data.get("fields")).add(map);
4855
}
4956

0 commit comments

Comments
 (0)