[subversion:27] Fixed some bugs in the location where the marker resolution places the i
- From: sinnema313@kenai.com
- To: commits@eplugin.kenai.com
- Subject: [subversion:27] Fixed some bugs in the location where the marker resolution places the i
- Date: Sat, 10 Jan 2009 20:17:27 +0000 (GMT)
Repository: subversion
Revision: 27
Author: sinnema313
Date: 2009-01-10 20:17:22 UTC
Log Message:
-----------
Fixed some bugs in the location where the marker resolution places the
import statement.
Show classes in the javafx package at the top of the suggestions.
Modified Paths:
--------------
trunk/com.sun.javafx.eclipse.core/src/com/sun/javafx/eclipse/core/build
er/AddImportStatementResolution.java
trunk/com.sun.javafx.eclipse.core/src/com/sun/javafx/eclipse/core/build
er/JavaFXMarkerResolutionGenerator.java
trunk/com.sun.javafx.eclipse.core/test/com/sun/javafx/eclipse/core/buil
der/UnknownSymbolResolutionTest.java
Diffs:
-----
Index:
trunk/com.sun.javafx.eclipse.core/test/com/sun/javafx/eclipse/core/buil
der/UnknownSymbolResolutionTest.java
===================================================================
---
trunk/com.sun.javafx.eclipse.core/test/com/sun/javafx/eclipse/core/buil
der/UnknownSymbolResolutionTest.java (revision 26)
+++
trunk/com.sun.javafx.eclipse.core/test/com/sun/javafx/eclipse/core/buil
der/UnknownSymbolResolutionTest.java (revision 27)
@@ -21,41 +21,61 @@
lines = new ArrayList<String>();
}
- public void testAddImportWhenEmpty() {
- assertImportStatement(0);
+ public void testEmpty() {
+ assertImportStatementPosition(0);
}
- public void testAddImportWithPackage() {
+ public void testPackage() {
lines.add(PACKAGE_STATEMENT);
- assertImportStatement(1);
+ assertImportStatementPosition(1);
}
- public void testAddImportWithClassComment() {
+ public void testClassComment() {
lines.add(PACKAGE_STATEMENT);
lines.add("/**");
lines.add(" * @author flamingo");
lines.add(" */");
lines.add("Giraffe {");
lines.add("}");
- assertImportStatement(1);
+ assertImportStatementPosition(1);
}
- public void testAddImportWithOtherImport() {
+ public void testOtherImport() {
lines.add("/**");
lines.add(" * @author hyena");
lines.add(" */");
lines.add("import iguaga.jaguar.Koala;");
lines.add("Leopard {");
lines.add("}");
- assertImportStatement(4);
+ assertImportStatementPosition(3);
}
- private void assertImportStatement(int expectedLine) {
- int index = resolution.getImportStatementIndex(getText());
+ public void testVariable() {
+ lines.add("var mandrill = Group {};");
+ lines.add("Nightingale {");
+ lines.add("}");
+ assertImportStatementPosition(0);
+ }
+
+ public void testConstant() {
+ lines.add("def owl = 313;");
+ lines.add("Parrot {");
+ lines.add("}");
+ assertImportStatementPosition(0);
+ }
+
+ private void assertImportStatementPosition(int expectedLine) {
+ String text = getText();
+ int index = resolution.getImportStatementIndex(text);
if (lines.size() > 0) {
+ if (index > 0) {
+ assertEquals("Not at start of line", '\n',
text.charAt(index - 1));
+ }
int actualLine = 0;
- while (index >= 0) {
- index -= lines.get(actualLine++).length() + 1;
+ int pos = text.indexOf('\n');
+ while (pos >= 0 && pos < index) {
+ actualLine++;
+ pos = text.indexOf('\n', pos + 1);
}
assertEquals("Import statement index", expectedLine,
actualLine);
} else {
Index:
trunk/com.sun.javafx.eclipse.core/src/com/sun/javafx/eclipse/core/build
er/AddImportStatementResolution.java
===================================================================
---
trunk/com.sun.javafx.eclipse.core/src/com/sun/javafx/eclipse/core/build
er/AddImportStatementResolution.java (revision 26)
+++
trunk/com.sun.javafx.eclipse.core/src/com/sun/javafx/eclipse/core/build
er/AddImportStatementResolution.java (revision 27)
@@ -65,29 +65,46 @@
if (result < 0) {
result = text.indexOf("package ");
if (result >= 0) {
- result = text.indexOf(';', result) + 1;
+ result = text.indexOf('\n', result) + 1;
} else {
result = 0;
}
int classStart = text.indexOf('{', result);
int commentStart = text.indexOf("/*", result);
- if (0 <= commentStart && commentStart < classStart) {
- result = commentStart - 1;
- } else if (classStart >= 0) {
- classStart--;
- while
(Character.isWhitespace(text.charAt(classStart))) {
- classStart--;
+ int varStart = text.indexOf("var ", result);
+ int defStart = text.indexOf("def ", result);
+ if (isSmallest(defStart, classStart, commentStart,
varStart, defStart)) {
+ result = defStart;
+ } else if (isSmallest(varStart, classStart, commentStart,
varStart, defStart)) {
+ result = varStart;
+ } else if (isSmallest(commentStart, classStart,
commentStart, varStart, defStart)) {
+ result = commentStart;
+ } else if (isSmallest(classStart, classStart,
commentStart, varStart, defStart)) {
+ result = classStart - 1;
+ while (Character.isWhitespace(text.charAt(result))) {
+ result--;
}
- while (classStart > 0 &&
!Character.isWhitespace(text.charAt(classStart))) {
- classStart--;
+ while (result > 0 &&
!Character.isWhitespace(text.charAt(result))) {
+ result--;
}
- while (classStart > 0 &&
Character.isWhitespace(text.charAt(classStart))) {
- classStart--;
- }
- result = classStart;
}
}
+ if (result < text.length()) {
+ while (result > 0 &&
Character.isWhitespace(text.charAt(result)) && text.charAt(result) !=
'\n') {
+ result--;
+ }
+ }
return result;
}
+ private boolean isSmallest(int index, int... indexes) {
+ boolean result = index >= 0;
+ for (int other : indexes) {
+ if (0 <= other && other < index) {
+ result = false;
+ }
+ }
+ return result;
+ }
+
}
Index:
trunk/com.sun.javafx.eclipse.core/src/com/sun/javafx/eclipse/core/build
er/JavaFXMarkerResolutionGenerator.java
===================================================================
---
trunk/com.sun.javafx.eclipse.core/src/com/sun/javafx/eclipse/core/build
er/JavaFXMarkerResolutionGenerator.java (revision 26)
+++
trunk/com.sun.javafx.eclipse.core/src/com/sun/javafx/eclipse/core/build
er/JavaFXMarkerResolutionGenerator.java (revision 27)
@@ -3,6 +3,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.Enumeration;
import java.util.List;
import java.util.Set;
@@ -26,7 +27,9 @@
private static final String JAVA_CLASS_EXTENSION = "class";
private static final Object JAVA_LIBARY_EXTENSION = "jar";
private static final String CLASS = "class ";
+ private static final String VARIABLE = "variable ";
private static final char INTERNAL_CLASS_SEPARATOR = '$';
+ private static final String JAVAFX = "javafx.";
public boolean hasResolutions(final IMarker marker) {
return isUnknownSymbolError(marker) &&
!getFullyQualifiedNames(marker).isEmpty();
@@ -55,10 +58,31 @@
}
private Set<String> getFullyQualifiedNames(final IMarker marker) {
- final Set<String> result = new TreeSet<String>();
+ // Sort classes alphabetically, but put javafx classes first
+ final Set<String> result = new TreeSet<String>(new
Comparator<String>() {
+ public int compare(String o1, String o2) {
+ final int result;
+ if (o1.startsWith(JAVAFX)) {
+ if (o2.startsWith(JAVAFX)) {
+ result = o1.compareTo(o2);
+ } else {
+ result = -1;
+ }
+ } else {
+ if (o2.startsWith(JAVAFX)) {
+ result = 1;
+ } else {
+ result = o1.compareTo(o2);
+ }
+ }
+ return result;
+ }
+ });
final String toMatch =
getMessage(marker).substring(JavaFXCompilerMessage.UNKNOWN_SYMBOL_BEGIN
.length() + 2);
if (toMatch.startsWith(CLASS)) {
addFullyQualifiedNames(marker.getResource().getProject(),
toMatch.substring(CLASS.length()), result);
+ } else if (toMatch.startsWith(VARIABLE) &&
Character.isUpperCase(toMatch.charAt(VARIABLE.length()))) {
+ addFullyQualifiedNames(marker.getResource().getProject(),
toMatch.substring(VARIABLE.length()), result);
}
return result;
}
|
[subversion:27] Fixed some bugs in the location where the marker resolution places the i |
sinnema313 | 01/10/2009 |





