forked from JavaTX/JavaCompilerCore
JavaClassName eingeführt
This commit is contained in:
parent
bd74b24500
commit
25d61b703b
124
src/mycompiler/myparser/JavaClassName.java
Normal file
124
src/mycompiler/myparser/JavaClassName.java
Normal file
@ -0,0 +1,124 @@
|
||||
package mycompiler.myparser;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import mycompiler.mytype.RefType;
|
||||
|
||||
/**
|
||||
* Stellt den Namen einer Java Klasse dar.
|
||||
* Dieser kann auch den Packagenamen mit beinhalten: java.util.Vector
|
||||
*
|
||||
* @author janulrich
|
||||
*
|
||||
*/
|
||||
public class JavaClassName {
|
||||
|
||||
private String name;
|
||||
private PackageName packageName;
|
||||
|
||||
public JavaClassName(String name){
|
||||
String[] names = name.split("[.]");
|
||||
boolean match = true;
|
||||
if(names.length == 1){
|
||||
packageName = new PackageName();
|
||||
this.name = name;
|
||||
}else {
|
||||
name = names[names.length-1];
|
||||
Vector<String> packageNames = new Vector<String>();
|
||||
for(int i = 0; i<names.length-1;i++){
|
||||
packageNames.add(names[i]);
|
||||
}
|
||||
packageName = new PackageName(packageNames);
|
||||
this.name = names[names.length-1];
|
||||
}
|
||||
}
|
||||
|
||||
//Auto-generated hashCode:
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result
|
||||
+ ((packageName == null) ? 0 : packageName.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Namen sind nur gleich, wenn bei den beiden zu vergleichenden JavaClassNames auch das Package angegeben ist
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if(obj instanceof String)
|
||||
return this.toString().equals(obj) || this.name != null && this.name.equals(obj); //Auch mit Strings als Klassennamen kompatibel TODO: sollte bald obsolet sein
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
JavaClassName other = (JavaClassName) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (packageName == null) {
|
||||
if (other.packageName != null)
|
||||
return false;
|
||||
} else if (!packageName.equals(other.packageName))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return packageName.toString() + name;
|
||||
}
|
||||
}
|
||||
|
||||
class PackageName{
|
||||
|
||||
Vector<String> names = new Vector<String>();
|
||||
|
||||
public PackageName(Vector<String> packageNames) {
|
||||
names = packageNames;
|
||||
}
|
||||
|
||||
public PackageName() {
|
||||
//Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((names == null) ? 0 : names.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
PackageName other = (PackageName) obj;
|
||||
if (names == null) {
|
||||
if (other.names != null)
|
||||
return false;
|
||||
} else if (!names.equals(other.names))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String ret = "";
|
||||
if(names == null)return "";
|
||||
for(String n : names)ret+=n+".";
|
||||
return ret;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user