1 11 package org.eclipse.jdt.internal.ui.text.java; 12 13 14 import java.io.IOException ; 15 import java.io.Reader ; 16 import java.io.StringReader ; 17 18 import org.eclipse.core.runtime.IProgressMonitor; 19 20 import org.eclipse.jdt.core.IJavaElement; 21 import org.eclipse.jdt.core.IMember; 22 import org.eclipse.jdt.core.JavaModelException; 23 24 import org.eclipse.jdt.ui.JavadocContentAccess; 25 26 import org.eclipse.jdt.internal.ui.JavaPlugin; 27 import org.eclipse.jdt.internal.ui.text.javadoc.JavaDoc2HTMLTextReader; 28 29 30 public class ProposalInfo { 31 32 private boolean fJavadocResolved= false; 33 private String fJavadoc= null; 34 35 protected IJavaElement fElement; 36 37 public ProposalInfo(IMember member) { 38 fElement= member; 39 } 40 41 protected ProposalInfo() { 42 fElement= null; 43 } 44 45 public IJavaElement getJavaElement() throws JavaModelException { 46 return fElement; 47 } 48 49 56 public final String getInfo(IProgressMonitor monitor) { 57 if (!fJavadocResolved) { 58 fJavadocResolved= true; 59 fJavadoc= computeInfo(monitor); 60 } 61 return fJavadoc; 62 } 63 64 71 private String computeInfo(IProgressMonitor monitor) { 72 try { 73 final IJavaElement javaElement= getJavaElement(); 74 if (javaElement instanceof IMember) { 75 IMember member= (IMember) javaElement; 76 return extractJavadoc(member, monitor); 77 } 78 } catch (JavaModelException e) { 79 JavaPlugin.log(e); 80 } catch (IOException e) { 81 JavaPlugin.log(e); 82 } 83 return null; 84 } 85 86 97 private String extractJavadoc(IMember member, IProgressMonitor monitor) throws JavaModelException, IOException { 98 if (member != null) { 99 Reader reader= getHTMLContentReader(member, monitor); 100 if (reader != null) 101 return getString(reader); 102 } 103 return null; 104 } 105 106 private Reader getHTMLContentReader(IMember member, IProgressMonitor monitor) throws JavaModelException { 107 Reader contentReader= JavadocContentAccess.getContentReader(member, true); 108 if (contentReader != null) 109 return new JavaDoc2HTMLTextReader(contentReader); 110 111 if (true && member.getOpenable().getBuffer() == null) { String s= member.getAttachedJavadoc(monitor); 113 if (s != null) 114 return new StringReader (s); 115 } 116 return null; 117 } 118 119 122 private static String getString(Reader reader) { 123 StringBuffer buf= new StringBuffer (); 124 char[] buffer= new char[1024]; 125 int count; 126 try { 127 while ((count= reader.read(buffer)) != -1) 128 buf.append(buffer, 0, count); 129 } catch (IOException e) { 130 return null; 131 } 132 return buf.toString(); 133 } 134 } 135 | Popular Tags |