summaryrefslogtreecommitdiff
path: root/java/jsp-spi
diff options
context:
space:
mode:
authorJean-Baptiste Queru <jbq@google.com>2013-01-08 11:11:20 -0800
committerJean-Baptiste Queru <jbq@google.com>2013-01-08 11:11:20 -0800
commitb56ea2a18f232d79481e778085fd64e8ae486fc3 (patch)
tree44e1f6eb4864a45033f865b74fe783e3d784dd6a /java/jsp-spi
downloadidea-b56ea2a18f232d79481e778085fd64e8ae486fc3.tar.gz
Snapshot of commit d5ec1d5018ed24f1b4f32b1d09df6dbd7e2fc425
from branch master of git://git.jetbrains.org/idea/community.git
Diffstat (limited to 'java/jsp-spi')
-rw-r--r--java/jsp-spi/jsp-spi.iml20
-rw-r--r--java/jsp-spi/src/com/intellij/jsp/impl/CustomTagDescriptorBase.java25
-rw-r--r--java/jsp-spi/src/com/intellij/jsp/impl/FunctionDescriptor.java53
-rw-r--r--java/jsp-spi/src/com/intellij/jsp/impl/JspElementDescriptor.java24
-rw-r--r--java/jsp-spi/src/com/intellij/jsp/impl/JspNsDescriptor.java27
-rw-r--r--java/jsp-spi/src/com/intellij/jsp/impl/TldAttributeDescriptor.java52
-rw-r--r--java/jsp-spi/src/com/intellij/jsp/impl/TldDescriptor.java47
-rw-r--r--java/jsp-spi/src/com/intellij/jsp/impl/TldTagDescriptor.java25
-rw-r--r--java/jsp-spi/src/com/intellij/jsp/impl/TldTagFileDescriptor.java29
-rw-r--r--java/jsp-spi/src/com/intellij/psi/impl/source/jsp/JspContextManager.java59
-rw-r--r--java/jsp-spi/src/com/intellij/psi/impl/source/jsp/JspManager.java87
-rw-r--r--java/jsp-spi/src/com/intellij/psi/impl/source/jsp/jspJava/JspExpressionStatement.java25
-rw-r--r--java/jsp-spi/src/com/intellij/psi/jsp/JspElementType.java46
-rw-r--r--java/jsp-spi/src/com/intellij/psi/jsp/JspSpiUtil.java237
14 files changed, 756 insertions, 0 deletions
diff --git a/java/jsp-spi/jsp-spi.iml b/java/jsp-spi/jsp-spi.iml
new file mode 100644
index 000000000000..416c7c0a507e
--- /dev/null
+++ b/java/jsp-spi/jsp-spi.iml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module relativePaths="true" type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="module" module-name="jsp-openapi" exported="" />
+ <orderEntry type="module" module-name="openapi" exported="" />
+ <orderEntry type="module" module-name="jsp-base-openapi" />
+ </component>
+ <component name="copyright">
+ <Base>
+ <setting name="state" value="1" />
+ </Base>
+ </component>
+</module>
+
diff --git a/java/jsp-spi/src/com/intellij/jsp/impl/CustomTagDescriptorBase.java b/java/jsp-spi/src/com/intellij/jsp/impl/CustomTagDescriptorBase.java
new file mode 100644
index 000000000000..6177b41df73f
--- /dev/null
+++ b/java/jsp-spi/src/com/intellij/jsp/impl/CustomTagDescriptorBase.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2000-2009 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.jsp.impl;
+
+import com.intellij.psi.meta.PsiMetaData;
+import com.intellij.psi.meta.PsiWritableMetaData;
+
+/**
+ * @author peter
+ */
+public interface CustomTagDescriptorBase extends JspElementDescriptor, PsiWritableMetaData, PsiMetaData {
+}
diff --git a/java/jsp-spi/src/com/intellij/jsp/impl/FunctionDescriptor.java b/java/jsp-spi/src/com/intellij/jsp/impl/FunctionDescriptor.java
new file mode 100644
index 000000000000..8d309b56109b
--- /dev/null
+++ b/java/jsp-spi/src/com/intellij/jsp/impl/FunctionDescriptor.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2000-2009 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.jsp.impl;
+
+import com.intellij.psi.PsiMethod;
+import com.intellij.psi.PsiType;
+import com.intellij.psi.meta.PsiMetaData;
+import com.intellij.psi.meta.PsiWritableMetaData;
+import com.intellij.psi.xml.XmlTag;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+
+/**
+ * @author peter
+ */
+public interface FunctionDescriptor extends PsiWritableMetaData, PsiMetaData {
+ String getFunctionClass();
+
+ void setFunctionClass(String functionClass);
+
+ String getFunctionSignature();
+
+ void setFunctionSignature(String functionSignature);
+
+ XmlTag getTag();
+
+ int getParameterCount();
+
+ String getFunctionName();
+
+ List<String> getFunctionParameters();
+
+ String getFunctionReturnType();
+
+ @Nullable
+ PsiType getResultType();
+
+ @Nullable PsiMethod getReferencedMethod();
+}
diff --git a/java/jsp-spi/src/com/intellij/jsp/impl/JspElementDescriptor.java b/java/jsp-spi/src/com/intellij/jsp/impl/JspElementDescriptor.java
new file mode 100644
index 000000000000..b9cbbd1e302d
--- /dev/null
+++ b/java/jsp-spi/src/com/intellij/jsp/impl/JspElementDescriptor.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2000-2009 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.jsp.impl;
+
+import com.intellij.xml.XmlElementDescriptor;
+
+/**
+ * @author Maxim.Mossienko
+ */
+public interface JspElementDescriptor extends XmlElementDescriptor {
+}
diff --git a/java/jsp-spi/src/com/intellij/jsp/impl/JspNsDescriptor.java b/java/jsp-spi/src/com/intellij/jsp/impl/JspNsDescriptor.java
new file mode 100644
index 000000000000..e834c835b44a
--- /dev/null
+++ b/java/jsp-spi/src/com/intellij/jsp/impl/JspNsDescriptor.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2000-2009 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.jsp.impl;
+
+import com.intellij.openapi.project.DumbAware;
+import com.intellij.xml.XmlNSDescriptor;
+import org.jetbrains.annotations.NonNls;
+
+/**
+ * @author peter
+ */
+public interface JspNsDescriptor extends XmlNSDescriptor {
+ @NonNls String ROOT_ELEMENT_DESCRIPTOR = "root";
+}
diff --git a/java/jsp-spi/src/com/intellij/jsp/impl/TldAttributeDescriptor.java b/java/jsp-spi/src/com/intellij/jsp/impl/TldAttributeDescriptor.java
new file mode 100644
index 000000000000..57bd038f57e0
--- /dev/null
+++ b/java/jsp-spi/src/com/intellij/jsp/impl/TldAttributeDescriptor.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2000-2009 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.jsp.impl;
+
+import com.intellij.xml.XmlAttributeDescriptor;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author Maxim.Mossienko
+ */
+public interface TldAttributeDescriptor extends XmlAttributeDescriptor {
+
+ /**
+ * Indicates that attribute is a fragment
+ *
+ * @return
+ */
+ boolean isIndirectSyntax();
+
+ /**
+ * Returns method signature for deferred methods
+ *
+ * @return
+ */
+ @Nullable
+ String getMethodSignature();
+
+ /**
+ * Returns value of "type" subtag
+ *
+ * @return
+ */
+ @Nullable
+ String getType();
+
+ boolean isDeferred();
+
+ boolean isDynamic();
+}
diff --git a/java/jsp-spi/src/com/intellij/jsp/impl/TldDescriptor.java b/java/jsp-spi/src/com/intellij/jsp/impl/TldDescriptor.java
new file mode 100644
index 000000000000..86df475e9457
--- /dev/null
+++ b/java/jsp-spi/src/com/intellij/jsp/impl/TldDescriptor.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2000-2009 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.jsp.impl;
+
+import com.intellij.psi.xml.XmlFile;
+import com.intellij.xml.XmlElementDescriptor;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author peter
+ */
+public interface TldDescriptor extends JspNsDescriptor {
+ XmlElementDescriptor getElementDescriptor(String name);
+
+ @Nullable
+ String getUri();
+
+ /**
+ *
+ * @return short name, or null if not present
+ */
+ @Nullable
+ String getDefaultPrefix();
+
+ int getFunctionsCount();
+
+ String[] getFunctionNames();
+
+ XmlFile getDeclarationFile();
+
+ FunctionDescriptor getFunctionDescriptor(String name);
+
+ void resetClassloaderState();
+}
diff --git a/java/jsp-spi/src/com/intellij/jsp/impl/TldTagDescriptor.java b/java/jsp-spi/src/com/intellij/jsp/impl/TldTagDescriptor.java
new file mode 100644
index 000000000000..89a028452730
--- /dev/null
+++ b/java/jsp-spi/src/com/intellij/jsp/impl/TldTagDescriptor.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2000-2009 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.jsp.impl;
+
+/**
+ * @author mike
+ */
+public interface TldTagDescriptor extends JspElementDescriptor {
+ String getTagClass();
+
+ String getTeiClass();
+}
diff --git a/java/jsp-spi/src/com/intellij/jsp/impl/TldTagFileDescriptor.java b/java/jsp-spi/src/com/intellij/jsp/impl/TldTagFileDescriptor.java
new file mode 100644
index 000000000000..8caa39c6e901
--- /dev/null
+++ b/java/jsp-spi/src/com/intellij/jsp/impl/TldTagFileDescriptor.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2000-2009 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.jsp.impl;
+
+import com.intellij.psi.xml.XmlTag;
+import org.jetbrains.annotations.NonNls;
+
+/**
+ * @author peter
+ */
+public interface TldTagFileDescriptor extends CustomTagDescriptorBase {
+ @NonNls String TAG_SUFFIX = "tag";
+ @NonNls String TAGX_SUFFIX = "tagx";
+
+ XmlTag getRealDeclaration();
+}
diff --git a/java/jsp-spi/src/com/intellij/psi/impl/source/jsp/JspContextManager.java b/java/jsp-spi/src/com/intellij/psi/impl/source/jsp/JspContextManager.java
new file mode 100644
index 000000000000..21d1701b096d
--- /dev/null
+++ b/java/jsp-spi/src/com/intellij/psi/impl/source/jsp/JspContextManager.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2000-2009 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.psi.impl.source.jsp;
+
+import com.intellij.openapi.project.Project;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.jsp.BaseJspFile;
+import com.intellij.psi.jsp.JspFile;
+import com.intellij.util.containers.HashSet;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author nik
+ */
+public abstract class JspContextManager {
+
+ public static JspContextManager getInstance(Project project) {
+ return project.getComponent(JspContextManager.class);
+ }
+
+ public abstract BaseJspFile[] getSuitableContextFiles(@NotNull PsiFile file);
+
+ public abstract void setContextFile(@NotNull PsiFile file, @Nullable BaseJspFile contextFile);
+
+ public abstract @Nullable
+ BaseJspFile getContextFile(@NotNull PsiFile file);
+
+ public abstract @Nullable JspFile getConfiguredContextFile(@NotNull PsiFile file);
+
+ public @NotNull
+ BaseJspFile getRootContextFile(@NotNull BaseJspFile file) {
+ BaseJspFile rootContext = file;
+ HashSet<BaseJspFile> recursionPreventer = new HashSet<BaseJspFile>();
+ do {
+ recursionPreventer.add(rootContext);
+ BaseJspFile context = getContextFile(rootContext);
+ if (context == null || recursionPreventer.contains(context)) break;
+ rootContext = context;
+ }
+ while (true);
+
+ return rootContext;
+ }
+}
diff --git a/java/jsp-spi/src/com/intellij/psi/impl/source/jsp/JspManager.java b/java/jsp-spi/src/com/intellij/psi/impl/source/jsp/JspManager.java
new file mode 100644
index 000000000000..3b93049b5e9b
--- /dev/null
+++ b/java/jsp-spi/src/com/intellij/psi/impl/source/jsp/JspManager.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2000-2009 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.psi.impl.source.jsp;
+
+import com.intellij.lang.jsp.IBaseJspManager;
+import com.intellij.lang.jsp.JspVersion;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Key;
+import com.intellij.openapi.util.Pair;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.openapi.components.ServiceManager;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.PsiFileSystemItem;
+import com.intellij.psi.jsp.JspFile;
+import com.intellij.psi.xml.XmlFile;
+import com.intellij.util.containers.MultiMap;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author peter
+ */
+public abstract class JspManager implements IBaseJspManager {
+
+ public static JspManager getInstance(@NotNull Project project) {
+ return ServiceManager.getService(project, JspManager.class);
+ }
+
+ @NotNull
+ public abstract Set<String> getNamespacesByTagName(@NotNull String tagName, @NotNull JspFile context, final boolean showProgress);
+ @NotNull
+ public abstract Set<String> getNamespacesByFunctionName(@NotNull String tagName, @NotNull JspFile context, final boolean showProgress);
+
+ /**
+ * Returns possible tag names for given context JSP file.
+ * @param context context JSP file.
+ * @return set of tag names
+ */
+ @NotNull
+ public abstract MultiMap<String,String> getAvailableTagNames(@NotNull final JspFile context);
+
+ @NotNull
+ public abstract List<Pair<String,String>> getAvailableFunctions(@NotNull final JspFile context);
+
+ @Nullable
+ public abstract String getPrefixForNamespace(@NotNull String namespaceUri, final @NotNull JspFile context);
+
+ @Nullable
+ public abstract String getDefaultPrefix(@NotNull XmlFile taglibFile);
+
+ public abstract String[] getPossibleTldUris(JspFile file);
+
+ public abstract String[] getPossibleTldUris(@NotNull Module module);
+
+ public abstract Collection<XmlFile> getPossibleTldFiles(@NotNull Module module);
+
+ @Nullable
+ public abstract String getTaglibUri(@NotNull XmlFile taglibFile);
+
+ @Nullable
+ public abstract XmlFile getTldFileByUri(@NonNls String uri, @NotNull JspFile jspFile);
+
+ @Nullable
+ public abstract XmlFile getTldFileByUri(@NonNls String uri, @Nullable Module module, @Nullable JspFile jspFile);
+
+ @NotNull
+ public abstract JspVersion getJspVersion(@NotNull PsiFileSystemItem context);
+}
diff --git a/java/jsp-spi/src/com/intellij/psi/impl/source/jsp/jspJava/JspExpressionStatement.java b/java/jsp-spi/src/com/intellij/psi/impl/source/jsp/jspJava/JspExpressionStatement.java
new file mode 100644
index 000000000000..e13ac13b6def
--- /dev/null
+++ b/java/jsp-spi/src/com/intellij/psi/impl/source/jsp/jspJava/JspExpressionStatement.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2000-2009 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.
+ */
+
+/*
+ * @author max
+ */
+package com.intellij.psi.impl.source.jsp.jspJava;
+
+import com.intellij.psi.PsiExpressionStatement;
+
+public interface JspExpressionStatement extends PsiExpressionStatement {
+} \ No newline at end of file
diff --git a/java/jsp-spi/src/com/intellij/psi/jsp/JspElementType.java b/java/jsp-spi/src/com/intellij/psi/jsp/JspElementType.java
new file mode 100644
index 000000000000..48162cbec54f
--- /dev/null
+++ b/java/jsp-spi/src/com/intellij/psi/jsp/JspElementType.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2000-2009 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.psi.jsp;
+
+import com.intellij.psi.tree.IElementType;
+
+/**
+ * @author peter
+ * todo[r.sh] replace usages with JspElementTypeEx in implementation modules
+ */
+public interface JspElementType {
+ enum Kind {
+ HOLDER_TEMPLATE_DATA, JSP_TEMPLATE_EXPRESSION, HOLDER_METHOD, JSP_TEMPLATE_STATEMENT, JSP_CLASS_LEVEL_DECLARATION_STATEMENT,
+ JSP_CODE_BLOCK, JSP_WHILE_STATEMENT, JSP_BLOCK_STATEMENT, JSP_CLASS, JSP_METHOD_CALL, JSP_EXPRESSION, JSP_SCRIPTLET
+ }
+
+ IElementType HOLDER_TEMPLATE_DATA = JspSpiUtil.getJspElementType(Kind.HOLDER_TEMPLATE_DATA);
+
+ IElementType JSP_TEMPLATE_EXPRESSION = JspSpiUtil.getJspElementType(Kind.JSP_TEMPLATE_EXPRESSION);
+ IElementType HOLDER_METHOD = JspSpiUtil.getJspElementType(Kind.HOLDER_METHOD);
+
+ IElementType JSP_TEMPLATE_STATEMENT = JspSpiUtil.getJspElementType(Kind.JSP_TEMPLATE_STATEMENT);
+ IElementType JSP_CLASS_LEVEL_DECLARATION_STATEMENT = JspSpiUtil.getJspElementType(Kind.JSP_CLASS_LEVEL_DECLARATION_STATEMENT);
+ IElementType JSP_CODE_BLOCK = JspSpiUtil.getJspElementType(Kind.JSP_CODE_BLOCK);
+ IElementType JSP_WHILE_STATEMENT = JspSpiUtil.getJspElementType(Kind.JSP_WHILE_STATEMENT);
+ IElementType JSP_BLOCK_STATEMENT = JspSpiUtil.getJspElementType(Kind.JSP_BLOCK_STATEMENT);
+
+ IElementType JSP_CLASS = JspSpiUtil.getJspElementType(Kind.JSP_CLASS);
+ IElementType JSP_METHOD_CALL = JspSpiUtil.getJspElementType(Kind.JSP_METHOD_CALL);
+
+ IElementType JSP_EXPRESSION = JspSpiUtil.getJspExpressionType();
+ IElementType JSP_SCRIPTLET = JspSpiUtil.getJspScriptletType();
+}
diff --git a/java/jsp-spi/src/com/intellij/psi/jsp/JspSpiUtil.java b/java/jsp-spi/src/com/intellij/psi/jsp/JspSpiUtil.java
new file mode 100644
index 000000000000..5f78d155c774
--- /dev/null
+++ b/java/jsp-spi/src/com/intellij/psi/jsp/JspSpiUtil.java
@@ -0,0 +1,237 @@
+/*
+ * Copyright 2000-2009 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.psi.jsp;
+
+import com.intellij.openapi.components.ServiceManager;
+import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.roots.ModuleRootManager;
+import com.intellij.openapi.roots.OrderEnumerator;
+import com.intellij.openapi.util.SystemInfo;
+import com.intellij.openapi.vfs.JarFileSystem;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.PsiClass;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.PsiReference;
+import com.intellij.psi.impl.source.jsp.jspJava.JspClass;
+import com.intellij.psi.tree.IElementType;
+import com.intellij.psi.util.PsiTreeUtil;
+import com.intellij.util.ArrayUtil;
+import com.intellij.util.Consumer;
+import com.intellij.util.IncorrectOperationException;
+import com.intellij.util.Processor;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author peter
+ */
+public abstract class JspSpiUtil {
+ private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.jsp.tagLibrary.JspTagInfoImpl");
+ @NonNls private static final String JAR_EXTENSION = "jar";
+
+ @Nullable
+ private static JspSpiUtil getJspSpiUtil() {
+ return ServiceManager.getService(JspSpiUtil.class);
+ }
+
+ public static int escapeCharsInJspContext(JspFile file, int offset, String toEscape) throws IncorrectOperationException {
+ final JspSpiUtil util = getJspSpiUtil();
+ return util != null ? util._escapeCharsInJspContext(file, offset, toEscape) : 0;
+ }
+
+ protected abstract int _escapeCharsInJspContext(JspFile file, int offset, String toEscape) throws IncorrectOperationException;
+
+ public static void visitAllIncludedFilesRecursively(BaseJspFile jspFile, Processor<BaseJspFile> visitor) {
+ final JspSpiUtil util = getJspSpiUtil();
+ if (util != null) {
+ util._visitAllIncludedFilesRecursively(jspFile, visitor);
+ }
+ }
+
+ protected abstract void _visitAllIncludedFilesRecursively(BaseJspFile jspFile, Processor<BaseJspFile> visitor);
+
+ @Nullable
+ public static PsiElement resolveMethodPropertyReference(@NotNull PsiReference reference, @Nullable PsiClass resolvedClass, boolean readable) {
+ final JspSpiUtil util = getJspSpiUtil();
+ return util == null ? null : util._resolveMethodPropertyReference(reference, resolvedClass, readable);
+ }
+
+ @Nullable
+ protected abstract PsiElement _resolveMethodPropertyReference(@NotNull PsiReference reference, @Nullable PsiClass resolvedClass, boolean readable);
+
+ @NotNull
+ public static Object[] getMethodPropertyReferenceVariants(@NotNull PsiReference reference, @Nullable PsiClass resolvedClass, boolean readable) {
+ final JspSpiUtil util = getJspSpiUtil();
+ return util == null ? ArrayUtil.EMPTY_OBJECT_ARRAY : util._getMethodPropertyReferenceVariants(reference, resolvedClass, readable);
+ }
+
+ protected abstract Object[] _getMethodPropertyReferenceVariants(@NotNull PsiReference reference, @Nullable PsiClass resolvedClass, boolean readable);
+
+ public static boolean isIncludedOrIncludesSomething(@NotNull JspFile file) {
+ return isIncludingAnything(file) || isIncluded(file);
+ }
+
+ public static boolean isIncluded(@NotNull JspFile jspFile) {
+ final JspSpiUtil util = getJspSpiUtil();
+ return util != null && util._isIncluded(jspFile);
+ }
+
+ public abstract boolean _isIncluded(@NotNull final JspFile jspFile);
+
+ public static boolean isIncludingAnything(@NotNull JspFile jspFile) {
+ final JspSpiUtil util = getJspSpiUtil();
+ return util != null && util._isIncludingAnything(jspFile);
+ }
+
+ protected abstract boolean _isIncludingAnything(@NotNull final JspFile jspFile);
+
+ public static PsiFile[] getIncludedFiles(@NotNull JspFile jspFile) {
+ final JspSpiUtil util = getJspSpiUtil();
+ return util == null ? PsiFile.EMPTY_ARRAY : util._getIncludedFiles(jspFile);
+ }
+
+ public static PsiFile[] getIncludingFiles(@NotNull JspFile jspFile) {
+ final JspSpiUtil util = getJspSpiUtil();
+ return util == null ? PsiFile.EMPTY_ARRAY : util._getIncludingFiles(jspFile);
+ }
+
+ protected abstract PsiFile[] _getIncludingFiles(@NotNull PsiFile file);
+
+ @NotNull
+ protected abstract PsiFile[] _getIncludedFiles(@NotNull final JspFile jspFile);
+
+ public static boolean isJavaContext(PsiElement position) {
+ if(PsiTreeUtil.getContextOfType(position, JspClass.class, false) != null) return true;
+ return false;
+ }
+
+ public static boolean isJarFile(@Nullable VirtualFile file) {
+ if (file != null){
+ final String ext = file.getExtension();
+ if(ext != null && ext.equalsIgnoreCase(JAR_EXTENSION)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public static List<URL> buildUrls(@Nullable final VirtualFile virtualFile, @Nullable final Module module) {
+ return buildUrls(virtualFile, module, true);
+ }
+
+ public static List<URL> buildUrls(@Nullable final VirtualFile virtualFile, @Nullable final Module module, boolean includeModuleOutput) {
+ final List<URL> urls = new ArrayList<URL>();
+ processClassPathItems(virtualFile, module, new Consumer<VirtualFile>() {
+ public void consume(final VirtualFile file) {
+ addUrl(urls, file);
+ }
+ }, includeModuleOutput);
+ return urls;
+ }
+
+ public static void processClassPathItems(final VirtualFile virtualFile, final Module module, final Consumer<VirtualFile> consumer) {
+ processClassPathItems(virtualFile, module, consumer, true);
+ }
+
+ public static void processClassPathItems(final VirtualFile virtualFile, final Module module, final Consumer<VirtualFile> consumer,
+ boolean includeModuleOutput) {
+ if (isJarFile(virtualFile)){
+ consumer.consume(virtualFile);
+ }
+
+ if (module != null) {
+ OrderEnumerator enumerator = ModuleRootManager.getInstance(module).orderEntries().recursively();
+ if (!includeModuleOutput) {
+ enumerator = enumerator.withoutModuleSourceEntries();
+ }
+ for (VirtualFile root : enumerator.getClassesRoots()) {
+ final VirtualFile file;
+ if (root.getFileSystem().getProtocol().equals(JarFileSystem.PROTOCOL)) {
+ file = JarFileSystem.getInstance().getVirtualFileForJar(root);
+ }
+ else {
+ file = root;
+ }
+ consumer.consume(file);
+ }
+ }
+ }
+
+ private static void addUrl(List<URL> urls, VirtualFile file) {
+ if (file == null || !file.isValid()) return;
+ final URL url = getUrl(file);
+ if (url != null) {
+ urls.add(url);
+ }
+ }
+
+ @SuppressWarnings({"HardCodedStringLiteral"})
+ @Nullable
+ private static URL getUrl(VirtualFile file) {
+ if (file.getFileSystem() instanceof JarFileSystem && file.getParent() != null) return null;
+
+ String path = file.getPath();
+ if (path.endsWith(JarFileSystem.JAR_SEPARATOR)) {
+ path = path.substring(0, path.length() - 2);
+ }
+
+ String url;
+ if (SystemInfo.isWindows) {
+ url = "file:/" + path;
+ }
+ else {
+ url = "file://" + path;
+ }
+
+ if (file.isDirectory() && !(file.getFileSystem() instanceof JarFileSystem)) url += "/";
+
+
+ try {
+ return new URL(url);
+ }
+ catch (MalformedURLException e) {
+ LOG.error(e);
+ return null;
+ }
+ }
+
+ @Nullable
+ public static IElementType getJspElementType(@NotNull final JspElementType.Kind kind) {
+ final JspSpiUtil spiUtil = getJspSpiUtil();
+ return spiUtil != null ? spiUtil._getJspElementType(kind) : null;
+ }
+
+ @Nullable
+ public static IElementType getJspScriptletType() {
+ return getJspElementType(JspElementType.Kind.JSP_SCRIPTLET);
+ }
+
+ @Nullable
+ public static IElementType getJspExpressionType() {
+ return getJspElementType(JspElementType.Kind.JSP_EXPRESSION);
+ }
+
+ protected abstract IElementType _getJspElementType(@NotNull final JspElementType.Kind kind);
+}