Tue, 20 Nov 2012 09:58:55 -0800
8003639: convert lambda testng tests to jtreg and add them
Reviewed-by: mcimadamore
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package org.openjdk.tests.shapegen; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.util.ArrayList; |
aoqi@0 | 29 | import java.util.HashSet; |
aoqi@0 | 30 | import java.util.List; |
aoqi@0 | 31 | import java.util.Map; |
aoqi@0 | 32 | import java.util.Set; |
aoqi@0 | 33 | |
aoqi@0 | 34 | /** |
aoqi@0 | 35 | * |
aoqi@0 | 36 | * @author Robert Field |
aoqi@0 | 37 | */ |
aoqi@0 | 38 | public class ClassCase { |
aoqi@0 | 39 | |
aoqi@0 | 40 | public enum Kind { |
aoqi@0 | 41 | IVAC (true, "v"), |
aoqi@0 | 42 | IPRESENT (true, "p"), |
aoqi@0 | 43 | IDEFAULT (true, "d"), |
aoqi@0 | 44 | CNONE (false, "n"), |
aoqi@0 | 45 | CABSTRACT (false, "a"), |
aoqi@0 | 46 | CCONCRETE (false, "c"); |
aoqi@0 | 47 | |
aoqi@0 | 48 | private final String prefix; |
aoqi@0 | 49 | public final boolean isInterface; |
aoqi@0 | 50 | |
aoqi@0 | 51 | Kind(boolean isInterface, String prefix) { |
aoqi@0 | 52 | this.isInterface = isInterface; |
aoqi@0 | 53 | this.prefix = prefix; |
aoqi@0 | 54 | } |
aoqi@0 | 55 | |
aoqi@0 | 56 | public String getPrefix() { return prefix; } |
aoqi@0 | 57 | } |
aoqi@0 | 58 | |
aoqi@0 | 59 | public final Kind kind; |
aoqi@0 | 60 | private final ClassCase superclass; |
aoqi@0 | 61 | private final List<ClassCase> supertypes; |
aoqi@0 | 62 | |
aoqi@0 | 63 | private String name; |
aoqi@0 | 64 | private boolean _OK; |
aoqi@0 | 65 | private boolean _HasClassMethod; |
aoqi@0 | 66 | private Set<ClassCase> _mprov; |
aoqi@0 | 67 | private boolean _IsConcrete; |
aoqi@0 | 68 | private boolean _HasDefault; |
aoqi@0 | 69 | private ClassCase _mres; |
aoqi@0 | 70 | private ClassCase _mdefend; |
aoqi@0 | 71 | |
aoqi@0 | 72 | private Set<RuleGroup> executed = new HashSet<RuleGroup>(); |
aoqi@0 | 73 | |
aoqi@0 | 74 | public ClassCase(Kind kind, ClassCase superclass, List<ClassCase> interfaces) { |
aoqi@0 | 75 | this.kind = kind; |
aoqi@0 | 76 | this.superclass = superclass; |
aoqi@0 | 77 | |
aoqi@0 | 78 | // Set supertypes from superclass (if any) and interfaces |
aoqi@0 | 79 | List<ClassCase> lc; |
aoqi@0 | 80 | if (superclass == null) { |
aoqi@0 | 81 | lc = interfaces; |
aoqi@0 | 82 | } else { |
aoqi@0 | 83 | lc = new ArrayList<>(); |
aoqi@0 | 84 | lc.add(superclass); |
aoqi@0 | 85 | lc.addAll(interfaces); |
aoqi@0 | 86 | } |
aoqi@0 | 87 | this.supertypes = lc; |
aoqi@0 | 88 | } |
aoqi@0 | 89 | |
aoqi@0 | 90 | public final boolean isInterface() { return kind.isInterface; } |
aoqi@0 | 91 | public final boolean isClass() { return !kind.isInterface; } |
aoqi@0 | 92 | |
aoqi@0 | 93 | public Set<ClassCase> get_mprov() { |
aoqi@0 | 94 | exec(RuleGroup.PROVENENCE); |
aoqi@0 | 95 | return _mprov; |
aoqi@0 | 96 | } |
aoqi@0 | 97 | |
aoqi@0 | 98 | public void set_mprov(ClassCase cc) { |
aoqi@0 | 99 | Set<ClassCase> s = new HashSet<>(); |
aoqi@0 | 100 | s.add(cc); |
aoqi@0 | 101 | _mprov = s; |
aoqi@0 | 102 | } |
aoqi@0 | 103 | |
aoqi@0 | 104 | public void set_mprov(Set<ClassCase> s) { |
aoqi@0 | 105 | _mprov = s; |
aoqi@0 | 106 | } |
aoqi@0 | 107 | |
aoqi@0 | 108 | public ClassCase get_mres() { |
aoqi@0 | 109 | exec(RuleGroup.RESOLUTION); |
aoqi@0 | 110 | return _mres; |
aoqi@0 | 111 | } |
aoqi@0 | 112 | |
aoqi@0 | 113 | public void set_mres(ClassCase cc) { |
aoqi@0 | 114 | _mres = cc; |
aoqi@0 | 115 | } |
aoqi@0 | 116 | |
aoqi@0 | 117 | public ClassCase get_mdefend() { |
aoqi@0 | 118 | exec(RuleGroup.DEFENDER); |
aoqi@0 | 119 | return _mdefend; |
aoqi@0 | 120 | } |
aoqi@0 | 121 | |
aoqi@0 | 122 | public void set_mdefend(ClassCase cc) { |
aoqi@0 | 123 | _mdefend = cc; |
aoqi@0 | 124 | } |
aoqi@0 | 125 | |
aoqi@0 | 126 | public boolean get_HasClassMethod() { |
aoqi@0 | 127 | exec(RuleGroup.PROVENENCE); |
aoqi@0 | 128 | return _HasClassMethod; |
aoqi@0 | 129 | } |
aoqi@0 | 130 | |
aoqi@0 | 131 | public void set_HasClassMethod(boolean bool) { |
aoqi@0 | 132 | _HasClassMethod = bool; |
aoqi@0 | 133 | } |
aoqi@0 | 134 | |
aoqi@0 | 135 | public boolean get_HasDefault() { |
aoqi@0 | 136 | exec(RuleGroup.MARKER); |
aoqi@0 | 137 | return _HasDefault; |
aoqi@0 | 138 | } |
aoqi@0 | 139 | |
aoqi@0 | 140 | public void set_HasDefault(boolean bool) { |
aoqi@0 | 141 | _HasDefault = bool; |
aoqi@0 | 142 | } |
aoqi@0 | 143 | |
aoqi@0 | 144 | public boolean get_IsConcrete() { |
aoqi@0 | 145 | exec(RuleGroup.MARKER); |
aoqi@0 | 146 | return _IsConcrete; |
aoqi@0 | 147 | } |
aoqi@0 | 148 | |
aoqi@0 | 149 | public void set_IsConcrete(boolean bool) { |
aoqi@0 | 150 | _IsConcrete = bool; |
aoqi@0 | 151 | } |
aoqi@0 | 152 | |
aoqi@0 | 153 | public boolean get_OK() { |
aoqi@0 | 154 | exec(RuleGroup.CHECKING); |
aoqi@0 | 155 | return _OK; |
aoqi@0 | 156 | } |
aoqi@0 | 157 | |
aoqi@0 | 158 | public void set_OK(boolean bool) { |
aoqi@0 | 159 | _OK = bool; |
aoqi@0 | 160 | } |
aoqi@0 | 161 | |
aoqi@0 | 162 | public boolean isMethodDefined() { |
aoqi@0 | 163 | for (ClassCase cc : supertypes) { |
aoqi@0 | 164 | if (cc.isMethodDefined()) { |
aoqi@0 | 165 | return true; |
aoqi@0 | 166 | } |
aoqi@0 | 167 | } |
aoqi@0 | 168 | switch (kind) { |
aoqi@0 | 169 | case CCONCRETE: |
aoqi@0 | 170 | case CABSTRACT: |
aoqi@0 | 171 | case IPRESENT: |
aoqi@0 | 172 | case IDEFAULT: |
aoqi@0 | 173 | return true; |
aoqi@0 | 174 | default: |
aoqi@0 | 175 | return false; |
aoqi@0 | 176 | } |
aoqi@0 | 177 | } |
aoqi@0 | 178 | |
aoqi@0 | 179 | public boolean isAbstract() { |
aoqi@0 | 180 | return isMethodDefined() && (get_mres()==null); |
aoqi@0 | 181 | } |
aoqi@0 | 182 | |
aoqi@0 | 183 | public boolean hasSuperclass() { |
aoqi@0 | 184 | return superclass != null; |
aoqi@0 | 185 | } |
aoqi@0 | 186 | |
aoqi@0 | 187 | public ClassCase getSuperclass() { |
aoqi@0 | 188 | return superclass; |
aoqi@0 | 189 | } |
aoqi@0 | 190 | |
aoqi@0 | 191 | public List<ClassCase> getSupertypes() { |
aoqi@0 | 192 | return supertypes; |
aoqi@0 | 193 | } |
aoqi@0 | 194 | |
aoqi@0 | 195 | public List<ClassCase> getInterfaces() { |
aoqi@0 | 196 | if (superclass != null) { |
aoqi@0 | 197 | if (supertypes.get(0) != superclass) { |
aoqi@0 | 198 | throw new AssertionError("superclass missing from supertypes"); |
aoqi@0 | 199 | } |
aoqi@0 | 200 | return supertypes.subList(1, supertypes.size()); |
aoqi@0 | 201 | } else { |
aoqi@0 | 202 | return supertypes; |
aoqi@0 | 203 | } |
aoqi@0 | 204 | } |
aoqi@0 | 205 | |
aoqi@0 | 206 | public boolean isSubtypeOf(ClassCase cc) { |
aoqi@0 | 207 | // S-Refl |
aoqi@0 | 208 | if (cc.equals(this)) { |
aoqi@0 | 209 | return true; |
aoqi@0 | 210 | } |
aoqi@0 | 211 | |
aoqi@0 | 212 | // S-Def |
aoqi@0 | 213 | for (ClassCase sp : getSupertypes()) { |
aoqi@0 | 214 | if (cc.equals(sp)) { |
aoqi@0 | 215 | return true; |
aoqi@0 | 216 | } |
aoqi@0 | 217 | } |
aoqi@0 | 218 | |
aoqi@0 | 219 | // _S-Trans |
aoqi@0 | 220 | for (ClassCase sp : getSupertypes()) { |
aoqi@0 | 221 | if (sp.isSubtypeOf(cc)) { |
aoqi@0 | 222 | return true; |
aoqi@0 | 223 | } |
aoqi@0 | 224 | } |
aoqi@0 | 225 | |
aoqi@0 | 226 | return false; |
aoqi@0 | 227 | } |
aoqi@0 | 228 | |
aoqi@0 | 229 | public void init(Map<String, Integer> namingContext) { |
aoqi@0 | 230 | if (name != null) { |
aoqi@0 | 231 | return; // Already inited |
aoqi@0 | 232 | } |
aoqi@0 | 233 | |
aoqi@0 | 234 | for (ClassCase sup : supertypes) { |
aoqi@0 | 235 | sup.init(namingContext); |
aoqi@0 | 236 | } |
aoqi@0 | 237 | |
aoqi@0 | 238 | // Build name |
aoqi@0 | 239 | StringBuilder sb = new StringBuilder(); |
aoqi@0 | 240 | if (!supertypes.isEmpty()) { |
aoqi@0 | 241 | sb.append(isInterface() ? "I" : "C"); |
aoqi@0 | 242 | for (ClassCase cc : supertypes) { |
aoqi@0 | 243 | sb.append(cc.getName()); |
aoqi@0 | 244 | } |
aoqi@0 | 245 | sb.append(kind.isInterface ? "i" : "c"); |
aoqi@0 | 246 | } |
aoqi@0 | 247 | sb.append(kind.prefix); |
aoqi@0 | 248 | String pname = sb.toString(); |
aoqi@0 | 249 | Integer icnt = namingContext.get(pname); |
aoqi@0 | 250 | int cnt = icnt == null ? 0 : icnt; |
aoqi@0 | 251 | ++cnt; |
aoqi@0 | 252 | namingContext.put(pname, cnt); |
aoqi@0 | 253 | if (cnt > 1) { |
aoqi@0 | 254 | sb.append(cnt); |
aoqi@0 | 255 | } |
aoqi@0 | 256 | this.name = sb.toString(); |
aoqi@0 | 257 | } |
aoqi@0 | 258 | |
aoqi@0 | 259 | public boolean isa(Kind... kinds) { |
aoqi@0 | 260 | for (Kind k : kinds) { |
aoqi@0 | 261 | if (kind == k) { |
aoqi@0 | 262 | return true; |
aoqi@0 | 263 | } |
aoqi@0 | 264 | } |
aoqi@0 | 265 | return false; |
aoqi@0 | 266 | } |
aoqi@0 | 267 | |
aoqi@0 | 268 | private void exec(RuleGroup rg ) { |
aoqi@0 | 269 | if (!executed.contains(rg)) { |
aoqi@0 | 270 | rg.exec(this); |
aoqi@0 | 271 | executed.add(rg); |
aoqi@0 | 272 | } |
aoqi@0 | 273 | } |
aoqi@0 | 274 | |
aoqi@0 | 275 | public void collectClasses(Set<ClassCase> seen) { |
aoqi@0 | 276 | seen.add(this); |
aoqi@0 | 277 | for (ClassCase cc : supertypes) { |
aoqi@0 | 278 | cc.collectClasses(seen); |
aoqi@0 | 279 | } |
aoqi@0 | 280 | } |
aoqi@0 | 281 | |
aoqi@0 | 282 | public String getID() { |
aoqi@0 | 283 | if (name == null) { |
aoqi@0 | 284 | throw new Error("Access to uninitialized ClassCase"); |
aoqi@0 | 285 | } else { |
aoqi@0 | 286 | return name; |
aoqi@0 | 287 | } |
aoqi@0 | 288 | } |
aoqi@0 | 289 | |
aoqi@0 | 290 | public final String getName() { |
aoqi@0 | 291 | if (name == null) { |
aoqi@0 | 292 | return "ClassCase uninited@" + hashCode(); |
aoqi@0 | 293 | } else { |
aoqi@0 | 294 | return name; |
aoqi@0 | 295 | } |
aoqi@0 | 296 | } |
aoqi@0 | 297 | |
aoqi@0 | 298 | @Override |
aoqi@0 | 299 | public boolean equals(Object obj) { |
aoqi@0 | 300 | return obj instanceof ClassCase && getID().equals(((ClassCase)obj).getID()); |
aoqi@0 | 301 | } |
aoqi@0 | 302 | |
aoqi@0 | 303 | @Override |
aoqi@0 | 304 | public int hashCode() { |
aoqi@0 | 305 | return getID().hashCode(); |
aoqi@0 | 306 | } |
aoqi@0 | 307 | |
aoqi@0 | 308 | @Override |
aoqi@0 | 309 | public String toString() { |
aoqi@0 | 310 | return getName(); |
aoqi@0 | 311 | } |
aoqi@0 | 312 | } |