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.psi; 018 019import com.intellij.openapi.project.Project; 020import com.intellij.psi.PsiElement; 021import com.intellij.psi.tree.IElementType; 022import org.jetbrains.annotations.Nullable; 023import org.jetbrains.jet.JetNodeTypes; 024import org.jetbrains.jet.lang.types.JetType; 025import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; 026import org.jetbrains.jet.lexer.JetTokens; 027 028public class JetTypeCodeFragmentImpl extends JetCodeFragmentImpl implements JetTypeCodeFragment { 029 public JetTypeCodeFragmentImpl(Project project, String name, CharSequence text, PsiElement context) { 030 super(project, name, text, JetNodeTypes.TYPE_CODE_FRAGMENT, context); 031 } 032 033 @Nullable 034 @Override 035 public JetType getType() { 036 JetType type = null; 037 038 for (PsiElement child : getChildren()) { 039 IElementType elementType = child.getNode().getElementType(); 040 041 if (elementType == JetNodeTypes.TYPE_CODE_FRAGMENT) { 042 for (PsiElement grChild : child.getChildren()) { 043 if (grChild instanceof JetTypeReference) { 044 if (!grChild.getText().isEmpty()) 045 //TODO return the actual type 046 type = KotlinBuiltIns.getInstance().getAnyType(); 047 } 048 else if (!JetTokens.WHITE_SPACE_OR_COMMENT_BIT_SET.contains(elementType)) 049 return null; 050 } 051 } 052 else if (!JetTokens.WHITE_SPACE_OR_COMMENT_BIT_SET.contains(elementType)) 053 return null; 054 } 055 056 return type; 057 } 058}