LanguageDefinition.java

Index Score
org.zkoss.zk.ui.metainfo
ZK

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
DECL_COMMENTSComments in declarations
JAVA0034JAVA0034 Missing braces in if statement
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
DOC_COMMENTNumber of javadoc comment lines
COMMENTSComment lines
CYCLOMATICCyclomatic complexity
JAVA0020JAVA0020 Field name does not have required form
INTERFACE_COMPLEXITYInterface complexity
PARAMSNumber of formal parameter declarations
RETURNSNumber of return points from functions
FUNCTIONSNumber of function declarations
SIZESize of the file in bytes
COMPARISONSNumber of comparison operators
LINESNumber of lines in the source file
UNIQUE_OPERANDSNumber of unique operands
OPERATORSNumber of operators
PROGRAM_LENGTHHalstead program length
ELOCEffective lines of code
OPERANDSNumber of operands
PROGRAM_VOCABHalstead program vocabulary
LOGICAL_LINESNumber of statements
LOCLines of code
BLOCKSNumber of blocks
JAVA0177JAVA0177 Variable declaration missing initializer
JAVA0254JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0082JAVA0082 Unnecessary widening cast
JAVA0163JAVA0163 Empty statement
JAVA0259JAVA0259 Return of collection/array field
JAVA0096JAVA0096 Field in nested class hides outer field
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0022JAVA0022 Static final field name does not have required form
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
EXEC_COMMENTSComments in executable code
JAVA0138JAVA0138 N parameters defined for method (maximum: M)
JAVA0126JAVA0126 Method declares unchecked exception in throws
EXITSProcedure exits
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
LINE_COMMENTNumber of line comments
LOOPSNumber of loops
WHITESPACENumber of whitespace lines
/* LanguageDefinition.java {{IS_NOTE Purpose: Description: History: Tue May 31 18:01:38 2005, Created by tomyeh }}IS_NOTE Copyright (C) 2005 Potix Corporation. All Rights Reserved. {{IS_RIGHT This program is distributed under GPL Version 2.0 in the hope that it will be useful, but WITHOUT ANY WARRANTY. }}IS_RIGHT */ package org.zkoss.zk.ui.metainfo; import java.util.Collection; import java.util.Map; import java.util.HashMap; import java.util.Set; import java.util.HashSet; import java.util.List; import java.util.LinkedList; import java.util.Collections; import java.util.Iterator; import org.zkoss.util.resource.Locator; import org.zkoss.util.logging.Log; import org.zkoss.xel.taglib.Taglibs; import org.zkoss.xel.taglib.Taglib; import org.zkoss.web.servlet.JavaScript; import org.zkoss.web.servlet.StyleSheet; import org.zkoss.zk.mesg.MZk; import org.zkoss.zk.ui.Page; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.ext.Macro; import org.zkoss.zk.ui.ext.Native; import org.zkoss.zk.ui.UiException; import org.zkoss.zk.xel.Evaluator; import org.zkoss.zk.xel.impl.SimpleEvaluator; import org.zkoss.zk.xel.impl.EvaluatorRef; import org.zkoss.zk.device.Devices; import org.zkoss.zk.device.DeviceNotFoundException; import org.zkoss.zk.ui.metainfo.impl.ComponentDefinitionImpl; /** * A definition of a language, such as xul. * * @author tomyeh */ public class LanguageDefinition { private static final Log log = Log.lookup(LanguageDefinition.class); //static// /** A map of (String name or namespace, LanguageDefinition). */ private static final Map _ldefByName = new HashMap(); /** A map of (String ext, LanguageDefinition). */ private static final Map _ldefsByExt = new HashMap(); /** A map of (String deviceType, List(LanguageDefinition). */ private static final Map _ldefsByClient = new HashMap(); /** The namespace for ZK. It is mainly used to resolve special components * and attributes, such as zscript and use. */ public static final String ZK_NAMESPACE = "http://www.zkoss.org/2005/zk"; /** The namespace for ZK annotations. */ public static final String ANNO_NAMESPACE = "http://www.zkoss.org/2005/zk/annotation"; /** The namespace for ZK native namespace. * @since 3.0.0 */ public static final String NATIVE_NAMESPACE = "http://www.zkoss.org/2005/zk/native"; /** The namespace for ZK native namespace prefix. * If a namespace starts with {@link #NATIVE_NAMESPACE_PREFIX} ("native:"), * it means it is also a native space ({@link #NATIVE_NAMESPACE} * but the namespace prefix and uri will be generated. * * <p>For example, * <pre><code>&lt;s:svg xmlns:s="native:http://www.w3.org/2000/svg"/&gt;</code></pre> * * <p>generates the following output: * * <pre><code>&lt;s:svg xmlns:s="http://www.w3.org/2000/svg"/&gt;</code></pre> * * where the prefix <code>s</code> and URI <code>http://www.w3.org/2000/svg</code> * are both generated. * * @since 3.0.0 */ public static final String NATIVE_NAMESPACE_PREFIX = "native:"; /** the device type that this definition belongs to. */ private final String _deviceType; /** name */ private final String _name; /** The name space. */ private final String _ns; /** The extensions supported by this language definition. */ private List _exts; /** The component map. */ private final ComponentDefinitionMap _compdefs; /** The component name for dynamic tags. */ private String _dyntagnm; /** The component definition for dynamic tags. */ private ComponentDefinition _dyntagDefn; /** The set of reserved attributes used by _dyntagDefn. */ private Set _dyntagRvAttrs; /** Map(String lang, String script). */ private final Map _initscripts = new HashMap(); /** Map(String lang, String script). */ private final Map _eachscripts = new HashMap(); /** The URI to render a page. */ private final String _completeURI, _desktopURI, _pageURI; /** A list of Taglib. */ private final List _taglibs = new LinkedList(); /** A list of JavaScript. */ private final List _js = new LinkedList(), _rojs = Collections.unmodifiableList(_js); private final Map _jsmods = new HashMap(5), _rojsmods = Collections.unmodifiableMap(_jsmods); /** A list of StyleSheet. */ private final List _ss = new LinkedList(), _ross = Collections.unmodifiableList(_ss); private final Locator _locator; /** The label template. */ private LabelTemplate _labeltmpl; /** The macro template. */ private MacroTemplate _macrotmpl; /** The native component definition. */ private ComponentDefinition _nativedef; /** The evaluator. */ private Evaluator _eval; /** The evaluator reference. */ private EvaluatorRef _evalr; /** Whether it is a native language. */ private final boolean _native; /** Returns whether the specified language exists. */ public static boolean exists(String name) { init(); synchronized (_ldefByName) { return _ldefByName.containsKey(name); } } /** Returns the language definition of the specified name or namespace. * * <p>Note: the name and namespace of any language cannot be the same. * * @param name the name or the namespace; If null or empty, "xul/html" is assumed. * @exception DefinitionNotFoundException is thrown if the definition * is not found */ public static final LanguageDefinition lookup(String name) { init(); if (name == null || name.length() == 0) name = "xul/html"; final LanguageDefinition langdef; synchronized (_ldefByName) { langdef = (LanguageDefinition)_ldefByName.get(name); } if (langdef == null) if (ZK_NAMESPACE.equals(name)) throw new DefinitionNotFoundException(ZK_NAMESPACE+" is reserved. Use it only with reserved elements and attributes, such as zscript and attribute"); else throw new DefinitionNotFoundException("Language not found: "+name); return langdef; } /** Returns the language definition by specifying an extension. * * @param ext the extension, e.g., "zul". * If null, "zul" is assumed. * @exception DefinitionNotFoundException is thrown if the definition * is not found */ public static final LanguageDefinition getByExtension(String ext) { init(); if (ext == null) ext = "zul"; final LanguageDefinition langdef; synchronized (_ldefsByExt) { langdef = (LanguageDefinition)_ldefsByExt.get(ext); } if (langdef == null) throw new DefinitionNotFoundException("Language not found for extension "+ext); return langdef; } /** Associates an extension to a language. * * @param lang the language name. It cannot be null. * @param ext the extension, e.g., "svg". It cannot be null. * @since 3.0.0 */ public static final void addExtension(String ext, String lang) { if (lang == null || ext == null) throw new IllegalArgumentException(); init(); final LanguageDefinition langdef = lookup(lang); //ensure it exists synchronized (_ldefsByExt) { _ldefsByExt.put(ext, langdef); } } /** Returns a readonly list of language definitions belong to * the specified device type. * * <p>A device type identifies the type of a client. For example, "ajax" * represents all Web browsers with Ajax support, * while "mil" represents clients that supports * <i>Mobile User interface markup Language</i> (on Limited Connected Device, * such as mobile phones). * * @param deviceType the device type, e.g., "ajax". * @see #getDeviceType * @see #getAll */ public static final List getByDeviceType(String deviceType) { init(); final List ldefs; synchronized (_ldefsByClient) { ldefs = (List)_ldefsByClient.get(deviceType); } return ldefs != null ? ldefs: Collections.EMPTY_LIST; } /** Returns a readonly list of all language definitions * regardless of the device type. * * @see #getByDeviceType * @since 2.4.1 */ public static final List getAll() { init(); final List list = new LinkedList(); synchronized (_ldefsByClient) { for (Iterator it = _ldefsByClient.values().iterator(); it.hasNext();) { list.addAll((List)it.next()); } } return list; } /** Returns a readonly collection of all device types. * @see #getByDeviceType */ public static final Collection getDeviceTypes() { init(); return _ldefsByClient.keySet(); } private static final void init() { DefinitionLoaders.load(); } /** Constructs a language defintion. * * <p>Note: the name and namespace of any language cannot be the same. * In other words, each language has two names, name and namespace. * You can find the language back by either of them via * {@link #lookup}. * * @param deviceType the device type; never null or empty * @param desktopURI the URI used to render a full page (i.e., the topmost page); never null. * @param pageURI the URI used to render a included page; never null. * @param ignoreCase whether the component name is case-insensitive * @param bNative whether it is native (i.e., all tags are * {@link org.zkoss.zk.ui.ext.Native}). * If native, the namespaces found in a ZUML page is no longer * used to specified a language. Rather, it is output to the client * directly. */ public LanguageDefinition(String deviceType, String name, String namespace, List extensions, String desktopURI, String pageURI, boolean ignoreCase, boolean bNative, Locator locator) { this(deviceType, name, namespace, extensions, desktopURI, desktopURI, pageURI, ignoreCase, bNative, locator); } /** Constructs a language defintion. * * <p>Note: the name and namespace of any language cannot be the same. * In other words, each language has two names, name and namespace. * You can find the language back by either of them via * {@link #lookup}. * * @param deviceType the device type; never null or empty * @param completeURI the URI used to render a complete page; never null. * @param desktopURI the URI used to render a full page (i.e., the topmost page); never null. * @param pageURI the URI used to render a included page; never null. * @param ignoreCase whether the component name is case-insensitive * @param bNative whether it is native (i.e., all tags are * {@link org.zkoss.zk.ui.ext.Native}). * If native, the namespaces found in a ZUML page is no longer * used to specified a language. Rather, it is output to the client * directly. * @since 3.0.5 */ public LanguageDefinition(String deviceType, String name, String namespace, List extensions, String completeURI, String desktopURI, String pageURI, boolean ignoreCase, boolean bNative, Locator locator) { if (deviceType == null || deviceType.length() == 0) throw new UiException("deviceType cannot be empty"); if (!Devices.exists(deviceType)) throw new DeviceNotFoundException(deviceType, MZk.NOT_FOUND, deviceType); if (ZK_NAMESPACE.equals(namespace)) throw new UiException(ZK_NAMESPACE+" is reserved."); if (name == null || name.length() == 0 || namespace == null || namespace.length() == 0 || completeURI == null || completeURI.length() == 0 || desktopURI == null || desktopURI.length() == 0 || pageURI == null || pageURI.length() == 0 || locator == null) throw new IllegalArgumentException(); _deviceType = deviceType; _name = name; _ns = namespace; _completeURI = completeURI; _desktopURI = desktopURI; _pageURI = pageURI; _locator = locator; _native = bNative; _compdefs = new ComponentDefinitionMap(ignoreCase); boolean replWarned = false; synchronized (_ldefByName) { if (!_ldefByName.containsKey(name) && _ldefByName.containsKey(namespace)) throw new UiException("Different language, "+name+", with the same namespace, "+namespace); _ldefByName.put(namespace, this); final Object old = _ldefByName.put(name, this); if (old != null) { final List ldefs = (List)_ldefsByClient.get(deviceType); if (ldefs != null) ldefs.remove(old); replWarned = true; log.warning("Replicated language: "+name+", overriden by "+this); //it is possible if zcommon.jar is placed in both //WEB-INF/lib and shared/lib, i.e., appear twice in the class path //We overwrite because shared/lib apears first due to //getResources is used (parent first) } } if (extensions != null) { synchronized (_ldefsByExt) { for (Iterator it = extensions.iterator(); it.hasNext();) { final String ext = (String)it.next(); final Object old = _ldefsByExt.put(ext, this); if (!replWarned && old != null) log.warning("Extension "+ext+", overriden by "+this); } } _exts = Collections.unmodifiableList(extensions); } else { _exts = Collections.EMPTY_LIST; } synchronized (_ldefsByClient) { List ldefs = (List)_ldefsByClient.get(deviceType); if (ldefs == null) _ldefsByClient.put(deviceType, ldefs = new LinkedList()); ldefs.add(this); } } /** Returns the device type that this definition belongs to. * * <p>A device type identifies the type of a client. For example, "ajax" * represents all HTML compatible clients (aka., browsers), * while "mil" represents clients that supports * <i>Mobile Interactive markup Language</i> (on Limited Connected Device, * such as mobile phones). */ public String getDeviceType() { return _deviceType; } /** Returns whether this is a native language. * If true, it means all tags in a ZUML page is considered as * native and all namespaces (except ZK namespace) are output * the client directly. * * @since 3.0.0 */ public boolean isNative() { return _native; } /** Returns name of this language. * Each language definition has a unique name and namespace. */ public String getName() { return _name; } /** Returns the name space. * Each language definition has a unique name and namespace. */ public String getNamespace() { return _ns; } /** Returns the readonly list of extensions that this language definition * is associated with (never null). * @since 2.4.1 */ public List getExtensions() { return _exts; } /** Returns the map of components defined in this language (never null). */ public ComponentDefinitionMap getComponentDefinitionMap() { return _compdefs; } /** Returns {@link ComponentDefinition} of the specified name. * * <p>Note: anonymous component definition won't be returned by * this method. * * @param name the name of the component definition. * @exception DefinitionNotFoundException is thrown if the definition * is not found */ public ComponentDefinition getComponentDefinition(String name) { final ComponentDefinition compdef = (ComponentDefinition)_compdefs.get(name); if (compdef == null) throw new DefinitionNotFoundException("Component definition not found: "+name); return compdef; } /** Returns {@link ComponentDefinition} of the specified name, or null * if not found. * It is the same as {@link #getComponentDefinition}, except this method * won't throw any exception. * * @param name the name of the component definition. * @since 3.0.2 */ public ComponentDefinition getComponentDefinitionIfAny(String name) { return (ComponentDefinition)_compdefs.get(name); } /** Returns {@link ComponentDefinition} of the specified class. * * <p>Note: anonymous component definition won't be returned by * this method. * * @param klass the class that implements the component. * @exception DefinitionNotFoundException is thrown if the definition * is not found */ public ComponentDefinition getComponentDefinition(Class klass) { final ComponentDefinition compdef = (ComponentDefinition)_compdefs.get(klass); if (compdef == null) throw new DefinitionNotFoundException("Component definition not found: "+klass); return compdef; } /** Returns whether the specified component is defined. */ public boolean hasComponentDefinition(String name) { return _compdefs.contains(name); } /** Adds a component definition. */ public void addComponentDefinition(ComponentDefinition compdef) { _compdefs.add(compdef); } /** Adds the script that shall execute when a page's interpreter * is initialized. In other words, they are evaluated only once for each * page. * * <p>Note: it doesn't test the existence of the specified language, * such that you can add the scripting language later. * * @param zslang the scripting language, say, Java. */ public void addInitScript(String zslang, String script) { if (zslang == null || zslang.length() == 0) throw new IllegalArgumentException("null or empty language"); if (script != null && script.length() > 0) { zslang = zslang.toLowerCase(); synchronized (_initscripts) { final String s = (String)_initscripts.get(zslang); _initscripts.put(zslang, s != null ? s + '\n' + script: script); } } } /** Returns the intial scripts of * the specified language, or null if no script. */ public String getInitScript(String zslang) { zslang = zslang.toLowerCase(); synchronized (_initscripts) { return (String)_initscripts.get(zslang); } } /** Adds the script that shall execute each time before evaluating * zscript. * * <p>Note: it doesn't test the existence of the specified language, * such that you can add the scripting language later. * * @param zslang the scripting language, say, Java. */ public void addEachTimeScript(String zslang, String script) { if (zslang == null || zslang.length() == 0) throw new IllegalArgumentException("null or empty language"); if (script != null && script.length() > 0) { zslang = zslang.toLowerCase(); synchronized (_eachscripts) { final String s = (String)_eachscripts.get(zslang); _eachscripts.put(zslang, s != null ? s + '\n' + script: script); } } } /** Returns the each-time scripts of * the specified language, or null if no scripts. * * <p>The each-time script is evaluated each time before evaluating * zscript. */ public String getEachTimeScript(String zslang) { zslang = zslang.toLowerCase(); synchronized (_eachscripts) { return (String)_eachscripts.get(zslang); } } /** Adds a {@link JavaScript} required by this language. */ public void addJavaScript(JavaScript js) { if (js == null) throw new IllegalArgumentException("null js"); synchronized (_js) { _js.add(js); } } /** Returns a readonly list of all {@link JavaScript} required * by this language. */ public List getJavaScripts() { return _rojs; } /** Adds the definition of a JavaScript module to this language. * <p>A JavaScript module represents a JavaScript file. This definition * is mainly used to define its version, such that ZK could encode * its URL such that browsers know when to reload it. */ public void addJavaScriptModule(String name, String version) { if (name == null || name.length() == 0 || version == null || version.length() == 0) throw new IllegalArgumentException(); _jsmods.put(name, version); } /** Returns a map of definitions of JavaScript modules, * (String name, String version). */ public Map getJavaScriptModules() { return _rojsmods; } /** Adds a {@link StyleSheet} required by this language. */ public void addStyleSheet(StyleSheet ss) { if (ss == null) throw new IllegalArgumentException("null ss"); synchronized (_ss) { _ss.add(ss); } } /** Returns a readonly list of all {@link StyleSheet} required * by this language. */ public List getStyleSheets() { return _ross; } /** Returns whether the component names are case-insensitive. */ public boolean isCaseInsensitive() { return _compdefs.isCaseInsensitive(); } /** Return the URI to render a full page (which might be an expression). * A full page is the topmost page of a desktop * (and its {@link Page#isComplete} is false). */ public String getDesktopURI() { return _desktopURI; } /** Return the URI to render an included page (which might be an expression). */ public String getPageURI() { return _pageURI; } /** Return the URI to render a complete page (which might be an expression). * A complete page is a page whose {@link Page#isComplete} is true. * @since 3.0.5 */ public String getCompleteURI() { return _completeURI; } /** Sets the macro template. * * @param moldURI the mold URI. If it starts with "class:", it * means a class that implements {@link org.zkoss.zk.ui.render.ComponentRenderer}. */ public void setMacroTemplate(Class klass, String moldURI) { _macrotmpl = klass != null ? new MacroTemplate(klass, moldURI): null; } /** Returns the component definition for the specified condition. * * @param pgdef the page definition the macro definitioin belongs to. * If null, it belongs to this language definition. * @exception UnsupportedOperationException if this language doesn't * support the macros * @since 3.0.0 */ public ComponentDefinition getMacroDefinition( String name, String macroURI, boolean inline, PageDefinition pgdef) { if (_macrotmpl == null) throw new UiException("Macro not supported by "+this); final ComponentDefinition compdef = ComponentDefinitionImpl.newMacroDefinition( pgdef != null ? null: this, pgdef, name, _macrotmpl.klass, macroURI, inline); compdef.addMold("default", _macrotmpl.moldURI); return compdef; } /** Sets the native template. * @since 3.0.0 */ public void setNativeTemplate(Class klass) { if (klass == null || !Component.class.isAssignableFrom(klass) || !Native.class.isAssignableFrom(klass)) throw new IllegalArgumentException("Illegal native class: "+klass); _nativedef = ComponentDefinitionImpl.newNativeDefinition(this, "native", klass);; } /** Returns the component definition for the native components. * * @exception UnsupportedOperationException if this language doesn't * support the native namespace * @since 3.0.0 */ public ComponentDefinition getNativeDefinition() { if (_nativedef == null) throw new UnsupportedOperationException("Native not supported by "+this); return _nativedef; } /** Sets the component and attribute names used to represent a label. * Since label is used a lot in a page, there is a simple way to create * an {@link ComponentInfo} by calling {@link #newLabelInfo}. * * <p>To be able to call {@link #newLabelInfo}, this method must * be called to define the component and attribute names used to create * an {@link ComponentInfo} for a label. */ public void setLabelTemplate(String compName, String propName, boolean raw) { _labeltmpl = compName != null ? new LabelTemplate(compName, propName, raw): null; } /** Constructs and returns an {@link ComponentInfo} for * the specified parent and text, */ public ComponentInfo newLabelInfo(ComponentInfo parent, String text) { if (_labeltmpl == null) throw new UiException("No default label component is supported by "+this); return _labeltmpl.newComponentInfo(parent, text); } /** Returns whether this language prefers the raw label. * By raw labels we mean the text shall not be trimmed and * shall be generated directly to the output (rather than wrapping * with, say, SPAN). */ public boolean isRawLabel() { return _labeltmpl != null && _labeltmpl.raw; } /** Adds the definition for the dynamic tag. * * @param compnm the component name used to represent any of dynamic * tags for this language. If null, it means this language definition * doesn't support the dynamic tag. * @param reservedAttrs a set of reserved attributes that * the dynamic tag support. The reserved attributes are the if, unless * and use attributes. */ public void setDynamicTagInfo(String compnm, Set reservedAttrs) { if (compnm != null && _dyntagnm != null) log.warning("Overwriting the definition of dynamic tag. Previous="+_dyntagnm+" New="+compnm+" for "+this); _dyntagnm = compnm; _dyntagDefn = null; _dyntagRvAttrs = compnm == null || reservedAttrs.isEmpty() ? null: Collections.unmodifiableSet(new HashSet(reservedAttrs)); } /** Returns the component defintion of the dynamic tag, or null if * this language doesn't support the dynamic tag. * @exception DefinitionNotFoundException is thrown if the definition * is not found */ public ComponentDefinition getDynamicTagDefinition() { if (_dyntagDefn == null) { //no sync since racing is OK if (_dyntagnm == null) return null; _dyntagDefn = getComponentDefinition(_dyntagnm); } return _dyntagDefn; } /** Returns whether a reserved attribute is used by the dynamic tag * ({@link #getDynamicTagDefinition}). */ public boolean isDynamicReservedAttributes(String attr) { return _dyntagRvAttrs != null && _dyntagRvAttrs.contains(attr); } /** Adds a tag lib. */ public void addTaglib(Taglib taglib) { synchronized (_taglibs) { _taglibs.add(taglib); _eval = null; //ask for re-gen } } /** Returns the evaluator based on this language definition (never null). * @since 3.0.0 */ public Evaluator getEvaluator() { if (_eval == null) _eval = newEvaluator(); return _eval; } private Evaluator newEvaluator() { return new SimpleEvaluator( Taglibs.getFunctionMapper(_taglibs, _locator), null); } /** Returns the evaluator reference (never null). * <p>This method is used only for implementation only. * @since 3.0.0 */ public EvaluatorRef getEvaluatorRef() { if (_evalr == null) _evalr = newEvaluatorRef(); return _evalr; } private EvaluatorRef newEvaluatorRef() { return new LangEvalRef(this); } //Object// public String toString() { return "[LanguageDefinition: "+_name+']'; } private static class MacroTemplate { private final Class klass; private final String moldURI; private MacroTemplate(Class klass, String moldURI) { if (moldURI == null || moldURI.length() == 0) throw new IllegalArgumentException("Macro mold UI required"); if (klass == null || !Component.class.isAssignableFrom(klass) || !Macro.class.isAssignableFrom(klass)) throw new IllegalArgumentException("Illegal macro class: "+klass); this.klass = klass; this.moldURI = moldURI; } } private class LabelTemplate { /** The component definition. */ private ComponentDefinition _compdef; /** The component name used for contructing a label. */ private final String _name; /** The component property used for contructing a label. */ private final String _prop; /** Whether the raw label is required. */ private final boolean raw; private LabelTemplate(String name, String prop, boolean raw) { if (name == null || name.length() == 0 || prop == null || prop.length() == 0) throw new IllegalArgumentException(); _name = name; _prop = prop; this.raw = raw; } private ComponentInfo newComponentInfo(ComponentInfo parent, String text) { if (_compdef == null) //no sync since racing is OK _compdef = getComponentDefinition(_name); final ComponentInfo info = new ComponentInfo(parent, _compdef); info.addProperty(_prop, text, null); return info; } } }

The table below shows all metrics for LanguageDefinition.java.

MetricValueDescription
BLOCKS78.00Number of blocks
BLOCK_COMMENT18.00Number of block comment lines
COMMENTS338.00Comment lines
COMMENT_DENSITY 0.97Comment density
COMPARISONS82.00Number of comparison operators
CYCLOMATIC135.00Cyclomatic complexity
DECL_COMMENTS82.00Comments in declarations
DOC_COMMENT314.00Number of javadoc comment lines
ELOC349.00Effective lines of code
EXEC_COMMENTS 1.00Comments in executable code
EXITS43.00Procedure exits
FUNCTIONS54.00Number of function declarations
HALSTEAD_DIFFICULTY57.52Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY141.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 1.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA002010.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 3.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA003434.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 0.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 0.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 3.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 1.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 1.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA010831.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA011033.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 0.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 0.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 0.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 2.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 1.00JAVA0144 Line exceeds maximum M characters
JAVA01451139.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 1.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 0.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 3.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 2.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 3.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 0.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES809.00Number of lines in the source file
LINE_COMMENT 6.00Number of line comments
LOC429.00Lines of code
LOGICAL_LINES211.00Number of statements
LOOPS 2.00Number of loops
NEST_DEPTH 4.00Maximum nesting depth
OPERANDS995.00Number of operands
OPERATORS1860.00Number of operators
PARAMS63.00Number of formal parameter declarations
PROGRAM_LENGTH2855.00Halstead program length
PROGRAM_VOCAB357.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS78.00Number of return points from functions
SIZE26981.00Size of the file in bytes
UNIQUE_OPERANDS320.00Number of unique operands
UNIQUE_OPERATORS37.00Number of unique operators
WHITESPACE42.00Number of whitespace lines