changeset 2343:ebb73c6cdaa6

Removing css2java converter as it did not yield the hoped-for benefits. (See RT-23526 'Use a Java class file for representing a CSS stylesheet instead of bss or css' for more information)
author jgiles
date Tue, 22 Jan 2013 16:26:11 +1300
parents 53cf47ef85b9
children 0707a49bd4bc
files javafx-ui-common/src/com/sun/javafx/css/CompoundSelector.java javafx-ui-common/src/com/sun/javafx/css/Declaration.java javafx-ui-common/src/com/sun/javafx/css/ParsedValueImpl.java javafx-ui-common/src/com/sun/javafx/css/Rule.java javafx-ui-common/src/com/sun/javafx/css/Selector.java javafx-ui-common/src/com/sun/javafx/css/SimpleSelector.java javafx-ui-common/src/com/sun/javafx/css/StyleConverterImpl.java javafx-ui-common/src/com/sun/javafx/css/Stylesheet.java javafx-ui-common/src/com/sun/javafx/css/parser/Css2Java.java javafx-ui-controls/build-common.xml
diffstat 10 files changed, 2 insertions(+), 496 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-common/src/com/sun/javafx/css/CompoundSelector.java	Tue Jan 22 13:33:16 2013 +1300
+++ b/javafx-ui-common/src/com/sun/javafx/css/CompoundSelector.java	Tue Jan 22 16:26:11 2013 +1300
@@ -384,60 +384,4 @@
         }
         return new CompoundSelector(selectors, relationships);
     }
-    
-    @Override public String writeJava() {
-        final String NEW_LINE = Rule.NEW_LINE;
-        final String INDENT = Rule.INDENT;
-        final String TWO_INDENT = Rule.TWO_INDENT;
-        final String FIVE_INDENT = TWO_INDENT + TWO_INDENT + INDENT;
-        
-        StringBuilder sb = new StringBuilder();
-        sb.append(NEW_LINE);
-        sb.append(TWO_INDENT);
-        sb.append(TWO_INDENT);
-        sb.append("new CompoundSelector(");
-        sb.append(NEW_LINE);
-        
-        sb.append(FIVE_INDENT);
-        sb.append("Arrays.<SimpleSelector>asList(");
-        sb.append(NEW_LINE);
-        
-        for (int i = 0; i < selectors.size(); i++) {
-            Selector sel = selectors.get(i);
-            
-            sb.append(INDENT);
-            sb.append(FIVE_INDENT);
-            sb.append(sel.writeJava());
-            
-            if (i < (selectors.size() - 1)) {
-                sb.append(", ");
-                sb.append(NEW_LINE);
-            }
-        }
-        
-        sb.append("), ");
-        
-        sb.append(NEW_LINE);
-        sb.append(FIVE_INDENT);
-        sb.append("Arrays.<Combinator>asList(");
-        sb.append(NEW_LINE);
-        
-        for (int i = 0; i < relationships.size(); i++) {
-            Combinator com = relationships.get(i);
-            
-            sb.append(INDENT);
-            sb.append(FIVE_INDENT);
-            sb.append("Combinator.");
-            sb.append(com.name());
-            
-            if (i < (relationships.size() - 1)) {
-                sb.append(", ");
-                sb.append(NEW_LINE);
-            }
-        }
-        
-        sb.append("))");
-        
-        return sb.toString();
-    }
 }
--- a/javafx-ui-common/src/com/sun/javafx/css/Declaration.java	Tue Jan 22 13:33:16 2013 +1300
+++ b/javafx-ui-common/src/com/sun/javafx/css/Declaration.java	Tue Jan 22 16:26:11 2013 +1300
@@ -149,18 +149,5 @@
         return new Declaration(propertyName, parsedValue, important);
             
     }
-    
-    public String writeJava() {
-        StringBuilder sb = new StringBuilder();
-        sb.append("new Declaration(\"");
-        sb.append(getProperty());
-        sb.append("\", ");
-        sb.append(getParsedValueImpl().writeJava());
-        sb.append(", ");
-        sb.append(isImportant());
-        sb.append(")"); 
-        
-        return sb.toString();
-    }
 }
 
--- a/javafx-ui-common/src/com/sun/javafx/css/ParsedValueImpl.java	Tue Jan 22 13:33:16 2013 +1300
+++ b/javafx-ui-common/src/com/sun/javafx/css/ParsedValueImpl.java	Tue Jan 22 16:26:11 2013 +1300
@@ -730,141 +730,4 @@
             throw new InternalError("unknown type: " + valType);
         }
     }
-
-    public String writeJava() {
-        StringBuilder sb = new StringBuilder();
-        
-        sb.append("new ParsedValueImpl("); 
-
-        // ---- Value
-        if (value instanceof ParsedValue) {
-            final ParsedValue pv = (ParsedValue)value;
-            if (pv instanceof ParsedValueImpl) {
-                sb.append(((ParsedValueImpl)pv).writeJava());
-            } else {
-                final ParsedValueImpl impl = new ParsedValueImpl(pv.getValue(), pv.getConverter());
-                sb.append(impl.writeJava());
-            }
-        } else if (value instanceof ParsedValue[]) {
-            final ParsedValue[] values = (ParsedValue[])value;
-            sb.append("new ParsedValueImpl[] {");
-            
-            for (int v=0; v<values.length; v++) {                
-                if (values[v] != null) {
-                    final ParsedValue pv = values[v];
-                    if (pv instanceof ParsedValueImpl) {
-                        sb.append(((ParsedValueImpl)pv).writeJava());
-                    } else {
-                        final ParsedValueImpl impl = new ParsedValueImpl(pv.getValue(), pv.getConverter());
-                        sb.append(impl.writeJava());
-                    }
-                } else {
-                    sb.append("null");
-                }
-                
-                if (v < (values.length - 1)) {
-                    sb.append(", ");
-                }
-            }
-            
-            sb.append("}");
-        } else if (value instanceof ParsedValue[][]) {
-            final ParsedValue[][] layers = (ParsedValue[][])value;
-            sb.append("new ParsedValueImpl[][] {");
-            
-            for (int l=0; l<layers.length; l++) {
-                final ParsedValue[] values = layers[l];
-                sb.append("new ParsedValueImpl[] {");
-                final int nValues = values != null ? values.length : 0;
-                for (int v=0; v<nValues; v++) {
-                    if (values[v] != null) {
-                        final ParsedValue pv = values[v];
-                        if (pv instanceof ParsedValueImpl) {
-                            sb.append(((ParsedValueImpl)pv).writeJava());
-                        } else {
-                            final ParsedValueImpl impl = new ParsedValueImpl(pv.getValue(), pv.getConverter());
-                            sb.append(impl.writeJava());
-                        }
-                    } else {
-                        sb.append("null");
-                    }
-                    
-                    if (v < (values.length - 1)) {
-                        sb.append(", ");
-                    }
-                }
-                
-                sb.append("}");
-            }
-            
-            sb.append("}");
-        } else if (value instanceof Color) {
-            final Color c = (Color)value;
-            sb.append("new Color(");
-            sb.append(c.getRed());
-            sb.append(", ");
-            sb.append(c.getGreen());
-            sb.append(", ");
-            sb.append(c.getBlue());
-            sb.append(", ");
-            sb.append(c.getOpacity());
-            sb.append(")");
-        } else if (value instanceof Enum) {
-            final Enum e = (Enum)value;
-            sb.append(e.getClass().getName());
-            sb.append(".");
-            sb.append(e);
-        } else if (value instanceof Boolean) {
-            final Boolean b = (Boolean)value;
-            sb.append(b);
-        } else if (value instanceof Size) {
-            final Size size = (Size)value;
-            final double sz = size.getValue();
-            sb.append("new Size(");
-            sb.append(sz);
-            sb.append(", SizeUnits.");
-            sb.append(size.getUnits().name());
-            sb.append(")");
-        } else if (value instanceof String) {
-            String str = (String)value;
-            if (! str.startsWith("\"")) sb.append("\"");
-            sb.append(str);
-            if (! str.endsWith("\"")) sb.append("\"");
-        } else if (value instanceof URL) {
-            URL url = (URL)value;
-            String urlString = url.toString();
-            
-            // convert all escaped slashes (\\) into \, and then convert all
-            // backslashes into escaped versions.
-            urlString = urlString.replace("\\\\", "\\");
-            urlString = urlString.replace("\\", "\\\\");
-            
-            sb.append("\"");
-            sb.append(urlString);
-            sb.append("\"");
-        } else if (value == null) {
-            sb.append("null");
-        } else {
-            throw new InternalError("cannot writeJava " + this);
-        }
-        
-        // --- Style Converter
-        sb.append(", ");
-        String styleConverterString = "null";
-        StyleConverter converter = getConverter();
-        if (converter instanceof StyleConverterImpl) {
-            styleConverterString = ((StyleConverterImpl)converter).writeJava();
-            
-        }
-        sb.append(styleConverterString);
-        
-        // --- IsLookup
-        sb.append(", ");
-        sb.append(isLookup());
-        
-        // close ParsedValueImpl constructor
-        sb.append(")"); 
-        
-        return sb.toString();
-    }
 }
--- a/javafx-ui-common/src/com/sun/javafx/css/Rule.java	Tue Jan 22 13:33:16 2013 +1300
+++ b/javafx-ui-common/src/com/sun/javafx/css/Rule.java	Tue Jan 22 16:26:11 2013 +1300
@@ -203,49 +203,4 @@
 
         return new Rule(selectors, declarations);
     }
-
-    public static final String NEW_LINE = "\r\n";
-    public static final String INDENT = "    ";
-    public static final String TWO_INDENT = "        ";
-    
-    String writeJava() throws IOException {
-        final String THREE_INDENT = INDENT + TWO_INDENT;
-        final String FOUR_INDENT = TWO_INDENT + TWO_INDENT;
-        
-        StringBuilder sb = new StringBuilder();
-        sb.append("new Rule(");
-        sb.append(NEW_LINE);
-        
-        // selectors
-        sb.append(THREE_INDENT);
-        sb.append("Arrays.<Selector>asList(");
-        for (int i = 0; i < selectors.size(); i++) {
-            Selector sel = selectors.get(i);
-            sb.append(sel.writeJava());
-            
-            if (i < (selectors.size() - 1)) {
-                sb.append(", ");
-            }
-        }
-        sb.append("), ");
-        
-        // declarations
-        sb.append(NEW_LINE);
-        sb.append(THREE_INDENT);
-        sb.append("Arrays.<Declaration>asList(");
-        for (int i = 0; i < declarations.size(); i++) {
-            Declaration decl = declarations.get(i);
-            
-            sb.append(NEW_LINE);
-            sb.append(FOUR_INDENT);
-            sb.append(decl.writeJava());
-            
-            if (i < (declarations.size() - 1)) {
-                sb.append(", ");
-            }
-        }
-        sb.append("))");
-        
-        return sb.toString();
-    }
 }
--- a/javafx-ui-common/src/com/sun/javafx/css/Selector.java	Tue Jan 22 13:33:16 2013 +1300
+++ b/javafx-ui-common/src/com/sun/javafx/css/Selector.java	Tue Jan 22 16:26:11 2013 +1300
@@ -95,8 +95,6 @@
             return CompoundSelector.readBinary(is,strings);
     }
     
-    protected abstract String writeJava();
-
     public static Selector createSelector(final String cssSelector) {
         if (cssSelector == null || cssSelector.length() == 0) {
             return null; // actually return a default no-match selector
--- a/javafx-ui-common/src/com/sun/javafx/css/SimpleSelector.java	Tue Jan 22 13:33:16 2013 +1300
+++ b/javafx-ui-common/src/com/sun/javafx/css/SimpleSelector.java	Tue Jan 22 16:26:11 2013 +1300
@@ -532,53 +532,4 @@
         }
         return new SimpleSelector(name, styleClasses, pseudoclasses, id);
     }
-
-    @Override public String writeJava() {
-        StringBuilder sb = new StringBuilder();
-        sb.append("new SimpleSelector(\"");
-        sb.append(getName());
-        sb.append("\", ");
-        
-        // styleclasses
-        if (getStyleClasses().isEmpty()) {
-            sb.append("null");
-        } else {
-            sb.append("Arrays.<String>asList(");
-            for (int i = 0, max = getStyleClasses().size(); i < max; i++) {
-                sb.append("\"");
-                sb.append(getStyleClasses().get(i));
-                sb.append("\"");
-
-                if (i < (max - 1)) {
-                    sb.append(", ");
-                }
-            }
-            sb.append(")");
-        }
-        
-        sb.append(", ");
-        
-        // pseudoclasses
-        if (getPseudoclasses().isEmpty()) {
-            sb.append("null");
-        } else {
-            sb.append("Arrays.<String>asList(");
-            for (int i = 0, max = getPseudoclasses().size(); i < max; i++) {
-                sb.append("\"");
-                sb.append(getPseudoclasses().get(i));
-                sb.append("\"");
-
-                if (i < (max - 1)) {
-                    sb.append(", ");
-                }
-            }
-            sb.append(")");
-        }
-        
-        sb.append(", \"");
-        sb.append(getId());
-        sb.append("\")");
-        
-        return sb.toString();
-    }
 }
--- a/javafx-ui-common/src/com/sun/javafx/css/StyleConverterImpl.java	Tue Jan 22 13:33:16 2013 +1300
+++ b/javafx-ui-common/src/com/sun/javafx/css/StyleConverterImpl.java	Tue Jan 22 16:26:11 2013 +1300
@@ -103,9 +103,4 @@
         }
         return tmap.get(cname);
     }
-    
-    public String writeJava() {
-        return getClass().getCanonicalName() + ".getInstance()";
-    }
-
 }
--- a/javafx-ui-common/src/com/sun/javafx/css/Stylesheet.java	Tue Jan 22 13:33:16 2013 +1300
+++ b/javafx-ui-common/src/com/sun/javafx/css/Stylesheet.java	Tue Jan 22 16:26:11 2013 +1300
@@ -250,93 +250,4 @@
         // return stylesheet
         return stylesheet;
     }
-    
-    public void writeJava(final PrintWriter writer, String className) throws IOException {
-        final String NEW_LINE = Rule.NEW_LINE;
-        final String INDENT = Rule.INDENT;
-        final String TWO_INDENT = Rule.TWO_INDENT;
-        
-        final int RULES_PER_METHOD = 50;
-        final int NUMBER_OF_METHODS = (rules.size() / RULES_PER_METHOD);
-
-        writer.write("import com.sun.javafx.css.*;" + NEW_LINE);
-        writer.write("import com.sun.javafx.css.parser.*;" + NEW_LINE);
-        writer.write("import java.util.*;" + NEW_LINE);
-        writer.write("import javafx.scene.paint.*;" + NEW_LINE);
-        
-        writer.write(NEW_LINE);
-        writer.write("public class " + className + " extends Stylesheet {");
-        writer.write(NEW_LINE);
-        writer.write(NEW_LINE);
-        
-        writer.write(INDENT);
-        writer.write("public ");
-        writer.write(className);
-        writer.write("() {");
-        writer.write(NEW_LINE);
-        
-        writer.write(TWO_INDENT);
-        writer.write("final List<Rule> rules = getRules();");
-        writer.write(NEW_LINE);
-        
-        for (int i = 0, max = NUMBER_OF_METHODS; i <= max; i++) {
-            writer.write(TWO_INDENT);
-            writer.write("loadRules");
-            writer.write(i+"");
-            writer.write("(rules);");
-            writer.write(NEW_LINE);
-        }
-        
-        // close the constructor
-        writer.write(INDENT);
-        writer.write("}");
-        writer.write(NEW_LINE);
-        writer.write(NEW_LINE);
-        
-        // get all the rules strings
-        String[] rulesStrings = new String[rules.size()];
-        for (int j = 0; j < rules.size(); j++) {
-            Rule r = rules.get(j);
-            rulesStrings[j] = r.writeJava();
-        }
-        
-        // write out methods
-        for (int i = 0; i <= NUMBER_OF_METHODS; i++) {
-            writer.write(INDENT);
-            writer.write("private final void loadRules");
-            writer.write(i+"");
-            writer.write("(final List<Rule> rules) {");
-            writer.write(NEW_LINE);
-            
-            writer.write(TWO_INDENT);
-            writer.write("Collections.addAll(rules, ");
-            writer.write(NEW_LINE);
-            
-            for (int j = 0; j < RULES_PER_METHOD; j++) {
-                int pos = i * RULES_PER_METHOD + j;
-                if (pos == rulesStrings.length) break;
-                
-                writer.write(TWO_INDENT);
-                writer.write(rulesStrings[pos]);
-                
-                if ((j < RULES_PER_METHOD - 1) && (pos < (rulesStrings.length - 1))) {
-                    writer.write(", ");
-                    writer.write(NEW_LINE);
-                }
-            }
-            
-            writer.write(NEW_LINE);
-            writer.write(TWO_INDENT);
-            writer.write(");");
-            
-            writer.write(NEW_LINE);
-            writer.write(INDENT);
-            writer.write("}");
-            writer.write(NEW_LINE);
-            writer.write(NEW_LINE);
-        }
-        
-        // close class
-        writer.write("}");
-    }
 }
--- a/javafx-ui-common/src/com/sun/javafx/css/parser/Css2Java.java	Tue Jan 22 13:33:16 2013 +1300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,79 +0,0 @@
-/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.sun.javafx.css.parser;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-
-import com.sun.javafx.css.Stylesheet;
-import java.io.*;
-
-/** Css2Java <input file> [<package name> <output file name>]
- * java -classpath <sdk desktop lib path>/javafx-ui-common.jar com.sun.javafx.css.parser.Css2Java input.css full.package.name output.java
- *  If no output file is given, then the input file name is used with an extension of 'java'
- */
-public class Css2Java {
-    public static void main(String args[]) throws Exception {
-        
-        if ( args.length < 1) throw new IllegalArgumentException("expected <input file> [<package name> <output file name>] as arguments");
-
-        try {
-            String ifname = args[0];
-            String packageName = (args.length > 1 ? args[1] : null);
-            String ofname = (args.length > 2) ?
-                args[2] : ifname.substring(0, ifname.lastIndexOf('.')+1).concat("java");
-            
-            convertToJava(ifname, ofname, packageName);
-        } catch (Exception e) {
-            System.err.println(e.toString());
-            e.printStackTrace(System.err);
-            System.exit(-1);
-        } 
-    }
-
-    public static void convertToJava(String ifname, String ofname, String packageName) throws IOException {
-        final URL urlIn = new java.net.URL("file", null, ifname);
-
-        CSSParser.EXIT_ON_ERROR = true;
-        Stylesheet stylesheet = CSSParser.getInstance().parse(urlIn);
-
-        File outFile = new File(ofname);
-        PrintWriter writer = new PrintWriter(outFile);
-        
-        if (packageName != null && ! packageName.isEmpty()) {
-            writer.write("package ");
-            writer.write(packageName);
-            writer.write(";");
-            writer.write("\r\n\r\n");
-        }
-        
-        String className = outFile.getName();
-        className = className.substring(0, className.indexOf("."));
-        stylesheet.writeJava(writer, className);
-        writer.flush();
-        writer.close();
-    }
-}
--- a/javafx-ui-controls/build-common.xml	Tue Jan 22 13:33:16 2013 +1300
+++ b/javafx-ui-controls/build-common.xml	Tue Jan 22 16:26:11 2013 +1300
@@ -18,7 +18,7 @@
     </target>
 
 
-    <target name="-pre-init" depends="check-binary-css, compile-java-css" unless="binaryCssUpToDate">
+    <target name="-pre-init" depends="check-binary-css" unless="binaryCssUpToDate">
       <mkdir dir="${basedir}/${build.dir}/classes/com/sun/javafx/scene/control/skin/caspian"/>
 
       <!-- compile all .css files in the build dir to .bss files, for faster startup -->
@@ -50,26 +50,7 @@
             <srcfiles dir="${src.dir}/com/sun/javafx/scene/control/skin/caspian" includes="caspian.css"/>
         </uptodate>
     </target> 
-
-    <target name="compile-java-css" depends="check-java-css" unless="javaCssUpToDate">
-        <mkdir dir="${build.dir}/classes/com/sun/javafx/scene/control/skin/caspian"/>
-        <java classname="com.sun.javafx.css.parser.Css2Java" fork="true" failonerror="true">
-          <jvmarg value="-Djavafx.toolkit=com.sun.javafx.tk.DummyToolkit"/>
-          <classpath> 
-            <pathelement location="${rt.dist.root.dir}/javafx-ui-common/dist/javafx-ui-common.jar"/>
-            <pathelement location="${runtime.dist.root.dir}/javafx-accessible/dist/javafx-accessible.jar"/>
-            <pathelement location="${runtime.dist.root.dir}/javafx-beans/dist/javafx-beans.jar"/>
-            <pathelement location="${rt.dist.root.dir}/javafx-anim/dist/javafx-anim.jar"/>
-            <pathelement location="${rt.dist.root.dir}/javafx-common/dist/javafx-common.jar"/>
-            <pathelement location="${rt.dist.root.dir}/javafx-logging/dist/javafx-logging.jar"/>
-            <pathelement location="${JFXRT_HOME}/jfxrt.jar"/>
-          </classpath> 
-          <arg value="${src.dir}/com/sun/javafx/scene/control/skin/caspian/caspian.css"/>
-          <arg value="com.sun.javafx.scene.control.skin.caspian"/>
-          <arg value="${build.dir}/classes/com/sun/javafx/scene/control/skin/caspian/Caspian.java"/>
-        </java>
-    </target>
-    
+   
     <!-- misc -->
     <target name="debug-test-file" depends="jar">
         <echo message="${run.test.classpath}" />