001 /*
002 * Copyright 2010-2014 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.jet.lang.resolve;
018
019 import com.google.common.collect.Lists;
020 import org.jetbrains.annotations.NotNull;
021 import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
022 import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
023 import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
024 import org.jetbrains.jet.lang.descriptors.impl.ValueParameterDescriptorImpl;
025 import org.jetbrains.jet.lang.parsing.JetScriptDefinition;
026 import org.jetbrains.jet.lang.parsing.JetScriptDefinitionProvider;
027 import org.jetbrains.jet.lang.psi.JetFile;
028 import org.jetbrains.jet.lang.psi.JetScript;
029
030 import java.util.List;
031
032 // SCRIPT: Resolve script parameters
033 public final class ScriptParameterResolver {
034 @NotNull
035 public static List<ValueParameterDescriptor> resolveScriptParameters(
036 @NotNull JetScript declaration,
037 @NotNull ScriptDescriptor scriptDescriptor
038 ) {
039 List<ValueParameterDescriptor> valueParameters = Lists.newArrayList();
040
041 JetFile file = declaration.getContainingJetFile();
042 JetScriptDefinition scriptDefinition = JetScriptDefinitionProvider.getInstance(file.getProject()).findScriptDefinition(file);
043
044 int index = 0;
045 for (AnalyzerScriptParameter scriptParameter : scriptDefinition.getScriptParameters()) {
046 ValueParameterDescriptor parameter = resolveScriptParameter(scriptParameter, index, scriptDescriptor);
047 valueParameters.add(parameter);
048 ++index;
049 }
050 return valueParameters;
051 }
052
053 @NotNull
054 private static ValueParameterDescriptor resolveScriptParameter(
055 @NotNull AnalyzerScriptParameter scriptParameter,
056 int index,
057 @NotNull ScriptDescriptor script
058 ) {
059 return new ValueParameterDescriptorImpl(script, null, index, Annotations.EMPTY, scriptParameter.getName(),
060 scriptParameter.getType(), false, null);
061 }
062
063 private ScriptParameterResolver() {
064 }
065 }