Skip to content

Commit 6a60fbf

Browse files
author
vsilaev
committed
Code style fixes
1 parent ead22ec commit 6a60fbf

File tree

18 files changed

+280
-266
lines changed

18 files changed

+280
-266
lines changed

net.tascalate.javaflow.providers.asm3/src/main/java/org/apache/commons/javaflow/providers/asm3/Asm3ContinuableClassInfoResolver.java

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
import org.objectweb.asm.ClassReader;
2929
import org.objectweb.asm.Type;
3030

31-
public class Asm3ContinuableClassInfoResolver implements ContinuableClassInfoResolver {
32-
final private Map<String, ContinuableClassInfo> visitedClasses = new HashMap<String, ContinuableClassInfo>();
33-
final private Set<String> processedAnnotations = new HashSet<String>();
34-
final private Set<String> continuableAnnotations = new HashSet<String>();
35-
final private ResourceLoader resourceLoader;
31+
class Asm3ContinuableClassInfoResolver implements ContinuableClassInfoResolver {
32+
private final Map<String, ContinuableClassInfo> visitedClasses = new HashMap<String, ContinuableClassInfo>();
33+
private final Set<String> processedAnnotations = new HashSet<String>();
34+
private final Set<String> continuableAnnotations = new HashSet<String>();
35+
private final ResourceLoader resourceLoader;
3636

37-
Asm3ContinuableClassInfoResolver(final ResourceLoader classLoader) {
37+
Asm3ContinuableClassInfoResolver(ResourceLoader classLoader) {
3838
this.resourceLoader = classLoader;
3939
markContinuableAnnotation(CONTINUABLE_ANNOTATION_TYPE.getDescriptor());
4040
}
@@ -47,25 +47,25 @@ public ContinuableClassInfo forget(String className) {
4747
return visitedClasses.remove(className);
4848
}
4949

50-
public ContinuableClassInfo resolve(final String classInternalName, final byte[] classBytes) {
50+
public ContinuableClassInfo resolve(String classInternalName, byte[] classBytes) {
5151
return resolveContinuableClassInfo(classInternalName, new ClassReader(classBytes));
5252
}
5353

54-
public ContinuableClassInfo resolve(final String classInternalName) throws IOException {
55-
final InputStream classBytes = resourceLoader.getResourceAsStream(classInternalName + ".class");
54+
public ContinuableClassInfo resolve(String classInternalName) throws IOException {
55+
InputStream classBytes = resourceLoader.getResourceAsStream(classInternalName + ".class");
5656
try {
5757
return resolveContinuableClassInfo(classInternalName, new ClassReader(classBytes));
5858
} finally {
5959
if (null != classBytes)
60-
try { classBytes.close(); } catch (final IOException exIgnore) {}
60+
try { classBytes.close(); } catch (IOException exIgnore) {}
6161
}
6262
}
6363

64-
private ContinuableClassInfo resolveContinuableClassInfo(final String classInternalName, final ClassReader reader) {
64+
private ContinuableClassInfo resolveContinuableClassInfo(String classInternalName, ClassReader reader) {
6565
ContinuableClassInfo classInfo = visitedClasses.get(classInternalName);
6666
if (classInfo == null) {
6767

68-
final MaybeContinuableClassVisitor maybeContinuableClassVisitor = new MaybeContinuableClassVisitor(this);
68+
MaybeContinuableClassVisitor maybeContinuableClassVisitor = new MaybeContinuableClassVisitor(this);
6969
reader.accept(maybeContinuableClassVisitor, ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG);
7070

7171
if (maybeContinuableClassVisitor.isContinuable()) {
@@ -81,9 +81,12 @@ private ContinuableClassInfo resolveContinuableClassInfo(final String classInter
8181
return classInfo == UNSUPPORTED_CLASS_INFO ? null : classInfo;
8282
}
8383

84-
private boolean resolveContinuableAnnotation(final String annotationClassDescriptor, final ClassReader reader) {
85-
final MaybeContinuableAnnotationVisitor maybeContinuableAnnotationVisitor = new MaybeContinuableAnnotationVisitor(this);
86-
reader.accept(maybeContinuableAnnotationVisitor, ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG);
84+
private boolean resolveContinuableAnnotation(String annotationClassDescriptor, ClassReader reader) {
85+
MaybeContinuableAnnotationVisitor maybeContinuableAnnotationVisitor = new MaybeContinuableAnnotationVisitor(this);
86+
reader.accept(
87+
maybeContinuableAnnotationVisitor,
88+
ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG
89+
);
8790

8891
if (maybeContinuableAnnotationVisitor.isContinuable()) {
8992
markContinuableAnnotation(annotationClassDescriptor);
@@ -93,7 +96,7 @@ private boolean resolveContinuableAnnotation(final String annotationClassDescrip
9396
}
9497
}
9598

96-
private AnnotationProcessingState getAnnotationProcessingState(final String annotationClassDescriptor) {
99+
private AnnotationProcessingState getAnnotationProcessingState(String annotationClassDescriptor) {
97100
if (continuableAnnotations.contains(annotationClassDescriptor))
98101
return AnnotationProcessingState.SUPPORTED;
99102
else if (processedAnnotations.contains(annotationClassDescriptor))
@@ -102,16 +105,16 @@ else if (processedAnnotations.contains(annotationClassDescriptor))
102105
return AnnotationProcessingState.UNKNON;
103106
}
104107

105-
private void markProcessedAnnotation(final String annotationClassDescriptor) {
108+
private void markProcessedAnnotation(String annotationClassDescriptor) {
106109
processedAnnotations.add(annotationClassDescriptor);
107110
}
108111

109-
private void markContinuableAnnotation(final String annotationClassDescriptor) {
112+
private void markContinuableAnnotation(String annotationClassDescriptor) {
110113
markProcessedAnnotation(annotationClassDescriptor);
111114
continuableAnnotations.add(annotationClassDescriptor);
112115
}
113116

114-
public boolean isContinuableAnnotation(final String annotationClassDescriptor) {
117+
public boolean isContinuableAnnotation(String annotationClassDescriptor) {
115118
switch (getAnnotationProcessingState(annotationClassDescriptor)) {
116119
case SUPPORTED:
117120
return true;
@@ -122,24 +125,24 @@ public boolean isContinuableAnnotation(final String annotationClassDescriptor) {
122125

123126
final Type type = Type.getType(annotationClassDescriptor);
124127
try {
125-
final InputStream annotationBytes= resourceLoader.getResourceAsStream(type.getInternalName() + ".class");
128+
InputStream annotationBytes= resourceLoader.getResourceAsStream(type.getInternalName() + ".class");
126129
try {
127130
return resolveContinuableAnnotation(annotationClassDescriptor, new ClassReader(annotationBytes));
128131
} finally {
129132
if (null != annotationBytes) {
130-
try { annotationBytes.close(); } catch (final IOException exIgnore) {}
133+
try { annotationBytes.close(); } catch (IOException exIgnore) {}
131134
}
132135
}
133-
} catch (final IOException ex) {
136+
} catch (IOException ex) {
134137
throw new RuntimeException(ex);
135138
}
136139
default:
137140
throw new RuntimeException("Unknown annotation kind");
138141
}
139142
}
140143

141-
final private static Type CONTINUABLE_ANNOTATION_TYPE = Type.getObjectType("org/apache/commons/javaflow/api/ContinuableAnnotation");
142-
final private static ContinuableClassInfo UNSUPPORTED_CLASS_INFO = new ContinuableClassInfo() {
144+
private static final Type CONTINUABLE_ANNOTATION_TYPE = Type.getObjectType("org/apache/commons/javaflow/api/ContinuableAnnotation");
145+
private static final ContinuableClassInfo UNSUPPORTED_CLASS_INFO = new ContinuableClassInfo() {
143146

144147
public void markClassProcessed() {}
145148

net.tascalate.javaflow.providers.asm3/src/main/java/org/apache/commons/javaflow/providers/asm3/ContinuableClassInfoInternal.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222
class ContinuableClassInfoInternal implements ContinuableClassInfo {
2323
private boolean processed;
24-
private Set<String> methods;
24+
private final Set<String> methods;
2525

26-
public ContinuableClassInfoInternal(final boolean defaultProcessed, final Set<String> methods) {
26+
public ContinuableClassInfoInternal(boolean defaultProcessed, Set<String> methods) {
2727
this.processed = defaultProcessed;
2828
this.methods = methods;
2929
}
@@ -36,7 +36,7 @@ public void markClassProcessed() {
3636
processed = true;
3737
}
3838

39-
public boolean isContinuableMethod(final int access, final String name, final String desc, final String signature) {
39+
public boolean isContinuableMethod(int access, String name, String desc, String signature) {
4040
return methods.contains(name + desc);
4141
}
4242

net.tascalate.javaflow.providers.asm3/src/main/java/org/apache/commons/javaflow/providers/asm3/ContinuableMethodNode.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,16 @@ public ContinuableMethodNode(int access, String name, String desc, String signat
7878
}
7979

8080
// Bug in rev 1632 (Refactoring to remove redundant code (and for easier subclassing).
81-
protected LabelNode getLabelNode(final Label l) {
81+
protected LabelNode getLabelNode(Label l) {
8282
if (!(l.info instanceof LabelNode)) {
8383
l.info = new LabelNode(l); // error was here -- new LabelNode(/* nothing */);
8484
}
8585
return (LabelNode)l.info;
8686
}
8787

8888
Frame getFrameByNode(AbstractInsnNode node) {
89-
final int insIndex = instructions.indexOf(node);
90-
final Frame[] frames = analyzer.getFrames();
89+
int insIndex = instructions.indexOf(node);
90+
Frame[] frames = analyzer.getFrames();
9191
return null == frames || insIndex >= frames.length ? null : frames[insIndex];
9292
}
9393

@@ -117,34 +117,34 @@ public void visitEnd() {
117117

118118
analyzer = new Analyzer(new FastClassVerifier(inheritanceLookup)) {
119119
@Override
120-
protected Frame newFrame(final int nLocals, final int nStack) {
120+
protected Frame newFrame(int nLocals, final int nStack) {
121121
return new MonitoringFrame(nLocals, nStack);
122122
}
123123

124124
@Override
125-
protected Frame newFrame(final Frame src) {
125+
protected Frame newFrame(Frame src) {
126126
return new MonitoringFrame(src);
127127
}
128128
};
129129

130130
analyzer.analyze(className, this);
131131
accept(new ContinuableMethodVisitor(this));
132132

133-
} catch (final AnalyzerException ex) {
133+
} catch (AnalyzerException ex) {
134134
throw new RuntimeException(ex);
135135
}
136136
}
137137

138138
void moveNew() throws AnalyzerException {
139-
final SourceInterpreter i = new SourceInterpreter();
140-
final Analyzer a = new Analyzer(i);
139+
SourceInterpreter i = new SourceInterpreter();
140+
Analyzer a = new Analyzer(i);
141141
a.analyze(className, this);
142142

143-
final HashMap<AbstractInsnNode, MethodInsnNode> movable = new HashMap<AbstractInsnNode, MethodInsnNode>();
143+
HashMap<AbstractInsnNode, MethodInsnNode> movable = new HashMap<AbstractInsnNode, MethodInsnNode>();
144144

145-
final Frame[] frames = a.getFrames();
145+
Frame[] frames = a.getFrames();
146146
for (int j = 0; j < methods.size(); j++) {
147-
final MethodInsnNode mnode = (MethodInsnNode) methods.get(j);
147+
MethodInsnNode mnode = (MethodInsnNode) methods.get(j);
148148
// require to move NEW instruction
149149
int n = instructions.indexOf(mnode);
150150
Frame f = frames[n];
@@ -153,7 +153,7 @@ void moveNew() throws AnalyzerException {
153153
SourceValue v = (SourceValue) f.getStack(f.getStackSize() - args.length - 1);
154154
@SuppressWarnings("unchecked")
155155
Set<AbstractInsnNode> insns = v.insns;
156-
for (final AbstractInsnNode ins : insns) {
156+
for (AbstractInsnNode ins : insns) {
157157
if (ins.getOpcode() == NEW) {
158158
movable.put(ins, mnode);
159159
} else {
@@ -176,7 +176,7 @@ void moveNew() throws AnalyzerException {
176176
}
177177

178178
int updateMaxStack = 0;
179-
for (final Map.Entry<AbstractInsnNode, MethodInsnNode> e : movable.entrySet()) {
179+
for (Map.Entry<AbstractInsnNode, MethodInsnNode> e : movable.entrySet()) {
180180
AbstractInsnNode node1 = e.getKey();
181181
int n1 = instructions.indexOf(node1);
182182
AbstractInsnNode node2 = instructions.get(n1 + 1);
@@ -203,7 +203,7 @@ void moveNew() throws AnalyzerException {
203203

204204
// optimizations for some common cases
205205
if (args.length == 0) {
206-
final InsnList doNew = new InsnList();
206+
InsnList doNew = new InsnList();
207207
doNew.add(node1); // NEW
208208
if (requireDup)
209209
doNew.add(new InsnNode(DUP));
@@ -213,7 +213,7 @@ void moveNew() throws AnalyzerException {
213213
}
214214

215215
if (args.length == 1 && args[0].getSize() == 1) {
216-
final InsnList doNew = new InsnList();
216+
InsnList doNew = new InsnList();
217217
doNew.add(node1); // NEW
218218
if (requireDup) {
219219
doNew.add(new InsnNode(DUP));
@@ -231,7 +231,7 @@ void moveNew() throws AnalyzerException {
231231
// TODO this one untested!
232232
if ((args.length == 1 && args[0].getSize() == 2) ||
233233
(args.length == 2 && args[0].getSize() == 1 && args[1].getSize() == 1)) {
234-
final InsnList doNew = new InsnList();
234+
InsnList doNew = new InsnList();
235235
doNew.add(node1); // NEW
236236
if (requireDup) {
237237
doNew.add(new InsnNode(DUP));
@@ -248,7 +248,7 @@ void moveNew() throws AnalyzerException {
248248
continue;
249249
}
250250

251-
final InsnList doNew = new InsnList();
251+
InsnList doNew = new InsnList();
252252
// generic code using temporary locals
253253
// save stack
254254
for (int j = args.length - 1; j >= 0; j--) {
@@ -309,21 +309,21 @@ boolean needsFrameGuard(int opcode, String owner, String name, String desc) {
309309
opcode == Opcodes.INVOKESPECIAL ||
310310
opcode == Opcodes.INVOKESTATIC ||
311311
opcode == Opcodes.INVOKEVIRTUAL) {
312-
final ContinuableClassInfo classInfo;
312+
ContinuableClassInfo classInfo;
313313
try {
314314
classInfo = cciResolver.resolve(owner);
315-
} catch (final IOException ex) {
315+
} catch (IOException ex) {
316316
throw new RuntimeException(ex);
317317
}
318318
return null != classInfo && classInfo.isContinuableMethod(opcode, name, desc, desc);
319319
}
320320
return false;
321321
}
322322

323-
final private static String CONTINUATION_CLASS_INTERNAL_NAME = "org/apache/commons/javaflow/api/Continuation";
324-
final private static Set<String> CONTINUATION_CLASS_CONTINUABLE_METHODS = new HashSet<String>(Arrays.asList(
325-
"suspend", "again", "cancel"
326-
// we are suspending here with potential resume later
327-
// "startWith", "continueWith", "exit" are unnecessary
328-
));
323+
private static final String CONTINUATION_CLASS_INTERNAL_NAME = "org/apache/commons/javaflow/api/Continuation";
324+
private static final Set<String> CONTINUATION_CLASS_CONTINUABLE_METHODS = new HashSet<String>(Arrays.asList(
325+
"suspend", "again", "cancel"
326+
// we are suspending here with potential resume later
327+
// "startWith", "continueWith", "exit" are unnecessary
328+
));
329329
}

net.tascalate.javaflow.providers.asm3/src/main/java/org/apache/commons/javaflow/providers/asm3/ContinuableMethodVisitor.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ public ContinuableMethodVisitor(ContinuableMethodNode a) {
5757
this.stackRecorderVar = a.stackRecorderVar;
5858
}
5959

60-
private static Type[] getArgumentTypes(final AbstractInsnNode node) {
60+
private static Type[] getArgumentTypes(AbstractInsnNode node) {
6161
if (node instanceof MethodInsnNode) {
62-
final MethodInsnNode mnode = (MethodInsnNode)node;
62+
MethodInsnNode mnode = (MethodInsnNode)node;
6363
return Type.getArgumentTypes(mnode.desc);
6464
} else {
6565
throw new RuntimeException("Unexpected node type: " + node);
6666
}
6767
}
6868

69-
private static int getOwnerSize(final AbstractInsnNode node) {
69+
private static int getOwnerSize(AbstractInsnNode node) {
7070
if (node instanceof MethodInsnNode) {
7171
return node.getOpcode() == INVOKESTATIC ? 0 : 1;
7272
} else {
@@ -156,7 +156,7 @@ public void visitCode() {
156156
}
157157

158158
// stack
159-
final Type[] paramTypes = getArgumentTypes(mnode);
159+
Type[] paramTypes = getArgumentTypes(mnode);
160160
int argSize = paramTypes.length;
161161
int ownerSize = getOwnerSize(mnode);
162162
int initSize = mnode.getOpcode() == INVOKESPECIAL && MethodInsnNode.class.cast(mnode).name.equals("<init>") ? 2 : 0;
@@ -231,8 +231,8 @@ public void visitMethodInsn(int opcode, String owner, String name, String desc)
231231
mv.visitJumpInsn(IFEQ, fl);
232232

233233
// save stack
234-
final Type returnType = Type.getReturnType(desc);
235-
final boolean hasReturn = returnType != Type.VOID_TYPE;
234+
Type returnType = Type.getReturnType(desc);
235+
boolean hasReturn = returnType != Type.VOID_TYPE;
236236
if (hasReturn) {
237237
mv.visitInsn(returnType.getSize() == 1 ? POP : POP2);
238238
}
@@ -252,7 +252,7 @@ public void visitMethodInsn(int opcode, String owner, String name, String desc)
252252
mv.visitInsn(SWAP);
253253
mv.visitMethodInsn(INVOKEVIRTUAL, STACK_RECORDER, PUSH_METHOD + "Object", "(Ljava/lang/Object;)V");
254254
} else {
255-
final Type type = value.getType();
255+
Type type = value.getType();
256256
if (type.getSize() > 1) {
257257
mv.visitInsn(ACONST_NULL); // dummy stack entry
258258
mv.visitVarInsn(ALOAD, stackRecorderVar);
@@ -268,17 +268,17 @@ public void visitMethodInsn(int opcode, String owner, String name, String desc)
268268
}
269269
}
270270

271-
final boolean isInstanceMethod = (methodNode.access & ACC_STATIC) == 0;
271+
boolean isInstanceMethod = (methodNode.access & ACC_STATIC) == 0;
272272
if (isInstanceMethod) {
273273
mv.visitVarInsn(ALOAD, stackRecorderVar);
274274
mv.visitVarInsn(ALOAD, 0);
275275
mv.visitMethodInsn(INVOKEVIRTUAL, STACK_RECORDER, PUSH_METHOD + "Reference", "(Ljava/lang/Object;)V");
276276
}
277277

278278
// save locals
279-
final int fsize = currentFrame.getLocals();
279+
int fsize = currentFrame.getLocals();
280280
for (int j = 0; j < fsize; j++) {
281-
final BasicValue value = (BasicValue) currentFrame.getLocal(j);
281+
BasicValue value = (BasicValue) currentFrame.getLocal(j);
282282
if (isNull(value)) {
283283
// no need to save null
284284
} else if (value == BasicValue.UNINITIALIZED_VALUE) {
@@ -303,7 +303,7 @@ public void visitMethodInsn(int opcode, String owner, String name, String desc)
303303
mv.visitMethodInsn(INVOKEVIRTUAL, STACK_RECORDER, "pushInt", "(I)V");
304304

305305
if (currentFrame instanceof MonitoringFrame) {
306-
final int[] monitoredLocals = ((MonitoringFrame) currentFrame).getMonitored();
306+
int[] monitoredLocals = ((MonitoringFrame) currentFrame).getMonitored();
307307
//System.out.println(System.identityHashCode(currentFrame)+" Monitored locals "+monitoredLocals.length);
308308
for (int j = 0; j < monitoredLocals.length; j++) {
309309
//System.out.println(System.identityHashCode(currentFrame)+" Monitored local "+monitoredLocals[j]);
@@ -312,7 +312,7 @@ public void visitMethodInsn(int opcode, String owner, String name, String desc)
312312
}
313313
}
314314

315-
final Type methodReturnType = Type.getReturnType(methodNode.desc);
315+
Type methodReturnType = Type.getReturnType(methodNode.desc);
316316
pushDefault(methodReturnType);
317317
mv.visitInsn(methodReturnType.getOpcode(IRETURN));
318318
mv.visitLabel(fl);
@@ -338,7 +338,7 @@ static boolean isNull(BasicValue value) {
338338
return true;
339339
if (!value.isReference())
340340
return false;
341-
final Type type = value.getType();
341+
Type type = value.getType();
342342
return "Lnull;".equals(type.getDescriptor());
343343
}
344344

0 commit comments

Comments
 (0)