Merge branch 'master' of git@git.labs.intellij.net:idea/community

This commit is contained in:
Kirill Kalishev
2010-04-06 13:25:56 +04:00
139 changed files with 1836 additions and 775 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")
@@ -1591,7 +1591,6 @@ public class CompileDriver {
}
private static boolean syncOutputDir(final CompileContextEx context, final Collection<Trinity<File, String, Boolean>> toDelete) throws CacheCorruptedException {
final int total = toDelete.size();
final DependencyCache dependencyCache = context.getDependencyCache();
final boolean isTestMode = ApplicationManager.getApplication().isUnitTestMode();
@@ -1601,11 +1600,9 @@ public class CompileDriver {
public void run() throws CacheCorruptedException {
final long start = System.currentTimeMillis();
try {
int current = 0;
for (final Trinity<File, String, Boolean> trinity : toDelete) {
final File outputPath = trinity.getFirst();
context.getProgressIndicator().checkCanceled();
context.getProgressIndicator().setFraction((double)++current / total);
context.getProgressIndicator().setText2(outputPath.getPath());
filesToRefresh.add(outputPath);
if (isTestMode) {
@@ -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);
}
}
@@ -26,7 +26,7 @@ import org.jetbrains.annotations.NonNls;
* A testcase that provides IDEA application and project. Note both are reused for each test run in the session so
* be careful to return all the modification made to application and project components (such as settings) after
* test is finished so other test aren't affected. The project is initialized with single module that have single
* content&amp;source entry. For your convinience the project may be equipped with some mock JDK so your tests may
* content&amp;source entry. For your convenience the project may be equipped with some mock JDK so your tests may
* refer to external classes. In order to enable this feature you have to have a folder named "mockJDK" under
* idea installation home that is used for test running. Place src.zip under that folder. We'd suggest this is real mock
* so it contains classes that is really needed in order to speed up tests startup.
@@ -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);
}
@@ -63,7 +63,7 @@ public class RunConfigurationAction extends ComboBoxAction implements DumbAware
}
try {
if (project == null || project.isDisposed()) {
if (project == null || project.isDisposed() || !project.isInitialized()) {
//if (ProjectManager.getInstance().getOpenProjects().length > 0) {
// // do nothing if frame is not active
// return;
@@ -36,6 +36,7 @@ import com.intellij.openapi.ui.popup.*;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.ui.awt.RelativeRectangle;
import com.intellij.util.ui.UIUtil;
@@ -717,37 +718,41 @@ public class ActionToolbarImpl extends JPanel implements ActionToolbar {
public void updateActionsImmediately() {
ApplicationManager.getApplication().assertIsDispatchThread();
myNewVisibleActions.clear();
final DataContext dataContext = getDataContext();
IdeFocusManager.getInstance(null).doWhenFocusSettlesDown(new Runnable() {
public void run() {
myNewVisibleActions.clear();
final DataContext dataContext = getDataContext();
Utils.expandActionGroup(myActionGroup, myNewVisibleActions, myPresentationFactory, dataContext, myPlace, myActionManager);
Utils.expandActionGroup(myActionGroup, myNewVisibleActions, myPresentationFactory, dataContext, myPlace, myActionManager);
if (!myNewVisibleActions.equals(myVisibleActions)) {
// should rebuild UI
if (!myNewVisibleActions.equals(myVisibleActions)) {
// should rebuild UI
final boolean changeBarVisibility = myNewVisibleActions.isEmpty() || myVisibleActions.isEmpty();
final boolean changeBarVisibility = myNewVisibleActions.isEmpty() || myVisibleActions.isEmpty();
final ArrayList<AnAction> temp = myVisibleActions;
myVisibleActions = myNewVisibleActions;
myNewVisibleActions = temp;
final ArrayList<AnAction> temp = myVisibleActions;
myVisibleActions = myNewVisibleActions;
myNewVisibleActions = temp;
removeAll();
mySecondaryActions.removeAll();
mySecondaryActionsButton = null;
fillToolBar(myVisibleActions, getLayoutPolicy() == AUTO_LAYOUT_POLICY && myOrientation == SwingConstants.HORIZONTAL);
removeAll();
mySecondaryActions.removeAll();
mySecondaryActionsButton = null;
fillToolBar(myVisibleActions, getLayoutPolicy() == AUTO_LAYOUT_POLICY && myOrientation == SwingConstants.HORIZONTAL);
if (changeBarVisibility) {
revalidate();
}
else {
final Container parent = getParent();
if (parent != null) {
parent.invalidate();
parent.validate();
if (changeBarVisibility) {
revalidate();
}
else {
final Container parent = getParent();
if (parent != null) {
parent.invalidate();
parent.validate();
}
}
repaint();
}
}
repaint();
}
});
}
public void setTargetComponent(final JComponent component) {
@@ -0,0 +1,69 @@
/*
* 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.util.ui;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ui.AbstractTableCellEditor;
import com.intellij.util.ui.CellEditorComponentWithBrowseButton;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class LocalPathCellEditor extends AbstractTableCellEditor {
private final String myTitle;
private CellEditorComponentWithBrowseButton<JTextField> myComponent;
public LocalPathCellEditor(String title) {
myTitle = title;
}
public Object getCellEditorValue() {
return myComponent.getChildComponent().getText();
}
public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, final int row, int column) {
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
FileChooserDescriptor d = new FileChooserDescriptor(false, true, false, true, false, false);
if (myTitle != null) {
d.setTitle(myTitle);
}
d.setShowFileSystemRoots(true);
VirtualFile initialFile = LocalFileSystem.getInstance().findFileByPath((String)getCellEditorValue());
VirtualFile[] files = FileChooser.chooseFiles(table, d, initialFile);
if (files.length == 1 && files[0] != null) {
String path = files[0].getPresentableUrl();
if (SystemInfo.isWindows && path.length() == 2 && Character.isLetter(path.charAt(0)) && path.charAt(1) == ':') {
path += "\\"; // make path absolute
}
myComponent.getChildComponent().setText(path);
}
}
};
myComponent = new CellEditorComponentWithBrowseButton<JTextField>(new TextFieldWithBrowseButton(listener), this);
myComponent.getChildComponent().setText((String)value);
return myComponent;
}
}
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.util.ui.ValidatingTableEditor">
<grid id="27dc6" binding="myContentPane" layout-manager="GridLayoutManager" row-count="3" 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>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane id="11f79">
<constraints>
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="37d9d" class="com.intellij.ui.table.TableView" binding="myTable" custom-create="true">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
<component id="38e47" class="javax.swing.JButton" binding="myAddButton" default-binding="true">
<constraints>
<grid row="1" column="0" 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="A&amp;dd"/>
</properties>
</component>
<component id="79576" class="javax.swing.JButton" binding="myRemoveButton" default-binding="true">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="&amp;Remove"/>
</properties>
</component>
<hspacer id="ef5dc">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<grid id="a830f" 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="2" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="b1d0" class="javax.swing.JLabel" binding="myMessageLabel">
<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>
<text value="Label"/>
</properties>
</component>
<hspacer id="a0645">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="4d864" class="com.intellij.ui.HoverHyperlinkLabel" binding="myFixLink" custom-create="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Fix"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>
@@ -0,0 +1,358 @@
/*
* 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.util.ui;
import com.intellij.openapi.util.NullableComputable;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.ui.HoverHyperlinkLabel;
import com.intellij.ui.table.TableView;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public abstract class ValidatingTableEditor<Item> {
private static final Icon WARNING_ICON = UIUtil.getBalloonWarningIcon();
private static final Icon EMPTY_ICON = new EmptyIcon(WARNING_ICON);
private static final String REMOVE_KEY = "REMOVE_SELECTED";
public interface RowHeightProvider {
int getRowHeight();
}
public interface Fix extends Runnable {
String getTitle();
}
private class ColumnInfoWrapper extends ColumnInfo<Item, String> {
private final ColumnInfo<Item, String> myDelegate;
public ColumnInfoWrapper(ColumnInfo<Item, String> delegate) {
super(delegate.getName());
myDelegate = delegate;
}
@Override
public String valueOf(Item item) {
return myDelegate.valueOf(item);
}
@Override
public boolean isCellEditable(Item item) {
return myDelegate.isCellEditable(item);
}
@Override
public void setValue(Item item, String value) {
myDelegate.setValue(item, value);
updateMessage(-1, null);
}
@Override
public TableCellEditor getEditor(Item item) {
return myDelegate.getEditor(item);
}
}
private JPanel myContentPane;
private TableView<Item> myTable;
private JButton myAddButton;
private JButton myRemoveButton;
private JLabel myMessageLabel;
private HoverHyperlinkLabel myFixLink;
private final List<String> myWarnings = new ArrayList<String>();
private Fix myFixRunnable;
protected abstract Item cloneOf(Item item);
@Nullable
protected Pair<String, Fix> validate(List<Item> current, List<String> warnings) {
String error = null;
for (int i = 0; i < current.size(); i++) {
Item item = current.get(i);
String s = validate(item);
warnings.set(i, s);
if (error == null) {
error = s;
}
}
return error != null ? Pair.create(error, (Fix)null) : null;
}
@Nullable
protected String validate(Item item) {
return null;
}
protected abstract Item createItem();
private class IconColumn extends ColumnInfo<Item, Object> implements RowHeightProvider {
public IconColumn() {
super(" ");
}
public String valueOf(Item item) {
return null;
}
@Override
public int getWidth(JTable table) {
return WARNING_ICON.getIconWidth() + 2;
}
public int getRowHeight() {
return WARNING_ICON.getIconHeight();
}
@Override
public TableCellRenderer getRenderer(final Item item) {
return new WarningIconCellRenderer(new NullableComputable<String>() {
public String compute() {
return myWarnings.get(doGetItems().indexOf(item));
}
});
}
}
private void createUIComponents() {
myTable = new ChangesTrackingTableView<Item>() {
protected void onTextChanged(int row, int column, String value) {
final Item original = getItems().get(row);
Item override = cloneOf(original);
final ColumnInfo<Item, String> columnInfo = getTableModel().getColumnInfos()[column];
columnInfo.setValue(override, value);
updateMessage(row, override);
}
@Override
protected void onEditingStopped() {
updateMessage(-1, null);
}
};
myFixLink = new HoverHyperlinkLabel(null);
}
protected ValidatingTableEditor() {
myTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
updateButtons();
}
});
myTable.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), REMOVE_KEY);
myTable.getActionMap().put(REMOVE_KEY, new AbstractAction() {
public void actionPerformed(final ActionEvent e) {
removeSelected();
}
});
myFixLink.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED && myFixRunnable != null) {
myFixRunnable.run();
}
}
});
myAddButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
addItem();
}
});
myRemoveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
removeSelected();
}
});
}
private void removeSelected() {
myTable.stopEditing();
List<Item> items = new ArrayList<Item>(doGetItems());
final int[] rows = myTable.getSelectedRows();
for (int i = rows.length - 1; i >= 0; i--) {
items.remove(rows[i]);
}
setItems(items);
updateMessage(-1, null);
if (!items.isEmpty()) {
int index = Math.min(rows[0], items.size() - 1);
myTable.getSelectionModel().addSelectionInterval(index, index);
}
}
protected void addItem() {
List<Item> items = new ArrayList<Item>(doGetItems());
items.add(createItem());
setItems(items);
final int row = items.size() - 1;
myTable.getSelectionModel().setSelectionInterval(row, row);
myTable.scrollRectToVisible(myTable.getCellRect(row, 0, true));
if (getTableModel().getColumnInfos()[1].isCellEditable(items.get(row))) {
myTable.editCellAt(row, 1);
IdeFocusManager.findInstanceByComponent(myContentPane).requestFocus(myTable.getEditorComponent(), true);
}
updateMessage(-1, null);
}
private ListTableModel<Item> getTableModel() {
return (ListTableModel<Item>)myTable.getModel();
}
public void setModel(ColumnInfo<Item, String>[] valueColumns, List<Item> items) {
ColumnInfo[] columns = new ColumnInfo[valueColumns.length + 1];
IconColumn iconColumn = new IconColumn();
int maxHeight = iconColumn.getRowHeight();
columns[0] = iconColumn;
for (int i = 0; i < valueColumns.length; i++) {
columns[i + 1] = new ColumnInfoWrapper(valueColumns[i]);
if (valueColumns[i] instanceof RowHeightProvider) {
maxHeight = Math.max(maxHeight, ((RowHeightProvider)valueColumns[i]).getRowHeight());
}
}
myTable.stopEditing();
myTable.setModel(new ListTableModel<Item>(columns));
if (maxHeight > 0) {
myTable.setRowHeight(maxHeight);
}
setItems(items);
updateMessage(-1, null);
}
public List<Item> getItems() {
return Collections.unmodifiableList(doGetItems());
}
private List<Item> doGetItems() {
List<Item> items = new ArrayList<Item>(getTableModel().getItems());
if (myTable.isEditing()) {
Component c = myTable.getEditorComponent();
final JTextField textField;
if (c instanceof CellEditorComponentWithBrowseButton) {
textField = (JTextField)((CellEditorComponentWithBrowseButton)c).getChildComponent();
}
else {
textField = (JTextField)c;
}
String value = textField.getText();
ColumnInfo column = ((ListTableModel)myTable.getModel()).getColumnInfos()[myTable.getEditingColumn()];
((ColumnInfoWrapper)column).myDelegate.setValue(items.get(myTable.getEditingRow()), value);
}
return items;
}
private void setItems(List<Item> items) {
if (items.isEmpty()) {
getTableModel().setItems(Collections.<Item>emptyList());
myWarnings.clear();
}
else {
getTableModel().setItems(new ArrayList<Item>(items));
for (Item item : items) {
myWarnings.add(null);
}
}
updateButtons();
}
public void setTableHeader(JTableHeader header) {
myTable.setTableHeader(header);
}
private void updateButtons() {
myRemoveButton.setEnabled(myTable.getSelectedRow() != -1);
}
public void updateMessage(int index, @Nullable Item override) {
List<Item> current = new ArrayList<Item>(doGetItems());
if (override != null) {
current.set(index, override);
}
Pair<String, Fix> messageAndFix = validate(current, myWarnings);
if (messageAndFix != null) {
myMessageLabel.setText(messageAndFix.first);
myMessageLabel.setIcon(WARNING_ICON);
myMessageLabel.setVisible(true);
myFixRunnable = messageAndFix.second;
myFixLink.setVisible(myFixRunnable != null);
myFixLink.setText(myFixRunnable != null ? myFixRunnable.getTitle() : null);
}
else {
myMessageLabel.setText(" ");
myMessageLabel.setIcon(EMPTY_ICON);
myFixLink.setVisible(false);
myFixRunnable = null;
}
myTable.repaint();
}
public JComponent getPreferredFocusedComponent() {
return myTable;
}
private static class WarningIconCellRenderer extends DefaultTableCellRenderer {
private final NullableComputable<String> myWarningProvider;
public WarningIconCellRenderer(NullableComputable<String> warningProvider) {
myWarningProvider = warningProvider;
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
JLabel label = (JLabel)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
String message = myWarningProvider.compute();
label.setIcon(message != null ? WARNING_ICON : null);
label.setToolTipText(message);
label.setHorizontalAlignment(CENTER);
label.setVerticalAlignment(CENTER);
return label;
}
}
public Component getContentPane() {
return myContentPane;
}
}
@@ -289,7 +289,13 @@ title.unable.to.save.data=Unable to Save Data
link.click.here.to.license.server.info=More info
link.purchase.commercial.license=To purchase a commercial license, please visit
license.panel.current.license.description=The license will expire on {0,date,MMMM dd, yyyy}
license.panel.buildit.evaluation.expires.in=Remains {0} day(s)
license.panel.current.permanent.ticket.description=Permanent ticket obtained
license.panel.current.floating.ticket.description=Floating ticket obtained
license.panel.buildit.evaluation.expires.in.one=1 day left
license.panel.buildit.evaluation.expires.in.many={0} days left
license.panel.ping.license.server.error.message=No response from autodetected license server
license.panel.ping.license.server.error.title=No response from server
license.panel.default.server.discover=Discover
editbox.license.user.name=User name:
editbox.license.license.key=License key:
radio.license.server.address=Enter license &server address
@@ -1051,3 +1057,4 @@ FileChooser.listViewActionLabelText=List
FileChooser.detailsViewActionLabelText=Details
FileChooser.refreshActionLabelText=Refresh
browsers.settings=Web Browsers
@@ -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"/>
@@ -1761,5 +1761,7 @@ remove.try.finally.block.quickfix=Remove try-finally block
remove.finally.block.quickfix=Remove finally block
remove.leading.zero.to.make.decimal.quickfix=Remove leading zero to make decimal
convert.octal.literal.to.decimal.literal.quickfix=Convert octal literal to decimal literal
ignore.single.field.static.imports=Ignore single &field static imports
ignore.single.method.static.imports=Ignore single &method static imports
ignore.single.field.static.imports.option=Ignore single &field static imports
ignore.single.method.static.imports.option=Ignore single &method static imports
ignore.methods.with.boolean.return.type.option=Ignore methods with &Boolean return type
ignore.boolean.methods.in.an.interface.option=Ignore boolean methods in an @&interface
@@ -60,10 +60,10 @@ public class StaticImportInspection extends BaseInspection {
final MultipleCheckboxOptionsPanel panel =
new MultipleCheckboxOptionsPanel(this);
panel.addCheckbox(InspectionGadgetsBundle.message(
"ignore.single.field.static.imports"),
"ignore.single.field.static.imports.option"),
"ignoreSingleFieldImports");
panel.addCheckbox(InspectionGadgetsBundle.message(
"ignore.single.method.static.imports"),
"ignore.single.method.static.imports.option"),
"ignoreSingeMethodImports");
return panel;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,34 +15,36 @@
*/
package com.siyeh.ig.j2me;
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
import com.intellij.psi.*;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.performance.VariableAccessVisitor;
import com.siyeh.ig.psiutils.ExpressionUtils;
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.JComponent;
import java.util.Set;
public class FieldRepeatedlyAccessedInspection extends BaseInspection {
/** @noinspection PublicField*/
public boolean m_ignoreFinalFields = false;
@Override
@NotNull
public String getID(){
return "FieldRepeatedlyAccessedInMethod";
}
@Override
@NotNull
public String getDisplayName() {
return InspectionGadgetsBundle.message(
"field.repeatedly.accessed.in.method.display.name");
}
@Override
@NotNull
public String buildErrorString(Object... arg) {
final String fieldName = ((PsiNamedElement) arg[0]).getName();
@@ -51,12 +53,14 @@ public class FieldRepeatedlyAccessedInspection extends BaseInspection {
fieldName);
}
@Override
public JComponent createOptionsPanel() {
return new SingleCheckboxOptionsPanel(InspectionGadgetsBundle.message(
"field.repeatedly.accessed.in.method.ignore.option"),
this, "m_ignoreFinalFields");
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new FieldRepeatedlyAccessedVisitor();
}
@@ -72,8 +76,11 @@ public class FieldRepeatedlyAccessedInspection extends BaseInspection {
method.accept(visitor);
final Set<PsiField> fields = visitor.getOveraccessedFields();
for(PsiField field : fields){
if(ExpressionUtils.isConstant(field) || m_ignoreFinalFields &&
field.hasModifierProperty(PsiModifier.FINAL)){
if(ExpressionUtils.isConstant(field)){
continue;
}
if(m_ignoreFinalFields &&
field.hasModifierProperty(PsiModifier.FINAL)){
continue;
}
registerError(nameIdentifier, field);
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2005 Dave Griffith
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.siyeh.ig.performance;
package com.siyeh.ig.j2me;
import com.intellij.psi.*;
import com.siyeh.ig.psiutils.ControlFlowUtils;
@@ -21,17 +21,17 @@ import org.jetbrains.annotations.NotNull;
import java.util.*;
public class VariableAccessVisitor extends JavaRecursiveElementVisitor {
class VariableAccessVisitor extends JavaRecursiveElementVisitor {
private final Map<PsiField,Integer> m_accessCounts =
new HashMap<PsiField, Integer>(2);
private final Set<PsiField> m_overAccessedFields =
new HashSet<PsiField>(2);
@Override public void visitReferenceExpression(@NotNull PsiReferenceExpression ref) {
@Override public void visitReferenceExpression(
@NotNull PsiReferenceExpression ref) {
super.visitReferenceExpression(ref);
final PsiExpression qualifier = ref.getQualifierExpression();
if (qualifier != null && !(qualifier instanceof PsiThisExpression)) {
return;
}
@@ -51,7 +51,7 @@ public class VariableAccessVisitor extends JavaRecursiveElementVisitor {
final Integer count = accessCounts.get(field);
if (count == null) {
accessCounts.put(field, 1);
} else if (count == 1) {
} else if (count.intValue() == 1) {
accessCounts.put(field, 2);
} else {
overAccessedFields.add(field);
@@ -1,49 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.siyeh.ig.naming.BooleanMethodNameMustStartWithQuestionInspection.Form">
<grid id="88823" binding="contentPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="4" vgap="4">
<margin top="4" left="4" bottom="4" right="4"/>
<constraints>
<xy x="92" y="33" width="295" height="162"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane id="14807">
<constraints>
<grid row="0" column="0" row-span="3" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="2273d" class="com.siyeh.ig.ui.IGTable" binding="table" custom-create="true">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
<component id="52926" class="javax.swing.JButton" binding="addButton">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<margin top="3" left="8" bottom="3" right="8"/>
<text resource-bundle="com/siyeh/InspectionGadgetsBundle" key="button.add"/>
</properties>
</component>
<component id="f6174" class="javax.swing.JButton" binding="removeButton">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<margin top="3" left="8" bottom="3" right="8"/>
<text resource-bundle="com/siyeh/InspectionGadgetsBundle" key="button.remove"/>
</properties>
</component>
<vspacer id="6a13b">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
</form>
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@ package com.siyeh.ig.naming;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiType;
import com.siyeh.InspectionGadgetsBundle;
@@ -25,21 +26,29 @@ import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.fixes.RenameFix;
import com.siyeh.ig.psiutils.LibraryUtil;
import com.siyeh.ig.ui.AddAction;
import com.siyeh.ig.ui.IGTable;
import com.siyeh.ig.ui.ListWrappingTableModel;
import com.siyeh.ig.ui.RemoveAction;
import com.siyeh.ig.ui.*;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.ArrayList;
import java.util.List;
public class BooleanMethodNameMustStartWithQuestionInspection
extends BaseInspection{
@SuppressWarnings({"PublicField"})
public boolean ignoreBooleanMethods = false;
@SuppressWarnings({"PublicField"})
public boolean ignoreInAnnotationInterface = true;
/** @noinspection PublicField*/
@NonNls public String questionString =
"is,can,has,should,could,will,shall,check,contains,equals,add," +
@@ -51,41 +60,97 @@ public class BooleanMethodNameMustStartWithQuestionInspection
parseString(questionString, questionList);
}
@Override
@NotNull
public String getDisplayName(){
return InspectionGadgetsBundle.message(
"boolean.method.name.must.start.with.question.display.name");
}
@Override
@NotNull
public String buildErrorString(Object... infos){
return InspectionGadgetsBundle.message(
"boolean.method.name.must.start.with.question.problem.descriptor");
}
@Override
public void readSettings(Element element) throws InvalidDataException{
super.readSettings(element);
parseString(questionString, questionList);
}
@Override
public void writeSettings(Element element) throws WriteExternalException{
questionString = formatString(questionList);
super.writeSettings(element);
}
@Override
public JComponent createOptionsPanel(){
final Form form = new Form();
return form.getContentPanel();
final JPanel panel = new JPanel(new GridBagLayout());
final IGTable table =
new IGTable(new ListWrappingTableModel(questionList,
InspectionGadgetsBundle.message(
"boolean.method.name.must.start.with.question.table.column.name")));
final JScrollPane scrollPane = new JScrollPane(table);
final GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridheight = 3;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
constraints.fill = GridBagConstraints.BOTH;
panel.add(scrollPane, constraints);
final JButton addButton = new JButton(new AddAction(table));
constraints.gridx = 1;
constraints.gridheight = 1;
constraints.weightx = 0.0;
constraints.weighty = 0.0;
constraints.fill = GridBagConstraints.HORIZONTAL;
panel.add(addButton, constraints);
final JButton removeButton = new JButton(new RemoveAction(table));
constraints.gridy = 1;
panel.add(removeButton, constraints);
final BlankFiller filler = new BlankFiller();
constraints.gridy = 2;
constraints.weighty = 1.0;
panel.add(filler, constraints);
final CheckBox checkBox1 =
new CheckBox(InspectionGadgetsBundle.message(
"ignore.methods.with.boolean.return.type.option"),
this, "ignoreBooleanMethods");
constraints.gridy = 3;
constraints.gridx = 0;
constraints.gridwidth = 2;
constraints.weighty = 0.0;
panel.add(checkBox1, constraints);
final CheckBox checkBox2 =
new CheckBox(InspectionGadgetsBundle.message(
"ignore.boolean.methods.in.an.interface.option"),
this, "ignoreInAnnotationInterface");
constraints.gridy = 4;
panel.add(checkBox2, constraints);
return panel;
}
@Override
protected InspectionGadgetsFix buildFix(Object... infos){
return new RenameFix();
}
@Override
protected boolean buildQuickFixesOnlyForOnTheFlyErrors(){
return true;
}
@Override
public BaseInspectionVisitor buildVisitor(){
return new BooleanMethodNameMustStartWithQuestionVisitor();
}
@@ -95,8 +160,20 @@ public class BooleanMethodNameMustStartWithQuestionInspection
@Override public void visitMethod(@NotNull PsiMethod method){
final PsiType returnType = method.getReturnType();
if(returnType == null || !returnType.equals(PsiType.BOOLEAN)){
if(returnType == null){
return;
} else if(!returnType.equals(PsiType.BOOLEAN)){
if (ignoreBooleanMethods ||
!returnType.equalsToText("java.lang.Boolean")) {
return;
}
}
if (ignoreInAnnotationInterface) {
final PsiClass containingClass = method.getContainingClass();
if (containingClass != null &&
containingClass.isAnnotationType()) {
return;
}
}
final String name = method.getName();
for(String question : questionList){
@@ -110,28 +187,4 @@ public class BooleanMethodNameMustStartWithQuestionInspection
registerMethodError(method);
}
}
private class Form{
JPanel contentPanel;
JButton addButton;
JButton removeButton;
IGTable table;
Form(){
super();
addButton.setAction(new AddAction(table));
removeButton.setAction(new RemoveAction(table));
}
private void createUIComponents(){
table = new IGTable(new ListWrappingTableModel(questionList,
InspectionGadgetsBundle.message(
"boolean.method.name.must.start.with.question.table.column.name")));
}
public JComponent getContentPanel(){
return contentPanel;
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,15 +25,17 @@ import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.fixes.RenameFix;
import com.siyeh.ig.psiutils.LibraryUtil;
import com.siyeh.ig.ui.AddAction;
import com.siyeh.ig.ui.IGTable;
import com.siyeh.ig.ui.ListWrappingTableModel;
import com.siyeh.ig.ui.RemoveAction;
import com.siyeh.ig.ui.*;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.ArrayList;
import java.util.List;
@@ -45,47 +47,99 @@ public class NonBooleanMethodNameMayNotStartWithQuestionInspection
"is,can,has,should,could,will,shall,check,contains,equals," +
"startsWith,endsWith";
@SuppressWarnings({"PublicField"})
public boolean ignoreBooleanMethods = false;
List<String> questionList = new ArrayList(32);
public NonBooleanMethodNameMayNotStartWithQuestionInspection(){
parseString(questionString, questionList);
}
@Override
@NotNull
public String getDisplayName(){
return InspectionGadgetsBundle.message(
"non.boolean.method.name.must.not.start.with.question.display.name");
}
@Override
@NotNull
public String buildErrorString(Object... infos){
return InspectionGadgetsBundle.message(
"non.boolean.method.name.must.not.start.with.question.problem.descriptor");
}
@Override
public void readSettings(Element element) throws InvalidDataException{
super.readSettings(element);
parseString(questionString, questionList);
}
@Override
public void writeSettings(Element element) throws WriteExternalException{
questionString = formatString(questionList);
super.writeSettings(element);
}
@Override
public JComponent createOptionsPanel(){
final Form form = new Form();
return form.getContentPanel();
final JPanel panel = new JPanel(new GridBagLayout());
final IGTable table =
new IGTable(new ListWrappingTableModel(questionList,
InspectionGadgetsBundle.message(
"boolean.method.name.must.start.with.question.table.column.name")));
final JScrollPane scrollPane = new JScrollPane(table);
final GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridheight = 3;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
constraints.fill = GridBagConstraints.BOTH;
panel.add(scrollPane, constraints);
final JButton addButton = new JButton(new AddAction(table));
constraints.gridx = 1;
constraints.gridheight = 1;
constraints.weightx = 0.0;
constraints.weighty = 0.0;
constraints.fill = GridBagConstraints.HORIZONTAL;
panel.add(addButton, constraints);
final JButton removeButton = new JButton(new RemoveAction(table));
constraints.gridy = 1;
panel.add(removeButton, constraints);
final BlankFiller filler = new BlankFiller();
constraints.gridy = 2;
constraints.weighty = 1.0;
panel.add(filler, constraints);
final CheckBox checkBox =
new CheckBox(InspectionGadgetsBundle.message(
"ignore.methods.with.boolean.return.type.option"),
this, "ignoreBooleanMethods");
constraints.gridy = 3;
constraints.gridx = 0;
constraints.gridwidth = 2;
constraints.weighty = 0.0;
panel.add(checkBox, constraints);
return panel;
}
@Override
protected InspectionGadgetsFix buildFix(Object... infos){
return new RenameFix();
}
@Override
protected boolean buildQuickFixesOnlyForOnTheFlyErrors(){
return true;
}
@Override
public BaseInspectionVisitor buildVisitor(){
return new NonBooleanMethodNameMayNotStartWithQuestionVisitor();
}
@@ -99,6 +153,10 @@ public class NonBooleanMethodNameMayNotStartWithQuestionInspection
if(returnType == null || returnType.equals(PsiType.BOOLEAN)){
return;
}
if(ignoreBooleanMethods && returnType.equalsToText(
"java.lang.Boolean")){
return;
}
final String name = method.getName();
boolean startsWithQuestionWord = false;
for(String question : questionList){
@@ -121,28 +179,4 @@ public class NonBooleanMethodNameMayNotStartWithQuestionInspection
registerMethodError(method);
}
}
private class Form{
JPanel contentPanel;
JButton addButton;
JButton removeButton;
IGTable table;
Form(){
super();
addButton.setAction(new AddAction(table));
removeButton.setAction(new RemoveAction(table));
}
private void createUIComponents(){
table = new IGTable(new ListWrappingTableModel(questionList,
InspectionGadgetsBundle.message(
"boolean.method.name.must.start.with.question.table.column.name")));
}
public JComponent getContentPanel(){
return contentPanel;
}
}
}
@@ -1,48 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.siyeh.ig.naming.NonBooleanMethodNameMayNotStartWithQuestionInspection.Form">
<grid id="c36c6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="4" vgap="4">
<margin top="4" left="4" bottom="4" right="4"/>
<constraints>
<xy x="94" y="35" width="298" height="158"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane id="14807">
<constraints>
<grid row="0" column="0" row-span="3" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="d8a2f" class="com.siyeh.ig.ui.IGTable" binding="table" custom-create="true">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
<component id="52926" class="javax.swing.JButton" binding="addButton">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="com/siyeh/InspectionGadgetsBundle" key="button.add"/>
</properties>
</component>
<component id="f6174" class="javax.swing.JButton" binding="removeButton">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<margin top="3" left="8" bottom="3" right="8"/>
<text resource-bundle="com/siyeh/InspectionGadgetsBundle" key="button.remove"/>
</properties>
</component>
<vspacer id="5ac98">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
</form>
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2005 Dave Griffith
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
*
* 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,8 @@ package com.siyeh.ig.psiutils;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
public class ArrayContentsAccessedVisitor extends JavaRecursiveElementVisitor{
class ArrayContentsAccessedVisitor extends JavaRecursiveElementVisitor{
private boolean accessed = false;
private final PsiVariable variable;
@@ -27,7 +28,8 @@ public class ArrayContentsAccessedVisitor extends JavaRecursiveElementVisitor{
this.variable = variable;
}
@Override public void visitForeachStatement(@NotNull PsiForeachStatement statement){
@Override public void visitForeachStatement(
@NotNull PsiForeachStatement statement){
if(accessed){
return;
}
@@ -36,7 +38,9 @@ public class ArrayContentsAccessedVisitor extends JavaRecursiveElementVisitor{
if(!(qualifier instanceof PsiReferenceExpression)){
return;
}
final PsiElement referent = ((PsiReference) qualifier).resolve();
final PsiReferenceExpression referenceExpression =
(PsiReferenceExpression)qualifier;
final PsiElement referent = referenceExpression.resolve();
if(referent == null){
return;
}
@@ -46,21 +50,29 @@ public class ArrayContentsAccessedVisitor extends JavaRecursiveElementVisitor{
accessed = true;
}
@Override public void visitArrayAccessExpression(PsiArrayAccessExpression arg){
@Override public void visitArrayAccessExpression(
PsiArrayAccessExpression arrayAccessExpression){
if(accessed){
return;
}
super.visitArrayAccessExpression(arg);
if(arg.getParent() instanceof PsiAssignmentExpression &&
((PsiAssignmentExpression) arg.getParent()).getLExpression()
.equals(arg)){
return;
super.visitArrayAccessExpression(arrayAccessExpression);
final PsiElement parent = arrayAccessExpression.getParent();
if(parent instanceof PsiAssignmentExpression) {
final PsiAssignmentExpression assignmentExpression =
(PsiAssignmentExpression)parent;
final PsiExpression lhs = assignmentExpression.getLExpression();
if(lhs.equals(arrayAccessExpression)){
return;
}
}
final PsiExpression arrayExpression = arg.getArrayExpression();
final PsiExpression arrayExpression =
arrayAccessExpression.getArrayExpression();
if(!(arrayExpression instanceof PsiReferenceExpression)){
return;
}
final PsiElement referent = ((PsiReference) arrayExpression).resolve();
final PsiReferenceExpression referenceExpression =
(PsiReferenceExpression)arrayExpression;
final PsiElement referent = referenceExpression.resolve();
if(referent == null){
return;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2009 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@ import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ArrayContentsAssignedVisitor extends JavaRecursiveElementVisitor {
class ArrayContentsAssignedVisitor extends JavaRecursiveElementVisitor {
private boolean assigned = false;
private final PsiVariable variable;
@@ -40,7 +40,9 @@ public class ArrayContentsAssignedVisitor extends JavaRecursiveElementVisitor {
if(!(arrayExpression instanceof PsiReferenceExpression)){
return;
}
final PsiElement referent = ((PsiReference) arrayExpression).resolve();
final PsiReferenceExpression referenceExpression =
(PsiReferenceExpression)arrayExpression;
final PsiElement referent = referenceExpression.resolve();
if(referent == null){
return;
}
@@ -66,7 +68,9 @@ public class ArrayContentsAssignedVisitor extends JavaRecursiveElementVisitor {
if(!(arrayExpression instanceof PsiReferenceExpression)){
return;
}
final PsiElement referent = ((PsiReference) arrayExpression).resolve();
final PsiReferenceExpression referenceExpression =
(PsiReferenceExpression)arrayExpression;
final PsiElement referent = referenceExpression.resolve();
if(referent == null){
return;
}
@@ -91,7 +95,9 @@ public class ArrayContentsAssignedVisitor extends JavaRecursiveElementVisitor {
if(!(arrayExpression instanceof PsiReferenceExpression)){
return;
}
final PsiElement referent = ((PsiReference) arrayExpression).resolve();
final PsiReferenceExpression referenceExpression =
(PsiReferenceExpression)arrayExpression;
final PsiElement referent = referenceExpression.resolve();
if(referent == null){
return;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2006 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
*
* 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,7 @@ package com.siyeh.ig.psiutils;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
public class VariableAssignedFromVisitor extends JavaRecursiveElementVisitor{
class VariableAssignedFromVisitor extends JavaRecursiveElementVisitor{
private boolean assignedFrom = false;
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2009 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@ import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.TypeConversionUtil;
import org.jetbrains.annotations.NotNull;
public class VariableAssignedVisitor extends JavaRecursiveElementVisitor{
class VariableAssignedVisitor extends JavaRecursiveElementVisitor{
@NotNull private final PsiVariable variable;
private final boolean recurseIntoClasses;
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2009 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.Set;
public class VariablePassedAsArgumentExcludedVisitor
class VariablePassedAsArgumentExcludedVisitor
extends JavaRecursiveElementVisitor{
@NotNull
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2009 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,8 +18,7 @@ package com.siyeh.ig.psiutils;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
public class VariablePassedAsArgumentVisitor
extends JavaRecursiveElementVisitor{
class VariablePassedAsArgumentVisitor extends JavaRecursiveElementVisitor{
@NotNull
private final PsiVariable variable;
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2005 Dave Griffith
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ import com.intellij.psi.PsiReturnStatement;
import com.intellij.psi.PsiVariable;
import org.jetbrains.annotations.NotNull;
public class VariableReturnedVisitor extends JavaRecursiveElementVisitor {
class VariableReturnedVisitor extends JavaRecursiveElementVisitor {
private boolean returned = false;
@NotNull private final PsiVariable variable;
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2005 Dave Griffith
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,8 +18,7 @@ package com.siyeh.ig.psiutils;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
public class VariableUsedInArrayInitializerVisitor
extends JavaRecursiveElementVisitor{
class VariableUsedInArrayInitializerVisitor extends JavaRecursiveElementVisitor{
@NotNull
private final PsiVariable variable;
@@ -42,11 +41,9 @@ public class VariableUsedInArrayInitializerVisitor
return;
}
super.visitArrayInitializerExpression(expression);
final PsiExpression[] args = expression.getInitializers();
for(final PsiExpression arg : args){
if(VariableAccessUtils.mayEvaluateToVariable(arg, variable)){
final PsiExpression[] initializers = expression.getInitializers();
for(final PsiExpression initializer : initializers){
if(VariableAccessUtils.mayEvaluateToVariable(initializer, variable)){
passed = true;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2005 Dave Griffith
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
*
* 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,7 @@ package com.siyeh.ig.psiutils;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
public class VariableUsedInInnerClassVisitor extends JavaRecursiveElementVisitor{
class VariableUsedInInnerClassVisitor extends JavaRecursiveElementVisitor{
@NotNull private final PsiVariable variable;
private boolean usedInInnerClass = false;
@@ -45,17 +45,17 @@ public class VariableUsedInInnerClassVisitor extends JavaRecursiveElementVisitor
inInnerClass = wasInInnerClass;
}
@Override public void visitReferenceExpression(@NotNull PsiReferenceExpression ref){
@Override public void visitReferenceExpression(
@NotNull PsiReferenceExpression referenceExpression){
if(usedInInnerClass){
return;
}
super.visitReferenceExpression(ref);
super.visitReferenceExpression(referenceExpression);
if(!inInnerClass){
return;
}
final PsiElement element = ref.resolve();
if(variable.equals(element)){
final PsiElement target = referenceExpression.resolve();
if(variable.equals(target)){
usedInInnerClass = true;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2008 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ import com.intellij.psi.PsiReferenceExpression;
import com.intellij.psi.PsiVariable;
import org.jetbrains.annotations.NotNull;
public class VariableUsedVisitor extends JavaRecursiveElementVisitor {
class VariableUsedVisitor extends JavaRecursiveElementVisitor {
private boolean used = false;
@NotNull private final PsiVariable variable;
@@ -1,5 +1,5 @@
/*
* Copyright 2008 Dave Griffith, Bas Leijdekkers
* Copyright 2008-2010 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@ import com.intellij.psi.*;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
public class VariableValueUsedVisitor extends JavaRecursiveElementVisitor {
class VariableValueUsedVisitor extends JavaRecursiveElementVisitor {
@NotNull
private final PsiVariable variable;
+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>
+4 -5
View File
@@ -6,10 +6,9 @@
<version>8.0</version>
<depends optional="true" config-file="intellilang-xpath-support.xml">XPathView</depends>
<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>
<!--<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>-->
<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$$$() {
}
}

Some files were not shown because too many files have changed in this diff Show More