From a2cdd0185062f53fd7b679af304bf085724f8bcf Mon Sep 17 00:00:00 2001 From: michael Date: Mon, 9 Dec 2019 13:54:28 +0100 Subject: [PATCH] =?UTF-8?q?Bug=20161=20-=20Automatische=20Merhoden-Erg?= =?UTF-8?q?=C3=A4nzung=20funktioniert=20nicht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/typinferenzplugin/Typinferenz.java | 14 +++++- .../editor/IdentifierFinder.java | 49 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/Typinferenz.java b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/Typinferenz.java index 025127c..b7b9d63 100644 --- a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/Typinferenz.java +++ b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/Typinferenz.java @@ -8,6 +8,8 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.StringWriter; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -28,6 +30,7 @@ import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultFor import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.exceptions.TypeinferenceException; import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; @@ -133,12 +136,21 @@ public class Typinferenz { Set ret = new TreeSet<>(); try { for (ResultSet tiResult : tiResults) { - ret.add(tiResult.resolveType(tph).resolvedType.acceptTV(new TypeToDescriptor())); + if (tiResult.resolveType(tph).resolvedType instanceof RefType) { + ret.add(((RefType)tiResult.resolveType(tph).resolvedType).getName().toString()); + } else { + ret.add(tiResult.resolveType(tph).getResultPair().getRight().toString()); + } } } catch (TypeinferenceException texc) { throw texc; // Die aufrufende Instanz sollte daraus dann einen ErrorMarker generieren. } catch (Exception exc) { exc.printStackTrace(); // Hier wird kein Marker generiert... nur Debug-Output + + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + exc.printStackTrace(pw); + new ErrorOutput("Fehler beim Parsen und Inferieren"); } diff --git a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/IdentifierFinder.java b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/IdentifierFinder.java index 5a83645..096e9b7 100644 --- a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/IdentifierFinder.java +++ b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/IdentifierFinder.java @@ -1,11 +1,18 @@ package typinferenzplugin.editor; import java.sql.Ref; +import java.util.Iterator; import java.util.Set; import java.util.TreeSet; +import org.antlr.runtime.tree.TreeFilter.fptr; + import de.dhbwstuttgart.syntaxtree.ASTVisitor; import de.dhbwstuttgart.syntaxtree.AbstractASTWalker; +import de.dhbwstuttgart.syntaxtree.Field; +import de.dhbwstuttgart.syntaxtree.FormalParameter; +import de.dhbwstuttgart.syntaxtree.ParameterList; +import de.dhbwstuttgart.syntaxtree.statement.FieldVar; import de.dhbwstuttgart.syntaxtree.statement.LocalVar; import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl; import de.dhbwstuttgart.syntaxtree.type.RefType; @@ -92,4 +99,46 @@ public class IdentifierFinder extends AbstractASTWalker implements ASTVisitor, R System.out.println(); } + + @Override + public void visit(ParameterList formalParameters) { + for (FormalParameter fp : formalParameters) { + if (fp.getName().equals(identifier)) { + this.result = fp.getType(); + if (fp.getType() instanceof TypePlaceholder) { + ((TypePlaceholder)fp.getType()).accept((ASTVisitor)this); + } else if (fp.getType() instanceof RefType) { + ((RefType)fp.getType()).accept((ASTVisitor)this); + } + } + } + + super.visit(formalParameters); + } + + @Override + public void visit(Field field) { + if (field.getName().equals(identifier)) { + this.result = field.getType(); + if (field.getType() instanceof TypePlaceholder) { + ((TypePlaceholder)field.getType()).accept((ASTVisitor)this); + } else if (field.getType() instanceof RefType) { + ((RefType)field.getType()).accept((ASTVisitor)this); + } + } + } + + @Override + public void visit(FieldVar field) { + if (field.fieldVarName.equals(identifier)) { + this.result = field.getType(); + if (field.getType() instanceof TypePlaceholder) { + ((TypePlaceholder)field.getType()).accept((ASTVisitor)this); + } else if (field.getType() instanceof RefType) { + ((RefType)field.getType()).accept((ASTVisitor)this); + } + } + } + + }