summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMickael Istria2013-08-28 11:56:10 (EDT)
committer Gerrit Code Review @ Eclipse.org2013-09-13 13:43:20 (EDT)
commit80821c74f0c08ee22b621c398e737860e3ed13c6 (patch)
tree2f7c4e3a03d3db8e5fec33fca8f66fd120b406e0
parent8c9793946e4604da4832b71ed6150358f5f4498e (diff)
downloadeclipse.platform.ui-80821c74f0c08ee22b621c398e737860e3ed13c6.zip
eclipse.platform.ui-80821c74f0c08ee22b621c398e737860e3ed13c6.tar.gz
eclipse.platform.ui-80821c74f0c08ee22b621c398e737860e3ed13c6.tar.bz2
* Some hashCode added * Some single-case switch blocks replaced by if * Some stronger typing on some generics Signed-off-by: Mickael Istria <mistria@redhat.com> Change-Id: Ia3eb5a99f6ad90daa7cce51a9b2fc0c619bb298e
-rw-r--r--bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2ColorHelper.java41
-rw-r--r--bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/ExtendedDocumentCSS.java16
-rw-r--r--bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/DocumentCSSImpl.java40
-rw-r--r--bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/MediaListImpl.java13
-rw-r--r--bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/StyleWrapper.java8
-rw-r--r--bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/ViewCSSImpl.java10
-rw-r--r--bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/serializers/CSSSerializer.java69
7 files changed, 83 insertions, 114 deletions
diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2ColorHelper.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2ColorHelper.java
index 6a6a0d0..8d29847 100644
--- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2ColorHelper.java
+++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2ColorHelper.java
@@ -11,9 +11,8 @@
package org.eclipse.e4.ui.css.core.css2;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
-
+import java.util.Map.Entry;
import org.eclipse.e4.ui.css.core.dom.properties.converters.ICSSValueConverterColorConfig;
import org.eclipse.e4.ui.css.core.dom.properties.converters.ICSSValueConverterConfig;
import org.w3c.dom.css.CSSPrimitiveValue;
@@ -21,27 +20,27 @@ import org.w3c.dom.css.RGBColor;
/**
* CSS2 Color Helper.
- *
+ *
* @version 1.0.0
* @author <a href="mailto:angelo.zerr@gmail.com">Angelo ZERR</a>
- *
+ *
*/
public class CSS2ColorHelper {
/**
* Map with key=color name and value=hexadecimal color.
*/
- private static Map colorNamesMap = new HashMap();;
+ private static Map<String, String> colorNamesMap = new HashMap<String, String>();
/**
* Map with key=hexadecimal color and value=color name.
*/
- private static Map colorHexasMap = new HashMap();;
+ private static Map<String, String> colorHexasMap = new HashMap<String, String>();
/**
* Return w3c {@link RGBColor} from string value. Format String value is
* hexadecimal like #FFFFFF or color name like white.
- *
+ *
* @param value
* @return
*/
@@ -49,12 +48,9 @@ public class CSS2ColorHelper {
if (value.startsWith("#") && value.length() == 7) {
// Color is like #FFFFFF
try {
- int redValue = Integer.decode("0x" + value.substring(1, 3))
- .intValue();
- int greenValue = Integer.decode("0x" + value.substring(3, 5))
- .intValue();
- int blueValue = Integer.decode("0x" + value.substring(5))
- .intValue();
+ int redValue = Integer.decode("0x" + value.substring(1, 3)).intValue();
+ int greenValue = Integer.decode("0x" + value.substring(3, 5)).intValue();
+ int blueValue = Integer.decode("0x" + value.substring(5)).intValue();
return new CSS2RGBColorImpl(redValue, greenValue, blueValue);
} catch (Exception e) {
return null;
@@ -63,8 +59,9 @@ public class CSS2ColorHelper {
// Search if it's color name
value = value.toLowerCase();
value = (String) colorNamesMap.get(value);
- if (value != null)
+ if (value != null) {
return getRGBColor(value);
+ }
return null;
}
@@ -72,7 +69,7 @@ public class CSS2ColorHelper {
* Return color string form w3c <code>rgbColor</code> instance. The format
* (Hexa, color name or rgb format) of the color string is managed with
* <code>config</code> {@link ICSSValueConverterConfig}.
- *
+ *
* @param rgbColor
* @param config
* @return
@@ -108,7 +105,7 @@ public class CSS2ColorHelper {
/**
* Return rgb (ex : rgb(0,0,0)) color string value from w3c
* <code>rgbColor</code> instance.
- *
+ *
* @param rgbColor
* @return
*/
@@ -132,7 +129,7 @@ public class CSS2ColorHelper {
/**
* Return hexadecimal (ex : #FFFFFF) color string value from w3c
* <code>rgbColor</code> instance.
- *
+ *
* @param rgbColor
* @return
*/
@@ -158,7 +155,7 @@ public class CSS2ColorHelper {
/**
* Return the Hexa color (ex : #FFFFFF) from color name (ex : white).
- *
+ *
* @param colorName
* @return
*/
@@ -169,7 +166,7 @@ public class CSS2ColorHelper {
/**
* Return true if <code>value</code> is color name (ex : white) and false
* otherwise.
- *
+ *
* @param value
* @return
*/
@@ -179,7 +176,7 @@ public class CSS2ColorHelper {
/**
* Return the color name (ex : white) from Hexa color (ex : #FFFFFF).
- *
+ *
* @param hexaColor
* @return
*/
@@ -337,9 +334,7 @@ public class CSS2ColorHelper {
colorNamesMap.put("yellowgreen", "#9ACD32");
// Build Map with key=hexadecimal color and value=color name
- for (Iterator iterator = colorNamesMap.entrySet().iterator(); iterator
- .hasNext();) {
- Map.Entry entry = (Map.Entry) iterator.next();
+ for (Entry<String, String> entry : colorNamesMap.entrySet()) {
colorHexasMap.put(entry.getValue(), entry.getKey());
}
}
diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/ExtendedDocumentCSS.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/ExtendedDocumentCSS.java
index 5777981..e394348 100644
--- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/ExtendedDocumentCSS.java
+++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/ExtendedDocumentCSS.java
@@ -22,16 +22,12 @@ import org.w3c.dom.stylesheets.StyleSheet;
*/
public interface ExtendedDocumentCSS extends DocumentCSS {
- public static final Integer SAC_ID_CONDITION = new Integer(
- Condition.SAC_ID_CONDITION);
- public static final Integer SAC_CLASS_CONDITION = new Integer(
- Condition.SAC_CLASS_CONDITION);
- public static final Integer SAC_PSEUDO_CLASS_CONDITION = new Integer(
- Condition.SAC_PSEUDO_CLASS_CONDITION);
- public static final Integer OTHER_SAC_CONDITIONAL_SELECTOR = new Integer(
- Selector.SAC_CONDITIONAL_SELECTOR);
-
- public static final Integer OTHER_SAC_SELECTOR = new Integer(999);
+ public static final Integer SAC_ID_CONDITION = Integer.valueOf(Condition.SAC_ID_CONDITION);
+ public static final Integer SAC_CLASS_CONDITION = Integer.valueOf(Condition.SAC_CLASS_CONDITION);
+ public static final Integer SAC_PSEUDO_CLASS_CONDITION = Integer.valueOf(Condition.SAC_PSEUDO_CLASS_CONDITION);
+ public static final Integer OTHER_SAC_CONDITIONAL_SELECTOR = Integer.valueOf(Selector.SAC_CONDITIONAL_SELECTOR);
+
+ public static final Integer OTHER_SAC_SELECTOR = Integer.valueOf(999);
public void addStyleSheet(StyleSheet styleSheet);
diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/DocumentCSSImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/DocumentCSSImpl.java
index 207e385..a18aad1 100644
--- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/DocumentCSSImpl.java
+++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/DocumentCSSImpl.java
@@ -92,15 +92,13 @@ public class DocumentCSSImpl implements ExtendedDocumentCSS {
return list;
}
- protected List querySelector(CSSRuleList ruleList, int selectorType,
- int selectorConditionType) {
- List list = new ArrayList();
- int length = ruleList.getLength();
- for (int i = 0; i < length; i++) {
- CSSRule rule = ruleList.item(i);
- switch (rule.getType()) {
- case CSSRule.STYLE_RULE: {
- if (rule instanceof ExtendedCSSRule) {
+ protected List<Selector> querySelector(CSSRuleList ruleList, int selectorType, int selectorConditionType) {
+ List<Selector> list = new ArrayList<Selector>();
+ if (selectorType == Selector.SAC_CONDITIONAL_SELECTOR) {
+ int length = ruleList.getLength();
+ for (int i = 0; i < length; i++) {
+ CSSRule rule = ruleList.item(i);
+ if (rule.getType() == CSSRule.STYLE_RULE && rule instanceof ExtendedCSSRule) {
ExtendedCSSRule r = (ExtendedCSSRule) rule;
SelectorList selectorList = r.getSelectorList();
// Loop for SelectorList
@@ -108,26 +106,20 @@ public class DocumentCSSImpl implements ExtendedDocumentCSS {
for (int j = 0; j < l; j++) {
Selector selector = (Selector) selectorList.item(j);
if (selector.getSelectorType() == selectorType) {
- switch (selectorType) {
- case Selector.SAC_CONDITIONAL_SELECTOR:
- // It's conditional selector
- ConditionalSelector conditionalSelector = (ConditionalSelector) selector;
- short conditionType = conditionalSelector
- .getCondition().getConditionType();
- if (selectorConditionType == conditionType) {
- // current selector match the current CSS
- // Rule
- // CSSStyleRule styleRule = (CSSStyleRule)
- // rule;
- list.add(selector);
- }
+ // It's conditional selector
+ ConditionalSelector conditionalSelector = (ConditionalSelector) selector;
+ short conditionType = conditionalSelector.getCondition().getConditionType();
+ if (selectorConditionType == conditionType) {
+ // current selector match the current CSS
+ // Rule
+ // CSSStyleRule styleRule = (CSSStyleRule)
+ // rule;
+ list.add(selector);
}
}
-
}
}
}
- }
}
return list;
}
diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/MediaListImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/MediaListImpl.java
index 232761a..46bee01 100644
--- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/MediaListImpl.java
+++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/MediaListImpl.java
@@ -21,13 +21,13 @@ import org.w3c.dom.stylesheets.MediaList;
public class MediaListImpl implements MediaList {
private List mediaList = null;
-
+
public MediaListImpl(SACMediaList media) {
mediaList = new ArrayList();
for (int i = 0; i < media.getLength(); i++) {
mediaList.add(media.item(i));
}
-
+
}
public void appendMedium(String newMedium) throws DOMException {
@@ -44,15 +44,16 @@ public class MediaListImpl implements MediaList {
}
public String getMediaText() {
- String media = "";
+ StringBuilder media = new StringBuilder();
int size = mediaList.size();
if (size > 0) {
- media += mediaList.get(0);
+ media.append(mediaList.get(0));
for (int i = 1; i < mediaList.size(); i++) {
- media += ", " + mediaList.get(i);
+ media.append(", ");
+ media.append(mediaList.get(i));
}
}
- return media;
+ return media.toString();
}
public String item(int index) {
diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/StyleWrapper.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/StyleWrapper.java
index f10e685..64e1028 100644
--- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/StyleWrapper.java
+++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/StyleWrapper.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* Copyright (c) 2009, 2013 EclipseSource and others. All rights reserved.
* This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
@@ -20,9 +20,9 @@ import org.w3c.dom.css.CSSStyleDeclaration;
*/
final class StyleWrapper {
- private static class StyleWrapperComparator implements Comparator {
-
- public int compare(final Object object1, final Object object2) {
+ private static class StyleWrapperComparator implements Comparator<StyleWrapper> {
+
+ public int compare(final StyleWrapper object1, final StyleWrapper object2) {
int result = 0;
StyleWrapper wrapper1 = (StyleWrapper) object1;
StyleWrapper wrapper2 = (StyleWrapper) object2;
diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/ViewCSSImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/ViewCSSImpl.java
index 8f9e2b6..511fdab 100644
--- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/ViewCSSImpl.java
+++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/ViewCSSImpl.java
@@ -69,8 +69,7 @@ public class ViewCSSImpl implements ViewCSS {
return null;
}
- public CSSStyleDeclaration getComputedStyle(CSSStyleSheet styleSheet,
- Element elt, String pseudoElt) {
+ public CSSStyleDeclaration getComputedStyle(CSSStyleSheet styleSheet, Element elt, String pseudoElt) {
List styleDeclarations = null;
StyleWrapper firstStyleDeclaration = null;
CSSRuleList ruleList = styleSheet.getCssRules();
@@ -78,8 +77,7 @@ public class ViewCSSImpl implements ViewCSS {
int position = 0;
for (int i = 0; i < length; i++) {
CSSRule rule = ruleList.item(i);
- switch (rule.getType()) {
- case CSSRule.STYLE_RULE: {
+ if (rule.getType() == CSSRule.STYLE_RULE) {
CSSStyleRule styleRule = (CSSStyleRule) rule;
if (rule instanceof ExtendedCSSRule) {
ExtendedCSSRule r = (ExtendedCSSRule) rule;
@@ -104,8 +102,7 @@ public class ViewCSSImpl implements ViewCSS {
// match the current element
if (styleDeclarations == null) {
styleDeclarations = new ArrayList();
- styleDeclarations
- .add(firstStyleDeclaration);
+ styleDeclarations.add(firstStyleDeclaration);
}
styleDeclarations.add(wrapper);
}
@@ -120,7 +117,6 @@ public class ViewCSSImpl implements ViewCSS {
// Manage this case...
}
}
- }
}
if (styleDeclarations != null) {
// There is several Style Declarations wich match
diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/serializers/CSSSerializer.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/serializers/CSSSerializer.java
index b5e9cd0..12e8010 100644
--- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/serializers/CSSSerializer.java
+++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/serializers/CSSSerializer.java
@@ -13,9 +13,7 @@ package org.eclipse.e4.ui.css.core.serializers;
import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
-
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@@ -37,15 +35,14 @@ public class CSSSerializer {
* stored into the <code>writer</code>. If
* <code>serializeChildNodes</code> is true, the method will serialize too
* the child nodes of the <code>element</code>.
- *
+ *
* @param writer
* @param engine
* @param element
* @param serializeChildNodes
* @throws IOException
*/
- public void serialize(Writer writer, CSSEngine engine, Object element,
- boolean serializeChildNodes) throws IOException {
+ public void serialize(Writer writer, CSSEngine engine, Object element, boolean serializeChildNodes) throws IOException {
serialize(writer, engine, element, serializeChildNodes, null);
}
@@ -57,7 +54,7 @@ public class CSSSerializer {
* the child nodes of the <code>element</code>. The
* {@link CSSSerializerConfiguration} <code>configuration</code> is used
* to generate selector with condition like Text[style='SWT.MULTI'].
- *
+ *
* @param writer
* @param engine
* @param element
@@ -65,19 +62,13 @@ public class CSSSerializer {
* @param configuration
* @throws IOException
*/
- public void serialize(Writer writer, CSSEngine engine, Object element,
- boolean serializeChildNodes,
- CSSSerializerConfiguration configuration) throws IOException {
- Map selectors = new HashMap();
- serialize(writer, engine, element, serializeChildNodes, selectors,
- configuration);
+ public void serialize(Writer writer, CSSEngine engine, Object element, boolean serializeChildNodes, CSSSerializerConfiguration configuration) throws IOException {
+ Map<String, CSSStyleDeclaration> selectors = new HashMap<String, CSSStyleDeclaration>();
+ serialize(writer, engine, element, serializeChildNodes, selectors, configuration);
boolean firstSelector = true;
- for (Iterator iterator = selectors.entrySet().iterator(); iterator
- .hasNext();) {
- Map.Entry entry = (Map.Entry) iterator.next();
- String selectorName = (String) entry.getKey();
- CSSStyleDeclaration styleDeclaration = (CSSStyleDeclaration) entry
- .getValue();
+ for (Map.Entry<String, CSSStyleDeclaration> entry : selectors.entrySet()) {
+ String selectorName = entry.getKey();
+ CSSStyleDeclaration styleDeclaration = entry.getValue();
if (styleDeclaration != null) {
int length = styleDeclaration.getLength();
// Start selector
@@ -85,8 +76,7 @@ public class CSSSerializer {
firstSelector = false;
for (int i = 0; i < length; i++) {
String propertyName = styleDeclaration.item(i);
- String propertyValue = styleDeclaration
- .getPropertyValue(propertyName);
+ String propertyValue = styleDeclaration.getPropertyValue(propertyName);
property(writer, propertyName, propertyValue);
}
// End selector
@@ -103,9 +93,9 @@ public class CSSSerializer {
* the child nodes of the <code>element</code>. The
* {@link CSSSerializerConfiguration} <code>configuration</code> is used
* to generate selector with condition like Text[style='SWT.MULTI'].
- *
+ *
* Map of <code>selectors</code> contains the selector already built.
- *
+ *
* @param writer
* @param engine
* @param element
@@ -114,14 +104,12 @@ public class CSSSerializer {
* @param configuration
* @throws IOException
*/
- protected void serialize(Writer writer, CSSEngine engine, Object element,
- boolean serializeChildNodes, Map selectors,
+ protected void serialize(Writer writer, CSSEngine engine, Object element, boolean serializeChildNodes, Map<String, CSSStyleDeclaration> selectors,
CSSSerializerConfiguration configuration) throws IOException {
Element elt = engine.getElement(element);
if (elt != null) {
- String selectorName = elt.getLocalName();
- CSSStyleDeclaration styleDeclaration = engine
- .getDefaultStyleDeclaration(element, null);
+ StringBuilder selectorName = new StringBuilder(elt.getLocalName());
+ CSSStyleDeclaration styleDeclaration = engine.getDefaultStyleDeclaration(element, null);
if (configuration != null) {
String[] attributesFilter = configuration.getAttributesFilter();
@@ -129,17 +117,20 @@ public class CSSSerializer {
String attributeFilter = attributesFilter[i];
String value = elt.getAttribute(attributeFilter);
if (value != null && value.length() > 0) {
+ selectorName.append("[");
+ selectorName.append(attributeFilter);
+ selectorName.append("=");
if (value.indexOf(".") != -1) {
value = "'" + value + "'";
}
- selectorName += "[" + attributeFilter + "=" + value
- + "]";
+ selectorName.append(value);
+ selectorName.append("]");
break;
}
}
}
- selectors.put(selectorName, styleDeclaration);
+ selectors.put(selectorName.toString(), styleDeclaration);
if (serializeChildNodes) {
NodeList nodes = elt.getChildNodes();
if (nodes != null) {
@@ -154,41 +145,39 @@ public class CSSSerializer {
/**
* Generate start selector.
- *
+ *
* @param writer
* @param selectorName
* @param firstSelector
* @throws IOException
*/
- protected void startSelector(Writer writer, String selectorName,
- boolean firstSelector) throws IOException {
- if (firstSelector == false)
+ protected void startSelector(Writer writer, String selectorName, boolean firstSelector) throws IOException {
+ if (firstSelector == false) {
writer.write("\n\n");
+ }
writer.write(selectorName + " {");
}
/**
* Generate end selector.
- *
+ *
* @param writer
* @param selectorName
* @throws IOException
*/
- protected void endSelector(Writer writer, String selectorName)
- throws IOException {
+ protected void endSelector(Writer writer, String selectorName) throws IOException {
writer.write("\n}");
}
/**
* Generate CSS Property.
- *
+ *
* @param writer
* @param propertyName
* @param propertyValue
* @throws IOException
*/
- private void property(Writer writer, String propertyName,
- String propertyValue) throws IOException {
+ private void property(Writer writer, String propertyName, String propertyValue) throws IOException {
writer.write("\n\t" + propertyName + ":" + propertyValue + ";");
}
}