diff options
author | Raluca Sauciuc <ralucas@google.com> | 2017-06-14 17:37:26 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-06-14 17:37:26 +0000 |
commit | 903e87fa82521d049fcbcd6d1e4575b793faa514 (patch) | |
tree | beab767533ca040fab4aad51202d7442d281af4f /src/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java | |
parent | 8d9547a9f54ee85c424bb9c3595283aa011bf5e8 (diff) | |
parent | ad06f386190d159fe7bc8202b3abae2f1b218ecd (diff) | |
download | jdk8u_jaxp-903e87fa82521d049fcbcd6d1e4575b793faa514.tar.gz |
Merge 'jetbrains-master-mirror' into studio-master-dev
am: ad06f38619
Change-Id: Idd8914d54957955224c27bdc89bbfe91c848a9a0
Diffstat (limited to 'src/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java')
-rw-r--r-- | src/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java | 82 |
1 files changed, 39 insertions, 43 deletions
diff --git a/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java b/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java index d15d90e..7088850 100644 --- a/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java +++ b/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -17,9 +17,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * $Id: Parser.java,v 1.2.4.1 2005/09/13 12:14:32 pvedula Exp $ - */ package com.sun.org.apache.xalan.internal.xsltc.compiler; @@ -37,6 +34,7 @@ import com.sun.org.apache.xml.internal.serializer.utils.SystemIDResolver; import java.io.File; import java.io.IOException; import java.io.StringReader; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -44,7 +42,6 @@ import java.util.Map; import java.util.Properties; import java.util.Stack; import java.util.StringTokenizer; -import java.util.Vector; import javax.xml.XMLConstants; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; @@ -68,20 +65,20 @@ import org.xml.sax.helpers.AttributesImpl; */ public class Parser implements Constants, ContentHandler { - private static final String XSL = "xsl"; // standard prefix + private static final String XSL = "xsl"; // standard prefix private static final String TRANSLET = "translet"; // extension prefix private Locator _locator = null; - private XSLTC _xsltc; // Reference to the compiler object. - private XPathParser _xpathParser; // Reference to the XPath parser. - private Vector _errors; // Contains all compilation errors - private Vector _warnings; // Contains all compilation errors + private XSLTC _xsltc; // Reference to the compiler object. + private XPathParser _xpathParser; // Reference to the XPath parser. + private ArrayList<ErrorMsg> _errors; // Contains all compilation errors + private ArrayList<ErrorMsg> _warnings; // Contains all compilation warnings private Map<String, String> _instructionClasses; // Maps instructions to classes private Map<String, String[]> _instructionAttrs; // reqd and opt attrs - private Map<String, QName> _qNames; - private Map<String, Map> _namespaces; + private Map<String, QName> _qNames; + private Map<String, Map<String, QName>> _namespaces; private QName _useAttributeSets; private QName _excludeResultPrefixes; private QName _extensionElementPrefixes; @@ -113,8 +110,8 @@ public class Parser implements Constants, ContentHandler { _instructionAttrs = new HashMap<>(); _variableScope = new HashMap<>(); _template = null; - _errors = new Vector(); - _warnings = new Vector(); + _errors = new ArrayList<>(); + _warnings = new ArrayList<>(); _symbolTable = new SymbolTable(); _xpathParser = new XPathParser(this); _currentStylesheet = null; @@ -139,7 +136,6 @@ public class Parser implements Constants, ContentHandler { public void setOutput(Output output) { if (_output != null) { if (_output.getImportPrecedence() <= output.getImportPrecedence()) { - String cdata = _output.getCdata(); output.mergeOutput(_output); _output.disable(); _output = output; @@ -173,12 +169,13 @@ public class Parser implements Constants, ContentHandler { Object existing = _variableScope.get(var.getName().getStringRep()); if (existing != null) { if (existing instanceof Stack) { - Stack stack = (Stack)existing; + @SuppressWarnings("unchecked") + Stack<VariableBase> stack = (Stack<VariableBase>)existing; stack.push(var); } else if (existing instanceof VariableBase) { - Stack stack = new Stack(); - stack.push(existing); + Stack<VariableBase> stack = new Stack<>(); + stack.push((VariableBase)existing); stack.push(var); _variableScope.put(var.getName().getStringRep(), stack); } @@ -191,7 +188,8 @@ public class Parser implements Constants, ContentHandler { public void removeVariable(QName name) { Object existing = _variableScope.get(name.getStringRep()); if (existing instanceof Stack) { - Stack stack = (Stack)existing; + @SuppressWarnings("unchecked") + Stack<VariableBase> stack = (Stack<VariableBase>)existing; if (!stack.isEmpty()) stack.pop(); if (!stack.isEmpty()) return; } @@ -201,13 +199,14 @@ public class Parser implements Constants, ContentHandler { public VariableBase lookupVariable(QName name) { Object existing = _variableScope.get(name.getStringRep()); if (existing instanceof VariableBase) { - return((VariableBase)existing); + return (VariableBase)existing; } else if (existing instanceof Stack) { - Stack stack = (Stack)existing; - return((VariableBase)stack.peek()); + @SuppressWarnings("unchecked") + Stack<VariableBase> stack = (Stack<VariableBase>)existing; + return stack.peek(); } - return(null); + return null; } public void setXSLTC(XSLTC xsltc) { @@ -397,7 +396,6 @@ public class Parser implements Constants, ContentHandler { try { if (stylesheet != null) { stylesheet.parseContents(this); - final int precedence = stylesheet.getImportPrecedence(); final Iterator<SyntaxTreeNode> elements = stylesheet.elements(); while (elements.hasNext()) { SyntaxTreeNode child = elements.next(); @@ -704,8 +702,6 @@ public class Parser implements Constants, ContentHandler { new String[] {"stylesheet-prefix", "result-prefix"}); } - - /** * Initialize the _instructionClasses map, which maps XSL element * names to Java classes in this package. @@ -779,6 +775,7 @@ public class Parser implements Constants, ContentHandler { /** * Add primops and base functions to the symbol table. */ + @SuppressWarnings("unused") private void initSymbolTable() { MethodType I_V = new MethodType(Type.Int, Type.Void); MethodType I_R = new MethodType(Type.Int, Type.Real); @@ -971,12 +968,12 @@ public class Parser implements Constants, ContentHandler { String local, Attributes attributes) { SyntaxTreeNode node = null; - QName qname = getQName(uri, prefix, local); + QName qname = getQName(uri, prefix, local); String className = _instructionClasses.get(qname.getStringRep()); if (className != null) { try { - final Class clazz = ObjectFactory.findProviderClass(className, true); + final Class<?> clazz = ObjectFactory.findProviderClass(className, true); node = (SyntaxTreeNode)clazz.newInstance(); node.setQName(qname); node.setParser(this); @@ -1023,7 +1020,7 @@ public class Parser implements Constants, ContentHandler { else { Stylesheet sheet = _xsltc.getStylesheet(); if ((sheet != null) && (sheet.isExtension(uri))) { - if (sheet != (SyntaxTreeNode)_parentStack.peek()) { + if (sheet != _parentStack.peek()) { node = new UnsupportedElement(uri, prefix, local, true); UnsupportedElement elem = (UnsupportedElement)node; ErrorMsg msg = @@ -1156,7 +1153,6 @@ public class Parser implements Constants, ContentHandler { node.setParser(this); node.setParent(parent); node.setLineNumber(line); -// System.out.println("e = " + text + " " + node); return node; } } @@ -1191,7 +1187,7 @@ public class Parser implements Constants, ContentHandler { if (size > 0) { System.err.println(new ErrorMsg(ErrorMsg.COMPILER_ERROR_KEY)); for (int i = 0; i < size; i++) { - System.err.println(" " + _errors.elementAt(i)); + System.err.println(" " + _errors.get(i)); } } } @@ -1204,7 +1200,7 @@ public class Parser implements Constants, ContentHandler { if (size > 0) { System.err.println(new ErrorMsg(ErrorMsg.COMPILER_WARNING_KEY)); for (int i = 0; i < size; i++) { - System.err.println(" " + _warnings.elementAt(i)); + System.err.println(" " + _warnings.get(i)); } } } @@ -1217,42 +1213,42 @@ public class Parser implements Constants, ContentHandler { case Constants.INTERNAL: // Unexpected internal errors, such as null-ptr exceptions, etc. // Immediately terminates compilation, no translet produced - _errors.addElement(error); + _errors.add(error); break; case Constants.UNSUPPORTED: // XSLT elements that are not implemented and unsupported ext. // Immediately terminates compilation, no translet produced - _errors.addElement(error); + _errors.add(error); break; case Constants.FATAL: // Fatal error in the stylesheet input (parsing or content) // Immediately terminates compilation, no translet produced - _errors.addElement(error); + _errors.add(error); break; case Constants.ERROR: // Other error in the stylesheet input (parsing or content) // Does not terminate compilation, no translet produced - _errors.addElement(error); + _errors.add(error); break; case Constants.WARNING: // Other error in the stylesheet input (content errors only) // Does not terminate compilation, a translet is produced - _warnings.addElement(error); + _warnings.add(error); break; } } - public Vector getErrors() { + public ArrayList<ErrorMsg> getErrors() { return _errors; } - public Vector getWarnings() { + public ArrayList<ErrorMsg> getWarnings() { return _warnings; } /************************ SAX2 ContentHandler INTERFACE *****************/ - private Stack _parentStack = null; + private Stack<SyntaxTreeNode> _parentStack = null; private Map<String, String> _prefixMapping = null; /** @@ -1262,7 +1258,7 @@ public class Parser implements Constants, ContentHandler { _root = null; _target = null; _prefixMapping = null; - _parentStack = new Stack(); + _parentStack = new Stack<>(); } /** @@ -1318,7 +1314,7 @@ public class Parser implements Constants, ContentHandler { _root = element; } else { - SyntaxTreeNode parent = (SyntaxTreeNode)_parentStack.peek(); + SyntaxTreeNode parent = _parentStack.peek(); parent.addElement(element); element.setParent(parent); } @@ -1349,7 +1345,7 @@ public class Parser implements Constants, ContentHandler { */ public void characters(char[] ch, int start, int length) { String string = new String(ch, start, length); - SyntaxTreeNode parent = (SyntaxTreeNode)_parentStack.peek(); + SyntaxTreeNode parent = _parentStack.peek(); if (string.length() == 0) return; |