# HG changeset patch # User Christian Humer # Date 1432663448 -7200 # Node ID f5b49d881909fbee15dc0618462bd79903e45580 # Parent 99e3f4c5c853c21c74ccdd2462be88af3be2661b Truffle-DSL: move internal @ExpectError annotation from public API to the test package only; share expect error handling between new processors. diff -r 99e3f4c5c853 -r f5b49d881909 graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ExpectError.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ExpectError.java Tue May 26 20:04:08 2015 +0200 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.api.dsl.test; + +import java.lang.annotation.*; + +/** + * This annotation is internally known by the dsl processor and used to expect errors for testing + * purposes. This is not part of public API. + */ +@Retention(RetentionPolicy.RUNTIME) +public @interface ExpectError { + + String[] value(); + +} diff -r 99e3f4c5c853 -r f5b49d881909 graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/LanguageRegistrationTest.java --- a/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/LanguageRegistrationTest.java Tue May 26 20:04:07 2015 +0200 +++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/LanguageRegistrationTest.java Tue May 26 20:04:08 2015 +0200 @@ -22,10 +22,11 @@ */ package com.oracle.truffle.api.dsl.test.processor; -import com.oracle.truffle.api.TruffleLanguage; -import com.oracle.truffle.api.dsl.ExpectError; -import com.oracle.truffle.api.source.Source; -import java.io.IOException; +import java.io.*; + +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.dsl.test.*; +import com.oracle.truffle.api.source.*; public class LanguageRegistrationTest { diff -r 99e3f4c5c853 -r f5b49d881909 graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/TruffleProcessorTest.java --- a/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/TruffleProcessorTest.java Tue May 26 20:04:07 2015 +0200 +++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/TruffleProcessorTest.java Tue May 26 20:04:08 2015 +0200 @@ -22,16 +22,18 @@ */ package com.oracle.truffle.api.dsl.test.processor; -import com.oracle.truffle.api.dsl.ExpectError; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.dsl.processor.verify.VerifyTruffleProcessor; -import java.util.Locale; -import java.util.ServiceLoader; -import javax.annotation.processing.Processor; -import javax.tools.Diagnostic; -import javax.tools.JavaFileObject; import static org.junit.Assert.*; -import org.junit.Test; + +import java.util.*; + +import javax.annotation.processing.*; +import javax.tools.*; + +import org.junit.*; + +import com.oracle.truffle.api.dsl.test.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.dsl.processor.verify.*; /** * Verify errors emitted by the processor. diff -r 99e3f4c5c853 -r f5b49d881909 graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/ExpectError.java --- a/graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/ExpectError.java Tue May 26 20:04:07 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.api.dsl; - -import java.lang.annotation.*; - -/** - * This annotation is internally known by the dsl processor and used to expect errors for testing - * purposes. This is not part of public API. - */ -@Retention(RetentionPolicy.RUNTIME) -public @interface ExpectError { - - String[] value(); - -} diff -r 99e3f4c5c853 -r f5b49d881909 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/ExpectError.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/ExpectError.java Tue May 26 20:04:08 2015 +0200 @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.dsl.processor; + +import java.util.*; + +import javax.annotation.processing.*; +import javax.lang.model.element.*; +import javax.tools.Diagnostic.*; + +public class ExpectError { + + public static void assertNoErrorExpected(ProcessingEnvironment processingEnv, Element element) { + TypeElement eee = processingEnv.getElementUtils().getTypeElement(TruffleTypes.EXPECT_ERROR_CLASS_NAME); + if (eee != null) { + for (AnnotationMirror am : element.getAnnotationMirrors()) { + if (am.getAnnotationType().asElement().equals(eee)) { + processingEnv.getMessager().printMessage(Kind.ERROR, "Expected an error, but none found!", element); + } + } + } + } + + public static boolean isExpectedError(ProcessingEnvironment processingEnv, Element element, String message) { + TypeElement eee = processingEnv.getElementUtils().getTypeElement(TruffleTypes.EXPECT_ERROR_CLASS_NAME); + if (eee != null) { + for (AnnotationMirror am : element.getAnnotationMirrors()) { + if (am.getAnnotationType().asElement().equals(eee)) { + Map vals = am.getElementValues(); + if (vals.size() == 1) { + AnnotationValue av = vals.values().iterator().next(); + if (av.getValue() instanceof List) { + List arr = (List) av.getValue(); + for (Object o : arr) { + if (o instanceof AnnotationValue) { + AnnotationValue ov = (AnnotationValue) o; + if (message.equals(ov.getValue())) { + return true; + } + } + } + } + } + } + } + } + return false; + } + +} diff -r 99e3f4c5c853 -r f5b49d881909 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/LanguageRegistrationProcessor.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/LanguageRegistrationProcessor.java Tue May 26 20:04:07 2015 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/LanguageRegistrationProcessor.java Tue May 26 20:04:08 2015 +0200 @@ -22,30 +22,18 @@ */ package com.oracle.truffle.dsl.processor; -import com.oracle.truffle.api.TruffleLanguage; +import java.io.*; +import java.util.*; + +import javax.annotation.processing.*; +import javax.lang.model.*; +import javax.lang.model.element.*; +import javax.lang.model.type.*; +import javax.tools.Diagnostic.Kind; +import javax.tools.*; + +import com.oracle.truffle.api.*; import com.oracle.truffle.api.TruffleLanguage.Registration; -import com.oracle.truffle.api.dsl.ExpectError; -import java.io.IOException; -import java.io.OutputStream; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -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.AnnotationValue; -import javax.lang.model.element.Element; -import javax.lang.model.element.ElementKind; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.Modifier; -import javax.lang.model.element.TypeElement; -import javax.lang.model.type.TypeMirror; -import javax.tools.Diagnostic.Kind; -import javax.tools.FileObject; -import javax.tools.StandardLocation; @SupportedAnnotationTypes("com.oracle.truffle.api.*") public final class LanguageRegistrationProcessor extends AbstractProcessor { @@ -123,35 +111,14 @@ } void assertNoErrorExpected(Element e) { - TypeElement eee = processingEnv.getElementUtils().getTypeElement(ExpectError.class.getName()); - for (AnnotationMirror am : e.getAnnotationMirrors()) { - if (am.getAnnotationType().asElement().equals(eee)) { - processingEnv.getMessager().printMessage(Kind.ERROR, "Expected an error, but none found!", e); - } - } + ExpectError.assertNoErrorExpected(processingEnv, e); } void emitError(String msg, Element e) { - TypeElement eee = processingEnv.getElementUtils().getTypeElement(ExpectError.class.getName()); - for (AnnotationMirror am : e.getAnnotationMirrors()) { - if (am.getAnnotationType().asElement().equals(eee)) { - Map vals = am.getElementValues(); - if (vals.size() == 1) { - AnnotationValue av = vals.values().iterator().next(); - if (av.getValue() instanceof List) { - List arr = (List) av.getValue(); - for (Object o : arr) { - if (o instanceof AnnotationValue) { - AnnotationValue ov = (AnnotationValue) o; - if (msg.equals(ov.getValue())) { - return; - } - } - } - } - } - } + if (ExpectError.isExpectedError(processingEnv, e, msg)) { + return; } processingEnv.getMessager().printMessage(Kind.ERROR, msg, e); } + } diff -r 99e3f4c5c853 -r f5b49d881909 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/TruffleTypes.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/TruffleTypes.java Tue May 26 20:04:07 2015 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/TruffleTypes.java Tue May 26 20:04:08 2015 +0200 @@ -44,6 +44,8 @@ */ public final class TruffleTypes { + public static final String EXPECT_ERROR_CLASS_NAME = "com.oracle.truffle.api.dsl.test.ExpectError"; + private final DeclaredType node; private final ArrayType nodeArray; private final TypeMirror unexpectedValueException; @@ -94,7 +96,7 @@ nodeFactory = getRequired(context, NodeFactory.class); nodeFactoryBase = getRequired(context, NodeFactoryBase.class); dslMetadata = getRequired(context, DSLMetadata.class); - expectError = (TypeElement) getRequired(context, ExpectError.class).asElement(); + expectError = getOptional(context, EXPECT_ERROR_CLASS_NAME); generateNodeFactory = getRequired(context, GenerateNodeFactory.class); } @@ -158,6 +160,10 @@ return (DeclaredType) type; } + private static TypeElement getOptional(ProcessorContext context, String name) { + return context.getEnvironment().getElementUtils().getTypeElement(name); + } + public TypeMirror getInvalidAssumption() { return invalidAssumption; } diff -r 99e3f4c5c853 -r f5b49d881909 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/TypeSystemParser.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/TypeSystemParser.java Tue May 26 20:04:07 2015 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/TypeSystemParser.java Tue May 26 20:04:08 2015 +0200 @@ -37,7 +37,7 @@ @DSLOptions public class TypeSystemParser extends AbstractParser { - public static final List> ANNOTATIONS = Arrays.asList(TypeSystem.class, ExpectError.class); + public static final List> ANNOTATIONS = Arrays.asList(TypeSystem.class); @Override public Class getAnnotationType() { diff -r 99e3f4c5c853 -r f5b49d881909 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/verify/VerifyTruffleProcessor.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/verify/VerifyTruffleProcessor.java Tue May 26 20:04:07 2015 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/verify/VerifyTruffleProcessor.java Tue May 26 20:04:08 2015 +0200 @@ -34,8 +34,8 @@ import javax.tools.Diagnostic.Kind; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; -import com.oracle.truffle.api.dsl.ExpectError; import com.oracle.truffle.api.nodes.Node.Child; +import com.oracle.truffle.dsl.processor.*; @SupportedAnnotationTypes({"com.oracle.truffle.api.CompilerDirectives.TruffleBoundary", "com.oracle.truffle.api.nodes.Node.Child"}) public class VerifyTruffleProcessor extends AbstractProcessor { @@ -125,37 +125,15 @@ return false; } - void assertNoErrorExpected(Element e) { - TypeElement eee = processingEnv.getElementUtils().getTypeElement(ExpectError.class.getName()); - for (AnnotationMirror am : e.getAnnotationMirrors()) { - if (am.getAnnotationType().asElement().equals(eee)) { - processingEnv.getMessager().printMessage(Kind.ERROR, "Expected an error, but none found!", e); - } - } + void assertNoErrorExpected(Element element) { + ExpectError.assertNoErrorExpected(processingEnv, element); } - void emitError(String msg, Element e) { - TypeElement eee = processingEnv.getElementUtils().getTypeElement(ExpectError.class.getName()); - for (AnnotationMirror am : e.getAnnotationMirrors()) { - if (am.getAnnotationType().asElement().equals(eee)) { - Map vals = am.getElementValues(); - if (vals.size() == 1) { - AnnotationValue av = vals.values().iterator().next(); - if (av.getValue() instanceof List) { - List arr = (List) av.getValue(); - for (Object o : arr) { - if (o instanceof AnnotationValue) { - AnnotationValue ov = (AnnotationValue) o; - if (msg.equals(ov.getValue())) { - return; - } - } - } - } - } - } + void emitError(String message, Element element) { + if (ExpectError.isExpectedError(processingEnv, element, message)) { + return; } - processingEnv.getMessager().printMessage(Kind.ERROR, msg, e); + processingEnv.getMessager().printMessage(Kind.ERROR, message, element); } /**