EclipseJDT ASTViewer Source Viewer

Home|eclipse_jdt_astviewer/src/org/eclipse/jdt/astview/views/ProblemNode.java
1/*******************************************************************************
2 * Copyright (c) 2000, 2015 IBM Corporation and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 *     IBM Corporation - initial API and implementation
13 *******************************************************************************/
14package org.eclipse.jdt.astview.views;
15
16import java.lang.reflect.Field;
17import java.util.ArrayList;
18import java.util.Objects;
19
20import org.eclipse.swt.graphics.Image;
21
22import org.eclipse.jdt.core.JavaCore;
23import org.eclipse.jdt.core.compiler.CategorizedProblem;
24import org.eclipse.jdt.core.compiler.IProblem;
25
26/**
27 *
28 */
29public class ProblemNode extends ASTAttribute {
30
31    private final IProblem fProblem;
32    private final Object fParent;
33
34    public ProblemNode(Object parentIProblem problem) {
35        fParentparent;
36        fProblemproblem;
37    }
38
39    @Override
40    public Object getParent() {
41        return fParent;
42    }
43
44    @Override
45    public Object[] getChildren() {
46        String[] argumentsfProblem.getArguments();
47        ArrayList<GeneralAttributechildren= new ArrayList<>();
48
49        children.add(new GeneralAttribute(this, "CONSTANT NAME"getConstantName()));
50        children.add(new GeneralAttribute(this, "ID"getErrorLabel()));
51        children.add(new GeneralAttribute(this, "OPTION FOR CONFIGURABLE SEVERITY"JavaCore.getOptionForConfigurableSeverity(fProblem.getID())));
52        if (fProblem instanceof CategorizedProblem) {
53            children.add(new GeneralAttribute(this, "CATEGORY ID"getCategoryCode()));
54            children.add(new GeneralAttribute(this, "MARKER TYPE", ((CategorizedProblemfProblem).getMarkerType()));
55        }
56        for (int i0i < arguments.lengthi++) {
57            children.add(new GeneralAttribute(this, "ARGUMENT " + iarguments[i]));
58        }
59        return children.toArray();
60    }
61
62    @Override
63    public String getLabel() {
64        StringBuilder buf= new StringBuilder();
65        int offsetfProblem.getSourceStart();
66        int lengthfProblem.getSourceEnd() + 1 - offset;
67
68        if (fProblem.isError())
69            buf.append("E");
70        if (fProblem.isWarning())
71            buf.append("W");
72        if (fProblem.isInfo())
73            buf.append("I");
74        buf.append('[').append(offset).append(", ").append(length).append(']').append(' ');
75        buf.append(fProblem.getMessage());
76
77        return buf.toString();
78    }
79
80    private String getErrorLabel() {
81        int idfProblem.getID();
82        StringBuilder buf= new StringBuilder();
83
84        if ((id & IProblem.TypeRelated) != 0) {
85            buf.append("TypeRelated + "); //$NON-NLS-1$
86        }
87        if ((id & IProblem.FieldRelated) != 0) {
88            buf.append("FieldRelated + "); //$NON-NLS-1$
89        }
90        if ((id & IProblem.ConstructorRelated) != 0) {
91            buf.append("ConstructorRelated + "); //$NON-NLS-1$
92        }
93        if ((id & IProblem.MethodRelated) != 0) {
94            buf.append("MethodRelated + "); //$NON-NLS-1$
95        }
96        if ((id & IProblem.ImportRelated) != 0) {
97            buf.append("ImportRelated + "); //$NON-NLS-1$
98        }
99        if ((id & IProblem.Internal) != 0) {
100            buf.append("Internal + "); //$NON-NLS-1$
101        }
102        if ((id & IProblem.Syntax) != 0) {
103            buf.append("Syntax + "); //$NON-NLS-1$
104        }
105        if ((id & IProblem.Javadoc) != 0) {
106            buf.append("Javadoc + "); //$NON-NLS-1$
107        }
108        buf.append(id & IProblem.IgnoreCategoriesMask);
109
110        buf.append(" = 0x").append(Integer.toHexString(id)).append(" = ").append(id);
111
112        return buf.toString();
113    }
114
115    private String getConstantName() {
116        int idfProblem.getID();
117        for (Field f : IProblem.class.getFields()) {
118            try {
119                if (f.getType() == int.class && f.getInt(f) == id) {
120                    return "IProblem." + f.getName();
121                }
122            } catch (IllegalArgumentException | IllegalAccessException e) {
123            }
124        }
125        return "<UNKNOWN CONSTANT>";
126    }
127
128    private String getCategoryCode() {
129        CategorizedProblem categorized= (CategorizedProblemfProblem;
130        int categoryIDcategorized.getCategoryID();
131        StringBuilder buf= new StringBuilder();
132
133        switch (categoryID) {
134            case CategorizedProblem.CAT_UNSPECIFIED:
135                buf.append("Unspecified");
136                break;
137
138            case CategorizedProblem.CAT_BUILDPATH:
139                buf.append("Buildpath");
140                break;
141            case CategorizedProblem.CAT_SYNTAX:
142                buf.append("Syntax");
143                break;
144            case CategorizedProblem.CAT_IMPORT:
145                buf.append("Import");
146                break;
147            case CategorizedProblem.CAT_TYPE:
148                buf.append("Type");
149                break;
150            case CategorizedProblem.CAT_MEMBER:
151                buf.append("Member");
152                break;
153            case CategorizedProblem.CAT_INTERNAL:
154                buf.append("Internal");
155                break;
156            case CategorizedProblem.CAT_JAVADOC:
157                buf.append("Javadoc");
158                break;
159            case CategorizedProblem.CAT_CODE_STYLE:
160                buf.append("Code Style");
161                break;
162            case CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM:
163                buf.append("Potential Programming Problem");
164                break;
165            case CategorizedProblem.CAT_NAME_SHADOWING_CONFLICT:
166                buf.append("Name Shadowing Conflict");
167                break;
168            case CategorizedProblem.CAT_DEPRECATION:
169                buf.append("Deprecation");
170                break;
171            case CategorizedProblem.CAT_UNNECESSARY_CODE:
172                buf.append("Unnecessary Code");
173                break;
174            case CategorizedProblem.CAT_UNCHECKED_RAW:
175                buf.append("Unchecked Raw");
176                break;
177            case CategorizedProblem.CAT_NLS:
178                buf.append("NLS");
179                break;
180            case CategorizedProblem.CAT_RESTRICTION:
181                buf.append("Restriction");
182                break;
183            case CategorizedProblem.CAT_MODULE:
184                buf.append("Module");
185                break;
186            default:
187                buf.append("<UNKNOWN CATEGORY>");
188                break;
189        }
190
191        buf.append(" = ").append(categoryID);
192
193        return buf.toString();
194    }
195
196    @Override
197    public Image getImage() {
198        return null;
199    }
200
201    /**
202     * @return Returns the offset of the problem
203     */
204    public int getOffset() {
205        return fProblem.getSourceStart();
206    }
207
208    /**
209     * @return Returns the length of the problem
210     */
211    public int getLength() {
212        return fProblem.getSourceEnd() + 1 - fProblem.getSourceStart();
213    }
214
215    /*
216     * @see java.lang.Object#equals(java.lang.Object)
217     */
218    @Override
219    public boolean equals(Object obj) {
220        if (this == obj)
221            return true;
222        if (obj == null || !obj.getClass().equals(getClass())) {
223            return false;
224        }
225
226        ProblemNode other= (ProblemNodeobj;
227        if (!Objects.equals(fParentother.fParent)) {
228            return false;
229        }
230
231        if (!Objects.equals(fProblemother.fProblem)) {
232            return false;
233        }
234
235        return true;
236    }
237
238    /*
239     * @see java.lang.Object#hashCode()
240     */
241    @Override
242    public int hashCode() {
243        return (fParent != null ? fParent.hashCode() : 0) + (fProblem != null ? fProblem.hashCode() : 0);
244    }
245}
246
MembersX
ProblemNode:equals:Block:other
ProblemNode:getOffset
ProblemNode:getChildren
ProblemNode:getLabel
ProblemNode:ProblemNode
ProblemNode:getLength
ProblemNode:getChildren:Block:children
ProblemNode:getCategoryCode:Block:buf
ProblemNode:getConstantName
ProblemNode:fParent
ProblemNode:getConstantName:Block:id
ProblemNode:fProblem
ProblemNode:getCategoryCode
ProblemNode:getCategoryCode:Block:categorized
ProblemNode:getErrorLabel
ProblemNode:getLabel:Block:buf
ProblemNode:getErrorLabel:Block:id
ProblemNode:getLabel:Block:offset
ProblemNode:getCategoryCode:Block:categoryID
ProblemNode:getParent
ProblemNode:hashCode
ProblemNode:getImage
ProblemNode:getChildren:Block:arguments
ProblemNode:getErrorLabel:Block:buf
ProblemNode:equals
ProblemNode:getLabel:Block:length
Members
X