1 /* 2 * Copyright 2016 Google Inc. All Rights Reserved. 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 17 package com.google.turbine.binder.sym; 18 19 import com.google.errorprone.annotations.Immutable; 20 21 /** 22 * A class symbol. 23 * 24 * <p>Turbine identifies classes by their binary string name. Symbols are immutable and do not hold 25 * any semantic information: the information that has been determined at the current phase (e.g. 26 * about super-types and members) is held externally. 27 */ 28 // TODO(cushon): investigate performance impact of interning names/symbols 29 @Immutable 30 public class ClassSymbol implements Symbol { 31 32 public static final ClassSymbol OBJECT = new ClassSymbol("java/lang/Object"); 33 public static final ClassSymbol STRING = new ClassSymbol("java/lang/String"); 34 public static final ClassSymbol ENUM = new ClassSymbol("java/lang/Enum"); 35 public static final ClassSymbol ANNOTATION = new ClassSymbol("java/lang/annotation/Annotation"); 36 37 private final String className; 38 ClassSymbol(String className)39 public ClassSymbol(String className) { 40 this.className = className; 41 } 42 43 @Override hashCode()44 public int hashCode() { 45 return className.hashCode(); 46 } 47 48 @Override toString()49 public String toString() { 50 return className.replace('/', '.'); 51 } 52 53 @Override equals(Object o)54 public boolean equals(Object o) { 55 return o instanceof ClassSymbol && className.equals(((ClassSymbol) o).className); 56 } 57 58 /** The JVMS 4.2.1 binary name of the class. */ binaryName()59 public String binaryName() { 60 return className; 61 } 62 63 @Override symKind()64 public Kind symKind() { 65 return Kind.CLASS; 66 } 67 } 68