made API classes final
This commit is contained in:
parent
df5b271ef2
commit
3598ace9bf
9 changed files with 31 additions and 11 deletions
|
|
@ -8,7 +8,7 @@ import java.util.*;
|
||||||
/**
|
/**
|
||||||
* Models a constructor
|
* Models a constructor
|
||||||
*/
|
*/
|
||||||
public class BeeConstructor extends CodeContainer {
|
public final class BeeConstructor extends CodeContainer {
|
||||||
|
|
||||||
private BeeConstructor(Set<MethodAccessFlags> accessFlags,
|
private BeeConstructor(Set<MethodAccessFlags> accessFlags,
|
||||||
List<BeeParameter> formalParameters,
|
List<BeeParameter> formalParameters,
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,10 @@ import java.util.HashSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class BeeField {
|
/**
|
||||||
|
* Models a field in a BeeClass
|
||||||
|
*/
|
||||||
|
public final class BeeField {
|
||||||
|
|
||||||
private final Set<FieldAccessFlags> accessFlags = new HashSet<>();
|
private final Set<FieldAccessFlags> accessFlags = new HashSet<>();
|
||||||
private final Class<?> type;
|
private final Class<?> type;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,9 @@ import nl.sander.beejava.flags.MethodAccessFlags;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Models a method in a BeeClass
|
||||||
|
*/
|
||||||
public final class BeeMethod extends CodeContainer {
|
public final class BeeMethod extends CodeContainer {
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package nl.sander.beejava.api;
|
||||||
/**
|
/**
|
||||||
* Contains the name of the package for a class
|
* Contains the name of the package for a class
|
||||||
*/
|
*/
|
||||||
public class BeePackage {
|
public final class BeePackage {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import java.util.Objects;
|
||||||
/**
|
/**
|
||||||
* Models a formal parameter in a method declaration.
|
* Models a formal parameter in a method declaration.
|
||||||
*/
|
*/
|
||||||
public class BeeParameter {
|
public final class BeeParameter {
|
||||||
private final Class<?> type;
|
private final Class<?> type;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import java.util.Set;
|
||||||
* End users need to create an instance of this class (using the Builder) and add all fields, methods etc.
|
* End users need to create an instance of this class (using the Builder) and add all fields, methods etc.
|
||||||
* Once created the BeeSource object is immutable.
|
* Once created the BeeSource object is immutable.
|
||||||
*/
|
*/
|
||||||
public class BeeSource {
|
public final class BeeSource {
|
||||||
private final Version classFileVersion;
|
private final Version classFileVersion;
|
||||||
private final BeePackage beePackage;
|
private final BeePackage beePackage;
|
||||||
private final Set<ClassAccessFlags> accessFlags = new HashSet<>();
|
private final Set<ClassAccessFlags> accessFlags = new HashSet<>();
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class CodeLine {
|
public final class CodeLine {
|
||||||
private final int linenumber;
|
private final int linenumber;
|
||||||
private final Opcode opcode;
|
private final Opcode opcode;
|
||||||
private Ref ref;
|
private Ref ref;
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ public class TestData {
|
||||||
.withAccessFlags(PUBLIC, SUPER)
|
.withAccessFlags(PUBLIC, SUPER)
|
||||||
.withSimpleName("EmptyBean")
|
.withSimpleName("EmptyBean")
|
||||||
.withSuperClass(Object.class) // Not mandatory, like in java sourcecode
|
.withSuperClass(Object.class) // Not mandatory, like in java sourcecode
|
||||||
.withConstructors(createConstructor()) // There's no default constructor in beejava. The user must always add them
|
.withConstructors(createDefaultConstructor()) // There's no default constructor in beejava. The user must always add them
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@ public class TestData {
|
||||||
.withSimpleName("EmptyBean")
|
.withSimpleName("EmptyBean")
|
||||||
.withSuperClass(Object.class) // Not mandatory, like in java sourcecode
|
.withSuperClass(Object.class) // Not mandatory, like in java sourcecode
|
||||||
.withInterfaces(Serializable.class)
|
.withInterfaces(Serializable.class)
|
||||||
.withConstructors(createConstructor()) // There's no default constructor in beejava. The user must always add them
|
.withConstructors(createDefaultConstructor()) // There's no default constructor in beejava. The user must always add them
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,7 +64,7 @@ public class TestData {
|
||||||
.withPackage("nl.sander.beejava.test")
|
.withPackage("nl.sander.beejava.test")
|
||||||
.withAccessFlags(PUBLIC, SUPER)
|
.withAccessFlags(PUBLIC, SUPER)
|
||||||
.withSimpleName("ClassWithReferences")
|
.withSimpleName("ClassWithReferences")
|
||||||
.withConstructors(createConstructor()) // There's no default constructor in beejava. The user must always add them
|
.withConstructors(createDefaultConstructor()) // There's no default constructor in beejava. The user must always add them
|
||||||
.withMethods(print1, print2)
|
.withMethods(print1, print2)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
@ -101,7 +101,7 @@ public class TestData {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BeeConstructor createConstructor() throws ClassNotFoundException {
|
public static BeeConstructor createDefaultConstructor() throws ClassNotFoundException {
|
||||||
return BeeConstructor.builder()
|
return BeeConstructor.builder()
|
||||||
.withAccessFlags(MethodAccessFlags.PUBLIC)
|
.withAccessFlags(MethodAccessFlags.PUBLIC)
|
||||||
.withCode(
|
.withCode(
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,13 @@ import nl.sander.beejava.CompiledClass;
|
||||||
import nl.sander.beejava.Compiler;
|
import nl.sander.beejava.Compiler;
|
||||||
import nl.sander.beejava.TestData;
|
import nl.sander.beejava.TestData;
|
||||||
import nl.sander.beejava.api.BeeSource;
|
import nl.sander.beejava.api.BeeSource;
|
||||||
|
import nl.sander.beejava.api.Version;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
|
|
||||||
|
import static nl.sander.beejava.flags.ClassAccessFlags.PUBLIC;
|
||||||
|
import static nl.sander.beejava.flags.ClassAccessFlags.SUPER;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -20,7 +23,7 @@ public class EmptyBeanTest {
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyBean() throws Exception {
|
public void testEmptyBean() throws Exception {
|
||||||
// Arrange
|
// Arrange
|
||||||
BeeSource emptyClass = TestData.createEmptyClass();
|
BeeSource emptyClass = createEmptyClass();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
CompiledClass compiledClass = Compiler.compile(emptyClass);
|
CompiledClass compiledClass = Compiler.compile(emptyClass);
|
||||||
|
|
@ -37,4 +40,15 @@ public class EmptyBeanTest {
|
||||||
assertNotNull(instance);
|
assertNotNull(instance);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BeeSource createEmptyClass() throws ClassNotFoundException {
|
||||||
|
return BeeSource.builder()
|
||||||
|
.withClassFileVersion(Version.V14)
|
||||||
|
.withPackage("nl.sander.beejava.test")
|
||||||
|
.withAccessFlags(PUBLIC, SUPER)
|
||||||
|
.withSimpleName("EmptyBean")
|
||||||
|
.withSuperClass(Object.class) // Not mandatory, like in java sourcecode
|
||||||
|
.withConstructors(TestData.createDefaultConstructor()) // There's no default constructor in beejava. The user must always add them
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue