[autocomplete] 39/143: Can now pass a different classloader for CompletionXMLParser to use for custom FunctionCompletions, etc., if necessary. Fixed Java completion bug - fields & methods sometimes didn't return correct containing type. Perl completion now only uses system perldoc if Perl home is set AND "use perldoc" option is also set.
Benjamin Mesing
ben at alioth.debian.org
Sat Oct 19 12:53:14 UTC 2013
This is an automated email from the git hooks/post-receive script.
ben pushed a commit to branch master
in repository autocomplete.
commit 99c13732b13be757bbd3161c757e10daa8d6508c
Author: bobbylight <robert at fifesoft.com>
Date: Tue May 18 12:50:08 2010 +0000
Can now pass a different classloader for CompletionXMLParser to use for custom FunctionCompletions, etc., if necessary.
Fixed Java completion bug - fields & methods sometimes didn't return correct containing type.
Perl completion now only uses system perldoc if Perl home is set AND "use perldoc" option is also set.
---
.../fife/ui/autocomplete/CompletionXMLParser.java | 67 ++++++++++++++++++--
.../ui/autocomplete/DefaultCompletionProvider.java | 18 +++++-
2 files changed, 80 insertions(+), 5 deletions(-)
diff --git a/src/org/fife/ui/autocomplete/CompletionXMLParser.java b/src/org/fife/ui/autocomplete/CompletionXMLParser.java
index 3451c1d..c7b5c09 100644
--- a/src/org/fife/ui/autocomplete/CompletionXMLParser.java
+++ b/src/org/fife/ui/autocomplete/CompletionXMLParser.java
@@ -51,6 +51,13 @@ public class CompletionXMLParser extends DefaultHandler {
*/
private CompletionProvider provider;
+ /**
+ * The completion provider to use when loading classes, such as custom
+ * {@link FunctionCompletion}s.
+ */
+ private ClassLoader completionCL;
+
+
private String name;
private String type;
private String returnType;
@@ -80,6 +87,14 @@ public class CompletionXMLParser extends DefaultHandler {
*/
private String funcCompletionType;
+ /**
+ * The class loader to use to load custom completion classes, such as
+ * the one defined by {@link #funcCompletionType}. If this is
+ * <code>null</code>, then a default class loader is used. This field
+ * will usually be <code>null</code>.
+ */
+ private static ClassLoader DEFAULT_COMPLETION_CLASS_LOADER;
+
/**
* Constructor.
@@ -88,7 +103,27 @@ public class CompletionXMLParser extends DefaultHandler {
* @see #reset(CompletionProvider)
*/
public CompletionXMLParser(CompletionProvider provider) {
+ this(provider, null);
+ }
+
+
+ /**
+ * Constructor.
+ *
+ * @param provider The provider to get completions for.
+ * @param cl The class loader to use, if necessary, when loading classes
+ * from the XML (custom {@link FunctionCompletion}s, for example).
+ * This may be <code>null</code> if the default is to be used, or
+ * if the XML does not define specific classes for completion types.
+ * @see #reset(CompletionProvider)
+ */
+ public CompletionXMLParser(CompletionProvider provider, ClassLoader cl) {
this.provider = provider;
+ this.completionCL = cl;
+ if (completionCL==null) {
+ // May also be null, but that's okay.
+ completionCL = DEFAULT_COMPLETION_CLASS_LOADER;
+ }
completions = new ArrayList();
params = new ArrayList(1);
desc = new StringBuffer();
@@ -120,7 +155,14 @@ public class CompletionXMLParser extends DefaultHandler {
FunctionCompletion fc = null;
if (funcCompletionType!=null) {
try {
- Class clazz = Class.forName(funcCompletionType);
+ Class clazz = null;
+ if (completionCL!=null) {
+ clazz = Class.forName(funcCompletionType, true,
+ completionCL);
+ }
+ else {
+ clazz = Class.forName(funcCompletionType);
+ }
Class[] paramTypes = { CompletionProvider.class,
String.class, String.class };
Constructor c = clazz.getDeclaredConstructor(paramTypes);
@@ -129,11 +171,11 @@ public class CompletionXMLParser extends DefaultHandler {
} catch (RuntimeException re) { // FindBugs
throw re;
} catch (Exception e) {
- throw new RuntimeException(
- "Problem with custom FunctionCompletion: " + e.toString());
+ e.printStackTrace();
}
}
- else {
+
+ if (fc==null) { // Fallback if completion failed for some reason
fc = new FunctionCompletion(provider, name, returnType);
}
@@ -147,7 +189,9 @@ public class CompletionXMLParser extends DefaultHandler {
fc.setReturnValueDescription(returnValDesc.toString());
returnValDesc.setLength(0);
}
+
return fc;
+
}
@@ -319,6 +363,21 @@ public class CompletionXMLParser extends DefaultHandler {
/**
+ * Sets the class loader to use when loading custom classes to use for
+ * various {@link Completion} types, such as {@link FunctionCompletion}s,
+ * from XML.<p>
+ *
+ * Users should very rarely have a need to use this method.
+ *
+ * @param cl The class loader to use. If this is <code>null</code>, then
+ * a default is used.
+ */
+ public static void setDefaultCompletionClassLoader(ClassLoader cl) {
+ DEFAULT_COMPLETION_CLASS_LOADER = cl;
+ }
+
+
+ /**
* Called when an element starts.
*/
public void startElement(String uri, String localName, String qName,
diff --git a/src/org/fife/ui/autocomplete/DefaultCompletionProvider.java b/src/org/fife/ui/autocomplete/DefaultCompletionProvider.java
index eaf6891..c0324be 100644
--- a/src/org/fife/ui/autocomplete/DefaultCompletionProvider.java
+++ b/src/org/fife/ui/autocomplete/DefaultCompletionProvider.java
@@ -307,11 +307,27 @@ public class DefaultCompletionProvider extends AbstractCompletionProvider {
* @throws IOException If an IO error occurs.
*/
public void loadFromXML(InputStream in) throws IOException {
+ loadFromXML(in, null);
+ }
+
+
+ /**
+ * Loads completions from an XML input stream. The XML should validate
+ * against the completion XML schema.
+ *
+ * @param in The input stream to read from.
+ * @param cl The class loader to use when loading any extra classes defined
+ * in the XML, such as custom {@link FunctionCompletion}s. This
+ * may be <code>null</code> if the default is to be used, or if no
+ * custom completions are defined in the XML.
+ * @throws IOException If an IO error occurs.
+ */
+ public void loadFromXML(InputStream in, ClassLoader cl) throws IOException {
//long start = System.currentTimeMillis();
SAXParserFactory factory = SAXParserFactory.newInstance();
- CompletionXMLParser handler = new CompletionXMLParser(this);
+ CompletionXMLParser handler = new CompletionXMLParser(this, cl);
BufferedInputStream bin = new BufferedInputStream(in);
try {
SAXParser saxParser = factory.newSAXParser();
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/autocomplete.git
More information about the pkg-java-commits
mailing list