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

Quelle  T6392782.java   Sprache: JAVA

 
/*
 * Copyright (c) 2006, 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.
 */


/*
 * @test
 * @bug 6392782
 * @summary TreeScanner.visitImport returns null, not result of nested scan
 * @modules jdk.compiler/com.sun.tools.javac.api
 *          jdk.compiler/com.sun.tools.javac.file
 */


import java.io.*;
import java.util.*;
import javax.tools.*;
import com.sun.source.tree.*;
import com.sun.source.util.*;
import com.sun.tools.javac.api.*;

public class T6392782 {
    public static void main(String... args) throws IOException {
        String testSrc = System.getProperty("test.src"".");
        JavacTool tool = JavacTool.create();
        try (StandardJavaFileManager fm = tool.getStandardFileManager(nullnullnull)) {
            Iterable<? extends JavaFileObject> files =
                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6392782.class.getName()+".java")));
            JavacTask task = tool.getTask(null, fm, nullnullnull, files);
            Iterable<? extends Tree> trees = task.parse();
            TreeScanner<Integer,Void> scanner = new MyScanner();
            check(scanner, 6, scanner.scan(trees, null));

            CountNodes nodeCounter = new CountNodes();
            // 359 nodes with the regular parser; 360 nodes with EndPosParser
            // We automatically switch to EndPosParser when calling JavacTask.parse()
            check(nodeCounter, 362, nodeCounter.scan(trees, null));

            CountIdentifiers idCounter = new CountIdentifiers();
            check(idCounter, 107, idCounter.scan(trees, null));
        }
    }

    private static void check(TreeScanner<?,?> scanner, int expect, int found) {
        if (found != expect)
            throw new AssertionError(scanner.getClass().getName() + ": expected: " + expect + " found: " + found);
    }

    static class MyScanner extends TreeScanner<Integer,Void> {
        @Override
        public Integer visitImport(ImportTree tree, Void ignore) {
            //System.err.println(tree);
            return 1;
        }

        @Override
        public Integer reduce(Integer i1, Integer i2) {
            return (i1 == null ? 0 : i1) + (i2 == null ? 0 : i2);
        }
    }

    static class CountNodes extends TreeScanner<Integer,Void> {
        @Override
        public Integer scan(Tree node, Void p) {
            if (node == null)
                return 0;
            Integer n = super.scan(node, p);
            return (n == null ? 0 : n) + 1;
        }
        @Override
        public Integer reduce(Integer r1, Integer r2) {
            return (r1 == null ? 0 : r1) + (r2 == null ? 0 : r2);
        }
    }

    // example from TreeScanner javadoc
    static class CountIdentifiers extends TreeScanner<Integer,Void> {
        @Override
        public Integer visitIdentifier(IdentifierTree node, Void p) {
            return 1;
        }
        @Override
        public Integer reduce(Integer r1, Integer r2) {
            return (r1 == null ? 0 : r1) + (r2 == null ? 0 : r2);
        }
    }
}

Messung V0.5
C=95 H=95 G=94

¤ Dauer der Verarbeitung: 0.26 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

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.