Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/main/java/org/fife/rsta/ac/LanguageSupportFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.beans.PropertyChangeListener;
import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
Expand Down Expand Up @@ -79,7 +80,8 @@ public void addLanguageSupport(String style, String lsClassName) {
*/
private void createSupportMap() {

styleToSupport = new HashMap<String, LanguageSupport>();
// use WeakHashMap so language supports not needed any more can be GC'd
styleToSupport = new WeakHashMap<String, LanguageSupport>();
styleToSupportClass = new HashMap<String, String>();

String prefix = "org.fife.rsta.ac.";
Expand Down Expand Up @@ -149,7 +151,8 @@ public LanguageSupport getSupportFor(String style) {
}
styleToSupport.put(style, support);
// Always remove from classes to load, so we don't try again
styleToSupportClass.remove(style);
// don't do this, since the WeakHashMap can loose the reference, so we need to load it again
// styleToSupportClass.remove(style);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/fife/rsta/ac/java/ClassCompletion.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public ClassCompletion(CompletionProvider provider, ClassFile cf) {
this.cf = cf;
}

public ClassCompletion(CompletionProvider provider, ClassFile cf, String replacementText) {
super(provider, replacementText);
this.cf = cf;
}


/*
* Fixed error when comparing classes of the same name, which did not allow
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.fife.rsta.ac.java;

import org.fife.rsta.ac.java.classreader.FieldInfo;
import org.fife.rsta.ac.java.classreader.MethodInfo;
import org.fife.rsta.ac.java.rjc.ast.*;

/**
* @since 2017.03.06.
*/
public interface ExternalMemberClickedListener
{
/**
* Indicates user clicked external class
* @param className the fully qualified class name clicked
*/
void openClass(String className);

/**
* Indicates user clicked a method in an external class
* @param className the fully qualified class name containing the method
* @param methodInfo the MethodInfo structure holding information about clicked method
*/
void gotoMethodInClass(String className, MethodInfo methodInfo);

/**
* Indicates user clicked a field in an external class
* @param className the fully qualified class name containing the field
* @param fieldInfo the FieldInfo structure holding information about clicked field
*/
void gotoFieldInClass(String className, FieldInfo fieldInfo);
}
125 changes: 124 additions & 1 deletion src/main/java/org/fife/rsta/ac/java/FieldCompletion.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,133 @@ public boolean equals(Object obj) {
((FieldCompletion)obj).getSignature().equals(getSignature());
}

/**
* Used to add "this" with the class type to the completion list
* @param provider
* @param type
* @return
*/
public static FieldCompletion createThisCompletion(CompletionProvider provider, final Type type) {
FieldCompletion fc = new FieldCompletion(provider, "this");
fc.data = new Data() {
@Override
public String getEnclosingClassName(boolean fullyQualified) {
return type.getName(fullyQualified);
}

@Override
public String getIcon() {
return IconFactory.FIELD_PUBLIC_ICON;
}

@Override
public String getSignature() {
return "this";
}

@Override
public String getSummary() {
return null;
}

@Override
public String getType() {
return type.getName(false);
}

@Override
public boolean isConstructor() {
return false;
}

@Override
public boolean isDeprecated() {
return false;
}

@Override
public boolean isAbstract() {
return false;
}

@Override
public boolean isFinal() {
return false;
}

@Override
public boolean isStatic() {
return false;
}
};
return fc;
}

/**
* Used to add "super" with the class type to the completion list
* @param provider
* @param type
* @return
*/
public static FieldCompletion createSuperCompletion(CompletionProvider provider, final Type type) {
FieldCompletion fc = new FieldCompletion(provider, "super");
fc.data = new Data() {
@Override
public String getEnclosingClassName(boolean fullyQualified) {
return type.getName(fullyQualified);
}

@Override
public String getIcon() {
return IconFactory.FIELD_PROTECTED_ICON;
}

@Override
public String getSignature() {
return "super";
}

@Override
public String getSummary() {
return null;
}

@Override
public String getType() {
return type.getName(false);
}

@Override
public boolean isConstructor() {
return false;
}

@Override
public boolean isDeprecated() {
return false;
}

@Override
public boolean isAbstract() {
return false;
}

@Override
public boolean isFinal() {
return false;
}

@Override
public boolean isStatic() {
return false;
}
};
return fc;
}

public static FieldCompletion createLengthCompletion(
CompletionProvider provider, final Type type) {
FieldCompletion fc = new FieldCompletion(provider, type.toString());
FieldCompletion fc = new FieldCompletion(provider, "length");
fc.data = new Data() {

@Override
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/fife/rsta/ac/java/FieldInfoData.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
package org.fife.rsta.ac.java;

import java.lang.ref.WeakReference;
import java.util.Iterator;

import org.fife.rsta.ac.java.MemberCompletion.Data;
Expand All @@ -33,12 +34,12 @@
class FieldInfoData implements Data {

private FieldInfo info;
private SourceCompletionProvider provider;
private WeakReference<SourceCompletionProvider> provider;


public FieldInfoData(FieldInfo info, SourceCompletionProvider provider) {
this.info = info;
this.provider = provider;
this.provider = new WeakReference<SourceCompletionProvider>(provider);
}


Expand Down Expand Up @@ -96,8 +97,9 @@ public String getSignature() {
@Override
public String getSummary() {

ClassFile cf = info.getClassFile();;
SourceLocation loc = provider.getSourceLocForClass(cf.getClassName(true));
ClassFile cf = info.getClassFile();
SourceLocation loc = null;
if (provider != null && provider.get() != null) loc = provider.get().getSourceLocForClass(cf.getClassName(true));
String summary = null;

// First, try to parse the Javadoc for this method from the attached
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/fife/rsta/ac/java/JarManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ public void addCompletions(CompletionProvider p, String text,
// completions for classes not in their import statements.
// Thanks to Guilherme Joao Frantz and Jonatas Schuler for the patch!
else {//if (text.indexOf('.')==-1) {
String lowerCaseText = text.toLowerCase();
// don't use lowercase here, since we would like to preserve the case for the textpartsmatch
// String lowerCaseText = text.toLowerCase();
for (int i=0; i<classFileSources.size(); i++) {
JarReader jar = classFileSources.get(i);
List<ClassFile> classFiles = jar.
getClassesWithNamesStartingWith(lowerCaseText);
getClassesWithNamesStartingWith(text);
if (classFiles!=null) {
for (ClassFile cf : classFiles) {
if (org.fife.rsta.ac.java.classreader.Util.isPublic(cf.getAccessFlags())) {
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/org/fife/rsta/ac/java/JavaCellRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.lang.ref.WeakReference;
import java.util.Map;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;
Expand All @@ -39,7 +40,7 @@ public class JavaCellRenderer extends DefaultListCellRenderer {
private JList list;
private boolean selected;
private boolean evenRow;
private JavaSourceCompletion jsc;
private WeakReference<JavaSourceCompletion> jsc;

/**
* The alternating background color, or <code>null</code> for none.
Expand Down Expand Up @@ -92,9 +93,9 @@ public Component getListCellRendererComponent(JList list, Object value,
this.selected = selected;

if (value instanceof JavaSourceCompletion) {
jsc = (JavaSourceCompletion)value;
jsc = new WeakReference<JavaSourceCompletion>((JavaSourceCompletion)value);
nonJavaCompletion = null;
setIcon(jsc.getIcon());
setIcon(jsc.get().getIcon());
}
else {
jsc = null;
Expand Down Expand Up @@ -157,11 +158,11 @@ protected void paintComponent(Graphics g) {
int x = getX() + iconW + 2;
g.setColor(selected ? list.getSelectionForeground() :
list.getForeground());
if (jsc!=null && !simpleText) {
jsc.rendererText(g, x, g.getFontMetrics().getHeight(), selected);
if (jsc!=null && jsc.get() != null && !simpleText) {
jsc.get().rendererText(g, x, g.getFontMetrics().getHeight(), selected);
}
else {
Completion c = jsc!=null ? jsc : nonJavaCompletion;
Completion c = jsc!=null && jsc.get() != null ? jsc.get() : nonJavaCompletion;
if (c!=null) {
g.drawString(c.toString(), x, g.getFontMetrics().getHeight());
}
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/org/fife/rsta/ac/java/JavaCompletionProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.swing.*;
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.rjc.ast.CompilationUnit;
import org.fife.ui.autocomplete.AbstractCompletionProvider;
import org.fife.ui.autocomplete.Completion;
import org.fife.ui.autocomplete.DefaultCompletionProvider;
import org.fife.ui.autocomplete.LanguageAwareCompletionProvider;
import org.fife.ui.autocomplete.ParameterizedCompletion;
import org.fife.ui.autocomplete.*;


/**
Expand Down Expand Up @@ -147,8 +144,8 @@ public List<LibraryInfo> getJars() {
@Override
public List<ParameterizedCompletion> getParameterizedCompletions(
JTextComponent tc) {
return null;
}
return sourceProvider.getParameterizedCompletions(cu, tc);
}


/**
Expand Down
Loading