forked from JavaTX/JavaCompilerCore
comments and refactoring
This commit is contained in:
parent
044e6fbc3f
commit
0313d297e1
@ -14,7 +14,7 @@ public final class ExtendsType extends WildcardType {
|
|||||||
* @param extendedType The extended type e.g. Integer in "? extends Integer"
|
* @param extendedType The extended type e.g. Integer in "? extends Integer"
|
||||||
*/
|
*/
|
||||||
public ExtendsType(UnifyType extendedType) {
|
public ExtendsType(UnifyType extendedType) {
|
||||||
super("? extends " + extendedType.getName(), extendedType, extendedType.getTypeParams());
|
super("? extends " + extendedType.getName(), extendedType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnifyType getExtendedType() {
|
public UnifyType getExtendedType() {
|
||||||
|
@ -16,13 +16,13 @@ public final class PlaceholderType extends UnifyType{
|
|||||||
private final boolean IsGenerated;
|
private final boolean IsGenerated;
|
||||||
|
|
||||||
public PlaceholderType(String name) {
|
public PlaceholderType(String name) {
|
||||||
super(name);
|
super(name, new TypeParams());
|
||||||
EXISTING_PLACEHOLDERS.add(name);
|
EXISTING_PLACEHOLDERS.add(name);
|
||||||
IsGenerated = false;
|
IsGenerated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PlaceholderType(String name, boolean isGenerated) {
|
protected PlaceholderType(String name, boolean isGenerated) {
|
||||||
super(name);
|
super(name, new TypeParams());
|
||||||
EXISTING_PLACEHOLDERS.add(name);
|
EXISTING_PLACEHOLDERS.add(name);
|
||||||
IsGenerated = isGenerated;
|
IsGenerated = isGenerated;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
|||||||
|
|
||||||
public final class SuperType extends WildcardType {
|
public final class SuperType extends WildcardType {
|
||||||
public SuperType(UnifyType superedType) {
|
public SuperType(UnifyType superedType) {
|
||||||
super("? super " + superedType.getName(), superedType, superedType.getTypeParams());
|
super("? super " + superedType.getName(), superedType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnifyType getSuperedType() {
|
public UnifyType getSuperedType() {
|
||||||
|
@ -17,7 +17,7 @@ public class Unifier implements Function<UnifyType, UnifyType> /*, Set<MPair>*/
|
|||||||
/**
|
/**
|
||||||
* Identity function as an "unifier".
|
* Identity function as an "unifier".
|
||||||
*/
|
*/
|
||||||
public Unifier() {
|
protected Unifier() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,35 +4,76 @@ import java.util.Set;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a java type.
|
||||||
|
* @author Florian Steurer
|
||||||
|
*/
|
||||||
public abstract class UnifyType {
|
public abstract class UnifyType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the type e.q. "Integer", "? extends Integer" or "List" for (List<T>)
|
||||||
|
*/
|
||||||
protected final String typeName;
|
protected final String typeName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type parameters of the type.
|
||||||
|
*/
|
||||||
protected final TypeParams typeParams;
|
protected final TypeParams typeParams;
|
||||||
|
|
||||||
protected UnifyType(String name, UnifyType... typeParams) {
|
/**
|
||||||
typeName = name;
|
* Creates a new instance
|
||||||
this.typeParams = new TypeParams(typeParams);
|
* @param name Name of the type (e.q. List for List<T>, Integer or ? extends Integer)
|
||||||
}
|
* @param typeParams Parameters of the type (e.q. <T> for List<T>)
|
||||||
|
*/
|
||||||
protected UnifyType(String name, TypeParams p) {
|
protected UnifyType(String name, TypeParams p) {
|
||||||
typeName = name;
|
typeName = name;
|
||||||
typeParams = p;
|
typeParams = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the type.
|
||||||
|
* @return The name e.q. List for List<T>, Integer or ? extends Integer
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return typeName;
|
return typeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The parameters of the type.
|
||||||
|
* @return Parameters of the type, e.q. <T> for List<T>.
|
||||||
|
*/
|
||||||
public TypeParams getTypeParams() {
|
public TypeParams getTypeParams() {
|
||||||
return typeParams;
|
return typeParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new type that equals this type except for the type parameters.
|
||||||
|
* @param newTp The type params of the new type.
|
||||||
|
* @return A new type object.
|
||||||
|
*/
|
||||||
public abstract UnifyType setTypeParams(TypeParams newTp);
|
public abstract UnifyType setTypeParams(TypeParams newTp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of the visitor-pattern. Returns the set of smArg
|
||||||
|
* by calling the most specific overload in the FC.
|
||||||
|
* @param fc The FC that is called.
|
||||||
|
* @return The set that is smArg(this)
|
||||||
|
*/
|
||||||
abstract Set<UnifyType> smArg(IFiniteClosure fc);
|
abstract Set<UnifyType> smArg(IFiniteClosure fc);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of the visitor-pattern. Returns the set of grArg
|
||||||
|
* by calling the most specific overload in the FC.
|
||||||
|
* @param fc The FC that is called.
|
||||||
|
* @return The set that is grArg(this)
|
||||||
|
*/
|
||||||
abstract Set<UnifyType> grArg(IFiniteClosure fc);
|
abstract Set<UnifyType> grArg(IFiniteClosure fc);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies a unifier to this object.
|
||||||
|
* @param unif The unifier
|
||||||
|
* @return A UnifyType, that may or may not be a new object, that has its subtypes substituted.
|
||||||
|
*/
|
||||||
abstract UnifyType apply(Unifier unif);
|
abstract UnifyType apply(Unifier unif);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,19 +1,30 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify.model;
|
package de.dhbwstuttgart.typeinference.unify.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wildcard type that is either a ExtendsType or a SuperType.
|
||||||
|
* @author Florian Steurer
|
||||||
|
*/
|
||||||
public abstract class WildcardType extends UnifyType {
|
public abstract class WildcardType extends UnifyType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The wildcarded type, e.q. Integer for ? extends Integer. Never a wildcard type itself.
|
||||||
|
*/
|
||||||
protected UnifyType wildcardedType;
|
protected UnifyType wildcardedType;
|
||||||
|
|
||||||
protected WildcardType(String name, UnifyType wildcardedType, UnifyType[] typeParams) {
|
/**
|
||||||
super(name, typeParams);
|
* Creates a new instance.
|
||||||
this.wildcardedType = wildcardedType;
|
* @param name The name of the type, e.q. ? extends Integer
|
||||||
}
|
* @param wildcardedType The wildcarded type, e.q. Integer for ? extends Integer. Never a wildcard type itself.
|
||||||
|
*/
|
||||||
protected WildcardType(String name, UnifyType wildcardedType, TypeParams p) {
|
protected WildcardType(String name, UnifyType wildcardedType) {
|
||||||
super(name, p);
|
super(name, wildcardedType.getTypeParams());
|
||||||
this.wildcardedType = wildcardedType;
|
this.wildcardedType = wildcardedType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the wildcarded type, e.q. Integer for ? extends Integer.
|
||||||
|
* @return The wildcarded type. Never a wildcard type itself.
|
||||||
|
*/
|
||||||
public UnifyType getWildcardedType() {
|
public UnifyType getWildcardedType() {
|
||||||
return wildcardedType;
|
return wildcardedType;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user