Lines 43-49
Link Here
|
43 |
*/ |
43 |
*/ |
44 |
package org.netbeans.spi.editor.hints; |
44 |
package org.netbeans.spi.editor.hints; |
45 |
|
45 |
|
|
|
46 |
import java.util.ArrayList; |
46 |
import java.util.List; |
47 |
import java.util.List; |
|
|
48 |
import java.util.logging.Level; |
49 |
import java.util.logging.Logger; |
47 |
import javax.swing.text.Document; |
50 |
import javax.swing.text.Document; |
48 |
import javax.swing.text.Position; |
51 |
import javax.swing.text.Position; |
49 |
import org.netbeans.api.annotations.common.NonNull; |
52 |
import org.netbeans.api.annotations.common.NonNull; |
Lines 267-272
Link Here
|
267 |
return new ErrorDescription(file, id, description, details, severity, fixes, HintsControllerImpl.linePart(file, start, end)); |
270 |
return new ErrorDescription(file, id, description, details, severity, fixes, HintsControllerImpl.linePart(file, start, end)); |
268 |
} |
271 |
} |
269 |
|
272 |
|
|
|
273 |
/**Create a new {@link ErrorDescription} with the given parameters. |
274 |
* |
275 |
* Should be called inside document read lock to assure consistency |
276 |
* |
277 |
* @param id an optional ID of the {@link ErrorDescription}. Should represent a "type" of an error/warning. |
278 |
* It is recommended that providers prefix the ID with their unique prefix. |
279 |
* @param severity the desired {@link Severity} |
280 |
* @param customType |
281 |
* @param description the text of the error/warning |
282 |
* @param details optional "more details" describing the error/warning |
283 |
* @param fixes a collection of {@link Fix}es that should be shown for the error/warning |
284 |
* @param file for which the {@link ErrorDescription} should be created |
285 |
* @param starts the array of start offsets for error/warning |
286 |
* @param ends the array of end offsets for error/warning |
287 |
* @return a newly created {@link ErrorDescription} based on the given parameters |
288 |
* @since 1.42 |
289 |
*/ |
290 |
public static @NonNull ErrorDescription createErrorDescription(@NullAllowed String id, @NonNull Severity severity, |
291 |
@NullAllowed String customType, @NonNull String description, @NullAllowed CharSequence details, @NonNull LazyFixList fixes, |
292 |
@NonNull FileObject file, int[] starts, int[] ends) { |
293 |
Parameters.notNull("severity", severity); |
294 |
Parameters.notNull("description", description); |
295 |
Parameters.notNull("fixes", fixes); |
296 |
Parameters.notNull("file", file); |
297 |
if (starts == null || starts.length == 0 || starts[0] < 0) throw new IndexOutOfBoundsException("start < 0 (" + starts + " < 0)");;//NOI18N |
298 |
if (ends == null || ends.length == 0 || ends[0] < 0) throw new IndexOutOfBoundsException("end < 0 (" + ends + " < 0)");;//NOI18N |
299 |
if (ends.length != starts.length) throw new IndexOutOfBoundsException("starts lentgh:" + starts.length + " != " + ends.length + " ends length");//NOI18N |
300 |
PositionBounds span = HintsControllerImpl.linePart(file, starts[0], ends[0]); |
301 |
ArrayList<PositionBounds> spanTail = new ArrayList<>(); |
302 |
if (starts.length > 1) { |
303 |
for (int i = 1; i < starts.length; i++) { |
304 |
//just skip if starts greater or equals to end |
305 |
if (starts[i] >= ends[i]) { |
306 |
//log and continue |
307 |
Logger.getLogger(ErrorDescriptionFactory.class.getName()).log(Level.INFO, "Incorrect span, start=" + starts[i] + ", end=" + ends[i], new Exception());;//NOI18N |
308 |
continue; |
309 |
} |
310 |
spanTail.add(HintsControllerImpl.linePart(file, starts[i], ends[i])); |
311 |
} |
312 |
} |
313 |
return new ErrorDescription(file, id, description, details, severity, customType, fixes, span, spanTail); |
314 |
} |
315 |
|
270 |
/**Create a new {@link ErrorDescription} with the given parameters. |
316 |
/**Create a new {@link ErrorDescription} with the given parameters. |
271 |
* |
317 |
* |
272 |
* @param id an optional ID of the {@link ErrorDescription}. Should represent a "type" of an error/warning. |
318 |
* @param id an optional ID of the {@link ErrorDescription}. Should represent a "type" of an error/warning. |
Lines 316-321
Link Here
|
316 |
|
362 |
|
317 |
return new ErrorDescription(file, id, description, details, severity, customType, new StaticFixList(fixes), HintsControllerImpl.linePart(doc, start, end)); |
363 |
return new ErrorDescription(file, id, description, details, severity, customType, new StaticFixList(fixes), HintsControllerImpl.linePart(doc, start, end)); |
318 |
} |
364 |
} |
|
|
365 |
|
366 |
/**Create a new {@link ErrorDescription} with the given parameters. |
367 |
* |
368 |
* @param id an optional ID of the {@link ErrorDescription}. Should represent a "type" of an error/warning. |
369 |
* It is recommended that providers prefix the ID with their unique prefix. |
370 |
* @param severity the desired {@link Severity} |
371 |
* @param customType custom annotation type |
372 |
* @param description the text of the error/warning |
373 |
* @param details optional "more details" describing the error/warning |
374 |
* @param fixes a collection of {@link Fix}es that should be shown for the error/warning |
375 |
* @param doc document for which the {@link ErrorDescription} should be created |
376 |
* @param starts the array of start offsets for error/warning |
377 |
* @param ends the array of end offsets for error/warning |
378 |
* @return a newly created {@link ErrorDescription} based on the given parameters |
379 |
* @since 1.42 |
380 |
*/ |
381 |
public static @NonNull ErrorDescription createErrorDescription(@NullAllowed String id, @NonNull Severity severity, |
382 |
@NullAllowed String customType, @NonNull String description, @NullAllowed CharSequence details, @NonNull List<Fix> fixes, |
383 |
@NonNull Document doc, int[] starts, int[] ends) { |
384 |
Parameters.notNull("severity", severity); |
385 |
Parameters.notNull("description", description); |
386 |
Parameters.notNull("fixes", fixes); |
387 |
Parameters.notNull("doc", doc); |
388 |
DataObject od = (DataObject) doc.getProperty(Document.StreamDescriptionProperty); |
389 |
FileObject file = od != null ? od.getPrimaryFile() : null; |
390 |
if (starts == null || starts.length == 0 || starts[0] < 0) throw new IndexOutOfBoundsException("start < 0 (" + starts + " < 0)");;//NOI18N |
391 |
if (ends == null || ends.length == 0 || ends[0] < 0) throw new IndexOutOfBoundsException("end < 0 (" + ends + " < 0)");;//NOI18N |
392 |
if (ends.length != starts.length) throw new IndexOutOfBoundsException("starts lentgh:" + starts.length + " != " + ends.length + " ends length");//NOI18N |
393 |
PositionBounds span = HintsControllerImpl.linePart(file, starts[0], ends[0]); |
394 |
ArrayList<PositionBounds> spanTail = new ArrayList<>(); |
395 |
if (starts.length > 1) { |
396 |
for (int i = 1; i < starts.length; i++) { |
397 |
//just skip if starts greater or equals to end |
398 |
if (starts[i] >= ends[i]) { |
399 |
//log and continue |
400 |
Logger.getLogger(ErrorDescriptionFactory.class.getName()).log(Level.INFO, "Incorrect span, start=" + starts[i] + ", end=" + ends[i], new Exception());;//NOI18N |
401 |
continue; |
402 |
} |
403 |
spanTail.add(HintsControllerImpl.linePart(file, starts[i], ends[i])); |
404 |
} |
405 |
} |
406 |
return new ErrorDescription(file, id, description, details, severity, customType, new StaticFixList(fixes), |
407 |
span, spanTail); |
408 |
} |
319 |
|
409 |
|
320 |
/** |
410 |
/** |
321 |
* Converts "normal" list of {@link Fix}es into {@link LazyFixList} |
411 |
* Converts "normal" list of {@link Fix}es into {@link LazyFixList} |