2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 package com
.intellij
.codeInspection
.ex
;
23 import com
.intellij
.codeInspection
.HTMLComposer
;
24 import com
.intellij
.codeInspection
.HTMLJavaHTMLComposer
;
25 import com
.intellij
.codeInspection
.InspectionsBundle
;
26 import com
.intellij
.codeInspection
.reference
.*;
27 import com
.intellij
.psi
.*;
28 import com
.intellij
.xml
.util
.XmlStringUtil
;
29 import org
.jetbrains
.annotations
.NonNls
;
30 import org
.jetbrains
.annotations
.Nullable
;
32 public class HTMLJavaHTMLComposerImpl
extends HTMLJavaHTMLComposer
{
33 private final HTMLComposerImpl myComposer
;
35 public HTMLJavaHTMLComposerImpl(final HTMLComposerImpl composer
) {
36 myComposer
= composer
;
39 public void appendClassOrInterface(StringBuffer buf
, RefClass refClass
, boolean capitalizeFirstLetter
) {
40 if (refClass
.isInterface()) {
41 buf
.append(capitalizeFirstLetter
42 ? InspectionsBundle
.message("inspection.export.results.capitalized.interface")
43 : InspectionsBundle
.message("inspection.export.results.interface"));
45 else if (refClass
.isAbstract()) {
46 buf
.append(capitalizeFirstLetter
47 ? InspectionsBundle
.message("inspection.export.results.capitalized.abstract.class")
48 : InspectionsBundle
.message("inspection.export.results.abstract.class"));
51 buf
.append(capitalizeFirstLetter
52 ? InspectionsBundle
.message("inspection.export.results.capitalized.class")
53 : InspectionsBundle
.message("inspection.export.results.class"));
57 public void appendClassExtendsImplements(StringBuffer buf
, RefClass refClass
) {
58 if (refClass
.getBaseClasses().size() > 0) {
59 HTMLComposerImpl
.appendHeading(buf
, InspectionsBundle
.message("inspection.export.results.extends.implements"));
60 myComposer
.startList(buf
);
61 for (RefClass refBase
: refClass
.getBaseClasses()) {
62 myComposer
.appendListItem(buf
, refBase
);
64 myComposer
.doneList(buf
);
68 public void appendDerivedClasses(StringBuffer buf
, RefClass refClass
) {
69 if (refClass
.getSubClasses().size() > 0) {
70 if (refClass
.isInterface()) {
71 HTMLComposerImpl
.appendHeading(buf
, InspectionsBundle
.message("inspection.export.results.extended.implemented"));
74 HTMLComposerImpl
.appendHeading(buf
, InspectionsBundle
.message("inspection.export.results.extended"));
77 myComposer
.startList(buf
);
78 for (RefClass refDerived
: refClass
.getSubClasses()) {
79 myComposer
.appendListItem(buf
, refDerived
);
81 myComposer
.doneList(buf
);
85 public void appendLibraryMethods(StringBuffer buf
, RefClass refClass
) {
86 if (refClass
.getLibraryMethods().size() > 0) {
87 HTMLComposerImpl
.appendHeading(buf
, InspectionsBundle
.message("inspection.export.results.overrides.library.methods"));
89 myComposer
.startList(buf
);
90 for (RefMethod refMethod
: refClass
.getLibraryMethods()) {
91 myComposer
.appendListItem(buf
, refMethod
);
93 myComposer
.doneList(buf
);
97 public void appendSuperMethods(StringBuffer buf
, RefMethod refMethod
) {
98 if (refMethod
.getSuperMethods().size() > 0) {
99 HTMLComposer
.appendHeading(buf
, InspectionsBundle
.message("inspection.export.results.overrides.implements"));
101 myComposer
.startList(buf
);
102 for (RefMethod refSuper
: refMethod
.getSuperMethods()) {
103 myComposer
.appendListItem(buf
, refSuper
);
105 myComposer
.doneList(buf
);
109 public void appendDerivedMethods(StringBuffer buf
, RefMethod refMethod
) {
110 if (refMethod
.getDerivedMethods().size() > 0) {
111 HTMLComposer
.appendHeading(buf
, InspectionsBundle
.message("inspection.export.results.derived.methods"));
113 myComposer
.startList(buf
);
114 for (RefMethod refDerived
: refMethod
.getDerivedMethods()) {
115 myComposer
.appendListItem(buf
, refDerived
);
117 myComposer
.doneList(buf
);
121 public void appendTypeReferences(StringBuffer buf
, RefClass refClass
) {
122 if (refClass
.getInTypeReferences().size() > 0) {
123 HTMLComposer
.appendHeading(buf
, InspectionsBundle
.message("inspection.export.results.type.references"));
125 myComposer
.startList(buf
);
126 for (final RefElement refElement
: refClass
.getInTypeReferences()) {
127 myComposer
.appendListItem(buf
, refElement
);
129 myComposer
.doneList(buf
);
133 public void appendShortName(final RefEntity refElement
, final StringBuffer buf
) {
134 if (refElement
instanceof RefJavaElement
) {
135 String modifier
= ((RefJavaElement
)refElement
).getAccessModifier();
136 if (modifier
!= null && modifier
!= PsiModifier
.PACKAGE_LOCAL
) {
137 buf
.append(modifier
);
138 buf
.append(HTMLComposerImpl
.NBSP
);
141 refElement
.accept(new RefJavaVisitor() {
143 public void visitClass(RefClass refClass
) {
144 if (refClass
.isStatic()) {
145 buf
.append(InspectionsBundle
.message("inspection.export.results.static"));
146 buf
.append(HTMLComposerImpl
.NBSP
);
149 appendClassOrInterface(buf
, refClass
, false);
150 buf
.append(HTMLComposerImpl
.NBSP
).append(HTMLComposerImpl
.B_OPENING
).append(HTMLComposerImpl
.CODE_OPENING
);
151 final String name
= refClass
.getName();
152 buf
.append(refClass
.isSyntheticJSP() ? XmlStringUtil
.escapeString(name
) : name
);
153 buf
.append(HTMLComposerImpl
.CODE_CLOSING
).append(HTMLComposerImpl
.B_CLOSING
);
157 public void visitField(RefField field
) {
158 PsiField psiField
= field
.getElement();
159 if (psiField
!= null) {
160 if (field
.isStatic()) {
161 buf
.append(InspectionsBundle
.message("inspection.export.results.static"));
162 buf
.append(HTMLComposerImpl
.NBSP
);
165 buf
.append(InspectionsBundle
.message("inspection.export.results.field"));
166 buf
.append(HTMLComposerImpl
.NBSP
).append(HTMLComposerImpl
.CODE_OPENING
);
168 buf
.append(psiField
.getType().getPresentableText());
169 buf
.append(HTMLComposerImpl
.NBSP
).append(HTMLComposerImpl
.B_OPENING
);
170 buf
.append(psiField
.getName());
171 buf
.append(HTMLComposerImpl
.B_CLOSING
).append(HTMLComposerImpl
.CODE_CLOSING
);
176 public void visitMethod(RefMethod method
) {
177 PsiMethod psiMethod
= (PsiMethod
)method
.getElement();
178 if (psiMethod
!= null) {
179 PsiType returnType
= psiMethod
.getReturnType();
181 if (method
.isStatic()) {
182 buf
.append(InspectionsBundle
.message("inspection.export.results.static"));
183 buf
.append(HTMLComposerImpl
.NBSP
);
185 else if (method
.isAbstract()) {
186 buf
.append(InspectionsBundle
.message("inspection.export.results.abstract"));
187 buf
.append(HTMLComposerImpl
.NBSP
);
189 buf
.append(method
.isConstructor()
190 ? InspectionsBundle
.message("inspection.export.results.constructor")
191 : InspectionsBundle
.message("inspection.export.results.method"));
192 buf
.append(HTMLComposerImpl
.NBSP
).append(HTMLComposerImpl
.CODE_OPENING
);
194 if (returnType
!= null) {
195 buf
.append(returnType
.getPresentableText());
196 buf
.append(HTMLComposerImpl
.NBSP
);
199 buf
.append(HTMLComposerImpl
.B_OPENING
);
200 buf
.append(psiMethod
.getName());
201 buf
.append(HTMLComposerImpl
.B_CLOSING
);
202 appendMethodParameters(buf
, psiMethod
, true);
203 buf
.append(HTMLComposerImpl
.CODE_CLOSING
);
208 public void visitFile(RefFile file
) {
209 final PsiFile psiFile
= file
.getElement();
210 buf
.append(HTMLComposerImpl
.B_OPENING
);
211 buf
.append(psiFile
.getName());
212 buf
.append(HTMLComposerImpl
.B_CLOSING
);
217 public void appendLocation(final RefEntity entity
, final StringBuffer buf
) {
218 RefEntity owner
= entity
.getOwner();
219 if (owner
instanceof RefPackage
) {
220 buf
.append(InspectionsBundle
.message("inspection.export.results.package"));
221 buf
.append(HTMLComposerImpl
.NBSP
).append(HTMLComposerImpl
.CODE_OPENING
);
222 buf
.append(RefJavaUtil
.getInstance().getPackageName(entity
));
223 buf
.append(HTMLComposerImpl
.CODE_CLOSING
);
225 else if (owner
instanceof RefMethod
) {
226 buf
.append(InspectionsBundle
.message("inspection.export.results.method"));
227 buf
.append(HTMLComposerImpl
.NBSP
);
228 myComposer
.appendElementReference(buf
, (RefElement
)owner
);
230 else if (owner
instanceof RefField
) {
231 buf
.append(InspectionsBundle
.message("inspection.export.results.field"));
232 buf
.append(HTMLComposerImpl
.NBSP
);
233 myComposer
.appendElementReference(buf
, (RefElement
)owner
);
234 buf
.append(HTMLComposerImpl
.NBSP
);
235 buf
.append(InspectionsBundle
.message("inspection.export.results.initializer"));
237 else if (owner
instanceof RefClass
) {
238 appendClassOrInterface(buf
, (RefClass
)owner
, false);
239 buf
.append(HTMLComposerImpl
.NBSP
);
240 myComposer
.appendElementReference(buf
, (RefElement
)owner
);
245 public String
getQualifiedName(final RefEntity refEntity
) {
246 if (refEntity
instanceof RefJavaElement
&& ((RefJavaElement
)refEntity
).isSyntheticJSP()) {
247 return XmlStringUtil
.escapeString(refEntity
.getName());
249 else if (refEntity
instanceof RefMethod
) {
250 PsiMethod psiMethod
= (PsiMethod
)((RefMethod
)refEntity
).getElement();
251 if (psiMethod
!= null) {
252 return psiMethod
.getName();
255 return refEntity
.getName();
261 public void appendReferencePresentation(RefEntity refElement
, final StringBuffer buf
, final boolean isPackageIncluded
) {
262 if (refElement
instanceof RefImplicitConstructor
) {
263 buf
.append(InspectionsBundle
.message("inspection.export.results.implicit.constructor"));
264 refElement
= ((RefImplicitConstructor
)refElement
).getOwnerClass();
267 buf
.append(HTMLComposerImpl
.CODE_OPENING
);
269 if (refElement
instanceof RefField
) {
270 RefField field
= (RefField
)refElement
;
271 PsiField psiField
= field
.getElement();
272 buf
.append(psiField
.getType().getPresentableText());
273 buf
.append(HTMLComposerImpl
.NBSP
);
275 else if (refElement
instanceof RefMethod
) {
276 RefMethod method
= (RefMethod
)refElement
;
277 PsiMethod psiMethod
= (PsiMethod
)method
.getElement();
278 PsiType returnType
= psiMethod
.getReturnType();
280 if (returnType
!= null) {
281 buf
.append(returnType
.getPresentableText());
282 buf
.append(HTMLComposerImpl
.NBSP
);
286 buf
.append(HTMLComposerImpl
.A_HREF_OPENING
);
288 if (myComposer
.myExporter
== null) {
289 buf
.append(((RefElementImpl
)refElement
).getURL());
292 buf
.append(myComposer
.myExporter
.getURL(refElement
));
297 if (refElement
instanceof RefClass
&& ((RefClass
)refElement
).isAnonymous()) {
298 buf
.append(InspectionsBundle
.message("inspection.reference.anonymous"));
300 else if (refElement
instanceof RefJavaElement
&& ((RefJavaElement
)refElement
).isSyntheticJSP()) {
301 buf
.append(XmlStringUtil
.escapeString(refElement
.getName()));
303 else if (refElement
instanceof RefMethod
) {
304 PsiMethod psiMethod
= (PsiMethod
)((RefMethod
)refElement
).getElement();
305 buf
.append(psiMethod
.getName());
308 buf
.append(refElement
.getName());
311 buf
.append(HTMLComposerImpl
.A_CLOSING
);
313 if (refElement
instanceof RefMethod
) {
314 PsiMethod psiMethod
= (PsiMethod
)((RefMethod
)refElement
).getElement();
315 appendMethodParameters(buf
, psiMethod
, false);
318 buf
.append(HTMLComposerImpl
.CODE_CLOSING
);
320 if (refElement
instanceof RefClass
&& ((RefClass
)refElement
).isAnonymous()) {
322 buf
.append(InspectionsBundle
.message("inspection.export.results.anonymous.ref.in.owner"));
324 myComposer
.appendElementReference(buf
, ((RefElement
)refElement
.getOwner()), isPackageIncluded
);
326 else if (isPackageIncluded
) {
327 @NonNls final String color
= "color:#808080\">";
328 buf
.append(" ").append(HTMLComposerImpl
.CODE_OPENING
).append(HTMLComposerImpl
.FONT_OPENING
).append(color
).append("(");
329 myComposer
.appendQualifiedName(buf
, refElement
.getOwner());
330 // buf.append(RefUtil.getPackageName(refElement));
331 buf
.append(")").append(HTMLComposerImpl
.FONT_CLOSING
).append(HTMLComposerImpl
.CODE_CLOSING
);
335 private static void appendMethodParameters(StringBuffer buf
, PsiMethod method
, boolean showNames
) {
336 PsiParameter
[] params
= method
.getParameterList().getParameters();
338 for (int i
= 0; i
< params
.length
; i
++) {
339 if (i
!= 0) buf
.append(", ");
340 PsiParameter param
= params
[i
];
341 buf
.append(param
.getType().getPresentableText());
344 buf
.append(param
.getName());