Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJayaprakash Arthanareeswaran2014-02-26 15:17:36 +0000
committerJayaprakash Arthanareeswaran2014-02-26 15:17:36 +0000
commit7100eda84b437a1d2f42be690490198bb0d2e1f0 (patch)
treed97d48bcfbb0fae3f7c194a42147e084495fe8f5
parentf1a111b3a23818f90206cf827aa78528b873971f (diff)
downloadeclipse.jdt.core-7100eda84b437a1d2f42be690490198bb0d2e1f0.tar.gz
eclipse.jdt.core-7100eda84b437a1d2f42be690490198bb0d2e1f0.tar.xz
eclipse.jdt.core-7100eda84b437a1d2f42be690490198bb0d2e1f0.zip
Fix for Bug 426058 - IJavaElement.getAttachedJavadoc(IProgressMonitor)I20140226-1700I20140226-1200
uses wrong encoding
-rw-r--r--org.eclipse.jdt.core.tests.model/.settings/org.eclipse.core.resources.prefs1
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java62
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/AttachedJavadocProject/UTF8doc2/p/TestBug394382.html253
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/AttachedJavadocProject/UTF8doc2/p/TestBug394382.txt8
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElement.java13
5 files changed, 333 insertions, 4 deletions
diff --git a/org.eclipse.jdt.core.tests.model/.settings/org.eclipse.core.resources.prefs b/org.eclipse.jdt.core.tests.model/.settings/org.eclipse.core.resources.prefs
index fc88236279..edee3a40a4 100644
--- a/org.eclipse.jdt.core.tests.model/.settings/org.eclipse.core.resources.prefs
+++ b/org.eclipse.jdt.core.tests.model/.settings/org.eclipse.core.resources.prefs
@@ -1,4 +1,5 @@
eclipse.preferences.version=1
encoding//workspace/AttachedJavadocProject/UTF8doc=UTF-8
encoding//workspace/AttachedJavadocProject/UTF8doc/p/TestBug394382.txt=UTF-8
+encoding//workspace/AttachedJavadocProject/UTF8doc2=UTF-8
encoding//workspace/Encoding/src/testUTF8/Test.java=UTF-8
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java
index d5d2351f17..d441819d73 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -95,6 +95,7 @@ public class AttachedJavadocTests extends ModifyingResourceTests {
suite.addTest(new AttachedJavadocTests("testBug394967"));
suite.addTest(new AttachedJavadocTests("testBug394382"));
suite.addTest(new AttachedJavadocTests("testBug398272"));
+ suite.addTest(new AttachedJavadocTests("testBug426058"));
return suite;
}
@@ -1172,4 +1173,63 @@ public class AttachedJavadocTests extends ModifyingResourceTests {
}
}
}
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=426058
+ public void testBug426058() throws JavaModelException {
+ IClasspathEntry[] oldClasspath = this.project.getRawClasspath();
+ try {
+ String encoding = "UTF-8";
+ IResource resource = this.project.getProject().findMember("/UTF8doc2/"); //$NON-NLS-1$
+ assertNotNull("doc folder cannot be null", resource); //$NON-NLS-1$
+ URI locationURI = resource.getLocationURI();
+ assertNotNull("doc folder cannot be null", locationURI); //$NON-NLS-1$
+ URL docUrl = null;
+ try {
+ docUrl = locationURI.toURL();
+ } catch (MalformedURLException e) {
+ assertTrue("Should not happen", false); //$NON-NLS-1$
+ } catch(IllegalArgumentException e) {
+ assertTrue("Should not happen", false); //$NON-NLS-1$
+ }
+ IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, docUrl.toExternalForm());
+ IClasspathEntry newEntry = JavaCore.newLibraryEntry(new Path("/AttachedJavadocProject/lib/bug394382.jar"), null, null, new IAccessRule[]{}, new IClasspathAttribute[] { attribute }, false ); //$NON-NLS-1$
+ IClasspathEntry[] newClasspath = new IClasspathEntry[oldClasspath.length + 1];
+ System.arraycopy(oldClasspath, 0, newClasspath, 0, oldClasspath.length);
+ newClasspath[oldClasspath.length] = newEntry;
+ this.project.setRawClasspath(newClasspath, null);
+ waitForAutoBuild();
+
+ IPackageFragmentRoot[] roots = this.project.getAllPackageFragmentRoots();
+ IPackageFragmentRoot packageRoot = null;
+ for(int i=0; i < roots.length; i++) {
+ IPath path = roots[i].getPath();
+ if (path.segment(path.segmentCount() - 1).equals("bug394382.jar")) {
+ packageRoot = roots[i];
+ }
+ }
+
+ assertNotNull("Should not be null", packageRoot);
+ IPackageFragment packageFragment = packageRoot.getPackageFragment("p"); //$NON-NLS-1$
+ assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
+ IClassFile classFile = packageFragment.getClassFile("TestBug394382.class"); //$NON-NLS-1$
+ assertNotNull(classFile);
+ IType type = classFile.getType();
+ IFile sourceFile = (IFile) this.project.getProject().findMember("UTF8doc2/p/TestBug394382.txt");
+ String javadoc = null;
+ try {
+ javadoc = type.getAttachedJavadoc(new NullProgressMonitor());
+ } catch(JavaModelException e) {
+ assertTrue("Should not happen", false);
+ }
+ assertNotNull("Shouldhave a javadoc", javadoc); //$NON-NLS-1$
+ String encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding));
+ char[] charArray = encodedContents.toCharArray();
+ encodedContents = new String(CharOperation.remove(charArray, '\r'));
+ charArray = javadoc.toCharArray();
+ javadoc = new String(CharOperation.remove(charArray, '\r'));
+ assertTrue("Sources should be decoded the same way", encodedContents.equals(javadoc));
+ }
+ finally {
+ this.project.setRawClasspath(oldClasspath, null);
+ }
+ }
}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/AttachedJavadocProject/UTF8doc2/p/TestBug394382.html b/org.eclipse.jdt.core.tests.model/workspace/AttachedJavadocProject/UTF8doc2/p/TestBug394382.html
new file mode 100644
index 0000000000..79a13b8e52
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/AttachedJavadocProject/UTF8doc2/p/TestBug394382.html
@@ -0,0 +1,253 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!-- NewPage -->
+<html lang="en">
+<head>
+<title>TestBug394382</title>
+<META http-equiv="Content-Type" content="text/html" charset="UTF-8">
+<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
+</head>
+<body>
+<script type="text/javascript"><!--
+ if (location.href.indexOf('is-external=true') == -1) {
+ parent.document.title="TestBug394382";
+ }
+//-->
+</script>
+<noscript>
+<div>JavaScript is disabled on your browser.</div>
+</noscript>
+<!-- ========= START OF TOP NAVBAR ======= -->
+<div class="topNav"><a name="navbar_top">
+<!-- -->
+</a><a href="#skip-navbar_top" title="Skip navigation links"></a><a name="navbar_top_firstrow">
+<!-- -->
+</a>
+<ul class="navList" title="Navigation">
+<li><a href="../p/package-summary.html">Package</a></li>
+<li class="navBarCell1Rev">Class</li>
+<li><a href="package-tree.html">Tree</a></li>
+<li><a href="../deprecated-list.html">Deprecated</a></li>
+<li><a href="../index-all.html">Index</a></li>
+<li><a href="../help-doc.html">Help</a></li>
+</ul>
+</div>
+<div class="subNav">
+<ul class="navList">
+<li>Prev Class</li>
+<li>Next Class</li>
+</ul>
+<ul class="navList">
+<li><a href="../index.html?p/TestBug394382.html" target="_top">Frames</a></li>
+<li><a href="TestBug394382.html" target="_top">No Frames</a></li>
+</ul>
+<ul class="navList" id="allclasses_navbar_top">
+<li><a href="../allclasses-noframe.html">All Classes</a></li>
+</ul>
+<div>
+<script type="text/javascript"><!--
+ allClassesLink = document.getElementById("allclasses_navbar_top");
+ if(window==top) {
+ allClassesLink.style.display = "block";
+ }
+ else {
+ allClassesLink.style.display = "none";
+ }
+ //-->
+</script>
+</div>
+<div>
+<ul class="subNavList">
+<li>Summary:&nbsp;</li>
+<li>Nested&nbsp;|&nbsp;</li>
+<li>Field&nbsp;|&nbsp;</li>
+<li><a href="#constructor_summary">Constr</a>&nbsp;|&nbsp;</li>
+<li><a href="#method_summary">Method</a></li>
+</ul>
+<ul class="subNavList">
+<li>Detail:&nbsp;</li>
+<li>Field&nbsp;|&nbsp;</li>
+<li><a href="#constructor_detail">Constr</a>&nbsp;|&nbsp;</li>
+<li><a href="#method_detail">Method</a></li>
+</ul>
+</div>
+<a name="skip-navbar_top">
+<!-- -->
+</a></div>
+<!-- ========= END OF TOP NAVBAR ========= -->
+<!-- ======== START OF CLASS DATA ======== -->
+<div class="header">
+<div class="subTitle">p</div>
+<h2 title="Class TestBug394382" class="title">Class TestBug394382</h2>
+</div>
+<div class="contentContainer">
+<ul class="inheritance">
+<li>java.lang.Object</li>
+<li>
+<ul class="inheritance">
+<li>p.TestBug394382</li>
+</ul>
+</li>
+</ul>
+<div class="description">
+<ul class="blockList">
+<li class="blockList">
+<hr>
+<br>
+<pre>public class <span class="strong">TestBug394382</span>
+extends java.lang.Object</pre>
+<div class="block">こんにちは世界 ! This class <code>TestBug394382</code> is to test bug 426058</div>
+<dl><dt><span class="strong">See Also:</span></dt><dd><code>https://bugs.eclipse.org/bugs/show_bug.cgi?id=394382</code></dd></dl>
+</li>
+</ul>
+</div>
+<div class="summary">
+<ul class="blockList">
+<li class="blockList">
+<!-- ======== CONSTRUCTOR SUMMARY ======== -->
+<ul class="blockList">
+<li class="blockList"><a name="constructor_summary">
+<!-- -->
+</a>
+<h3>Constructor Summary</h3>
+<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation">
+<caption><span>Constructors</span><span class="tabEnd">&nbsp;</span></caption>
+<tr>
+<th class="colOne" scope="col">Constructor and Description</th>
+</tr>
+<tr class="altColor">
+<td class="colOne"><code><strong><a href="../p/TestBug394382.html#TestBug394382()">TestBug394382</a></strong>()</code>&nbsp;</td>
+</tr>
+</table>
+</li>
+</ul>
+<!-- ========== METHOD SUMMARY =========== -->
+<ul class="blockList">
+<li class="blockList"><a name="method_summary">
+<!-- -->
+</a>
+<h3>Method Summary</h3>
+<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
+<caption><span>Methods</span><span class="tabEnd">&nbsp;</span></caption>
+<tr>
+<th class="colFirst" scope="col">Modifier and Type</th>
+<th class="colLast" scope="col">Method and Description</th>
+</tr>
+<tr class="altColor">
+<td class="colFirst"><code>static void</code></td>
+<td class="colLast"><code><strong><a href="../p/TestBug394382.html#main(java.lang.String[])">main</a></strong>(java.lang.String[]&nbsp;args)</code>&nbsp;</td>
+</tr>
+</table>
+<ul class="blockList">
+<li class="blockList"><a name="methods_inherited_from_class_java.lang.Object">
+<!-- -->
+</a>
+<h3>Methods inherited from class&nbsp;java.lang.Object</h3>
+<code>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li>
+</ul>
+</li>
+</ul>
+</li>
+</ul>
+</div>
+<div class="details">
+<ul class="blockList">
+<li class="blockList">
+<!-- ========= CONSTRUCTOR DETAIL ======== -->
+<ul class="blockList">
+<li class="blockList"><a name="constructor_detail">
+<!-- -->
+</a>
+<h3>Constructor Detail</h3>
+<a name="TestBug394382()">
+<!-- -->
+</a>
+<ul class="blockListLast">
+<li class="blockList">
+<h4>TestBug394382</h4>
+<pre>public&nbsp;TestBug394382()</pre>
+</li>
+</ul>
+</li>
+</ul>
+<!-- ============ METHOD DETAIL ========== -->
+<ul class="blockList">
+<li class="blockList"><a name="method_detail">
+<!-- -->
+</a>
+<h3>Method Detail</h3>
+<a name="main(java.lang.String[])">
+<!-- -->
+</a>
+<ul class="blockListLast">
+<li class="blockList">
+<h4>main</h4>
+<pre>public static&nbsp;void&nbsp;main(java.lang.String[]&nbsp;args)</pre>
+</li>
+</ul>
+</li>
+</ul>
+</li>
+</ul>
+</div>
+</div>
+<!-- ========= END OF CLASS DATA ========= -->
+<!-- ======= START OF BOTTOM NAVBAR ====== -->
+<div class="bottomNav"><a name="navbar_bottom">
+<!-- -->
+</a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow">
+<!-- -->
+</a>
+<ul class="navList" title="Navigation">
+<li><a href="../p/package-summary.html">Package</a></li>
+<li class="navBarCell1Rev">Class</li>
+<li><a href="package-tree.html">Tree</a></li>
+<li><a href="../deprecated-list.html">Deprecated</a></li>
+<li><a href="../index-all.html">Index</a></li>
+<li><a href="../help-doc.html">Help</a></li>
+</ul>
+</div>
+<div class="subNav">
+<ul class="navList">
+<li>Prev Class</li>
+<li>Next Class</li>
+</ul>
+<ul class="navList">
+<li><a href="../index.html?p/TestBug394382.html" target="_top">Frames</a></li>
+<li><a href="TestBug394382.html" target="_top">No Frames</a></li>
+</ul>
+<ul class="navList" id="allclasses_navbar_bottom">
+<li><a href="../allclasses-noframe.html">All Classes</a></li>
+</ul>
+<div>
+<script type="text/javascript"><!--
+ allClassesLink = document.getElementById("allclasses_navbar_bottom");
+ if(window==top) {
+ allClassesLink.style.display = "block";
+ }
+ else {
+ allClassesLink.style.display = "none";
+ }
+ //-->
+</script>
+</div>
+<div>
+<ul class="subNavList">
+<li>Summary:&nbsp;</li>
+<li>Nested&nbsp;|&nbsp;</li>
+<li>Field&nbsp;|&nbsp;</li>
+<li><a href="#constructor_summary">Constr</a>&nbsp;|&nbsp;</li>
+<li><a href="#method_summary">Method</a></li>
+</ul>
+<ul class="subNavList">
+<li>Detail:&nbsp;</li>
+<li>Field&nbsp;|&nbsp;</li>
+<li><a href="#constructor_detail">Constr</a>&nbsp;|&nbsp;</li>
+<li><a href="#method_detail">Method</a></li>
+</ul>
+</div>
+<a name="skip-navbar_bottom">
+<!-- -->
+</a></div>
+<!-- ======== END OF BOTTOM NAVBAR ======= -->
+</body>
+</html>
diff --git a/org.eclipse.jdt.core.tests.model/workspace/AttachedJavadocProject/UTF8doc2/p/TestBug394382.txt b/org.eclipse.jdt.core.tests.model/workspace/AttachedJavadocProject/UTF8doc2/p/TestBug394382.txt
new file mode 100644
index 0000000000..dce4d86440
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/AttachedJavadocProject/UTF8doc2/p/TestBug394382.txt
@@ -0,0 +1,8 @@
+<div class="block">こんにちは世界 ! This class <code>TestBug394382</code> is to test bug 426058</div>
+<dl><dt><span class="strong">See Also:</span></dt><dd><code>https://bugs.eclipse.org/bugs/show_bug.cgi?id=394382</code></dd></dl>
+</li>
+</ul>
+</div>
+<div class="summary">
+<ul class="blockList">
+<li class="blockList">
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElement.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElement.java
index 9fd2d474b3..6987c0060e 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElement.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -719,9 +719,9 @@ public abstract class JavaElement extends PlatformObject implements IJavaElement
if (arrayLength < toBeFoundLength)
return -1;
loop: for (int i = start, max = arrayLength - toBeFoundLength + 1; i < max; i++) {
- if (array[i] == toBeFound[0]) {
+ if (isSameCharacter(array[i], toBeFound[0])) {
for (int j = 1; j < toBeFoundLength; j++) {
- if (array[i + j] != toBeFound[j])
+ if (!isSameCharacter(array[i + j], toBeFound[j]))
continue loop;
}
return i;
@@ -729,6 +729,13 @@ public abstract class JavaElement extends PlatformObject implements IJavaElement
}
return -1;
}
+ boolean isSameCharacter(byte b1, byte b2) {
+ if (b1 == b2 || Character.toUpperCase((char) b1) == Character.toUpperCase((char) b2)) {
+ return true;
+ }
+ return false;
+ }
+
/*
* We don't use getContentEncoding() on the URL connection, because it might leave open streams behind.
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=117890

Back to the top