forked from i21017/JavaCompilerCore
Compare commits
2 Commits
1391206dfe
...
7442880452
Author | SHA1 | Date | |
---|---|---|---|
|
7442880452 | ||
|
c4dc3b4245 |
@@ -24,17 +24,11 @@ public final class PlaceholderType extends UnifyType{
|
|||||||
* Used for generating fresh placeholders.
|
* Used for generating fresh placeholders.
|
||||||
*/
|
*/
|
||||||
public static final ArrayList<String> EXISTING_PLACEHOLDERS = new ArrayList<String>();
|
public static final ArrayList<String> EXISTING_PLACEHOLDERS = new ArrayList<String>();
|
||||||
|
|
||||||
/**
|
|
||||||
* Prefix of auto-generated placeholder names.
|
private static final char[] PLACEHOLDER_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
|
||||||
*/
|
private static int placeholderCount = 0;
|
||||||
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.
|
* True if this object was auto-generated, false if this object was user-generated.
|
||||||
*/
|
*/
|
||||||
@@ -100,16 +94,24 @@ public final class PlaceholderType extends UnifyType{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a fresh placeholder type with a name that does so far not exist.
|
* Creates a fresh placeholder type with a name that does so far not exist from the chars A-Z.
|
||||||
* A user could later instantiate a type using the same name that is equivalent to this type.
|
* A user could later instantiate a type using the same name that is equivalent to this type.
|
||||||
* @return A fresh placeholder type.
|
* @return A fresh placeholder type.
|
||||||
*/
|
*/
|
||||||
public synchronized static PlaceholderType freshPlaceholder() {
|
public synchronized static PlaceholderType freshPlaceholder() {
|
||||||
String name = nextName + (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z'
|
String name;
|
||||||
// Add random chars while the name is in use.
|
do {
|
||||||
while(EXISTING_PLACEHOLDERS.contains(name)) {
|
int pc = PlaceholderType.placeholderCount++;
|
||||||
name += (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z'
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
while (pc >= 0) {
|
||||||
|
sb.insert(0, PLACEHOLDER_CHARS[pc % 26]);
|
||||||
|
pc = pc / 26 - 1;
|
||||||
|
}
|
||||||
|
name = sb.toString();
|
||||||
}
|
}
|
||||||
|
while (EXISTING_PLACEHOLDERS.contains(name));
|
||||||
|
|
||||||
return new PlaceholderType(name, true);
|
return new PlaceholderType(name, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user