summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorStephan Herrmann2012-08-28 10:46:20 (EDT)
committer Jayaprakash Arthanareeswaran2012-10-19 00:48:55 (EDT)
commitc90b82edd1ac1d83673b4c91396967c8c061cdc3 (patch)
tree23cc594e7ebcdeb7835b045dcaa1e42b6e7d5a01
parent63af609b0c4ca15a76568f63423f1cb23d7be92e (diff)
downloadeclipse.jdt.core-c90b82edd1ac1d83673b4c91396967c8c061cdc3.zip
eclipse.jdt.core-c90b82edd1ac1d83673b4c91396967c8c061cdc3.tar.gz
eclipse.jdt.core-c90b82edd1ac1d83673b4c91396967c8c061cdc3.tar.bz2
Bug 380048 - error popup when navigating to source files
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SignatureTests.java52
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMapper.java32
2 files changed, 83 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SignatureTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SignatureTests.java
index b98b89d..e236030 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SignatureTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SignatureTests.java
@@ -7,10 +7,12 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Stephan Herrmann - Contribution for Bug 380048 - error popup when navigating to source files
*******************************************************************************/
package org.eclipse.jdt.core.tests.model;
import org.eclipse.jdt.core.*;
+import org.eclipse.jdt.internal.core.SourceMapper;
import junit.framework.Test;
@@ -1555,4 +1557,54 @@ public void testCreateIntersectionTypeSignature2() {
Signature.getIntersectionTypeBounds(signature)
);
}
+// Bug 380048 - error popup when navigating to source files
+public void testSourceMapperSigConversion01() {
+ SourceMapper mapper = new SourceMapper();
+ char[][] typeNames = new char[][] {
+ "java.lang.String".toCharArray(),
+
+ ("apache.Mapper" +
+ "<?,?,ap.Text,ap.ClusterObservations>" +
+ ".Context"
+ ).toCharArray(),
+
+ ("apache.Mapper" +
+ "<?,?,ap.Text,ap.ClusterObservations>" +
+ ".Context<java.lang.String>"
+ ).toCharArray(),
+
+ ("app.Mapper" +
+ "<?,?,ap.Text,ap2.ClusterObservations>"
+ ).toCharArray(),
+
+ "Context<String>".toCharArray(),
+
+ ("Mapper" +
+ "<?,?,Text,ClusterObservations>" +
+ ".Context"
+ +"<String>"
+ ).toCharArray(),
+
+ "Iterable<Mapper<?,?,Text,ClusterObservations>.Context>".toCharArray(),
+
+ "java.util.Iterable<Mapper<?,?,Text,ClusterObservations>.Context>".toCharArray(),
+
+ "Mapper<?,?,Text,Mapper<?,?,Text,ClusterObservations>.Context>.Context".toCharArray()
+ };
+ String[] expectedSigs = new String[] {
+ "QString;",
+ "QContext;",
+ "QContext<QString;>;",
+ "QMapper<**QText;QClusterObservations;>;",
+ "QContext<QString;>;",
+ "QContext<QString;>;",
+ "QIterable<QContext;>;",
+ "QIterable<QContext;>;",
+ "QContext;"
+ };
+ String[] ss = mapper.convertTypeNamesToSigs(typeNames);
+ assertEquals("Wrong number of signatures", expectedSigs.length, ss.length);
+ for (int i=0; i<ss.length; i++)
+ assertEquals("Unexpected signature", expectedSigs[i], ss[i]);
+}
}
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMapper.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMapper.java
index f36be68..7dbd06c 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMapper.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMapper.java
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Kelly Campbell <kellyc@google.com> - Hangs in SourceMapper during java proposals - https://bugs.eclipse.org/bugs/show_bug.cgi?id=281575
+ * Stephan Herrmann - Contribution for Bug 380048 - error popup when navigating to source files
*******************************************************************************/
package org.eclipse.jdt.internal.core;
@@ -369,12 +370,13 @@ public class SourceMapper
}
/**
+ * NOT API, public only for access by Unit tests.
* Converts these type names to unqualified signatures. This needs to be done in order to be consistent
* with the way the source range is retrieved.
* @see SourceMapper#getUnqualifiedMethodHandle
* @see Signature
*/
- private String[] convertTypeNamesToSigs(char[][] typeNames) {
+ public String[] convertTypeNamesToSigs(char[][] typeNames) {
if (typeNames == null)
return CharOperation.NO_STRINGS;
int n = typeNames.length;
@@ -401,6 +403,16 @@ public class SourceMapper
dot = j;
break;
case Signature.C_GENERIC_START:
+ int matchingEnd = findMatchingGenericEnd(typeSig, j+1);
+ if (matchingEnd > 0 && matchingEnd+1 < length && typeSig[matchingEnd+1] == Signature.C_DOT) {
+ // found Head<Param>.Tail -> discard everything except Tail
+ if (simpleTypeSig == null)
+ simpleTypeSig = new StringBuffer().append(typeSig, 0, start);
+ simpleTypeSig.append(Signature.C_UNRESOLVED);
+ start = j = matchingEnd+2;
+ break;
+ }
+ //$FALL-THROUGH$
case Signature.C_NAME_END:
if (dot > start) {
if (simpleTypeSig == null)
@@ -422,6 +434,24 @@ public class SourceMapper
return typeSigs;
}
+ private int findMatchingGenericEnd(char[] sig, int start) {
+ int nesting = 0;
+ int length = sig.length;
+ for (int i=start; i < length; i++) {
+ switch (sig[i]) {
+ case Signature.C_GENERIC_START:
+ nesting++;
+ break;
+ case Signature.C_GENERIC_END:
+ if (nesting == 0)
+ return i;
+ nesting--;
+ break;
+ }
+ }
+ return -1;
+ }
+
private synchronized void computeAllRootPaths(IType type) {
if (this.areRootPathsComputed) {
return;