001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.languages.parser;
043:
044: import java.util.HashMap;
045: import java.util.HashSet;
046: import java.util.Map;
047: import java.util.Set;
048: import java.util.StringTokenizer;
049: import org.netbeans.modules.languages.Feature;
050: import org.netbeans.modules.languages.Language;
051:
052: /**
053: *
054: * @author Jan Jancura
055: */
056: class ASTFeatures {
057:
058: private static final ASTFeatures DEFAULT = new ASTFeatures();
059: private static Map<String, ASTFeatures> mimeTypeToASTFeatures = new HashMap<String, ASTFeatures>();
060:
061: boolean removeEmpty = false;
062: boolean removeSimple = false;
063: boolean removeEmptyN = true;
064: boolean removeSimpleN = true;
065: Set<String> empty = new HashSet<String>();
066: Set<String> simple = new HashSet<String>();
067:
068: static ASTFeatures get(Language language) {
069: if (language == null)
070: return DEFAULT;
071: String mimeType = language.getMimeType();
072: ASTFeatures astFeatures = mimeTypeToASTFeatures.get(mimeType);
073: if (astFeatures == null) {
074: astFeatures = new ASTFeatures();
075: mimeTypeToASTFeatures.put(mimeType, astFeatures);
076: Feature optimiseProperty = language.getFeatureList()
077: .getFeature("AST");
078: if (optimiseProperty != null) {
079:
080: String s = (String) optimiseProperty
081: .getValue("removeEmpty");
082: if (s != null) {
083: if (s.startsWith("!")) {
084: astFeatures.removeEmptyN = false;
085: s = s.substring(1);
086: }
087: astFeatures.removeEmpty = "true".equals(s);
088: if (!"false".equals(s)) {
089: StringTokenizer st = new StringTokenizer(s, ",");
090: while (st.hasMoreTokens())
091: astFeatures.empty.add(st.nextToken());
092: }
093: }
094:
095: s = (String) optimiseProperty.getValue("removeSimple");
096: if (s != null) {
097: if (s.startsWith("!")) {
098: astFeatures.removeSimpleN = false;
099: s = s.substring(1);
100: }
101: astFeatures.removeSimple = "true".equals(s);
102: if (!"false".equals(s)) {
103: StringTokenizer st = new StringTokenizer(s, ",");
104: while (st.hasMoreTokens())
105: astFeatures.simple.add(st.nextToken());
106: }
107: }
108: }
109: }
110: return astFeatures;
111: }
112: }
|