Skip to content
This repository was archived by the owner on Feb 17, 2022. It is now read-only.

Commit 346daf1

Browse files
committed
Move some code, rename some code
1 parent b58710c commit 346daf1

File tree

6 files changed

+33
-32
lines changed

6 files changed

+33
-32
lines changed

src/main/java/io/github/seggan/javaclasslib/attributes/code/CodeAttribute.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.common.primitives.Bytes;
44
import io.github.seggan.javaclasslib.ByteUtils;
55
import io.github.seggan.javaclasslib.attributes.Attribute;
6+
import io.github.seggan.javaclasslib.attributes.code.instructions.JvmInstructionImpl;
67
import io.github.seggan.javaclasslib.constantpool.UTF8Entry;
78

89
import java.io.ByteArrayOutputStream;

src/main/java/io/github/seggan/javaclasslib/attributes/code/instructions/JvmInstruction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.github.seggan.javaclasslib.attributes.code.instructions;
22

3-
public abstract class JvmInstruction {
3+
abstract class JvmInstruction {
44

55
private final byte instructionByte;
66

src/main/java/io/github/seggan/javaclasslib/attributes/code/JvmInstructionImpl.java renamed to src/main/java/io/github/seggan/javaclasslib/attributes/code/instructions/JvmInstructionImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
package io.github.seggan.javaclasslib.attributes.code;
2-
3-
import io.github.seggan.javaclasslib.attributes.code.instructions.JvmInstruction;
1+
package io.github.seggan.javaclasslib.attributes.code.instructions;
42

53
import javax.annotation.Nonnull;
64

src/main/java/io/github/seggan/javaclasslib/attributes/code/instructions/JvmInstructions.java

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.google.common.primitives.Bytes;
44
import io.github.seggan.javaclasslib.ByteUtils;
5-
import io.github.seggan.javaclasslib.attributes.code.JvmInstructionImpl;
65
import io.github.seggan.javaclasslib.constantpool.ClassEntry;
76
import io.github.seggan.javaclasslib.constantpool.ConstantPoolEntry;
87
import io.github.seggan.javaclasslib.constantpool.classmembers.FieldrefEntry;
@@ -25,7 +24,7 @@ public final class JvmInstructions {
2524
* <dd>..., null</dd>
2625
* </dl>
2726
*/
28-
public static final StackInstruction ACONST_NULL = new StackInstruction(0x01);
27+
public static final NoArgInstruction ACONST_NULL = new NoArgInstruction(0x01);
2928
/**
3029
* Loads an object reference from local variable #parameter
3130
*
@@ -83,7 +82,7 @@ public final class JvmInstructions {
8382
* <dd>..., 0.0</dd>
8483
* </dl>
8584
*/
86-
public static final StackInstruction DCONST_0 = new StackInstruction(0x0e);
85+
public static final NoArgInstruction DCONST_0 = new NoArgInstruction(0x0e);
8786
/**
8887
* Pushes {@code 1.0} (a double) onto the stack
8988
*
@@ -93,7 +92,7 @@ public final class JvmInstructions {
9392
* <dd>..., 1.0</dd>
9493
* </dl>
9594
*/
96-
public static final StackInstruction DCONST_1 = new StackInstruction(0x0f);
95+
public static final NoArgInstruction DCONST_1 = new NoArgInstruction(0x0f);
9796
/**
9897
* Loads a double from local variable #parameter
9998
*
@@ -127,7 +126,7 @@ public final class JvmInstructions {
127126
* <dd>..., value, value</dd>
128127
* </dl>
129128
*/
130-
public static final StackInstruction DUP = new StackInstruction(0x59);
129+
public static final NoArgInstruction DUP = new NoArgInstruction(0x59);
131130
/**
132131
* Pushes {@code 0.0} (a float) onto the stack
133132
*
@@ -137,7 +136,7 @@ public final class JvmInstructions {
137136
* <dd>..., 0.0</dd>
138137
* </dl>
139138
*/
140-
public static final StackInstruction FCONST_0 = new StackInstruction(0x0b);
139+
public static final NoArgInstruction FCONST_0 = new NoArgInstruction(0x0b);
141140
/**
142141
* Pushes {@code 1.0} (a float) onto the stack
143142
*
@@ -147,7 +146,7 @@ public final class JvmInstructions {
147146
* <dd>..., 1.0</dd>
148147
* </dl>
149148
*/
150-
public static final StackInstruction FCONST_1 = new StackInstruction(0x0c);
149+
public static final NoArgInstruction FCONST_1 = new NoArgInstruction(0x0c);
151150
/**
152151
* Pushes {@code 2.0} (a float) onto the stack
153152
*
@@ -157,7 +156,7 @@ public final class JvmInstructions {
157156
* <dd>..., 2.0</dd>
158157
* </dl>
159158
*/
160-
public static final StackInstruction FCONST_2 = new StackInstruction(0x0d);
159+
public static final NoArgInstruction FCONST_2 = new NoArgInstruction(0x0d);
161160
/**
162161
* Loads a float from local variable #parameter
163162
*
@@ -237,7 +236,7 @@ public final class JvmInstructions {
237236
* <dd>..., result</dd>
238237
* </dl>
239238
*/
240-
public static final StackInstruction IADD = new StackInstruction(0x60);
239+
public static final NoArgInstruction IADD = new NoArgInstruction(0x60);
241240
/**
242241
* Pushes {@code 0} (an int) onto the stack
243242
*
@@ -247,7 +246,7 @@ public final class JvmInstructions {
247246
* <dd>..., 0</dd>
248247
* </dl>
249248
*/
250-
public static final StackInstruction ICONST_0 = new StackInstruction(0x03);
249+
public static final NoArgInstruction ICONST_0 = new NoArgInstruction(0x03);
251250
/**
252251
* Pushes {@code 1} (an int) onto the stack
253252
*
@@ -257,7 +256,7 @@ public final class JvmInstructions {
257256
* <dd>..., 1</dd>
258257
* </dl>
259258
*/
260-
public static final StackInstruction ICONST_1 = new StackInstruction(0x04);
259+
public static final NoArgInstruction ICONST_1 = new NoArgInstruction(0x04);
261260
/**
262261
* Pushes {@code 2} (an int) onto the stack
263262
*
@@ -267,7 +266,7 @@ public final class JvmInstructions {
267266
* <dd>..., 2</dd>
268267
* </dl>
269268
*/
270-
public static final StackInstruction ICONST_2 = new StackInstruction(0x05);
269+
public static final NoArgInstruction ICONST_2 = new NoArgInstruction(0x05);
271270
/**
272271
* Pushes {@code 3} (an int) onto the stack
273272
*
@@ -277,7 +276,7 @@ public final class JvmInstructions {
277276
* <dd>..., 3</dd>
278277
* </dl>
279278
*/
280-
public static final StackInstruction ICONST_3 = new StackInstruction(0x06);
279+
public static final NoArgInstruction ICONST_3 = new NoArgInstruction(0x06);
281280
/**
282281
* Pushes {@code 4} (an int) onto the stack
283282
*
@@ -287,7 +286,7 @@ public final class JvmInstructions {
287286
* <dd>..., 4</dd>
288287
* </dl>
289288
*/
290-
public static final StackInstruction ICONST_4 = new StackInstruction(0x07);
289+
public static final NoArgInstruction ICONST_4 = new NoArgInstruction(0x07);
291290
/**
292291
* Pushes {@code 5} (an int) onto the stack
293292
*
@@ -297,7 +296,7 @@ public final class JvmInstructions {
297296
* <dd>..., 5</dd>
298297
* </dl>
299298
*/
300-
public static final StackInstruction ICONST_5 = new StackInstruction(0x08);
299+
public static final NoArgInstruction ICONST_5 = new NoArgInstruction(0x08);
301300
/**
302301
* Pushes {@code -1} (an int) onto the stack
303302
*
@@ -307,7 +306,7 @@ public final class JvmInstructions {
307306
* <dd>..., -1</dd>
308307
* </dl>
309308
*/
310-
public static final StackInstruction ICONST_M1 = new StackInstruction(0x02);
309+
public static final NoArgInstruction ICONST_M1 = new NoArgInstruction(0x02);
311310
/**
312311
* If value is not zero, go to another instruction as specified by {@link #GOTO_W}
313312
*
@@ -379,7 +378,7 @@ public final class JvmInstructions {
379378
* <dd>..., result</dd>
380379
* </dl>
381380
*/
382-
public static final StackInstruction ISUB = new StackInstruction(0x64);
381+
public static final NoArgInstruction ISUB = new NoArgInstruction(0x64);
383382
/**
384383
* Pushes {@code 0} (a long) onto the stack
385384
*
@@ -389,7 +388,7 @@ public final class JvmInstructions {
389388
* <dd>..., 0</dd>
390389
* </dl>
391390
*/
392-
public static final StackInstruction LCONST_0 = new StackInstruction(0x09);
391+
public static final NoArgInstruction LCONST_0 = new NoArgInstruction(0x09);
393392
/**
394393
* Pushes {@code 1} (a long) onto the stack
395394
*
@@ -399,7 +398,7 @@ public final class JvmInstructions {
399398
* <dd>..., 1</dd>
400399
* </dl>
401400
*/
402-
public static final StackInstruction LCONST_1 = new StackInstruction(0x0a);
401+
public static final NoArgInstruction LCONST_1 = new NoArgInstruction(0x0a);
403402
/**
404403
* Loads a String, int, float, or Class from the constant pool (index specified by the parameter)
405404
* onto the stack
@@ -487,7 +486,7 @@ public final class JvmInstructions {
487486
* <dd>...,</dd>
488487
* </dl>
489488
*/
490-
public static final StackInstruction POP = new StackInstruction(0x57);
489+
public static final NoArgInstruction POP = new NoArgInstruction(0x57);
491490
/**
492491
* Discards the top two values of the stack, or or the top value if it's a double or
493492
* long
@@ -498,7 +497,7 @@ public final class JvmInstructions {
498497
* <dd>...,</dd>
499498
* </dl>
500499
*/
501-
public static final StackInstruction POP2 = new StackInstruction(0x58);
500+
public static final NoArgInstruction POP2 = new NoArgInstruction(0x58);
502501
/**
503502
* Swaps the top two values on the stack
504503
*
@@ -508,17 +507,17 @@ public final class JvmInstructions {
508507
* <dd>..., value2, value1</dd>
509508
* </dl>
510509
*/
511-
public static final StackInstruction SWAP = new StackInstruction(0x5f);
510+
public static final NoArgInstruction SWAP = new NoArgInstruction(0x5f);
512511

513512
private JvmInstructions() {
514513
}
515514

516515
/**
517-
* An instruction that performs a simple operation on the stack
516+
* An instruction that has no parameters
518517
*/
519-
public static final class StackInstruction extends JvmInstruction {
518+
public static final class NoArgInstruction extends JvmInstruction {
520519

521-
private StackInstruction(int instructionByte) {
520+
private NoArgInstruction(int instructionByte) {
522521
super(instructionByte);
523522
}
524523

@@ -596,7 +595,7 @@ public byte[] getBytes() {
596595
}
597596

598597
/**
599-
* Instructions that branch (e.x. {@code goto})
598+
* An instruction that branches (e.x. {@code goto})
600599
*/
601600
public static final class BranchInstruction extends JvmInstruction {
602601

src/main/java/io/github/seggan/javaclasslib/attributes/code/instructions/SimpleInstructionImpl.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package io.github.seggan.javaclasslib.attributes.code.instructions;
22

3-
import io.github.seggan.javaclasslib.attributes.code.JvmInstructionImpl;
4-
53
import javax.annotation.Nonnull;
64

75
final class SimpleInstructionImpl extends JvmInstructionImpl {

src/main/java/io/github/seggan/javaclasslib/methods/Method.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.common.primitives.Bytes;
44
import io.github.seggan.javaclasslib.ByteUtils;
55
import io.github.seggan.javaclasslib.attributes.Attribute;
6+
import io.github.seggan.javaclasslib.constantpool.ConstantPoolEntry;
67
import io.github.seggan.javaclasslib.constantpool.UTF8Entry;
78

89
import javax.annotation.Nonnull;
@@ -23,6 +24,10 @@ public Method(UTF8Entry name, UTF8Entry descriptor) {
2324
this.descriptor = descriptor;
2425
}
2526

27+
public Method(List<ConstantPoolEntry> constantPool, String name, String descriptor) {
28+
this(new UTF8Entry(constantPool, name), new UTF8Entry(constantPool, descriptor));
29+
}
30+
2631
@Nonnull
2732
public byte[] getBytes() {
2833
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

0 commit comments

Comments
 (0)