From ad840e2d40b7f2834578928d6207b2ca8c82c540 Mon Sep 17 00:00:00 2001 From: Max Roncace Date: Mon, 9 Sep 2019 11:43:41 -0400 Subject: [PATCH 01/10] Initial draft of reference API --- .../bombe/type/reference/ClassReference.java | 37 +++++++++++++++++++ .../bombe/type/reference/FieldReference.java | 17 +++++++++ .../type/reference/InnerClassReference.java | 37 +++++++++++++++++++ .../bombe/type/reference/MemberReference.java | 24 ++++++++++++ .../reference/MethodParameterReference.java | 22 +++++++++++ .../bombe/type/reference/MethodReference.java | 26 +++++++++++++ .../type/reference/QualifiedReference.java | 28 ++++++++++++++ .../reference/TopLevelClassReference.java | 11 ++++++ 8 files changed, 202 insertions(+) create mode 100644 bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java create mode 100644 bombe/src/main/java/org/cadixdev/bombe/type/reference/FieldReference.java create mode 100644 bombe/src/main/java/org/cadixdev/bombe/type/reference/InnerClassReference.java create mode 100644 bombe/src/main/java/org/cadixdev/bombe/type/reference/MemberReference.java create mode 100644 bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodParameterReference.java create mode 100644 bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodReference.java create mode 100644 bombe/src/main/java/org/cadixdev/bombe/type/reference/QualifiedReference.java create mode 100644 bombe/src/main/java/org/cadixdev/bombe/type/reference/TopLevelClassReference.java diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java new file mode 100644 index 0000000..e9bab34 --- /dev/null +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java @@ -0,0 +1,37 @@ +package org.cadixdev.bombe.type.reference; + +import org.cadixdev.bombe.type.ObjectType; +import org.cadixdev.bombe.type.signature.FieldSignature; +import org.cadixdev.bombe.type.signature.MethodSignature; + +public abstract class ClassReference extends QualifiedReference { + + protected static final char INNER_CLASS_SEPARATOR_CHAR = '$'; + + protected final ObjectType classType; + + public ClassReference(Type type, ObjectType classType) { + super(type); + this.classType = classType; + } + + public ObjectType getClassType() { + return classType; + } + + public InnerClassReference getInnerClass(String unqualifiedName) { + return new InnerClassReference( + this, + new ObjectType(this.getClassType().getClassName() + INNER_CLASS_SEPARATOR_CHAR + unqualifiedName) + ); + } + + public FieldReference getField(FieldSignature signature) { + return new FieldReference(this, signature); + } + + public MethodReference getMethod(MethodSignature signature) { + return new MethodReference(this, signature); + } + +} diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/FieldReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/FieldReference.java new file mode 100644 index 0000000..730cc13 --- /dev/null +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/FieldReference.java @@ -0,0 +1,17 @@ +package org.cadixdev.bombe.type.reference; + +import org.cadixdev.bombe.type.ObjectType; +import org.cadixdev.bombe.type.signature.FieldSignature; + +public class FieldReference extends MemberReference { + + public FieldReference(ClassReference owningClass, FieldSignature signature) { + super(Type.FIELD, owningClass, signature); + } + + @Override + public FieldSignature getSignature() { + return (FieldSignature) signature; + } + +} diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/InnerClassReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/InnerClassReference.java new file mode 100644 index 0000000..dfd5e0c --- /dev/null +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/InnerClassReference.java @@ -0,0 +1,37 @@ +package org.cadixdev.bombe.type.reference; + +import org.cadixdev.bombe.type.ObjectType; + +public class InnerClassReference extends ClassReference { + + private static ClassReference deriveParentClass(ObjectType classType) { + if (classType.getClassName().indexOf(INNER_CLASS_SEPARATOR_CHAR) < 0) { + throw new IllegalArgumentException("Cannot derive parent class from non-inner class identifier"); + } + + ObjectType parentType = new ObjectType( + classType.getClassName().substring(0, classType.getClassName().lastIndexOf('$')) + ); + if (parentType.getClassName().indexOf(INNER_CLASS_SEPARATOR_CHAR) >= 0) { + return new InnerClassReference(parentType); + } else { + return new TopLevelClassReference(parentType); + } + } + + private final ClassReference parentClass; + + public InnerClassReference(ClassReference parentClass, ObjectType classType) { + super(Type.INNER_CLASS, classType); + this.parentClass = parentClass; + } + + public InnerClassReference(ObjectType classType) { + this(deriveParentClass(classType), classType); + } + + public ClassReference getParentClass() { + return parentClass; + } + +} diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MemberReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MemberReference.java new file mode 100644 index 0000000..c27dfd8 --- /dev/null +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MemberReference.java @@ -0,0 +1,24 @@ +package org.cadixdev.bombe.type.reference; + +import org.cadixdev.bombe.type.signature.MemberSignature; + +public abstract class MemberReference extends QualifiedReference { + + protected final ClassReference owningClass; + protected final MemberSignature signature; + + public MemberReference(Type type, ClassReference owningClass, MemberSignature signature) { + super(type); + this.owningClass = owningClass; + this.signature = signature; + } + + public ClassReference getOwningClass() { + return owningClass; + } + + public MemberSignature getSignature() { + return signature; + } + +} diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodParameterReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodParameterReference.java new file mode 100644 index 0000000..5892053 --- /dev/null +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodParameterReference.java @@ -0,0 +1,22 @@ +package org.cadixdev.bombe.type.reference; + +public class MethodParameterReference extends QualifiedReference { + + private final MethodReference parentMethod; + private final int index; + + public MethodParameterReference(MethodReference parentMethod, int index) { + super(Type.METHOD_PARAMETER); + this.parentMethod = parentMethod; + this.index = index; + } + + public MethodReference getParentMethod() { + return parentMethod; + } + + public int getParameterIndex() { + return index; + } + +} diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodReference.java new file mode 100644 index 0000000..403fe8c --- /dev/null +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodReference.java @@ -0,0 +1,26 @@ +package org.cadixdev.bombe.type.reference; + +import org.cadixdev.bombe.type.ObjectType; +import org.cadixdev.bombe.type.signature.FieldSignature; +import org.cadixdev.bombe.type.signature.MethodSignature; + +public class MethodReference extends MemberReference { + + public MethodReference(ClassReference owningClass, MethodSignature signature) { + super(Type.METHOD, owningClass, signature); + } + + @Override + public MethodSignature getSignature() { + return (MethodSignature) signature; + } + + public MethodParameterReference getParameter(int index) { + if (index >= getSignature().getDescriptor().getParamTypes().size()) { + throw new IllegalArgumentException("Cannot get out-of-bounds parameter index " + index); + } + + return new MethodParameterReference(this, index); + } + +} diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/QualifiedReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/QualifiedReference.java new file mode 100644 index 0000000..90db6aa --- /dev/null +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/QualifiedReference.java @@ -0,0 +1,28 @@ +package org.cadixdev.bombe.type.reference; + +import org.cadixdev.bombe.type.ObjectType; + +/** + * Represents a unique, qualified path to a class, class member, or method + * parameter. + * + * @author Max Roncace + * @since 0.3.0 + */ +public abstract class QualifiedReference { + + protected final Type type; + + public QualifiedReference(Type type) { + this.type = type; + } + + public enum Type { + TOP_LEVEL_CLASS, + INNER_CLASS, + FIELD, + METHOD, + METHOD_PARAMETER + } + +} diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/TopLevelClassReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/TopLevelClassReference.java new file mode 100644 index 0000000..e02a650 --- /dev/null +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/TopLevelClassReference.java @@ -0,0 +1,11 @@ +package org.cadixdev.bombe.type.reference; + +import org.cadixdev.bombe.type.ObjectType; + +public class TopLevelClassReference extends ClassReference { + + public TopLevelClassReference(ObjectType classType) { + super(Type.TOP_LEVEL_CLASS, classType); + } + +} From 47095624144aea9e16ab2d75b6114916cda80ac5 Mon Sep 17 00:00:00 2001 From: Max Roncace Date: Mon, 9 Sep 2019 12:15:04 -0400 Subject: [PATCH 02/10] Add documentation to reference classes --- .../bombe/type/reference/ClassReference.java | 37 +++++++++++++++++++ .../bombe/type/reference/FieldReference.java | 21 +++++++---- .../type/reference/InnerClassReference.java | 37 ++++++++++++++++++- .../bombe/type/reference/MemberReference.java | 33 +++++++++++++++-- .../reference/MethodParameterReference.java | 31 +++++++++++++++- .../bombe/type/reference/MethodReference.java | 33 +++++++++++------ .../type/reference/QualifiedReference.java | 13 +++++-- .../reference/TopLevelClassReference.java | 18 +++++++++ 8 files changed, 195 insertions(+), 28 deletions(-) diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java index e9bab34..7abb9c7 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java @@ -4,21 +4,46 @@ import org.cadixdev.bombe.type.signature.FieldSignature; import org.cadixdev.bombe.type.signature.MethodSignature; +/** + * Represents a unique, qualified path to a class. + * + * @author Max Roncace + * @since 0.3.1 + */ public abstract class ClassReference extends QualifiedReference { protected static final char INNER_CLASS_SEPARATOR_CHAR = '$'; protected final ObjectType classType; + /** + * Constructs a new reference to a class. + * + * @param type The {@link Type} of reference (must be + * {@link Type#TOP_LEVEL_CLASS} or {@link Type#INNER_CLASS}) + * @param classType An {@link ObjectType} representing the type of the + * referenced class + */ public ClassReference(Type type, ObjectType classType) { super(type); this.classType = classType; } + /** + * Returns the type of class represented by this reference + * + * @return The type of class + */ public ObjectType getClassType() { return classType; } + /** + * Returns a reference to an inner class of this class. + * + * @param unqualifiedName The unqualified name of the inner class + * @return A reference to the inner class + */ public InnerClassReference getInnerClass(String unqualifiedName) { return new InnerClassReference( this, @@ -26,10 +51,22 @@ public InnerClassReference getInnerClass(String unqualifiedName) { ); } + /** + * Returns a reference to a field contained by this class. + * + * @param signature The {@link FieldSignature signature} of the field + * @return A reference to the field + */ public FieldReference getField(FieldSignature signature) { return new FieldReference(this, signature); } + /** + * Returns a reference to a method contained by this class. + * + * @param signature The {@link MethodSignature signature} of the method + * @return A reference to the method + */ public MethodReference getMethod(MethodSignature signature) { return new MethodReference(this, signature); } diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/FieldReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/FieldReference.java index 730cc13..0ec4736 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/FieldReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/FieldReference.java @@ -1,17 +1,24 @@ package org.cadixdev.bombe.type.reference; -import org.cadixdev.bombe.type.ObjectType; import org.cadixdev.bombe.type.signature.FieldSignature; -public class FieldReference extends MemberReference { +/** + * Represents a unique, qualified path to a field of a + * {@link ClassReference class}. + * + * @author Max Roncace + * @since 0.3.1 + */ +public class FieldReference extends MemberReference { + /** + * Constructs a new reference to a class field. + * + * @param owningClass The class containing the field + * @param signature The signature of the field + */ public FieldReference(ClassReference owningClass, FieldSignature signature) { super(Type.FIELD, owningClass, signature); } - @Override - public FieldSignature getSignature() { - return (FieldSignature) signature; - } - } diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/InnerClassReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/InnerClassReference.java index dfd5e0c..fc33950 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/InnerClassReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/InnerClassReference.java @@ -2,9 +2,22 @@ import org.cadixdev.bombe.type.ObjectType; +/** + * Represents a unique, qualified path to an inner {@link ClassReference class}. + * + * @author Max Roncace + * @since 0.3.1 + */ public class InnerClassReference extends ClassReference { - private static ClassReference deriveParentClass(ObjectType classType) { + /** + * Derives the parent of an inner class based on its identifier. + * + * @param classType The full type of the inner class + * @return A reference to the parent class + * @throws IllegalArgumentException If the given type is not an inner class + */ + private static ClassReference deriveParentClass(ObjectType classType) throws IllegalArgumentException { if (classType.getClassName().indexOf(INNER_CLASS_SEPARATOR_CHAR) < 0) { throw new IllegalArgumentException("Cannot derive parent class from non-inner class identifier"); } @@ -21,15 +34,35 @@ private static ClassReference deriveParentClass(ObjectType classType) { private final ClassReference parentClass; - public InnerClassReference(ClassReference parentClass, ObjectType classType) { + /** + * Constructs a new reference to an inner class. + * + * @param parentClass The parent class to the inner class + * @param classType The full type of the inner class + */ + InnerClassReference(ClassReference parentClass, ObjectType classType) { super(Type.INNER_CLASS, classType); + + assert(classType.getClassName().substring(0, classType.getClassName().lastIndexOf(INNER_CLASS_SEPARATOR_CHAR)) + .equals(parentClass.classType.getClassName())); + this.parentClass = parentClass; } + /** + * Constructs a new reference to an inner class. + * + * @param classType The full type of the inner class + */ public InnerClassReference(ObjectType classType) { this(deriveParentClass(classType), classType); } + /** + * Gets a reference to the parent class of this inner class. + * + * @return The parent class + */ public ClassReference getParentClass() { return parentClass; } diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MemberReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MemberReference.java index c27dfd8..5bc0ce6 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MemberReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MemberReference.java @@ -2,21 +2,48 @@ import org.cadixdev.bombe.type.signature.MemberSignature; -public abstract class MemberReference extends QualifiedReference { +/** + * Represents a unique, qualified path to a {@link ClassReference class} member. + * + * @param The {@link MemberSignature} type used by this reference + * + * @author Max Roncace + * @since 0.3.1 + */ +public abstract class MemberReference extends QualifiedReference { protected final ClassReference owningClass; - protected final MemberSignature signature; + protected final S signature; - public MemberReference(Type type, ClassReference owningClass, MemberSignature signature) { + /** + * Constructs a new reference to a class member. + * + * @param type The type of reference (must be either {@link Type#FIELD} or + * {@link Type#METHOD}. + * + * @param owningClass A reference to the class which owns the member + * @param signature The signature of the member + */ + public MemberReference(Type type, ClassReference owningClass, S signature) { super(type); this.owningClass = owningClass; this.signature = signature; } + /** + * Gets the class which owns this member. + * + * @return The class which owns this member + */ public ClassReference getOwningClass() { return owningClass; } + /** + * Gets the signature of this member. + * + * @return The signature of this member + */ public MemberSignature getSignature() { return signature; } diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodParameterReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodParameterReference.java index 5892053..d9e104d 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodParameterReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodParameterReference.java @@ -1,20 +1,49 @@ package org.cadixdev.bombe.type.reference; +/** + * Represents a unique, qualified path to a parameter of a + * {@link MethodReference method}. + * + * @author Max Roncace + * @since 0.3.1 + */ public class MethodParameterReference extends QualifiedReference { private final MethodReference parentMethod; private final int index; - public MethodParameterReference(MethodReference parentMethod, int index) { + /** + * Constructs a new reference to a method parameter. + * + * @param parentMethod The method specifying the parameter + * @param index The index of the parameter (0-indexed) + * @throws IllegalArgumentException If the parameter index of out-of-bounds + */ + public MethodParameterReference(MethodReference parentMethod, int index) throws IllegalArgumentException { super(Type.METHOD_PARAMETER); + + if (index >= parentMethod.getSignature().getDescriptor().getParamTypes().size()) { + throw new IllegalArgumentException("Cannot get out-of-bounds parameter index " + index); + } + this.parentMethod = parentMethod; this.index = index; } + /** + * Gets the method specifying this parameter. + * + * @return The method specifying this parameter + */ public MethodReference getParentMethod() { return parentMethod; } + /** + * Gets the index of this parameter (0-indexed). + * + * @return The index of this parameter + */ public int getParameterIndex() { return index; } diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodReference.java index 403fe8c..a3fe10e 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodReference.java @@ -1,25 +1,34 @@ package org.cadixdev.bombe.type.reference; -import org.cadixdev.bombe.type.ObjectType; -import org.cadixdev.bombe.type.signature.FieldSignature; import org.cadixdev.bombe.type.signature.MethodSignature; -public class MethodReference extends MemberReference { +/** + * Represents a unique, qualified path to a method of a + * {@link ClassReference class}. + * + * @author Max Roncace + * @since 0.3.1 + */ +public class MethodReference extends MemberReference { + /** + * Constructs a new reference to a class method. + * + * @param owningClass The class containing the method + * @param signature The signature of the method + */ public MethodReference(ClassReference owningClass, MethodSignature signature) { super(Type.METHOD, owningClass, signature); } - @Override - public MethodSignature getSignature() { - return (MethodSignature) signature; - } - + /** + * Returns a reference to the parameter of this method with the given index. + * + * @param index The index of the parameter + * @return A refernce to the parameter + * @throws IllegalArgumentException If the parameter index is out-of-bounds + */ public MethodParameterReference getParameter(int index) { - if (index >= getSignature().getDescriptor().getParamTypes().size()) { - throw new IllegalArgumentException("Cannot get out-of-bounds parameter index " + index); - } - return new MethodParameterReference(this, index); } diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/QualifiedReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/QualifiedReference.java index 90db6aa..b91d5e9 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/QualifiedReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/QualifiedReference.java @@ -1,13 +1,11 @@ package org.cadixdev.bombe.type.reference; -import org.cadixdev.bombe.type.ObjectType; - /** * Represents a unique, qualified path to a class, class member, or method * parameter. * * @author Max Roncace - * @since 0.3.0 + * @since 0.3.1 */ public abstract class QualifiedReference { @@ -17,6 +15,15 @@ public QualifiedReference(Type type) { this.type = type; } + /** + * Returns the {@link Type} of this reference. + * + * @return The {@link Type} of this reference + */ + public Type getType() { + return type; + } + public enum Type { TOP_LEVEL_CLASS, INNER_CLASS, diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/TopLevelClassReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/TopLevelClassReference.java index e02a650..a01e9c1 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/TopLevelClassReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/TopLevelClassReference.java @@ -2,10 +2,28 @@ import org.cadixdev.bombe.type.ObjectType; +/** + * Represents a unique, qualified path to a top-level + * {@link ClassReference class}. + * + * @author Max Roncace + * @since 0.3.1 + */ public class TopLevelClassReference extends ClassReference { + /** + * Constructs a new reference to a top-level class. + * + * @param classType The type of the class + * @throws IllegalArgumentException If the given type represents an inner + * class + */ public TopLevelClassReference(ObjectType classType) { super(Type.TOP_LEVEL_CLASS, classType); + + if (classType.getClassName().indexOf(INNER_CLASS_SEPARATOR_CHAR) >= 0) { + throw new IllegalArgumentException("Cannot create top-level class reference from inner class identifier"); + } } } From 7fc5ef8ac20936edb847e2869415fc1738a69d37 Mon Sep 17 00:00:00 2001 From: Max Roncace Date: Mon, 9 Sep 2019 13:18:26 -0400 Subject: [PATCH 03/10] Implement JVMS identifier generation and equals/hashCode for references --- .../bombe/type/reference/ClassReference.java | 17 +++++++++++ .../bombe/type/reference/FieldReference.java | 1 - .../bombe/type/reference/MemberReference.java | 23 +++++++++++++-- .../reference/MethodParameterReference.java | 20 +++++++++++++ .../type/reference/QualifiedReference.java | 28 +++++++++++++++++++ .../bombe/type/signature/FieldSignature.java | 5 ++++ .../bombe/type/signature/MemberSignature.java | 18 ++++++++++++ .../bombe/type/signature/MethodSignature.java | 5 ++++ 8 files changed, 114 insertions(+), 3 deletions(-) diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java index 7abb9c7..791cc56 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java @@ -4,6 +4,8 @@ import org.cadixdev.bombe.type.signature.FieldSignature; import org.cadixdev.bombe.type.signature.MethodSignature; +import java.util.Objects; + /** * Represents a unique, qualified path to a class. * @@ -71,4 +73,19 @@ public MethodReference getMethod(MethodSignature signature) { return new MethodReference(this, signature); } + @Override + public String toJvmsIdentifier() { + return classType.getClassName(); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), classType); + } + + @Override + public boolean equals(Object o) { + return o instanceof ClassReference && ((ClassReference) o).classType == classType; + } + } diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/FieldReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/FieldReference.java index 0ec4736..92177d2 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/FieldReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/FieldReference.java @@ -20,5 +20,4 @@ public class FieldReference extends MemberReference { public FieldReference(ClassReference owningClass, FieldSignature signature) { super(Type.FIELD, owningClass, signature); } - } diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MemberReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MemberReference.java index 5bc0ce6..4302dc6 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MemberReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MemberReference.java @@ -2,10 +2,12 @@ import org.cadixdev.bombe.type.signature.MemberSignature; +import java.util.Objects; + /** * Represents a unique, qualified path to a {@link ClassReference class} member. * - * @param The {@link MemberSignature} type used by this reference + * @param The {@link MemberSignature} type used by this reference * * @author Max Roncace * @since 0.3.1 @@ -44,8 +46,25 @@ public ClassReference getOwningClass() { * * @return The signature of this member */ - public MemberSignature getSignature() { + public S getSignature() { return signature; } + @Override + public String toJvmsIdentifier() { + return owningClass.toJvmsIdentifier() + JVMS_COMPONENT_JOINER + signature.toJvmsIdentifier(); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), owningClass, signature); + } + + @Override + public boolean equals(Object o) { + return o instanceof MemberReference + && super.equals(o) + && owningClass.equals(((MemberReference) o).owningClass) + && signature.equals(((MemberReference) o).signature); + } } diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodParameterReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodParameterReference.java index d9e104d..44875c5 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodParameterReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodParameterReference.java @@ -1,5 +1,7 @@ package org.cadixdev.bombe.type.reference; +import java.util.Objects; + /** * Represents a unique, qualified path to a parameter of a * {@link MethodReference method}. @@ -48,4 +50,22 @@ public int getParameterIndex() { return index; } + @Override + public String toJvmsIdentifier() { + return getParentMethod().toJvmsIdentifier() + JVMS_COMPONENT_JOINER + index; + } + + @Override + public int hashCode() { + return Objects.hash(getClass(), super.hashCode(), parentMethod, index); + } + + @Override + public boolean equals(Object o) { + return o instanceof MethodParameterReference + && super.equals(o) + && parentMethod.equals(((MethodParameterReference) o).parentMethod) + && index == ((MethodParameterReference) o).index; + } + } diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/QualifiedReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/QualifiedReference.java index b91d5e9..edae246 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/QualifiedReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/QualifiedReference.java @@ -1,5 +1,7 @@ package org.cadixdev.bombe.type.reference; +import java.util.Objects; + /** * Represents a unique, qualified path to a class, class member, or method * parameter. @@ -9,6 +11,8 @@ */ public abstract class QualifiedReference { + protected static final char JVMS_COMPONENT_JOINER = '.'; + protected final Type type; public QualifiedReference(Type type) { @@ -24,6 +28,30 @@ public Type getType() { return type; } + /** + * Returns a JVMS-like identifier string corresponding to this reference. + * + * The JVMS does not specify a qualified format for member and parameter + * identifiers, so for these cases, a dot (".") is used to separate the + * class, member signature, and parameter index components (as appropriate). + * + * @return A JVMS-like identifier string for this reference + * + * @see + * @see + */ + public abstract String toJvmsIdentifier(); + + @Override + public int hashCode() { + return Objects.hash(getClass(), type); + } + + @Override + public boolean equals(Object o) { + return o instanceof QualifiedReference && type == ((QualifiedReference) o).type; + } + public enum Type { TOP_LEVEL_CLASS, INNER_CLASS, diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/signature/FieldSignature.java b/bombe/src/main/java/org/cadixdev/bombe/type/signature/FieldSignature.java index f11a45d..0b31efd 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/signature/FieldSignature.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/signature/FieldSignature.java @@ -100,6 +100,11 @@ public Optional getType() { return Optional.ofNullable(this.type); } + @Override + public String toJvmsIdentifier() { + return this.name + "(" + this.type.toString() + ")"; + } + @Override protected StringJoiner buildToString() { return super.buildToString() diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/signature/MemberSignature.java b/bombe/src/main/java/org/cadixdev/bombe/type/signature/MemberSignature.java index d6fb808..3e4bf52 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/signature/MemberSignature.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/signature/MemberSignature.java @@ -64,6 +64,24 @@ public String getName() { return this.name; } + /** + * Returns a JVMS-like identifier corresponding to this signature. + * + *

+ * For field signatures, this will take the form + * {@code name(descriptor)}. + *

+ * + *

+ * For method signatures, this will take the form + * {@code name(params)ret_type} - in other terms, the name directly + * concatenated with the JVMS descriptor. + *

+ * + * @return A JVMS-like identifier + */ + public abstract String toJvmsIdentifier(); + protected StringJoiner buildToString() { return new StringJoiner(", ", getClass().getSimpleName() + "{", "}") .add("name=" + name); diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/signature/MethodSignature.java b/bombe/src/main/java/org/cadixdev/bombe/type/signature/MethodSignature.java index d6e23b6..5baaf1f 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/signature/MethodSignature.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/signature/MethodSignature.java @@ -100,6 +100,11 @@ public MethodDescriptor getDescriptor() { return this.descriptor; } + @Override + public String toJvmsIdentifier() { + return this.name + this.descriptor.toString(); + } + @Override protected StringJoiner buildToString() { return super.buildToString() From 9acf81b56deac2950134fea83c4bbde55bc762b4 Mon Sep 17 00:00:00 2001 From: Max Roncace Date: Mon, 9 Sep 2019 13:24:03 -0400 Subject: [PATCH 04/10] Implement toString for references --- .../cadixdev/bombe/type/reference/ClassReference.java | 6 ++++++ .../cadixdev/bombe/type/reference/FieldReference.java | 1 + .../cadixdev/bombe/type/reference/MemberReference.java | 8 ++++++++ .../bombe/type/reference/MethodParameterReference.java | 8 ++++++++ .../bombe/type/reference/QualifiedReference.java | 10 ++++++++++ 5 files changed, 33 insertions(+) diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java index 791cc56..b69669b 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java @@ -5,6 +5,7 @@ import org.cadixdev.bombe.type.signature.MethodSignature; import java.util.Objects; +import java.util.StringJoiner; /** * Represents a unique, qualified path to a class. @@ -78,6 +79,11 @@ public String toJvmsIdentifier() { return classType.getClassName(); } + @Override + protected StringJoiner buildToString() { + return super.buildToString().add(";classType=" + classType.getClassName()); + } + @Override public int hashCode() { return Objects.hash(super.hashCode(), classType); diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/FieldReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/FieldReference.java index 92177d2..0ec4736 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/FieldReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/FieldReference.java @@ -20,4 +20,5 @@ public class FieldReference extends MemberReference { public FieldReference(ClassReference owningClass, FieldSignature signature) { super(Type.FIELD, owningClass, signature); } + } diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MemberReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MemberReference.java index 4302dc6..d8d28fd 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MemberReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MemberReference.java @@ -3,6 +3,7 @@ import org.cadixdev.bombe.type.signature.MemberSignature; import java.util.Objects; +import java.util.StringJoiner; /** * Represents a unique, qualified path to a {@link ClassReference class} member. @@ -55,6 +56,13 @@ public String toJvmsIdentifier() { return owningClass.toJvmsIdentifier() + JVMS_COMPONENT_JOINER + signature.toJvmsIdentifier(); } + @Override + protected StringJoiner buildToString() { + return super.buildToString() + .add(";owningClass=" + owningClass.getClassType().getClassName()) + .add(";signature=" + signature.toJvmsIdentifier()); + } + @Override public int hashCode() { return Objects.hash(super.hashCode(), owningClass, signature); diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodParameterReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodParameterReference.java index 44875c5..d8427bb 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodParameterReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodParameterReference.java @@ -1,6 +1,7 @@ package org.cadixdev.bombe.type.reference; import java.util.Objects; +import java.util.StringJoiner; /** * Represents a unique, qualified path to a parameter of a @@ -55,6 +56,13 @@ public String toJvmsIdentifier() { return getParentMethod().toJvmsIdentifier() + JVMS_COMPONENT_JOINER + index; } + @Override + public StringJoiner buildToString() { + return super.buildToString() + .add(";parentMethod=" + parentMethod.toJvmsIdentifier()) + .add(";index=" + index); + } + @Override public int hashCode() { return Objects.hash(getClass(), super.hashCode(), parentMethod, index); diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/QualifiedReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/QualifiedReference.java index edae246..a13e783 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/QualifiedReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/QualifiedReference.java @@ -1,6 +1,7 @@ package org.cadixdev.bombe.type.reference; import java.util.Objects; +import java.util.StringJoiner; /** * Represents a unique, qualified path to a class, class member, or method @@ -42,6 +43,10 @@ public Type getType() { */ public abstract String toJvmsIdentifier(); + protected StringJoiner buildToString() { + return new StringJoiner("{type=" + type.name()); + } + @Override public int hashCode() { return Objects.hash(getClass(), type); @@ -52,6 +57,11 @@ public boolean equals(Object o) { return o instanceof QualifiedReference && type == ((QualifiedReference) o).type; } + @Override + public String toString() { + return buildToString().add("}").toString(); + } + public enum Type { TOP_LEVEL_CLASS, INNER_CLASS, From 34bb5f7086e374253ced3361aea3e15a35145a24 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Mon, 9 Sep 2019 19:42:01 +0100 Subject: [PATCH 05/10] 0.3.1: Begin dev cycle --- build.gradle | 6 +----- changelogs/0.3.1.md | 4 ++++ 2 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 changelogs/0.3.1.md diff --git a/build.gradle b/build.gradle index 961612a..d03d6f6 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ subprojects { group = 'org.cadixdev' archivesBaseName = project.name.toLowerCase() - version = '0.3.0' + version = '0.3.1-SNAPSHOT' repositories { mavenCentral() @@ -117,7 +117,3 @@ subprojects { } } } - -task wrapper(type: Wrapper) { - gradleVersion = '4.9' -} diff --git a/changelogs/0.3.1.md b/changelogs/0.3.1.md new file mode 100644 index 0000000..e68cb8f --- /dev/null +++ b/changelogs/0.3.1.md @@ -0,0 +1,4 @@ +Bombe 0.3.1 +=========== + + From bf3b160d8209e49832fc6e2c9be381286a6fd807 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Tue, 13 Aug 2019 21:57:22 +0100 Subject: [PATCH 06/10] travis: Fix build --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 82f9e04..ab357ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ # The Basics +dist: trusty language: java jdk: - oraclejdk8 From 073fcb770b187a267b113438e9980f5df14be47d Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Mon, 9 Sep 2019 19:56:41 +0100 Subject: [PATCH 07/10] Add licence headers + match code style --- .../bombe/type/reference/ClassReference.java | 55 +++++++++++++---- .../bombe/type/reference/FieldReference.java | 32 +++++++++- .../type/reference/InnerClassReference.java | 43 +++++++++++-- .../bombe/type/reference/MemberReference.java | 59 ++++++++++++++---- .../reference/MethodParameterReference.java | 60 ++++++++++++++----- .../bombe/type/reference/MethodReference.java | 34 ++++++++++- .../type/reference/QualifiedReference.java | 51 +++++++++++++--- .../reference/TopLevelClassReference.java | 32 +++++++++- 8 files changed, 309 insertions(+), 57 deletions(-) diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java index b69669b..7b5fcde 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java @@ -1,3 +1,33 @@ +/* + * Copyright (c) 2018, Jamie Mansfield + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + package org.cadixdev.bombe.type.reference; import org.cadixdev.bombe.type.ObjectType; @@ -27,7 +57,7 @@ public abstract class ClassReference extends QualifiedReference { * @param classType An {@link ObjectType} representing the type of the * referenced class */ - public ClassReference(Type type, ObjectType classType) { + public ClassReference(final Type type, final ObjectType classType) { super(type); this.classType = classType; } @@ -38,7 +68,7 @@ public ClassReference(Type type, ObjectType classType) { * @return The type of class */ public ObjectType getClassType() { - return classType; + return this.classType; } /** @@ -47,7 +77,7 @@ public ObjectType getClassType() { * @param unqualifiedName The unqualified name of the inner class * @return A reference to the inner class */ - public InnerClassReference getInnerClass(String unqualifiedName) { + public InnerClassReference getInnerClass(final String unqualifiedName) { return new InnerClassReference( this, new ObjectType(this.getClassType().getClassName() + INNER_CLASS_SEPARATOR_CHAR + unqualifiedName) @@ -60,7 +90,7 @@ public InnerClassReference getInnerClass(String unqualifiedName) { * @param signature The {@link FieldSignature signature} of the field * @return A reference to the field */ - public FieldReference getField(FieldSignature signature) { + public FieldReference getField(final FieldSignature signature) { return new FieldReference(this, signature); } @@ -70,28 +100,31 @@ public FieldReference getField(FieldSignature signature) { * @param signature The {@link MethodSignature signature} of the method * @return A reference to the method */ - public MethodReference getMethod(MethodSignature signature) { + public MethodReference getMethod(final MethodSignature signature) { return new MethodReference(this, signature); } @Override public String toJvmsIdentifier() { - return classType.getClassName(); + return this.classType.getClassName(); } @Override protected StringJoiner buildToString() { - return super.buildToString().add(";classType=" + classType.getClassName()); + return super.buildToString().add(";classType=" + this.classType.getClassName()); } @Override - public int hashCode() { - return Objects.hash(super.hashCode(), classType); + public boolean equals(final Object obj) { + if (this == obj) return true; + if (!(obj instanceof ClassReference)) return false; + final ClassReference that = (ClassReference) obj; + return Objects.equals(this.classType, that.classType); } @Override - public boolean equals(Object o) { - return o instanceof ClassReference && ((ClassReference) o).classType == classType; + public int hashCode() { + return Objects.hash(super.hashCode(), this.classType); } } diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/FieldReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/FieldReference.java index 0ec4736..d886514 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/FieldReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/FieldReference.java @@ -1,3 +1,33 @@ +/* + * Copyright (c) 2018, Jamie Mansfield + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + package org.cadixdev.bombe.type.reference; import org.cadixdev.bombe.type.signature.FieldSignature; @@ -17,7 +47,7 @@ public class FieldReference extends MemberReference { * @param owningClass The class containing the field * @param signature The signature of the field */ - public FieldReference(ClassReference owningClass, FieldSignature signature) { + public FieldReference(final ClassReference owningClass, final FieldSignature signature) { super(Type.FIELD, owningClass, signature); } diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/InnerClassReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/InnerClassReference.java index fc33950..e078ed1 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/InnerClassReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/InnerClassReference.java @@ -1,3 +1,33 @@ +/* + * Copyright (c) 2018, Jamie Mansfield + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + package org.cadixdev.bombe.type.reference; import org.cadixdev.bombe.type.ObjectType; @@ -17,17 +47,18 @@ public class InnerClassReference extends ClassReference { * @return A reference to the parent class * @throws IllegalArgumentException If the given type is not an inner class */ - private static ClassReference deriveParentClass(ObjectType classType) throws IllegalArgumentException { + private static ClassReference deriveParentClass(final ObjectType classType) throws IllegalArgumentException { if (classType.getClassName().indexOf(INNER_CLASS_SEPARATOR_CHAR) < 0) { throw new IllegalArgumentException("Cannot derive parent class from non-inner class identifier"); } - ObjectType parentType = new ObjectType( + final ObjectType parentType = new ObjectType( classType.getClassName().substring(0, classType.getClassName().lastIndexOf('$')) ); if (parentType.getClassName().indexOf(INNER_CLASS_SEPARATOR_CHAR) >= 0) { return new InnerClassReference(parentType); - } else { + } + else { return new TopLevelClassReference(parentType); } } @@ -40,7 +71,7 @@ private static ClassReference deriveParentClass(ObjectType classType) throws Ill * @param parentClass The parent class to the inner class * @param classType The full type of the inner class */ - InnerClassReference(ClassReference parentClass, ObjectType classType) { + InnerClassReference(final ClassReference parentClass, final ObjectType classType) { super(Type.INNER_CLASS, classType); assert(classType.getClassName().substring(0, classType.getClassName().lastIndexOf(INNER_CLASS_SEPARATOR_CHAR)) @@ -54,7 +85,7 @@ private static ClassReference deriveParentClass(ObjectType classType) throws Ill * * @param classType The full type of the inner class */ - public InnerClassReference(ObjectType classType) { + public InnerClassReference(final ObjectType classType) { this(deriveParentClass(classType), classType); } @@ -64,7 +95,7 @@ public InnerClassReference(ObjectType classType) { * @return The parent class */ public ClassReference getParentClass() { - return parentClass; + return this.parentClass; } } diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MemberReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MemberReference.java index d8d28fd..5f12ec7 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MemberReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MemberReference.java @@ -1,3 +1,33 @@ +/* + * Copyright (c) 2018, Jamie Mansfield + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + package org.cadixdev.bombe.type.reference; import org.cadixdev.bombe.type.signature.MemberSignature; @@ -27,7 +57,7 @@ public abstract class MemberReference extends Qualifi * @param owningClass A reference to the class which owns the member * @param signature The signature of the member */ - public MemberReference(Type type, ClassReference owningClass, S signature) { + public MemberReference(final Type type, final ClassReference owningClass, final S signature) { super(type); this.owningClass = owningClass; this.signature = signature; @@ -39,7 +69,7 @@ public MemberReference(Type type, ClassReference owningClass, S signature) { * @return The class which owns this member */ public ClassReference getOwningClass() { - return owningClass; + return this.owningClass; } /** @@ -48,31 +78,34 @@ public ClassReference getOwningClass() { * @return The signature of this member */ public S getSignature() { - return signature; + return this.signature; } @Override public String toJvmsIdentifier() { - return owningClass.toJvmsIdentifier() + JVMS_COMPONENT_JOINER + signature.toJvmsIdentifier(); + return this.owningClass.toJvmsIdentifier() + JVMS_COMPONENT_JOINER + this.signature.toJvmsIdentifier(); } @Override protected StringJoiner buildToString() { return super.buildToString() - .add(";owningClass=" + owningClass.getClassType().getClassName()) - .add(";signature=" + signature.toJvmsIdentifier()); + .add(";owningClass=" + this.owningClass.getClassType().getClassName()) + .add(";signature=" + this.signature.toJvmsIdentifier()); } @Override - public int hashCode() { - return Objects.hash(super.hashCode(), owningClass, signature); + public boolean equals(final Object obj) { + if (this == obj) return true; + if (!(obj instanceof MemberReference)) return false; + final MemberReference that = (MemberReference) obj; + return super.equals(obj) && + Objects.equals(this.owningClass, that.owningClass) && + Objects.equals(this.signature, that.signature); } @Override - public boolean equals(Object o) { - return o instanceof MemberReference - && super.equals(o) - && owningClass.equals(((MemberReference) o).owningClass) - && signature.equals(((MemberReference) o).signature); + public int hashCode() { + return Objects.hash(super.hashCode(), this.owningClass, this.signature); } + } diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodParameterReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodParameterReference.java index d8427bb..874ed42 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodParameterReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodParameterReference.java @@ -1,3 +1,33 @@ +/* + * Copyright (c) 2018, Jamie Mansfield + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + package org.cadixdev.bombe.type.reference; import java.util.Objects; @@ -20,9 +50,9 @@ public class MethodParameterReference extends QualifiedReference { * * @param parentMethod The method specifying the parameter * @param index The index of the parameter (0-indexed) - * @throws IllegalArgumentException If the parameter index of out-of-bounds + * @throws IllegalArgumentException If the parameter index is out-of-bounds */ - public MethodParameterReference(MethodReference parentMethod, int index) throws IllegalArgumentException { + public MethodParameterReference(final MethodReference parentMethod, final int index) throws IllegalArgumentException { super(Type.METHOD_PARAMETER); if (index >= parentMethod.getSignature().getDescriptor().getParamTypes().size()) { @@ -39,7 +69,7 @@ public MethodParameterReference(MethodReference parentMethod, int index) throws * @return The method specifying this parameter */ public MethodReference getParentMethod() { - return parentMethod; + return this.parentMethod; } /** @@ -48,32 +78,34 @@ public MethodReference getParentMethod() { * @return The index of this parameter */ public int getParameterIndex() { - return index; + return this.index; } @Override public String toJvmsIdentifier() { - return getParentMethod().toJvmsIdentifier() + JVMS_COMPONENT_JOINER + index; + return this.getParentMethod().toJvmsIdentifier() + JVMS_COMPONENT_JOINER + this.index; } @Override public StringJoiner buildToString() { return super.buildToString() - .add(";parentMethod=" + parentMethod.toJvmsIdentifier()) - .add(";index=" + index); + .add(";parentMethod=" + this.parentMethod.toJvmsIdentifier()) + .add(";index=" + this.index); } @Override - public int hashCode() { - return Objects.hash(getClass(), super.hashCode(), parentMethod, index); + public boolean equals(final Object obj) { + if (this == obj) return true; + if (!(obj instanceof MethodParameterReference)) return false; + final MethodParameterReference that = (MethodParameterReference) obj; + return super.equals(obj) && + Objects.equals(this.parentMethod, that.parentMethod) && + Objects.equals(this.index, that.index); } @Override - public boolean equals(Object o) { - return o instanceof MethodParameterReference - && super.equals(o) - && parentMethod.equals(((MethodParameterReference) o).parentMethod) - && index == ((MethodParameterReference) o).index; + public int hashCode() { + return Objects.hash(super.hashCode(), this.parentMethod, this.index); } } diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodReference.java index a3fe10e..77aec2e 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/MethodReference.java @@ -1,3 +1,33 @@ +/* + * Copyright (c) 2018, Jamie Mansfield + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + package org.cadixdev.bombe.type.reference; import org.cadixdev.bombe.type.signature.MethodSignature; @@ -17,7 +47,7 @@ public class MethodReference extends MemberReference { * @param owningClass The class containing the method * @param signature The signature of the method */ - public MethodReference(ClassReference owningClass, MethodSignature signature) { + public MethodReference(final ClassReference owningClass, final MethodSignature signature) { super(Type.METHOD, owningClass, signature); } @@ -28,7 +58,7 @@ public MethodReference(ClassReference owningClass, MethodSignature signature) { * @return A refernce to the parameter * @throws IllegalArgumentException If the parameter index is out-of-bounds */ - public MethodParameterReference getParameter(int index) { + public MethodParameterReference getParameter(final int index) { return new MethodParameterReference(this, index); } diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/QualifiedReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/QualifiedReference.java index a13e783..0db9d52 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/QualifiedReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/QualifiedReference.java @@ -1,3 +1,33 @@ +/* + * Copyright (c) 2018, Jamie Mansfield + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + package org.cadixdev.bombe.type.reference; import java.util.Objects; @@ -16,7 +46,7 @@ public abstract class QualifiedReference { protected final Type type; - public QualifiedReference(Type type) { + public QualifiedReference(final Type type) { this.type = type; } @@ -26,7 +56,7 @@ public QualifiedReference(Type type) { * @return The {@link Type} of this reference */ public Type getType() { - return type; + return this.type; } /** @@ -44,22 +74,25 @@ public Type getType() { public abstract String toJvmsIdentifier(); protected StringJoiner buildToString() { - return new StringJoiner("{type=" + type.name()); + return new StringJoiner("{type=" + this.type.name()); } @Override - public int hashCode() { - return Objects.hash(getClass(), type); + public String toString() { + return buildToString().add("}").toString(); } @Override - public boolean equals(Object o) { - return o instanceof QualifiedReference && type == ((QualifiedReference) o).type; + public boolean equals(final Object obj) { + if (this == obj) return true; + if (!(obj instanceof QualifiedReference)) return false; + final QualifiedReference that = (QualifiedReference) obj; + return Objects.equals(this.type, that.type); } @Override - public String toString() { - return buildToString().add("}").toString(); + public int hashCode() { + return Objects.hash(this.type); } public enum Type { diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/TopLevelClassReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/TopLevelClassReference.java index a01e9c1..6a90c70 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/TopLevelClassReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/TopLevelClassReference.java @@ -1,3 +1,33 @@ +/* + * Copyright (c) 2018, Jamie Mansfield + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + package org.cadixdev.bombe.type.reference; import org.cadixdev.bombe.type.ObjectType; @@ -18,7 +48,7 @@ public class TopLevelClassReference extends ClassReference { * @throws IllegalArgumentException If the given type represents an inner * class */ - public TopLevelClassReference(ObjectType classType) { + public TopLevelClassReference(final ObjectType classType) { super(Type.TOP_LEVEL_CLASS, classType); if (classType.getClassName().indexOf(INNER_CLASS_SEPARATOR_CHAR) >= 0) { From 1ad7c44ff0d8a6824f7dff2706f184ef50dfb079 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Mon, 9 Sep 2019 20:22:52 +0100 Subject: [PATCH 08/10] 0.3.1: Add basic changelog --- changelogs/0.3.1.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/changelogs/0.3.1.md b/changelogs/0.3.1.md index e68cb8f..6dc7bba 100644 --- a/changelogs/0.3.1.md +++ b/changelogs/0.3.1.md @@ -1,4 +1,17 @@ Bombe 0.3.1 =========== +Bombe 0.3.1 brings with it qualified references - a way to directly reference a member of +a class, or a class itself. +## Example + +```java +import org.cadixdev.bombe.type.ObjectType; +import org.cadixdev.bombe.type.reference.FieldReference; +import org.cadixdev.bombe.type.reference.TopLevelClassReference; + +final ObjectType demo = new ObjectType("org/cadixdev/Demo"); +final FieldReference field = new TopLevelClassReference(demo) + .getField(new FieldSignature("x", BaseType.INT)); +``` From 3f1dbb5bb0644f4f9f00a4d039bfb581617c6305 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Mon, 9 Sep 2019 20:34:33 +0100 Subject: [PATCH 09/10] Add convenience methods to Reference API --- .../bombe/type/reference/ClassReference.java | 56 +++++++++++++++++++ .../reference/TopLevelClassReference.java | 11 ++++ changelogs/0.3.1.md | 6 +- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java index 7b5fcde..e4b7b1d 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/ClassReference.java @@ -30,6 +30,8 @@ package org.cadixdev.bombe.type.reference; +import org.cadixdev.bombe.type.FieldType; +import org.cadixdev.bombe.type.MethodDescriptor; import org.cadixdev.bombe.type.ObjectType; import org.cadixdev.bombe.type.signature.FieldSignature; import org.cadixdev.bombe.type.signature.MethodSignature; @@ -94,6 +96,38 @@ public FieldReference getField(final FieldSignature signature) { return new FieldReference(this, signature); } + /** + * Returns a reference to a field contained by this class. + * + * @param name The name of the field + * @param type The {@link FieldType type} of the field + * @return A reference to the field + */ + public FieldReference getField(final String name, final FieldType type) { + return this.getField(new FieldSignature(name, type)); + } + + /** + * Returns a reference to a field contained by this class. + * + * @param name The name of the field + * @param type The type of the field + * @return A reference to the field + */ + public FieldReference getField(final String name, final String type) { + return this.getField(name, FieldType.of(type)); + } + + /** + * Returns a reference to a field contained by this class. + * + * @param name The name of the field + * @return A reference to the field + */ + public FieldReference getField(final String name) { + return this.getField(new FieldSignature(name)); + } + /** * Returns a reference to a method contained by this class. * @@ -104,6 +138,28 @@ public MethodReference getMethod(final MethodSignature signature) { return new MethodReference(this, signature); } + /** + * Returns a reference to a method contained by this class. + * + * @param name The name of the method + * @param descriptor The {@link MethodDescriptor descriptor} of the method + * @return A reference to the method + */ + public MethodReference getMethod(final String name, final MethodDescriptor descriptor) { + return this.getMethod(new MethodSignature(name, descriptor)); + } + + /** + * Returns a reference to a method contained by this class. + * + * @param name The name of the method + * @param descriptor The JVMS descriptor of the method + * @return A reference to the method + */ + public MethodReference getMethod(final String name, final String descriptor) { + return this.getMethod(name, MethodDescriptor.of(descriptor)); + } + @Override public String toJvmsIdentifier() { return this.classType.getClassName(); diff --git a/bombe/src/main/java/org/cadixdev/bombe/type/reference/TopLevelClassReference.java b/bombe/src/main/java/org/cadixdev/bombe/type/reference/TopLevelClassReference.java index 6a90c70..4deaf8f 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/type/reference/TopLevelClassReference.java +++ b/bombe/src/main/java/org/cadixdev/bombe/type/reference/TopLevelClassReference.java @@ -56,4 +56,15 @@ public TopLevelClassReference(final ObjectType classType) { } } + /** + * Constructs a new reference to a top-level class. + * + * @param className The name of the class + * @throws IllegalArgumentException If the given type represents an inner + * class + */ + public TopLevelClassReference(final String className) { + this(new ObjectType(className)); + } + } diff --git a/changelogs/0.3.1.md b/changelogs/0.3.1.md index 6dc7bba..cb7edf6 100644 --- a/changelogs/0.3.1.md +++ b/changelogs/0.3.1.md @@ -7,11 +7,9 @@ a class, or a class itself. ## Example ```java -import org.cadixdev.bombe.type.ObjectType; import org.cadixdev.bombe.type.reference.FieldReference; import org.cadixdev.bombe.type.reference.TopLevelClassReference; -final ObjectType demo = new ObjectType("org/cadixdev/Demo"); -final FieldReference field = new TopLevelClassReference(demo) - .getField(new FieldSignature("x", BaseType.INT)); +final FieldReference field = new TopLevelClassReference("org/cadixdev/Demo") + .getField("x", BaseType.INT); ``` From 1ce4b7a50e2e3bb1247d6273b6518548983c14df Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Mon, 9 Sep 2019 22:37:46 +0100 Subject: [PATCH 10/10] 0.3.1: Release Time --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index d03d6f6..6db20c2 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ subprojects { group = 'org.cadixdev' archivesBaseName = project.name.toLowerCase() - version = '0.3.1-SNAPSHOT' + version = '0.3.1' repositories { mavenCentral()