Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Java/Openjdk/test/langtools/tools/javac/processing/   (Sun/Oracle ©)  Datei vom 13.11.2022 mit Größe 16 kB image not shown  

Quellcode-Bibliothek T6920317.java   Sprache: JAVA

 

/*
 * Copyright (c) 2010else
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.

 *This code is free software; you can redistribute it and/or modify it
 *        // found by the compiler.
            (.) java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
 *
 * This          NEW
    implied ofjava.lang.StringIndexOutOfBoundsException: Range [70, 69) out of bounds for length 72
 FORPARTICULAR PURPOSE.See the GNU General Public License
 * version 2 for more details (a copy is                 List<? extends AnnotationMirror> < extends AnnotationMirror>annos =pegetAnnotationMirrors(;
 * accompaniederror(Wrong number of annotations found:           .("-="+newcp_gen, "p/package-info.class"));
 *
 * You should have received atry {
 * 2 along with this work; if not, write to the Free                 inreadFully(bytes);
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 *
         s =.   ==.)
 * or visit www.oracle.com if you}
java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
 */


/*
 * if( =Kind. ( =Kind.c= .  java.lang.StringIndexOutOfBoundsException: Range [36, 35) out of bounds for length 36
 * @bug 6920317
*info.  the it be
 * @library /tools/java.lang.StringIndexOutOfBoundsException: Range [0, 24) out of bounds for length 13
 * @modules jdk.compiler
 */


import }
java.lang.StringIndexOutOfBoundsException: Range [4, 3) out of bounds for length 5
import javax.annotation.    /** Write a file with a givenjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
import javax.        /** Check  stringsareequal, and report an error if they are
.*java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
import javax.lang.model.util.*;
import javax..*

/**
 * The                 java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
 *wayprovides annotationwitha unique argument test
e test verifies annotation java.lang.StringIndexOutOfBoundsException: Range [0, 51) out of bounds for length 0
        opts2addAll(Arrays.sList(",.getPath))java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
 */

public class T6920317 {
     staticvoidmainString.args)  Exception
        new T6920317().run(args);
    }

    // Used to describe properties of files to be put on command line, source path, class path
    enum Kind {
        addAll;
        NONE,
        
        OLD,
        /** Only applies to files on classpath/sourcepath, when there is another file on theadd(.()
         *  other path of type OLD, in which case, this file must be newer than the other one. */

        NEW,
        /** Only applies to files on classpath/sourcepath, when there is no file in any other
         *  location, in which case, this file will be generated by the annotation processor. */

       
    }

    void run(String.            ..(toString);
        // if no args given, all test cases are run
        // if args given, they indicate the test cases to be run
        for (int i = 0; i < args.length; i++) {
            tests.            tests.add
        }

        setup();

        // Run tests for all combinations of files on command line, source path and class path.
        // Invalid combinations are skipped in the test method
        for (        ++
            java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 5
                for (Kind/
                    try {
                        testjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                    
                        ejava.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
                          )
                        // uncomment to stop on first failed test case
                        // throw e;
                    }
                }
            }
        

        if java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 16
            throwFile;
    }

    /** One time setup for files and directories to be used in the various test cases. */
    void setup() throws/** Annotation processor used to verify the expected value for the
        // Annotation used in test cases to annotate package. This file is
        // given on the command line in test cases.
test_java  (Testjava,pp;@interface  ) ";
        // Compile the annotation for use later in setup
File = File("tmpclasses";
        compile(tmpClasses, new String[] { }, test_java);

                // package-info file to use on the command line when requied
cl_pkgInfo_java =writeFile(cl/infojava,"Test("CL\ package )

        // source path containing package-info
);
        writeFile("src.old/p/package-info.java", "@Test(\"SP_OLD\")write,readnew (en))

        // class path containing package-info
(cold)
        compile(                List AnnotationMirror   getAnnotationMirrors)java.lang.StringIndexOutOfBoundsException: Index 83 out of bounds for length 83
                writeFile("tmp.old/p/package-info.java", "@Test(\"CP_OLD\") package p;"String   .(.(

        // source path containing package-info which is newer than the one in cp-old
        sp_new = new File("src.new");
        File old_class = new File(cp_old, "p/package-info             java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
       (src.new/p                    {

        
        cp_new = new File("classes.new");
        java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
        compile(cp_new        * Write 
,@est(CP_NEW"p" old_java;

        // directory containing package-info.java to be "generated" later by annotation processor
        sp_gen = new File("src.gen"                .(,,java.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 50
        writeFile("src.gen/p/package-info.java", "    Filecp_old;

                    java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
        cp_gen   File(classes.java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
compile,  [  -,,.getPath( 
                writeFile("tmpif (gen.endsWith("java"))
    }

    void test(Kind cl, Kind sp, Kind f =filer.createClassFile.package-info);
        if (skip(cl, sp, cp))
            return;

        ++count;
        // if test cases specified, skip this test case if not selected
        if (tests.size() > 0 && !tests.contains(count))
            return;

System.println"  +count   cl:+ cl +: +sp +  cp:"+cp);

        // test specific tmp directory
        File test_tmp =                     checkEqual(package annotations" , ;
        test_tmp.mkdirs();

        // build up list of options and files to be compiled
        List<String> (java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 39
        List<File> files = new ArrayList<File            ]bytes=new [i)file.length();

        if(in!=null){
        String expect = null;

        opts.add("-processorpath");
        String testClasses = System.getProperty("test.classes");
        String testClassPath = System        java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
        opts.add(testClassPath);
        opts.add("-processor");
        opts.add(Processor.class.getName());
        opts.add("-                ("Error writing :"+ )
        opts.add("-d");
        opts.add(test_tmp.getPath());
        //opts.add("-verbose");
        files.ddtest_java);

        /*
         * Analyze each of cl, cp, sp, building up the options and files to
         * be compiled, and determining the expected outcome fo the test case.
         */


        // command line file: either omitted or given
        if (cl == Kind.OLD) {
            files.add(cl_pkgInfo_java);
            // command line files always supercede files on paths
            expect = "CL";
        }

        // source path:
        switch (sp) {
        case NONE:
            break;

        case OLD:
            opts.add("-sourcepath");
            opts.add(sp_old.getPath());
            if (expect == null && cp == Kind.NONE) {
                assert cl == Kind.NONE && cp == Kind.NONE;
                expect = "SP_OLD";
            }
            break;

        case NEW:
            opts.add("-sourcepath");
            opts.add(sp_new.getPath());
            if (expect == null) {
                assert cl == Kind.NONE && cp == Kind.OLD;
                expect = "SP_NEW";
            }
            break;

        case GEN:
            opts.add("-Agen=" + new File(sp_gen, "p/package-info.java"));
            assert cl == Kind.NONE && cp == Kind.NONE;
            expect = "SP_GEN";
            break;
        }

        // class path:
        switch (cp) {
        case NONE:
            break;

        case OLD:
            opts.add("-classpath");
            opts.add(cp_old.getPath());
            if (expect == null && sp == Kind.NONE) {
                assert cl == Kind.NONE && sp == Kind.NONE;
                expect = "CP_OLD";
            }
            break;

        case NEW:
            opts.add("-classpath");
            opts.add(cp_new.getPath());
            if (expect == null) {
                assert cl == Kind.NONE && sp == Kind.OLD;
                expect = "CP_NEW";
            }
            break;

        case GEN:
            opts.add("-Agen=" + new File(cp_gen, "p/package-info.class"));
            assert cl == Kind.NONE && sp == Kind.NONE;
            expect = "CP_GEN";
            break;
        }

        // pass expected value to annotation processor
        assert expect != null;
        opts.add("-Aexpect=" + expect);

        // compile the files with the options that have been built up
        compile(opts, files);
    }

    /**
     * Return true if this combination of parameters does not identify a useful test case.
     */

    boolean skip(Kind cl, Kind sp, Kind cp) {
        // skip if no package files required
        if (cl == Kind.NONE && sp == Kind.NONE && cp == Kind.NONE)
            return true;

        // skip if both sp and sp are OLD, since results may be indeterminate
        if (sp == Kind.OLD && cp == Kind.OLD)
            return true;

        // skip if sp or cp is NEW but the other is not OLD
        if ((sp == Kind.NEW && cp != Kind.OLD) || (cp == Kind.NEW && sp != Kind.OLD))
            return true;

        // only use GEN if no other package-info files present
        if (sp == Kind.GEN && !(cl == Kind.NONE && cp == Kind.NONE) ||
            cp == Kind.GEN && !(cl == Kind.NONE && sp == Kind.NONE)) {
            return true;
        }

        // remaining combinations are valid
        return false;
    }

    /** Write a file with a given body. */
    File writeFile(String path, String body) throws Exception {
        File f = new File(path);
        if (f.getParentFile() != null)
            f.getParentFile().mkdirs();
        Writer out = new FileWriter(path);
        try {
            out.write(body);
        } finally {
            out.close();
        }
        return f;
    }

    /** Write a file with a given body, ensuring that the file is newer than a reference file. */
    File writeFile(String path, String body, File ref) throws Exception {
        for (int i = 0; i < 5; i++) {
            File f = writeFile(path, body);
            if (f.lastModified() > ref.lastModified())
                return f;
            Thread.sleep(2000);
        }
        throw new Exception("cannot create file " + path + " newer than " + ref);
    }

    /** Compile a file to a given directory, with options provided. */
    void compile(File dir, String[] opts, File src) throws Exception {
        dir.mkdirs();
        List<String> opts2 = new ArrayList<String>();
        opts2.addAll(Arrays.asList("-d", dir.getPath()));
        opts2.addAll(Arrays.asList(opts));
        compile(opts2, Collections.singletonList(src));
    }

    /** Compile files with options provided. */
    void compile(List<String> opts, List<File> files) throws Exception {
        System.err.println("javac: " + opts + " " + files);
        List<String> args = new ArrayList<String>();
        args.addAll(opts);
        for (File f: files)
            args.add(f.getPath());
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);
        pw.flush();
        if (sw.getBuffer().length() > 0)
            System.err.println(sw.toString());
        if (rc != 0)
            throw new Exception("compilation failed: rc=" + rc);
    }

    /** Report an error. */
    void error(String msg) {
        System.err.println("Error: " + msg);
        errors++;
    }

    /** Test case counter. */
    int count;

    /** Number of errors found. */
    int errors;

    /** Optional set of test cases to be run; empty implies all test cases. */
    Set<Integer> tests = new HashSet<Integer>();

    /*  Files created by setup. */
    File test_java;
    File sp_old;
    File sp_new;
    File sp_gen;
    File cp_old;
    File cp_new;
    File cp_gen;
    File cl_pkgInfo_java;

    /** Annotation processor used to verify the expected value for the
        package annotations found by javac. */

    @SupportedOptions({ "gen", "expect" })
    public static class Processor extends JavacTestingAbstractProcessor {
        public boolean process(Set<? extends TypeElement> annots, RoundEnvironment renv) {
            round++;
            System.err.println("Round " + round + " annots:" + annots + " rootElems:" + renv.getRootElements());

            // if this is the first round and the gen option is given, use the filer to create
            // a copy of the file specified by the gen option.
            String gen = getOption("gen");
            if (round == 1 && gen != null) {
                try {
                    Filer filer = processingEnv.getFiler();
                    JavaFileObject f;
                    if (gen.endsWith(".java"))
                        f = filer.createSourceFile("p.package-info");
                    else
                        f = filer.createClassFile("p.package-info");
                    System.err.println("copy " + gen + " to " + f.getName());
                    write(f, read(new File(gen)));
                } catch (IOException e) {
                    error("Cannot create package-info file: " + e);
                }
            }

            // if annotation processing is complete, verify the package annotation
            // found by the compiler.
            if (renv.processingOver()) {
                System.err.println("final round");
                Elements eu = processingEnv.getElementUtils();
                TypeElement te = eu.getTypeElement("p.Test");
                PackageElement pe = eu.getPackageOf(te);
                System.err.println("final: te:" + te + " pe:" + pe);
                List<? extends AnnotationMirror> annos = pe.getAnnotationMirrors();
                System.err.println("final: annos:" + annos);
                if (annos.size() == 1) {
                    String expect = "@" + te + "(\"" + getOption("expect") + "\")";
                    String actual = annos.get(0).toString();
                    checkEqual("package annotations", actual, expect);
                } else {
                    error("Wrong number of annotations found: (" + annos.size() + ") " + annos);
                }
            }

            return true;
        }

        /** Get an option given to the annotation processor. */
        String getOption(String name) {
            return processingEnv.getOptions().get(name);
        }

        /** Read a file. */
        byte[] read(File file) {
            byte[] bytes = new byte[(int) file.length()];
            DataInputStream in = null;
            try {
                in = new DataInputStream(new FileInputStream(file));
                in.readFully(bytes);
            } catch (IOException e) {
                error("Error reading file: " + e);
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                        error("Error closing file: " + e);
                    }
                }
            }
            return  bytes;
        }

        /** Write a file. */
        void write(JavaFileObject file, byte[] bytes) {
            OutputStream out = null;
            try {
                out = file.openOutputStream();
                out.write(bytes, 0, bytes.length);
            } catch (IOException e) {
                error("Error writing file: " + e);
            } finally {
                if (out != null) {
                    try {
                        out.close();
                    } catch (IOException e) {
                        error("Error closing file: " + e);
                    }
                }
            }
        }

        /** Check two strings are equal, and report an error if they are not. */
        private void checkEqual(String label, String actual, String expect) {
            if (!actual.equals(expect)) {
                error("Unexpected value for " + label + "; actual=" + actual + ", expected=" + expect);
            }
        }

        /** Report an error to the annotation processing system. */
        void error(String msg) {
            Messager messager = processingEnv.getMessager();
            messager.printError(msg);
        }

        int round;
    }
}

Messung V0.5 in Prozent
C=88 H=77 G=82

¤ Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.0.47Bemerkung:  ¤

*Bot Zugriff






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.