Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 225809 Details for
Bug 397464
No Javadoc for package-info.java in source attachment when package-info.class doesn't exist
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Proposed Fix
eclipse.jdt.ui.20130118.patch (text/plain), 14.79 KB, created by
Martin Mathew
on 2013-01-18 05:50:58 EST
(
hide
)
Description:
Proposed Fix
Filename:
MIME Type:
Creator:
Martin Mathew
Created:
2013-01-18 05:50:58 EST
Size:
14.79 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui >diff --git ui/org/eclipse/jdt/internal/ui/text/javadoc/JavadocContentAccess2.java ui/org/eclipse/jdt/internal/ui/text/javadoc/JavadocContentAccess2.java >index 36e8639..e355094 100644 >--- ui/org/eclipse/jdt/internal/ui/text/javadoc/JavadocContentAccess2.java >+++ ui/org/eclipse/jdt/internal/ui/text/javadoc/JavadocContentAccess2.java >@@ -30,6 +30,7 @@ > import java.util.zip.ZipEntry; > import java.util.zip.ZipFile; > >+import org.eclipse.core.runtime.Assert; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.IStatus; >@@ -73,7 +74,6 @@ > import org.eclipse.jdt.core.dom.ASTNode; > import org.eclipse.jdt.core.dom.ASTParser; > import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; >-import org.eclipse.jdt.core.dom.Comment; > import org.eclipse.jdt.core.dom.CompilationUnit; > import org.eclipse.jdt.core.dom.IBinding; > import org.eclipse.jdt.core.dom.IVariableBinding; >@@ -83,6 +83,7 @@ > import org.eclipse.jdt.core.dom.MethodRefParameter; > import org.eclipse.jdt.core.dom.Name; > import org.eclipse.jdt.core.dom.NodeFinder; >+import org.eclipse.jdt.core.dom.PackageDeclaration; > import org.eclipse.jdt.core.dom.SimpleName; > import org.eclipse.jdt.core.dom.TagElement; > import org.eclipse.jdt.core.dom.TextElement; >@@ -439,9 +440,11 @@ > } > } > >- private final IMember fMember; >+ private final IJavaElement fElement; >+ > /** >- * The method, or <code>null</code> if {@link #fMember} is not a method where @inheritDoc could work. >+ * The method, or <code>null</code> if {@link #fElement} is not a method where @inheritDoc could >+ * work. > */ > private final IMethod fMethod; > private final Javadoc fJavadoc; >@@ -456,15 +459,17 @@ > private HashMap<String, StringBuffer> fExceptionDescriptions; > > private JavadocContentAccess2(IMethod method, Javadoc javadoc, String source, JavadocLookup lookup) { >- fMember= method; >+ Assert.isNotNull(method); >+ fElement= method; > fMethod= method; > fJavadoc= javadoc; > fSource= source; > fJavadocLookup= lookup; > } > >- private JavadocContentAccess2(IMember member, Javadoc javadoc, String source) { >- fMember= member; >+ private JavadocContentAccess2(IJavaElement element, Javadoc javadoc, String source) { >+ Assert.isNotNull(element); >+ fElement= element; > fMethod= null; > fJavadoc= javadoc; > fSource= source; >@@ -609,7 +614,7 @@ > //Caveat: Javadoc nodes are not available when Javadoc processing has been disabled! > //https://bugs.eclipse.org/bugs/show_bug.cgi?id=212207 > >- CompilationUnit root= createAST(element, rawJavadoc); >+ CompilationUnit root= createCompilationUnit(element, rawJavadoc); > if (root == null) > return null; > List<AbstractTypeDeclaration> types= root.types(); >@@ -619,6 +624,16 @@ > return type.getJavadoc(); > } > >+ private static Javadoc getPackageJavadocNode(IJavaElement element, String rawJavadoc) { >+ CompilationUnit cu= createCompilationUnit(element, rawJavadoc); >+ if (cu != null) { >+ PackageDeclaration packDeclr= cu.getPackage(); >+ if (packDeclr != null) { >+ return packDeclr.getJavadoc(); >+ } >+ } >+ return null; >+ } > > private static String javadoc2HTML(IMember member, String rawJavadoc) { > Javadoc javadoc= getJavadocNode(member, rawJavadoc); >@@ -1066,7 +1081,7 @@ > // should never happen, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=304826 > Exception exception= new Exception("Illegal ASTNode positions: previousEnd=" + previousEnd //$NON-NLS-1$ > + ", childStart=" + childStart //$NON-NLS-1$ >- + ", member=" + fMember.getHandleIdentifier() //$NON-NLS-1$ >+ + ", element=" + fElement.getHandleIdentifier() //$NON-NLS-1$ > + ", Javadoc:\n" + fSource); //$NON-NLS-1$ > JavaPlugin.log(exception); > } else if (previousEnd != childStart) { >@@ -1183,9 +1198,12 @@ > > List<? extends ASTNode> fragments= node.fragments(); > try { >+ if (!(fElement instanceof IMember)) { >+ return false; >+ } > if (fragments.isEmpty()) { >- if (fMember instanceof IField && JdtFlags.isStatic(fMember) && JdtFlags.isFinal(fMember)) { >- IField field= (IField) fMember; >+ if (fElement instanceof IField && JdtFlags.isStatic((IField) fElement) && JdtFlags.isFinal((IField) fElement)) { >+ IField field= (IField) fElement; > return handleConstantValue(field, false); > } > } else if (fragments.size() == 1) { >@@ -1194,7 +1212,7 @@ > MemberRef memberRef= (MemberRef) first; > if (memberRef.getQualifier() == null) { > SimpleName name= memberRef.getName(); >- IType type= fMember instanceof IType ? (IType)fMember : fMember.getDeclaringType(); >+ IType type= fElement instanceof IType ? (IType) fElement : ((IMember) fElement).getDeclaringType(); > while (type != null) { > IField field= type.getField(name.getIdentifier()); > if (field != null && field.exists()) { >@@ -1271,13 +1289,13 @@ > > try { > String url= null; >- if (fMember.isBinary()) { >- URL javadocBaseLocation= JavaUI.getJavadocBaseLocation(fMember); >+ if (fElement instanceof IMember && ((IMember) fElement).isBinary()) { >+ URL javadocBaseLocation= JavaUI.getJavadocBaseLocation(fElement); > if (javadocBaseLocation != null) { > url= javadocBaseLocation.toExternalForm(); > } > } else { >- IPackageFragmentRoot srcRoot= JavaModelUtil.getPackageFragmentRoot(fMember); >+ IPackageFragmentRoot srcRoot= JavaModelUtil.getPackageFragmentRoot(fElement); > if (srcRoot != null) { > IResource resource= srcRoot.getResource(); > if (resource != null) { >@@ -1569,7 +1587,7 @@ > fBuf.append("<a href='"); //$NON-NLS-1$ > try { > String scheme= JavaElementLinks.JAVADOC_SCHEME; >- String uri= JavaElementLinks.createURI(scheme, fMember, refTypeName, refMemberName, refMethodParamTypes); >+ String uri= JavaElementLinks.createURI(scheme, fElement, refTypeName, refMemberName, refMethodParamTypes); > fBuf.append(uri); > } catch (URISyntaxException e) { > JavaPlugin.log(e); >@@ -1669,10 +1687,16 @@ > String source= typeRoot.getSource(); > //the source can be null for some of the class files > if (source != null) { >- CompilationUnit ast= createAST(typeRoot); >- String javadoc= getJavadocFromAST(ast, source); >- if (javadoc != null) >- return javadoc; >+ Javadoc packageJavadocNode= getPackageJavadocNode(packageFragment, source); >+ if (packageJavadocNode != null) { >+ IMember member= null; >+ if (typeRoot instanceof ICompilationUnit && typeRoot.exists()) { >+ member= ((ICompilationUnit) typeRoot).getType(typeRoot.getElementName()); >+ } else if (typeRoot instanceof IClassFile && typeRoot.exists()) { >+ member= ((IClassFile) typeRoot).getType(); >+ } >+ return new JavadocContentAccess2(member, packageJavadocNode, source).toHTML(); >+ } > } > } > >@@ -1717,20 +1741,6 @@ > return null; > } > >- private static String getJavadocFromAST(CompilationUnit ast, String source) { >- List<Comment> commentList= ast.getCommentList(); >- if (commentList != null && !commentList.isEmpty()) { >- for (int i= commentList.size() - 1; i >= 0; i--) { >- Comment comment= commentList.get(i); >- if (comment instanceof Javadoc) { >- JavadocContentAccess2 docacc= new JavadocContentAccess2(null, (Javadoc) comment, source); >- return docacc.toHTML(); >- } >- } >- } >- return null; >- } >- > private static String getHTMLContent(IJarEntryResource jarEntryResource, String encoding) throws CoreException { > InputStream in= jarEntryResource.getContents(); > try { >@@ -1750,12 +1760,12 @@ > String filePath= packageFragment.getElementName().replace('.', '/') + '/' + JavaModelUtil.PACKAGE_INFO_JAVA; > String contents= getHTMLContentFromAttachedSource(root, filePath); > if (contents != null) { >- ASTParser parser= createASTParser(packageFragment); >- parser.setSource(contents.toCharArray()); >- CompilationUnit ast= (CompilationUnit) parser.createAST(null); >- String javadoc= getJavadocFromAST(ast, contents); >- if (javadoc != null) >- return javadoc; >+ ICompilationUnit cu= packageFragment.getCompilationUnit(JavaModelUtil.PACKAGE_INFO_JAVA); >+ IType type= cu.getType(cu.getElementName()); >+ Javadoc packageJavadocNode= getPackageJavadocNode(type, contents); >+ if (packageJavadocNode != null) >+ return new JavadocContentAccess2(type, packageJavadocNode, contents).toHTML(); >+ > } > filePath= packageFragment.getElementName().replace('.', '/') + '/' + JavaModelUtil.PACKAGE_HTML; > return getHTMLContentFromAttachedSource(root, filePath); >@@ -1765,6 +1775,18 @@ > IPath sourceAttachmentPath= root.getSourceAttachmentPath(); > if (sourceAttachmentPath != null) { > File file= sourceAttachmentPath.toFile(); >+ >+ if (!file.exists()) { >+ //the path could be a workspace relative path to a jar or to the source folder >+ IWorkspaceRoot wsRoot= ResourcesPlugin.getWorkspace().getRoot(); >+ IResource res= wsRoot.findMember(sourceAttachmentPath.append(filePath)); >+ if (res == null) >+ res= wsRoot.findMember(sourceAttachmentPath); >+ >+ if (res != null) >+ file= res.getLocation().toFile(); >+ >+ } > if (file.isDirectory()) { > //the path could be an absolute path to the source folder > IPath packagedocPath= sourceAttachmentPath.append(filePath); >@@ -1772,17 +1794,6 @@ > return getFileContent(packagedocPath.toFile()); > > } else { >- if (!file.exists()) { >- //the path could be a workspace relative path to a jar or to the source folder >- IWorkspaceRoot wsRoot= ResourcesPlugin.getWorkspace().getRoot(); >- IResource res= wsRoot.findMember(sourceAttachmentPath.append(filePath)); >- if (res == null) >- res= wsRoot.findMember(sourceAttachmentPath); >- >- if (res != null) >- file= res.getLocation().toFile(); >- >- } > if (file.exists()) { > if (JavaModelUtil.PACKAGE_HTML.equals(file.getName())) > return getFileContent(file); >@@ -1883,28 +1894,7 @@ > return encoding; > } > >- /** >- * Reads a compilation unit and creates the AST DOM for manipulating the Java source. >- * >- * @param typeRoot cane be a compilation unit or a class file >- * @return parsed compilation unit >- */ >- >- private static CompilationUnit createAST(ITypeRoot typeRoot) { >- ASTParser parser= createASTParser(typeRoot); >- parser.setKind(ASTParser.K_COMPILATION_UNIT); >- if (typeRoot instanceof ICompilationUnit) { >- parser.setSource((ICompilationUnit) typeRoot); >- } else if (typeRoot instanceof IClassFile) { >- parser.setSource((IClassFile) typeRoot); >- } >- parser.setResolveBindings(true); >- return (CompilationUnit) parser.createAST(null); >- >- } >- >- >- private static CompilationUnit createAST(IJavaElement element, String rawJavadoc) { >+ private static CompilationUnit createCompilationUnit(IJavaElement element, String rawJavadoc) { > ASTParser parser= createASTParser(element); > String source= rawJavadoc + "class C{}"; //$NON-NLS-1$ > parser.setSource(source.toCharArray()); >@@ -1912,6 +1902,7 @@ > } > > private static ASTParser createASTParser(IJavaElement element) { >+ Assert.isNotNull(element); > ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL); > IJavaProject javaProject= element.getJavaProject(); > parser.setProject(javaProject); >diff --git ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLinks.java ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLinks.java >index e95102a..969d706 100644 >--- ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLinks.java >+++ ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLinks.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2008, 2012 IBM Corporation and others. >+ * Copyright (c) 2008, 2013 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 >@@ -22,10 +22,14 @@ > import org.eclipse.swt.widgets.Display; > > import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.NullProgressMonitor; > > import org.eclipse.jdt.core.IAnnotation; >+import org.eclipse.jdt.core.ICompilationUnit; > import org.eclipse.jdt.core.IField; >+import org.eclipse.jdt.core.IImportDeclaration; > import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.IJavaProject; > import org.eclipse.jdt.core.ILocalVariable; > import org.eclipse.jdt.core.IMember; > import org.eclipse.jdt.core.IMethod; >@@ -325,14 +329,16 @@ > > if (segments.length > 2) { > String refTypeName= segments[2]; >- if (refTypeName.indexOf('.') == -1) { >- try { >+ try { >+ if (!element.exists() && JavaModelUtil.PACKAGE_INFO_JAVA.equals(element.getElementName())) { >+ return resolvePackageInfo(element, refTypeName); >+ } else if (refTypeName.indexOf('.') == -1) { > IJavaElement resolvedTypeVariable= resolveTypeVariable(element, refTypeName); > if (resolvedTypeVariable != null) > return resolvedTypeVariable; >- } catch (JavaModelException e) { >- JavaPlugin.log(e); > } >+ } catch (JavaModelException e) { >+ JavaPlugin.log(e); > } > if (element instanceof IAnnotation) { > element= element.getParent(); >@@ -411,6 +417,52 @@ > return element; > } > >+ private static IType resolvePackageInfo(IJavaElement element, String refLinkName) throws JavaModelException { >+ IType type= null; >+ IJavaProject javaProject= element.getJavaProject(); >+ >+ //check if the reference link is a qualified name >+ if (refLinkName.indexOf('.') != -1) { >+ return javaProject.findType(refLinkName, new NullProgressMonitor()); >+ } >+ >+ ICompilationUnit cu= null; >+ //check if the reference link is in enclosing package >+ if (element instanceof IType) { >+ IType typeElement= (IType) element; >+ cu= typeElement.getCompilationUnit(); >+ type= javaProject.findType(typeElement.getPackageFragment().getElementName() + '.' + refLinkName, new NullProgressMonitor()); >+ if (type != null) { >+ return type; >+ } >+ } >+ >+ //check whether the reference link is part of on-demand import or type import >+ if (cu != null) { >+ IImportDeclaration[] imports= cu.getImports(); >+ for (IImportDeclaration iImportDeclaration : imports) { >+ String name= iImportDeclaration.getElementName(); >+ if (iImportDeclaration.isOnDemand()) { >+ //remove the * from the element name >+ name= name.substring(0, name.length() - 1); >+ type= javaProject.findType(name + refLinkName, new NullProgressMonitor()); >+ } else { >+ if (name.endsWith('.' + refLinkName)) { >+ type= javaProject.findType(name, new NullProgressMonitor()); >+ } >+ } >+ if (type != null) { >+ return type; >+ } >+ } >+ } >+ >+ //check whether the reference link is from java.lang. >+ return javaProject.findType("java.lang." + refLinkName, new NullProgressMonitor()); //$NON-NLS-1$ >+ } >+ >+ >+ > private static IJavaElement resolveTypeVariable(IJavaElement baseElement, String typeVariableName) throws JavaModelException { > while (baseElement != null) { > switch (baseElement.getElementType()) {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 397464
: 225809