langtools/src/share/classes/com/sun/tools/javac/sym/Profiles.java
author briangoetz
Wed, 18 Dec 2013 16:05:18 -0500
changeset 22163 3651128c74eb
parent 22159 682da512ec17
child 22165 ec53c8946fc2
permissions -rw-r--r--
8030244: Update langtools to use Diamond Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     1
/*
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     2
 * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     4
 *
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    10
 *
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    15
 * accompanied this code).
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    16
 *
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    20
 *
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    23
 * questions.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    24
 */
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    25
package com.sun.tools.javac.sym;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    26
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    27
import java.io.BufferedInputStream;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    28
import java.io.BufferedWriter;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    29
import java.io.File;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    30
import java.io.FileInputStream;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    31
import java.io.FileWriter;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    32
import java.io.IOException;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    33
import java.nio.charset.Charset;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    34
import java.nio.file.Files;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    35
import java.util.HashMap;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    36
import java.util.Map;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    37
import java.util.Properties;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    38
import java.util.Set;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    39
import java.util.TreeMap;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    40
import java.util.TreeSet;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    41
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    42
import com.sun.tools.javac.util.Assert;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    43
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    44
/**
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    45
 * Provide details about profile contents.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    46
 *
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    47
 * <p><b>This is NOT part of any supported API.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    48
 * If you write code that depends on this, you do so at your own
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    49
 * risk.  This code and its internal interfaces are subject to change
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    50
 * or deletion without notice.</b></p>
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    51
 */
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    52
public abstract class Profiles {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    53
    // for debugging
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    54
    public static void main(String[] args) throws IOException {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    55
        Profiles p = Profiles.read(new File(args[0]));
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    56
        if (args.length >= 2) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
    57
            Map<Integer,Set<String>> lists = new TreeMap<>();
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    58
            for (int i = 1; i <= 4; i++)
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
    59
                lists.put(i, new TreeSet<>());
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    60
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    61
            File rt_jar_lst = new File(args[1]);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    62
            for (String line: Files.readAllLines(rt_jar_lst.toPath(), Charset.defaultCharset())) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    63
                if (line.endsWith(".class")) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    64
                    String type = line.substring(0, line.length() - 6);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    65
                    int profile = p.getProfile(type);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    66
                    for (int i = profile; i <= 4; i++)
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    67
                        lists.get(i).add(type);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    68
                }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    69
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    70
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    71
            for (int i = 1; i <= 4; i++) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 19653
diff changeset
    72
                try (BufferedWriter out = new BufferedWriter(new FileWriter(i + ".txt"))) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 19653
diff changeset
    73
                    for (String type : lists.get(i)) {
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    74
                        out.write(type);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    75
                        out.newLine();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    76
                    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    77
                }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    78
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    79
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    80
    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    81
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    82
    public static Profiles read(File file) throws IOException {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 19653
diff changeset
    83
        try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(file))) {
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    84
            Properties p = new Properties();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    85
            p.load(in);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    86
            if (p.containsKey("java/lang/Object"))
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    87
                return new SimpleProfiles(p);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    88
            else
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    89
                return new MakefileProfiles(p);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    90
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    91
    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    92
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    93
    public abstract int getProfileCount();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    94
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    95
    public abstract int getProfile(String typeName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    96
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    97
    public abstract Set<String> getPackages(int profile);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    98
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    99
    private static class MakefileProfiles extends Profiles {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   100
        static class Package {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   101
            final Package parent;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   102
            final String name;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   103
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   104
            Map<String, Package> subpackages = new TreeMap<>();
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   105
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   106
            int profile;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   107
            Map<String, Integer> includedTypes = new TreeMap<>();
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   108
            Map<String, Integer> excludedTypes = new TreeMap<>();
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   109
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   110
            Package(Package parent, String name) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   111
                this.parent = parent;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   112
                this.name = name;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   113
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   114
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   115
            int getProfile() {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   116
                return (parent == null) ? profile : Math.max(parent.getProfile(), profile);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   117
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   118
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   119
            int getProfile(String simpleTypeName) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   120
                Integer i;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   121
                if ((i = includedTypes.get(simpleTypeName)) != null)
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   122
                    return i;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   123
                if ((i = includedTypes.get("*")) != null)
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   124
                    return i;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   125
                if ((i = excludedTypes.get(simpleTypeName)) != null)
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   126
                    return i + 1;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   127
                if ((i = excludedTypes.get("*")) != null)
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   128
                    return i + 1;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   129
                return getProfile();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   130
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   131
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   132
            String getName() {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   133
                return (parent == null) ? name : (parent.getName() + "/" + name);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   134
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   135
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   136
            void getPackages(int profile, Set<String> results) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   137
                int prf = getProfile();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   138
                if (prf != 0 && profile >= prf)
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   139
                    results.add(getName());
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   140
                for (Package pkg: subpackages.values())
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   141
                    pkg.getPackages(profile, results);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   142
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   143
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   144
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   145
        final Map<String, Package> packages = new TreeMap<>();
16548
d55a654e2751 8009429: Miscellaneous profiles cleanup
dholmes
parents: 15724
diff changeset
   146
d55a654e2751 8009429: Miscellaneous profiles cleanup
dholmes
parents: 15724
diff changeset
   147
        final int maxProfile = 4;  // Three compact profiles plus full JRE
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   148
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   149
        MakefileProfiles(Properties p) {
16548
d55a654e2751 8009429: Miscellaneous profiles cleanup
dholmes
parents: 15724
diff changeset
   150
            for (int profile = 1; profile <= maxProfile; profile++) {
d55a654e2751 8009429: Miscellaneous profiles cleanup
dholmes
parents: 15724
diff changeset
   151
                String prefix = (profile < maxProfile ? "PROFILE_" + profile : "FULL_JRE");
d55a654e2751 8009429: Miscellaneous profiles cleanup
dholmes
parents: 15724
diff changeset
   152
                String inclPackages = p.getProperty(prefix + "_RTJAR_INCLUDE_PACKAGES");
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   153
                if (inclPackages == null)
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   154
                    break;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   155
                for (String pkg: inclPackages.substring(1).trim().split("\\s+")) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   156
                    if (pkg.endsWith("/"))
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   157
                        pkg = pkg.substring(0, pkg.length() - 1);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   158
                    includePackage(profile, pkg);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   159
                }
16548
d55a654e2751 8009429: Miscellaneous profiles cleanup
dholmes
parents: 15724
diff changeset
   160
                String inclTypes =  p.getProperty(prefix + "_RTJAR_INCLUDE_TYPES");
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   161
                if (inclTypes != null) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   162
                    for (String type: inclTypes.replace("$$", "$").split("\\s+")) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   163
                        if (type.endsWith(".class"))
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   164
                            includeType(profile, type.substring(0, type.length() - 6));
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   165
                    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   166
                }
16548
d55a654e2751 8009429: Miscellaneous profiles cleanup
dholmes
parents: 15724
diff changeset
   167
                String exclTypes =  p.getProperty(prefix + "_RTJAR_EXCLUDE_TYPES");
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   168
                if (exclTypes != null) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   169
                    for (String type: exclTypes.replace("$$", "$").split("\\s+")) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   170
                        if (type.endsWith(".class"))
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   171
                            excludeType(profile, type.substring(0, type.length() - 6));
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   172
                    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   173
                }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   174
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   175
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   176
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   177
        @Override
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   178
        public int getProfileCount() {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   179
            return maxProfile;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   180
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   181
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   182
        @Override
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   183
        public int getProfile(String typeName) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   184
            int sep = typeName.lastIndexOf("/");
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   185
            String packageName = typeName.substring(0, sep);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   186
            String simpleName = typeName.substring(sep + 1);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   187
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   188
            Package p = getPackage(packageName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   189
            return p.getProfile(simpleName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   190
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   191
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   192
        @Override
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   193
        public Set<String> getPackages(int profile) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   194
            Set<String> results = new TreeSet<>();
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   195
            for (Package p: packages.values())
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   196
                p.getPackages(profile, results);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   197
            return results;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   198
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   199
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   200
        private void includePackage(int profile, String packageName) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   201
//            System.err.println("include package " + packageName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   202
            Package p = getPackage(packageName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   203
            Assert.check(p.profile == 0);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   204
            p.profile = profile;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   205
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   206
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   207
        private void includeType(int profile, String typeName) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   208
//            System.err.println("include type " + typeName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   209
            int sep = typeName.lastIndexOf("/");
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   210
            String packageName = typeName.substring(0, sep);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   211
            String simpleName = typeName.substring(sep + 1);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   212
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   213
            Package p = getPackage(packageName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   214
            Assert.check(!p.includedTypes.containsKey(simpleName));
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   215
            p.includedTypes.put(simpleName, profile);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   216
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   217
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   218
        private void excludeType(int profile, String typeName) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   219
//            System.err.println("exclude type " + typeName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   220
            int sep = typeName.lastIndexOf("/");
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   221
            String packageName = typeName.substring(0, sep);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   222
            String simpleName = typeName.substring(sep + 1);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   223
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   224
            Package p = getPackage(packageName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   225
            Assert.check(!p.excludedTypes.containsKey(simpleName));
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   226
            p.excludedTypes.put(simpleName, profile);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   227
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   228
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   229
        private Package getPackage(String packageName) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   230
            int sep = packageName.lastIndexOf("/");
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   231
            Package parent;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   232
            Map<String, Package> parentSubpackages;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   233
            String simpleName;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   234
            if (sep == -1) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   235
                parent = null;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   236
                parentSubpackages = packages;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   237
                simpleName = packageName;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   238
            } else {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   239
                parent = getPackage(packageName.substring(0, sep));
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   240
                parentSubpackages = parent.subpackages;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   241
                simpleName = packageName.substring(sep + 1);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   242
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   243
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   244
            Package p = parentSubpackages.get(simpleName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   245
            if (p == null) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   246
                parentSubpackages.put(simpleName, p = new Package(parent, simpleName));
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   247
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   248
            return p;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   249
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   250
    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   251
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   252
    private static class SimpleProfiles extends Profiles {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   253
        private final Map<String, Integer> map;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   254
        private final int profileCount;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   255
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   256
        SimpleProfiles(Properties p) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   257
            int max = 0;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   258
            map = new HashMap<>();
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   259
            for (Map.Entry<Object,Object> e: p.entrySet()) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   260
                String typeName = (String) e.getKey();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   261
                int profile = Integer.valueOf((String) e.getValue());
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   262
                map.put(typeName, profile);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   263
                max = Math.max(max, profile);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   264
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   265
            profileCount = max;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   266
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   267
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   268
        @Override
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   269
        public int getProfileCount() {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   270
            return profileCount;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   271
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   272
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   273
        @Override
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   274
        public int getProfile(String typeName) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   275
            return map.get(typeName);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   276
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   277
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   278
        @Override
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   279
        public Set<String> getPackages(int profile) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   280
            Set<String> results = new TreeSet<>();
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   281
            for (Map.Entry<String,Integer> e: map.entrySet()) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   282
                String tn = e.getKey();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   283
                int prf = e.getValue();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   284
                int sep = tn.lastIndexOf("/");
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   285
                if (sep > 0 && profile >= prf)
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   286
                    results.add(tn);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   287
            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   288
            return results;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   289
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   290
    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   291
}