Skip to content

Commit

Permalink
Don't reference AnnotationBinder at runtime.
Browse files Browse the repository at this point in the history
javax.annotation.processing is no longer available at runtime in
Java 10+.
  • Loading branch information
headius committed Feb 12, 2018
1 parent 7b0fbf0 commit acd9a53
Showing 4 changed files with 22 additions and 22 deletions.
20 changes: 2 additions & 18 deletions core/src/main/java/org/jruby/anno/AnnotationBinder.java
Original file line number Diff line number Diff line change
@@ -40,8 +40,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
@@ -249,9 +247,9 @@ public void processType(TypeElement cd) {
// write out a static initializer for frame names, so it only fires once
out.println(" static {");

populateMethodIndex(readGroups,
AnnotationHelper.populateMethodIndex(readGroups,
(bits, names) -> emitIndexCode(bits, names, " MethodIndex.addMethodReadFieldsPacked(%d, \"%s\");"));
populateMethodIndex(writeGroups,
AnnotationHelper.populateMethodIndex(writeGroups,
(bits, names) -> emitIndexCode(bits, names, " MethodIndex.addMethodWriteFieldsPacked(%d, \"%s\");"));

out.println(" }");
@@ -275,20 +273,6 @@ public void emitIndexCode(int bits, String names, String format) {
out.println(String.format(format, bits, names));
}

public static void populateMethodIndex(Map<Set<FrameField>, List<String>> accessGroups, BiConsumer<Integer, String> action) {
if (!accessGroups.isEmpty()) {
for (Map.Entry<Set<FrameField>, List<String>> accessEntry : accessGroups.entrySet()) {
Set<FrameField> reads = accessEntry.getKey();
List<String> names = accessEntry.getValue();

int bits = FrameField.pack(reads.stream().toArray(n -> new FrameField[n]));
String namesJoined = names.stream().collect(Collectors.joining(";"));

action.accept(bits, namesJoined);
}
}
}

private static StringBuilder join(final Iterable<String> names) {
final StringBuilder str = new StringBuilder();
for (String name : names) {
16 changes: 16 additions & 0 deletions core/src/main/java/org/jruby/anno/AnnotationHelper.java
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;

/**
* Utility methods for generating bindings at build time. Used by AnnotationBinder.
@@ -99,5 +101,19 @@ public static void groupFrameFields(Map<Set<FrameField>, List<String>> readGroup
}
}
}

public static void populateMethodIndex(Map<Set<FrameField>, List<String>> accessGroups, BiConsumer<Integer, String> action) {
if (!accessGroups.isEmpty()) {
for (Map.Entry<Set<FrameField>, List<String>> accessEntry : accessGroups.entrySet()) {
Set<FrameField> reads = accessEntry.getKey();
List<String> names = accessEntry.getValue();

int bits = FrameField.pack(reads.stream().toArray(n -> new FrameField[n]));
String namesJoined = names.stream().collect(Collectors.joining(";"));

action.accept(bits, namesJoined);
}
}
}
}

4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/anno/IndyBinder.java
Original file line number Diff line number Diff line change
@@ -274,8 +274,8 @@ public void processType(TypeElement cd) {

mv.start();

AnnotationBinder.populateMethodIndex(readGroups, (bits, names) -> emitIndexCode(bits, names, "addMethodReadFieldsPacked"));
AnnotationBinder.populateMethodIndex(writeGroups, (bits, names) -> emitIndexCode(bits, names, "addMethodWriteFieldsPacked"));
AnnotationHelper.populateMethodIndex(readGroups, (bits, names) -> emitIndexCode(bits, names, "addMethodReadFieldsPacked"));
AnnotationHelper.populateMethodIndex(writeGroups, (bits, names) -> emitIndexCode(bits, names, "addMethodWriteFieldsPacked"));

mv.voidreturn();
mv.end();
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/anno/TypePopulator.java
Original file line number Diff line number Diff line change
@@ -92,8 +92,8 @@ public void populate(final RubyModule target, final Class clazz) {
// fallback on non-pregenerated logic

// populate method index; this is done statically in generated code
AnnotationBinder.populateMethodIndex(clumper.readGroups, MethodIndex::addMethodReadFieldsPacked);
AnnotationBinder.populateMethodIndex(clumper.writeGroups, MethodIndex::addMethodWriteFieldsPacked);
AnnotationHelper.populateMethodIndex(clumper.readGroups, MethodIndex::addMethodReadFieldsPacked);
AnnotationHelper.populateMethodIndex(clumper.writeGroups, MethodIndex::addMethodWriteFieldsPacked);

final Ruby runtime = target.getRuntime();
final MethodFactory methodFactory = MethodFactory.createFactory(runtime.getJRubyClassLoader());

0 comments on commit acd9a53

Please sign in to comment.