1 11 12 package org.eclipse.ant.internal.ui.model; 13 14 import org.eclipse.ant.internal.ui.AntUIPlugin; 15 import org.eclipse.ant.internal.ui.preferences.AntEditorPreferenceConstants; 16 import org.eclipse.jface.preference.IPreferenceStore; 17 import org.eclipse.jface.text.Region; 18 19 public class AntModelProblem extends Region implements IProblem { 20 21 public static final int NO_PROBLEM= -1; 22 public static final int SEVERITY_WARNING= 0; 23 public static final int SEVERITY_ERROR= 1; 24 public static final int SEVERITY_FATAL_ERROR= 2; 25 26 private String fMessage; 27 private String fEscapedMessage; 28 private int fSeverity; 29 private int fAdjustedLength= -1; 30 private int fLineNumber= -1; 31 32 public AntModelProblem(String message, int severity, int offset, int length, int lineNumber) { 33 super(offset, length); 34 fMessage= message; 35 fEscapedMessage= getEscaped(message); 36 fSeverity= severity; 37 fLineNumber= lineNumber; 38 } 39 40 43 public String getMessage() { 44 return fEscapedMessage; 45 } 46 47 50 public boolean isError() { 51 return fSeverity == SEVERITY_ERROR || fSeverity == SEVERITY_FATAL_ERROR; 52 } 53 54 57 public boolean isWarning() { 58 return fSeverity == SEVERITY_WARNING; 59 } 60 61 64 public int getLength() { 65 if (fAdjustedLength != -1) { 66 return fAdjustedLength; 67 } 68 return super.getLength(); 69 } 70 71 74 public void setLength(int adjustedLength) { 75 fAdjustedLength= adjustedLength; 76 } 77 78 81 public int getLineNumber() { 82 return fLineNumber; 83 } 84 85 private void appendEscapedChar(StringBuffer buffer, char c) { 86 String replacement= getReplacement(c); 87 if (replacement != null) { 88 buffer.append(replacement); 89 } else { 90 buffer.append(c); 91 } 92 } 93 94 private String getEscaped(String s) { 95 StringBuffer result= new StringBuffer (s.length() + 10); 96 for (int i= 0; i < s.length(); ++i) { 97 appendEscapedChar(result, s.charAt(i)); 98 } 99 return result.toString(); 100 } 101 102 private String getReplacement(char c) { 103 switch (c) { 107 case '<' : 108 return "<"; case '>' : 110 return ">"; case '"' : 112 return """; case '&' : 114 return "&"; } 116 return null; 117 } 118 119 122 public String getUnmodifiedMessage() { 123 return fMessage; 124 } 125 126 public static int getSeverity(String preferenceKey) { 127 IPreferenceStore store= AntUIPlugin.getDefault().getPreferenceStore(); 128 String severityLevel= store.getString(preferenceKey); 129 if (severityLevel.length() == 0 || severityLevel.equals(AntEditorPreferenceConstants.BUILDFILE_ERROR)) { 130 return SEVERITY_ERROR; 131 } else if (severityLevel.equals(AntEditorPreferenceConstants.BUILDFILE_WARNING)) { 132 return SEVERITY_WARNING; 133 } else { 134 return NO_PROBLEM; 135 } 136 } 137 138 141 public boolean equals(Object o) { 142 boolean equal= super.equals(o); 143 if (equal) { 144 return ((AntModelProblem)o).getUnmodifiedMessage().equals(getUnmodifiedMessage()); 145 } 146 return false; 147 } 148 } 149 | Popular Tags |