forked from JavaTX/JavaCompilerCore
refactoring and commenting
This commit is contained in:
parent
a16e62f4bd
commit
8b6a4d1746
@ -6,42 +6,68 @@ import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
|
||||
/**
|
||||
* An unbounded placeholder type.
|
||||
* @author Florian Steurer
|
||||
*/
|
||||
public final class PlaceholderType extends UnifyType{
|
||||
|
||||
/**
|
||||
* Static list containing the names of all existing placeholders.
|
||||
* Used for generating fresh placeholders.
|
||||
*/
|
||||
protected static final HashSet<String> EXISTING_PLACEHOLDERS = new HashSet<String>();
|
||||
|
||||
/**
|
||||
* Prefix of auto-generated placeholder names.
|
||||
*/
|
||||
protected static String nextName = "gen_";
|
||||
|
||||
/**
|
||||
* Random number generator used to generate fresh placeholder name.
|
||||
*/
|
||||
protected static Random rnd = new Random(43558747548978L);
|
||||
|
||||
/**
|
||||
* True if this object was auto-generated, false if this object was user-generated.
|
||||
*/
|
||||
private final boolean IsGenerated;
|
||||
|
||||
/**
|
||||
* Creates a new placeholder type with the specified name.
|
||||
*/
|
||||
public PlaceholderType(String name) {
|
||||
super(name, new TypeParams());
|
||||
EXISTING_PLACEHOLDERS.add(name);
|
||||
IsGenerated = false;
|
||||
EXISTING_PLACEHOLDERS.add(name); // Add to list of existing placeholder names
|
||||
IsGenerated = false; // This type is user generated
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new placeholdertype
|
||||
* @param isGenerated true if this placeholder is auto-generated, false if it is user-generated.
|
||||
*/
|
||||
protected PlaceholderType(String name, boolean isGenerated) {
|
||||
super(name, new TypeParams());
|
||||
EXISTING_PLACEHOLDERS.add(name);
|
||||
EXISTING_PLACEHOLDERS.add(name); // Add to list of existing placeholder names
|
||||
IsGenerated = isGenerated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a fresh placeholder type with a name that does so far not exist.
|
||||
* A user could later instantiate a type using the same name that is equivalent to this type.
|
||||
* @return A fresh placeholder type.
|
||||
*/
|
||||
public static PlaceholderType freshPlaceholder() {
|
||||
String name = nextName + randomChar();
|
||||
|
||||
String name = nextName + (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z'
|
||||
// Add random chars while the name is in use.
|
||||
while(EXISTING_PLACEHOLDERS.contains(name));
|
||||
name += randomChar();
|
||||
|
||||
name += (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z'
|
||||
return new PlaceholderType(name, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns random char between 'a' and 'z'
|
||||
* True if this placeholder is auto-generated, false if it is user-generated.
|
||||
*/
|
||||
private static char randomChar() {
|
||||
return (char) (rnd.nextInt(22) + 97);
|
||||
}
|
||||
|
||||
public boolean isGenerated() {
|
||||
return IsGenerated;
|
||||
}
|
||||
@ -58,7 +84,7 @@ public final class PlaceholderType extends UnifyType{
|
||||
|
||||
@Override
|
||||
public UnifyType setTypeParams(TypeParams newTp) {
|
||||
return this;
|
||||
return this; // Placeholders never have params.
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,7 +4,13 @@ import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
|
||||
/**
|
||||
* A reference type e.q. Integer or List<T>.
|
||||
* @author Florian Steurer
|
||||
*
|
||||
*/
|
||||
public final class ReferenceType extends UnifyType {
|
||||
|
||||
public ReferenceType(String name, UnifyType... typeParams) {
|
||||
super(name, new TypeParams(typeParams));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user