incubator-imperius-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From daw...@apache.org
Subject svn commit: r961811 - in /incubator/imperius/trunk: imperius-javaspl/src/main/java/org/apache/imperius/javaspl/ imperius-splcore/src/main/antlr/org/apache/imperius/spl/parser/compiler/ imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/im...
Date Thu, 08 Jul 2010 15:34:39 GMT
Author: dawood
Date: Thu Jul  8 15:34:39 2010
New Revision: 961811

URL: http://svn.apache.org/viewvc?rev=961811&view=rev
Log:
Improved error communication during parsing so that PolicyParser.createInternalPolicyObject()
can return the syntax errors in the thrown exception.

Modified:
    incubator/imperius/trunk/imperius-javaspl/src/main/java/org/apache/imperius/javaspl/JavaDataCollectorImpl.java
    incubator/imperius/trunk/imperius-splcore/src/main/antlr/org/apache/imperius/spl/parser/compiler/cimspl.tree.g
    incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyParser.java
    incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyParserImpl.java
    incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/compiler/symboltable/SPLSymbolTable.java
    incubator/imperius/trunk/imperius-splcore/src/main/resources/org/apache/imperius/util/messages.properties

Modified: incubator/imperius/trunk/imperius-javaspl/src/main/java/org/apache/imperius/javaspl/JavaDataCollectorImpl.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-javaspl/src/main/java/org/apache/imperius/javaspl/JavaDataCollectorImpl.java?rev=961811&r1=961810&r2=961811&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-javaspl/src/main/java/org/apache/imperius/javaspl/JavaDataCollectorImpl.java
(original)
+++ incubator/imperius/trunk/imperius-javaspl/src/main/java/org/apache/imperius/javaspl/JavaDataCollectorImpl.java
Thu Jul  8 15:34:39 2010
@@ -43,6 +43,7 @@ import org.apache.imperius.spl.parser.co
 import org.apache.imperius.spl.parser.compiler.symboltable.Symbol;
 import org.apache.imperius.spl.parser.exceptions.SPLException;
 import org.apache.imperius.spl.parser.statements.impl.ArgumentImpl;
+import org.apache.imperius.util.SPLLogger;
 
 
 
@@ -112,8 +113,8 @@ public class JavaDataCollectorImpl imple
 			}
 		} catch (Exception e) {
 
-			e.printStackTrace();
-			throw new SPLException(e.getMessage());
+			// e.printStackTrace();
+			throw new SPLException("Loading symbols for class " + className, e);
 		}
 
 	}

Modified: incubator/imperius/trunk/imperius-splcore/src/main/antlr/org/apache/imperius/spl/parser/compiler/cimspl.tree.g
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/antlr/org/apache/imperius/spl/parser/compiler/cimspl.tree.g?rev=961811&r1=961810&r2=961811&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/antlr/org/apache/imperius/spl/parser/compiler/cimspl.tree.g
(original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/antlr/org/apache/imperius/spl/parser/compiler/cimspl.tree.g
Thu Jul  8 15:34:39 2010
@@ -151,7 +151,7 @@ importstatement[SPLSymbolTable symTab] r
 	  	catch (SPLException exep)
 	  	{ 
 	  			ASTWithLineNumber q = (ASTWithLineNumber)i1;
-	  			errorMsg = exep.getMessage() + "at line" + q.getLine();
+	  			errorMsg = exep.getMessage() + " at line " + q.getLine();
 	  			errorList.add(errorMsg);
 	  			//System.out.println(exep.getMessage() + "at line" + q.getLine()); 
 	  			
@@ -510,7 +510,7 @@ expr[SPLSymbolTable symTab] returns [Exp
 				//System.out.println("TreeParser::Exception inserting symbol at line "+q.getLine());
 				//System.err.println("$SPLTreeParser$ Error at line no#"+q.getLine()+":"+excep.getMessage());
 				errorList.add(errorMsg);
-				throw new RecognitionException(excep.getMessage());
+				throw new RecognitionException(excep.getLocalizedMessage());
         	}
         }
         |#(t1:LOR e1=expr[symTab] e2=expr[symTab]) 

Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyParser.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyParser.java?rev=961811&r1=961810&r2=961811&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyParser.java
(original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyParser.java
Thu Jul  8 15:34:39 2010
@@ -32,6 +32,13 @@ import org.apache.imperius.spl.parser.st
 public interface PolicyParser
 {
     
+	/**
+	 * @param PolicyRuleName
+	 * @param PolicyString
+	 * @return
+	 * @throws SPLException if a parse error occurs.  Exception message will contain indication
+	 * of where the problem(s) are and is suitable for printing to the user.
+	 */
     public SPLPolicy createInternalPolicyObject(String PolicyRuleName,
             String PolicyString) throws SPLException;
     

Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyParserImpl.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyParserImpl.java?rev=961811&r1=961810&r2=961811&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyParserImpl.java
(original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/datastore/impl/PolicyParserImpl.java
Thu Jul  8 15:34:39 2010
@@ -26,6 +26,8 @@ package org.apache.imperius.spl.datastor
 
 import java.io.Reader;
 import java.io.StringReader;
+import java.util.Iterator;
+import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -114,15 +116,15 @@ public class PolicyParserImpl implements
 	{
 		logger.entering(sourceClass, Thread.currentThread().getName() + " "
 				+ "parseFile");
+		// Create a scanner that reads from the input stream passed to us
+		SPLLexer lexer = new SPLLexer(r);
+		lexer.setFilename(f);
 
+		// Create a parser that reads from the scanner
+		SPLParser parser = new SPLParser(lexer);
 		try 
 		{
-			// Create a scanner that reads from the input stream passed to us
-			SPLLexer lexer = new SPLLexer(r);
-			lexer.setFilename(f);
 
-			// Create a parser that reads from the scanner
-			SPLParser parser = new SPLParser(lexer);
 			parser.setASTNodeClass("org.apache.imperius.spl.parser.compiler.ASTWithLineNumber");
 			parser.setFilename(f);
 			
@@ -131,10 +133,11 @@ public class PolicyParserImpl implements
 			// start parsing at the compilationUnit rule
 			parser.splpolicy();
 			
-			if(parser.getErrorList() != null && parser.getErrorList().size() > 0)
+			String errMsg = getErrorMessages(parser.getErrorList());
+			if(errMsg != null)
 			{
 				throw new SPLException(Messages
-						.getString("SPL_POLICY_PARSING_EXCEPTION_MSG"));
+						.getString("SPL_POLICY_PARSING_EXCEPTION_MSG" + "\n" + errMsg));
 			}
 			
 			logger.fine(Thread.currentThread().getName() + " parsing file completed here...");
@@ -151,7 +154,7 @@ public class PolicyParserImpl implements
 			}
 
 			// do something with the tree
-			SPLPolicy pol = doTreeAction(f, parser.getAST(), parser.getTokenNames());
+			SPLPolicy pol = doTreeAction(f, parser, parser.getAST(), parser.getTokenNames());
 			
 			logger.exiting(sourceClass, Thread.currentThread().getName() + " "
 					+ "parseFile");
@@ -160,17 +163,40 @@ public class PolicyParserImpl implements
 		} 
 		catch (Exception e) 
 		{
-			logger.severe(e.getMessage());
-			throw new SPLException(e.getMessage());
+//			e.printStackTrace();
+			String errMsg = getErrorMessages(parser.getErrorList());
+			if(errMsg != null)	{
+				logger.severe(errMsg + "\n" + e.getMessage());
+				throw new SPLException(errMsg, e);
+			} else {
+				logger.severe(e.getMessage());
+				throw new SPLException(e);
+			}
 		}
 	}
 
+	private static String getErrorMessages(List errors) {
+		if(errors == null || errors.size() == 0)
+			return null;
+		Iterator iter = errors.iterator();
+		StringBuilder msg = null;
+		while (iter.hasNext()) {
+			if (msg == null) {
+				msg = new StringBuilder();
+			} else {
+				msg.append("\n");
+			}
+			msg.append(iter.next());
+		}
+		return msg.toString();
+		
+	}
 	public static void traverseTree(AST t) 
 	{
 
 	}
 
-	public static synchronized SPLPolicy doTreeAction(String f, AST t,
+	private static synchronized SPLPolicy doTreeAction(String f, SPLParser parser, AST t,
 			String[] tokenNames) throws SPLException 
 	{
 		logger.entering(sourceClass, Thread.currentThread().getName() + " "
@@ -188,17 +214,22 @@ public class PolicyParserImpl implements
 			DataCollector dc = DataCollectorFactory.getDataCollector();
 			SPLSymbolTable st = new SPLSymbolTable();
 			SPLPolicy cp = tparse.splpolicy(t, dc, st);
-			if(tparse.getErrorList() != null && tparse.getErrorList().size() > 0)
+			String errMsgs = getErrorMessages(tparse.getErrorList());
+			if(errMsgs != null)
 			{
-				throw new SPLException(Messages.getString("SPL_POLICY_TREE_PARSING_EXCEPTION_MSG"));
+				parser.getErrorList().addAll(tparse.getErrorList());
+				throw new SPLException(Messages.getString("SPL_POLICY_TREE_PARSING_EXCEPTION_MSG") +
": " + errMsgs);
 			}
 			logger.exiting(sourceClass, Thread.currentThread().getName() + " "
 					+ "doTreeAction");
 			return cp;
 		}
-		catch (RecognitionException e) 
+		catch (Exception e) 
 		{
-			throw new SPLException(e.getMessage());
+			parser.getErrorList().addAll(tparse.getErrorList());
+			String errMsgs = getErrorMessages(tparse.getErrorList());
+			errMsgs = "Error parsing policy tree: \n" + errMsgs;
+			throw new SPLException(errMsgs, e);
 		}
 	}
 

Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/compiler/symboltable/SPLSymbolTable.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/compiler/symboltable/SPLSymbolTable.java?rev=961811&r1=961810&r2=961811&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/compiler/symboltable/SPLSymbolTable.java
(original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/compiler/symboltable/SPLSymbolTable.java
Thu Jul  8 15:34:39 2010
@@ -339,7 +339,7 @@ public class SPLSymbolTable 
 	
 	private void _populateAnchorClassSymbols(String className, 
 			String qualifier, 
-			List instanceInfoList)
+			List instanceInfoList) throws SPLException
 	{
 		logger.entering(sourceClass,Thread.currentThread().getName()+" " +
 				"populateAnchorElementSymbols");
@@ -408,7 +408,8 @@ public class SPLSymbolTable 
 		catch (SPLException e) 
 		{
 			// TODO Auto-generated catch block
-			e.printStackTrace();
+//			e.printStackTrace();
+			throw e;
 		} 
 		
 		

Modified: incubator/imperius/trunk/imperius-splcore/src/main/resources/org/apache/imperius/util/messages.properties
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/resources/org/apache/imperius/util/messages.properties?rev=961811&r1=961810&r2=961811&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/resources/org/apache/imperius/util/messages.properties
(original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/resources/org/apache/imperius/util/messages.properties
Thu Jul  8 15:34:39 2010
@@ -47,7 +47,7 @@ SPL_COLLECT_OPERATION_EXP_EXCEPTION1_MSG
 SPL_COLLECT_OPERATION_EXP_EXCEPTION2_MSG =  parameter in CollectOperation expression needs
to be a string expression
 SPL_COLLECT_OPERATION_EXP_EXCEPTION3_MSG =  parameter in CollectOperation expression needs
to be a boolean expression
 SPL_POSTCOLLECT_EXP_EXCEPTION1_MSG =  array index should be integer and not {0}
-SPL_SYMBOL_DOES_NOT_EXIST_EXCEPTION_MSG =  symbol {0} doesnot exist
+SPL_SYMBOL_DOES_NOT_EXIST_EXCEPTION_MSG =  symbol {0} does not exist
 SPL_INVALID_METHOD_INVOCATION_SECTION_EXCEPTION_MSG = Cannot invoke methods in the {0} sections
 SPL_ARRAY_INDEX_OUT_OF_RANGE_EXCEPTION_MSG = array index is out of range 
 SPL_VALIDATE_METHOD_NOT_SUPPORTED_EXCEPTION_MSG = validate method not supported for the expression
: {0}



Mime
View raw message