Bug 161 - Automatische Merhoden-Ergänzung funktioniert nicht

This commit is contained in:
michael 2019-12-09 13:54:28 +01:00
parent 95b5523615
commit a2cdd01850
2 changed files with 62 additions and 1 deletions

View File

@ -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<String> 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");
}

View File

@ -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);
}
}
}
}