Parser.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
COMPARISONSNumber of comparison operators
JAVA0034JAVA0034 Missing braces in if statement
CYCLOMATICCyclomatic complexity
EXITSProcedure exits
PROGRAM_LENGTHHalstead program length
OPERANDSNumber of operands
OPERATORSNumber of operators
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
ELOCEffective lines of code
UNIQUE_OPERANDSNumber of unique operands
LOGICAL_LINESNumber of statements
INTERFACE_COMPLEXITYInterface complexity
RETURNSNumber of return points from functions
EXEC_COMMENTSComments in executable code
SIZESize of the file in bytes
LOOPSNumber of loops
PROGRAM_VOCABHalstead program vocabulary
LOCLines of code
BLOCKSNumber of blocks
PARAMSNumber of formal parameter declarations
LINE_COMMENTNumber of line comments
JAVA0254JAVA0254 Use enhanced for loop construct instead of Iterator
LINESNumber of lines in the source file
JAVA0115JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0145JAVA0145 Tab character used in source file
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0160JAVA0160 Method does not throw specified exception
JAVA0177JAVA0177 Variable declaration missing initializer
DECL_COMMENTSComments in declarations
JAVA0123JAVA0123 Use all three components of for loop
JAVA0285JAVA0285 Dereference of potentially null variable
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0049JAVA0049 Nested block at depth N (maximum: M)
FUNCTIONSNumber of function declarations
JAVA0035JAVA0035 Missing braces in for statement
JAVA0163JAVA0163 Empty statement
JAVA0130JAVA0130 Non-static method does not use instance fields
UNIQUE_OPERATORSNumber of unique operators
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0080JAVA0080 Import declaration not used
JAVA0282JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
NEST_DEPTHMaximum nesting depth
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
COMMENTSComment lines
JAVA0173JAVA0173 Unused method parameter
/* Parser.java {{IS_NOTE Purpose: Description: History: Tue May 31 14:26:18 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.lang.reflect.Modifier; import java.lang.reflect.Method; import java.util.List; import java.util.LinkedList; import java.util.Collections; import java.util.Collection; import java.util.ListIterator; import java.util.Iterator; import java.util.Map; import java.util.HashMap; import java.util.Set; import java.util.LinkedHashSet; import java.io.File; import java.io.Reader; import java.net.URL; import org.zkoss.lang.D; import org.zkoss.lang.Library; import org.zkoss.lang.Classes; import org.zkoss.lang.PotentialDeadLockException; import org.zkoss.util.CollectionsX; import org.zkoss.util.logging.Log; import org.zkoss.util.resource.Locator; import org.zkoss.idom.Namespace; import org.zkoss.idom.Document; import org.zkoss.idom.Element; import org.zkoss.idom.Text; import org.zkoss.idom.CData; import org.zkoss.idom.Item; import org.zkoss.idom.Attribute; import org.zkoss.idom.ProcessingInstruction; import org.zkoss.idom.util.IDOMs; import org.zkoss.idom.input.SAXBuilder; import org.zkoss.xel.taglib.Taglib; import org.zkoss.xel.util.Evaluators; import org.zkoss.xel.util.MethodFunction; import org.zkoss.web.servlet.Servlets; import org.zkoss.zk.ui.WebApp; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.UiException; import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.util.ConditionImpl; import org.zkoss.zk.ui.sys.WebAppCtrl; import org.zkoss.zk.ui.sys.RequestInfo; import org.zkoss.zk.ui.sys.UiFactory; import org.zkoss.zk.ui.impl.RequestInfoImpl; import org.zkoss.zk.ui.impl.ZScriptInitiator; import org.zkoss.zk.ui.metainfo.impl.*; /** * Used to prase the ZUL file * @author tomyeh */ public class Parser { private static final Log log = Log.lookup(Parser.class); private final WebApp _wapp; private final Locator _locator; /** Constructor. * * @param locator the locator used to locate taglib and other resources. * If null, wapp is assumed ({@link WebApp} is also assumed). */ public Parser(WebApp wapp, Locator locator) { if (wapp == null) throw new IllegalArgumentException("null"); _wapp = wapp; _locator = locator != null ? locator: (Locator)wapp; } /** Parses the specified file. * * @param path the request path. * It is used as {@link org.zkoss.zk.ui.Page#getRequestPath}, or null * if not available. */ public PageDefinition parse(File file, String path) throws Exception { //if (log.debugable()) log.debug("Parsing "+file); final PageDefinition pgdef = parse(new SAXBuilder(true, false, true).build(file), Servlets.getExtension(file.getName())); pgdef.setRequestPath(path); return pgdef; } /** Parses the specified URL. * * @param path the request path. * It is used as {@link org.zkoss.zk.ui.Page#getRequestPath}, or null * if not available. */ public PageDefinition parse(URL url, String path) throws Exception { //if (log.debugable()) log.debug("Parsing "+url); final PageDefinition pgdef = parse(new SAXBuilder(true, false, true).build(url), Servlets.getExtension(url.toExternalForm())); pgdef.setRequestPath(path); return pgdef; } /** Parses from the specified reader. * * @param extension the default extension if doc (of reader) doesn't specify * an language. Ignored if null. * If extension is null and the content doesn't specify a language, * the language called "xul/html" is assumed. */ public PageDefinition parse(Reader reader, String extension) throws Exception { //if (log.debugable()) log.debug("Parsing "+reader); return parse(new SAXBuilder(true, false, true).build(reader), extension); } /** Parss the raw content directly from a DOM tree. * * @param extension the default extension if doc doesn't specify * an language. Ignored if null. * If extension is null and the content doesn't specify a language, * the language called "xul/html" is assumed. */ public PageDefinition parse(Document doc, String extension) throws Exception { //1. parse the page and import directive if any final List pis = new LinkedList(), imports = new LinkedList(); String lang = null; for (Iterator it = doc.getChildren().iterator(); it.hasNext();) { final Object o = it.next(); if (!(o instanceof ProcessingInstruction)) continue; final ProcessingInstruction pi = (ProcessingInstruction)o; final String target = pi.getTarget(); if ("page".equals(target)) { //we handle only the language attribute here final Map params = pi.parseData(); final String l = (String)params.remove("language"); if (l != null) { noEL("language", l, pi); lang = l; } if (!params.isEmpty()) pis.add(pi); //process it later } else if ("import".equals(target)) { //import final Map params = pi.parseData(); final String src = (String)params.remove("src"); final String dirs = (String)params.remove("directives"); if (!params.isEmpty()) log.warning("Ignored unknown attributes: "+params.keySet()+", "+pi.getLocator()); noELnorEmpty("src", src, pi); noEL("directives", dirs, pi); imports.add(new String[] {src, dirs}); } else { pis.add(pi); } } //2. Create PageDefinition final LanguageDefinition langdef = extension != null && lang == null? LanguageDefinition.getByExtension(extension): LanguageDefinition.lookup(lang); final PageDefinition pgdef = new PageDefinition(langdef, getLocator()); //3. resolve imports if (!imports.isEmpty()) { final RequestInfo ri = new RequestInfoImpl(_wapp, null, null, null, _locator); final UiFactory uf = ((WebAppCtrl)_wapp).getUiFactory(); for (Iterator it = imports.iterator(); it.hasNext();) { final String[] imprt = (String[])it.next(); final String path = imprt[0], dirs = imprt[1]; try { final PageDefinition pd = uf.getPageDefinition(ri, path); if (pd == null) throw new UiException("Import page not found: "+path); pgdef.imports(pd, parseToArray(dirs)); } catch (PotentialDeadLockException ex) { throw new UiException("Recursive import: "+path, ex); } } } //4. Processing the rest of processing instructions at the top level for (Iterator it = pis.iterator(); it.hasNext();) parse(pgdef, (ProcessingInstruction)it.next()); //5. Processing from the root element final Element root = doc.getRootElement(); if (root != null) parse(pgdef, pgdef, root, new AnnotationHelper(), false); return pgdef; } private static Class locateClass(String clsnm) throws Exception { try { return Classes.forNameByThread(clsnm); } catch (ClassNotFoundException ex) { throw new ClassNotFoundException("Class not found: "+clsnm, ex); } } /** Parses a list of string separated by comma, into a String array. */ private static String[] parseToArray(String s) { if (s == null) return null; Collection ims = CollectionsX.parse(null, s, ',', false); //NO EL return (String[])ims.toArray(new String[ims.size()]); } //-- derive to override --// /** returns locator for locating resources. */ public Locator getLocator() { return _locator; } /** Parse processing instruction. */ private void parse(PageDefinition pgdef, ProcessingInstruction pi) throws Exception { final String target = pi.getTarget(); final Map params = pi.parseData(); if ("page".equals(target)) { parsePageDirective(pgdef, pi, params); } else if ("init".equals(target)) { parseInitDirective(pgdef, pi, params); } else if ("variable-resolver".equals(target) || "function-mapper".equals(target)) { final String clsnm = (String)params.remove("class"); if (isEmpty(clsnm)) throw new UiException("The class attribute is required, "+pi.getLocator()); final List args = new LinkedList(); for (int j = 0;; ++j) { final String arg = (String)params.remove("arg" + j); if (arg == null) break; args.add(arg); } if (!params.isEmpty()) log.warning("Ignored unknown attributes: "+params.keySet()+", "+pi.getLocator()); if ("variable-resolver".equals(target)) pgdef.addVariableResolverInfo( clsnm.indexOf("${") >= 0 ? //class supports EL new VariableResolverInfo(clsnm, args): new VariableResolverInfo(locateClass(clsnm), args)); else pgdef.addFunctionMapperInfo( clsnm.indexOf("${") >= 0 ? //class supports EL new FunctionMapperInfo(clsnm, args): new FunctionMapperInfo(locateClass(clsnm), args)); } else if ("component".equals(target)) { //declare a component parseComponentDirective(pgdef, pi, params); } else if ("taglib".equals(target)) { final String uri = (String)params.remove("uri"); final String prefix = (String)params.remove("prefix"); if (!params.isEmpty()) log.warning("Ignored unknown attributes: "+params.keySet()+", "+pi.getLocator()); if (uri == null || prefix == null) throw new UiException("Both uri and prefix attribute are required, "+pi.getLocator()); //if (D.ON && log.debugable()) log.debug("taglib: prefix="+prefix+" uri="+uri); noEL("prefix", prefix, pi); noEL("uri", uri, pi); //not support EL (kind of chicken-egg issue) pgdef.addTaglib(new Taglib(prefix, toAbsoluteURI(uri, false))); } else if ("evaluator".equals(target)) { parseEvaluatorDirective(pgdef, pi, params); } else if ("xel-method".equals(target)) { parseXelMethod(pgdef, pi, params); } else if ("link".equals(target) || "meta".equals(target)) { //declare a header element pgdef.addHeaderInfo(new HeaderInfo(target, params)); } else if ("root-attributes".equals(target)) { for (Iterator it = pi.parseData().entrySet().iterator(); it.hasNext();) { final Map.Entry me = (Map.Entry)it.next(); pgdef.setRootAttribute((String)me.getKey(), (String)me.getValue()); } } else if ("forward".equals(target)) { //forward final String uri = (String)params.remove("uri"); final String ifc = (String)params.remove("if"); final String unless = (String)params.remove("unless"); if (!params.isEmpty()) log.warning("Ignored unknown attributes: "+params.keySet()+", "+pi.getLocator()); noEmpty("uri", uri, pi); pgdef.addForwardInfo( new ForwardInfo(uri, ConditionImpl.getInstance(ifc, unless))); } else if ("import".equals(target)) { //import throw new UiException("The import directive can be used only at the top level, "+pi.getLocator()); } else { log.warning("Unknown processing instruction: "+target+", "+pi.getLocator()); } } /** Process the init directive. */ private void parseInitDirective(PageDefinition pgdef, ProcessingInstruction pi, Map params) throws Exception { final List args = new LinkedList(); for (int j = 0;; ++j) { final String arg = (String)params.remove("arg" + j); if (arg == null) break; args.add(arg); } final String clsnm = (String)params.remove("class"); final String zsrc = (String)params.remove("zscript"); if (!params.isEmpty()) log.warning("Ignored unknown attributes: "+params.keySet()+", "+pi.getLocator()); if (isEmpty(clsnm)) { if (isEmpty(zsrc)) throw new UiException("Either the class or zscript attribute must be specified, "+pi.getLocator()); final ZScript zs; final String zslang = pgdef.getZScriptLanguage(); if (zsrc.indexOf("${") >= 0) { zs = new ZScript(pgdef.getEvaluatorRef(), zslang, zsrc, null, getLocator()); //URL in EL } else { final URL url = getLocator().getResource(zsrc); if (url == null) throw new UiException("File not found: "+zsrc+", at "+pi.getLocator()); //don't throw FileNotFoundException since Tomcat 'eats' it zs = new ZScript(pgdef.getEvaluatorRef(), zslang, url, null); } pgdef.addInitiatorInfo( new InitiatorInfo(new ZScriptInitiator(zs), args)); } else { if (!isEmpty(zsrc)) throw new UiException("You cannot specify both class and zscript, "+pi.getLocator()); pgdef.addInitiatorInfo( clsnm.indexOf("${") >= 0 ? //class supports EL new InitiatorInfo(clsnm, args): new InitiatorInfo(locateClass(clsnm), args)); //Note: we don't resolve the class name later because //no zscript run before init (and better performance) } } /** Process the page directive. */ private static void parsePageDirective(PageDefinition pgdef, ProcessingInstruction pi, Map params) throws Exception { for (Iterator it = pi.parseData().entrySet().iterator(); it.hasNext();) { final Map.Entry me = (Map.Entry)it.next(); final String nm = (String)me.getKey(); final String val = (String)me.getValue(); if ("language".equals(nm)) { if (!(pi.getParent() instanceof Document)) log.warning("Ignored language attribute since the page directive is not at the top level, "+pi.getLocator()); } else if ("title".equals(nm)) { pgdef.setTitle(val); } else if ("style".equals(nm)) { pgdef.setStyle(val); } else if ("id".equals(nm)) { pgdef.setId(val); } else if ("zscriptLanguage".equals(nm) || "zscript-language".equals(nm)) { //backward compatible with 2.4.x noELnorEmpty("zscriptLanguage", val, pi); pgdef.setZScriptLanguage(val); } else if ("cacheable".equals(nm)) { noELnorEmpty("cacheable", val, pi); pgdef.setCacheable(Boolean.valueOf("true".equals(val))); } else if ("contentType".equals(nm)) { noEmpty("contentType", val, pi); pgdef.setContentType(val); } else if ("docType".equals(nm)) { noEmpty("docType", val, pi); pgdef.setDocType("<!DOCTYPE " + val + '>'); } else if ("xml".equals(nm)) { noEmpty("xml", val, pi); pgdef.setFirstLine("<?xml " + val + "?>"); } else if ("complete".equals(nm)) { pgdef.setComplete("true".equals(val)); } else { log.warning("Ignored unknown attribute: "+nm+", "+pi.getLocator()); } } } /** Process the component directive. */ private void parseComponentDirective(PageDefinition pgdef, ProcessingInstruction pi, Map params) throws Exception { final String name = (String)params.remove("name"); noELnorEmpty("name", name, pi); String macroURI = (String)params.remove("macroURI"); if (macroURI == null) macroURI = (String)params.remove("macro-uri"); //backward compatible (2.4.x) final String extds = (String)params.remove("extends"); final String clsnm = (String)params.remove("class"); ComponentDefinition compdef; if (macroURI != null) { //if (D.ON && log.finerable()) log.finer("macro component definition: "+name); final String inline = (String)params.remove("inline"); noEL("inline", inline, pi); noEL("macroURI", macroURI, pi); //no EL because pagedef must be loaded to resolve //the impl class before creating an instance of macro final boolean bInline = "true".equals(inline); compdef = pgdef.getLanguageDefinition().getMacroDefinition( name, toAbsoluteURI(macroURI, false), bInline, pgdef); if (!isEmpty(clsnm)) { if (bInline) throw new UiException("class not allowed with inline macros, "+pi.getLocator()); noEL("class", clsnm, pi); compdef.setImplementationClass(clsnm); //Resolve later since might defined in zscript } } else if (extds != null) { //extends //if (D.ON && log.finerable()) log.finer("Override component definition: "+name); noEL("extends", extds, pi); final ComponentDefinition ref = pgdef.getLanguageDefinition() .getComponentDefinition(extds); if (ref.isMacro()) throw new UiException("Unable to extend from a macro component, "+pi.getLocator()); compdef = ref.clone(null, name); if (!isEmpty(clsnm)) { noEL("class", clsnm, pi); compdef.setImplementationClass(clsnm); //Resolve later since might defined in zscript } } else { //if (D.ON && log.finerable()) log.finer("Add component definition: name="+name); noELnorEmpty("class", clsnm, pi); final ComponentDefinitionImpl cdi = new ComponentDefinitionImpl(null, pgdef, name, (Class)null); cdi.setCurrentDirectory(getLocator().getDirectory()); //mold URI requires it compdef = cdi; compdef.setImplementationClass(clsnm); //Resolve later since might be defined in zscript } pgdef.addComponentDefinition(compdef); String moldnm = (String)params.remove("moldName"); if (moldnm == null) moldnm = (String)params.remove("mold-name"); //backward comaptible (2.4.x) noEL("moldName", moldnm, pi); String moldURI = (String)params.remove("moldURI"); if (moldURI == null) moldURI = (String)params.remove("mold-uri"); //backward comaptible (2.4.x) if (!isEmpty(moldURI)) compdef.addMold(isEmpty(moldnm) ? "default": moldnm, moldURI.startsWith("class:") ? moldURI: toAbsoluteURI(moldURI, true)); for (Iterator e = params.entrySet().iterator(); e.hasNext();) { final Map.Entry me = (Map.Entry)e.next(); compdef.addProperty((String)me.getKey(), (String)me.getValue()); } } /** Parse the evaluator directive. */ private static void parseEvaluatorDirective(PageDefinition pgdef, ProcessingInstruction pi, Map params) throws Exception { final String clsnm = (String)params.remove("class"); if (clsnm != null && clsnm.length() > 0) { noELnorEmpty("class", clsnm, pi); pgdef.setExpressionFactoryClass(locateClass(clsnm)); } else { //name has the lower priorty final String nm = (String)params.remove("name"); if (nm != null) pgdef.setExpressionFactoryClass(Evaluators.getEvaluatorClass(nm)); } final String imports = (String)params.remove("import"); if (imports != null && imports.length() > 0) { Collection ims = CollectionsX.parse(null, imports, ',', false); //No EL for (Iterator it = ims.iterator(); it.hasNext();) { final String im = (String)it.next(); final int k = im.indexOf('='); String nm = k > 0 ? im.substring(0, k).trim(): null; String cn = (k >= 0 ? im.substring(k + 1): im).trim(); if (cn.length() != 0) { final Class cs = locateClass(cn); if (nm == null || nm.length() == 0) { final int j = cn.lastIndexOf('.'); nm = j >= 0 ? cn.substring(j + 1): cn; } pgdef.addExpressionImport(nm, cs); } } } } /** Parse the XEL method. */ private static void parseXelMethod(PageDefinition pgdef, ProcessingInstruction pi, Map params) throws Exception { final String prefix = (String)params.remove("prefix"); noELnorEmpty("prefix", prefix, pi); final String nm = (String)params.remove("name"); noELnorEmpty("name", nm, pi); final String clsnm = (String)params.remove("class"); noELnorEmpty("class", clsnm, pi); final String sig = (String)params.remove("signature"); noELnorEmpty("signature", sig, pi); final Method mtd; try { final Class cls = Classes.forNameByThread(clsnm); mtd = Classes.getMethodBySignature(cls, sig, null); } catch (ClassNotFoundException ex) { throw new UiException("Class not found: "+clsnm+", "+pi.getLocator()); } catch (Exception ex) { throw new UiException("Method not found: "+sig+" in "+clsnm+", "+pi.getLocator()); } if ((mtd.getModifiers() & Modifier.STATIC) == 0) throw new UiException("Not a static method: "+mtd); pgdef.addXelMethod(prefix, nm, new MethodFunction(mtd)); } private static void noELnorEmpty(String nm, String val, Item item) throws UiException { if (isEmpty(val)) throw new UiException(nm + " cannot be empty, "+item.getLocator()); noEL(nm, val, item); } private static void noEL(String nm, String val, Item item) throws UiException { if (val != null && val.indexOf("${") >= 0) throw new UiException(nm+" does not support EL expressions, "+item.getLocator()); } /** Checks whether the value is an empty string. * Note: Like {@link #noEL}, it is OK to be null!! * To check neither null nor empty, use IDOMs.getRequiredAttribute. */ private static void noEmpty(String nm, String val, Item item) throws UiException { if (val != null && val.length() == 0) throw new UiException(nm+" cannot be empty, "+item.getLocator()); } private String toAbsoluteURI(String uri, boolean allowEL) { if (uri != null && uri.length() > 0) { final char cc = uri.charAt(0); if (cc != '/' && cc != '~' && (!allowEL || uri.indexOf("${") < 0) && !Servlets.isUniversalURL(uri)) { final String dir = getLocator().getDirectory(); if (dir != null && dir.length() > 0) return dir.charAt(dir.length() - 1) == '/' ? dir + uri: dir + '/' + uri; } } return uri; } /** Parses the specified elements. * @param bNativeContent whether to consider the child element all native * It is true if a component definition with text-as is found */ private void parse(PageDefinition pgdef, NodeInfo parent, Collection items, AnnotationHelper annHelper, boolean bNativeContent) throws Exception { final ComponentInfo parentInfo = parent instanceof ComponentInfo ? (ComponentInfo)parent: null; for (Iterator it = items.iterator(); it.hasNext();) { final Object o = it.next(); if (o instanceof Element) { parse(pgdef, bNativeContent ? parentInfo: parent, (Element)o, annHelper, bNativeContent); } else if (o instanceof ProcessingInstruction) { parse(pgdef, (ProcessingInstruction)o); } else if ((o instanceof Text) || (o instanceof CData)) { String label = ((Item)o).getText(), trimLabel = label.trim();; if (label.length() == 0) continue; LanguageDefinition parentlang = getLanguageDefinition(parent); if (parentlang == null) parentlang = pgdef.getLanguageDefinition(); ComponentInfo pi = parentInfo; while (pi instanceof ZkInfo) { NodeInfo n = pi.getParent(); if (n instanceof ComponentInfo) { pi = (ComponentInfo)n; } else { pi = null; break; } } //Ingore blank text if no need to preserved if (trimLabel.length() == 0 && pi != null && !pi.isBlankPreserved() && !(pi instanceof NativeInfo)) continue; //consider as a label if (isZkSwitch(parent)) throw new UiException("Only <zk> can be used in <zk switch>, "+((Item)o).getLocator()); if (pi instanceof NativeInfo) { parentInfo.appendChild( new TextInfo(pgdef.getEvaluatorRef(), label)); //Don't trim if native (3.5.0) } else { final String textAs = parentInfo != null ? parentInfo.getTextAs(): null; if (textAs != null) { parentInfo.addProperty(textAs, trimLabel, null); } else { if (isTrimLabel() && !parentlang.isRawLabel()) { if (trimLabel.length() == 0) continue; //ignore label = trimLabel; } final ComponentInfo labelInfo = parentlang.newLabelInfo(parentInfo, label); if (trimLabel.length() == 0) labelInfo.setReplaceableText(label); //yes, it can be replaced by a text } } } } } /** Returns whether to trim the leading and trailing whitespaces * of labels. * <p>Default: false since 3.0.4. * * <p>If you want to trim like 3.0.4 and ealier did, you can specify * the system property called "org.zkoss.zk.ui.parser.trimLabel" * with a non-empty value. */ private static boolean isTrimLabel() { if (_trimLabel == null) { final String s = Library.getProperty("org.zkoss.zk.ui.parser.trimLabel"); _trimLabel = Boolean.valueOf(s != null && s.length() > 0); } return _trimLabel.booleanValue(); } private static Boolean _trimLabel; private static final LanguageDefinition getLanguageDefinition(NodeInfo node) { for (; node != null; node = node.getParent()) { if (node instanceof ComponentInfo) { LanguageDefinition langdef = ((ComponentInfo)node).getLanguageDefinition(); if (langdef != null) return langdef; } else if (node instanceof PageDefinition) { return ((PageDefinition)node).getLanguageDefinition(); } } return null; } /** Parse an component definition specified in the given element. * @param bNativeContent whether to consider the child element all native * It is true if a component definition with text-as is found */ private void parse(PageDefinition pgdef, NodeInfo parent, Element el, AnnotationHelper annHelper, boolean bNativeContent) throws Exception { final String nm = el.getLocalName(); final Namespace ns = el.getNamespace(); final String pref = ns != null ? ns.getPrefix(): ""; final String uri = ns != null ? ns.getURI(): ""; LanguageDefinition langdef = pgdef.getLanguageDefinition(); if ("zscript".equals(nm) && isZkElement(langdef, nm, pref, uri)) { parseZScript(parent, el, annHelper); } else if ("attribute".equals(nm) && isZkElement(langdef, nm, pref, uri)) { if (!(parent instanceof ComponentInfo)) throw new UiException("<attribute> cannot be the root element, "+el.getLocator()); parseAttribute(pgdef, (ComponentInfo)parent, el, annHelper); } else if ("custom-attributes".equals(nm) && isZkElement(langdef, nm, pref, uri)) { parseCustomAttributes(langdef, parent, el, annHelper); } else if ("variables".equals(nm) && isZkElement(langdef, nm, pref, uri)) { parseVariables(langdef, parent, el, annHelper); } else if (LanguageDefinition.ANNO_NAMESPACE.equals(uri)) { parseAnnotation(el, annHelper); } else { //if (D.ON && log.debugable()) log.debug("component: "+nm+", ns:"+ns); final ComponentInfo compInfo; final boolean bzk = "zk".equals(nm) && isZkElement(langdef, nm, pref, uri); if (bzk) { if (annHelper.clear()) log.warning("Annotations are ignored since <zk> doesn't support them, "+el.getLocator()); compInfo = new ZkInfo(parent); } else { if (isZkSwitch(parent)) throw new UiException("Only <zk> can be used in <zk switch>, "+el.getLocator()); boolean prefRequired = uri.startsWith(LanguageDefinition.NATIVE_NAMESPACE_PREFIX); boolean bNative = bNativeContent || prefRequired || LanguageDefinition.NATIVE_NAMESPACE.equals(uri); if (!bNative && langdef.isNative() && !langdef.getNamespace().equals(uri)) bNative = prefRequired = ("".equals(pref) && "".equals(uri)) || !LanguageDefinition.exists(uri); //Spec: if pref/URI not specified => native // if uri unknown => native if (bNative) { if (annHelper.clear()) log.warning("Annotations are ignored since native doesn't support them, "+el.getLocator()); final NativeInfo ni; compInfo = ni = new NativeInfo( parent, langdef.getNativeDefinition(), prefRequired && pref.length() > 0 ? pref + ":" + nm: nm); //add declared namespace if starting with native: final Collection dns = el.getDeclaredNamespaces(); if (!dns.isEmpty()) addDeclaredNamespace(ni, dns, langdef); } else { final boolean defaultNS = isDefaultNS(langdef, pref, uri); final LanguageDefinition complangdef = defaultNS ? langdef: LanguageDefinition.lookup(uri); ComponentDefinition compdef = defaultNS ? pgdef.getComponentDefinitionMap().get(nm): null; if (compdef != null) { compInfo = new ComponentInfo(parent, compdef); } else if (complangdef.hasComponentDefinition(nm)) { compdef = complangdef.getComponentDefinition(nm); compInfo = new ComponentInfo(parent, compdef); langdef = complangdef; } else { compdef = complangdef.getDynamicTagDefinition(); if (compdef == null) throw new DefinitionNotFoundException("Component definition not found: "+nm+" in "+complangdef+", "+el.getLocator()); compInfo = new ComponentInfo(parent, compdef, nm); langdef = complangdef; } //process use first because addProperty needs it String use = el.getAttributeValue("use"); if (use != null) { use = use.trim(); if (use.length() != 0) compInfo.setImplementationClass(use); //Resolve later since might defined in zscript } } } String ifc = null, unless = null, forEach = null, forEachBegin = null, forEachEnd = null; AnnotationHelper attrAnnHelper = null; for (Iterator it = el.getAttributeItems().iterator(); it.hasNext();) { final Attribute attr = (Attribute)it.next(); final Namespace attrns = attr.getNamespace(); final String attnm = attr.getLocalName(); final String attval = attr.getValue(); if (attrns != null && LanguageDefinition.ANNO_NAMESPACE.equals(attrns.getURI())) { if (bzk) warnWrongZkAttr(attr); else { if (attrAnnHelper == null) attrAnnHelper = new AnnotationHelper(); attrAnnHelper.addByRawValue(attnm, attval); } } else if ("apply".equals(attnm) && isZkAttr(langdef, attrns)) { if (bzk) warnWrongZkAttr(attr); else compInfo.setApply(attval); } else if ("forward".equals(attnm) && isZkAttr(langdef, attrns)) { if (bzk) warnWrongZkAttr(attr); else compInfo.setForward(attval); } else if ("if".equals(attnm) && isZkAttr(langdef, attrns)) { ifc = attval; } else if ("unless".equals(attnm) && isZkAttr(langdef, attrns)) { unless = attval; } else if ("forEach".equals(attnm) && isZkAttr(langdef, attrns)) { forEach = attval; } else if ("forEachBegin".equals(attnm) && isZkAttr(langdef, attrns)) { forEachBegin = attval; } else if ("forEachEnd".equals(attnm) && isZkAttr(langdef, attrns)) { forEachEnd = attval; } else if ("fulfill".equals(attnm) && isZkAttr(langdef, attrns)) { if (bzk) warnWrongZkAttr(attr); else compInfo.setFulfill(attval); } else if (bzk) { if ("switch".equals(attnm) || "choose".equals(attnm)) { if (isZkSwitch(parent)) throw new UiException("<zk "+attnm+"> cannot be used in <zk switch/choose>, "+el.getLocator()); ((ZkInfo)compInfo).setSwitch(attval); } else if ("case".equals(attnm)) { if (!isZkSwitch(parent)) throw new UiException("<zk case> can be used only in <zk switch>, "+attr.getLocator()); ((ZkInfo)compInfo).setCase(attval); } else if ("when".equals(attnm)) { ifc = attval; } else { final String attpref = attrns != null ? attrns.getPrefix(): null; if (attpref == null || (!"xmlns".equals(attpref) && !"xml".equals(attpref))) warnWrongZkAttr(attr); } } else if (!("use".equals(attnm) && isZkAttr(langdef, attrns))) { final String attpref = attrns != null ? attrns.getPrefix(): ""; final String attruri = attrns != null ? attrns.getURI(): ""; if (!"xmlns".equals(attpref) && !("xmlns".equals(attnm) && "".equals(attpref)) && !"http://www.w3.org/2001/XMLSchema-instance".equals(attruri)) { final int len = attval.length(); if (len >= 3 && attval.charAt(0) == '@' && attval.charAt(1) == '{' && attval.charAt(len-1) == '}') { //annotation if (attrAnnHelper == null) attrAnnHelper = new AnnotationHelper(); attrAnnHelper.addByCompoundValue( attval.substring(2, len -1)); attrAnnHelper.applyAnnotations(compInfo, "self".equals(attnm) ? null: attnm, true); } else { addAttribute(compInfo, attrns, attnm, attval, null); if (attrAnnHelper != null) attrAnnHelper.applyAnnotations(compInfo, attnm, true); } } } } compInfo.setCondition(ConditionImpl.getInstance(ifc, unless)); compInfo.setForEach(forEach, forEachBegin, forEachEnd); annHelper.applyAnnotations(compInfo, null, true); parse(pgdef, compInfo, el.getChildren(), annHelper, bNativeContent); //recursive //optimize native components if (compInfo instanceof NativeInfo && !compInfo.getChildren().isEmpty()) optimizeNativeInfos((NativeInfo)compInfo); } } private void warnWrongZkAttr(Attribute attr) { log.warning("Attribute "+attr.getName()+" ignored in <zk>, "+attr.getLocator()); } private boolean isZkSwitch(NodeInfo nodeInfo) { return nodeInfo instanceof ZkInfo && ((ZkInfo)nodeInfo).withSwitch(); } private void parseZScript(NodeInfo parent, Element el, AnnotationHelper annHelper) { if (el.getAttributeItem("forEach") != null) throw new UiException("forEach not applicable to <zscript>, "+el.getLocator()); if (annHelper.clear()) log.warning("Annotations are ignored since <zscript> doesn't support them, "+el.getLocator()); final String ifc = el.getAttributeValue("if"), unless = el.getAttributeValue("unless"), zsrc = el.getAttributeValue("src"); final boolean deferred = "true".equals(el.getAttributeValue("deferred")); String zslang = el.getAttributeValue("language"); if (zslang == null) { zslang = parent.getPageDefinition().getZScriptLanguage(); //we have to resolve it in parser since a page might be //created by use of createComponents } else { noEmpty("language", zslang, el); noEL("language", zslang, el); } final ConditionImpl cond = ConditionImpl.getInstance(ifc, unless); if (!isEmpty(zsrc)) { //ignore empty (not error) final ZScript zs; if (zsrc.indexOf("${") >= 0) { zs = new ZScript(parent.getEvaluatorRef(), zslang, zsrc, cond, getLocator()); } else { final URL url = getLocator().getResource(zsrc); if (url == null) throw new UiException("File not found: "+zsrc+", at "+el.getLocator()); //don't throw FileNotFoundException since Tomcat 'eats' it zs = new ZScript(parent.getEvaluatorRef(), zslang, url, cond); } if (deferred) zs.setDeferred(true); parent.appendChild(zs); } final String script = el.getText(true); if (!isEmpty(script)) { final ZScript zs = new ZScript(parent.getEvaluatorRef(), zslang, script, cond); if (deferred) zs.setDeferred(true); parent.appendChild(zs); } } private void parseAttribute(PageDefinition pgdef, ComponentInfo parent, Element el, AnnotationHelper annHelper) throws Exception { if (el.getAttributeItem("forEach") != null) throw new UiException("forEach not applicable to attribute, "+el.getLocator()); //Test if native content is used boolean bNativeContent = false; for (Iterator it = el.getChildren().iterator(); it.hasNext();) if (it.next() instanceof Element) { bNativeContent = true; break; } final String attnm = IDOMs.getRequiredAttributeValue(el, "name"); final ConditionImpl cond = ConditionImpl.getInstance( el.getAttributeValue("if"), el.getAttributeValue("unless")); if (bNativeContent) { if (Events.isValid(attnm)) throw new UiException("Event listeners not support native content"); final NativeInfo nativeInfo = new NativeInfo( parent.getEvaluatorRef(), pgdef.getLanguageDefinition().getNativeDefinition(), ""); parse(pgdef, nativeInfo, el.getChildren(), annHelper, true); parent.addProperty(attnm, nativeInfo, cond); } else { final String trim = el.getAttributeValue("trim"); noEL("trim", trim, el); final String attval = el.getText(trim != null && "true".equals(trim)); addAttribute(parent, null, attnm, attval, cond); } annHelper.applyAnnotations(parent, attnm, true); } private static void parseCustomAttributes(LanguageDefinition langdef, NodeInfo parent, Element el, AnnotationHelper annHelper) throws Exception { //if (!el.getElements().isEmpty()) // throw new UiException("Child elements are not allowed for <custom-attributes>, "+el.getLocator()); if (parent instanceof PageDefinition) throw new UiException("custom-attributes must be used under a component, "+el.getLocator()); if (annHelper.clear()) log.warning("Annotations are ignored since <custom-attribute> doesn't support them, "+el.getLocator()); String ifc = null, unless = null, scope = null, composite = null; final Map attrs = new HashMap(); for (Iterator it = el.getAttributeItems().iterator(); it.hasNext();) { final Attribute attr = (Attribute)it.next(); final Namespace attrns = attr.getNamespace(); final String attnm = attr.getLocalName(); final String attval = attr.getValue(); if ("if".equals(attnm) && isZkElementAttr(langdef, attrns)) { ifc = attval; } else if ("unless".equals(attnm) && isZkElementAttr(langdef, attrns)) { unless = attval; } else if ("scope".equals(attnm) && isZkElementAttr(langdef, attrns)) { scope = attval; } else if ("composite".equals(attnm) && isZkElementAttr(langdef, attrns)) { composite = attval; } else if ("forEach".equals(attnm) && isZkElementAttr(langdef, attrns)) { throw new UiException("forEach not applicable to <custom-attributes>, "+el.getLocator()); } else { attrs.put(attnm, attval); } } if (!attrs.isEmpty()) parent.appendChild(new AttributesInfo( parent.getEvaluatorRef(), attrs, scope, composite, ConditionImpl.getInstance(ifc, unless))); } private static void parseVariables(LanguageDefinition langdef, NodeInfo parent, Element el, AnnotationHelper annHelper) throws Exception { //if (!el.getElements().isEmpty()) // throw new UiException("Child elements are not allowed for <variables> element, "+el.getLocator()); if (annHelper.clear()) log.warning("Annotations are ignored since <variables> doesn't support them, "+el.getLocator()); String ifc = null, unless = null, composite = null; boolean local = false; final Map vars = new HashMap(); for (Iterator it = el.getAttributeItems().iterator(); it.hasNext();) { final Attribute attr = (Attribute)it.next(); final Namespace attrns = attr.getNamespace(); final String attnm = attr.getLocalName(); final String attval = attr.getValue(); if ("if".equals(attnm) && isZkElementAttr(langdef, attrns)) { ifc = attval; } else if ("unless".equals(attnm) && isZkElementAttr(langdef, attrns)) { unless = attval; } else if ("local".equals(attnm) && isZkElementAttr(langdef, attrns)) { local = "true".equals(attval); } else if ("composite".equals(attnm) && isZkElementAttr(langdef, attrns)) { composite = attval; } else if ("forEach".equals(attnm) && isZkElementAttr(langdef, attrns)) { throw new UiException("forEach not applicable to <variables>, "+el.getLocator()); } else { vars.put(attnm, attval); } } if (!vars.isEmpty()) parent.appendChild(new VariablesInfo( parent.getEvaluatorRef(), vars, local, composite, ConditionImpl.getInstance(ifc, unless))); } private static void parseAnnotation(Element el, AnnotationHelper annHelper) throws Exception { if (!el.getElements().isEmpty()) throw new UiException("Child elements are not allowed for the annotations, "+el.getLocator()); final Map attrs = new HashMap(); for (Iterator it = el.getAttributeItems().iterator(); it.hasNext();) { final Attribute attr = (Attribute)it.next(); attrs.put(attr.getLocalName(), attr.getValue()); } annHelper.add(el.getLocalName(), attrs); } /** Whether a string is null or empty. */ private static boolean isEmpty(String s) { return s == null || s.length() == 0; } /** Whether the name space belongs to the default language. */ private static final boolean isDefaultNS(LanguageDefinition langdef, String pref, String uri) { return (!langdef.isNative() && "".equals(pref) && "".equals(uri)) || langdef.getNamespace().equals(uri); } /** Returns whether it is a ZK element. * @param pref namespace's prefix * @param uri namespace's URI */ private static final boolean isZkElement(LanguageDefinition langdef, String nm, String pref, String uri) { if (isDefaultNS(langdef, pref, uri)) return !langdef.hasComponentDefinition(nm); return LanguageDefinition.ZK_NAMESPACE.equals(uri); } /** Returns whether it is a ZK attribute (in a non-ZK element). */ private static final boolean isZkAttr(LanguageDefinition langdef, Namespace attrns) { //if native we will make sure URI is ZK or lang's namespace if (langdef.isNative() && attrns != null && "".equals(attrns.getPrefix())) return false; //if navtive, "" means not ZK return isZkElementAttr(langdef, attrns); } /** Similar to {@link #isZkAttr}, except it doesn't care isNative * (i.e., we consider it as a ZK attribute unless a namespace * other than ZK is specified. */ private static final boolean isZkElementAttr(LanguageDefinition langdef, Namespace attrns) { if (attrns == null //not possible; just in case || "".equals(attrns.getPrefix())) //w3c attr: uri is "" if prefix "" return true; final String uri = attrns.getURI(); return LanguageDefinition.ZK_NAMESPACE.equals(uri) || langdef.getNamespace().equals(uri); } /** Parse an attribute and adds it to the definition. */ private static void addAttribute(ComponentInfo compInfo, Namespace attrns, String name, String value, ConditionImpl cond) throws Exception { if (Events.isValid(name)) { boolean bZkAttr = attrns == null; if (!bZkAttr) { String pref = attrns.getPrefix(), uri = attrns.getURI(); LanguageDefinition langdef = compInfo.getLanguageDefinition(); if (langdef == null) bZkAttr = true; else if (isDefaultNS(langdef, pref, uri)) bZkAttr = !langdef.isDynamicReservedAttributes("[event]"); else bZkAttr = LanguageDefinition.ZK_NAMESPACE.equals(uri); } if (bZkAttr) { final ZScript zscript = ZScript.parseContent(value); if (zscript.getLanguage() == null) zscript.setLanguage( compInfo.getPageDefinition().getZScriptLanguage()); //resolve it here instead of runtime since createComponents compInfo.addEventHandler(name, zscript, cond); return; //done } } compInfo.addProperty(name, value, cond); } /** Adds the declared namespaces to the native info, if necessary. */ private static void addDeclaredNamespace( NativeInfo nativeInfo, Collection namespaces, LanguageDefinition langdef) { for (Iterator it = namespaces.iterator(); it.hasNext();) { final Namespace ns = (Namespace)it.next(); final String uri = ns.getURI(); boolean bNatPrefix = uri.startsWith(LanguageDefinition.NATIVE_NAMESPACE_PREFIX); if (bNatPrefix || (langdef.isNative() && !LanguageDefinition.ZK_NAMESPACE.equals(uri) && !LanguageDefinition.ANNO_NAMESPACE.equals(uri) && !LanguageDefinition.NATIVE_NAMESPACE.equals(uri) && !langdef.getNamespace().equals(uri))) nativeInfo.addDeclaredNamespace( new Namespace(ns.getPrefix(), bNatPrefix ? uri.substring(LanguageDefinition.NATIVE_NAMESPACE_PREFIX.length()): uri)); } } /** Minimizes the native infos such that UiEngine creates * the minimal number of components. */ private static void optimizeNativeInfos(NativeInfo compInfo) { //Optimize 1: merge to prolog, if the first children are //native and have no child for (Iterator it = compInfo.getChildren().iterator(); it.hasNext();) { final Object o = it.next(); if (o instanceof NativeInfo) { final NativeInfo childInfo = (NativeInfo)o; if (!childInfo.getChildren().isEmpty()) break; childInfo.setParentDirectly(null); } else if (o instanceof ComponentInfo) { break; } compInfo.addPrologChildDirectly(o); it.remove(); //detach it from the children list } //Optimize 2: merge to epilog if the last children, are //native and have no child int sz = compInfo.getChildren().size(); if (sz >= 0) { final ListIterator it = compInfo.getChildren().listIterator(sz); while (it.hasPrevious()) { final Object o = it.previous(); if (o instanceof NativeInfo) { final NativeInfo childInfo = (NativeInfo)o; if (!childInfo.getChildren().isEmpty()) { it.next(); break; } childInfo.setParentDirectly(null); } else if (o instanceof ComponentInfo) { it.next(); break; } } while (it.hasNext()) { final Object o = it.next(); compInfo.addEpilogChildDirectly(o); it.remove(); } } //Optimize 3: merge to split child //If there is only one native child, we make it a split child and //make all its children (grand-chidren) up one level if (compInfo.getChildren().size() == 1 && !compInfo.withForEach() && compInfo.getSplitChild() == null /*just in case*/) { Iterator it = compInfo.getChildren().iterator(); final Object o = it.next(); if (o instanceof NativeInfo) { final NativeInfo childInfo = (NativeInfo)o; childInfo.setParentDirectly(null); compInfo.setSplitChild(childInfo); it.remove(); for (it = childInfo.getChildren().iterator(); it.hasNext();) { final Object gc = it.next(); it.remove(); compInfo.appendChildDirectly(gc); if (gc instanceof ComponentInfo) ((ComponentInfo)gc).setParentDirectly(compInfo); } } } } }

The table below shows all metrics for Parser.java.

MetricValueDescription
BLOCKS186.00Number of blocks
BLOCK_COMMENT18.00Number of block comment lines
COMMENTS152.00Comment lines
COMMENT_DENSITY 0.18Comment density
COMPARISONS331.00Number of comparison operators
CYCLOMATIC341.00Cyclomatic complexity
DECL_COMMENTS28.00Comments in declarations
DOC_COMMENT84.00Number of javadoc comment lines
ELOC849.00Effective lines of code
EXEC_COMMENTS39.00Comments in executable code
EXITS204.00Procedure exits
FUNCTIONS37.00Number of function declarations
HALSTEAD_DIFFICULTY110.12Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY225.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
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.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
JAVA003485.00JAVA0034 Missing braces in if statement
JAVA0035 2.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 3.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 5.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 1.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 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 0.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
JAVA010853.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA011012.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
JAVA011514.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 4.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 3.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 2.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 0.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
JAVA01453224.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 7.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 1.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 1.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 6.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
JAVA025414.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 0.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 2.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 4.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
LINES1195.00Number of lines in the source file
LINE_COMMENT50.00Number of line comments
LOC960.00Lines of code
LOGICAL_LINES515.00Number of statements
LOOPS22.00Number of loops
NEST_DEPTH 6.00Maximum nesting depth
OPERANDS3096.00Number of operands
OPERATORS5645.00Number of operators
PARAMS91.00Number of formal parameter declarations
PROGRAM_LENGTH8741.00Halstead program length
PROGRAM_VOCAB783.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS134.00Number of return points from functions
SIZE44578.00Size of the file in bytes
UNIQUE_OPERANDS731.00Number of unique operands
UNIQUE_OPERATORS52.00Number of unique operators
WHITESPACE83.00Number of whitespace lines