Skip to content

Commit

Permalink
Merge branch 'release-0.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
jamierocks committed Sep 9, 2019
2 parents 4b5310c + 1ce4b7a commit dc6ba55
Show file tree
Hide file tree
Showing 14 changed files with 849 additions and 5 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# The Basics
dist: trusty
language: java
jdk:
- oraclejdk8
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/*
* Copyright (c) 2018, Jamie Mansfield <https://jamiemansfield.me/>
* 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.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;

import java.util.Objects;
import java.util.StringJoiner;

/**
* 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(final Type type, final 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 this.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(final String unqualifiedName) {
return new InnerClassReference(
this,
new ObjectType(this.getClassType().getClassName() + INNER_CLASS_SEPARATOR_CHAR + 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(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.
*
* @param signature The {@link MethodSignature signature} of the method
* @return A reference to the method
*/
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();
}

@Override
protected StringJoiner buildToString() {
return super.buildToString().add(";classType=" + this.classType.getClassName());
}

@Override
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 int hashCode() {
return Objects.hash(super.hashCode(), this.classType);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2018, Jamie Mansfield <https://jamiemansfield.me/>
* 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;

/**
* 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<FieldSignature> {

/**
* Constructs a new reference to a class field.
*
* @param owningClass The class containing the field
* @param signature The signature of the field
*/
public FieldReference(final ClassReference owningClass, final FieldSignature signature) {
super(Type.FIELD, owningClass, signature);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright (c) 2018, Jamie Mansfield <https://jamiemansfield.me/>
* 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;

/**
* Represents a unique, qualified path to an inner {@link ClassReference class}.
*
* @author Max Roncace
* @since 0.3.1
*/
public class InnerClassReference extends ClassReference {

/**
* 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(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");
}

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 {
return new TopLevelClassReference(parentType);
}
}

private final ClassReference parentClass;

/**
* 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(final ClassReference parentClass, final 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(final 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 this.parentClass;
}

}
Loading

0 comments on commit dc6ba55

Please sign in to comment.