Code completion uses classpath of generateed classes.
This commit is contained in:
parent
c351cd4adf
commit
744b9ac99d
@ -1,10 +1,14 @@
|
|||||||
package typinferenzplugin.editor;
|
package typinferenzplugin.editor;
|
||||||
|
|
||||||
import static org.eclipse.core.runtime.IStatus.*;
|
import static org.eclipse.core.runtime.IStatus.ERROR;
|
||||||
|
import static org.eclipse.core.runtime.IStatus.WARNING;
|
||||||
import static typinferenzplugin.Activator.PLUGIN_ID;
|
import static typinferenzplugin.Activator.PLUGIN_ID;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -21,6 +25,7 @@ import org.eclipse.jface.text.contentassist.ICompletionProposal;
|
|||||||
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
|
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
|
||||||
import org.eclipse.jface.text.contentassist.IContextInformation;
|
import org.eclipse.jface.text.contentassist.IContextInformation;
|
||||||
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
|
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
|
||||||
|
import org.eclipse.swt.internal.C;
|
||||||
|
|
||||||
import typinferenzplugin.Activator;
|
import typinferenzplugin.Activator;
|
||||||
|
|
||||||
@ -51,6 +56,9 @@ public class JafCompletionProcess implements IContentAssistProcessor {
|
|||||||
Set<String> methodNames = new TreeSet<>();
|
Set<String> methodNames = new TreeSet<>();
|
||||||
Set<String> fieldNames = new TreeSet<>();
|
Set<String> fieldNames = new TreeSet<>();
|
||||||
|
|
||||||
|
//LOG.log(new Status(WARNING, PLUGIN_ID,"New path for classpath: " + editor.getFilePath().toFile().getAbsolutePath()));
|
||||||
|
ClassLoader additionalCP = addPath(editor.getFilePath().toFile().getParentFile());
|
||||||
|
|
||||||
for (String prop : editor.resolveTypeInserts(prefix, evaluateLineNumber(doc, offset))) {
|
for (String prop : editor.resolveTypeInserts(prefix, evaluateLineNumber(doc, offset))) {
|
||||||
if (prop.contains("<")) {
|
if (prop.contains("<")) {
|
||||||
prop = prop.substring(0, prop.indexOf('<'));
|
prop = prop.substring(0, prop.indexOf('<'));
|
||||||
@ -61,10 +69,10 @@ public class JafCompletionProcess implements IContentAssistProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (Method meth : Class.forName(prop).getMethods()) {
|
for (Method meth : additionalCP.loadClass(prop).getMethods()) {
|
||||||
methodNames.add(meth.getName() + " from " + meth.getDeclaringClass().getCanonicalName());
|
methodNames.add(meth.getName() + " from " + meth.getDeclaringClass().getCanonicalName());
|
||||||
}
|
}
|
||||||
for (Field fld : Class.forName(prop).getFields()) {
|
for (Field fld : additionalCP.loadClass(prop).getFields()) {
|
||||||
fieldNames.add(fld.getName());// + " from " + fld.getDeclaringClass().getCanonicalName());
|
fieldNames.add(fld.getName());// + " from " + fld.getDeclaringClass().getCanonicalName());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -92,6 +100,11 @@ public class JafCompletionProcess implements IContentAssistProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ClassLoader addPath(File f ) throws Exception {
|
||||||
|
URL u = f.toURI().toURL();
|
||||||
|
return URLClassLoader.newInstance(new URL[]{u}, Thread.currentThread().getContextClassLoader());
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isAfterDotOper(int offset, IDocument doc) {
|
private boolean isAfterDotOper(int offset, IDocument doc) {
|
||||||
return lastChar(doc, offset) == DOT_OPERATOR;
|
return lastChar(doc, offset) == DOT_OPERATOR;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user