Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Vogel2021-02-08 12:52:08 +0000
committerAndrey Loskutov2021-02-11 13:57:36 +0000
commit1256b8ec4c0ff791d33f292e6f171848e670db26 (patch)
tree0cacea153ef48f4ba12b20e970eb8b040eef31a2 /org.eclipse.jdt.core
parentd890922f01a874dd5cafce5db8dfb5bae47b2f3c (diff)
downloadeclipse.jdt.core-1256b8ec4c0ff791d33f292e6f171848e670db26.tar.gz
eclipse.jdt.core-1256b8ec4c0ff791d33f292e6f171848e670db26.tar.xz
eclipse.jdt.core-1256b8ec4c0ff791d33f292e6f171848e670db26.zip
Bug 571017 - Use atomic marker creation API in AbstractImageBuilder
The new marker API from Bug 570914 allows to create markers with attributes and therefore avoids sending out resource change events for every attribute change. JDT core dependencies have already increased the minimum required resource API version in a previous commit. Change-Id: I0d3565990a7f70bcec226d8ee5211c593c3bb30a Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
Diffstat (limited to 'org.eclipse.jdt.core')
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java135
1 files changed, 61 insertions, 74 deletions
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java
index 5bc904460b..6ce54d3049 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -65,25 +65,16 @@ protected Set<SourceFile> filesWithAnnotations = null;
//2000 is best compromise between space used and speed
public static int MAX_AT_ONCE = Integer.getInteger(JavaModelManager.MAX_COMPILED_UNITS_AT_ONCE, 2000).intValue();
public final static String[] JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES = {
- IMarker.MESSAGE,
- IMarker.SEVERITY,
- IJavaModelMarker.ID,
- IMarker.CHAR_START,
- IMarker.CHAR_END,
- IMarker.LINE_NUMBER,
- IJavaModelMarker.ARGUMENTS,
- IJavaModelMarker.CATEGORY_ID,
-};
-public final static String[] JAVA_TASK_MARKER_ATTRIBUTE_NAMES = {
- IMarker.MESSAGE,
- IMarker.PRIORITY,
- IJavaModelMarker.ID,
- IMarker.CHAR_START,
- IMarker.CHAR_END,
- IMarker.LINE_NUMBER,
- IMarker.USER_EDITABLE,
- IMarker.SOURCE_ID,
-};
+ IMarker.MESSAGE,
+ IMarker.SEVERITY,
+ IJavaModelMarker.ID,
+ IMarker.CHAR_START,
+ IMarker.CHAR_END,
+ IMarker.LINE_NUMBER,
+ IJavaModelMarker.ARGUMENTS,
+ IJavaModelMarker.CATEGORY_ID,
+ };
+
public final static Integer S_ERROR = Integer.valueOf(IMarker.SEVERITY_ERROR);
public final static Integer S_WARNING = Integer.valueOf(IMarker.SEVERITY_WARNING);
public final static Integer S_INFO = Integer.valueOf(IMarker.SEVERITY_INFO);
@@ -763,41 +754,42 @@ protected void storeProblemsFor(SourceFile sourceFile, CategorizedProblem[] prob
}
}
}
- IMarker marker = resource.createMarker(markerType);
- String[] attributeNames = JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES;
- int standardLength = attributeNames.length;
- String[] allNames = attributeNames;
- int managedLength = managedProblem ? 0 : 1;
+ int attributesLength = JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES.length;
+ if (!managedProblem) {
+ attributesLength++;
+ }
+ // optional extra attributes
String[] extraAttributeNames = problem.getExtraMarkerAttributeNames();
- int extraLength = extraAttributeNames == null ? 0 : extraAttributeNames.length;
- if (managedLength > 0 || extraLength > 0) {
- allNames = new String[standardLength + managedLength + extraLength];
- System.arraycopy(attributeNames, 0, allNames, 0, standardLength);
- if (managedLength > 0)
- allNames[standardLength] = IMarker.SOURCE_ID;
- System.arraycopy(extraAttributeNames, 0, allNames, standardLength + managedLength, extraLength);
+ Object[] extraAttributeValues = problem.getExtraMarkerAttributeValues();
+ boolean extraAttributesExist = false;
+ if (extraAttributeNames != null && extraAttributeValues != null
+ && extraAttributeNames.length == extraAttributeValues.length) {
+ attributesLength += extraAttributeNames.length;
+ extraAttributesExist = true;
}
- Object[] allValues = new Object[allNames.length];
- // standard attributes
- int index = 0;
- allValues[index++] = problem.getMessage(); // message
- allValues[index++] = problem.isError() ? S_ERROR : problem.isWarning() ? S_WARNING : S_INFO; // severity
- allValues[index++] = Integer.valueOf(id); // ID
- allValues[index++] = Integer.valueOf(problem.getSourceStart()); // start
- allValues[index++] = Integer.valueOf(problem.getSourceEnd() + 1); // end
- allValues[index++] = Integer.valueOf(problem.getSourceLineNumber()); // line
- allValues[index++] = Util.getProblemArgumentsForMarker(problem.getArguments()); // arguments
- allValues[index++] = Integer.valueOf(problem.getCategoryID()); // category ID
+ Map<String, Object> attributes = new HashMap<>(attributesLength, 1.0f);
+ attributes.put(JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES[0], problem.getMessage()); //MESSAGE
+ attributes.put(JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES[1], problem.isError() ? S_ERROR : problem.isWarning() ? S_WARNING : S_INFO);//SEVERITY
+ attributes.put(JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES[2], Integer.valueOf(id));//ID
+ attributes.put(JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES[3], Integer.valueOf(problem.getSourceStart()));//CHAR_START
+ attributes.put(JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES[4], Integer.valueOf(problem.getSourceEnd() + 1));//CHAR_END,
+ attributes.put(JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES[5], Integer.valueOf(problem.getSourceLineNumber()));//LINE_NUMBER
+ attributes.put(JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES[6], Util.getProblemArgumentsForMarker(problem.getArguments()));//ARGUMENTS
+ attributes.put(JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES[7], Integer.valueOf(problem.getCategoryID()));//CATEGORY_ID
+
// SOURCE_ID attribute for JDT problems
- if (managedLength > 0)
- allValues[index++] = JavaBuilder.SOURCE_ID;
- // optional extra attributes
- if (extraLength > 0)
- System.arraycopy(problem.getExtraMarkerAttributeValues(), 0, allValues, index, extraLength);
+ if (!managedProblem) {
+ attributes.put(IMarker.SOURCE_ID, JavaBuilder.SOURCE_ID);
+ }
- marker.setAttributes(allNames, allValues);
+ if (extraAttributesExist) {
+ for (int j = 0; j < extraAttributeNames.length; j++) {
+ attributes.put(extraAttributeNames[j], extraAttributeValues[j]);
+ }
+ }
+ resource.createMarker(markerType, attributes);
if (!this.keepStoringProblemMarkers) return; // only want the one error recorded on this source file
}
@@ -811,7 +803,6 @@ protected void storeTasksFor(SourceFile sourceFile, CategorizedProblem[] tasks)
for (int i = 0, l = tasks.length; i < l; i++) {
CategorizedProblem task = tasks[i];
if (task.getID() == IProblem.Task) {
- IMarker marker = resource.createMarker(IJavaModelMarker.TASK_MARKER);
Integer priority = P_NORMAL;
String compilerPriority = task.getArguments()[2];
if (JavaCore.COMPILER_TASK_PRIORITY_HIGH.equals(compilerPriority))
@@ -819,33 +810,29 @@ protected void storeTasksFor(SourceFile sourceFile, CategorizedProblem[] tasks)
else if (JavaCore.COMPILER_TASK_PRIORITY_LOW.equals(compilerPriority))
priority = P_LOW;
- String[] attributeNames = JAVA_TASK_MARKER_ATTRIBUTE_NAMES;
- int standardLength = attributeNames.length;
- String[] allNames = attributeNames;
- String[] extraAttributeNames = task.getExtraMarkerAttributeNames();
- int extraLength = extraAttributeNames == null ? 0 : extraAttributeNames.length;
- if (extraLength > 0) {
- allNames = new String[standardLength + extraLength];
- System.arraycopy(attributeNames, 0, allNames, 0, standardLength);
- System.arraycopy(extraAttributeNames, 0, allNames, standardLength, extraLength);
- }
-
- Object[] allValues = new Object[allNames.length];
// standard attributes
- int index = 0;
- allValues[index++] = task.getMessage();
- allValues[index++] = priority;
- allValues[index++] = Integer.valueOf(task.getID());
- allValues[index++] = Integer.valueOf(task.getSourceStart());
- allValues[index++] = Integer.valueOf(task.getSourceEnd() + 1);
- allValues[index++] = Integer.valueOf(task.getSourceLineNumber());
- allValues[index++] = Boolean.FALSE;
- allValues[index++] = JavaBuilder.SOURCE_ID;
+ Map<String, Object> attributes = new HashMap<>();
+
+ attributes.put(IMarker.MESSAGE, task.getMessage());
+ attributes.put(IMarker.PRIORITY, priority);
+ attributes.put(IJavaModelMarker.ID, Integer.valueOf(task.getID()));
+ attributes.put(IMarker.CHAR_START, Integer.valueOf(task.getSourceStart()));
+ attributes.put(IMarker.CHAR_END, Integer.valueOf(task.getSourceEnd() + 1));
+ attributes.put(IMarker.LINE_NUMBER, Integer.valueOf(task.getSourceLineNumber()));
+ attributes.put(IMarker.USER_EDITABLE, Boolean.FALSE);
+ attributes.put(IMarker.SOURCE_ID, JavaBuilder.SOURCE_ID);
+
// optional extra attributes
- if (extraLength > 0)
- System.arraycopy(task.getExtraMarkerAttributeValues(), 0, allValues, index, extraLength);
+ String[] extraAttributeNames = task.getExtraMarkerAttributeNames();
+ Object[] extraAttributeValues = task.getExtraMarkerAttributeValues();
+ if (extraAttributeNames != null && extraAttributeValues != null
+ && extraAttributeNames.length == extraAttributeValues.length) {
+ for (int j = 0; j < extraAttributeNames.length; j++) {
+ attributes.put(extraAttributeNames[j], extraAttributeValues[j]);
+ }
+ }
- marker.setAttributes(allNames, allValues);
+ resource.createMarker(IJavaModelMarker.TASK_MARKER, attributes);
}
}
}

Back to the top