Code completion uses classpath of generateed classes.
This commit is contained in:
parent
c351cd4adf
commit
744b9ac99d
@ -1,10 +1,14 @@
|
||||
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 java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
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.IContextInformation;
|
||||
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
|
||||
import org.eclipse.swt.internal.C;
|
||||
|
||||
import typinferenzplugin.Activator;
|
||||
|
||||
@ -51,6 +56,9 @@ public class JafCompletionProcess implements IContentAssistProcessor {
|
||||
Set<String> methodNames = 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))) {
|
||||
if (prop.contains("<")) {
|
||||
prop = prop.substring(0, prop.indexOf('<'));
|
||||
@ -61,10 +69,10 @@ public class JafCompletionProcess implements IContentAssistProcessor {
|
||||
}
|
||||
|
||||
try {
|
||||
for (Method meth : Class.forName(prop).getMethods()) {
|
||||
for (Method meth : additionalCP.loadClass(prop).getMethods()) {
|
||||
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());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -91,6 +99,11 @@ public class JafCompletionProcess implements IContentAssistProcessor {
|
||||
return NO_COMPLETIONS;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
return lastChar(doc, offset) == DOT_OPERATOR;
|
||||
|
Loading…
Reference in New Issue
Block a user