Somehow I missed a bunch of imports for @NotNull. Fixes #815.

This commit is contained in:
Terence Parr 2015-02-14 16:29:37 -08:00
parent 0ed80d90da
commit 5e70f94628
97 changed files with 240 additions and 814 deletions

View File

@ -30,8 +30,6 @@
package org.antlr.v4.runtime;
import org.antlr.v4.runtime.misc.NotNull;
/**
* The interface for defining strategies to deal with syntax errors encountered
* during a parse by ANTLR-generated parsers. We distinguish between three

View File

@ -31,7 +31,6 @@
package org.antlr.v4.runtime;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.misc.NotNull;
import java.util.ArrayList;
import java.util.HashSet;

View File

@ -31,7 +31,6 @@
package org.antlr.v4.runtime;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.misc.NotNull;
/** A source of characters for an ANTLR lexer. */
public interface CharStream extends IntStream {

View File

@ -30,7 +30,6 @@
package org.antlr.v4.runtime;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Pair;
import java.io.Serializable;
@ -47,24 +46,24 @@ public class CommonToken implements WritableToken, Serializable {
* This is the backing field for {@link #getType} and {@link #setType}.
*/
protected int type;
/**
* This is the backing field for {@link #getLine} and {@link #setLine}.
*/
protected int line;
/**
* This is the backing field for {@link #getCharPositionInLine} and
* {@link #setCharPositionInLine}.
*/
protected int charPositionInLine = -1; // set to invalid position
/**
* This is the backing field for {@link #getChannel} and
* {@link #setChannel}.
*/
protected int channel=DEFAULT_CHANNEL;
/**
* This is the backing field for {@link #getTokenSource} and
* {@link #getInputStream}.

View File

@ -34,8 +34,6 @@ import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNState;
import org.antlr.v4.runtime.atn.RuleTransition;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.runtime.misc.Pair;
/**

View File

@ -32,8 +32,6 @@ package org.antlr.v4.runtime;
import org.antlr.v4.runtime.atn.ATNState;
import org.antlr.v4.runtime.atn.AbstractPredicateTransition;
import org.antlr.v4.runtime.atn.PredicateTransition;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
import java.util.Locale;

View File

@ -35,7 +35,6 @@ import org.antlr.v4.runtime.atn.ATNType;
import org.antlr.v4.runtime.atn.LexerATNSimulator;
import org.antlr.v4.runtime.atn.PredictionContextCache;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.NotNull;
import java.util.Collection;

View File

@ -32,7 +32,6 @@ package org.antlr.v4.runtime;
import org.antlr.v4.runtime.atn.ATNConfigSet;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.runtime.misc.Utils;
import java.util.Locale;

View File

@ -1,6 +1,5 @@
package org.antlr.v4.runtime;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Pair;
import java.util.List;

View File

@ -30,8 +30,6 @@
package org.antlr.v4.runtime;
import org.antlr.v4.runtime.atn.ATNConfigSet;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
/** Indicates that the parser could not decide which of two or more paths
* to take based upon the remaining input. It tracks the starting token

View File

@ -31,7 +31,6 @@ package org.antlr.v4.runtime;
import org.antlr.v4.runtime.atn.DecisionState;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.misc.Nullable;
/** The root of the ANTLR exception hierarchy. In general, ANTLR tracks just
* 3 kinds of errors: prediction errors, failed predicate errors, and

View File

@ -33,7 +33,6 @@ package org.antlr.v4.runtime;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNSimulator;
import org.antlr.v4.runtime.atn.ParseInfo;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Utils;
import java.util.Collections;

View File

@ -30,8 +30,6 @@
package org.antlr.v4.runtime;
import org.antlr.v4.runtime.misc.NotNull;
/**
* This class provides access to the current version of the ANTLR 4 runtime
* library as compile-time and runtime constants, along with methods for

View File

@ -30,7 +30,6 @@
package org.antlr.v4.runtime;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Pair;
/** The default mechanism for creating tokens. It's used by default in Lexer and

View File

@ -29,9 +29,6 @@
*/
package org.antlr.v4.runtime;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
/**
* A source of tokens must provide a sequence of tokens via {@link #nextToken()}
* and also must reveal it's source of characters; {@link CommonToken}'s text is

View File

@ -31,7 +31,6 @@
package org.antlr.v4.runtime;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.misc.NotNull;
/**
* An {@link IntStream} whose symbols are {@link Token} instances.

View File

@ -31,7 +31,6 @@
package org.antlr.v4.runtime;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.misc.NotNull;
import java.util.Arrays;

View File

@ -29,9 +29,6 @@
*/
package org.antlr.v4.runtime;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
/**
* This interface provides information about the vocabulary used by a
* recognizer.

View File

@ -29,9 +29,6 @@
*/
package org.antlr.v4.runtime;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
import java.util.Arrays;
/**

View File

@ -34,7 +34,6 @@ import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.RuleContext;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.misc.NotNull;
import java.util.ArrayList;
import java.util.LinkedHashMap;

View File

@ -32,8 +32,6 @@ package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.Recognizer;
import org.antlr.v4.runtime.misc.MurmurHash;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
/** A tuple: (ATN state, predicted alt, syntactic, semantic context).
* The syntactic context is a graph-structured stack node whose

View File

@ -30,8 +30,6 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.misc.NotNull;
/**
*
* @author Sam Harwell

View File

@ -32,7 +32,6 @@ package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Pair;
import java.io.InvalidClassException;

View File

@ -32,7 +32,6 @@ package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.dfa.DFAState;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.misc.NotNull;
import java.util.IdentityHashMap;
import java.util.List;

View File

@ -31,7 +31,6 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.misc.NotNull;
/** TODO: make all transitions sets? no, should remove set edges */
public final class AtomTransition extends Transition {

View File

@ -30,8 +30,6 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.misc.NotNull;
public final class EpsilonTransition extends Transition {
private final int outermostPrecedenceReturn;

View File

@ -33,8 +33,6 @@ package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.RuleContext;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
import java.util.BitSet;
import java.util.HashSet;

View File

@ -31,7 +31,6 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.misc.MurmurHash;
import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.runtime.misc.ObjectEqualityComparator;
public class LexerATNConfig extends ATNConfig {

View File

@ -38,8 +38,6 @@ import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.dfa.DFAState;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
import java.util.Locale;

View File

@ -32,7 +32,6 @@ package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.misc.NotNull;
/**
* Represents a single action which can be executed following the successful

View File

@ -35,7 +35,6 @@ import org.antlr.v4.runtime.IntStream;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.MurmurHash;
import org.antlr.v4.runtime.misc.NotNull;
import java.util.Arrays;

View File

@ -33,7 +33,6 @@ package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.misc.MurmurHash;
import org.antlr.v4.runtime.misc.NotNull;
/**
* This implementation of {@link LexerAction} is used for tracking input offsets

View File

@ -31,7 +31,6 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.NotNull;
import java.util.ArrayList;
import java.util.List;

View File

@ -30,8 +30,6 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.misc.NotNull;
/** TODO: this is old comment:
* A tree of semantic predicates from the grammar AST if label==SEMPRED.
* In the ATN, labels will always be exactly one predicate, but the DFA

View File

@ -31,7 +31,6 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.misc.NotNull;
public final class RangeTransition extends Transition {
public final int from;

View File

@ -30,8 +30,6 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.misc.NotNull;
/** */
public final class RuleTransition extends Transition {
/** Ptr to the rule definition object for this rule ref */

View File

@ -33,7 +33,6 @@ package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.Recognizer;
import org.antlr.v4.runtime.RuleContext;
import org.antlr.v4.runtime.misc.MurmurHash;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Utils;
import java.util.ArrayList;

View File

@ -32,7 +32,6 @@ package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.misc.NotNull;
/** A transition containing a set of values. */
public class SetTransition extends Transition {

View File

@ -31,8 +31,6 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
import java.util.Arrays;
import java.util.Collections;

View File

@ -30,8 +30,6 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.misc.NotNull;
public final class WildcardTransition extends Transition {
public WildcardTransition(ATNState target) { super(target); }

View File

@ -35,8 +35,6 @@ import org.antlr.v4.runtime.VocabularyImpl;
import org.antlr.v4.runtime.atn.ATNConfigSet;
import org.antlr.v4.runtime.atn.DecisionState;
import org.antlr.v4.runtime.atn.StarLoopEntryState;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
import java.util.ArrayList;
import java.util.Arrays;

View File

@ -32,7 +32,6 @@ package org.antlr.v4.runtime.dfa;
import org.antlr.v4.runtime.Vocabulary;
import org.antlr.v4.runtime.VocabularyImpl;
import org.antlr.v4.runtime.misc.NotNull;
import java.util.Arrays;
import java.util.List;

View File

@ -38,8 +38,6 @@ import org.antlr.v4.runtime.atn.LexerActionExecutor;
import org.antlr.v4.runtime.atn.ParserATNSimulator;
import org.antlr.v4.runtime.atn.SemanticContext;
import org.antlr.v4.runtime.misc.MurmurHash;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
import java.util.Arrays;
import java.util.HashSet;

View File

@ -31,7 +31,6 @@
package org.antlr.v4.runtime.dfa;
import org.antlr.v4.runtime.VocabularyImpl;
import org.antlr.v4.runtime.misc.NotNull;
public class LexerDFASerializer extends DFASerializer {
public LexerDFASerializer(DFA dfa) {

View File

@ -1,72 +0,0 @@
/*
* [The "BSD license"]
* Copyright (c) 2012 Terence Parr
* Copyright (c) 2012 Sam Harwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.antlr.v4.runtime.misc;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation marks a field, parameter, local variable, or method (return
* value) as never being {@code null}. The specific semantics implied by this
* annotation depend on the kind of element the annotation is applied to.
*
* <ul>
* <li><strong>Field or Local Variable:</strong> Code reading the field or local
* variable may assume that the value is never {@code null}. Code writing to the
* field or local variable should ensure that a {@code null} reference is never
* written.</li>
* <li><strong>Parameter:</strong> Code calling the method should never pass
* {@code null} for this parameter. The implementation may assume that the value
* is never {@code null}, and the behavior of the method if the parameter is
* {@code null} is undefined. Overriding methods may optionally use the
* {@link Nullable} annotation instead of this annotation for the parameter,
* indicating that the overriding method provides additional code to handle a
* {@code null} reference passed for the parameter.</li>
* <li><strong>Method (Return Value):</strong> Code calling the method may
* assume that the result of the method is never {@code null}. The
* implementation of the method should ensure that a {@code null} reference is
* never returned.</li>
* </ul>
*
* <p>
* The {@link NullUsageProcessor} annotation processor validates certain usage
* scenarios for this annotation, with compile-time errors or warnings reported
* for misuse. For detailed information about the supported analysis, see the
* documentation for {@link NullUsageProcessor}.</p>
*/
@Documented
@Retention(RetentionPolicy.CLASS)
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})
public @interface NotNull {
}

View File

@ -1,331 +0,0 @@
/*
* [The "BSD license"]
* Copyright (c) 2013 Terence Parr
* Copyright (c) 2013 Sam Harwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.antlr.v4.runtime.misc;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.NoType;
import javax.lang.model.type.PrimitiveType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* A compile-time validator for correct usage of the {@link NotNull} and
* {@link Nullable} annotations.
*
* <p>The validation process checks the following items.</p>
*
* <ul>
* <li><strong>Error</strong>: an element is annotated with both {@link NotNull} and {@link Nullable}.</li>
* <li><strong>Error</strong>: an method which returns {@code void} is annotated with {@link NotNull} or {@link Nullable}.</li>
* <li><strong>Error</strong>: an element with a primitive type is annotated with {@link Nullable}.</li>
* <li><strong>Error</strong>: a parameter is annotated with {@link NotNull}, but the method overrides or implements a method where the parameter is annotated {@link Nullable}.</li>
* <li><strong>Error</strong>: a method is annotated with {@link Nullable}, but the method overrides or implements a method that is annotated with {@link NotNull}.</li>
* <li><strong>Warning</strong>: an element with a primitive type is annotated with {@link NotNull}.</li>
* <li><strong>Warning</strong>: a parameter is annotated with {@link NotNull}, but the method overrides or implements a method where the parameter is not annotated.</li>
* <li><strong>Warning</strong>: a method is annotated with {@link Nullable}, but the method overrides or implements a method that is not annotated.</li>
* </ul>
*
* <p>In the future, the validation process may be updated to check the following additional items.</p>
*
* <ul>
* <li><strong>Warning</strong>: a parameter is not annotated, but the method overrides or implements a method where the parameter is annotated with {@link NotNull} or {@link Nullable}.</li>
* <li><strong>Warning</strong>: a method is not annotated, but the method overrides or implements a method that is annotated with with {@link NotNull} or {@link Nullable}.</li>
* </ul>
*
* @author Sam Harwell
*/
@SupportedAnnotationTypes({NullUsageProcessor.NotNullClassName, NullUsageProcessor.NullableClassName})
public class NullUsageProcessor extends AbstractProcessor {
public static final String NotNullClassName = "org.antlr.v4.runtime.misc.NotNull";
public static final String NullableClassName = "org.antlr.v4.runtime.misc.Nullable";
private TypeElement notNullType;
private TypeElement nullableType;
public NullUsageProcessor() {
}
@Override
public SourceVersion getSupportedSourceVersion() {
SourceVersion latestSupported = SourceVersion.latestSupported();
if (latestSupported.ordinal() <= 6) {
return SourceVersion.RELEASE_6;
}
else if (latestSupported.ordinal() <= 8) {
return latestSupported;
}
else {
// this annotation processor is tested through Java 8
return SourceVersion.values()[8];
}
}
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (!checkClassNameConstants()) {
return true;
}
notNullType = processingEnv.getElementUtils().getTypeElement(NotNullClassName);
nullableType = processingEnv.getElementUtils().getTypeElement(NullableClassName);
Set<? extends Element> notNullElements = roundEnv.getElementsAnnotatedWith(notNullType);
Set<? extends Element> nullableElements = roundEnv.getElementsAnnotatedWith(nullableType);
Set<Element> intersection = new HashSet<Element>(notNullElements);
intersection.retainAll(nullableElements);
for (Element element : intersection) {
String error = String.format("%s cannot be annotated with both %s and %s", element.getKind().toString().replace('_', ' ').toLowerCase(), notNullType.getSimpleName(), nullableType.getSimpleName());
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, error, element);
}
checkVoidMethodAnnotations(notNullElements, notNullType);
checkVoidMethodAnnotations(nullableElements, nullableType);
checkPrimitiveTypeAnnotations(nullableElements, Diagnostic.Kind.ERROR, nullableType);
checkPrimitiveTypeAnnotations(notNullElements, Diagnostic.Kind.WARNING, notNullType);
// method name -> method -> annotated elements of method
Map<String, Map<ExecutableElement, List<Element>>> namedMethodMap =
new HashMap<String, Map<ExecutableElement, List<Element>>>();
addElementsToNamedMethodMap(notNullElements, namedMethodMap);
addElementsToNamedMethodMap(nullableElements, namedMethodMap);
for (Map.Entry<String, Map<ExecutableElement, List<Element>>> entry : namedMethodMap.entrySet()) {
for (Map.Entry<ExecutableElement, List<Element>> subentry : entry.getValue().entrySet()) {
checkOverriddenMethods(subentry.getKey());
}
}
return true;
}
private boolean checkClassNameConstants() {
boolean success = checkClassNameConstant(NotNullClassName, NotNull.class);
success &= checkClassNameConstant(NullableClassName, Nullable.class);
return success;
}
private boolean checkClassNameConstant(String className, Class<?> clazz) {
if (className == null) {
throw new NullPointerException("className");
}
if (clazz == null) {
throw new NullPointerException("clazz");
}
if (!className.equals(clazz.getCanonicalName())) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, String.format("Unable to process null usage annotations due to class name mismatch: %s != %s", className, clazz.getCanonicalName()));
return false;
}
return true;
}
private void checkVoidMethodAnnotations(Set<? extends Element> elements, TypeElement annotationType) {
for (Element element : elements) {
if (element.getKind() != ElementKind.METHOD) {
continue;
}
ExecutableElement executableElement = (ExecutableElement)element;
TypeMirror returnType = executableElement.getReturnType();
if (returnType instanceof NoType && returnType.getKind() == TypeKind.VOID) {
String error = String.format("void method cannot be annotated with %s", annotationType.getSimpleName());
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, error, element, getAnnotationMirror(element, annotationType));
}
}
}
private void checkPrimitiveTypeAnnotations(Set<? extends Element> elements, Diagnostic.Kind kind, TypeElement annotationType) {
for (Element element : elements) {
TypeMirror typeToCheck;
switch (element.getKind()) {
case FIELD:
case PARAMETER:
case LOCAL_VARIABLE:
// checking variable type
VariableElement variableElement = (VariableElement)element;
typeToCheck = variableElement.asType();
break;
case METHOD:
// checking return type
ExecutableElement executableElement = (ExecutableElement)element;
typeToCheck = executableElement.getReturnType();
break;
default:
continue;
}
if (typeToCheck instanceof PrimitiveType && typeToCheck.getKind().isPrimitive()) {
String error = String.format("%s with a primitive type %s be annotated with %s", element.getKind().toString().replace('_', ' ').toLowerCase(), kind == Diagnostic.Kind.ERROR ? "cannot" : "should not", annotationType.getSimpleName());
processingEnv.getMessager().printMessage(kind, error, element, getAnnotationMirror(element, annotationType));
}
}
}
private void addElementsToNamedMethodMap(Set<? extends Element> elements, Map<String, Map<ExecutableElement, List<Element>>> namedMethodMap) {
for (Element element : elements) {
ExecutableElement method;
switch (element.getKind()) {
case PARAMETER:
method = (ExecutableElement)element.getEnclosingElement();
assert method.getKind() == ElementKind.METHOD;
break;
case METHOD:
method = (ExecutableElement)element;
break;
default:
continue;
}
Map<ExecutableElement, List<Element>> annotatedMethodWithName =
namedMethodMap.get(method.getSimpleName().toString());
if (annotatedMethodWithName == null) {
annotatedMethodWithName = new HashMap<ExecutableElement, List<Element>>();
namedMethodMap.put(method.getSimpleName().toString(), annotatedMethodWithName);
}
List<Element> annotatedElementsOfMethod = annotatedMethodWithName.get(method);
if (annotatedElementsOfMethod == null) {
annotatedElementsOfMethod = new ArrayList<Element>();
annotatedMethodWithName.put(method, annotatedElementsOfMethod);
}
annotatedElementsOfMethod.add(element);
}
}
private void checkOverriddenMethods(ExecutableElement method) {
TypeElement declaringType = (TypeElement)method.getEnclosingElement();
Set<Element> errorElements = new HashSet<Element>();
Set<Element> warnedElements = new HashSet<Element>();
typeLoop:
for (TypeMirror supertypeMirror : getAllSupertypes(processingEnv.getTypeUtils().getDeclaredType(declaringType))) {
for (Element element : ((TypeElement)processingEnv.getTypeUtils().asElement(supertypeMirror)).getEnclosedElements()) {
if (element instanceof ExecutableElement) {
if (processingEnv.getElementUtils().overrides(method, (ExecutableElement)element, declaringType)) {
checkOverriddenMethod(method, (ExecutableElement)element, errorElements, warnedElements);
continue typeLoop;
}
}
}
}
}
private List<? extends TypeMirror> getAllSupertypes(TypeMirror type) {
Set<TypeMirror> supertypes = new HashSet<TypeMirror>();
Deque<TypeMirror> worklist = new ArrayDeque<TypeMirror>();
worklist.add(type);
while (!worklist.isEmpty()) {
List<? extends TypeMirror> next = processingEnv.getTypeUtils().directSupertypes(worklist.poll());
if (supertypes.addAll(next)) {
worklist.addAll(next);
}
}
return new ArrayList<TypeMirror>(supertypes);
}
private void checkOverriddenMethod(ExecutableElement overrider, ExecutableElement overridden, Set<Element> errorElements, Set<Element> warnedElements) {
// check method annotation
if (isNullable(overrider) && isNotNull(overridden) && errorElements.add(overrider)) {
String error = String.format("method annotated with %s cannot override or implement a method annotated with %s", nullableType.getSimpleName(), notNullType.getSimpleName());
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, error, overrider, getNullableAnnotationMirror(overrider));
}
else if (isNullable(overrider) && !(isNullable(overridden) || isNotNull(overridden)) && !errorElements.contains(overrider) && warnedElements.add(overrider)) {
String error = String.format("method annotated with %s overrides a method that is not annotated", nullableType.getSimpleName());
processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, error, overrider, getNullableAnnotationMirror(overrider));
}
List<? extends VariableElement> overriderParameters = overrider.getParameters();
List<? extends VariableElement> overriddenParameters = overridden.getParameters();
for (int i = 0; i < overriderParameters.size(); i++) {
if (isNotNull(overriderParameters.get(i)) && isNullable(overriddenParameters.get(i)) && errorElements.add(overriderParameters.get(i))) {
String error = String.format("parameter %s annotated with %s cannot override or implement a parameter annotated with %s", overriderParameters.get(i).getSimpleName(), notNullType.getSimpleName(), nullableType.getSimpleName());
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, error, overriderParameters.get(i), getNotNullAnnotationMirror(overriderParameters.get(i)));
}
else if (isNotNull(overriderParameters.get(i)) && !(isNullable(overriddenParameters.get(i)) || isNotNull(overriddenParameters.get(i))) && !errorElements.contains(overriderParameters.get(i)) && warnedElements.add(overriderParameters.get(i))) {
String error = String.format("parameter %s annotated with %s overrides a parameter that is not annotated", overriderParameters.get(i).getSimpleName(), notNullType.getSimpleName());
processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, error, overriderParameters.get(i), getNotNullAnnotationMirror(overriderParameters.get(i)));
}
}
}
private boolean isNotNull(Element element) {
return getNotNullAnnotationMirror(element) != null;
}
private boolean isNullable(Element element) {
return getNullableAnnotationMirror(element) != null;
}
private AnnotationMirror getNotNullAnnotationMirror(Element element) {
return getAnnotationMirror(element, notNullType);
}
private AnnotationMirror getNullableAnnotationMirror(Element element) {
return getAnnotationMirror(element, nullableType);
}
private AnnotationMirror getAnnotationMirror(Element element, TypeElement annotationType) {
for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
if (annotationMirror.getAnnotationType().asElement() == annotationType) {
return annotationMirror;
}
}
return null;
}
}

View File

@ -1,72 +0,0 @@
/*
* [The "BSD license"]
* Copyright (c) 2012 Terence Parr
* Copyright (c) 2012 Sam Harwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.antlr.v4.runtime.misc;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation marks a field, parameter, local variable, or method (return
* value) as potentially having the value {@code null}. The specific semantics
* implied by this annotation depend on the kind of element the annotation is
* applied to.
*
* <ul>
* <li><strong>Field or Local Variable:</strong> Code reading the field or local
* variable may not assume that the value is never {@code null}.</li>
* <li><strong>Parameter:</strong> Code calling the method might pass
* {@code null} for this parameter. The documentation for the method should
* describe the behavior of the method in the event this parameter is
* {@code null}.
* </li>
* <li><strong>Method (Return Value):</strong> Code calling the method may not
* assume that the result of the method is never {@code null}. The documentation
* for the method should describe the meaning of a {@code null} reference being
* returned. Overriding methods may optionally use the {@link NotNull}
* annotation instead of this annotation for the method, indicating that the
* overriding method (and any method which overrides it) will never return a
* {@code null} reference.</li>
* </ul>
*
* <p>
* The {@link NullUsageProcessor} annotation processor validates certain usage
* scenarios for this annotation, with compile-time errors or warnings reported
* for misuse. For detailed information about the supported analysis, see the
* documentation for {@link NullUsageProcessor}.</p>
*/
@Documented
@Retention(RetentionPolicy.CLASS)
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})
public @interface Nullable {
}

View File

@ -32,7 +32,6 @@ package org.antlr.v4.runtime.tree;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.misc.NotNull;
/** A tree that knows about an interval in a token stream
* is some kind of syntax tree. Subinterfaces distinguish

View File

@ -36,7 +36,6 @@ import org.abego.treelayout.TreeLayout;
import org.abego.treelayout.util.DefaultConfiguration;
import org.antlr.v4.runtime.misc.GraphicsSupport;
import org.antlr.v4.runtime.misc.JFileChooserConfirmOverwrite;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Utils;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.Tree;

View File

@ -31,8 +31,6 @@
package org.antlr.v4.runtime.tree.pattern;
import org.antlr.v4.runtime.misc.MultiMap;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.runtime.tree.ParseTree;
import java.util.Collections;

View File

@ -30,7 +30,6 @@
package org.antlr.v4.runtime.tree.pattern;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.xpath.XPath;

View File

@ -42,8 +42,6 @@ import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.misc.MultiMap;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.runtime.misc.ParseCancellationException;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.RuleNode;

View File

@ -33,8 +33,6 @@ package org.antlr.v4.runtime.tree.pattern;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenSource;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
/**
* A {@link Token} object representing an entire subtree matched by a parser

View File

@ -30,9 +30,6 @@
package org.antlr.v4.runtime.tree.pattern;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
/**
* Represents a placeholder tag in a tree pattern. A tag can have any of the
* following forms.

View File

@ -30,8 +30,6 @@
package org.antlr.v4.runtime.tree.pattern;
import org.antlr.v4.runtime.misc.NotNull;
/**
* Represents a span of raw text (concrete syntax) between tags in a tree
* pattern string.

View File

@ -32,8 +32,6 @@ package org.antlr.v4.runtime.tree.pattern;
import org.antlr.v4.runtime.CommonToken;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
/**
* A {@link Token} object representing a token of a particular type; e.g.,

View File

@ -66,7 +66,6 @@ ListenerFile(file, header) ::= <<
package <file.genPackage>;
<endif>
<header>
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.tree.ParseTreeListener;
/**
@ -106,7 +105,6 @@ package <file.genPackage>;
<header>
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.TerminalNode;
@ -163,7 +161,6 @@ VisitorFile(file, header) ::= <<
package <file.genPackage>;
<endif>
<header>
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
/**
@ -195,7 +192,6 @@ BaseVisitorFile(file, header) ::= <<
package <file.genPackage>;
<endif>
<header>
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
/**

View File

@ -51,7 +51,6 @@ import org.antlr.v4.parse.ToolANTLRParser;
import org.antlr.v4.parse.v3TreeGrammarException;
import org.antlr.v4.runtime.RuntimeMetaData;
import org.antlr.v4.runtime.misc.LogManager;
import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.semantics.SemanticPipeline;
import org.antlr.v4.tool.ANTLRMessage;
import org.antlr.v4.tool.ANTLRToolListener;

View File

@ -32,7 +32,6 @@ package org.antlr.v4.automata;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNState;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.tool.ast.ActionAST;
import org.antlr.v4.tool.ast.BlockAST;
import org.antlr.v4.tool.ast.GrammarAST;

View File

@ -42,7 +42,6 @@ import org.antlr.v4.runtime.atn.SetTransition;
import org.antlr.v4.runtime.atn.Transition;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.Rule;

View File

@ -32,7 +32,6 @@ package org.antlr.v4.automata;
import org.antlr.v4.runtime.atn.ATNState;
import org.antlr.v4.runtime.atn.Transition;
import org.antlr.v4.runtime.misc.NotNull;
import java.util.HashSet;
import java.util.Set;

View File

@ -58,8 +58,6 @@ import org.antlr.v4.runtime.atn.TokensStartState;
import org.antlr.v4.runtime.atn.Transition;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.tool.ErrorType;
import org.antlr.v4.tool.LexerGrammar;
import org.antlr.v4.tool.Rule;

View File

@ -68,8 +68,6 @@ import org.antlr.v4.runtime.atn.StarLoopbackState;
import org.antlr.v4.runtime.atn.Transition;
import org.antlr.v4.runtime.atn.WildcardTransition;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.runtime.misc.Triple;
import org.antlr.v4.semantics.UseDefAnalyzer;
import org.antlr.v4.tool.ErrorManager;

View File

@ -38,7 +38,6 @@ import org.antlr.v4.runtime.atn.PlusLoopbackState;
import org.antlr.v4.runtime.atn.RuleTransition;
import org.antlr.v4.runtime.atn.StarLoopbackState;
import org.antlr.v4.runtime.atn.Transition;
import org.antlr.v4.runtime.misc.NotNull;
/**
*

View File

@ -30,12 +30,6 @@
package org.antlr.v4.codegen;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.Token;
import org.antlr.v4.codegen.model.RuleFunction;
@ -79,6 +73,12 @@ import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.Rule;
import org.antlr.v4.tool.ast.ActionAST;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** */
public class ActionTranslator implements ActionSplitterListener {
public static final Map<String, Class<? extends RulePropertyRef>> thisRulePropToModelMap =

View File

@ -33,8 +33,6 @@ package org.antlr.v4.codegen;
import org.antlr.v4.Tool;
import org.antlr.v4.codegen.model.OutputModelObject;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.tool.ErrorType;
import org.antlr.v4.tool.Grammar;
import org.stringtemplate.v4.AutoIndentWriter;

View File

@ -36,8 +36,6 @@ import org.antlr.v4.codegen.model.RuleFunction;
import org.antlr.v4.codegen.model.SrcOp;
import org.antlr.v4.codegen.model.decl.CodeBlock;
import org.antlr.v4.codegen.model.decl.Decl;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.tool.Alternative;
import org.antlr.v4.tool.Grammar;

View File

@ -37,7 +37,6 @@ import org.antlr.v4.misc.Utils;
import org.antlr.v4.parse.ANTLRParser;
import org.antlr.v4.runtime.RuntimeMetaData;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.tool.ErrorType;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.Rule;

View File

@ -32,7 +32,6 @@ package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.runtime.atn.PlusBlockStartState;
import org.antlr.v4.runtime.atn.PlusLoopbackState;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.ast.BlockAST;
import org.antlr.v4.tool.ast.GrammarAST;

View File

@ -61,6 +61,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -68,8 +69,6 @@ import java.util.Set;
import static org.antlr.v4.parse.ANTLRParser.RULE_REF;
import static org.antlr.v4.parse.ANTLRParser.TOKEN_REF;
import java.util.LinkedHashSet;
/** */
public class RuleFunction extends OutputModelObject {
public String name;

View File

@ -35,7 +35,6 @@ import org.antlr.v4.codegen.CodeGenerator;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.model.chunk.ActionChunk;
import org.antlr.v4.runtime.atn.AbstractPredicateTransition;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.tool.ast.ActionAST;
import org.antlr.v4.tool.ast.GrammarAST;

View File

@ -30,7 +30,6 @@
package org.antlr.v4.misc;
import org.antlr.v4.runtime.misc.IntegerList;
import org.antlr.v4.tool.ast.GrammarAST;
import java.util.ArrayList;

View File

@ -32,12 +32,9 @@ package org.antlr.v4.parse;
import org.antlr.runtime.BaseRecognizer;
import org.antlr.runtime.CommonToken;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.runtime.misc.Pair;
import org.antlr.v4.tool.Attribute;
import org.antlr.v4.tool.AttributeDict;
import org.antlr.v4.tool.ErrorManager;
import org.antlr.v4.tool.ErrorType;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.ast.ActionAST;

View File

@ -33,7 +33,6 @@ package org.antlr.v4.semantics;
import org.antlr.v4.analysis.LeftRecursiveRuleTransformer;
import org.antlr.v4.parse.ANTLRParser;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Pair;
import org.antlr.v4.tool.ErrorType;
import org.antlr.v4.tool.Grammar;

View File

@ -31,8 +31,6 @@
package org.antlr.v4.semantics;
import org.antlr.v4.parse.ANTLRParser;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.tool.Alternative;
import org.antlr.v4.tool.Attribute;
import org.antlr.v4.tool.AttributeDict;

View File

@ -31,9 +31,8 @@
package org.antlr.v4.tool;
import org.antlr.runtime.Token;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
import org.stringtemplate.v4.ST;
import java.util.Arrays;
public class ANTLRMessage {

View File

@ -31,8 +31,6 @@
package org.antlr.v4.tool;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.tool.ast.GrammarAST;
import java.util.Collections;

View File

@ -30,7 +30,6 @@
package org.antlr.v4.tool;
import org.antlr.runtime.Token;
import org.antlr.v4.Tool;
import org.stringtemplate.v4.ST;
import org.stringtemplate.v4.STGroup;

View File

@ -55,8 +55,6 @@ import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.IntSet;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.runtime.misc.Pair;
import org.antlr.v4.tool.ast.ActionAST;
import org.antlr.v4.tool.ast.GrammarAST;

View File

@ -32,7 +32,6 @@ package org.antlr.v4.tool.ast;
import org.antlr.runtime.Token;
import org.antlr.v4.misc.CharSupport;
import org.antlr.v4.runtime.misc.NotNull;
import java.util.Collections;
import java.util.HashMap;

View File

@ -33,7 +33,6 @@ package org.antlr.v4.tool.ast;
import org.antlr.runtime.Token;
import org.antlr.runtime.TokenStream;
import org.antlr.runtime.tree.Tree;
import org.antlr.v4.runtime.misc.NotNull;
import java.util.HashMap;
import java.util.Map;

View File

@ -56,7 +56,6 @@ import org.antlr.v4.runtime.atn.LexerATNSimulator;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.IntegerList;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Pair;
import org.antlr.v4.runtime.misc.Utils;
import org.antlr.v4.runtime.tree.ParseTree;

View File

@ -1,7 +1,9 @@
package org.antlr.v4.test.rt.java;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class TestCompositeLexers extends BaseTest {
@ -21,10 +23,10 @@ public class TestCompositeLexers extends BaseTest {
sb.append("WS : (' '|'\\n') -> skip ;\n");
String grammar = sb.toString();
String found = execLexer("M.g4", grammar, "M", "abc", false);
assertEquals("S.A\n" +
"[@0,0:0='a',<3>,1:0]\n" +
"[@1,1:1='b',<1>,1:1]\n" +
"[@2,2:2='c',<4>,1:2]\n" +
assertEquals("S.A\n" +
"[@0,0:0='a',<3>,1:0]\n" +
"[@1,1:1='b',<1>,1:1]\n" +
"[@2,2:2='c',<4>,1:2]\n" +
"[@3,3:2='<EOF>',<-1>,1:3]\n", found);
assertNull(this.stderrDuringParse);
}
@ -45,8 +47,8 @@ public class TestCompositeLexers extends BaseTest {
sb.append("WS : (' '|'\\n') -> skip ;\n");
String grammar = sb.toString();
String found = execLexer("M.g4", grammar, "M", "ab", false);
assertEquals("M.A\n" +
"[@0,0:1='ab',<1>,1:0]\n" +
assertEquals("M.A\n" +
"[@0,0:1='ab',<1>,1:0]\n" +
"[@1,2:1='<EOF>',<-1>,1:2]\n", found);
assertNull(this.stderrDuringParse);
}

View File

@ -1,10 +1,11 @@
package org.antlr.v4.test.rt.java;
import org.junit.Test;
import static org.junit.Assert.*;
import org.antlr.v4.test.tool.ErrorQueue;
import org.antlr.v4.tool.Grammar;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class TestCompositeParsers extends BaseTest {

View File

@ -1,7 +1,9 @@
package org.antlr.v4.test.rt.java;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class TestFullContextParsing extends BaseTest {

View File

@ -1,7 +1,9 @@
package org.antlr.v4.test.rt.java;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class TestLeftRecursion extends BaseTest {

View File

@ -1,7 +1,9 @@
package org.antlr.v4.test.rt.java;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class TestLexerErrors extends BaseTest {
@ -27,7 +29,7 @@ public class TestLexerErrors extends BaseTest {
sb.append("WS : [ \\t\\r\\n]+ -> skip;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "[\"foo\"]", false);
assertEquals("[@0,0:6='[\"foo\"]',<1>,1:0]\n" +
assertEquals("[@0,0:6='[\"foo\"]',<1>,1:0]\n" +
"[@1,7:6='<EOF>',<-1>,1:7]\n", found);
assertNull(this.stderrDuringParse);
}
@ -55,7 +57,7 @@ public class TestLexerErrors extends BaseTest {
sb.append("WS : [ \\r\\n\\t]+ -> skip;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "{ { } }", false);
assertEquals("[@0,0:6='{ { } }',<1>,1:0]\n" +
assertEquals("[@0,0:6='{ { } }',<1>,1:0]\n" +
"[@1,7:6='<EOF>',<-1>,1:7]\n", found);
assertNull(this.stderrDuringParse);
}
@ -81,7 +83,7 @@ public class TestLexerErrors extends BaseTest {
sb.append("A : 'a' 'b' ;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "abx", false);
assertEquals("[@0,0:1='ab',<1>,1:0]\n" +
assertEquals("[@0,0:1='ab',<1>,1:0]\n" +
"[@1,3:2='<EOF>',<-1>,1:3]\n", found);
assertEquals("line 1:2 token recognition error at: 'x'\n", this.stderrDuringParse);
}
@ -106,7 +108,7 @@ public class TestLexerErrors extends BaseTest {
sb.append("A : 'a' 'b' ;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "abax", false);
assertEquals("[@0,0:1='ab',<1>,1:0]\n" +
assertEquals("[@0,0:1='ab',<1>,1:0]\n" +
"[@1,4:3='<EOF>',<-1>,1:4]\n", found);
assertEquals("line 1:2 token recognition error at: 'ax'\n", this.stderrDuringParse);
}
@ -120,8 +122,8 @@ public class TestLexerErrors extends BaseTest {
sb.append("B : 'abc' ;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "ababx", false);
assertEquals("[@0,0:1='ab',<1>,1:0]\n" +
"[@1,2:3='ab',<1>,1:2]\n" +
assertEquals("[@0,0:1='ab',<1>,1:0]\n" +
"[@1,2:3='ab',<1>,1:2]\n" +
"[@2,5:4='<EOF>',<-1>,1:5]\n", found);
assertEquals("line 1:4 token recognition error at: 'x'\n", this.stderrDuringParse);
}
@ -136,8 +138,8 @@ public class TestLexerErrors extends BaseTest {
sb.append("C : 'abcd' ;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "ababcx", false);
assertEquals("[@0,0:1='ab',<1>,1:0]\n" +
"[@1,2:4='abc',<2>,1:2]\n" +
assertEquals("[@0,0:1='ab',<1>,1:0]\n" +
"[@1,2:4='abc',<2>,1:2]\n" +
"[@2,6:5='<EOF>',<-1>,1:6]\n", found);
assertEquals("line 1:5 token recognition error at: 'x'\n", this.stderrDuringParse);
}
@ -165,9 +167,9 @@ public class TestLexerErrors extends BaseTest {
sb.append("ID : [a-z]+;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "LLexer", "x : x", false);
assertEquals("[@0,0:0='x',<3>,1:0]\n" +
"[@1,2:2=':',<1>,1:2]\n" +
"[@2,4:4='x',<3>,1:4]\n" +
assertEquals("[@0,0:0='x',<3>,1:0]\n" +
"[@1,2:2=':',<1>,1:2]\n" +
"[@2,4:4='x',<3>,1:4]\n" +
"[@3,5:4='<EOF>',<-1>,1:5]\n", found);
assertEquals("line 1:1 token recognition error at: ' '\nline 1:3 token recognition error at: ' '\n", this.stderrDuringParse);
}

View File

@ -1,7 +1,9 @@
package org.antlr.v4.test.rt.java;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class TestLexerExec extends BaseTest {
@ -13,7 +15,7 @@ public class TestLexerExec extends BaseTest {
sb.append("QUOTE : '\"' ; // make sure this compiles\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "\"", false);
assertEquals("[@0,0:0='\"',<1>,1:0]\n" +
assertEquals("[@0,0:0='\"',<1>,1:0]\n" +
"[@1,1:0='<EOF>',<-1>,1:1]\n", found);
assertNull(this.stderrDuringParse);
}
@ -28,9 +30,9 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : (' '|'\\n') -> skip ;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "34 -21 3", false);
assertEquals("[@0,0:1='34',<2>,1:0]\n" +
"[@1,3:5='-21',<1>,1:3]\n" +
"[@2,7:7='3',<2>,1:7]\n" +
assertEquals("[@0,0:1='34',<2>,1:0]\n" +
"[@1,3:5='-21',<1>,1:3]\n" +
"[@2,7:7='3',<2>,1:7]\n" +
"[@3,8:7='<EOF>',<-1>,1:8]\n", found);
assertNull(this.stderrDuringParse);
}
@ -47,10 +49,10 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : [ \\t] -> skip;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "\\ / \\/ /\\", false);
assertEquals("[@0,0:0='\\',<1>,1:0]\n" +
"[@1,2:2='/',<2>,1:2]\n" +
"[@2,4:5='\\/',<3>,1:4]\n" +
"[@3,7:8='/\\',<4>,1:7]\n" +
assertEquals("[@0,0:0='\\',<1>,1:0]\n" +
"[@1,2:2='/',<2>,1:2]\n" +
"[@2,4:5='\\/',<3>,1:4]\n" +
"[@3,7:8='/\\',<4>,1:7]\n" +
"[@4,9:8='<EOF>',<-1>,1:9]\n", found);
assertNull(this.stderrDuringParse);
}
@ -68,8 +70,8 @@ public class TestLexerExec extends BaseTest {
sb.append("SEPARATOR: '!';\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "-.-.-!", false);
assertEquals("[@0,0:4='-.-.-',<1>,1:0]\n" +
"[@1,5:5='!',<3>,1:5]\n" +
assertEquals("[@0,0:4='-.-.-',<1>,1:0]\n" +
"[@1,5:5='!',<3>,1:5]\n" +
"[@2,6:5='<EOF>',<-1>,1:6]\n", found);
assertNull(this.stderrDuringParse);
}
@ -82,8 +84,8 @@ public class TestLexerExec extends BaseTest {
sb.append("STRING : '\"' ('\"\"' | .)*? '\"';\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "\"hi\"\"mom\"", false);
assertEquals("[@0,0:3='\"hi\"',<1>,1:0]\n" +
"[@1,4:8='\"mom\"',<1>,1:4]\n" +
assertEquals("[@0,0:3='\"hi\"',<1>,1:0]\n" +
"[@1,4:8='\"mom\"',<1>,1:4]\n" +
"[@2,9:8='<EOF>',<-1>,1:9]\n", found);
assertNull(this.stderrDuringParse);
}
@ -96,7 +98,7 @@ public class TestLexerExec extends BaseTest {
sb.append("STRING : '\"' ('\"\"' | .)+? '\"';\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "\"\"\"mom\"", false);
assertEquals("[@0,0:6='\"\"\"mom\"',<1>,1:0]\n" +
assertEquals("[@0,0:6='\"\"\"mom\"',<1>,1:0]\n" +
"[@1,7:6='<EOF>',<-1>,1:7]\n", found);
assertNull(this.stderrDuringParse);
}
@ -110,7 +112,7 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : (' '|'\\t')+;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "//blah\n//blah\n", false);
assertEquals("[@0,0:13='//blah\\n//blah\\n',<1>,1:0]\n" +
assertEquals("[@0,0:13='//blah\\n//blah\\n',<1>,1:0]\n" +
"[@1,14:13='<EOF>',<-1>,3:0]\n", found);
assertNull(this.stderrDuringParse);
}
@ -124,8 +126,8 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : (' '|'\\t')+;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "//blah\n//blah\n", false);
assertEquals("[@0,0:6='//blah\\n',<1>,1:0]\n" +
"[@1,7:13='//blah\\n',<1>,2:0]\n" +
assertEquals("[@0,0:6='//blah\\n',<1>,1:0]\n" +
"[@1,7:13='//blah\\n',<1>,2:0]\n" +
"[@2,14:13='<EOF>',<-1>,3:0]\n", found);
assertNull(this.stderrDuringParse);
}
@ -139,7 +141,7 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : (' '|'\\t')+;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "//blah\n//blah\n", false);
assertEquals("[@0,0:13='//blah\\n//blah\\n',<1>,1:0]\n" +
assertEquals("[@0,0:13='//blah\\n//blah\\n',<1>,1:0]\n" +
"[@1,14:13='<EOF>',<-1>,3:0]\n", found);
assertNull(this.stderrDuringParse);
}
@ -153,8 +155,8 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : (' '|'\\t')+;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "//blah\n//blah\n", false);
assertEquals("[@0,0:6='//blah\\n',<1>,1:0]\n" +
"[@1,7:13='//blah\\n',<1>,2:0]\n" +
assertEquals("[@0,0:6='//blah\\n',<1>,1:0]\n" +
"[@1,7:13='//blah\\n',<1>,2:0]\n" +
"[@2,14:13='<EOF>',<-1>,3:0]\n", found);
assertNull(this.stderrDuringParse);
}
@ -168,7 +170,7 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : (' '|'\\t')+;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "//blah\n//blah\n", false);
assertEquals("[@0,0:13='//blah\\n//blah\\n',<1>,1:0]\n" +
assertEquals("[@0,0:13='//blah\\n//blah\\n',<1>,1:0]\n" +
"[@1,14:13='<EOF>',<-1>,3:0]\n", found);
assertNull(this.stderrDuringParse);
}
@ -182,8 +184,8 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : (' '|'\\t')+;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "//blah\n//blah\n", false);
assertEquals("[@0,0:6='//blah\\n',<1>,1:0]\n" +
"[@1,7:13='//blah\\n',<1>,2:0]\n" +
assertEquals("[@0,0:6='//blah\\n',<1>,1:0]\n" +
"[@1,7:13='//blah\\n',<1>,2:0]\n" +
"[@2,14:13='<EOF>',<-1>,3:0]\n", found);
assertNull(this.stderrDuringParse);
}
@ -197,10 +199,10 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : (' '|'\\n')+;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "/* ick */\n/* /* */\n/* /*nested*/ */\n", false);
assertEquals("[@0,0:8='/* ick */',<1>,1:0]\n" +
"[@1,9:9='\\n',<2>,1:9]\n" +
"[@2,10:34='/* /* */\\n/* /*nested*/ */',<1>,2:0]\n" +
"[@3,35:35='\\n',<2>,3:16]\n" +
assertEquals("[@0,0:8='/* ick */',<1>,1:0]\n" +
"[@1,9:9='\\n',<2>,1:9]\n" +
"[@2,10:34='/* /* */\\n/* /*nested*/ */',<1>,2:0]\n" +
"[@3,35:35='\\n',<2>,3:16]\n" +
"[@4,36:35='<EOF>',<-1>,4:0]\n", found);
assertNull(this.stderrDuringParse);
}
@ -214,10 +216,10 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : (' '|'\\n')+;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "/* ick */x\n/* /* */x\n/* /*nested*/ */x\n", false);
assertEquals("[@0,0:8='/* ick */',<1>,1:0]\n" +
"[@1,10:10='\\n',<2>,1:10]\n" +
"[@2,11:36='/* /* */x\\n/* /*nested*/ */',<1>,2:0]\n" +
"[@3,38:38='\\n',<2>,3:17]\n" +
assertEquals("[@0,0:8='/* ick */',<1>,1:0]\n" +
"[@1,10:10='\\n',<2>,1:10]\n" +
"[@2,11:36='/* /* */x\\n/* /*nested*/ */',<1>,2:0]\n" +
"[@3,38:38='\\n',<2>,3:17]\n" +
"[@4,39:38='<EOF>',<-1>,4:0]\n", found);
assertEquals("line 1:9 token recognition error at: 'x'\nline 3:16 token recognition error at: 'x'\n", this.stderrDuringParse);
}
@ -231,10 +233,10 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : (' '|'\\n')+;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "/* ick */\n/* /* */\n/* /*nested*/ */\n", false);
assertEquals("[@0,0:8='/* ick */',<1>,1:0]\n" +
"[@1,9:9='\\n',<2>,1:9]\n" +
"[@2,10:34='/* /* */\\n/* /*nested*/ */',<1>,2:0]\n" +
"[@3,35:35='\\n',<2>,3:16]\n" +
assertEquals("[@0,0:8='/* ick */',<1>,1:0]\n" +
"[@1,9:9='\\n',<2>,1:9]\n" +
"[@2,10:34='/* /* */\\n/* /*nested*/ */',<1>,2:0]\n" +
"[@3,35:35='\\n',<2>,3:16]\n" +
"[@4,36:35='<EOF>',<-1>,4:0]\n", found);
assertNull(this.stderrDuringParse);
}
@ -248,10 +250,10 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : (' '|'\\n')+;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "/* ick */x\n/* /* */x\n/* /*nested*/ */x\n", false);
assertEquals("[@0,0:8='/* ick */',<1>,1:0]\n" +
"[@1,10:10='\\n',<2>,1:10]\n" +
"[@2,11:36='/* /* */x\\n/* /*nested*/ */',<1>,2:0]\n" +
"[@3,38:38='\\n',<2>,3:17]\n" +
assertEquals("[@0,0:8='/* ick */',<1>,1:0]\n" +
"[@1,10:10='\\n',<2>,1:10]\n" +
"[@2,11:36='/* /* */x\\n/* /*nested*/ */',<1>,2:0]\n" +
"[@3,38:38='\\n',<2>,3:17]\n" +
"[@4,39:38='<EOF>',<-1>,4:0]\n", found);
assertEquals("line 1:9 token recognition error at: 'x'\nline 3:16 token recognition error at: 'x'\n", this.stderrDuringParse);
}
@ -270,11 +272,11 @@ public class TestLexerExec extends BaseTest {
sb.append("J : .;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "ab", false);
assertEquals("stuff0: \n" +
"stuff1: a\n" +
"stuff2: ab\n" +
"ab\n" +
"[@0,0:1='ab',<1>,1:0]\n" +
assertEquals("stuff0: \n" +
"stuff1: a\n" +
"stuff2: ab\n" +
"ab\n" +
"[@0,0:1='ab',<1>,1:0]\n" +
"[@1,2:1='<EOF>',<-1>,1:2]\n", found);
assertNull(this.stderrDuringParse);
}
@ -289,8 +291,8 @@ public class TestLexerExec extends BaseTest {
sb.append("J : .;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "ab", false);
assertEquals("ab\n" +
"[@0,0:1='ab',<1>,1:0]\n" +
assertEquals("ab\n" +
"[@0,0:1='ab',<1>,1:0]\n" +
"[@1,2:1='<EOF>',<-1>,1:2]\n", found);
assertNull(this.stderrDuringParse);
}
@ -305,10 +307,10 @@ public class TestLexerExec extends BaseTest {
sb.append("J : . {System.out.println(this.getText());};\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "ab", false);
assertEquals("a\n" +
"b\n" +
"[@0,0:0='a',<1>,1:0]\n" +
"[@1,1:1='b',<3>,1:1]\n" +
assertEquals("a\n" +
"b\n" +
"[@0,0:0='a',<1>,1:0]\n" +
"[@1,1:1='b',<3>,1:1]\n" +
"[@2,2:1='<EOF>',<-1>,1:2]\n", found);
assertNull(this.stderrDuringParse);
}
@ -323,13 +325,13 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : (' '|'\\n')+;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "end eend ending a", false);
assertEquals("[@0,0:2='end',<1>,1:0]\n" +
"[@1,3:3=' ',<3>,1:3]\n" +
"[@2,4:7='eend',<2>,1:4]\n" +
"[@3,8:8=' ',<3>,1:8]\n" +
"[@4,9:14='ending',<2>,1:9]\n" +
"[@5,15:15=' ',<3>,1:15]\n" +
"[@6,16:16='a',<2>,1:16]\n" +
assertEquals("[@0,0:2='end',<1>,1:0]\n" +
"[@1,3:3=' ',<3>,1:3]\n" +
"[@2,4:7='eend',<2>,1:4]\n" +
"[@3,8:8=' ',<3>,1:8]\n" +
"[@4,9:14='ending',<2>,1:9]\n" +
"[@5,15:15=' ',<3>,1:15]\n" +
"[@6,16:16='a',<2>,1:16]\n" +
"[@7,17:16='<EOF>',<-1>,1:17]\n", found);
assertNull(this.stderrDuringParse);
}
@ -348,19 +350,19 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : (' '|'\\n')+;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "x 0 1 a.b a.l", false);
assertEquals("[@0,0:0='x',<5>,1:0]\n" +
"[@1,1:1=' ',<6>,1:1]\n" +
"[@2,2:2='0',<2>,1:2]\n" +
"[@3,3:3=' ',<6>,1:3]\n" +
"[@4,4:4='1',<2>,1:4]\n" +
"[@5,5:5=' ',<6>,1:5]\n" +
"[@6,6:6='a',<5>,1:6]\n" +
"[@7,7:7='.',<4>,1:7]\n" +
"[@8,8:8='b',<5>,1:8]\n" +
"[@9,9:9=' ',<6>,1:9]\n" +
"[@10,10:10='a',<5>,1:10]\n" +
"[@11,11:11='.',<4>,1:11]\n" +
"[@12,12:12='l',<5>,1:12]\n" +
assertEquals("[@0,0:0='x',<5>,1:0]\n" +
"[@1,1:1=' ',<6>,1:1]\n" +
"[@2,2:2='0',<2>,1:2]\n" +
"[@3,3:3=' ',<6>,1:3]\n" +
"[@4,4:4='1',<2>,1:4]\n" +
"[@5,5:5=' ',<6>,1:5]\n" +
"[@6,6:6='a',<5>,1:6]\n" +
"[@7,7:7='.',<4>,1:7]\n" +
"[@8,8:8='b',<5>,1:8]\n" +
"[@9,9:9=' ',<6>,1:9]\n" +
"[@10,10:10='a',<5>,1:10]\n" +
"[@11,11:11='.',<4>,1:11]\n" +
"[@12,12:12='l',<5>,1:12]\n" +
"[@13,13:12='<EOF>',<-1>,1:13]\n", found);
assertNull(this.stderrDuringParse);
}
@ -374,7 +376,7 @@ public class TestLexerExec extends BaseTest {
sb.append("A : 'a';\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "", false);
assertEquals("[@0,0:-1='<EOF>',<1>,1:0]\n" +
assertEquals("[@0,0:-1='<EOF>',<1>,1:0]\n" +
"[@1,0:-1='<EOF>',<-1>,1:0]\n", found);
assertNull(this.stderrDuringParse);
}
@ -403,7 +405,7 @@ public class TestLexerExec extends BaseTest {
sb.append("C : 'c';\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "a", false);
assertEquals("[@0,0:0='a',<1>,1:0]\n" +
assertEquals("[@0,0:0='a',<1>,1:0]\n" +
"[@1,1:0='<EOF>',<-1>,1:1]\n", found);
assertNull(this.stderrDuringParse);
}
@ -417,10 +419,10 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : [ \\n\\u000D] -> skip ;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "34\n 34", false);
assertEquals("I\n" +
"I\n" +
"[@0,0:1='34',<1>,1:0]\n" +
"[@1,4:5='34',<1>,2:1]\n" +
assertEquals("I\n" +
"I\n" +
"[@0,0:1='34',<1>,1:0]\n" +
"[@1,4:5='34',<1>,2:1]\n" +
"[@2,6:5='<EOF>',<-1>,2:3]\n", found);
assertNull(this.stderrDuringParse);
}
@ -434,10 +436,10 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : [ \\n\\u000D]+ -> skip ;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "34\n 34", false);
assertEquals("I\n" +
"I\n" +
"[@0,0:1='34',<1>,1:0]\n" +
"[@1,4:5='34',<1>,2:1]\n" +
assertEquals("I\n" +
"I\n" +
"[@0,0:1='34',<1>,1:0]\n" +
"[@1,4:5='34',<1>,2:1]\n" +
"[@2,6:5='<EOF>',<-1>,2:3]\n", found);
assertNull(this.stderrDuringParse);
}
@ -451,8 +453,8 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : [ \\n\\u000D]+ -> skip ;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "xaf", false);
assertEquals("I\n" +
"[@0,0:2='xaf',<1>,1:0]\n" +
assertEquals("I\n" +
"[@0,0:2='xaf',<1>,1:0]\n" +
"[@1,3:2='<EOF>',<-1>,1:3]\n", found);
assertNull(this.stderrDuringParse);
}
@ -467,10 +469,10 @@ public class TestLexerExec extends BaseTest {
sb.append(" \n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "a x", false);
assertEquals("I\n" +
"I\n" +
"[@0,0:0='a',<1>,1:0]\n" +
"[@1,2:2='x',<1>,1:2]\n" +
assertEquals("I\n" +
"I\n" +
"[@0,0:0='a',<1>,1:0]\n" +
"[@1,2:2='x',<1>,1:2]\n" +
"[@2,3:2='<EOF>',<-1>,1:3]\n", found);
assertNull(this.stderrDuringParse);
}
@ -485,14 +487,14 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : [ \\n\\u0009\\r]+ -> skip ;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "34\n 34 a2 abc \n ", false);
assertEquals("I\n" +
"I\n" +
"ID\n" +
"ID\n" +
"[@0,0:1='34',<1>,1:0]\n" +
"[@1,4:5='34',<1>,2:1]\n" +
"[@2,7:8='a2',<2>,2:4]\n" +
"[@3,10:12='abc',<2>,2:7]\n" +
assertEquals("I\n" +
"I\n" +
"ID\n" +
"ID\n" +
"[@0,0:1='34',<1>,1:0]\n" +
"[@1,4:5='34',<1>,2:1]\n" +
"[@2,7:8='a2',<2>,2:4]\n" +
"[@3,10:12='abc',<2>,2:7]\n" +
"[@4,18:17='<EOF>',<-1>,3:3]\n", found);
assertNull(this.stderrDuringParse);
}
@ -506,8 +508,8 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : [ \\n\\u000D]+ -> skip ;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "00\n", false);
assertEquals("I\n" +
"[@0,0:1='00',<1>,1:0]\n" +
assertEquals("I\n" +
"[@0,0:1='00',<1>,1:0]\n" +
"[@1,3:2='<EOF>',<-1>,2:0]\n", found);
assertNull(this.stderrDuringParse);
}
@ -521,8 +523,8 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : [ \\u]+ -> skip ;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "34 ", false);
assertEquals("I\n" +
"[@0,0:1='34',<1>,1:0]\n" +
assertEquals("I\n" +
"[@0,0:1='34',<1>,1:0]\n" +
"[@1,3:2='<EOF>',<-1>,1:3]\n", found);
assertNull(this.stderrDuringParse);
}
@ -536,10 +538,10 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : [ \\u]+ -> skip ;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "- ] ", false);
assertEquals("DASHBRACK\n" +
"DASHBRACK\n" +
"[@0,0:0='-',<1>,1:0]\n" +
"[@1,2:2=']',<1>,1:2]\n" +
assertEquals("DASHBRACK\n" +
"DASHBRACK\n" +
"[@0,0:0='-',<1>,1:0]\n" +
"[@1,2:2=']',<1>,1:2]\n" +
"[@2,4:3='<EOF>',<-1>,1:4]\n", found);
assertNull(this.stderrDuringParse);
}
@ -553,8 +555,8 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : [ \\u]+ -> skip ;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "9", false);
assertEquals("A\n" +
"[@0,0:0='9',<1>,1:0]\n" +
assertEquals("A\n" +
"[@0,0:0='9',<1>,1:0]\n" +
"[@1,1:0='<EOF>',<-1>,1:1]\n", found);
assertNull(this.stderrDuringParse);
}
@ -568,8 +570,8 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : [ \\n\\t]+ -> skip ;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "b\"a", false);
assertEquals("A\n" +
"[@0,0:2='b\"a',<1>,1:0]\n" +
assertEquals("A\n" +
"[@0,0:2='b\"a',<1>,1:0]\n" +
"[@1,3:2='<EOF>',<-1>,1:3]\n", found);
assertNull(this.stderrDuringParse);
}
@ -583,8 +585,8 @@ public class TestLexerExec extends BaseTest {
sb.append("WS : [ \\n\\t]+ -> skip ;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "b\"\\a", false);
assertEquals("A\n" +
"[@0,0:3='b\"\\a',<1>,1:0]\n" +
assertEquals("A\n" +
"[@0,0:3='b\"\\a',<1>,1:0]\n" +
"[@1,4:3='<EOF>',<-1>,1:4]\n", found);
assertNull(this.stderrDuringParse);
}
@ -708,15 +710,15 @@ public class TestLexerExec extends BaseTest {
sb.append(" ;\n");
String grammar = sb.toString();
String found = execLexer("PositionAdjustingLexer.g4", grammar, "PositionAdjustingLexer", "tokens\ntokens {\nnotLabel\nlabel1 =\nlabel2 +=\nnotLabel\n", false);
assertEquals("[@0,0:5='tokens',<6>,1:0]\n" +
"[@1,7:12='tokens',<4>,2:0]\n" +
"[@2,14:14='{',<3>,2:7]\n" +
"[@3,16:23='notLabel',<6>,3:0]\n" +
"[@4,25:30='label1',<5>,4:0]\n" +
"[@5,32:32='=',<1>,4:7]\n" +
"[@6,34:39='label2',<5>,5:0]\n" +
"[@7,41:42='+=',<2>,5:7]\n" +
"[@8,44:51='notLabel',<6>,6:0]\n" +
assertEquals("[@0,0:5='tokens',<6>,1:0]\n" +
"[@1,7:12='tokens',<4>,2:0]\n" +
"[@2,14:14='{',<3>,2:7]\n" +
"[@3,16:23='notLabel',<6>,3:0]\n" +
"[@4,25:30='label1',<5>,4:0]\n" +
"[@5,32:32='=',<1>,4:7]\n" +
"[@6,34:39='label2',<5>,5:0]\n" +
"[@7,41:42='+=',<2>,5:7]\n" +
"[@8,44:51='notLabel',<6>,6:0]\n" +
"[@9,53:52='<EOF>',<-1>,7:0]\n", found);
assertNull(this.stderrDuringParse);
}
@ -4729,7 +4731,7 @@ public class TestLexerExec extends BaseTest {
sb.append("KW3999 : 'KW' '3999';\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "KW400", false);
assertEquals("[@0,0:4='KW400',<402>,1:0]\n" +
assertEquals("[@0,0:4='KW400',<402>,1:0]\n" +
"[@1,5:4='<EOF>',<-1>,1:5]\n", found);
assertNull(this.stderrDuringParse);
}
@ -4749,7 +4751,7 @@ public class TestLexerExec extends BaseTest {
sb.append(" EndString : '\\'' -> popMode;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "'xxx'", false);
assertEquals("[@0,0:4=''xxx'',<1>,1:0]\n" +
assertEquals("[@0,0:4=''xxx'',<1>,1:0]\n" +
"[@1,5:4='<EOF>',<-1>,1:5]\n", found);
assertNull(this.stderrDuringParse);
}

View File

@ -1,7 +1,9 @@
package org.antlr.v4.test.rt.java;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class TestListeners extends BaseTest {

View File

@ -1,7 +1,9 @@
package org.antlr.v4.test.rt.java;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class TestParseTrees extends BaseTest {

View File

@ -1,7 +1,9 @@
package org.antlr.v4.test.rt.java;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class TestParserExec extends BaseTest {

View File

@ -1,7 +1,9 @@
package org.antlr.v4.test.rt.java;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class TestSemPredEvalLexer extends BaseTest {
@ -16,15 +18,15 @@ public class TestSemPredEvalLexer extends BaseTest {
sb.append("WS : (' '|'\\n') -> skip;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "enum abc", true);
assertEquals("[@0,0:3='enum',<2>,1:0]\n" +
"[@1,5:7='abc',<3>,1:5]\n" +
"[@2,8:7='<EOF>',<-1>,1:8]\n" +
"s0-' '->:s5=>4\n" +
"s0-'a'->:s6=>3\n" +
"s0-'e'->:s1=>3\n" +
":s1=>3-'n'->:s2=>3\n" +
":s2=>3-'u'->:s3=>3\n" +
":s6=>3-'b'->:s6=>3\n" +
assertEquals("[@0,0:3='enum',<2>,1:0]\n" +
"[@1,5:7='abc',<3>,1:5]\n" +
"[@2,8:7='<EOF>',<-1>,1:8]\n" +
"s0-' '->:s5=>4\n" +
"s0-'a'->:s6=>3\n" +
"s0-'e'->:s1=>3\n" +
":s1=>3-'n'->:s2=>3\n" +
":s2=>3-'u'->:s3=>3\n" +
":s6=>3-'b'->:s6=>3\n" +
":s6=>3-'c'->:s6=>3\n", found);
assertNull(this.stderrDuringParse);
}
@ -39,16 +41,16 @@ public class TestSemPredEvalLexer extends BaseTest {
sb.append("WS : (' '|'\\n') -> skip;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "enum abc enum", true);
assertEquals("[@0,0:3='enum',<2>,1:0]\n" +
"[@1,5:7='abc',<2>,1:5]\n" +
"[@2,9:12='enum',<2>,1:9]\n" +
"[@3,13:12='<EOF>',<-1>,1:13]\n" +
"s0-' '->:s5=>3\n" +
"s0-'a'->:s4=>2\n" +
"s0-'e'->:s1=>2\n" +
":s1=>2-'n'->:s2=>2\n" +
":s2=>2-'u'->:s3=>2\n" +
":s4=>2-'b'->:s4=>2\n" +
assertEquals("[@0,0:3='enum',<2>,1:0]\n" +
"[@1,5:7='abc',<2>,1:5]\n" +
"[@2,9:12='enum',<2>,1:9]\n" +
"[@3,13:12='<EOF>',<-1>,1:13]\n" +
"s0-' '->:s5=>3\n" +
"s0-'a'->:s4=>2\n" +
"s0-'e'->:s1=>2\n" +
":s1=>2-'n'->:s2=>2\n" +
":s2=>2-'u'->:s3=>2\n" +
":s4=>2-'b'->:s4=>2\n" +
":s4=>2-'c'->:s4=>2\n", found);
assertNull(this.stderrDuringParse);
}
@ -63,10 +65,10 @@ public class TestSemPredEvalLexer extends BaseTest {
sb.append("WS : (' '|'\\n') -> skip;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "enum abc enum", true);
assertEquals("[@0,0:3='enum',<2>,1:0]\n" +
"[@1,5:7='abc',<2>,1:5]\n" +
"[@2,9:12='enum',<2>,1:9]\n" +
"[@3,13:12='<EOF>',<-1>,1:13]\n" +
assertEquals("[@0,0:3='enum',<2>,1:0]\n" +
"[@1,5:7='abc',<2>,1:5]\n" +
"[@2,9:12='enum',<2>,1:9]\n" +
"[@3,13:12='<EOF>',<-1>,1:13]\n" +
"s0-' '->:s2=>3\n", found);
assertNull(this.stderrDuringParse);
}
@ -81,10 +83,10 @@ public class TestSemPredEvalLexer extends BaseTest {
sb.append("WS : (' '|'\\n') -> skip;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "enum abc enum", true);
assertEquals("[@0,0:3='enum',<1>,1:0]\n" +
"[@1,5:7='abc',<2>,1:5]\n" +
"[@2,9:12='enum',<1>,1:9]\n" +
"[@3,13:12='<EOF>',<-1>,1:13]\n" +
assertEquals("[@0,0:3='enum',<1>,1:0]\n" +
"[@1,5:7='abc',<2>,1:5]\n" +
"[@2,9:12='enum',<1>,1:9]\n" +
"[@3,13:12='<EOF>',<-1>,1:13]\n" +
"s0-' '->:s3=>3\n", found);
assertNull(this.stderrDuringParse);
}
@ -101,21 +103,21 @@ public class TestSemPredEvalLexer extends BaseTest {
sb.append("WS : [ \\t]+ ;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "abc\n def \n", true);
assertEquals("INDENT\n" +
"[@0,0:2='abc',<1>,1:0]\n" +
"[@1,3:3='\\n',<3>,1:3]\n" +
"[@2,4:5=' ',<2>,2:0]\n" +
"[@3,6:8='def',<1>,2:2]\n" +
"[@4,9:10=' ',<4>,2:5]\n" +
"[@5,11:11='\\n',<3>,2:7]\n" +
"[@6,12:11='<EOF>',<-1>,3:0]\n" +
"s0-'\n" +
"'->:s2=>3\n" +
"s0-'a'->:s1=>1\n" +
"s0-'d'->:s1=>1\n" +
":s1=>1-'b'->:s1=>1\n" +
":s1=>1-'c'->:s1=>1\n" +
":s1=>1-'e'->:s1=>1\n" +
assertEquals("INDENT\n" +
"[@0,0:2='abc',<1>,1:0]\n" +
"[@1,3:3='\\n',<3>,1:3]\n" +
"[@2,4:5=' ',<2>,2:0]\n" +
"[@3,6:8='def',<1>,2:2]\n" +
"[@4,9:10=' ',<4>,2:5]\n" +
"[@5,11:11='\\n',<3>,2:7]\n" +
"[@6,12:11='<EOF>',<-1>,3:0]\n" +
"s0-'\n" +
"'->:s2=>3\n" +
"s0-'a'->:s1=>1\n" +
"s0-'d'->:s1=>1\n" +
":s1=>1-'b'->:s1=>1\n" +
":s1=>1-'c'->:s1=>1\n" +
":s1=>1-'e'->:s1=>1\n" +
":s1=>1-'f'->:s1=>1\n", found);
assertNull(this.stderrDuringParse);
}
@ -132,14 +134,14 @@ public class TestSemPredEvalLexer extends BaseTest {
sb.append("WS : (' '|'\\n') -> skip;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "a cde\nabcde\n", true);
assertEquals("a\n" +
"cde\n" +
"ab\n" +
"cde\n" +
"[@0,0:0='a',<1>,1:0]\n" +
"[@1,2:4='cde',<2>,1:2]\n" +
"[@2,6:7='ab',<1>,2:0]\n" +
"[@3,8:10='cde',<2>,2:2]\n" +
assertEquals("a\n" +
"cde\n" +
"ab\n" +
"cde\n" +
"[@0,0:0='a',<1>,1:0]\n" +
"[@1,2:4='cde',<2>,1:2]\n" +
"[@2,6:7='ab',<1>,2:0]\n" +
"[@3,8:10='cde',<2>,2:2]\n" +
"[@4,12:11='<EOF>',<-1>,3:0]\n", found);
assertNull(this.stderrDuringParse);
}
@ -154,12 +156,12 @@ public class TestSemPredEvalLexer extends BaseTest {
sb.append("WS : [ \\n] -> skip ;\n");
String grammar = sb.toString();
String found = execLexer("L.g4", grammar, "L", "enum enu a", false);
assertEquals("enum!\n" +
"ID enu\n" +
"ID a\n" +
"[@0,0:3='enum',<1>,1:0]\n" +
"[@1,5:7='enu',<2>,1:5]\n" +
"[@2,9:9='a',<2>,1:9]\n" +
assertEquals("enum!\n" +
"ID enu\n" +
"ID a\n" +
"[@0,0:3='enum',<1>,1:0]\n" +
"[@1,5:7='enu',<2>,1:5]\n" +
"[@2,9:9='a',<2>,1:9]\n" +
"[@3,10:9='<EOF>',<-1>,1:10]\n", found);
assertNull(this.stderrDuringParse);
}

View File

@ -1,7 +1,9 @@
package org.antlr.v4.test.rt.java;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class TestSemPredEvalParser extends BaseTest {

View File

@ -1,7 +1,9 @@
package org.antlr.v4.test.rt.java;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class TestSets extends BaseTest {

View File

@ -56,7 +56,6 @@ import org.antlr.v4.runtime.atn.LexerATNSimulator;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.IntegerList;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Pair;
import org.antlr.v4.runtime.misc.Utils;
import org.antlr.v4.runtime.tree.ParseTree;

View File

@ -33,7 +33,6 @@ package org.antlr.v4.test.tool;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.misc.IntegerList;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.misc.NotNull;
/**
*

View File

@ -57,7 +57,6 @@ import org.antlr.v4.runtime.atn.PredictionMode;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.dfa.DFAState;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.ParseCancellationException;
import org.antlr.v4.runtime.misc.Utils;
import org.antlr.v4.runtime.tree.ErrorNode;