Ersetzung funtioniert jetzt.
This commit is contained in:
parent
dd6d5de33c
commit
1dd755bc0a
@ -17,7 +17,7 @@
|
||||
<classpathentry kind="lib" path="lib/icu4j.jar"/>
|
||||
<classpathentry kind="lib" path="lib/j2objc-annotations.jar"/>
|
||||
<classpathentry kind="lib" path="lib/javassist.jar"/>
|
||||
<classpathentry kind="lib" path="lib/JavaTXcompiler.jar"/>
|
||||
<classpathentry kind="lib" path="lib/JavaTXcompiler.jar" sourcepath="/JavaCompilerCore"/>
|
||||
<classpathentry kind="lib" path="lib/javax.json.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jsr305.jar"/>
|
||||
<classpathentry kind="lib" path="lib/listenablefuture.jar"/>
|
||||
|
@ -0,0 +1,63 @@
|
||||
package typinferenzplugin.editor;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHEqualTPH;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
||||
|
||||
public class IdentifierFinder extends AbstractASTWalker implements ASTVisitor, ResultSetVisitor {
|
||||
|
||||
private RefTypeOrTPHOrWildcardOrGeneric result;
|
||||
|
||||
private String identifier;
|
||||
private int line;
|
||||
|
||||
public IdentifierFinder(String identifier, int line) {
|
||||
this.identifier = identifier;
|
||||
this.line = line;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LocalVar localVar) {
|
||||
if (localVar.name.equals(identifier)) {
|
||||
this.result = localVar.getType();
|
||||
localVar.getType().accept((ResultSetVisitor)this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LocalVarDecl localVar) {
|
||||
if (localVar.getName().equals(identifier)) {
|
||||
this.result = localVar.getType();
|
||||
localVar.getType().accept((ResultSetVisitor)this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visit(PairTPHsmallerTPH p) {
|
||||
System.out.println();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(PairTPHequalRefTypeOrWildcardType p) {
|
||||
System.out.println();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(PairTPHEqualTPH p) {
|
||||
System.out.println();
|
||||
}
|
||||
}
|
@ -1,9 +1,16 @@
|
||||
package typinferenzplugin.editor;
|
||||
|
||||
import static org.eclipse.core.runtime.IStatus.ERROR;
|
||||
import static org.eclipse.core.runtime.IStatus.WARNING;
|
||||
import static typinferenzplugin.Activator.PLUGIN_ID;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.eclipse.core.runtime.ILog;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
@ -16,7 +23,6 @@ import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
|
||||
import org.eclipse.jface.text.contentassist.IContextInformation;
|
||||
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
|
||||
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import typinferenzplugin.Activator;
|
||||
|
||||
public class JafCompletionProcess implements IContentAssistProcessor {
|
||||
@ -39,21 +45,46 @@ public class JafCompletionProcess implements IContentAssistProcessor {
|
||||
IDocument doc = viewer.getDocument();
|
||||
|
||||
if (isAfterDotOper(offset, doc)) {
|
||||
String prefix = lastWord(doc, offset - 1);
|
||||
String indent = lastIndent(doc, offset);
|
||||
String prefix = lastWord(doc, offset);
|
||||
|
||||
ArrayList<ICompletionProposal> result = new ArrayList<>();
|
||||
/*
|
||||
for (String ti : editor.resolveTypeInserts()) {
|
||||
String proposal = ti;
|
||||
result.add(new CompletionProposal(proposal, offset - prefix.length(), prefix.length(), proposal.length()));
|
||||
}
|
||||
*/
|
||||
Collection<ICompletionProposal> result = new ArrayList<>();
|
||||
Set<String> duplicatesFinder = new HashSet<>();
|
||||
Set<String> methodNames = new TreeSet<>();
|
||||
Set<String> fieldNames = new TreeSet<>();
|
||||
|
||||
String proposal = "Line '" + evaluateLineNumber(doc, offset) + "' identifer '" + lastWord(doc, offset) + "'.";
|
||||
result.add(new CompletionProposal(proposal, offset - prefix.length(), prefix.length(), proposal.length()));
|
||||
|
||||
return (ICompletionProposal[]) result.toArray(new ICompletionProposal[result.size()]);
|
||||
for (String prop : editor.resolveTypeInserts(prefix, evaluateLineNumber(doc, offset))) {
|
||||
if (prop.contains("<")) {
|
||||
prop = prop.substring(0, prop.indexOf('<'));
|
||||
}
|
||||
|
||||
if (!duplicatesFinder.add(prop)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
for (Method meth : Class.forName(prop).getMethods()) {
|
||||
methodNames.add(meth.getName() + " from " + meth.getDeclaringClass().getCanonicalName());
|
||||
}
|
||||
for (Field fld : Class.forName(prop).getFields()) {
|
||||
fieldNames.add(fld.getName());// + " from " + fld.getDeclaringClass().getCanonicalName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.log(new Status(WARNING, PLUGIN_ID, e.getMessage(), e));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
for (String methProp : methodNames) {
|
||||
String insertMeth = methProp.substring(0, methProp.indexOf(' '));
|
||||
result.add(new CompletionProposal(insertMeth, offset, 0, insertMeth.length(), null, methProp, null, null));
|
||||
}
|
||||
|
||||
for (String fieldProp : fieldNames) {
|
||||
fieldProp = "." + fieldProp;
|
||||
result.add(new CompletionProposal(fieldProp, offset - prefix.length(), prefix.length(), fieldProp.length()));
|
||||
}
|
||||
|
||||
return (ICompletionProposal[]) result.toArray(new ICompletionProposal[result.size()]);
|
||||
}
|
||||
return NO_COMPLETIONS;
|
||||
} catch (Exception e) {
|
||||
@ -103,21 +134,6 @@ public class JafCompletionProcess implements IContentAssistProcessor {
|
||||
return ' ';
|
||||
}
|
||||
|
||||
private String lastIndent(IDocument doc, int offset) {
|
||||
try {
|
||||
int start = offset - 1;
|
||||
while (start >= 0 && doc.getChar(start) != '\n')
|
||||
start--;
|
||||
int end = start;
|
||||
while (end > offset && Character.isSpaceChar(doc.getChar(end)))
|
||||
end++;
|
||||
return doc.get(start + 1, end - start - 1);
|
||||
} catch (BadLocationException e) {
|
||||
LOG.log(new Status(ERROR, PLUGIN_ID, e.getMessage(), e));
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IContextInformation[] computeContextInformation(ITextViewer arg0, int arg1) {
|
||||
return NO_CONTEXTS;
|
||||
@ -143,4 +159,5 @@ public class JafCompletionProcess implements IContentAssistProcessor {
|
||||
return "Error resolving Autocomplete in '" + PLUGIN_ID + "'.";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import typinferenzplugin.Activator;
|
||||
import typinferenzplugin.CodePoint;
|
||||
@ -34,7 +35,9 @@ import typinferenzplugin.error.ErrorOutput;
|
||||
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.TreeSet;
|
||||
|
||||
//Example from: http://help.eclipse.org/indigo/index.jsp
|
||||
/**
|
||||
@ -215,7 +218,7 @@ public class JavEditor extends TextEditor{
|
||||
IDocument document = this.getDocumentProvider().getDocument(this.getEditorInput());
|
||||
document.set(typeReplaceMarker.insertType(document.get()));
|
||||
this.removeMarkers();
|
||||
//Erneut den Typinferenzalgorithmus ausführen:
|
||||
//Erneut den Typinferenzalgorithmus ausführen:
|
||||
this.typeReconstruction();
|
||||
}
|
||||
|
||||
@ -251,9 +254,22 @@ public class JavEditor extends TextEditor{
|
||||
return typeReplaceMarkers ;
|
||||
}
|
||||
|
||||
public Collection<String> resolveTypeInserts() {
|
||||
return typeinference.getSourceFile().getImports().stream().map(i -> i.toString()).collect(Collectors.toList());
|
||||
//return getTypeReplaceMarkers().stream().map(ti -> ti.getInsertPoint()).collect(toSet());
|
||||
public Collection<String> resolveTypeInserts(String identifier, int line) {
|
||||
Collection<String> typesToInsert = new TreeSet<>();
|
||||
|
||||
IdentifierFinder identifierFinder = new IdentifierFinder(identifier, line);
|
||||
typeinference.getSourceFile().accept(identifierFinder);
|
||||
RefTypeOrTPHOrWildcardOrGeneric result = identifierFinder.getResult();
|
||||
|
||||
int type = result.getOffset().getTokenIndex();
|
||||
|
||||
|
||||
for (TypeReplaceMarker trm : typeinference.run()) {
|
||||
int tp = trm.getPoint().getPositionInCode();
|
||||
typesToInsert.add(trm.getInsertPoint().getInsertString());
|
||||
}
|
||||
|
||||
return typesToInsert;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,7 +27,7 @@
|
||||
<dependency>
|
||||
<groupId>de.dhbwstuttgart</groupId>
|
||||
<artifactId>JavaTXcompiler</artifactId>
|
||||
<version>0.1.0</version>
|
||||
<version>0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.antlr</groupId>
|
||||
|
Loading…
Reference in New Issue
Block a user