Home | History | Annotate | Download | only in match
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.google.currysrc.api.match;
     17 
     18 /**
     19  * The name of a type: a class or an enum. The className is expected to contain $ to indicate
     20  * nested / inner classes.
     21  */
     22 public final class TypeName {
     23 
     24   private final String packageName;
     25 
     26   private final String className;
     27 
     28   public TypeName(String packageName, String className) {
     29     this.packageName = packageName;
     30     this.className = className;
     31   }
     32 
     33   public String packageName() {
     34     return packageName;
     35   }
     36 
     37   public String className() {
     38     return className;
     39   }
     40 
     41   public static TypeName fromFullyQualifiedClassName(String fullyQualifiedClassName) {
     42     int packageSeparatorIndex = fullyQualifiedClassName.lastIndexOf('.');
     43     String packageName;
     44     String className;
     45     if (packageSeparatorIndex == -1) {
     46       packageName = "";
     47       className = fullyQualifiedClassName;
     48     } else {
     49       packageName = fullyQualifiedClassName.substring(0, packageSeparatorIndex);
     50       className = fullyQualifiedClassName.substring(packageSeparatorIndex + 1);
     51     }
     52     return new TypeName(packageName, className);
     53   }
     54 }
     55