001 /* 002 * Copyright 2010-2015 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 017 package org.jetbrains.kotlin.asJava; 018 019 import com.intellij.lang.Language; 020 import com.intellij.navigation.NavigationItem; 021 import com.intellij.psi.*; 022 import com.intellij.psi.impl.ElementPresentationUtil; 023 import com.intellij.psi.impl.light.LightElement; 024 import com.intellij.psi.impl.light.LightModifierList; 025 import com.intellij.ui.RowIcon; 026 import com.intellij.util.IncorrectOperationException; 027 import com.intellij.util.PlatformIcons; 028 import org.jetbrains.annotations.NonNls; 029 import org.jetbrains.annotations.NotNull; 030 031 import javax.swing.*; 032 033 // Based on com.intellij.psi.impl.light.LightVariableBuilder 034 public class LightVariableBuilder extends LightElement implements PsiVariable, NavigationItem { 035 private final String myName; 036 private final PsiType myType; 037 private final LightModifierList myModifierList; 038 039 public LightVariableBuilder(PsiManager manager, @NotNull String name, @NotNull PsiType type, Language language) { 040 super(manager, language); 041 myName = name; 042 myType = type; 043 myModifierList = new LightModifierList(manager); 044 } 045 046 @Override 047 public String toString() { 048 return "LightVariableBuilder:" + getName(); 049 } 050 051 @NotNull 052 @Override 053 public PsiType getType() { 054 return myType; 055 } 056 057 @Override 058 @NotNull 059 public PsiModifierList getModifierList() { 060 return myModifierList; 061 } 062 063 @Override 064 public boolean hasModifierProperty(@NonNls @NotNull String name) { 065 return myModifierList.hasModifierProperty(name); 066 } 067 068 @NotNull 069 @Override 070 public String getName() { 071 return myName; 072 } 073 074 @Override 075 public PsiTypeElement getTypeElement() { 076 return null; 077 } 078 079 @Override 080 public PsiExpression getInitializer() { 081 return null; 082 } 083 084 @Override 085 public boolean hasInitializer() { 086 return false; 087 } 088 089 @Override 090 public void normalizeDeclaration() throws IncorrectOperationException { 091 } 092 093 @Override 094 public Object computeConstantValue() { 095 return null; 096 } 097 098 @Override 099 public PsiIdentifier getNameIdentifier() { 100 return null; 101 } 102 103 @Override 104 public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException { 105 throw new UnsupportedOperationException("setName is not implemented yet in org.jetbrains.kotlin.asJava.light.LightVariableBuilder"); 106 } 107 108 @Override 109 protected boolean isVisibilitySupported() { 110 return true; 111 } 112 113 @Override 114 public Icon getElementIcon(int flags) { 115 RowIcon baseIcon = ElementPresentationUtil.createLayeredIcon(PlatformIcons.VARIABLE_ICON, this, false); 116 return ElementPresentationUtil.addVisibilityIcon(this, flags, baseIcon); 117 } 118 }