• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Bazel Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 package com.google.devtools.build.android.desugar.testdata.java8;
15 
16 /** Desugar test interface to test precedence of inherited methods over default methods. */
17 public interface Named {
name()18   default String name() {
19     return getClass().getSimpleName();
20   }
21 
22   /** Base class defining {@link #name} without implementing {@link Named}. */
23   static class ExplicitNameBase {
24     private final String name;
25 
ExplicitNameBase(String name)26     public ExplicitNameBase(String name) {
27       this.name = name;
28     }
29 
name()30     public String name() {
31       return name;
32     }
33   }
34 
35   /** Class whose base class implementes {@link #name}. */
36   public static class ExplicitName extends ExplicitNameBase implements Named {
ExplicitName(String name)37     public ExplicitName(String name) {
38       super(name);
39     }
40   }
41 
42   /** Class that explicitly defers to the default method in {@link Named}. */
43   public static class DefaultName extends ExplicitNameBase implements Named {
DefaultName()44     public DefaultName() {
45       super(null);
46     }
47 
48     @Override
name()49     public String name() {
50       return Named.super.name() + "-once";
51     }
52   }
53 
54   /** Subclass of {@link DefaultName} that uses {@code super} as well. */
55   public static class DefaultNameSubclass extends DefaultName {
56     @Override
name()57     public String name() {
58       return super.name() + "-twice";
59     }
60   }
61 
62   /** Base class that declares {@link #name} abstract. */
63   abstract static class AbstractNameBase {
name()64     public abstract String name();
65   }
66 
67   /**
68    * Class that inherits {@link #name} abstract so subclasses must implement it despite default
69    * method in implemented interface.
70    */
71   public abstract static class AbstractName extends AbstractNameBase implements Named {}
72 }
73