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

258 lines
6.2 KiB
Java
Executable File

// ino.module.FormalParameter.8561.package
package de.dhbwstuttgart.syntaxtree;
// ino.end
// ino.module.FormalParameter.8561.import
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.bytecode.ClassFile;
import de.dhbwstuttgart.bytecode.CodeAttribute;
import de.dhbwstuttgart.syntaxtree.misc.DeclId;
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.exceptions.NotImplementedException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
// ino.class.FormalParameter.23391.declaration
public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeInsertable
// ino.end
// ino.class.FormalParameter.23391.body
{
// ino.attribute.type.23395.declaration
private Type type;
// ino.end
// ino.attribute.declid.23398.declaration
private DeclId declid;
// ino.end
// ino.attribute.inferencelog.23401.declaration
protected static Logger inferencelog = Logger.getLogger("inference");
// ino.end
public FormalParameter(DeclId name){
this.set_DeclId(name);
}
@Override
public boolean equals(Object object) {
//if(!super.equals(object))return false; //Nicht die Position im SyntaxBaum prüfen.
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);
}
return true;
}
// ino.method.setType.23404.defdescription type=javadoc
/**
* <br/>Author: J�rg B�uerle
* @param t
*/
// ino.end
// ino.method.setType.23404.definition
public void setType(Type t)
// ino.end
// ino.method.setType.23404.body
{
this.type = t;
}
// ino.end
// ino.method.set_DeclId.23407.definition
public void set_DeclId(DeclId did)
// ino.end
// ino.method.set_DeclId.23407.body
{
if(did == null)throw new NullPointerException();
this.declid = did;
}
// ino.end
// ino.method.get_Name.23410.definition
public String getIdentifier()
// ino.end
// ino.method.get_Name.23410.body
{
return declid.get_Name();
}
// ino.end
// ino.method.getType.23413.definition
public Type getType()
// ino.end
// ino.method.getType.23413.body
{
return type;
}
// ino.end
// ino.method.getTypeName.23416.definition
public String getTypeName()
// ino.end
// ino.method.getTypeName.23416.body
{ if(this.getType() == null)return "";
return this.getType().getName().toString();
}
// ino.end
// ino.method.codegen.23419.definition
public void codegen(ClassFile classfile, CodeAttribute code)
// ino.end
// ino.method.codegen.23419.body
{
code.add_local(declid.get_Name(), this.getType());
}
// ino.end
// ino.method.getOffset.23422.defdescription type=javadoc
/**
* <br/>Author: Thomas Hornberger 09.04.2006
* @return
*/
// ino.end
// ino.method.getOffset.23422.definition
public int getOffset()
// ino.end
// ino.method.getOffset.23422.body
{
return declid.getOffset();
}
// ino.end
// ino.method.getLineNumber.23425.defdescription type=javadoc
/**
* <br/>Author: J�rg B�uerle
* @return
*/
// ino.end
// ino.method.getLineNumber.23425.definition
public int getLineNumber()
// ino.end
// ino.method.getLineNumber.23425.body
{
return declid.getLineNumber();
}
// ino.end
// ino.method.getTypeLineNumber.23431.defdescription type=javadoc
/**
* <br>Author: J�rg B�uerle
* @return
*/
// ino.end
// ino.method.getTypeLineNumber.23431.definition
public int getTypeLineNumber()
// ino.end
// ino.method.getTypeLineNumber.23431.body
{
return this.getLineNumber();
}
// ino.end
//private Type typeVariable;
public String getTypeInformation() {
return getType().toString() + " " +this.getIdentifier();
}
@Override
public String toString(){
String ret = "";
if(this.getType() != null)ret += this.getType().toString();
if(this.getIdentifier() != null)ret += " "+getIdentifier();
return ret;
}
public JavaCodeResult printJavaCode(ResultSet resultSet) {
JavaCodeResult ret = new JavaCodeResult();
if(this.getType() != null)ret.attach(this.getType().printJavaCode(resultSet));
if(this.getIdentifier() != null)ret.attach(" "+getIdentifier());
return ret;
}
@Override
public void setOffset(int offset) {
//Das Offset steht in declId
throw new NotImplementedException();
}
@Override
public Menge<SyntaxTreeNode> getChildren() {
Menge<SyntaxTreeNode> ret = new Menge<SyntaxTreeNode>();
if(type != null)ret.add(this.type);
return ret;
}
@Override
public void parserPostProcessing(SyntaxTreeNode parent) {
super.parserPostProcessing(parent);
if(this.type==null)this.type = TypePlaceholder.fresh(this);
}
@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 int getVariableLength() {
int ret = 0;
ret += this.getTypeName().length();
ret +=this.getIdentifier().length();
return ret;
}
public DeclId getDeclId() {
return this.declid;
}
@Override
public String getDescription() {
String ret = "";
if(this.getType() != null && !(this.getType() instanceof TypePlaceholder)){
ret += this.getType().getName() + " ";
}
return ret+this.getIdentifier();
}
}
// ino.end