LanguageSupport.
*/
public void addLanguageSupport(String style, String lsClassName) {
@@ -104,8 +104,8 @@ private void createSupportMap() {
prefix + "perl.PerlLanguageSupport");
addLanguageSupport(SyntaxConstants.SYNTAX_STYLE_PHP,
prefix + "php.PhpLanguageSupport");
- addLanguageSupport(SyntaxConstants.SYNTAX_STYLE_TYPESCRIPT,
- prefix + "ts.TypeScriptLanguageSupport");
+// addLanguageSupport(SyntaxConstants.SYNTAX_STYLE_TYPESCRIPT,
+// prefix + "ts.TypeScriptLanguageSupport");
addLanguageSupport(SyntaxConstants.SYNTAX_STYLE_UNIX_SHELL,
prefix + "sh.ShellLanguageSupport");
addLanguageSupport(SyntaxConstants.SYNTAX_STYLE_XML,
diff --git a/src/main/java/org/fife/rsta/ac/demo/AboutDialog.java b/src/main/java/org/fife/rsta/ac/demo/AboutDialog.java
index ecec2ee6..9faee6d0 100644
--- a/src/main/java/org/fife/rsta/ac/demo/AboutDialog.java
+++ b/src/main/java/org/fife/rsta/ac/demo/AboutDialog.java
@@ -21,6 +21,7 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
+
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
@@ -38,12 +39,10 @@
import org.fife.rsta.ac.java.buildpath.JarLibraryInfo;
import org.fife.rsta.ac.java.buildpath.LibraryInfo;
-import org.fife.rsta.ac.perl.PerlLanguageSupport;
-
/**
* The "About" dialog for the demo application.
- *
+ *
* @author Robert Futrell
* @version 1.0
*/
@@ -51,13 +50,12 @@ public class AboutDialog extends JDialog {
private final Border empty5Border = BorderFactory.createEmptyBorder(5, 5, 5, 5);
-
public AboutDialog(DemoApp parent) {
super(parent);
JPanel cp = new JPanel(new BorderLayout());
-// cp.setBorder(empty5Border);
+ // cp.setBorder(empty5Border);
Box box = Box.createVerticalBox();
@@ -80,12 +78,10 @@ public AboutDialog(DemoApp parent) {
JTextArea textArea = new JTextArea(6, 60);
// Windows LAF picks a bad font for text areas, for some reason.
textArea.setFont(labelFont);
- textArea.setText("Version 0.2\n\n" +
- "Demonstrates basic features of the RSTALanguageSupport library.\n" +
- "Note that some features for some languages may not work unless your system " +
- "is set up properly.\nFor example, Java code completion requries a JRE on " +
- "your PATH, and Perl completion requires the Perl executable to be on your " +
- "PATH.");
+ textArea.setText("Version 0.2\n\n" + "Demonstrates basic features of the RSTALanguageSupport library.\n"
+ + "Note that some features for some languages may not work unless your system "
+ + "is set up properly.\nFor example, Java code completion requries a JRE on "
+ + "your PATH, and Perl completion requires the Perl executable to be on your " + "PATH.");
textArea.setEditable(false);
textArea.setBackground(Color.white);
textArea.setLineWrap(true);
@@ -99,27 +95,30 @@ public AboutDialog(DemoApp parent) {
SpringLayout sl = new SpringLayout();
JPanel temp = new JPanel(sl);
JLabel perlLabel = new JLabel("Perl install location:");
- File loc = PerlLanguageSupport.getDefaultPerlInstallLocation();
- String text = loc==null ? null : loc.getAbsolutePath();
+ // File loc = PerlLanguageSupport.getDefaultPerlInstallLocation();
+ String text = null;
JTextField perlField = createTextField(text);
JLabel javaLabel = new JLabel("Java home:");
String jre = null;
LibraryInfo info = LibraryInfo.getMainJreJarInfo();
- if (info!=null) { // Should always be true
- File jarFile = ((JarLibraryInfo)info).getJarFile();
+ if (info != null) { // Should always be true
+ File jarFile = ((JarLibraryInfo) info).getJarFile();
jre = jarFile.getParentFile().getParentFile().getAbsolutePath();
}
JTextField javaField = createTextField(jre);
if (getComponentOrientation().isLeftToRight()) {
- temp.add(perlLabel); temp.add(perlField);
- temp.add(javaLabel); temp.add(javaField);
- }
- else {
- temp.add(perlField); temp.add(perlLabel);
- temp.add(javaField); temp.add(javaLabel);
+ temp.add(perlLabel);
+ temp.add(perlField);
+ temp.add(javaLabel);
+ temp.add(javaField);
+ } else {
+ temp.add(perlField);
+ temp.add(perlLabel);
+ temp.add(javaField);
+ temp.add(javaLabel);
}
- makeSpringCompactGrid(temp, 2, 2, 5,5, 15,5);
+ makeSpringCompactGrid(temp, 2, 2, 5, 5, 15, 5);
box.add(temp);
box.add(Box.createVerticalGlue());
@@ -146,7 +145,6 @@ public void actionPerformed(ActionEvent e) {
}
-
private JPanel addLeftAligned(Component toAdd, Container addTo) {
JPanel temp = new JPanel(new BorderLayout());
temp.setOpaque(false); // For ones on white background.
@@ -155,7 +153,6 @@ private JPanel addLeftAligned(Component toAdd, Container addTo) {
return temp;
}
-
private JTextField createTextField(String text) {
JTextField field = new JTextField(text);
field.setEditable(false);
@@ -164,107 +161,102 @@ private JTextField createTextField(String text) {
return field;
}
-
/**
- * Used by makeSpringCompactGrid. This is ripped off directly from
+ * Used by makeSpringCompactGrid. This is ripped off directly from
* SpringUtilities.java in the Sun Java Tutorial.
*
- * @param parent The container whose layout must be an instance of
- * SpringLayout.
- * @return The spring constraints for the specified component contained
- * in parent.
+ * @param parent
+ * The container whose layout must be an instance of
+ * SpringLayout.
+ * @return The spring constraints for the specified component contained in
+ * parent.
*/
- private static final SpringLayout.Constraints getConstraintsForCell(
- int row, int col,
- Container parent, int cols) {
+ private static final SpringLayout.Constraints getConstraintsForCell(int row, int col, Container parent, int cols) {
SpringLayout layout = (SpringLayout) parent.getLayout();
Component c = parent.getComponent(row * cols + col);
return layout.getConstraints(c);
}
-
/**
- * This method is ripped off from SpringUtilities.java found
- * on Sun's Java Tutorial pages. It takes a component whose layout is
- * SpringLayout and organizes the components it contains into
- * a nice grid.
- * Aligns the first rows * cols components of
- * parent in a grid. Each component in a column is as wide as
- * the maximum preferred width of the components in that column; height is
- * similarly determined for each row. The parent is made just big enough
- * to fit them all.
+ * This method is ripped off from SpringUtilities.java found on
+ * Sun's Java Tutorial pages. It takes a component whose layout is
+ * SpringLayout and organizes the components it contains into a
+ * nice grid. Aligns the first rows * cols
+ * components of parent in a grid. Each component in a column
+ * is as wide as the maximum preferred width of the components in that
+ * column; height is similarly determined for each row. The parent is made
+ * just big enough to fit them all.
*
- * @param parent The container whose layout is SpringLayout.
- * @param rows The number of rows of components to make in the container.
- * @param cols The umber of columns of components to make.
- * @param initialX The x-location to start the grid at.
- * @param initialY The y-location to start the grid at.
- * @param xPad The x-padding between cells.
- * @param yPad The y-padding between cells.
+ * @param parent
+ * The container whose layout is SpringLayout.
+ * @param rows
+ * The number of rows of components to make in the container.
+ * @param cols
+ * The umber of columns of components to make.
+ * @param initialX
+ * The x-location to start the grid at.
+ * @param initialY
+ * The y-location to start the grid at.
+ * @param xPad
+ * The x-padding between cells.
+ * @param yPad
+ * The y-padding between cells.
*/
- public static final void makeSpringCompactGrid(Container parent, int rows,
- int cols, int initialX, int initialY,
- int xPad, int yPad) {
+ public static final void makeSpringCompactGrid(Container parent, int rows, int cols, int initialX, int initialY,
+ int xPad, int yPad) {
SpringLayout layout;
try {
- layout = (SpringLayout)parent.getLayout();
+ layout = (SpringLayout) parent.getLayout();
} catch (ClassCastException cce) {
- System.err.println("The first argument to makeCompactGrid " +
- "must use SpringLayout.");
+ System.err.println("The first argument to makeCompactGrid " + "must use SpringLayout.");
return;
}
- //Align all cells in each column and make them the same width.
+ // Align all cells in each column and make them the same width.
Spring x = Spring.constant(initialX);
for (int c = 0; c < cols; c++) {
Spring width = Spring.constant(0);
for (int r = 0; r < rows; r++) {
- width = Spring.max(width,
- getConstraintsForCell(
- r, c, parent, cols).getWidth());
+ width = Spring.max(width, getConstraintsForCell(r, c, parent, cols).getWidth());
}
for (int r = 0; r < rows; r++) {
- SpringLayout.Constraints constraints =
- getConstraintsForCell(r, c, parent, cols);
+ SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
constraints.setX(x);
constraints.setWidth(width);
}
x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad)));
}
- //Align all cells in each row and make them the same height.
+ // Align all cells in each row and make them the same height.
Spring y = Spring.constant(initialY);
for (int r = 0; r < rows; r++) {
Spring height = Spring.constant(0);
for (int c = 0; c < cols; c++) {
- height = Spring.max(height,
- getConstraintsForCell(r, c, parent, cols).getHeight());
+ height = Spring.max(height, getConstraintsForCell(r, c, parent, cols).getHeight());
}
for (int c = 0; c < cols; c++) {
- SpringLayout.Constraints constraints =
- getConstraintsForCell(r, c, parent, cols);
+ SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
constraints.setY(y);
constraints.setHeight(height);
}
y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad)));
}
- //Set the parent's size.
+ // Set the parent's size.
SpringLayout.Constraints pCons = layout.getConstraints(parent);
pCons.setConstraint(SpringLayout.SOUTH, y);
pCons.setConstraint(SpringLayout.EAST, x);
}
-
/**
* The border of the "top section" of the About dialog.
*/
private static class TopBorder extends AbstractBorder {
@Override
- public Insets getBorderInsets(Component c) {
+ public Insets getBorderInsets(Component c) {
return getBorderInsets(c, new Insets(0, 0, 0, 0));
}
@@ -276,17 +268,15 @@ public Insets getBorderInsets(Component c, Insets insets) {
}
@Override
- public void paintBorder(Component c, Graphics g, int x, int y,
- int width, int height) {
+ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
Color color = UIManager.getColor("controlShadow");
- if (color==null) {
+ if (color == null) {
color = SystemColor.controlShadow;
}
g.setColor(color);
- g.drawLine(x,y+height-1, x+width,y+height-1);
+ g.drawLine(x, y + height - 1, x + width, y + height - 1);
}
}
-
}
\ No newline at end of file
diff --git a/src/main/java/org/fife/rsta/ac/demo/DemoRootPane.java b/src/main/java/org/fife/rsta/ac/demo/DemoRootPane.java
index ecf75cfc..f9f2a004 100644
--- a/src/main/java/org/fife/rsta/ac/demo/DemoRootPane.java
+++ b/src/main/java/org/fife/rsta/ac/demo/DemoRootPane.java
@@ -18,9 +18,25 @@
import java.io.InputStreamReader;
import java.net.URL;
-import javax.swing.*;
+import javax.swing.Action;
+import javax.swing.ButtonGroup;
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JRadioButtonMenuItem;
+import javax.swing.JRootPane;
+import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
+import javax.swing.JTree;
+import javax.swing.SwingUtilities;
+import javax.swing.ToolTipManager;
+import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
-import javax.swing.event.*;
+import javax.swing.event.HyperlinkEvent;
+import javax.swing.event.HyperlinkListener;
import javax.swing.tree.TreeNode;
import org.fife.rsta.ac.AbstractSourceTree;
@@ -28,17 +44,15 @@
import org.fife.rsta.ac.LanguageSupportFactory;
import org.fife.rsta.ac.java.JavaLanguageSupport;
import org.fife.rsta.ac.java.tree.JavaOutlineTree;
-import org.fife.rsta.ac.js.tree.JavaScriptOutlineTree;
-import org.fife.rsta.ac.xml.tree.XmlOutlineTree;
import org.fife.ui.rsyntaxtextarea.ErrorStrip;
-import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
+import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rtextarea.RTextScrollPane;
/**
* The root pane used by the demos. This allows both the applet and the
- * stand-alone application to share the same UI.
+ * stand-alone application to share the same UI.
*
* @author Robert Futrell
* @version 1.0
@@ -65,13 +79,13 @@ public DemoRootPane() {
} catch (IOException ioe) {
ioe.printStackTrace();
}
-
+
// Dummy tree keeps JViewport's "background" looking right initially
JTree dummy = new JTree((TreeNode)null);
treeSP = new JScrollPane(dummy);
textArea = createTextArea();
- setText("CExample.txt", SYNTAX_STYLE_C);
+ setText("JavaExample.txt", SYNTAX_STYLE_JAVA);
scrollPane = new RTextScrollPane(textArea, true);
scrollPane.setIconRowHeaderEnabled(true);
scrollPane.getGutter().setBookmarkingEnabled(true);
@@ -127,7 +141,7 @@ private JMenuBar createMenuBar() {
addItem(new StyleAction(this, "HTML", "HtmlExample.txt", SYNTAX_STYLE_HTML), bg, menu);
addItem(new StyleAction(this, "PHP", "PhpExample.txt", SYNTAX_STYLE_PHP), bg, menu);
addItem(new StyleAction(this, "sh", "ShellExample.txt", SYNTAX_STYLE_UNIX_SHELL), bg, menu);
- addItem(new StyleAction(this, "TypeScript", "TypeScriptExample.txt", SYNTAX_STYLE_TYPESCRIPT), bg, menu);
+// addItem(new StyleAction(this, "TypeScript", "TypeScriptExample.txt", SYNTAX_STYLE_TYPESCRIPT), bg, menu);
addItem(new StyleAction(this, "XML", "XMLExample.txt", SYNTAX_STYLE_XML), bg, menu);
menu.getItem(0).setSelected(true);
mb.add(menu);
@@ -143,7 +157,7 @@ private JMenuBar createMenuBar() {
menu = new JMenu("View");
menu.add(new JCheckBoxMenuItem(new ToggleLayeredHighlightsAction(this)));
mb.add(menu);
-
+
menu = new JMenu("Help");
menu.add(new JMenuItem(new AboutAction(this)));
mb.add(menu);
@@ -242,12 +256,12 @@ private void refreshSourceTree() {
if (SyntaxConstants.SYNTAX_STYLE_JAVA.equals(language)) {
tree = new JavaOutlineTree();
}
- else if (SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT.equals(language)) {
- tree = new JavaScriptOutlineTree();
- }
- else if (SyntaxConstants.SYNTAX_STYLE_XML.equals(language)) {
- tree = new XmlOutlineTree();
- }
+// else if (SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT.equals(language)) {
+// tree = new JavaScriptOutlineTree();
+// }
+// else if (SyntaxConstants.SYNTAX_STYLE_XML.equals(language)) {
+// tree = new XmlOutlineTree();
+// }
else {
tree = null;
}
diff --git a/src/main/java/org/fife/rsta/ac/java/JavaLanguageSupport.java b/src/main/java/org/fife/rsta/ac/java/JavaLanguageSupport.java
index 79cbd144..dc822291 100644
--- a/src/main/java/org/fife/rsta/ac/java/JavaLanguageSupport.java
+++ b/src/main/java/org/fife/rsta/ac/java/JavaLanguageSupport.java
@@ -1,618 +1,669 @@
-/*
- * 03/21/2010
- *
- * Copyright (C) 2010 Robert Futrell
- * robert_futrell at users.sourceforge.net
- * http://fifesoft.com/rsyntaxtextarea
- *
- * This library is distributed under a modified BSD license. See the included
- * RSTALanguageSupport.License.txt file for details.
- */
-package org.fife.rsta.ac.java;
-
-import java.awt.Point;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.InputEvent;
-import java.awt.event.KeyEvent;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import javax.swing.ActionMap;
-import javax.swing.InputMap;
-import javax.swing.KeyStroke;
-import javax.swing.Timer;
-import javax.swing.event.CaretEvent;
-import javax.swing.event.CaretListener;
-import javax.swing.text.BadLocationException;
-import javax.swing.text.Document;
-import javax.swing.text.Element;
-
-import org.fife.rsta.ac.AbstractLanguageSupport;
-import org.fife.rsta.ac.GoToMemberAction;
-import org.fife.rsta.ac.java.rjc.ast.CompilationUnit;
-import org.fife.rsta.ac.java.rjc.ast.ImportDeclaration;
-import org.fife.rsta.ac.java.rjc.ast.Package;
-import org.fife.rsta.ac.java.tree.JavaOutlineTree;
-import org.fife.ui.autocomplete.AutoCompletion;
-import org.fife.ui.autocomplete.Completion;
-import org.fife.ui.rsyntaxtextarea.RSyntaxDocument;
-import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
-
-
-/**
- * Language support for Java.
- *
- * @author Robert Futrell
- * @version 1.0
- * @see JavaOutlineTree
- */
-public class JavaLanguageSupport extends AbstractLanguageSupport {
-
- /**
- * Maps JavaParsers to Info instances about them.
- */
- private Mapnull if each one should have a unique jar manager.
- */
- private JarManager jarManager;
-
- /**
- * Client property installed on text areas that points to a listener.
- */
- private static final String PROPERTY_LISTENER =
- "org.fife.rsta.ac.java.JavaLanguageSupport.Listener";
-
-
- /**
- * Constructor.
- */
- public JavaLanguageSupport() {
- parserToInfoMap = new HashMapnull if
- * the text area does not have this JavaLanguageSupport
- * installed.
- */
- public JavaCompletionProvider getCompletionProvider(
- RSyntaxTextArea textArea) {
- AutoCompletion ac = getAutoCompletionFor(textArea);
- return (JavaCompletionProvider)ac.getCompletionProvider();
- }
-
-
- /**
- * Returns the shared jar manager instance.
- * NOTE: This method will be removed over time, as the Java support becomes
- * more robust!
- *
- * @return The shared jar manager.
- */
- public JarManager getJarManager() {
- return jarManager;
- }
-
-
- /**
- * Returns the Java parser running on a text area with this Java language
- * support installed.
- *
- * @param textArea The text area.
- * @return The Java parser. This will be null if the text
- * area does not have this JavaLanguageSupport installed.
- */
- public JavaParser getParser(RSyntaxTextArea textArea) {
- // Could be a parser for another language.
- Object parser = textArea.getClientProperty(PROPERTY_LANGUAGE_PARSER);
- if (parser instanceof JavaParser) {
- return (JavaParser)parser;
- }
- return null;
- }
-
-
- /**
- * {@inheritDoc}
- */
- public void install(RSyntaxTextArea textArea) {
-
- JavaCompletionProvider p = new JavaCompletionProvider(jarManager);
- // Can't use createAutoCompletion(), as Java's is "special."
- AutoCompletion ac = new JavaAutoCompletion(p, textArea);
- ac.setListCellRenderer(new JavaCellRenderer());
- ac.setAutoCompleteEnabled(isAutoCompleteEnabled());
- ac.setAutoActivationEnabled(isAutoActivationEnabled());
- ac.setAutoActivationDelay(getAutoActivationDelay());
- ac.setExternalURLHandler(new JavadocUrlHandler());
- ac.setParameterAssistanceEnabled(isParameterAssistanceEnabled());
- ac.setParamChoicesRenderer(new JavaParamListCellRenderer());
- ac.setShowDescWindow(getShowDescWindow());
- ac.install(textArea);
- installImpl(textArea, ac);
-
- textArea.setToolTipSupplier(p);
-
- Listener listener = new Listener(textArea);
- textArea.putClientProperty(PROPERTY_LISTENER, listener);
-
- JavaParser parser = new JavaParser(textArea);
- textArea.putClientProperty(PROPERTY_LANGUAGE_PARSER, parser);
- textArea.addParser(parser);
- textArea.setToolTipSupplier(p);
-
- Info info = new Info(textArea, p, parser);
- parserToInfoMap.put(parser, info);
-
- installKeyboardShortcuts(textArea);
-
- textArea.setLinkGenerator(new JavaLinkGenerator(this));
-
- }
-
-
- /**
- * Installs extra keyboard shortcuts supported by this language support.
- *
- * @param textArea The text area to install the shortcuts into.
- */
- private void installKeyboardShortcuts(RSyntaxTextArea textArea) {
-
- InputMap im = textArea.getInputMap();
- ActionMap am = textArea.getActionMap();
- int c = textArea.getToolkit().getMenuShortcutKeyMask();
- int shift = InputEvent.SHIFT_MASK;
-
- im.put(KeyStroke.getKeyStroke(KeyEvent.VK_O, c|shift), "GoToType");
- am.put("GoToType", new GoToMemberAction(JavaOutlineTree.class));
-
- }
-
-
- /**
- * {@inheritDoc}
- */
- public void uninstall(RSyntaxTextArea textArea) {
-
- uninstallImpl(textArea);
-
- JavaParser parser = getParser(textArea);
- Info info = parserToInfoMap.remove(parser);
- if (info!=null) { // Should always be true
- parser.removePropertyChangeListener(
- JavaParser.PROPERTY_COMPILATION_UNIT, info);
- }
- textArea.removeParser(parser);
- textArea.putClientProperty(PROPERTY_LANGUAGE_PARSER, null);
- textArea.setToolTipSupplier(null);
-
- Object listener = textArea.getClientProperty(PROPERTY_LISTENER);
- if (listener instanceof Listener) { // Should always be true
- ((Listener)listener).uninstall();
- textArea.putClientProperty(PROPERTY_LISTENER, null);
- }
-
- uninstallKeyboardShortcuts(textArea);
- textArea.setLinkGenerator(null);
-
- }
-
-
- /**
- * Uninstalls any keyboard shortcuts specific to this language support.
- *
- * @param textArea The text area to uninstall the actions from.
- */
- private void uninstallKeyboardShortcuts(RSyntaxTextArea textArea) {
-
- InputMap im = textArea.getInputMap();
- ActionMap am = textArea.getActionMap();
- int c = textArea.getToolkit().getMenuShortcutKeyMask();
- int shift = InputEvent.SHIFT_MASK;
-
- im.remove(KeyStroke.getKeyStroke(KeyEvent.VK_O, c|shift));
- am.remove("GoToType");
-
- }
-
-
- /**
- * Information about an import statement to add and where it should be
- * added. This is used internally when a class completion is inserted,
- * and it needs an import statement added to the source.
- */
- private static class ImportToAddInfo {
-
- public int offs;
- public String text;
-
- public ImportToAddInfo(int offset, String text) {
- this.offs = offset;
- this.text = text;
- }
-
- }
-
-
- /**
- * Manages information about the parsing/auto-completion for a single text
- * area. Unlike many simpler language supports,
- * JavaLanguageSupport cannot share any information amongst
- * instances of RSyntaxTextArea.
- */
- private static class Info implements PropertyChangeListener {
-
- public JavaCompletionProvider provider;
- //public JavaParser parser;
-
- public Info(RSyntaxTextArea textArea, JavaCompletionProvider provider,
- JavaParser parser) {
- this.provider = provider;
- //this.parser = parser;
- parser.addPropertyChangeListener(
- JavaParser.PROPERTY_COMPILATION_UNIT, this);
- }
-
- /**
- * Called when a text area is re-parsed.
- *
- * @param e The event.
- */
- public void propertyChange(PropertyChangeEvent e) {
-
- String name = e.getPropertyName();
-
- if (JavaParser.PROPERTY_COMPILATION_UNIT.equals(name)) {
- CompilationUnit cu = (CompilationUnit)e.getNewValue();
-// structureTree.update(file, cu);
-// updateTable();
- provider.setCompilationUnit(cu);
- }
-
- }
-
- }
-
-
- /**
- * A hack of AutoCompletion that forces the JavaParser
- * to re-parse the document when the user presses ctrl+space.
- */
- private class JavaAutoCompletion extends AutoCompletion {
-
- private RSyntaxTextArea textArea;
- private String replacementTextPrefix;
-
- public JavaAutoCompletion(JavaCompletionProvider provider,
- RSyntaxTextArea textArea) {
- super(provider);
- this.textArea = textArea;
- }
-
- private String getCurrentLineText() {
-
- int caretPosition = textArea.getCaretPosition();
- Element root = textArea.getDocument().getDefaultRootElement();
- int line= root.getElementIndex(caretPosition);
- Element elem = root.getElement(line);
- int endOffset = elem.getEndOffset();
- int lineStart = elem.getStartOffset();
-
- String text = "";
- try {
- text = textArea.getText(lineStart, endOffset-lineStart).trim();
- } catch (BadLocationException e) {
- e.printStackTrace();
- }
-
- return text;
-
- }
-
- /**
- * Overridden to allow for prepending to the replacement text. This
- * allows us to insert fully qualified class names. instead of
- * unqualified ones, if necessary (i.e. if the user tries to
- * auto-complete javax.swing.text.Document, but they've
- * explicitly imported org.w3c.dom.Document - we need to
- * insert the fully qualified name in that case).
- */
- @Override
- protected String getReplacementText(Completion c, Document doc,
- int start, int len) {
- String text = super.getReplacementText(c, doc, start, len);
- if (replacementTextPrefix!=null) {
- text = replacementTextPrefix + text;
- replacementTextPrefix = null;
- }
- return text;
- }
-
- /**
- * Determines whether the class name being completed has been imported,
- * and if it hasn't, returns the import statement that should be added
- * for it. Alternatively, if the class hasn't been imported, but a
- * class with the same (unqualified) name HAS been imported, this
- * method sets things up so the fully-qualified version of this class's
- * name is inserted.
- *
- * Thanks to Guilherme Joao Frantz and Jonatas Schuler for helping
- * with the patch!
- *
- * @param c The completion being inserted.
- * @return Whether an import was added.
- */
- private ImportToAddInfo getShouldAddImport(ClassCompletion cc) {
-
- String text = getCurrentLineText();
-
- // Make sure we're not currently typing an import statement.
- if (!text.startsWith("import ")) {
-
- JavaCompletionProvider provider = (JavaCompletionProvider)
- getCompletionProvider();
- CompilationUnit cu = provider.getCompilationUnit();
- int offset = 0;
- boolean alreadyImported = false;
-
- // Try to bail early, if possible.
- if (cu==null) { // Can never happen, right?
- return null;
- }
- if ("java.lang".equals(cc.getPackageName())) {
- // Package java.lang is "imported" by default.
- return null;
- }
-
- String className = cc.getClassName(false);
- String fqClassName = cc.getClassName(true);
-
- // If the completion is in the same package as the source we're
- // editing (or both are in the default package), bail.
- int lastClassNameDot = fqClassName.lastIndexOf('.');
- boolean ccInPackage = lastClassNameDot>-1;
- Package pkg = cu.getPackage();
- if (ccInPackage && pkg!=null) {
- String ccPkg = fqClassName.substring(0, lastClassNameDot);
- String pkgName = pkg.getName();
- if (ccPkg.equals(pkgName)) {
- return null;
- }
- }
- else if (!ccInPackage && pkg==null) {
- return null;
- }
-
- // Loop through all import statements.
- Iterator
+ *
+ * Thanks to Guilherme Joao Frantz and Jonatas Schuler for helping
+ * with the patch!
+ *
+ * @param c The completion being inserted.
+ * @return Whether an import was added.
+ */
+ private ImportToAddInfo getShouldAddImport(ClassCompletion cc) {
+
+ String text = getCurrentLineText();
+
+ // Make sure we're not currently typing an import statement.
+ if (!text.startsWith("import ")) {
+
+ JavaCompletionProvider provider = (JavaCompletionProvider)
+ getCompletionProvider();
+ CompilationUnit cu = provider.getCompilationUnit();
+ int offset = 0;
+ boolean alreadyImported = false;
+
+ // Try to bail early, if possible.
+ if (cu==null) { // Can never happen, right?
+ return null;
+ }
+ if ("java.lang".equals(cc.getPackageName())) {
+ // Package java.lang is "imported" by default.
+ return null;
+ }
+
+ String className = cc.getClassName(false);
+ String fqClassName = cc.getClassName(true);
+
+ // If the completion is in the same package as the source we're
+ // editing (or both are in the default package), bail.
+ int lastClassNameDot = fqClassName.lastIndexOf('.');
+ boolean ccInPackage = lastClassNameDot>-1;
+ Package pkg = cu.getPackage();
+ if (ccInPackage && pkg!=null) {
+ String ccPkg = fqClassName.substring(0, lastClassNameDot);
+ String pkgName = pkg.getName();
+ if (ccPkg.equals(pkgName)) {
+ return null;
+ }
+ }
+ else if (!ccInPackage && pkg==null) {
+ return null;
+ }
+
+ // Loop through all import statements.
+ Iterator
@@ -45,12 +48,15 @@
* RSyntaxTextArea.
*
* Please keep in mind that this class is a work-in-progress!
- *
+ *
* @author Robert Futrell
* @version 0.5
*/
public class JavaParser extends AbstractParser {
+
+ private static final Logger log = Logger.getLogger(Reflection.getCallerClass(1));
+
/**
* The property change event that's fired when the document is re-parsed.
* Applications can listen for this property change and update themselves
@@ -117,6 +123,10 @@ public CompilationUnit getCompilationUnit() {
public int getOffset(RSyntaxDocument doc, ParserNotice notice) {
Element root = doc.getDefaultRootElement();
Element elem = root.getElement(notice.getLine());
+ if (elem == null) {
+ log.info("NPE " + notice.getLine() + " " + notice);
+ return -1;
+ }
int offs = elem.getStartOffset() + notice.getColumn();
return offs>=elem.getEndOffset() ? -1 : offs;
}
diff --git a/src/main/java/org/fife/rsta/ac/java/OpenMember.java b/src/main/java/org/fife/rsta/ac/java/OpenMember.java
new file mode 100644
index 00000000..7bc6ee13
--- /dev/null
+++ b/src/main/java/org/fife/rsta/ac/java/OpenMember.java
@@ -0,0 +1,30 @@
+package org.fife.rsta.ac.java;
+
+import org.apache.log4j.Logger;
+import org.fife.rsta.ac.java.classreader.ClassFile;
+import org.fife.rsta.ac.java.classreader.FieldInfo;
+import org.fife.rsta.ac.java.classreader.MethodInfo;
+
+import sun.reflect.Reflection;
+
+public class OpenMember {
+
+ private static final Logger log = Logger.getLogger(Reflection.getCallerClass(1));
+
+ public static OpenMember openMember =new OpenMember();
+
+
+ public void openClass(ClassFile classFile) {
+ log.info(classFile);
+ }
+
+ public void openMember(MethodInfo methodInfo) {
+ log.info(methodInfo);
+ }
+
+ public void openMember(FieldInfo fieldInfoByName) {
+ log.info(fieldInfoByName);
+ }
+
+
+}
diff --git a/src/main/java/org/fife/rsta/ac/java/SourceCompletionProvider.java b/src/main/java/org/fife/rsta/ac/java/SourceCompletionProvider.java
index b913f95b..89941e4f 100644
--- a/src/main/java/org/fife/rsta/ac/java/SourceCompletionProvider.java
+++ b/src/main/java/org/fife/rsta/ac/java/SourceCompletionProvider.java
@@ -1,1072 +1,1400 @@
-/*
- * 03/21/2010
- *
- * Copyright (C) 2010 Robert Futrell
- * robert_futrell at users.sourceforge.net
- * http://fifesoft.com/rsyntaxtextarea
- *
- * This library is distributed under a modified BSD license. See the included
- * RSTALanguageSupport.License.txt file for details.
- */
-package org.fife.rsta.ac.java;
-
-import java.awt.Cursor;
-import java.awt.Point;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-import javax.swing.text.BadLocationException;
-import javax.swing.text.JTextComponent;
-
-import org.fife.rsta.ac.ShorthandCompletionCache;
-import org.fife.rsta.ac.java.buildpath.LibraryInfo;
-import org.fife.rsta.ac.java.buildpath.SourceLocation;
-import org.fife.rsta.ac.java.classreader.ClassFile;
-import org.fife.rsta.ac.java.classreader.FieldInfo;
-import org.fife.rsta.ac.java.classreader.MemberInfo;
-import org.fife.rsta.ac.java.classreader.MethodInfo;
-import org.fife.rsta.ac.java.rjc.ast.CodeBlock;
-import org.fife.rsta.ac.java.rjc.ast.CompilationUnit;
-import org.fife.rsta.ac.java.rjc.ast.Field;
-import org.fife.rsta.ac.java.rjc.ast.FormalParameter;
-import org.fife.rsta.ac.java.rjc.ast.ImportDeclaration;
-import org.fife.rsta.ac.java.rjc.ast.LocalVariable;
-import org.fife.rsta.ac.java.rjc.ast.Member;
-import org.fife.rsta.ac.java.rjc.ast.Method;
-import org.fife.rsta.ac.java.rjc.ast.NormalClassDeclaration;
-import org.fife.rsta.ac.java.rjc.ast.TypeDeclaration;
-import org.fife.rsta.ac.java.rjc.lang.Type;
-import org.fife.rsta.ac.java.rjc.lang.TypeArgument;
-import org.fife.rsta.ac.java.rjc.lang.TypeParameter;
-import org.fife.ui.autocomplete.Completion;
-import org.fife.ui.autocomplete.DefaultCompletionProvider;
-import org.fife.ui.rsyntaxtextarea.RSyntaxDocument;
-import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
-import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities;
-import org.fife.ui.rsyntaxtextarea.Token;
-
-
-/**
- * Parses a Java AST for code completions. It currently scans the following:
- *
- *
- *
+ *
* Note that if this method does not have parameterized arguments or
* return type, calling this method won't affect its behavior.
*/
@@ -448,11 +449,20 @@ public String getReturnTypeString(boolean fullyQualified) {
if(!fullyQualified)
{
if(returnType != null && returnType.indexOf(".") > -1) {
- return returnType.substring(returnType.lastIndexOf(".") +1, returnType.length());
+ return returnType.substring(returnType.lastIndexOf(".") +1, returnType.length());
}
}
return returnType;
}
+ public String getReturnTypeFull() {
+ if (returnTypeQualified==null) {
+ returnTypeQualified = getReturnTypeStringFromTypeSignature(true);
+ if (returnTypeQualified==null) {
+ returnTypeQualified = getReturnTypeStringFromDescriptor(true);
+ }
+ }
+ return returnTypeQualified;
+ }
/**
diff --git a/src/main/java/org/fife/rsta/ac/java/classreader/constantpool/ConstantUtf8Info.java b/src/main/java/org/fife/rsta/ac/java/classreader/constantpool/ConstantUtf8Info.java
index 6c319ef0..2799b84e 100644
--- a/src/main/java/org/fife/rsta/ac/java/classreader/constantpool/ConstantUtf8Info.java
+++ b/src/main/java/org/fife/rsta/ac/java/classreader/constantpool/ConstantUtf8Info.java
@@ -97,7 +97,8 @@ else if (15==(b>>4)) {
representedString = new String(bytes, "UTF-8");
} catch (UnsupportedEncodingException uee) { // Never happens.
uee.printStackTrace();
- System.exit(0);
+ // System.exit(0);
+ throw new Error(uee);
}
return representedString;
diff --git a/src/main/resources/examples/JavaExample.txt b/src/main/resources/examples/JavaExample.txt
index 57adb381..b45d1f36 100644
--- a/src/main/resources/examples/JavaExample.txt
+++ b/src/main/resources/examples/JavaExample.txt
@@ -1,12 +1,22 @@
+import javax.swing.JComponent;
+import java.util.Arrays;
+
public class ExampleCode {
private String strField;
protected int aaa;
protected int abb;
public float foo;
+ java.util.ArrayList al;
+ JComponent jc;
public ExampleCode(int value) {
this.value = value;
+ Object aaa = jc.actionMap;
+ jc.getColorModel();
+
+ Object yy = Arrays.clone();
+ yy.
}
public String getX() {
@@ -27,31 +37,31 @@ public class ExampleCode {
/** Ctrl+click my stuff! */
private class Inner1 {
-
+
private int aaa;
private double d;
private String strField;
-
+
public void doSomething(double newVal) {
d = newVal;
aaa = abb = clickable;
strField = getX(); // getX() clickable
}
-
+
}
-
+
/** Ctrl+click my stuff also! */
private static class Inner2 {
-
+
private double d;
private String strField;
-
+
public void doSomething(double newVal) {
d = newVal;
aaa = abb = notClickable;
strField = getX(); // getX() not clickable
}
-
+
}
-
-}
\ No newline at end of file
+
+}
\ No newline at end of file
null if each one should have a unique jar manager.
+ */
+ private JarManager jarManager;
+
+ /**
+ * Client property installed on text areas that points to a listener.
+ */
+ private static final String PROPERTY_LISTENER =
+ "org.fife.rsta.ac.java.JavaLanguageSupport.Listener";
+
+
+ /**
+ * Constructor.
+ */
+ public JavaLanguageSupport() {
+ parserToInfoMap = new HashMapnull if
+ * the text area does not have this JavaLanguageSupport
+ * installed.
+ */
+ public JavaCompletionProvider getCompletionProvider(
+ RSyntaxTextArea textArea) {
+ AutoCompletion ac = getAutoCompletionFor(textArea);
+ return (JavaCompletionProvider)ac.getCompletionProvider();
+ }
+
+
+ /**
+ * Returns the shared jar manager instance.
+ * NOTE: This method will be removed over time, as the Java support becomes
+ * more robust!
+ *
+ * @return The shared jar manager.
+ */
+ public JarManager getJarManager() {
+ return jarManager;
+ }
+
+
+ /**
+ * Returns the Java parser running on a text area with this Java language
+ * support installed.
+ *
+ * @param textArea The text area.
+ * @return The Java parser. This will be null if the text
+ * area does not have this JavaLanguageSupport installed.
+ */
+ public JavaParser getParser(RSyntaxTextArea textArea) {
+ // Could be a parser for another language.
+ Object parser = textArea.getClientProperty(PROPERTY_LANGUAGE_PARSER);
+ if (parser instanceof JavaParser) {
+ return (JavaParser)parser;
+ }
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void install(RSyntaxTextArea textArea) {
+
+ JavaCompletionProvider p = new JavaCompletionProvider(jarManager);
+ // Can't use createAutoCompletion(), as Java's is "special."
+ AutoCompletion ac = new JavaAutoCompletion(p, textArea);
+ ac.setListCellRenderer(new JavaCellRenderer());
+ ac.setAutoCompleteEnabled(isAutoCompleteEnabled());
+ ac.setAutoActivationEnabled(isAutoActivationEnabled());
+ ac.setAutoActivationDelay(getAutoActivationDelay());
+ ac.setExternalURLHandler(new JavadocUrlHandler());
+ ac.setParameterAssistanceEnabled(isParameterAssistanceEnabled());
+ ac.setParamChoicesRenderer(new JavaParamListCellRenderer());
+ ac.setShowDescWindow(getShowDescWindow());
+ ac.install(textArea);
+ installImpl(textArea, ac);
+
+ textArea.setToolTipSupplier(p);
+
+ Listener listener = new Listener(textArea);
+ textArea.putClientProperty(PROPERTY_LISTENER, listener);
+
+ JavaParser parser = new JavaParser(textArea);
+ textArea.putClientProperty(PROPERTY_LANGUAGE_PARSER, parser);
+ textArea.addParser(parser);
+ textArea.setToolTipSupplier(p);
+
+ Info info = new Info(textArea, p, parser);
+ parserToInfoMap.put(parser, info);
+
+ installKeyboardShortcuts(textArea);
+ log.info("lang support installed");
+ textArea.setLinkGenerator(new JavaLinkGenerator(this,p));
+
+ }
+
+ protected void installCreateLocalVarButton(RSyntaxTextArea textArea) {
+ // textArea.re
+ Action action = null;
+ KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0);
+ InputMap im = textArea.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
+ im.put(ks, ks);
+ action = new Action() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+
+ }
+
+ @Override
+ public void setEnabled(boolean b) {
+ }
+
+ @Override
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ }
+
+ @Override
+ public void putValue(String key, Object value) {
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return true;
+ }
+
+ @Override
+ public Object getValue(String key) {
+ return null;
+ }
+
+ @Override
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+
+ }
+ };
+ textArea.getActionMap().put(ks, action);
+ }
+
+ /**
+ * Installs extra keyboard shortcuts supported by this language support.
+ *
+ * @param textArea The text area to install the shortcuts into.
+ */
+ private void installKeyboardShortcuts(RSyntaxTextArea textArea) {
+
+ InputMap im = textArea.getInputMap();
+ ActionMap am = textArea.getActionMap();
+ int c = textArea.getToolkit().getMenuShortcutKeyMask();
+ int shift = InputEvent.SHIFT_MASK;
+
+ im.put(KeyStroke.getKeyStroke(KeyEvent.VK_O, c|shift), "GoToType");
+ am.put("GoToType", new GoToMemberAction(JavaOutlineTree.class));
+
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void uninstall(RSyntaxTextArea textArea) {
+
+ uninstallImpl(textArea);
+
+ JavaParser parser = getParser(textArea);
+ Info info = parserToInfoMap.remove(parser);
+ if (info!=null) { // Should always be true
+ parser.removePropertyChangeListener(
+ JavaParser.PROPERTY_COMPILATION_UNIT, info);
+ }
+ textArea.removeParser(parser);
+ textArea.putClientProperty(PROPERTY_LANGUAGE_PARSER, null);
+ textArea.setToolTipSupplier(null);
+
+ Object listener = textArea.getClientProperty(PROPERTY_LISTENER);
+ if (listener instanceof Listener) { // Should always be true
+ ((Listener)listener).uninstall();
+ textArea.putClientProperty(PROPERTY_LISTENER, null);
+ }
+
+ uninstallKeyboardShortcuts(textArea);
+ textArea.setLinkGenerator(null);
+
+ }
+
+
+ /**
+ * Uninstalls any keyboard shortcuts specific to this language support.
+ *
+ * @param textArea The text area to uninstall the actions from.
+ */
+ private void uninstallKeyboardShortcuts(RSyntaxTextArea textArea) {
+
+ InputMap im = textArea.getInputMap();
+ ActionMap am = textArea.getActionMap();
+ int c = textArea.getToolkit().getMenuShortcutKeyMask();
+ int shift = InputEvent.SHIFT_MASK;
+
+ im.remove(KeyStroke.getKeyStroke(KeyEvent.VK_O, c|shift));
+ am.remove("GoToType");
+
+ }
+
+
+ /**
+ * Information about an import statement to add and where it should be
+ * added. This is used internally when a class completion is inserted,
+ * and it needs an import statement added to the source.
+ */
+ private static class ImportToAddInfo {
+
+ public int offs;
+ public String text;
+
+ public ImportToAddInfo(int offset, String text) {
+ this.offs = offset;
+ this.text = text;
+ }
+
+ }
+
+
+ /**
+ * Manages information about the parsing/auto-completion for a single text
+ * area. Unlike many simpler language supports,
+ * JavaLanguageSupport cannot share any information amongst
+ * instances of RSyntaxTextArea.
+ */
+ private static class Info implements PropertyChangeListener {
+
+ public JavaCompletionProvider provider;
+ //public JavaParser parser;
+
+ public Info(RSyntaxTextArea textArea, JavaCompletionProvider provider,
+ JavaParser parser) {
+ this.provider = provider;
+ //this.parser = parser;
+ parser.addPropertyChangeListener(
+ JavaParser.PROPERTY_COMPILATION_UNIT, this);
+ }
+
+ /**
+ * Called when a text area is re-parsed.
+ *
+ * @param e The event.
+ */
+ public void propertyChange(PropertyChangeEvent e) {
+
+ String name = e.getPropertyName();
+
+ if (JavaParser.PROPERTY_COMPILATION_UNIT.equals(name)) {
+ CompilationUnit cu = (CompilationUnit)e.getNewValue();
+// structureTree.update(file, cu);
+// updateTable();
+ provider.setCompilationUnit(cu);
+ }
+
+ }
+
+ }
+
+
+ /**
+ * A hack of AutoCompletion that forces the JavaParser
+ * to re-parse the document when the user presses ctrl+space.
+ */
+ private class JavaAutoCompletion extends AutoCompletion {
+
+ private RSyntaxTextArea textArea;
+ private String replacementTextPrefix;
+
+ public JavaAutoCompletion(JavaCompletionProvider provider,
+ RSyntaxTextArea textArea) {
+ super(provider);
+ this.textArea = textArea;
+ }
+
+ private String getCurrentLineText() {
+
+ int caretPosition = textArea.getCaretPosition();
+ Element root = textArea.getDocument().getDefaultRootElement();
+ int line= root.getElementIndex(caretPosition);
+ Element elem = root.getElement(line);
+ int endOffset = elem.getEndOffset();
+ int lineStart = elem.getStartOffset();
+
+ String text = "";
+ try {
+ text = textArea.getText(lineStart, endOffset-lineStart).trim();
+ } catch (BadLocationException e) {
+ e.printStackTrace();
+ }
+
+ return text;
+
+ }
+
+ /**
+ * Overridden to allow for prepending to the replacement text. This
+ * allows us to insert fully qualified class names. instead of
+ * unqualified ones, if necessary (i.e. if the user tries to
+ * auto-complete javax.swing.text.Document, but they've
+ * explicitly imported org.w3c.dom.Document - we need to
+ * insert the fully qualified name in that case).
+ */
+ @Override
+ protected String getReplacementText(Completion c, Document doc,
+ int start, int len) {
+ String text = super.getReplacementText(c, doc, start, len);
+ if (replacementTextPrefix!=null) {
+ text = replacementTextPrefix + text;
+ replacementTextPrefix = null;
+ }
+ return text;
+ }
+
+ /**
+ * Determines whether the class name being completed has been imported,
+ * and if it hasn't, returns the import statement that should be added
+ * for it. Alternatively, if the class hasn't been imported, but a
+ * class with the same (unqualified) name HAS been imported, this
+ * method sets things up so the fully-qualified version of this class's
+ * name is inserted.
- *
- *
- * Also, if the caret is inside a method, local variables up to the caret
- * position are also returned.
- *
- * @author Robert Futrell
- * @version 1.0
- */
-class SourceCompletionProvider extends DefaultCompletionProvider {
-
- /**
- * The parent completion provider.
- */
- private JavaCompletionProvider javaProvider;
-
- /**
- * Used to get information about what classes match imports.
- */
- private JarManager jarManager;
-
- private static final String JAVA_LANG_PACKAGE = "java.lang.*";
- private static final String THIS = "this";
-
- //Shorthand completions (templates and comments)
- private ShorthandCompletionCache shorthandCache;
- /**
- * Constructor.
- */
- public SourceCompletionProvider() {
- this(null);
- }
-
-
- /**
- * Constructor.
- *
- * @param jarManager The jar manager for this provider.
- */
- public SourceCompletionProvider(JarManager jarManager) {
- if (jarManager==null) {
- jarManager = new JarManager();
- }
- this.jarManager = jarManager;
- setParameterizedCompletionParams('(', ", ", ')');
- setAutoActivationRules(false, "."); // Default - only activate after '.'
- setParameterChoicesProvider(new SourceParamChoicesProvider());
- }
-
-
- private void addCompletionsForStaticMembers(Setnull if
- * cf represents java.lang.Object (or
- * if the super class could not be determined).
- */
- private ClassFile getClassFileFor(CompilationUnit cu, String className) {
-
- //System.err.println(">>> Getting class file for: " + className);
- if (className==null) {
- return null;
- }
-
- ClassFile superClass = null;
-
- // Determine the fully qualified class to grab
- if (!Util.isFullyQualified(className)) {
-
- // Check in this source file's package first
- String pkg = cu.getPackageName();
- if (pkg!=null) {
- String temp = pkg + "." + className;
- superClass = jarManager.getClassEntry(temp);
- }
-
- // Next, go through the imports (order is important)
- if (superClass==null) {
- Iteratormethod.
- */
- private void addLocalVarCompletions(Setnull, then
- * the current JVM's main JRE jar (rt.jar, or classes.jar on OS X)
- * will be added. If this jar has already been added, adding it
- * again will do nothing (except possibly update its attached source
- * location).
- * @throws IOException If an IO error occurs.
- * @see #getJars()
- * @see #removeJar(File)
- */
- public void addJar(LibraryInfo info) throws IOException {
- jarManager.addClassFileSource(info);
- }
-
-
- /**
- * Checks whether the user is typing a completion for a String member after
- * a String literal.
- *
- * @param comp The text component.
- * @param alreadyEntered The text already entered.
- * @param cu The compilation unit being parsed.
- * @param set The set to add possible completions to.
- * @return Whether the user is indeed typing a completion for a String
- * literal member.
- */
- private boolean checkStringLiteralMember(JTextComponent comp,
- String alreadyEntered,
- CompilationUnit cu, SetClassFile representing the actual type of
- * the variable/field/etc. being code completed
- * @return A mapping of type parameter names to type arguments (both
- * Strings).
- */
- private MapLibraryInfo in this list will have no effect on
- * this completion provider; in order to do that, you must re-add
- * the jar via {@link #addJar(LibraryInfo)}. If there are
- * no jars on the "build path," this will be an empty list.
- * @see #addJar(LibraryInfo)
- */
- public List
- *
- *
- * @param cu
- * @param comp
- * @param alreadyEntered
- * @param retVal
- */
- private void loadCompletionsForCaretPosition(CompilationUnit cu,
- JTextComponent comp, String alreadyEntered, Setnull not equal to
- * "this".
- * @param offs The offset of the caret in the document.
- */
- private void loadCompletionsForCaretPositionQualified(CompilationUnit cu,
- String alreadyEntered, Setfalse
- * if the jar was not on the build path.
- * @see #addJar(LibraryInfo)
- * @see #getJars()
- * @see #clearJars()
- */
- public boolean removeJar(File jar) {
- boolean removed = jarManager.removeClassFileSource(jar);
- // The memory used by the completions can be quite large, so go ahead
- // and clear out the completions list so no-longer-needed ones are
- // eligible for GC.
- if (removed) {
- clear();
- }
- return removed;
- }
-
-
- /**
- * Sets the parent Java provider.
- *
- * @param javaProvider The parent completion provider.
- */
- void setJavaProvider(JavaCompletionProvider javaProvider) {
- this.javaProvider = javaProvider;
- }
-
-
+/*
+ * 03/21/2010
+ *
+ * Copyright (C) 2010 Robert Futrell
+ * robert_futrell at users.sourceforge.net
+ * http://fifesoft.com/rsyntaxtextarea
+ *
+ * This library is distributed under a modified BSD license. See the included
+ * RSTALanguageSupport.License.txt file for details.
+ */
+package org.fife.rsta.ac.java;
+
+import java.awt.Cursor;
+import java.awt.Point;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.swing.JComponent;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import javax.swing.text.Element;
+import javax.swing.text.JTextComponent;
+import javax.swing.text.Segment;
+
+import org.apache.log4j.Logger;
+import org.fife.rsta.ac.ShorthandCompletionCache;
+import org.fife.rsta.ac.java.buildpath.LibraryInfo;
+import org.fife.rsta.ac.java.buildpath.SourceLocation;
+import org.fife.rsta.ac.java.classreader.ClassFile;
+import org.fife.rsta.ac.java.classreader.FieldInfo;
+import org.fife.rsta.ac.java.classreader.MemberInfo;
+import org.fife.rsta.ac.java.classreader.MethodInfo;
+import org.fife.rsta.ac.java.rjc.ast.CodeBlock;
+import org.fife.rsta.ac.java.rjc.ast.CompilationUnit;
+import org.fife.rsta.ac.java.rjc.ast.Field;
+import org.fife.rsta.ac.java.rjc.ast.FormalParameter;
+import org.fife.rsta.ac.java.rjc.ast.ImportDeclaration;
+import org.fife.rsta.ac.java.rjc.ast.LocalVariable;
+import org.fife.rsta.ac.java.rjc.ast.Member;
+import org.fife.rsta.ac.java.rjc.ast.Method;
+import org.fife.rsta.ac.java.rjc.ast.NormalClassDeclaration;
+import org.fife.rsta.ac.java.rjc.ast.TypeDeclaration;
+import org.fife.rsta.ac.java.rjc.lang.Type;
+import org.fife.rsta.ac.java.rjc.lang.TypeArgument;
+import org.fife.rsta.ac.java.rjc.lang.TypeParameter;
+import org.fife.ui.autocomplete.Completion;
+import org.fife.ui.autocomplete.DefaultCompletionProvider;
+import org.fife.ui.rsyntaxtextarea.RSyntaxDocument;
+import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
+import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities;
+import org.fife.ui.rsyntaxtextarea.Token;
+
+import sun.reflect.Reflection;
+
+/**
+ * Parses a Java AST for code completions. It currently scans the following:
+ *
+ *
+ *
+ *
+ * Also, if the caret is inside a method, local variables up to the caret
+ * position are also returned.
+ *
+ * @author Robert Futrell
+ * @version 1.0
+ */
+public class SourceCompletionProvider extends DefaultCompletionProvider {
+
+ private static final Logger log = Logger.getLogger(Reflection.getCallerClass(1));
+
+ public static boolean loadPrivateMemberAlways = true;
+
+ /**
+ * The parent completion provider.
+ */
+ private JavaCompletionProvider javaProvider;
+
+ /**
+ * Used to get information about what classes match imports.
+ */
+ private JarManager jarManager;
+
+ private static final String JAVA_LANG_PACKAGE = "java.lang.*";
+ private static final String THIS = "this";
+
+ // Shorthand completions (templates and comments)
+ private ShorthandCompletionCache shorthandCache;
+
+ /**
+ * Constructor.
+ */
+ public SourceCompletionProvider() {
+ this(null);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param jarManager
+ * The jar manager for this provider.
+ */
+ public SourceCompletionProvider(JarManager jarManager) {
+ if (jarManager == null) {
+ jarManager = new JarManager();
+ }
+ this.jarManager = jarManager;
+ setParameterizedCompletionParams('(', ", ", ')');
+ setAutoActivationRules(false, "."); // Default - only activate after '.'
+ setParameterChoicesProvider(new SourceParamChoicesProvider());
+ }
+
+ private void addCompletionsForStaticMembers(Setnull if
+ * cf represents java.lang.Object (or if
+ * the super class could not be determined).
+ */
+ private ClassFile getClassFileFor(CompilationUnit cu, String className) {
+
+ // System.err.println(">>> Getting class file for: " + className);
+ if (className == null) {
+ return null;
+ }
+
+ ClassFile superClass = null;
+
+ // Determine the fully qualified class to grab
+ if (!Util.isFullyQualified(className)) {
+
+ // Check in this source file's package first
+ String pkg = cu.getPackageName();
+ if (pkg != null) {
+ String temp = pkg + "." + className;
+ superClass = jarManager.getClassEntry(temp);
+ }
+
+ // Next, go through the imports (order is important)
+ if (superClass == null) {
+ Iteratormethod.
+ */
+ private void addLocalVarCompletions(Setblock.
+ */
+ private void addLocalVarCompletions(Setnull, then the current
+ * JVM's main JRE jar (rt.jar, or classes.jar on OS X) will be
+ * added. If this jar has already been added, adding it again
+ * will do nothing (except possibly update its attached source
+ * location).
+ * @throws IOException
+ * If an IO error occurs.
+ * @see #getJars()
+ * @see #removeJar(File)
+ */
+ public void addJar(LibraryInfo info) throws IOException {
+ jarManager.addClassFileSource(info);
+ }
+
+ /**
+ * Checks whether the user is typing a completion for a String member after
+ * a String literal.
+ *
+ * @param comp
+ * The text component.
+ * @param alreadyEntered
+ * The text already entered.
+ * @param cu
+ * The compilation unit being parsed.
+ * @param set
+ * The set to add possible completions to.
+ * @return Whether the user is indeed typing a completion for a String
+ * literal member.
+ */
+ private boolean checkStringLiteralMember(JTextComponent comp, String alreadyEntered, CompilationUnit cu,
+ SetClassFile representing the actual type of the
+ * variable/field/etc. being code completed
+ * @return A mapping of type parameter names to type arguments (both
+ * Strings).
+ */
+ private MapLibraryInfo in this list will have no effect on this
+ * completion provider; in order to do that, you must re-add the jar
+ * via {@link #addJar(LibraryInfo)}. If there are no jars on the
+ * "build path," this will be an empty list.
+ * @see #addJar(LibraryInfo)
+ */
+ public List
+ *
+ *
+ * @param cu
+ * @param comp
+ * @param alreadyEntered
+ * @param retVal
+ */
+ private void loadCompletionsForCaretPosition(CompilationUnit cu, JTextComponent comp, String alreadyEntered,
+ Set
+ *
+ *
+ * @param cu
+ * @param comp
+ * @param alreadyEntered
+ * @param retVal
+ */
+ private void loadCompletionsForCaretPosition(CompilationUnit cu, JTextComponent comp, String alreadyEntered,
+ Setnull if none.
+ * @param prefix
+ * The text up to the current caret position. This is guaranteed
+ * to be non-null not equal to "this".
+ * @param offs
+ * The offset of the caret in the document.
+ */
+ private void loadCompletionsForCaretPositionQualified(CompilationUnit cu, String alreadyEntered,
+ Setfalse if
+ * the jar was not on the build path.
+ * @see #addJar(LibraryInfo)
+ * @see #getJars()
+ * @see #clearJars()
+ */
+ public boolean removeJar(File jar) {
+ boolean removed = jarManager.removeClassFileSource(jar);
+ // The memory used by the completions can be quite large, so go ahead
+ // and clear out the completions list so no-longer-needed ones are
+ // eligible for GC.
+ if (removed) {
+ clear();
+ }
+ return removed;
+ }
+
+ /**
+ * Sets the parent Java provider.
+ *
+ * @param javaProvider
+ * The parent completion provider.
+ */
+ void setJavaProvider(JavaCompletionProvider javaProvider) {
+ this.javaProvider = javaProvider;
+ }
+
}
\ No newline at end of file
diff --git a/src/main/java/org/fife/rsta/ac/java/classreader/MethodInfo.java b/src/main/java/org/fife/rsta/ac/java/classreader/MethodInfo.java
index 2e94841e..3fd92ff6 100644
--- a/src/main/java/org/fife/rsta/ac/java/classreader/MethodInfo.java
+++ b/src/main/java/org/fife/rsta/ac/java/classreader/MethodInfo.java
@@ -62,7 +62,7 @@ public class MethodInfo extends MemberInfo implements AccessFlags {
* The type of all parameters to this method. Note that this cache will
* be short-lived, as classes that take type parameters will pass their
* type arguments down to individual MethodInfos when doing
- * completions, to ensure types are as correct as possible.
+ * completions, to ensure types are as correct as possible.
*/
private String[] paramTypes;
@@ -71,6 +71,7 @@ public class MethodInfo extends MemberInfo implements AccessFlags {
*/
private String returnType;
+ private String returnTypeQualified;
/**
* Cached string representing the name and parameters for this method.
*/
@@ -118,7 +119,7 @@ private void appendParamDescriptors(StringBuilder sb) {
sb.append(", ");
}
}
-
+
}
@@ -129,7 +130,7 @@ private void appendParamDescriptors(StringBuilder sb) {
* lazily recomputed the next time they are needed. This allows this
* MethodInfo to be used for code completion for instances
* of the same class initialized with different type arguments.