/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.coldFusion.model;
import com.intellij.coldFusion.model.psi.impl.CfmlFunctionParameterImpl;
import com.intellij.coldFusion.model.psi.impl.CfmlTagFunctionParameterImpl;
import com.intellij.psi.PsiElement;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.Nullable;
/**
* @author vnikolaenko
*/
public class CfmlScopesInfo {
private static String[] ourTypeNames = {
"application",
"arguments",
"attributes",
"caller",
"cgi",
"client",
"cookie",
"flash",
"form",
"request",
"server",
"session",
// "this",
"thistag",
"thread",
"url",
"variables",
"default",
"super"
};
public static final int APPLICATION_SCOPE = 0;
public static final int ARGUMENTS_SCOPE = 1;
public static final int ATTRIBUTES_SCOPE = 2;
public static final int CALLER_SCOPE = 3;
public static final int CGI_SCOPE = 4;
public static final int CLIENT_SCOPE = 5;
public static final int COOKIE_SCOPE = 6;
public static final int FLASH_SCOPE = 7;
public static final int FORM_SCOPE = 8;
public static final int REQUEST_SCOPE = 9;
public static final int SERVER_SCOPE = 10;
public static final int SESSION_SCOPE = 11;
public static final int THIS_SCOPE = 12;
public static final int THISTAG_SCOPE = 13;
public static final int THREAD_SCOPE = 14;
public static final int URL_SCOPE = 15;
public static final int VARIABLES_SCOPE = 16;
public static final int DEFAULT_SCOPE = 17;
public static int getScopeByString(@Nullable String s) {
if (s == null) {
return DEFAULT_SCOPE;
}
final int find = ArrayUtil.find(ourTypeNames, s.toLowerCase());
if (find != -1) {
return find;
}
return DEFAULT_SCOPE;
}
public static boolean isConvenient(PsiElement targetElement, int scopeSource) {
if (scopeSource == ARGUMENTS_SCOPE) {
if (targetElement instanceof CfmlTagFunctionParameterImpl || targetElement instanceof CfmlFunctionParameterImpl) {
return true;
}
return false;
}
return true;
}
}