forked from JavaTX/JavaCompilerCore
Type löschen
This commit is contained in:
parent
343c7d3a55
commit
aff39ba442
@ -21,6 +21,8 @@ import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
public class ASTFactory {
|
||||
|
||||
private final JavaClassRegistry names;
|
||||
|
||||
/**
|
||||
* Anmerkung:
|
||||
* Die ASTFactory Methoden, welche ASTBäume aus java.lang.Class Objekten generieren, können davon ausgehen,
|
||||
@ -107,14 +109,14 @@ public class ASTFactory {
|
||||
* @param inClass
|
||||
* @return
|
||||
*/
|
||||
public static Method createMethod(java.lang.reflect.Method jreMethod, java.lang.Class inClass){
|
||||
public Method createMethod(java.lang.reflect.Method jreMethod, java.lang.Class inClass){
|
||||
String name = jreMethod.getName();
|
||||
Type returnType = createType(jreMethod.getReturnType());
|
||||
Parameter[] jreParams = jreMethod.getParameters();
|
||||
List<FormalParameter> params = new ArrayList<>();
|
||||
for(Parameter jreParam : jreParams){
|
||||
Type paramType = createType(jreParam.getType());
|
||||
params.add(new FormalParameter(jreParam.getName(),paramType));
|
||||
RefType paramType = createType(jreParam.getType());
|
||||
params.add(new FormalParameter(jreParam.getName(),paramType,-1));
|
||||
}
|
||||
ParameterList parameterList = new ParameterList(params);
|
||||
Block block = new Block(new ArrayList<Statement>(), -1);
|
||||
@ -128,14 +130,21 @@ public class ASTFactory {
|
||||
|
||||
return new Method(name, returnType, parameterList, block, gtvDeclarations, offset);
|
||||
}
|
||||
|
||||
|
||||
public RefType createType(java.lang.Class jreClass){
|
||||
List<RefType> params = new ArrayList<>();
|
||||
for(TypeVariable jreTV : jreClass.getTypeParameters()){
|
||||
GenericTypeVar gtv = createGeneric(jreTV, jreClass);
|
||||
gtvs.add(gtv);
|
||||
RefType gtv = createType(jreTV);
|
||||
params.add(gtv);
|
||||
}
|
||||
jreClass.getT
|
||||
return new RefType(jreClass.getName(), -1);
|
||||
jreClass
|
||||
return new RefType(jreClass.getName(), params, -1);
|
||||
}
|
||||
|
||||
public RefType createType(java.lang.reflect.Type type){
|
||||
RefType ret = new RefType(type.getTypeName(), -1);
|
||||
//TODO hier die Generischen Variablen extrahieren
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -151,10 +160,11 @@ public class ASTFactory {
|
||||
public GenericTypeVar createGeneric(TypeVariable jreTypeVar, java.lang.Class inClass){
|
||||
//TODO: Bei den Namen der Parameter des Generishen Typs nachschauen, ob er in der Klasse als Generic deklariert wurde
|
||||
String name = jreTypeVar.getTypeName();
|
||||
List<Type> genericBounds = new ArrayList<>();
|
||||
java.lang.reflect.Type[] bounds = jreTypeVar.getBounds();
|
||||
if(bounds.length > 0){
|
||||
for(java.lang.reflect.Type bound : bounds){
|
||||
bound
|
||||
genericBounds.add(createType(bound));
|
||||
}
|
||||
return new BoundedGenericVar();
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public class RefType extends ObjectType implements IMatchable
|
||||
*/
|
||||
private boolean IsArray = false;
|
||||
|
||||
private List<Type> parameter = null;
|
||||
private List<RefType> parameter = null;
|
||||
/**
|
||||
* Ist primitiveFlag auf true, muss beim Codegen dieser Reftype durch
|
||||
* den primitiven Datentyp ersetzt werden
|
||||
@ -69,7 +69,7 @@ public class RefType extends ObjectType implements IMatchable
|
||||
}
|
||||
|
||||
// ino.method.RefType.26640.definition
|
||||
public RefType(String fullyQualifiedName, List parameter,SyntaxTreeNode parent, int offset)
|
||||
public RefType(String fullyQualifiedName, List<RefType> parameter, int offset)
|
||||
// ino.end
|
||||
// ino.method.RefType.26640.body
|
||||
{
|
||||
@ -77,12 +77,8 @@ public class RefType extends ObjectType implements IMatchable
|
||||
this.setName(fullyQualifiedName);
|
||||
if(parameter != null && parameter.size()>0)this.set_ParaList(parameter);
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.RefType.26643.definition
|
||||
public RefType( RefType R, SyntaxTreeNode parent,int offset )
|
||||
// ino.end
|
||||
// ino.method.RefType.26643.body
|
||||
{
|
||||
super(R.name.toString(),offset);
|
||||
// otth: Copy-Konstruktor
|
||||
@ -480,7 +476,13 @@ public class RefType extends ObjectType implements IMatchable
|
||||
ret.addAll(this.printJavaCode(resultSet).getUnresolvedTPH());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean involves(TypePlaceholder tph) {
|
||||
for(RefType param : parameter)
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Menge<TypePlaceholder> getInvolvedTypePlaceholder() {
|
||||
Menge<TypePlaceholder> ret = super.getInvolvedTypePlaceholder();
|
||||
@ -541,7 +543,12 @@ public class RefType extends ObjectType implements IMatchable
|
||||
String ret = new org.apache.bcel.generic.ObjectType(combinedType).getSignature();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getClassSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getCombinedType(ClassGenerator cg, TypeinferenceResultSet rs){
|
||||
//Bsp.: Ljava/util/Vector<Ljava/lang/String;>;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
@ -1,298 +0,0 @@
|
||||
// ino.module.Type.8677.package
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
// ino.end
|
||||
// ino.module.Type.8677.import
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||
import de.dhbwstuttgart.parser.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
|
||||
|
||||
//TODO: Die Klasse Type muss abstract werden!
|
||||
// ino.class.Type.26716.declaration
|
||||
public abstract class Type extends SyntaxTreeNode implements IItemWithOffset
|
||||
// ino.end
|
||||
// ino.class.Type.26716.body
|
||||
{
|
||||
protected JavaClassName name;
|
||||
private int offset;
|
||||
|
||||
public Type(JavaClassName s, int offset)
|
||||
{
|
||||
super(offset);
|
||||
this.offset = offset;
|
||||
this.name = s;
|
||||
}
|
||||
|
||||
// ino.method.getOffset.26735.definition
|
||||
public int getOffset()
|
||||
// ino.end
|
||||
// ino.method.getOffset.26735.body
|
||||
{
|
||||
return offset;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
public void setOffset(int offset){
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
// ino.method.getVariableLength.26738.definition
|
||||
public int getVariableLength()
|
||||
// ino.end
|
||||
// ino.method.getVariableLength.26738.body
|
||||
{
|
||||
if(this.name!=null){return this.name.toString().length();}
|
||||
else{return 1;}
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.get_Name.26747.definition
|
||||
public String get_Name()
|
||||
// ino.end
|
||||
// ino.method.get_Name.26747.body
|
||||
{
|
||||
return name.toString();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
// ino.method.Type2String.26756.definition
|
||||
public String Type2String()
|
||||
// ino.end
|
||||
// ino.method.Type2String.26756.body
|
||||
{
|
||||
return "((TypePlaceholder))" + getName();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.Type2Key.26759.definition
|
||||
public String Type2Key()
|
||||
// ino.end
|
||||
// ino.method.Type2Key.26759.body
|
||||
{
|
||||
return "";
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.getName.26762.definition
|
||||
public JavaClassName getName()
|
||||
// ino.end
|
||||
// ino.method.getName.26762.body
|
||||
{
|
||||
return name;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.equals.26765.defdescription type=javadoc
|
||||
/**
|
||||
* Author: J�rg B�uerle<br/>
|
||||
* @param Object
|
||||
* @return
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.equals.26765.definition
|
||||
public boolean equals(Object obj)
|
||||
// ino.end
|
||||
// ino.method.equals.26765.body
|
||||
{
|
||||
if(obj instanceof Type){
|
||||
// String name2 = ((Type)obj).printJavaCode(new ResultSet()).toString();
|
||||
//return printJavaCode(new ResultSet()).toString().equals(name2);
|
||||
if(((Type)obj).name == null)return false; //Auch wenn der Name dieses Typs auch null ist. Typen sind nur gleich wenn sie einen gleichen Namen haben, welcher nicht null ist.
|
||||
return ((Type)obj).name.equals(name);
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.clone.26768.defdescription type=javadoc
|
||||
/**
|
||||
* <br>Author: J�rg B�uerle
|
||||
* @return
|
||||
|
||||
// ino.end
|
||||
// ino.method.clone.26768.definition
|
||||
public Type clone()
|
||||
// ino.end
|
||||
// ino.method.clone.26768.body
|
||||
{
|
||||
return new RefType(this.getName().toString(), this.getParent(),getOffset());
|
||||
}
|
||||
// ino.end
|
||||
*/
|
||||
|
||||
public abstract Type clone();
|
||||
|
||||
// ino.method.toString.26771.defdescription type=javadoc
|
||||
/**
|
||||
* <br/>Author: J�rg B�uerle
|
||||
* @return
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.toString.26771.definition
|
||||
public String toString()
|
||||
// ino.end
|
||||
// ino.method.toString.26771.body
|
||||
{
|
||||
return getName().toString();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
/*
|
||||
// ino.method.removeClassParameters.26774.definition
|
||||
public Type removeClassParameters()
|
||||
// ino.end
|
||||
// ino.method.removeClassParameters.26774.body
|
||||
{
|
||||
if(this instanceof RefType){
|
||||
RefType rt=(RefType)this.clone();
|
||||
rt.set_ParaList(null);
|
||||
return(rt);
|
||||
}else{
|
||||
return(this);
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
*/
|
||||
|
||||
// ino.method.getSimpleName.26777.defdescription type=javadoc
|
||||
/**
|
||||
* HOTI
|
||||
* Liefert bei Klassen die fullyQualified angegeben wurden
|
||||
* nur den schlussendlichen Bezeichner
|
||||
* p.ex. de.dhbwstuttgart.typeinference.Menge => Menge
|
||||
* @return
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.getSimpleName.26777.definition
|
||||
public String getSimpleName()
|
||||
// ino.end
|
||||
// ino.method.getSimpleName.26777.body
|
||||
{
|
||||
return name.getName();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
public JavaCodeResult printJavaCode(ResultSet resultSet){
|
||||
return new JavaCodeResult(this.name.toString());
|
||||
}
|
||||
|
||||
public JavaCodeResult printJavaCode(ResultSet resultSet, boolean resolveTPHs){
|
||||
return printJavaCode(resultSet);
|
||||
}
|
||||
|
||||
public Type applyResultSet(ResultSet result){
|
||||
return this.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert alle SuperWildcardTypes, die in diesem Typ enthalten sind.
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<SuperWildcardType> getSuperWildcardTypes() {
|
||||
ArrayList<SuperWildcardType> ret = new ArrayList<SuperWildcardType>();
|
||||
if(this instanceof SuperWildcardType)ret.add((SuperWildcardType)this);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sucht nach TPHs in diesem Typ, denen das resultSet keinen Typ zuordnen kann.
|
||||
* @param resultSet
|
||||
* @return
|
||||
*/
|
||||
public Menge<TypePlaceholder> getUnresolvedTPH(ResultSet resultSet) {
|
||||
return new Menge<TypePlaceholder>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft ob der Typ von dem übergebenen TypPlaceholder abhängt.
|
||||
* @param tph
|
||||
* @return
|
||||
*/
|
||||
public boolean involves(TypePlaceholder tph) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft ob der Typ in den Assumptions ass vorhanden ist.
|
||||
* Dabei kann eine neue Instanz eines Typs entstehen, welche von der Methode zurückgegeben wird.
|
||||
* @param ass - Die Assumptions für den jeweiligen Kontext in dem sich der Typ befindet.
|
||||
|
||||
public ConstraintType checkType(TypeAssumptions ass, SyntaxTreeNode parent){
|
||||
ConstraintType t = ass.getTypeFor(this, this);
|
||||
if(t==null)
|
||||
throw new TypeinferenceException("Der Typ "+this.getName()+" ist nicht korrekt", parent);
|
||||
return t;
|
||||
}
|
||||
*/
|
||||
//TODO: checkType wird nicht mehr gebraucht. TYPE übernimmt dessen Aufgabe. Es muss nur sichergestellt werden, dass jeder Typ in den Constraints landet, dadurch wird für jeden Typ die Methode TYPE aufgerufen.
|
||||
public Type TYPE(TypeAssumptions ass, SyntaxTreeNode parent){
|
||||
Type t = ass.getTypeFor(this, parent);
|
||||
if(t==null)
|
||||
throw new TypeinferenceException("Der Typ "+this.getName()+" ist nicht korrekt", parent);
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sammelt alle TypePlaceholder, welche in diesem Typ vorkommen.
|
||||
* @return
|
||||
*/
|
||||
public Menge<TypePlaceholder> getInvolvedTypePlaceholder(){
|
||||
Menge<TypePlaceholder> ret = new Menge<>();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Menge<SyntaxTreeNode> getChildren() {
|
||||
return new Menge<>();
|
||||
}
|
||||
|
||||
public Type checkTYPE(TypeAssumptions ass, SyntaxTreeNode method){
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract org.apache.bcel.generic.Type getBytecodeType(ClassGenerator cg, TypeinferenceResultSet rs);
|
||||
|
||||
/**
|
||||
* Erzeugt einen String, welcher den Typ genauer angibt.
|
||||
* Dieser kann dann in Methoden und Feldersignaturen verwendet werden
|
||||
* @param cg
|
||||
* @return
|
||||
*/
|
||||
public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
return this.getBytecodeType(cg, rs).getSignature();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cg
|
||||
* @return Die Signatur wie sie in Klassensignaturen verwendet wird
|
||||
*/
|
||||
public String getClassSignature(ClassGenerator cg, TypeinferenceResultSet rs){
|
||||
return this.getBytecodeSignature(cg, rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wird beim Bytecode gebraucht.
|
||||
* Einige Klassen werden vom Compiler als gegeben angenommen,
|
||||
* obwohl sie sich nicht in der Java Standard Library befinden.
|
||||
* Diese müssen beim generieren von Bytecode als zusätzliche Klassen generiert werden.
|
||||
*
|
||||
* @return - Eine Liste der Klassen, welche bei Verwendung dieses Typs zusätzlich gebraucht werden.
|
||||
*/
|
||||
//public abstract List<de.dhbwstuttgart.syntaxtree.Class> isClassFromJavaX();
|
||||
}
|
||||
// ino.end
|
@ -18,7 +18,7 @@ import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
*
|
||||
*/
|
||||
|
||||
public abstract class WildcardType extends Type{
|
||||
public abstract class WildcardType extends RefType{
|
||||
|
||||
protected ObjectType innerType = null;
|
||||
|
||||
@ -46,20 +46,11 @@ public abstract class WildcardType extends Type{
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Die Allgemeine Wildcard enthält keinen Typen.
|
||||
*/
|
||||
public Type GetWildcardType()
|
||||
public RefType GetWildcardType()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Setzt den Typ in der Wildcard, Allgemeine Wildcard hat aber keinen Typen.
|
||||
* @param T - Type to be set
|
||||
*/
|
||||
public void SetWildcardType(Type T)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
@ -67,7 +58,7 @@ public abstract class WildcardType extends Type{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type TYPE(TypeAssumptions ass, SyntaxTreeNode parent) {
|
||||
public RefType TYPE(TypeAssumptions ass, SyntaxTreeNode parent) {
|
||||
this.innerType = (ObjectType) innerType.TYPE(ass, this);
|
||||
return this;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user