001/* 002 * Copyright 2010-2013 JetBrains s.r.o. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.jetbrains.jet.lang.descriptors.impl; 018 019import org.jetbrains.annotations.NotNull; 020import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; 021import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorVisitor; 022import org.jetbrains.jet.lang.descriptors.Named; 023import org.jetbrains.jet.lang.descriptors.annotations.AnnotatedImpl; 024import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; 025import org.jetbrains.jet.lang.resolve.name.Name; 026import org.jetbrains.jet.renderer.DescriptorRenderer; 027 028import java.util.List; 029 030public abstract class DeclarationDescriptorImpl extends AnnotatedImpl implements Named, DeclarationDescriptor { 031 032 @NotNull 033 private final Name name; 034 035 public DeclarationDescriptorImpl(@NotNull List<AnnotationDescriptor> annotations, @NotNull Name name) { 036 super(annotations); 037 this.name = name; 038 } 039 040 @NotNull 041 @Override 042 public Name getName() { 043 return name; 044 } 045 046 @NotNull 047 @Override 048 public DeclarationDescriptor getOriginal() { 049 return this; 050 } 051 052 @Override 053 public void acceptVoid(DeclarationDescriptorVisitor<Void, Void> visitor) { 054 accept(visitor, null); 055 } 056 057 @Override 058 public String toString() { 059 try { 060 return DescriptorRenderer.DEBUG_TEXT.render(this) + "[" + getClass().getSimpleName() + "@" + Integer.toHexString(System.identityHashCode(this)) + "]"; 061 } catch (Throwable e) { 062 // DescriptionRenderer may throw if this is not yet completely initialized 063 // It is very inconvenient while debugging 064 return this.getClass().getName() + "@" + System.identityHashCode(this); 065 } 066 } 067}