1 11 package org.eclipse.jdt.internal.ui.text.correction; 12 13 import org.eclipse.jdt.core.IJavaModelMarker; 14 import org.eclipse.jdt.core.compiler.CategorizedProblem; 15 import org.eclipse.jdt.core.compiler.IProblem; 16 import org.eclipse.jdt.core.dom.ASTNode; 17 import org.eclipse.jdt.core.dom.CompilationUnit; 18 19 import org.eclipse.jdt.ui.text.java.*; 20 21 import org.eclipse.jdt.internal.corext.dom.NodeFinder; 22 import org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation; 23 import org.eclipse.jdt.internal.ui.javaeditor.JavaMarkerAnnotation; 24 25 28 public class ProblemLocation implements IProblemLocation { 29 30 private final int fId; 31 private final String [] fArguments; 32 private final int fOffset; 33 private final int fLength; 34 private final boolean fIsError; 35 private final String fMarkerType; 36 37 public ProblemLocation(int offset, int length, IJavaAnnotation annotation) { 38 fId= annotation.getId(); 39 fArguments= annotation.getArguments(); 40 fOffset= offset; 41 fLength= length; 42 fIsError= JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(annotation.getType()); 43 44 String markerType= annotation.getMarkerType(); 45 fMarkerType= markerType != null ? markerType : IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER; 46 } 47 48 public ProblemLocation(int offset, int length, int id, String [] arguments, boolean isError, String markerType) { 49 fId= id; 50 fArguments= arguments; 51 fOffset= offset; 52 fLength= length; 53 fIsError= isError; 54 fMarkerType= markerType; 55 } 56 57 public ProblemLocation(IProblem problem) { 58 fId= problem.getID(); 59 fArguments= problem.getArguments(); 60 fOffset= problem.getSourceStart(); 61 fLength= problem.getSourceEnd() - fOffset + 1; 62 fIsError= problem.isError(); 63 fMarkerType= problem instanceof CategorizedProblem ? ((CategorizedProblem) problem).getMarkerType() : IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER; 64 } 65 66 67 70 public int getProblemId() { 71 return fId; 72 } 73 74 77 public String [] getProblemArguments() { 78 return fArguments; 79 } 80 81 84 public int getLength() { 85 return fLength; 86 } 87 88 91 public int getOffset() { 92 return fOffset; 93 } 94 95 98 public boolean isError() { 99 return fIsError; 100 } 101 102 105 public String getMarkerType() { 106 return fMarkerType; 107 } 108 109 113 public ASTNode getCoveringNode(CompilationUnit astRoot) { 114 NodeFinder finder= new NodeFinder(fOffset, fLength); 115 astRoot.accept(finder); 116 return finder.getCoveringNode(); 117 } 118 119 123 public ASTNode getCoveredNode(CompilationUnit astRoot) { 124 NodeFinder finder= new NodeFinder(fOffset, fLength); 125 astRoot.accept(finder); 126 return finder.getCoveredNode(); 127 } 128 129 public String toString() { 130 StringBuffer buf= new StringBuffer (); 131 buf.append("Id: ").append(getErrorCode(fId)).append('\n'); buf.append('[').append(fOffset).append(", ").append(fLength).append(']').append('\n'); String [] arg= fArguments; 134 if (arg != null) { 135 for (int i= 0; i < arg.length; i++) { 136 buf.append(arg[i]); 137 buf.append('\n'); 138 } 139 } 140 return buf.toString(); 141 } 142 143 private String getErrorCode(int code) { 144 StringBuffer buf= new StringBuffer (); 145 146 if ((code & IProblem.TypeRelated) != 0) { 147 buf.append("TypeRelated + "); } 149 if ((code & IProblem.FieldRelated) != 0) { 150 buf.append("FieldRelated + "); } 152 if ((code & IProblem.ConstructorRelated) != 0) { 153 buf.append("ConstructorRelated + "); } 155 if ((code & IProblem.MethodRelated) != 0) { 156 buf.append("MethodRelated + "); } 158 if ((code & IProblem.ImportRelated) != 0) { 159 buf.append("ImportRelated + "); } 161 if ((code & IProblem.Internal) != 0) { 162 buf.append("Internal + "); } 164 if ((code & IProblem.Syntax) != 0) { 165 buf.append("Syntax + "); } 167 if ((code & IProblem.Javadoc) != 0) { 168 buf.append("Javadoc + "); } 170 buf.append(code & IProblem.IgnoreCategoriesMask); 171 172 return buf.toString(); 173 } 174 175 176 } 177 | Popular Tags |