Refactoring für innere Typen, welche ausschließlich einen Descriptor besitzen.
Innere Typen sind dabei IntermediateRefType und IntermediateGenericType. Implementierung der IntermediateWildcard Typen und Hinzufügen leerer Tests.
This commit is contained in:
parent
06b27dabd2
commit
55a75b04a0
@ -3,35 +3,57 @@ package de.dhbwstuttgart.intermediate.types;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
|
||||
/**
|
||||
* //ToDo Beschreiben
|
||||
* Represents a Java Wildcard with a extends-operator.
|
||||
* E.g. {@code <? extends String>}
|
||||
*
|
||||
* @since Studienarbeit Type Erasure
|
||||
* @author etiennezink
|
||||
*/
|
||||
public final class IntermediateExtendsWildcard extends IntermediateType {
|
||||
//ToDo
|
||||
|
||||
public IntermediateExtendsWildcard(JavaClassName className) {
|
||||
super(className);
|
||||
private final IntermediateInnerType innerType;
|
||||
|
||||
/**
|
||||
* Caches the hashCode after first computation.
|
||||
*/
|
||||
private int hashCode;
|
||||
|
||||
/**
|
||||
* Caches the signature after first computation.
|
||||
*/
|
||||
private String signature = "";
|
||||
|
||||
public IntermediateExtendsWildcard(IntermediateInnerType innerType) {
|
||||
this.innerType = innerType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return false;
|
||||
if (!(o instanceof IntermediateExtendsWildcard)) return false;
|
||||
|
||||
IntermediateExtendsWildcard intermediateExtendsWildcard = (IntermediateExtendsWildcard) o;
|
||||
if(!innerType.equals(intermediateExtendsWildcard.innerType)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 0;
|
||||
int prime = 31;
|
||||
int hashCode = this.hashCode;
|
||||
if (hashCode == 0){
|
||||
hashCode += innerType.hashCode();
|
||||
hashCode = prime * hashCode + "extends".hashCode();
|
||||
this.hashCode = hashCode;
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSignature() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescriptor() {
|
||||
return null;
|
||||
String signature = this.signature;
|
||||
if (!signature.equals("")) return this.signature;
|
||||
signature = String.format("+%s", innerType.getSignature());
|
||||
this.signature = signature;
|
||||
return signature;
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,10 @@ import org.objectweb.asm.Type;
|
||||
* @since Studienarbeit Type Erasure
|
||||
* @author etiennezink
|
||||
*/
|
||||
public final class IntermediateGenericType extends IntermediateType {
|
||||
public final class IntermediateGenericType extends IntermediateInnerType {
|
||||
|
||||
private final String genericName;
|
||||
private final IntermediateInnerType innerType;
|
||||
|
||||
/**
|
||||
* Caches the hashCode after first computation.
|
||||
@ -30,11 +31,11 @@ public final class IntermediateGenericType extends IntermediateType {
|
||||
private String descriptor = "";
|
||||
|
||||
public IntermediateGenericType(String genericName){
|
||||
this(genericName, new JavaClassName(Type.getInternalName(Object.class)));
|
||||
this(genericName, new IntermediateRefType(new JavaClassName(Type.getInternalName(Object.class))));
|
||||
}
|
||||
|
||||
public IntermediateGenericType(String genericName, JavaClassName className) {
|
||||
super(className);
|
||||
public IntermediateGenericType(String genericName, IntermediateInnerType innerType) {
|
||||
this.innerType = innerType;
|
||||
this.genericName = genericName;
|
||||
}
|
||||
|
||||
@ -43,7 +44,7 @@ public final class IntermediateGenericType extends IntermediateType {
|
||||
if (!(o instanceof IntermediateGenericType)) return false;
|
||||
|
||||
IntermediateGenericType intermediateGenericType = (IntermediateGenericType) o;
|
||||
if(!getFullyQualifiedName().equals(intermediateGenericType.getFullyQualifiedName())) return false;
|
||||
if(!innerType.equals(intermediateGenericType.innerType)) return false;
|
||||
if(!genericName.equals(intermediateGenericType.genericName)) return false;
|
||||
return true;
|
||||
}
|
||||
@ -53,7 +54,7 @@ public final class IntermediateGenericType extends IntermediateType {
|
||||
int prime = 31;
|
||||
int hashCode = this.hashCode;
|
||||
if (hashCode == 0){
|
||||
hashCode += getFullyQualifiedName().hashCode();
|
||||
hashCode += innerType.hashCode();
|
||||
hashCode = prime * hashCode + genericName.hashCode();
|
||||
this.hashCode = hashCode;
|
||||
}
|
||||
@ -73,7 +74,7 @@ public final class IntermediateGenericType extends IntermediateType {
|
||||
public String getDescriptor() {
|
||||
String descriptor = this.descriptor;
|
||||
if (!descriptor.equals("")) return this.descriptor;
|
||||
descriptor = String.format("L%s;", getFullyQualifiedName()).replace('.','/');
|
||||
descriptor = innerType.getDescriptor();
|
||||
this.descriptor = descriptor;
|
||||
return descriptor;
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
package de.dhbwstuttgart.intermediate.types;
|
||||
|
||||
/**
|
||||
* Only Java types which can be used as an inner type, have a descriptor definition.
|
||||
*/
|
||||
public abstract class IntermediateInnerType extends IntermediateType {
|
||||
|
||||
public abstract String getDescriptor();
|
||||
}
|
@ -11,9 +11,10 @@ import java.util.List;
|
||||
* @since Studienarbeit Type Erasure
|
||||
* @author etiennezink
|
||||
*/
|
||||
public final class IntermediateRefType extends IntermediateType{
|
||||
public final class IntermediateRefType extends IntermediateInnerType{
|
||||
|
||||
private final List<IntermediateRefType> typParameters;
|
||||
private final JavaClassName className;
|
||||
|
||||
/**
|
||||
* Caches the hashCode after first computation.
|
||||
@ -35,7 +36,7 @@ public final class IntermediateRefType extends IntermediateType{
|
||||
}
|
||||
|
||||
public IntermediateRefType(JavaClassName className, List<IntermediateRefType> typParameters){
|
||||
super(className);
|
||||
this.className = className;
|
||||
this.typParameters = Collections.unmodifiableList(typParameters);
|
||||
}
|
||||
|
||||
@ -71,13 +72,13 @@ public final class IntermediateRefType extends IntermediateType{
|
||||
String signature = this.signature;
|
||||
if (!signature.equals("")) return this.signature;
|
||||
|
||||
if (getClassName().equals("void")) signature = "V";
|
||||
if (className.getClassName().equals("void")) signature = "V";
|
||||
else {
|
||||
signature += String.format("L%s", getFullyQualifiedName());
|
||||
if (typParameters.size() != 0){
|
||||
signature += "<";
|
||||
for (IntermediateType typParameter:typParameters) {
|
||||
signature += String.format("L%s;", typParameter.getFullyQualifiedName());
|
||||
signature += typParameter.getSignature();
|
||||
}
|
||||
signature += ">";
|
||||
}
|
||||
@ -109,4 +110,6 @@ public final class IntermediateRefType extends IntermediateType{
|
||||
if(typParameters.size() < index) return null;
|
||||
return typParameters.get(index);
|
||||
}
|
||||
|
||||
private String getFullyQualifiedName(){ return className.toString(); }
|
||||
}
|
||||
|
@ -3,35 +3,56 @@ package de.dhbwstuttgart.intermediate.types;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
|
||||
/**
|
||||
* //ToDo Beschreiben
|
||||
* Represents a Java Wildcard with a super-operator.
|
||||
* E.g. {@code <? super String>}
|
||||
*
|
||||
* @since Studienarbeit Type Erasure
|
||||
* @author etiennezink
|
||||
*/
|
||||
public final class IntermediateSuperWildcard extends IntermediateType {
|
||||
//ToDo
|
||||
private final IntermediateInnerType innerType;
|
||||
|
||||
public IntermediateSuperWildcard(JavaClassName className) {
|
||||
super(className);
|
||||
/**
|
||||
* Caches the hashCode after first computation.
|
||||
*/
|
||||
private int hashCode;
|
||||
|
||||
/**
|
||||
* Caches the signature after first computation.
|
||||
*/
|
||||
private String signature = "";
|
||||
|
||||
public IntermediateSuperWildcard(IntermediateInnerType innerType) {
|
||||
this.innerType = innerType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return false;
|
||||
if (!(o instanceof IntermediateSuperWildcard)) return false;
|
||||
|
||||
IntermediateSuperWildcard intermediateSuperWildcard = (IntermediateSuperWildcard) o;
|
||||
if(!innerType.equals(intermediateSuperWildcard.innerType)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 0;
|
||||
int prime = 31;
|
||||
int hashCode = this.hashCode;
|
||||
if (hashCode == 0){
|
||||
hashCode += innerType.hashCode();
|
||||
hashCode = prime * hashCode + "super".hashCode();
|
||||
this.hashCode = hashCode;
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSignature() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescriptor() {
|
||||
return null;
|
||||
String signature = this.signature;
|
||||
if (!signature.equals("")) return this.signature;
|
||||
signature = String.format("-%s", innerType.getSignature());
|
||||
this.signature = signature;
|
||||
return signature;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package de.dhbwstuttgart.intermediate.types;
|
||||
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
|
||||
/**
|
||||
* Base class for Java data types which is used as an intermediate representation after type resolution.
|
||||
* This class and it's subtypes have to be immutable (e.g. no mutators) to ensure side effect freedom.
|
||||
@ -12,10 +10,6 @@ import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
*/
|
||||
public abstract class IntermediateType {
|
||||
|
||||
private final JavaClassName className;
|
||||
|
||||
public IntermediateType(JavaClassName className){ this.className = className; }
|
||||
|
||||
@Override
|
||||
public abstract boolean equals(Object o);
|
||||
|
||||
@ -23,14 +17,7 @@ public abstract class IntermediateType {
|
||||
public abstract int hashCode();
|
||||
|
||||
public abstract String getSignature();
|
||||
public abstract String getDescriptor();
|
||||
|
||||
@Override
|
||||
public String toString() { return getSignature(); }
|
||||
|
||||
protected String getClassName() {
|
||||
return className.getClassName();
|
||||
}
|
||||
protected String getPackageName() { return className.getPackageName(); }
|
||||
protected String getFullyQualifiedName() { return className.toString(); }
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package intermediate.types;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IntermediateExtensWildcardTest {
|
||||
@Test
|
||||
public void ToDo(){
|
||||
Assert.fail();
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package intermediate.types;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IntermediateGenericTypeTest {
|
||||
@Test
|
||||
public void ToDo(){
|
||||
Assert.fail();
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package intermediate.types;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IntermediateSuperWildcardTest {
|
||||
@Test
|
||||
public void ToDo(){
|
||||
Assert.fail();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user