JavaPatternMatching/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java

90 lines
2.7 KiB
Java
Raw Normal View History

2014-09-02 08:33:54 +00:00
package de.dhbwstuttgart.syntaxtree;
2013-10-18 11:33:46 +00:00
import de.dhbwstuttgart.typeinference.Menge;
2016-12-02 00:23:01 +00:00
import java.util.List;
import de.dhbwstuttgart.bytecode.ClassGenerator;
2014-10-09 10:01:16 +00:00
import de.dhbwstuttgart.logger.Logger;
2014-09-02 08:33:54 +00:00
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeInsertable;
import de.dhbwstuttgart.typeinference.Typeable;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
2014-09-02 08:33:54 +00:00
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
2013-10-18 11:33:46 +00:00
public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeInsertable
2013-10-18 11:33:46 +00:00
{
private Type type;
private String name;
2013-10-18 11:33:46 +00:00
protected static Logger inferencelog = Logger.getLogger("inference");
2016-09-16 11:25:20 +00:00
public FormalParameter(String name, Type type, int offset){
super(offset);
this.name = name;
this.type = type;
}
2013-10-18 11:33:46 +00:00
2014-04-09 12:12:55 +00:00
@Override
public boolean equals(Object object) {
//if(!super.equals(object))return false; //Nicht die Position im SyntaxBaum prüfen.
2014-04-09 12:12:55 +00:00
if(!(object instanceof FormalParameter))return false;
FormalParameter equals = (FormalParameter)object;
if((this.type==null)!=(equals.type == null))return false;
if(this.type != null){
return this.type.equals(equals.type);
}
2014-04-09 12:12:55 +00:00
return true;
}
2013-10-18 11:33:46 +00:00
2014-02-19 04:20:54 +00:00
public String getIdentifier()
2013-10-18 11:33:46 +00:00
{
return name;
2013-10-18 11:33:46 +00:00
}
public Type getType()
{
return type;
}
@Override
public String toString(){
String ret = "";
if(this.getType() != null)ret += this.getType().toString();
2014-02-19 04:20:54 +00:00
if(this.getIdentifier() != null)ret += " "+getIdentifier();
2013-10-18 11:33:46 +00:00
return ret;
}
public JavaCodeResult printJavaCode(ResultSet resultSet) {
JavaCodeResult ret = new JavaCodeResult();
if(this.getType() != null)ret.attach(this.getType().printJavaCode(resultSet));
2014-02-19 04:20:54 +00:00
if(this.getIdentifier() != null)ret.attach(" "+getIdentifier());
2013-10-18 11:33:46 +00:00
return ret;
}
@Override
public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph,
ResultSet resultSet) {
if(this.getOffset()<=0)return null;
Type t = resultSet.getTypeEqualTo(tph);
return new TypeInsertPoint(this, this, t, resultSet);
}
@Override
public String getDescription(){
String ret = "";
if(this.getType() != null && !(this.getType() instanceof TypePlaceholder)){
2016-04-29 14:52:35 +00:00
ret += this.getType().toString();//getBytecodeSignature(null, null);
}
return ret+this.getIdentifier();
}
2013-10-18 11:33:46 +00:00
}