test/tools/javac/lambdaShapes/org/openjdk/tests/shapegen/ClassCase.java

Mon, 21 Jan 2013 20:15:16 +0000

author
mcimadamore
date
Mon, 21 Jan 2013 20:15:16 +0000
changeset 1512
b12ffdfa1341
parent 0
959103a6100f
permissions
-rw-r--r--

8005851: Remove support for synchronized interface methods
Summary: Synchronized default methods are no longer supported
Reviewed-by: jjg

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

mercurial