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.k2js.translate.reference; 018 019import com.google.dart.compiler.backend.js.ast.JsExpression; 020import org.jetbrains.annotations.NotNull; 021import org.jetbrains.jet.lang.psi.*; 022import org.jetbrains.k2js.translate.context.TranslationContext; 023 024public final class AccessTranslationUtils { 025 private AccessTranslationUtils() { 026 } 027 028 @NotNull 029 public static AccessTranslator getAccessTranslator(@NotNull JetExpression referenceExpression, 030 @NotNull TranslationContext context) { 031 assert ((referenceExpression instanceof JetReferenceExpression) || 032 (referenceExpression instanceof JetQualifiedExpression)); 033 if (referenceExpression instanceof JetQualifiedExpression) { 034 return QualifiedExpressionTranslator.getAccessTranslator((JetQualifiedExpression) referenceExpression, context); 035 } 036 if (referenceExpression instanceof JetSimpleNameExpression) { 037 return ReferenceTranslator.getAccessTranslator((JetSimpleNameExpression) referenceExpression, context); 038 } 039 assert referenceExpression instanceof JetArrayAccessExpression; 040 return ArrayAccessTranslator.newInstance((JetArrayAccessExpression) referenceExpression, context); 041 } 042 043 @NotNull 044 public static CachedAccessTranslator getCachedAccessTranslator(@NotNull JetExpression referenceExpression, 045 @NotNull TranslationContext context) { 046 return getAccessTranslator(referenceExpression, context).getCached(); 047 } 048 049 @NotNull 050 public static JsExpression translateAsGet(@NotNull JetExpression expression, 051 @NotNull TranslationContext context) { 052 return (getAccessTranslator(expression, context)).translateAsGet(); 053 } 054}