intelliLang dependency optimization

This commit is contained in:
Gregory Shrago
2010-04-05 20:36:19 +04:00
parent a22a4aacf5
commit a6c33dd0f6
88 changed files with 665 additions and 363 deletions
+11 -8
View File
@@ -65,13 +65,17 @@
<option name="countGettersAndSetters" value="false" />
</inspection_tool>
<inspection_tool class="FieldMayBeStatic" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="Finalize" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="Finalize" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoreTrivialFinalizers" value="true" />
</inspection_tool>
<inspection_tool class="FinalizeNotProtected" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="ForLoopReplaceableByWhile" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_ignoreLoopsWithoutConditions" value="false" />
</inspection_tool>
<inspection_tool class="ForLoopThatDoesntUseLoopVariable" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="IOResource" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="IOResource" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredTypesString" value="java.io.ByteArrayOutputStream,java.io.ByteArrayInputStream,java.io.StringBufferInputStream,java.io.CharArrayWriter,java.io.CharArrayReader,java.io.StringWriter,java.io.StringReader" />
</inspection_tool>
<inspection_tool class="IfStatementWithIdenticalBranches" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="InnerClassMayBeStatic" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="InstanceofCatchParameter" enabled="true" level="WARNING" enabled_by_default="true" />
@@ -109,6 +113,7 @@
</option>
<option name="IGNORE_DEPRECATED" value="false" />
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
<option name="myAdditionalJavadocTags" value="" />
</scope>
<scope name="idea openapi" level="WARNING" enabled="true">
@@ -138,6 +143,7 @@
</option>
<option name="IGNORE_DEPRECATED" value="true" />
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
<option name="myAdditionalJavadocTags" value="" />
</scope>
<scope name="runtime.classes" level="WARNING" enabled="true">
@@ -167,6 +173,7 @@
</option>
<option name="IGNORE_DEPRECATED" value="false" />
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
<option name="myAdditionalJavadocTags" value="" />
</scope>
<option name="TOP_LEVEL_CLASS_OPTIONS">
@@ -195,6 +202,7 @@
</option>
<option name="IGNORE_DEPRECATED" value="false" />
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
<option name="myAdditionalJavadocTags" value="" />
</inspection_tool>
<inspection_tool class="JavadocReference" enabled="true" level="WARNING" enabled_by_default="true">
@@ -263,12 +271,7 @@
<inspection_tool class="SimplifiableConditionalExpression" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="SimplifiableIfStatement" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="Since15" enabled="true" level="ERROR" enabled_by_default="true">
<scope name="IDEA Test Sources" level="ERROR" enabled="false">
<option name="FORBID_15_API" value="true" />
<option name="FORBID_16_API" value="true" />
</scope>
<option name="FORBID_15_API" value="false" />
<option name="FORBID_16_API" value="true" />
<scope name="IDEA Test Sources" level="ERROR" enabled="false" />
</inspection_tool>
<inspection_tool class="SocketResource" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="StaticSuite" enabled="true" level="WARNING" enabled_by_default="true" />
+11 -8
View File
@@ -65,13 +65,17 @@
<option name="countGettersAndSetters" value="false" />
</inspection_tool>
<inspection_tool class="FieldMayBeStatic" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="Finalize" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="Finalize" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoreTrivialFinalizers" value="true" />
</inspection_tool>
<inspection_tool class="FinalizeNotProtected" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="ForLoopReplaceableByWhile" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_ignoreLoopsWithoutConditions" value="false" />
</inspection_tool>
<inspection_tool class="ForLoopThatDoesntUseLoopVariable" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="IOResource" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="IOResource" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredTypesString" value="java.io.ByteArrayOutputStream,java.io.ByteArrayInputStream,java.io.StringBufferInputStream,java.io.CharArrayWriter,java.io.CharArrayReader,java.io.StringWriter,java.io.StringReader" />
</inspection_tool>
<inspection_tool class="IfStatementWithIdenticalBranches" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="InnerClassMayBeStatic" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="InstanceofCatchParameter" enabled="true" level="WARNING" enabled_by_default="true" />
@@ -109,6 +113,7 @@
</option>
<option name="IGNORE_DEPRECATED" value="false" />
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
<option name="myAdditionalJavadocTags" value="" />
</scope>
<scope name="idea openapi" level="WARNING" enabled="true">
@@ -138,6 +143,7 @@
</option>
<option name="IGNORE_DEPRECATED" value="true" />
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
<option name="myAdditionalJavadocTags" value="" />
</scope>
<scope name="runtime.classes" level="WARNING" enabled="true">
@@ -167,6 +173,7 @@
</option>
<option name="IGNORE_DEPRECATED" value="false" />
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
<option name="myAdditionalJavadocTags" value="" />
</scope>
<option name="TOP_LEVEL_CLASS_OPTIONS">
@@ -195,6 +202,7 @@
</option>
<option name="IGNORE_DEPRECATED" value="false" />
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
<option name="myAdditionalJavadocTags" value="" />
</inspection_tool>
<inspection_tool class="JavadocReference" enabled="true" level="WARNING" enabled_by_default="true">
@@ -263,12 +271,7 @@
<inspection_tool class="SimplifiableConditionalExpression" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="SimplifiableIfStatement" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="Since15" enabled="true" level="ERROR" enabled_by_default="true">
<scope name="IDEA Test Sources" level="ERROR" enabled="false">
<option name="FORBID_15_API" value="true" />
<option name="FORBID_16_API" value="true" />
</scope>
<option name="FORBID_15_API" value="false" />
<option name="FORBID_16_API" value="true" />
<scope name="IDEA Test Sources" level="ERROR" enabled="false" />
</inspection_tool>
<inspection_tool class="SocketResource" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
+5 -2
View File
@@ -3,7 +3,10 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/plugins/InspectionGadgets/InspectionGadgetsPlugin.iml" filepath="$PROJECT_DIR$/plugins/InspectionGadgets/InspectionGadgetsPlugin.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/IntelliLang/IntelliLangJava.iml" filepath="$PROJECT_DIR$/plugins/IntelliLang/IntelliLangJava.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/IntelliLang/IntelliLang-java.iml" filepath="$PROJECT_DIR$/plugins/IntelliLang/IntelliLang-java.iml" group="plugins/IntelliLang" />
<module fileurl="file://$PROJECT_DIR$/plugins/IntelliLang/IntelliLang-javaee.iml" filepath="$PROJECT_DIR$/plugins/IntelliLang/IntelliLang-javaee.iml" group="plugins/IntelliLang" />
<module fileurl="file://$PROJECT_DIR$/plugins/IntelliLang/IntelliLang-xml.iml" filepath="$PROJECT_DIR$/plugins/IntelliLang/IntelliLang-xml.iml" group="plugins/IntelliLang" />
<module fileurl="file://$PROJECT_DIR$/plugins/IntelliLang/IntelliLangJava.iml" filepath="$PROJECT_DIR$/plugins/IntelliLang/IntelliLangJava.iml" group="plugins/IntelliLang" />
<module fileurl="file://$PROJECT_DIR$/plugins/IntentionPowerPak/IntentionPowerPackPlugin.iml" filepath="$PROJECT_DIR$/plugins/IntentionPowerPak/IntentionPowerPackPlugin.iml" />
<module fileurl="file://$PROJECT_DIR$/RegExpSupport/RegExpSupport.iml" filepath="$PROJECT_DIR$/RegExpSupport/RegExpSupport.iml" />
<module fileurl="file://$PROJECT_DIR$/platform/annotations/annotations.iml" filepath="$PROJECT_DIR$/platform/annotations/annotations.iml" group="platform" />
@@ -70,11 +73,11 @@
<module fileurl="file://$PROJECT_DIR$/plugins/svn4idea/svn4idea.iml" filepath="$PROJECT_DIR$/plugins/svn4idea/svn4idea.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/svn4idea/svn4idea-tests.iml" filepath="$PROJECT_DIR$/plugins/svn4idea/svn4idea-tests.iml" />
<module fileurl="file://$PROJECT_DIR$/platform/testFramework/testFramework.iml" filepath="$PROJECT_DIR$/platform/testFramework/testFramework.iml" group="platform" />
<module fileurl="file://$PROJECT_DIR$/platform/testFramework/bootstrap/tests_bootstrap.iml" filepath="$PROJECT_DIR$/platform/testFramework/bootstrap/tests_bootstrap.iml" group="platform" />
<module fileurl="file://$PROJECT_DIR$/java/testFramework/testFramework-java.iml" filepath="$PROJECT_DIR$/java/testFramework/testFramework-java.iml" group="java" />
<module fileurl="file://$PROJECT_DIR$/platform/testRunner/testRunner.iml" filepath="$PROJECT_DIR$/platform/testRunner/testRunner.iml" group="platform" />
<module fileurl="file://$PROJECT_DIR$/plugins/testng/testng.iml" filepath="$PROJECT_DIR$/plugins/testng/testng.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/testng_rt/testng_rt.iml" filepath="$PROJECT_DIR$/plugins/testng_rt/testng_rt.iml" />
<module fileurl="file://$PROJECT_DIR$/platform/testFramework/bootstrap/tests_bootstrap.iml" filepath="$PROJECT_DIR$/platform/testFramework/bootstrap/tests_bootstrap.iml" group="platform" />
<module fileurl="file://$PROJECT_DIR$/plugins/ui-designer/ui-designer.iml" filepath="$PROJECT_DIR$/plugins/ui-designer/ui-designer.iml" group="plugins" />
<module fileurl="file://$PROJECT_DIR$/platform/usageView/usageView.iml" filepath="$PROJECT_DIR$/platform/usageView/usageView.iml" group="platform" />
<module fileurl="file://$PROJECT_DIR$/platform/util/util.iml" filepath="$PROJECT_DIR$/platform/util/util.iml" group="platform" />
+11 -1
View File
@@ -156,7 +156,17 @@ def layoutFull(String home, String targetDirectory) {
layoutPlugin("ant", "ant", "antIntegration")
layoutPlugin("InspectionGadgets", "InspectionGadgetsPlugin")
layoutPlugin("IntelliLang", "IntelliLangJava")
dir("IntelliLang") {
dir("lib") {
jar("IntelliLang.jar") {
module("IntelliLangJava")
module("IntelliLang-java")
module("IntelliLang-xml")
module("IntelliLang-javaee")
}
}
}
layoutPlugin("IntentionPowerPack", "IntentionPowerPackPlugin")
layoutPlugin("ToString", "generate-tostring", "toString")
@@ -31,4 +31,12 @@ public class JavaLiteralEscaper implements LiteralEscaper {
}
return originalText;
}
public String escapeText(String originalText) {
return StringUtil.escapeStringCharacters(originalText);
}
public String unescapeText(String originalText) {
return StringUtil.unescapeStringCharacters(originalText);
}
}
@@ -29,6 +29,14 @@ public class LanguageLiteralEscapers extends LanguageExtension<LiteralEscaper> {
public String getEscapedText(final PsiElement context, final String originalText) {
return originalText;
}
public String escapeText(String originalText) {
return originalText;
}
public String unescapeText(String originalText) {
return originalText;
}
});
}
}
@@ -23,4 +23,6 @@ import com.intellij.psi.PsiElement;
*/
public interface LiteralEscaper {
String getEscapedText(PsiElement context, String originalText);
String escapeText(String originalText);
String unescapeText(String originalText);
}
@@ -44,6 +44,7 @@
<renameHandler implementation="com.intellij.xml.refactoring.XmlTagRenameHandler"/>
<lang.literalEscaper language="XML" implementationClass="com.intellij.lang.xml.XmlLiteralEscaper"/>
<completion.contributor language="any" implementationClass="com.intellij.codeInsight.completion.XmlCompletionContributor" id="xml"
order="first, before basic2ClassName"/>
+26
View File
@@ -0,0 +1,26 @@
<?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$/java-support">
<sourceFolder url="file://$MODULE_DIR$/java-support" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="openapi" />
<orderEntry type="module" module-name="platform-impl" />
<orderEntry type="module" module-name="lang-impl" />
<orderEntry type="module" module-name="compiler-impl" />
<orderEntry type="library" name="asm" level="project" />
<orderEntry type="module" module-name="RegExpSupport" />
<orderEntry type="module" module-name="platform-api" />
<orderEntry type="module" module-name="java-impl" />
<orderEntry type="module" module-name="IntelliLangJava" />
</component>
<component name="copyright">
<Base>
<setting name="state" value="1" />
</Base>
</component>
</module>
@@ -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$/javaee-support">
<sourceFolder url="file://$MODULE_DIR$/javaee-support" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="IntelliLangJava" />
<orderEntry type="module" module-name="lang-api" />
<orderEntry type="module" module-name="jsp-spi" />
</component>
<component name="copyright">
<Base>
<setting name="state" value="1" />
</Base>
</component>
</module>
+27
View File
@@ -0,0 +1,27 @@
<?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$/xml-support">
<sourceFolder url="file://$MODULE_DIR$/xml-support" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="openapi" />
<orderEntry type="module" module-name="platform-impl" />
<orderEntry type="module" module-name="lang-impl" />
<orderEntry type="module" module-name="xml" />
<orderEntry type="library" name="asm" level="project" />
<orderEntry type="module" module-name="RegExpSupport" />
<orderEntry type="module" module-name="xpath" />
<orderEntry type="module" module-name="platform-api" />
<orderEntry type="library" name="Jaxen" level="project" />
<orderEntry type="module" module-name="IntelliLangJava" />
</component>
<component name="copyright">
<Base>
<setting name="state" value="1" />
</Base>
</component>
</module>
-8
View File
@@ -7,18 +7,10 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="openapi" />
<orderEntry type="module" module-name="platform-impl" />
<orderEntry type="module" module-name="jsp-spi" />
<orderEntry type="module" module-name="lang-impl" />
<orderEntry type="module" module-name="xml" />
<orderEntry type="module" module-name="compiler-impl" />
<orderEntry type="library" name="asm" level="project" />
<orderEntry type="module" module-name="RegExpSupport" />
<orderEntry type="module" module-name="xpath" />
<orderEntry type="module" module-name="platform-api" />
<orderEntry type="module" module-name="jetgroovy" />
<orderEntry type="module" module-name="java-impl" />
<orderEntry type="library" name="Jaxen" level="project" />
</component>
<component name="copyright">
@@ -117,7 +117,7 @@ public class MethodParameterInjection extends BaseInjection {
@Override
protected List<String> generatePlaces() {
return PatternBasedInjectionHelper.getPatternString(this);
return getPatternString(this);
}
@SuppressWarnings({"RedundantIfStatement"})
@@ -230,6 +230,45 @@ public class MethodParameterInjection extends BaseInjection {
return null;
}
public static String getParameterTypesString(final String signature) {
@NonNls final StringBuilder sb = new StringBuilder();
final StringTokenizer st = new StringTokenizer(signature, "(,)");
//noinspection ForLoopThatDoesntUseLoopVariable
for (int i = 0; st.hasMoreTokens(); i++) {
final String token = st.nextToken().trim();
if (i > 1) sb.append(", ");
final int idx;
if (i == 0) {
// nothing
}
else {
sb.append('\"');
if ((idx = token.indexOf(' ')) > -1) {
sb.append(token.substring(0, idx));
}
else {
sb.append(token);
}
sb.append('\"');
}
}
return sb.toString();
}
public static String getPatternStringForJavaPlace(final String methodName, final String parametersStrings, final int parameterIndex, final String className) {
final StringBuilder sb = new StringBuilder();
if (parameterIndex >= 0) {
sb.append("psiParameter().ofMethod(").append(parameterIndex).append(", ");
}
sb.append("psiMethod().withName(\"").append(methodName)
.append("\").withParameters(").append(parametersStrings)
.append(").definedInClass(\"").append(className).append("\")");
if (parameterIndex >= 0) {
sb.append(")");
}
return sb.toString();
}
public static class MethodInfo {
@NotNull
final String methodSignature;
@@ -343,5 +382,24 @@ public class MethodParameterInjection extends BaseInjection {
}
}
public static List<String> getPatternString(final MethodParameterInjection injection) {
final ArrayList<String> list = new ArrayList<String>();
final String className = injection.getClassName();
for (MethodParameterInjection.MethodInfo info : injection.getMethodInfos()) {
final boolean[] paramFlags = info.getParamFlags();
final int paramFlagsLength = paramFlags.length;
final String methodName = info.getMethodName();
final String typesString = getParameterTypesString(info.getMethodSignature());
if (info.isReturnFlag()) {
list.add(getPatternStringForJavaPlace(methodName, typesString, -1, className));
}
for (int i = 0; i < paramFlagsLength; i++) {
if (paramFlags[i]) {
list.add(getPatternStringForJavaPlace(methodName, typesString, i, className));
}
}
}
return list;
}
}
@@ -38,4 +38,4 @@ public class MethodParameterInjectionConfigurable extends InjectionConfigurable<
public Icon getIcon() {
return Icons.METHOD_ICON;
}
}
}
@@ -45,7 +45,6 @@ import com.intellij.ui.SimpleColoredText;
import com.intellij.ui.SimpleTextAttributes;
import org.intellij.plugins.intelliLang.AdvancedSettingsUI;
import org.intellij.plugins.intelliLang.Configuration;
import org.intellij.plugins.intelliLang.PatternBasedInjectionHelper;
import org.intellij.plugins.intelliLang.inject.AbstractLanguageInjectionSupport;
import org.intellij.plugins.intelliLang.inject.EditInjectionSettingsAction;
import org.intellij.plugins.intelliLang.inject.InjectLanguageAction;
@@ -66,6 +65,8 @@ import java.util.*;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import static org.intellij.plugins.intelliLang.inject.config.MethodParameterInjection.*;
/**
* @author Gregory.Shrago
*/
@@ -245,7 +246,7 @@ public class JavaLanguageInjectionSupport extends AbstractLanguageInjectionSuppo
final MethodParameterInjection injection = new MethodParameterInjection();
injection.setInjectedLanguageId(languageId);
injection.setClassName(className);
final MethodParameterInjection.MethodInfo info = MethodParameterInjection.createMethodInfo(psiMethod);
final MethodParameterInjection.MethodInfo info = createMethodInfo(psiMethod);
if (parameterIndex < 0) {
info.setReturnFlag(true);
}
@@ -389,8 +390,8 @@ public class JavaLanguageInjectionSupport extends AbstractLanguageInjectionSuppo
final PsiModifierList modifiers = method.getModifierList();
if (modifiers.hasModifierProperty(PsiModifier.PRIVATE) || modifiers.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) continue;
boolean add = false;
final MethodParameterInjection.MethodInfo methodInfo = MethodParameterInjection.createMethodInfo(method);
if (MethodParameterInjection.isInjectable(method.getReturnType(), method.getProject())) {
final MethodParameterInjection.MethodInfo methodInfo = createMethodInfo(method);
if (isInjectable(method.getReturnType(), method.getProject())) {
final int parameterIndex = -1;
final InjectionPlace place = injection.findPlaceByText(getPatternStringForJavaPlace(method, parameterIndex));
methodInfo.setReturnFlag(place != null && place.isEnabled() || includeAllPlaces);
@@ -399,7 +400,7 @@ public class JavaLanguageInjectionSupport extends AbstractLanguageInjectionSuppo
final PsiParameter[] parameters = method.getParameterList().getParameters();
for (int i = 0; i < parameters.length; i++) {
final PsiParameter p = parameters[i];
if (MethodParameterInjection.isInjectable(p.getType(), p.getProject())) {
if (isInjectable(p.getType(), p.getProject())) {
final InjectionPlace place = injection.findPlaceByText(getPatternStringForJavaPlace(method, i));
methodInfo.getParamFlags()[i] = place != null && place.isEnabled() || includeAllPlaces;
add = true;
@@ -426,8 +427,8 @@ public class JavaLanguageInjectionSupport extends AbstractLanguageInjectionSuppo
public static String getPatternStringForJavaPlace(final PsiMethod method, final int parameterIndex) {
final PsiClass psiClass = method.getContainingClass();
final String className = psiClass == null ? "" : StringUtil.notNullize(psiClass.getQualifiedName());
final String signature = MethodParameterInjection.createMethodInfo(method).getMethodSignature();
return PatternBasedInjectionHelper.getPatternStringForJavaPlace(method.getName(), PatternBasedInjectionHelper.getParameterTypesString(signature), parameterIndex, className);
final String signature = createMethodInfo(method).getMethodSignature();
return MethodParameterInjection.getPatternStringForJavaPlace(method.getName(), getParameterTypesString(signature), parameterIndex, className);
}
@Override
@@ -476,4 +477,4 @@ public class JavaLanguageInjectionSupport extends AbstractLanguageInjectionSuppo
super.setupPresentation(injection, presentation, isSelected);
}
}
}
}
@@ -97,4 +97,4 @@ public class InjectionNotApplicable extends LocalInspectionTool {
public String getShortName() {
return "InjectionNotApplicable";
}
}
}
@@ -63,4 +63,4 @@ public abstract class StringLiteralReference implements PsiReference {
return (String)myValue.getValue();
}
}
}
@@ -0,0 +1,31 @@
/*
* Copyright 2000-2010 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 org.intellij.plugins.intelliLang.inject.config;
import com.intellij.openapi.module.Module;
import com.intellij.psi.impl.source.jsp.JspManager;
import org.jetbrains.annotations.NotNull;
/**
* @author Gregory.Shrago
*/
public class JspSupportProxyImpl extends JspSupportProxy {
@NotNull
@Override
public String[] getPossibleTldUris(Module module) {
return JspManager.getInstance(module.getProject()).getPossibleTldUris(module);
}
}
@@ -4,6 +4,6 @@
<extensions defaultExtensionNs="com.intellij">
<applicationService serviceInterface="org.intellij.plugins.intelliLang.inject.config.JspSupportProxy"
serviceImplementation="org.intellij.plugins.intelliLang.inject.config.JspSupportProxy$Impl"/>
serviceImplementation="org.intellij.plugins.intelliLang.inject.config.JspSupportProxyImpl"/>
</extensions>
</idea-plugin>
@@ -4,7 +4,7 @@
<extensions defaultExtensionNs="com.intellij">
<applicationService serviceInterface="org.intellij.plugins.intelliLang.inject.config.XPathSupportProxy"
serviceImplementation="org.intellij.plugins.intelliLang.inject.config.XPathSupportProxy$Impl"/>
serviceImplementation="org.intellij.plugins.intelliLang.inject.config.XPathSupportProxyImpl"/>
</extensions>
</idea-plugin>
+1 -2
View File
@@ -9,7 +9,6 @@
<depends optional="true" config-file="intellilang-java-support.xml">com.intellij.modules.java</depends>
<depends optional="true" config-file="intellilang-javaee-support.xml">com.intellij.javaee</depends>
<depends optional="true" config-file="intellilang-xml-support.xml">com.intellij.modules.xml</depends>
<depends optional="true" config-file="intellilang-groovy-support.xml">org.intellij.groovy</depends>
<vendor email="sascha.weinreuter@cit.de" logo="/org/intellij/plugins/intelliLang/icon_small.png">Sascha Weinreuter</vendor>
@@ -45,4 +44,4 @@
<projectService serviceInterface="org.intellij.plugins.intelliLang.inject.TemporaryPlacesRegistry"
serviceImplementation="org.intellij.plugins.intelliLang.inject.TemporaryPlacesRegistry"/>
</extensions>
</idea-plugin>
</idea-plugin>
@@ -122,21 +122,7 @@ public final class Configuration implements PersistentStateComponent<Element> {
for (LanguageInjectionSupport support : Extensions.getExtensions(LanguageInjectionSupport.EP_NAME)) {
supports.put(support.getId(), support);
}
myInjections.get(LanguageInjectionSupport.XML_SUPPORT_ID).addAll(readExternal(element.getChild(TAG_INJECTION_NAME), new Factory<XmlTagInjection>() {
public XmlTagInjection create() {
return new XmlTagInjection();
}
}));
myInjections.get(LanguageInjectionSupport.XML_SUPPORT_ID).addAll(readExternal(element.getChild(ATTRIBUTE_INJECTION_NAME), new Factory<XmlAttributeInjection>() {
public XmlAttributeInjection create() {
return new XmlAttributeInjection();
}
}));
myInjections.get(LanguageInjectionSupport.JAVA_SUPPORT_ID).addAll(readExternal(element.getChild(PARAMETER_INJECTION_NAME), new Factory<MethodParameterInjection>() {
public MethodParameterInjection create() {
return new MethodParameterInjection();
}
}));
loadStateOld(element, supports.get(LanguageInjectionSupport.XML_SUPPORT_ID), supports.get(LanguageInjectionSupport.JAVA_SUPPORT_ID));
for (Element child : (List<Element>)element.getChildren("injection")){
final String key = child.getAttributeValue("injector-id");
final LanguageInjectionSupport support = supports.get(key);
@@ -163,6 +149,31 @@ public final class Configuration implements PersistentStateComponent<Element> {
}
}
private void loadStateOld(Element element, final LanguageInjectionSupport xmlSupport, final LanguageInjectionSupport javaSupport) {
if (xmlSupport != null) {
final Element xmlTagMarker = new Element("XmlTagInjection");
myInjections.get(LanguageInjectionSupport.XML_SUPPORT_ID).addAll(readExternal(element.getChild(TAG_INJECTION_NAME), new Factory<BaseInjection>() {
public BaseInjection create() {
return xmlSupport.createInjection(xmlTagMarker);
}
}));
final Element xmlAttributeMarker = new Element("XmlAttributeInjection");
myInjections.get(LanguageInjectionSupport.XML_SUPPORT_ID).addAll(readExternal(element.getChild(ATTRIBUTE_INJECTION_NAME), new Factory<BaseInjection>() {
public BaseInjection create() {
return xmlSupport.createInjection(xmlAttributeMarker);
}
}));
}
if (javaSupport != null) {
final Element javaMethodMarker = new Element("MethodParameterInjection");
myInjections.get(LanguageInjectionSupport.JAVA_SUPPORT_ID).addAll(readExternal(element.getChild(PARAMETER_INJECTION_NAME), new Factory<BaseInjection>() {
public BaseInjection create() {
return javaSupport.createInjection(javaMethodMarker);
}
}));
}
}
private static boolean readBoolean(Element element, String key, boolean defValue) {
final String value = JDOMExternalizerUtil.readField(element, key);
if (value == null) return defValue;
@@ -18,7 +18,6 @@ package org.intellij.plugins.intelliLang;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.patterns.ElementPattern;
import com.intellij.psi.PsiElement;
import com.intellij.util.Function;
@@ -27,9 +26,6 @@ import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.Stack;
import gnu.trove.THashSet;
import org.intellij.plugins.intelliLang.inject.LanguageInjectionSupport;
import org.intellij.plugins.intelliLang.inject.config.AbstractTagInjection;
import org.intellij.plugins.intelliLang.inject.config.MethodParameterInjection;
import org.intellij.plugins.intelliLang.inject.config.XmlAttributeInjection;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
@@ -71,86 +67,6 @@ public class PatternBasedInjectionHelper {
// return StandardPatterns.or(list.toArray(new ElementPattern[list.size()]));
//}
public static List<String> getPatternString(final MethodParameterInjection injection) {
final ArrayList<String> list = new ArrayList<String>();
final String className = injection.getClassName();
for (MethodParameterInjection.MethodInfo info : injection.getMethodInfos()) {
final boolean[] paramFlags = info.getParamFlags();
final int paramFlagsLength = paramFlags.length;
final String methodName = info.getMethodName();
final String typesString = getParameterTypesString(info.getMethodSignature());
if (info.isReturnFlag()) {
list.add(getPatternStringForJavaPlace(methodName, typesString, -1, className));
}
for (int i = 0; i < paramFlagsLength; i++) {
if (paramFlags[i]) {
list.add(getPatternStringForJavaPlace(methodName, typesString, i, className));
}
}
}
return list;
}
public static String getParameterTypesString(final String signature) {
@NonNls final StringBuilder sb = new StringBuilder();
final StringTokenizer st = new StringTokenizer(signature, "(,)");
//noinspection ForLoopThatDoesntUseLoopVariable
for (int i = 0; st.hasMoreTokens(); i++) {
final String token = st.nextToken().trim();
if (i > 1) sb.append(", ");
final int idx;
if (i == 0) {
// nothing
}
else {
sb.append('\"');
if ((idx = token.indexOf(' ')) > -1) {
sb.append(token.substring(0, idx));
}
else {
sb.append(token);
}
sb.append('\"');
}
}
return sb.toString();
}
public static String getPatternStringForJavaPlace(final String methodName, final String parametersStrings, final int parameterIndex, final String className) {
final StringBuilder sb = new StringBuilder();
if (parameterIndex >= 0) {
sb.append("psiParameter().ofMethod(").append(parameterIndex).append(", ");
}
sb.append("psiMethod().withName(\"").append(methodName)
.append("\").withParameters(").append(parametersStrings)
.append(").definedInClass(\"").append(className).append("\")");
if (parameterIndex >= 0) {
sb.append(")");
}
return sb.toString();
}
public static String getPatternString(final XmlAttributeInjection injection) {
final String name = injection.getAttributeName();
final String namespace = injection.getAttributeNamespace();
final StringBuilder result = new StringBuilder("xmlAttribute()");
if (StringUtil.isNotEmpty(name)) result.append(".withLocalName(string().matches(\"").append(name).append("\"))");
if (StringUtil.isNotEmpty(namespace)) result.append(".withNamespace(string().matches(\"").append(namespace).append("\"))");
if (StringUtil.isNotEmpty(injection.getTagName()) || StringUtil.isNotEmpty(injection.getTagNamespace())) {
result.append(".inside(").append(getPatternString((AbstractTagInjection)injection)).append(")");
}
return result.toString();
}
public static String getPatternString(final AbstractTagInjection injection) {
final String name = injection.getTagName();
final String namespace = injection.getTagNamespace();
final StringBuilder result = new StringBuilder("xmlTag()");
if (StringUtil.isNotEmpty(name)) result.append(".withLocalName(string().matches(\"").append(name).append("\"))");
if (StringUtil.isNotEmpty(namespace)) result.append(".withNamespace(string().matches(\"").append(namespace).append("\"))");
return result.toString();
}
@Nullable
public static ElementPattern<PsiElement> createElementPattern(final String text, final String displayName, final String supportId) {
return createElementPatternNoGroovy(text, displayName, supportId);
@@ -17,20 +17,17 @@
package org.intellij.plugins.intelliLang.inject;
import com.intellij.lang.Language;
import com.intellij.lang.LanguageLiteralEscapers;
import com.intellij.lang.LiteralEscaper;
import com.intellij.lang.injection.MultiHostRegistrar;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.Trinity;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiLanguageInjectionHost;
import com.intellij.psi.PsiLiteralExpression;
import com.intellij.psi.xml.XmlElement;
import com.intellij.util.NotNullFunction;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.xml.util.XmlUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -56,17 +53,6 @@ public class InjectorUtils {
registrar.addPlace(prefix, suffix, host, textRange);
}
public static String getUnescapedText(final PsiElement host, final String text) {
if (host instanceof PsiLiteralExpression) {
return StringUtil.unescapeStringCharacters(text);
}
else if (host instanceof XmlElement) {
return XmlUtil.unescape(text);
}
else {
return text;
}
}// Avoid sticking text and prefix/suffix together in a way that it would form a single token.
// See http://www.jetbrains.net/jira/browse/IDEADEV-8302#action_111865
// This code assumes that for the injected language a single space character is a token separator
// that doesn't (significantly) change the semantics if added to the prefix/suffix
@@ -117,6 +103,7 @@ public class InjectorUtils {
if (language == null/* && (pair.second.getLength() > 0*/) {
return;
}
final LiteralEscaper literalEscaper = LanguageLiteralEscapers.INSTANCE.forLanguage(containingFile.getLanguage());
boolean injectionStarted = false;
for (Trinity<PsiLanguageInjectionHost, InjectedLanguage, TextRange> trinity : list) {
final PsiLanguageInjectionHost host = trinity.first;
@@ -134,7 +121,10 @@ public class InjectorUtils {
// useful cases may break. This system is far from perfect still...
final StringBuilder prefix = new StringBuilder(injectedLanguage.getPrefix());
final StringBuilder suffix = new StringBuilder(injectedLanguage.getSuffix());
adjustPrefixAndSuffix(getUnescapedText(host, textRange.substring(host.getText())), prefix, suffix);
final String text = textRange.substring(host.getText());
final String result = literalEscaper != null ? literalEscaper.unescapeText(text) : text;
adjustPrefixAndSuffix(result, prefix, suffix);
addPlaceSafe(registrar, prefix.toString(), suffix.toString(), host, textRange);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2010 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.
@@ -18,7 +18,6 @@ package org.intellij.plugins.intelliLang.inject.config;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.module.Module;
import com.intellij.psi.impl.source.jsp.JspManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -44,12 +43,4 @@ public abstract class JspSupportProxy {
isInitialized = true;
}
}
public static class Impl extends JspSupportProxy {
@NotNull
@Override
public String[] getPossibleTldUris(Module module) {
return JspManager.getInstance(module.getProject()).getPossibleTldUris(module);
}
}
}
@@ -1,129 +0,0 @@
/*
* 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 org.intellij.plugins.intelliLang.inject.config;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.source.xml.XmlTokenImpl;
import com.intellij.psi.xml.XmlElement;
import com.intellij.psi.xml.XmlElementType;
import org.intellij.lang.xpath.context.ContextProvider;
import org.intellij.lang.xpath.context.ContextType;
import org.intellij.lang.xpath.context.NamespaceContext;
import org.intellij.lang.xpath.context.VariableContext;
import org.intellij.lang.xpath.psi.XPathExpression;
import org.intellij.lang.xpath.psi.XPathType;
import org.intellij.plugins.xpathView.support.XPathSupport;
import org.intellij.plugins.xpathView.util.Namespace;
import org.jaxen.JaxenException;
import org.jaxen.XPath;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.xml.namespace.QName;
import java.util.Collections;
import java.util.Set;
/**
* Proxy class that allows to avoid a hard compile time dependency on the XPathView plugin.
*/
public abstract class XPathSupportProxy {
private static final Logger LOG = Logger.getInstance("org.intellij.plugins.intelliLang.inject.config.XPathSupportProxy");
public static final Object UNSUPPORTED = "UNSUPPORTED";
public static final Object INVALID = "INVALID";
@NotNull
public abstract XPath createXPath(String expression) throws JaxenException;
public abstract void attachContext(@NotNull PsiFile file);
private static XPathSupportProxy ourInstance;
private static boolean isInitialized;
@Nullable
public static synchronized XPathSupportProxy getInstance() {
if (isInitialized) {
return ourInstance;
}
try {
return ourInstance = ServiceManager.getService(XPathSupportProxy.class);
} finally {
if (ourInstance == null) {
LOG.info("XPath Support is not available");
}
isInitialized = true;
}
}
public static class Impl extends XPathSupportProxy {
private static class Provider extends ContextProvider {
private final XmlTokenImpl myDummyContext = new XmlTokenImpl(XmlElementType.XML_CONTENT_EMPTY, "") {
@Override
public boolean isValid() {
return true;
}
};
@NotNull
public ContextType getContextType() {
return XPathSupport.TYPE;
}
@NotNull
@Override
public XPathType getExpectedType(XPathExpression expr) {
return XPathType.BOOLEAN;
}
public XmlElement getContextElement() {
// needed because the static method ContextProvider.isValid() checks this to determine if the provider
// is still valid - refactor this into an instance method ContextProvider.isValid()?
return myDummyContext;
}
public NamespaceContext getNamespaceContext() {
return null;
}
public VariableContext getVariableContext() {
return null;
}
public Set<QName> getAttributes(boolean forValidation) {
return null;
}
public Set<QName> getElements(boolean forValidation) {
return null;
}
}
private final ContextProvider myProvider = new Provider();
private final XPathSupport mySupport = XPathSupport.getInstance();
@NotNull
public XPath createXPath(String expression) throws JaxenException {
return mySupport.createXPath(null, expression, Collections.<Namespace>emptyList());
}
public void attachContext(@NotNull PsiFile file) {
myProvider.attachTo(file);
}
}
}
@@ -8,10 +8,10 @@
<properties/>
<border type="none"/>
<children>
<grid id="6d2ed" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="6d2ed" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none" title="Advanced"/>
@@ -33,23 +33,6 @@
</grid>
</constraints>
</component>
<component id="aef90" class="javax.swing.JLabel" binding="myXPathConditionLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="a6f2"/>
<text value="&amp;XPath Condition:"/>
<toolTipText value="&lt;html&gt;Enter an XPath expression that the tag/attribute must match additionally to the name-condition specified above.&lt;br&gt;This requires the XPathView plugin to be installed&lt;/html&gt;"/>
</properties>
</component>
<component id="a6f2" class="com.intellij.ui.EditorTextField" binding="myXPathCondition" custom-create="true">
<constraints>
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="7" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
</component>
<component id="ba9f0" class="javax.swing.JCheckBox" binding="mySingleFileCheckBox" default-binding="true">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
@@ -20,9 +20,6 @@ import com.intellij.psi.PsiFile;
import com.intellij.ui.EditorTextField;
import com.intellij.util.Consumer;
import org.intellij.lang.regexp.RegExpLanguage;
import org.intellij.plugins.intelliLang.inject.InjectedLanguage;
import org.intellij.plugins.intelliLang.inject.config.AbstractTagInjection;
import org.intellij.plugins.intelliLang.inject.config.XPathSupportProxy;
import org.intellij.plugins.intelliLang.inject.config.BaseInjection;
import org.intellij.plugins.intelliLang.util.LanguageTextField;
@@ -33,34 +30,21 @@ public class AdvancedPanel extends AbstractInjectionPanel<BaseInjection> {
private JPanel myRoot;
private EditorTextField myValuePattern;
private EditorTextField myXPathCondition;
private JLabel myXPathConditionLabel;
private JCheckBox mySingleFileCheckBox;
public AdvancedPanel(Project project, BaseInjection injection) {
super(injection, project);
$$$setupUI$$$(); // see IDEA-9987
if (!(injection instanceof AbstractTagInjection)) {
myXPathCondition.setVisible(false);
myXPathConditionLabel.setVisible(false);
}
}
protected void apply(BaseInjection other) {
other.setValuePattern(myValuePattern.getText());
other.setSingleFile(mySingleFileCheckBox.isSelected());
if (myOrigInjection instanceof AbstractTagInjection) {
((AbstractTagInjection)other).setXPathCondition(myXPathCondition.getText());
}
}
protected void resetImpl() {
myValuePattern.setText(myOrigInjection.getValuePattern());
mySingleFileCheckBox.setSelected(myOrigInjection.isSingleFile());
if (myOrigInjection instanceof AbstractTagInjection) {
myXPathCondition.setText(((AbstractTagInjection)myOrigInjection).getXPathCondition());
}
}
public JPanel getComponent() {
@@ -73,26 +57,8 @@ public class AdvancedPanel extends AbstractInjectionPanel<BaseInjection> {
psiFile.putCopyableUserData(ValueRegExpAnnotator.KEY, Boolean.TRUE);
}
});
if (myOrigInjection instanceof AbstractTagInjection) {
// don't even bother to look up the language when xpath-evaluation isn't possible
final XPathSupportProxy proxy = XPathSupportProxy.getInstance();
myXPathCondition = new LanguageTextField(proxy != null ? InjectedLanguage.findLanguageById("XPath") : null, myProject,
((AbstractTagInjection)myOrigInjection).getXPathCondition(), new Consumer<PsiFile>() {
public void consume(PsiFile psiFile) {
// important to get proper validation & completion for Jaxen's built-in and PSI functions
// like lower-case(), file-type(), file-ext(), file-name(), etc.
if (proxy != null) {
proxy.attachContext(psiFile);
}
}
});
}
else {
myXPathCondition = new EditorTextField();
}
}
private void $$$setupUI$$$() {
}
}
}
@@ -0,0 +1,59 @@
/*
* Copyright 2000-2010 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 org.intellij.plugins.intelliLang.inject.config;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.PsiFile;
import org.jaxen.JaxenException;
import org.jaxen.XPath;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Proxy class that allows to avoid a hard compile time dependency on the XPathView plugin.
*/
public abstract class XPathSupportProxy {
private static final Logger LOG = Logger.getInstance("org.intellij.plugins.intelliLang.inject.config.XPathSupportProxy");
public static final Object UNSUPPORTED = "UNSUPPORTED";
public static final Object INVALID = "INVALID";
@NotNull
public abstract XPath createXPath(String expression) throws JaxenException;
public abstract void attachContext(@NotNull PsiFile file);
private static XPathSupportProxy ourInstance;
private static boolean isInitialized;
@Nullable
public static synchronized XPathSupportProxy getInstance() {
if (isInitialized) {
return ourInstance;
}
try {
return ourInstance = ServiceManager.getService(XPathSupportProxy.class);
} finally {
if (ourInstance == null) {
LOG.info("XPath Support is not available");
}
isInitialized = true;
}
}
}
@@ -0,0 +1,95 @@
/*
* Copyright 2000-2010 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 org.intellij.plugins.intelliLang.inject.config;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.source.xml.XmlTokenImpl;
import com.intellij.psi.xml.XmlElement;
import com.intellij.psi.xml.XmlElementType;
import org.intellij.lang.xpath.context.ContextProvider;
import org.intellij.lang.xpath.context.ContextType;
import org.intellij.lang.xpath.context.NamespaceContext;
import org.intellij.lang.xpath.context.VariableContext;
import org.intellij.lang.xpath.psi.XPathExpression;
import org.intellij.lang.xpath.psi.XPathType;
import org.intellij.plugins.xpathView.support.XPathSupport;
import org.intellij.plugins.xpathView.util.Namespace;
import org.jaxen.JaxenException;
import org.jaxen.XPath;
import org.jetbrains.annotations.NotNull;
import javax.xml.namespace.QName;
import java.util.Collections;
import java.util.Set;
/**
* @author Gregory.Shrago
*/
public class XPathSupportProxyImpl extends XPathSupportProxy {
private static class Provider extends ContextProvider {
private final XmlTokenImpl myDummyContext = new XmlTokenImpl(XmlElementType.XML_CONTENT_EMPTY, "") {
@Override
public boolean isValid() {
return true;
}
};
@NotNull
public ContextType getContextType() {
return XPathSupport.TYPE;
}
@NotNull
@Override
public XPathType getExpectedType(XPathExpression expr) {
return XPathType.BOOLEAN;
}
public XmlElement getContextElement() {
// needed because the static method ContextProvider.isValid() checks this to determine if the provider
// is still valid - refactor this into an instance method ContextProvider.isValid()?
return myDummyContext;
}
public NamespaceContext getNamespaceContext() {
return null;
}
public VariableContext getVariableContext() {
return null;
}
public Set<QName> getAttributes(boolean forValidation) {
return null;
}
public Set<QName> getElements(boolean forValidation) {
return null;
}
}
private final ContextProvider myProvider = new Provider();
private final XPathSupport mySupport = XPathSupport.getInstance();
@NotNull
public XPath createXPath(String expression) throws JaxenException {
return mySupport.createXPath(null, expression, Collections.<Namespace>emptyList());
}
public void attachContext(@NotNull PsiFile file) {
myProvider.attachTo(file);
}
}
@@ -16,6 +16,7 @@
package org.intellij.plugins.intelliLang.inject.config;
import com.intellij.openapi.util.JDOMExternalizer;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlAttributeValue;
@@ -75,7 +76,7 @@ public class XmlAttributeInjection extends AbstractTagInjection {
@Override
protected List<String> generatePlaces() {
return Collections.singletonList(PatternBasedInjectionHelper.getPatternString(this));
return Collections.singletonList(getPatternString(this));
}
private boolean matches(@NotNull XmlAttribute attr) {
@@ -135,4 +136,17 @@ public class XmlAttributeInjection extends AbstractTagInjection {
result = 31 * result + myAttributeNamespace.hashCode();
return result;
}
public static String getPatternString(final XmlAttributeInjection injection) {
final String name = injection.getAttributeName();
final String namespace = injection.getAttributeNamespace();
final StringBuilder result = new StringBuilder("xmlAttribute()");
if (StringUtil.isNotEmpty(name)) result.append(".withLocalName(string().matches(\"").append(name).append("\"))");
if (StringUtil.isNotEmpty(namespace)) result.append(".withNamespace(string().matches(\"").append(namespace).append("\"))");
if (StringUtil.isNotEmpty(injection.getTagName()) || StringUtil.isNotEmpty(injection.getTagNamespace())) {
result.append(".inside(").append(XmlTagInjection.getPatternString(injection)).append(")");
}
return result.toString();
}
}
@@ -15,6 +15,7 @@
*/
package org.intellij.plugins.intelliLang.inject.config;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.xml.XmlTag;
import org.intellij.plugins.intelliLang.PatternBasedInjectionHelper;
import org.jetbrains.annotations.NotNull;
@@ -50,6 +51,17 @@ public class XmlTagInjection extends AbstractTagInjection {
@Override
protected List<String> generatePlaces() {
return Collections.singletonList(PatternBasedInjectionHelper.getPatternString(this));
return Collections.singletonList(getPatternString(this));
}
public static String getPatternString(final AbstractTagInjection injection) {
final String name = injection.getTagName();
final String namespace = injection.getTagNamespace();
final StringBuilder result = new StringBuilder("xmlTag()");
if (StringUtil.isNotEmpty(name)) result.append(".withLocalName(string().matches(\"").append(name).append("\"))");
if (StringUtil.isNotEmpty(namespace)) result.append(".withNamespace(string().matches(\"").append(namespace).append("\"))");
return result.toString();
}
}
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.intellij.plugins.intelliLang.inject.config.ui.AdvancedXmlPanel">
<grid id="27dc6" binding="myRoot" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="531" height="81"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="6d2ed" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none" title="Advanced"/>
<children>
<component id="843" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="7bf4e"/>
<text value="&amp;Value Pattern:"/>
<toolTipText value="&lt;html&gt;Enter a regular expression that selects the parts of the tag's or attribute's value the language should be injected into.&lt;br&gt;The pattern should contain exactly one capturing group.&lt;/html&gt;"/>
</properties>
</component>
<component id="7bf4e" class="com.intellij.ui.EditorTextField" binding="myValuePattern" custom-create="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
</component>
<component id="aef90" class="javax.swing.JLabel" binding="myXPathConditionLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="a6f2"/>
<text value="&amp;XPath Condition:"/>
<toolTipText value="&lt;html&gt;Enter an XPath expression that the tag/attribute must match additionally to the name-condition specified above.&lt;br&gt;This requires the XPathView plugin to be installed&lt;/html&gt;"/>
</properties>
</component>
<component id="a6f2" class="com.intellij.ui.EditorTextField" binding="myXPathCondition" custom-create="true">
<constraints>
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="7" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
</component>
<component id="ba9f0" class="javax.swing.JCheckBox" binding="mySingleFileCheckBox" default-binding="true">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="&amp;Single File"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>
@@ -0,0 +1,98 @@
/*
* Copyright 2006 Sascha Weinreuter
*
* 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 org.intellij.plugins.intelliLang.inject.config.ui;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import com.intellij.ui.EditorTextField;
import com.intellij.util.Consumer;
import org.intellij.lang.regexp.RegExpLanguage;
import org.intellij.plugins.intelliLang.inject.InjectedLanguage;
import org.intellij.plugins.intelliLang.inject.config.AbstractTagInjection;
import org.intellij.plugins.intelliLang.inject.config.BaseInjection;
import org.intellij.plugins.intelliLang.inject.config.XPathSupportProxy;
import org.intellij.plugins.intelliLang.util.LanguageTextField;
import javax.swing.*;
public class AdvancedXmlPanel extends AbstractInjectionPanel<BaseInjection> {
private JPanel myRoot;
private EditorTextField myValuePattern;
private EditorTextField myXPathCondition;
private JLabel myXPathConditionLabel;
private JCheckBox mySingleFileCheckBox;
public AdvancedXmlPanel(Project project, BaseInjection injection) {
super(injection, project);
$$$setupUI$$$(); // see IDEA-9987
if (!(injection instanceof AbstractTagInjection)) {
myXPathCondition.setVisible(false);
myXPathConditionLabel.setVisible(false);
}
}
protected void apply(BaseInjection other) {
other.setValuePattern(myValuePattern.getText());
other.setSingleFile(mySingleFileCheckBox.isSelected());
if (myOrigInjection instanceof AbstractTagInjection) {
((AbstractTagInjection)other).setXPathCondition(myXPathCondition.getText());
}
}
protected void resetImpl() {
myValuePattern.setText(myOrigInjection.getValuePattern());
mySingleFileCheckBox.setSelected(myOrigInjection.isSingleFile());
if (myOrigInjection instanceof AbstractTagInjection) {
myXPathCondition.setText(((AbstractTagInjection)myOrigInjection).getXPathCondition());
}
}
public JPanel getComponent() {
return myRoot;
}
private void createUIComponents() {
myValuePattern = new LanguageTextField(RegExpLanguage.INSTANCE, myProject, myOrigInjection.getValuePattern(), new Consumer<PsiFile>() {
public void consume(PsiFile psiFile) {
psiFile.putCopyableUserData(ValueRegExpAnnotator.KEY, Boolean.TRUE);
}
});
if (myOrigInjection instanceof AbstractTagInjection) {
// don't even bother to look up the language when xpath-evaluation isn't possible
final XPathSupportProxy proxy = XPathSupportProxy.getInstance();
myXPathCondition = new LanguageTextField(proxy != null ? InjectedLanguage.findLanguageById("XPath") : null, myProject,
((AbstractTagInjection)myOrigInjection).getXPathCondition(), new Consumer<PsiFile>() {
public void consume(PsiFile psiFile) {
// important to get proper validation & completion for Jaxen's built-in and PSI functions
// like lower-case(), file-type(), file-ext(), file-name(), etc.
if (proxy != null) {
proxy.attachContext(psiFile);
}
}
});
}
else {
myXPathCondition = new EditorTextField();
}
}
private void $$$setupUI$$$() {
}
}
@@ -69,7 +69,7 @@
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</nested-form>
<nested-form id="b6e0b" form-file="org/intellij/plugins/intelliLang/inject/config/ui/AdvancedPanel.form" binding="myAdvancedPanel" custom-create="true">
<nested-form id="b6e0b" form-file="org/intellij/plugins/intelliLang/inject/config/ui/AdvancedXmlPanel.form" binding="myAdvancedPanel" custom-create="true">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
@@ -31,7 +31,7 @@ public class XmlAttributePanel extends AbstractInjectionPanel<XmlAttributeInject
// read by reflection
LanguagePanel myLanguagePanel;
TagPanel myTagPanel;
AdvancedPanel myAdvancedPanel;
AdvancedXmlPanel myAdvancedPanel;
private EditorTextField myLocalName;
private ComboBox myNamespace;
@@ -70,7 +70,7 @@ public class XmlAttributePanel extends AbstractInjectionPanel<XmlAttributeInject
private void createUIComponents() {
myLanguagePanel = new LanguagePanel(myProject, myOrigInjection);
myTagPanel = new TagPanel(myProject, myOrigInjection);
myAdvancedPanel = new AdvancedPanel(myProject, myOrigInjection);
myAdvancedPanel = new AdvancedXmlPanel(myProject, myOrigInjection);
myLocalName = new LanguageTextField(RegExpLanguage.INSTANCE, myProject, myOrigInjection.getAttributeName());
@@ -23,7 +23,7 @@
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</nested-form>
<nested-form id="fa14a" form-file="org/intellij/plugins/intelliLang/inject/config/ui/AdvancedPanel.form" binding="myAdvancedPanel" custom-create="true">
<nested-form id="fa14a" form-file="org/intellij/plugins/intelliLang/inject/config/ui/AdvancedXmlPanel.form" binding="myAdvancedPanel" custom-create="true">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
@@ -25,7 +25,7 @@ public class XmlTagPanel extends AbstractInjectionPanel<XmlTagInjection> {
// read by reflection
LanguagePanel myLanguagePanel;
TagPanel myPanel;
AdvancedPanel myAdvancedPanel;
AdvancedXmlPanel myAdvancedPanel;
private JPanel myRoot;
@@ -51,7 +51,7 @@ public class XmlTagPanel extends AbstractInjectionPanel<XmlTagInjection> {
private void createUIComponents() {
myLanguagePanel = new LanguagePanel(myProject, myOrigInjection);
myPanel = new TagPanel(myProject, myOrigInjection);
myAdvancedPanel = new AdvancedPanel(myProject, myOrigInjection);
myAdvancedPanel = new AdvancedXmlPanel(myProject, myOrigInjection);
}
private void $$$setupUI$$$() {
@@ -38,4 +38,4 @@ public class XmlAttributeInjectionConfigurable extends InjectionConfigurable<Xml
public Icon getIcon() {
return Icons.ANNOTATION_TYPE_ICON;
}
}
}
@@ -38,4 +38,4 @@ public class XmlTagInjectionConfigurable extends InjectionConfigurable<XmlTagInj
public Icon getIcon() {
return Icons.XML_TAG_ICON;
}
}
}
+1
View File
@@ -32,6 +32,7 @@
</orderEntry>
<orderEntry type="module" module-name="java-impl" />
<orderEntry type="module" module-name="copyright" />
<orderEntry type="module" module-name="IntelliLangJava" />
</component>
</module>
@@ -7,4 +7,4 @@
config="/resources/groovyInjections.xml"/>
</extensions>
</idea-plugin>
</idea-plugin>
+1
View File
@@ -24,6 +24,7 @@
<depends>com.intellij.properties</depends>
<depends optional="true" config-file="groovy-copyright.xml">com.intellij.copyright</depends>
<depends optional="true" config-file="intellilang-groovy-support.xml">org.intellij.intelliLang</depends>
<extensionPoints>
<extensionPoint name="libraryManager" interface="org.jetbrains.plugins.groovy.config.AbstractGroovyLibraryManager"/>
@@ -0,0 +1,37 @@
/*
* Copyright 2000-2010 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.lang.xml;
import com.intellij.lang.LiteralEscaper;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
/**
* @author Gregory.Shrago
*/
public class XmlLiteralEscaper implements LiteralEscaper {
public String getEscapedText(PsiElement context, String originalText) {
return escapeText(originalText);
}
public String escapeText(String originalText) {
return StringUtil.escapeXml(originalText);
}
public String unescapeText(String originalText) {
return StringUtil.unescapeXml(originalText);
}
}