groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cchamp...@apache.org
Subject [44/62] [abbrv] [partial] groovy git commit: Move Java source set into `src/main/java`
Date Sun, 17 Dec 2017 14:01:55 GMT
http://git-wip-us.apache.org/repos/asf/groovy/blob/0edfcde9/src/main/java/org/codehaus/groovy/GroovyBugError.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/GroovyBugError.java b/src/main/java/org/codehaus/groovy/GroovyBugError.java
new file mode 100644
index 0000000..30ed7de
--- /dev/null
+++ b/src/main/java/org/codehaus/groovy/GroovyBugError.java
@@ -0,0 +1,111 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy;
+
+/**
+ * This class represents an error that is thrown when a bug is 
+ * recognized inside the runtime. Basically it is thrown when
+ * a constraint is not fulfilled that should be fulfilled.
+ * 
+ * @author Jochen Theodorou
+ */
+public class GroovyBugError extends AssertionError {
+    
+    // message string
+    private String message;
+    // optional exception
+    private final Exception exception;
+
+    /**
+     * constructs a bug error using the given text
+     * @param message the error message text
+     */
+    public GroovyBugError( String message ) {
+        this(message, null);
+    }
+    
+    /**
+     * Constructs a bug error using the given exception
+     * @param exception cause of this error
+     */
+    public GroovyBugError( Exception exception ) {
+        this(null, exception);
+    }
+    
+    /**
+     * Constructs a bug error using the given exception and
+     * a text with additional information about the cause 
+     * @param msg additional information about this error
+     * @param exception cause of this error
+     */
+    public GroovyBugError( String msg, Exception exception ) {
+        this.exception = exception;
+        this.message = msg;
+    }
+
+    /**
+     * Returns a String representation of this class by calling <code>getMessage()</code>.
 
+     * @see #getMessage()
+     */
+    public String toString() {
+        return getMessage();
+    }
+    
+    /**
+     * Returns the detail message string of this error. The message 
+     * will consist of the bug text prefixed by "BUG! " if there this
+     * instance was created using a message. If this error was
+     * constructed without using a bug text the message of the cause 
+     * is used prefixed by "BUG! UNCAUGHT EXCEPTION: "
+     *  
+     * @return the detail message string of this error.
+     */
+    public String getMessage() {
+        if( message != null )
+        {
+            return "BUG! "+message;
+        }
+        else
+        {
+            return "BUG! UNCAUGHT EXCEPTION: " + exception.getMessage();
+        }
+    }
+    
+    public Throwable getCause() {
+        return this.exception;
+    }    
+    
+    /**
+     * Returns the bug text to describe this error
+     */
+    public String getBugText(){
+        if( message != null ){
+            return message;
+        } else {
+            return exception.getMessage();
+        }
+    }
+    
+    /**
+     * Sets the bug text to describe this error
+     */
+    public void setBugText(String msg) {
+        this.message = msg;
+    }
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/0edfcde9/src/main/java/org/codehaus/groovy/GroovyException.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/GroovyException.java b/src/main/java/org/codehaus/groovy/GroovyException.java
new file mode 100644
index 0000000..582da48
--- /dev/null
+++ b/src/main/java/org/codehaus/groovy/GroovyException.java
@@ -0,0 +1,52 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy;
+
+public class GroovyException extends Exception implements GroovyExceptionInterface {
+    private boolean fatal = true;
+
+    public GroovyException() {
+    }
+
+    public GroovyException(String message) {
+        super(message);
+    }
+
+    public GroovyException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public GroovyException(boolean fatal) {
+        super();
+        this.fatal = fatal;
+    }
+
+    public GroovyException(String message, boolean fatal) {
+        super(message);
+        this.fatal = fatal;
+    }
+
+    public boolean isFatal() {
+        return fatal;
+    }
+
+    public void setFatal(boolean fatal) {
+        this.fatal = fatal;
+    }
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/0edfcde9/src/main/java/org/codehaus/groovy/GroovyExceptionInterface.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/GroovyExceptionInterface.java b/src/main/java/org/codehaus/groovy/GroovyExceptionInterface.java
new file mode 100644
index 0000000..bfff301
--- /dev/null
+++ b/src/main/java/org/codehaus/groovy/GroovyExceptionInterface.java
@@ -0,0 +1,31 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy;
+
+/**
+ *  An interface for use by all Groovy compiler exceptions.
+ */
+
+public interface GroovyExceptionInterface {
+
+    boolean isFatal();
+
+    void setFatal( boolean fatal );
+    
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/0edfcde9/src/main/java/org/codehaus/groovy/antlr/ASTParserException.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/antlr/ASTParserException.java b/src/main/java/org/codehaus/groovy/antlr/ASTParserException.java
new file mode 100644
index 0000000..204674b
--- /dev/null
+++ b/src/main/java/org/codehaus/groovy/antlr/ASTParserException.java
@@ -0,0 +1,54 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.antlr;
+
+import antlr.collections.AST;
+import org.codehaus.groovy.syntax.ParserException;
+
+/**
+ * Thrown when trying to parse the AST
+ *
+ */
+public class ASTParserException extends ParserException {
+    private final AST ast;
+
+    public ASTParserException(ASTRuntimeException e) {
+        super(e.getMessage(), e, e.getLine(), e.getColumn(), getLineLast(e), getColumnLast(e));
+        this.ast = e.getAst();
+    }
+
+    public ASTParserException(String message, ASTRuntimeException e) {
+        super(message, e, e.getLine(), e.getColumn(), getLineLast(e), getColumnLast(e));
+        this.ast = e.getAst();
+    }
+
+    public AST getAst() {
+        return ast;
+    }
+    
+    private static int getLineLast(ASTRuntimeException e) {
+        final AST ast = e.getAst();
+        return (ast instanceof SourceInfo) ? ((SourceInfo)ast).getLineLast() : ast.getLine();
+    }
+
+    private static int getColumnLast(ASTRuntimeException e) {
+        final AST ast = e.getAst();
+        return (ast instanceof SourceInfo) ? ((SourceInfo)ast).getColumnLast() : ast.getColumn()+1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/0edfcde9/src/main/java/org/codehaus/groovy/antlr/ASTRuntimeException.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/antlr/ASTRuntimeException.java b/src/main/java/org/codehaus/groovy/antlr/ASTRuntimeException.java
new file mode 100644
index 0000000..aec85d4
--- /dev/null
+++ b/src/main/java/org/codehaus/groovy/antlr/ASTRuntimeException.java
@@ -0,0 +1,55 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.antlr;
+
+import antlr.collections.AST;
+
+/**
+ * @author <a href="mailto:jstrachan@protique.com">James Strachan</a>
+ */
+public class ASTRuntimeException extends RuntimeException {
+    private final AST ast;
+
+    public ASTRuntimeException(AST ast, String message) {
+        super(message + description(ast));
+        this.ast = ast;
+    }
+
+    public ASTRuntimeException(AST ast, String message, Throwable throwable) {
+        super(message + description(ast), throwable);
+        this.ast = null;
+    }
+
+    protected static String description(AST node) {
+        return (node != null) ? " at line: " + node.getLine() + " column: " + node.getColumn()
: "";
+    }
+
+    public AST getAst() {
+        return ast;
+    }
+
+    public int getLine() {
+        return ast != null ? ast.getLine() : -1;
+    }
+
+    public int getColumn() {
+        return ast != null ? ast.getColumn() : -1;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/0edfcde9/src/main/java/org/codehaus/groovy/antlr/AntlrASTProcessSnippets.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/antlr/AntlrASTProcessSnippets.java b/src/main/java/org/codehaus/groovy/antlr/AntlrASTProcessSnippets.java
new file mode 100644
index 0000000..94e8bf1
--- /dev/null
+++ b/src/main/java/org/codehaus/groovy/antlr/AntlrASTProcessSnippets.java
@@ -0,0 +1,96 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.antlr;
+
+/**
+ * Process to decorate antlr AST with ending line/col info, and if
+ * possible the snippet of source from the start/end line/col for each node.
+ *
+ * @author <a href="mailto:groovy@ross-rayner.com">Jeremy Rayner</a>
+ */
+
+import antlr.collections.AST;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class AntlrASTProcessSnippets implements AntlrASTProcessor{
+
+    public AntlrASTProcessSnippets() {
+    }
+
+    /**
+     * decorate antlr AST with ending line/col info, and if
+     * possible the snippet of source from the start/end line/col for each node.
+     * @param t the AST to decorate
+     * @return the decorated AST
+     */
+    public AST process(AST t) {
+        // first visit
+        List l = new ArrayList();
+        traverse((GroovySourceAST)t,l,null);
+
+        //System.out.println("l:" + l);
+        // second visit
+        Iterator itr = l.iterator();
+        if (itr.hasNext()) { itr.next(); /* discard first */ }
+        traverse((GroovySourceAST)t,null,itr);
+        return t;
+    }
+
+    /**
+     * traverse an AST node
+     * @param t the AST node to traverse
+     * @param l A list to add line/col info to
+     * @param itr An iterator over a list of line/col
+     */
+    private void traverse(GroovySourceAST t,List l,Iterator itr) {
+         while (t != null) {
+             // first visit of node
+             if (l != null) {
+                 l.add(new LineColumn(t.getLine(),t.getColumn()));
+             }
+
+             // second visit of node
+             if (itr != null && itr.hasNext()) {
+                 LineColumn lc = (LineColumn)itr.next();
+                 if (t.getLineLast() == 0) {
+                     int nextLine = lc.getLine();
+                     int nextColumn = lc.getColumn();
+                     if (nextLine < t.getLine() || (nextLine == t.getLine() &&
nextColumn < t.getColumn())) {
+                         nextLine = t.getLine();
+                         nextColumn = t.getColumn();
+                     }
+                     t.setLineLast(nextLine);
+                     t.setColumnLast(nextColumn);
+                     // This is a good point to call t.setSnippet(),
+                     // but it bulks up the AST too much for production code.
+                 }
+             }
+
+             GroovySourceAST child = (GroovySourceAST)t.getFirstChild();
+             if (child != null) {
+                 traverse(child,l,itr);
+             }
+
+             t = (GroovySourceAST)t.getNextSibling();
+         }
+    }
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/0edfcde9/src/main/java/org/codehaus/groovy/antlr/AntlrASTProcessor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/antlr/AntlrASTProcessor.java b/src/main/java/org/codehaus/groovy/antlr/AntlrASTProcessor.java
new file mode 100644
index 0000000..924f91f
--- /dev/null
+++ b/src/main/java/org/codehaus/groovy/antlr/AntlrASTProcessor.java
@@ -0,0 +1,35 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.antlr;
+
+import antlr.collections.AST;
+
+/**
+ * An interface for processing antlr AST objects
+ *
+ * @author <a href="mailto:groovy@ross-rayner.com">Jeremy Rayner</a>
+ */
+public interface AntlrASTProcessor {
+    /**
+     * performs some processing on the supplied AST node.
+     * @param t the AST node to process.
+     * @return possibly returns the AST modified or null, depends on the implementation.
+     */
+    AST process(AST t);
+}


Mime
View raw message