Author: scabanovich
Date: 2012-04-27 17:35:32 -0400 (Fri, 27 Apr 2012)
New Revision: 40587
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ELReference.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELInstanceImpl.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELModelImpl.java
Log:
JBIDE-11682
https://issues.jboss.org/browse/JBIDE-11682
Do not create empty arrays/lists/maps
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ELReference.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ELReference.java 2012-04-27
21:18:39 UTC (rev 40586)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ELReference.java 2012-04-27
21:35:32 UTC (rev 40587)
@@ -46,7 +46,6 @@
private int startPosition;
private ELExpression[] el;
private Set<IMarker> markers;
- private IMarker[] markerArray;
private boolean needToInitMarkers = false;
private List<SyntaxError> syntaxErrors;
private String source;
@@ -201,25 +200,22 @@
private static final IMarker[] EMPTY_MARKER_ARRAY = new IMarker[0];
private void initMarkers() {
- if(markers==null) {
- markers = new HashSet<IMarker>();
- if(needToInitMarkers) {
- IFile file = getResource();
- if(file!=null) {
- IMarker[] markers = null;
- try {
- markers = file.findMarkers(null, true, IResource.DEPTH_INFINITE);
- } catch (CoreException e) {
- ELCorePlugin.getDefault().logError(e);
- }
- for(int i=0; i<markers.length; i++){
- String groupName = markers[i].getAttribute("groupName", null);
//$NON-NLS-1$
- if(groupName!=null && (groupName.equals(this.elMarkerGroupID))) {
- int start = markers[i].getAttribute(IMarker.CHAR_START, -1);
- int end = markers[i].getAttribute(IMarker.CHAR_END, -1);
- if(start>=startPosition && end<=startPosition+length) {
- addMarker(markers[i]);
- }
+ if(markers == null && needToInitMarkers) {
+ IFile file = getResource();
+ if(file!=null) {
+ IMarker[] markers = null;
+ try {
+ markers = file.findMarkers(null, true, IResource.DEPTH_INFINITE);
+ } catch (CoreException e) {
+ ELCorePlugin.getDefault().logError(e);
+ }
+ for(int i=0; i<markers.length; i++){
+ String groupName = markers[i].getAttribute("groupName", null);
//$NON-NLS-1$
+ if(groupName!=null && (groupName.equals(this.elMarkerGroupID))) {
+ int start = markers[i].getAttribute(IMarker.CHAR_START, -1);
+ int end = markers[i].getAttribute(IMarker.CHAR_END, -1);
+ if(start>=startPosition && end<=startPosition+length) {
+ addMarker(markers[i]);
}
}
}
@@ -253,53 +249,31 @@
this.needToInitMarkers = needToInitMarkers;
}
- public synchronized void setMarkers(Set<IMarker> markers) {
- this.markers = markers;
- }
-
/**
- * @return the markers
- */
- public synchronized IMarker[] getMarkers() {
- initMarkers();
- if(markerArray==null) {
- if(markers.isEmpty()) {
- markerArray = EMPTY_MARKER_ARRAY;
- } else {
- markerArray = markers.toArray(new IMarker[markers.size()]);
- }
- }
- return markerArray;
- }
-
- /**
* @param markers the markers to set
*/
public synchronized void addMarker(IMarker marker) {
if(marker==null) {
return;
}
- markerArray = null;
if(markers==null) {
markers = new HashSet<IMarker>();
}
markers.add(marker);
}
- public boolean hasMarkers() {
- return !markers.isEmpty();
- }
-
/**
* Removes all markers from this EL.
*/
public void deleteMarkers() {
- IMarker[] aMarkers = null;
+ Set<IMarker> aMarkers = null;
synchronized (this) {
initMarkers();
- aMarkers = getMarkers();
- markers.clear();
- markerArray = null;
+ if(markers == null) {
+ return;
+ }
+ aMarkers = markers;
+ markers = null;
}
for (IMarker marker : aMarkers) {
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELInstanceImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELInstanceImpl.java 2012-04-27
21:18:39 UTC (rev 40586)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELInstanceImpl.java 2012-04-27
21:35:32 UTC (rev 40587)
@@ -11,6 +11,7 @@
package org.jboss.tools.common.el.internal.core.model;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.jboss.tools.common.el.core.model.ELExpression;
@@ -26,8 +27,10 @@
* @author V. Kabanovich
*/
public class ELInstanceImpl extends ELObjectImpl implements ELInstance {
+ public static final List<SyntaxError> EMPTY = Collections.unmodifiableList(new
ArrayList<SyntaxError>());
+
ELExpressionImpl expression;
- List<SyntaxError> errors = new ArrayList<SyntaxError>();
+ List<SyntaxError> errors = null;
public ELInstanceImpl() {
}
@@ -55,7 +58,7 @@
}
public List<SyntaxError> getErrors() {
- return errors;
+ return errors != null ? errors : EMPTY;
}
public void addChild(ELObjectImpl child) {
@@ -108,6 +111,9 @@
}
public void addError(SyntaxError error) {
+ if(errors == null) {
+ errors = new ArrayList<SyntaxError>();
+ }
errors.add(error);
}
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELModelImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELModelImpl.java 2012-04-27
21:18:39 UTC (rev 40586)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELModelImpl.java 2012-04-27
21:35:32 UTC (rev 40587)
@@ -73,7 +73,7 @@
}
public void setErrors(List<SyntaxError> errors) {
- this.errors = errors;
+ this.errors = errors.isEmpty() ? null : errors;
for (SyntaxError e: errors) {
for (ELInstance i: instances) {
ELInstanceImpl im = (ELInstanceImpl)i;
@@ -87,7 +87,7 @@
}
public List<SyntaxError> getSyntaxErrors() {
- return errors;
+ return errors == null ? ELInstanceImpl.EMPTY : errors;
}
public void shift(int delta) {