From 45cad9f675d5d2bfe607a811b23bf445600c351c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Thu, 7 Apr 2016 14:53:29 +0200 Subject: [PATCH] - getDescription ist nicht die Descripiton im Bytecode --- src/de/dhbwstuttgart/syntaxtree/Class.java | 2 +- src/de/dhbwstuttgart/syntaxtree/Field.java | 2 +- src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java | 4 ++-- src/de/dhbwstuttgart/syntaxtree/FormalParameter.java | 2 +- src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java | 6 ++++-- src/de/dhbwstuttgart/syntaxtree/statement/Block.java | 2 +- .../dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java | 2 +- src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java | 7 +++++-- src/de/dhbwstuttgart/syntaxtree/statement/Statement.java | 2 +- src/de/dhbwstuttgart/syntaxtree/type/RefType.java | 6 ------ test/bytecode/SystemOutPrintln.jav | 2 ++ 11 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index e2d97772..09c33f80 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -993,7 +993,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I } @Override - public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){ + public String getDescription(){ return "class "+this.getName(); } @Override diff --git a/src/de/dhbwstuttgart/syntaxtree/Field.java b/src/de/dhbwstuttgart/syntaxtree/Field.java index 25e97f78..1b77df93 100644 --- a/src/de/dhbwstuttgart/syntaxtree/Field.java +++ b/src/de/dhbwstuttgart/syntaxtree/Field.java @@ -108,7 +108,7 @@ public abstract class Field extends GTVDeclarationContext implements TypeInserta } @Override - public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){ + public String getDescription(){ return this.getIdentifier(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java b/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java index f9c2c5cc..f4fa56e7 100644 --- a/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java +++ b/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java @@ -173,7 +173,7 @@ public class FieldDeclaration extends Field{ */ public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) { //Das Feld an die Klasse anfügen: - FieldGen field = new FieldGen(0, this.getType().getBytecodeType(cg, rs), this.getDescription(cg, rs), cg.getConstantPool()); + FieldGen field = new FieldGen(0, this.getType().getBytecodeType(cg, rs), this.getDescription(), cg.getConstantPool()); field.addAttribute(cg.getInstructionFactory().createSignatureAttribute(this.getType().getBytecodeSignature(cg, rs))); cg.addField(field.getField()); @@ -187,7 +187,7 @@ public class FieldDeclaration extends Field{ FieldInstruction putFieldInstruction = cg.getInstructionFactory().createFieldAccess(this.getParentClass().getName().toString(), - this.getDescription(cg, rs), this.getType().getBytecodeType(cg, rs), Constants.PUTFIELD); + this.getDescription(), this.getType().getBytecodeType(cg, rs), Constants.PUTFIELD); il.append(putFieldInstruction ); return il; } diff --git a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java index f897ac05..f2f9099e 100755 --- a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java +++ b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java @@ -234,7 +234,7 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns } @Override - public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){ + public String getDescription(){ String ret = ""; if(this.getType() != null && !(this.getType() instanceof TypePlaceholder)){ ret += this.getType().getBytecodeSignature(null, null); diff --git a/src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java b/src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java index b557ed74..3f2bbfa5 100644 --- a/src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java +++ b/src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java @@ -55,9 +55,11 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{ /** * Eine Beschreibung/Name des SyntaxTree-Nodes + * Hat nichts mit der Description im Bytecode zu tun, + * wird für die Anzeige des AST im Plugin verwendet * @return */ - public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){ + public String getDescription(){ return this.toString(); } @@ -66,7 +68,7 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{ public boolean equals(Object object){ if(!(object instanceof SyntaxTreeNode))return false; SyntaxTreeNode equal = (SyntaxTreeNode)object; - if(!equal.getDescription(null, null).equals(this.getDescription(null, null)))return false; + if(!equal.getDescription().equals(this.getDescription()))return false; if(this.getParent()!=null) if(!this.getParent().equals(equal.getParent()))return false; //auch das Elternelement überprüfen. return true; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Block.java b/src/de/dhbwstuttgart/syntaxtree/statement/Block.java index 2625da53..a149a0cf 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Block.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Block.java @@ -252,7 +252,7 @@ public class Block extends Statement } @Override - public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){ + public String getDescription(){ return "Block"; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java index 423e143f..a5a319b0 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java @@ -379,7 +379,7 @@ public class LocalVarDecl extends Statement implements TypeInsertable } @Override - public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){ + public String getDescription(){ if(this.getType() == null)return "no type " + declid.toString(); if(this.getType() instanceof TypePlaceholder)return declid.toString(); return this.getType().toString() + " " + declid.toString(); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java b/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java index 079f652c..eb1405b2 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java @@ -200,13 +200,16 @@ public class NewClass extends Expr il.append(_cg.getInstructionFactory().createNew(this.getType().getBytecodeType(_cg, rs).toString())); il.append(InstructionConstants.DUP); + String signature = getType().getBytecodeSignature(_cg, rs); + String description = signature.substring(1, signature.length()-1); + if(arglist!=null){ il.append(arglist.generateBytecode(_cg, rs)); - il.append(_cg.getInstructionFactory().createInvoke(this.getType().getDescription(_cg, rs), "", + il.append(_cg.getInstructionFactory().createInvoke(description, "", org.apache.commons.bcel6.generic.Type.VOID, this.arglist.getBytecodeTypeList(_cg, rs), Constants.INVOKESPECIAL)); }else{ - il.append(_cg.getInstructionFactory().createInvoke(this.getType().getDescription(_cg, rs), "", + il.append(_cg.getInstructionFactory().createInvoke(description, "", org.apache.commons.bcel6.generic.Type.VOID, new org.apache.commons.bcel6.generic.Type[]{}, Constants.INVOKESPECIAL)); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java b/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java index 4e1ce702..d6e2e9f8 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java @@ -119,7 +119,7 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse public abstract JavaCodeResult printJavaCode(ResultSet resultSet); @Override - public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){ + public String getDescription(){ return this.printJavaCode(new ResultSet(new Menge())).toString(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index aded666a..80534098 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -874,12 +874,6 @@ public class RefType extends ObjectType implements IMatchable public GenericClassType getGenericClassType(){ return new GenericClassType(getName().toString(), getParaList(), parent, getOffset()); } - - @Override - public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs) { - String signature = getBytecodeSignature(cg, rs); - return signature.substring(1, signature.length()-1); - } } // ino.end diff --git a/test/bytecode/SystemOutPrintln.jav b/test/bytecode/SystemOutPrintln.jav index 37c8078f..c9f7ba39 100644 --- a/test/bytecode/SystemOutPrintln.jav +++ b/test/bytecode/SystemOutPrintln.jav @@ -1,3 +1,5 @@ +import java.lang.System; + class SystemOutPrintln{ void method() { System.out.println("Hello World");