Merge remote-tracking branch 'origin/master'

This commit is contained in:
Ekaterina Tuzova
2013-09-24 10:56:14 +04:00
204 changed files with 1480 additions and 1079 deletions
@@ -16,6 +16,7 @@
package org.intellij.lang.regexp;
import com.intellij.lexer.FlexAdapter;
import org.jetbrains.annotations.NotNull;
import java.util.EnumSet;
@@ -29,7 +30,7 @@ public class RegExpLexer extends FlexAdapter {
myCapabilities = capabilities;
}
public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) {
public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) {
getFlex().commentMode = (initialState & COMMENT_MODE) != 0 || myCapabilities.contains(RegExpCapability.COMMENT_MODE);
super.start(buffer, startOffset, endOffset, initialState & ~COMMENT_MODE);
}
@@ -23,7 +23,7 @@
<help file="ideahelp.jar" root="idea"/>
<documentation url="http://www.jetbrains.com/idea/documentation"/>
<support url="http://www.jetbrains.com/support/idea/index.html"/>
<feedback eap-url="http://youtrack.jetbrains.com"
<feedback eap-url="http://youtrack.jetbrains.com/newissue?project=IDEA&amp;clearDraft=true&amp;c=Affected+versions+$BUILD"
release-url="http://www.jetbrains.com/feedback/feedback.jsp?product=IDEA&amp;build=$BUILD&amp;timezone=$TIMEZONE&amp;eval=$EVAL"/>
<plugins url="http://plugins.jetbrains.com"/>
<whatsnew url="http://www.jetbrains.com/idea/whatsnew/index.html"/>
@@ -38,7 +38,7 @@
<text resource-bundle="messages/CompilerBundle" key="java.compiler.option.generate.no.warnings"/>
</properties>
</component>
<grid id="d7ddf" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="d7ddf" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="8" bottom="0" right="0"/>
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -62,33 +62,6 @@
</constraints>
<properties/>
</component>
<component id="327dc" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/CompilerBundle" key="javac.option.max.heap.size"/>
</properties>
</component>
<component id="15c16" class="javax.swing.JTextField" binding="myJavacMaximumHeapField">
<constraints>
<grid row="1" 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>
<columns value="4"/>
<margin top="0" left="2" bottom="0" right="0"/>
<text value="128"/>
</properties>
</component>
<component id="6f8c2" class="com.intellij.ui.components.JBLabel">
<constraints>
<grid row="1" column="2" row-span="1" col-span="2" vsize-policy="0" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="false"/>
<text value="(ineffective when &quot;Use external build&quot; is on)"/>
</properties>
</component>
</children>
</grid>
<vspacer id="af30">
@@ -35,7 +35,6 @@ public class EclipseCompilerConfigurable implements Configurable {
private JCheckBox myCbDebuggingInfo;
private JCheckBox myCbGenerateNoWarnings;
private RawCommandLineEditor myAdditionalOptionsField;
private JTextField myJavacMaximumHeapField;
private JCheckBox myCbProceedOnErrors;
private final EclipseCompilerOptions myCompilerSettings;
@@ -59,7 +58,7 @@ public class EclipseCompilerConfigurable implements Configurable {
}
public boolean isModified() {
boolean isModified = ComparingUtils.isModified(myJavacMaximumHeapField, myCompilerSettings.MAXIMUM_HEAP_SIZE);
boolean isModified = false;
isModified |= ComparingUtils.isModified(myCbDeprecation, myCompilerSettings.DEPRECATION);
isModified |= ComparingUtils.isModified(myCbDebuggingInfo, myCompilerSettings.DEBUGGING_INFO);
@@ -70,17 +69,6 @@ public class EclipseCompilerConfigurable implements Configurable {
}
public void apply() throws ConfigurationException {
try {
myCompilerSettings.MAXIMUM_HEAP_SIZE = Integer.parseInt(myJavacMaximumHeapField.getText());
if(myCompilerSettings.MAXIMUM_HEAP_SIZE < 1) {
myCompilerSettings.MAXIMUM_HEAP_SIZE = 128;
}
}
catch(NumberFormatException exception) {
myCompilerSettings.MAXIMUM_HEAP_SIZE = 128;
}
myCompilerSettings.DEPRECATION = myCbDeprecation.isSelected();
myCompilerSettings.DEBUGGING_INFO = myCbDebuggingInfo.isSelected();
myCompilerSettings.GENERATE_NO_WARNINGS = myCbGenerateNoWarnings.isSelected();
@@ -89,7 +77,6 @@ public class EclipseCompilerConfigurable implements Configurable {
}
public void reset() {
myJavacMaximumHeapField.setText(Integer.toString(myCompilerSettings.MAXIMUM_HEAP_SIZE));
myCbDeprecation.setSelected(myCompilerSettings.DEPRECATION);
myCbDebuggingInfo.setSelected(myCompilerSettings.DEBUGGING_INFO);
myCbGenerateNoWarnings.setSelected(myCompilerSettings.GENERATE_NO_WARNINGS);
@@ -34,7 +34,6 @@ public class JavacConfigurable implements Configurable{
private JCheckBox myCbDeprecation;
private JCheckBox myCbGenerateNoWarnings;
private RawCommandLineEditor myAdditionalOptionsField;
private JTextField myJavacMaximumHeapField;
private final JpsJavaCompilerOptions myJavacSettings;
public JavacConfigurable(final JpsJavaCompilerOptions javacSettings) {
@@ -56,8 +55,6 @@ public class JavacConfigurable implements Configurable{
public boolean isModified() {
boolean isModified = false;
isModified |= ComparingUtils.isModified(myJavacMaximumHeapField, myJavacSettings.MAXIMUM_HEAP_SIZE);
isModified |= ComparingUtils.isModified(myCbDeprecation, myJavacSettings.DEPRECATION);
isModified |= ComparingUtils.isModified(myCbDebuggingInfo, myJavacSettings.DEBUGGING_INFO);
isModified |= ComparingUtils.isModified(myCbGenerateNoWarnings, myJavacSettings.GENERATE_NO_WARNINGS);
@@ -66,17 +63,6 @@ public class JavacConfigurable implements Configurable{
}
public void apply() throws ConfigurationException {
try {
myJavacSettings.MAXIMUM_HEAP_SIZE = Integer.parseInt(myJavacMaximumHeapField.getText());
if(myJavacSettings.MAXIMUM_HEAP_SIZE < 1) {
myJavacSettings.MAXIMUM_HEAP_SIZE = 128;
}
}
catch(NumberFormatException exception) {
myJavacSettings.MAXIMUM_HEAP_SIZE = 128;
}
myJavacSettings.DEPRECATION = myCbDeprecation.isSelected();
myJavacSettings.DEBUGGING_INFO = myCbDebuggingInfo.isSelected();
myJavacSettings.GENERATE_NO_WARNINGS = myCbGenerateNoWarnings.isSelected();
@@ -84,7 +70,6 @@ public class JavacConfigurable implements Configurable{
}
public void reset() {
myJavacMaximumHeapField.setText(Integer.toString(myJavacSettings.MAXIMUM_HEAP_SIZE));
myCbDeprecation.setSelected(myJavacSettings.DEPRECATION);
myCbDebuggingInfo.setSelected(myJavacSettings.DEBUGGING_INFO);
myCbGenerateNoWarnings.setSelected(myJavacSettings.GENERATE_NO_WARNINGS);
@@ -3,7 +3,7 @@
<grid id="280f7" binding="myPanel" layout-manager="GridLayoutManager" row-count="5" 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="79" y="160" width="574" height="210"/>
<xy x="79" y="160" width="577" height="210"/>
</constraints>
<properties/>
<clientProperties>
@@ -37,7 +37,7 @@
<text resource-bundle="messages/CompilerBundle" key="java.compiler.option.generate.no.warnings"/>
</properties>
</component>
<grid id="d7ddf" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="d7ddf" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="8" bottom="0" right="0"/>
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -61,33 +61,6 @@
</constraints>
<properties/>
</component>
<component id="327dc" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/CompilerBundle" key="javac.option.max.heap.size"/>
</properties>
</component>
<component id="15c16" class="javax.swing.JTextField" binding="myJavacMaximumHeapField">
<constraints>
<grid row="1" 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>
<columns value="4"/>
<margin top="0" left="2" bottom="0" right="0"/>
<text value="128"/>
</properties>
</component>
<component id="9ae23" class="com.intellij.ui.components.JBLabel">
<constraints>
<grid row="1" column="2" row-span="1" col-span="2" vsize-policy="0" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="false"/>
<text value="(ineffective when &quot;Use external build&quot; is on)"/>
</properties>
</component>
</children>
</grid>
<vspacer id="72a3c">
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.compiler.options.CompilerUIConfigurable">
<grid id="1663f" binding="myPanel" layout-manager="GridLayoutManager" row-count="11" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="1663f" binding="myPanel" layout-manager="GridLayoutManager" row-count="10" 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="28" y="24" width="883" height="379"/>
@@ -10,7 +10,7 @@
<children>
<vspacer id="67edf">
<constraints>
<grid row="10" column="0" row-span="1" col-span="3" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="9" column="0" row-span="1" col-span="3" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="b341d" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="1">
@@ -76,17 +76,9 @@
<text resource-bundle="messages/CompilerBundle" key="label.option.autoshow.first.error"/>
</properties>
</component>
<component id="ce617" class="javax.swing.JCheckBox" binding="myCbUseExternalBuild" default-binding="true">
<constraints>
<grid row="4" 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="Use external build"/>
</properties>
</component>
<component id="b9b2d" class="javax.swing.JCheckBox" binding="myCbEnableAutomake">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
<grid row="4" 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="Make project automatically"/>
@@ -94,7 +86,7 @@
</component>
<component id="17126" class="javax.swing.JLabel" binding="myHeapSizeLabel">
<constraints>
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
<grid row="7" 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="Compiler process heap size (Mbytes):"/>
@@ -102,7 +94,7 @@
</component>
<component id="a28b8" class="javax.swing.JTextField" binding="myHeapSizeField">
<constraints>
<grid row="8" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false">
<grid row="7" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="50" height="-1"/>
</grid>
</constraints>
@@ -110,7 +102,7 @@
</component>
<component id="5b86a" class="javax.swing.JLabel" binding="myVMOptionsLabel">
<constraints>
<grid row="9" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
<grid row="8" 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="Additional compiler process VM options:"/>
@@ -118,7 +110,7 @@
</component>
<component id="b5547" class="javax.swing.JTextField" binding="myVMOptionsField">
<constraints>
<grid row="9" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="8" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
@@ -126,7 +118,7 @@
</component>
<component id="ba694" class="javax.swing.JCheckBox" binding="myCbParallelCompilation">
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
<grid row="5" 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="Compile independent modules in parallel"/>
@@ -134,7 +126,7 @@
</component>
<component id="91979" class="javax.swing.JLabel" binding="myParallelCompilationLegendLabel">
<constraints>
<grid row="6" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="5" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="(may require larger heap size)"/>
@@ -142,7 +134,7 @@
</component>
<component id="732b1" class="javax.swing.JLabel" binding="myEnableAutomakeLegendLabel">
<constraints>
<grid row="5" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="4" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="(only works while not running / debugging)"/>
@@ -150,7 +142,7 @@
</component>
<component id="4b44" class="javax.swing.JCheckBox" binding="myCbRebuildOnDependencyChange" default-binding="true">
<constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
<grid row="6" 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="Rebuild module on dependency change"/>
@@ -36,8 +36,6 @@ import com.intellij.util.containers.ContainerUtilRt;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.*;
import static com.intellij.compiler.options.CompilerOptionsFilter.Setting;
@@ -77,7 +75,6 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura
private JCheckBox myCbAssertNotNull;
private JBLabel myPatternLegendLabel;
private JCheckBox myCbAutoShowFirstError;
private JCheckBox myCbUseExternalBuild;
private JCheckBox myCbEnableAutomake;
private JCheckBox myCbParallelCompilation;
private JTextField myHeapSizeField;
@@ -93,19 +90,12 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura
myProject = project;
myPatternLegendLabel.setText("<html><body>" +
"Use <b>;</b> to separate patterns and <b>!</b> to negate a pattern. " +
"Accepted wildcards: <b>?</b> &mdash; exactly one symbol; <b>*</b> &mdash; zero or more symbols; " +
"<b>/</b> &mdash; path separator; <b>/**/</b> &mdash; any number of directories; " +
"<i>&lt;dir_name&gt;</i>:<i>&lt;pattern&gt;</i> &mdash; restrict to source roots with the specified name" +
"</body></html>");
"Use <b>;</b> to separate patterns and <b>!</b> to negate a pattern. " +
"Accepted wildcards: <b>?</b> &mdash; exactly one symbol; <b>*</b> &mdash; zero or more symbols; " +
"<b>/</b> &mdash; path separator; <b>/**/</b> &mdash; any number of directories; " +
"<i>&lt;dir_name&gt;</i>:<i>&lt;pattern&gt;</i> &mdash; restrict to source roots with the specified name" +
"</body></html>");
myPatternLegendLabel.setForeground(new JBColor(Gray._50, Gray._130));
myCbUseExternalBuild.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
updateExternalMakeOptionControls(myCbUseExternalBuild.isSelected());
}
});
tweakControls(project);
}
@@ -141,7 +131,6 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura
controls.put(Setting.CLEAR_OUTPUT_DIR_ON_REBUILD, Collections.<JComponent>singleton(myCbClearOutputDirectory));
controls.put(Setting.ADD_NOT_NULL_ASSERTIONS, Collections.<JComponent>singleton(myCbAssertNotNull));
controls.put(Setting.AUTO_SHOW_FIRST_ERROR_IN_EDITOR, Collections.<JComponent>singleton(myCbAutoShowFirstError));
controls.put(Setting.EXTERNAL_BUILD, ContainerUtilRt.<JComponent>newArrayList(myCbUseExternalBuild));
controls.put(Setting.AUTO_MAKE, ContainerUtilRt.<JComponent>newArrayList(myCbEnableAutomake, myEnableAutomakeLegendLabel));
controls.put(Setting.PARALLEL_COMPILATION,
ContainerUtilRt.<JComponent>newArrayList(myCbParallelCompilation, myParallelCompilationLegendLabel));
@@ -166,14 +155,12 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura
myCbAutoShowFirstError.setSelected(workspaceConfiguration.AUTO_SHOW_ERRORS_IN_EDITOR);
myCbClearOutputDirectory.setSelected(workspaceConfiguration.CLEAR_OUTPUT_DIRECTORY);
myCbAssertNotNull.setSelected(configuration.isAddNotNullAssertions());
myCbUseExternalBuild.setSelected(workspaceConfiguration.useOutOfProcessBuild());
myCbEnableAutomake.setSelected(workspaceConfiguration.MAKE_PROJECT_ON_SAVE);
myCbParallelCompilation.setSelected(workspaceConfiguration.PARALLEL_COMPILATION);
myCbRebuildOnDependencyChange.setSelected(workspaceConfiguration.REBUILD_ON_DEPENDENCY_CHANGE);
myHeapSizeField.setText(String.valueOf(workspaceConfiguration.COMPILER_PROCESS_HEAP_SIZE));
final String options = workspaceConfiguration.COMPILER_PROCESS_ADDITIONAL_VM_OPTIONS;
myVMOptionsField.setText(options == null ? "" : options.trim());
updateExternalMakeOptionControls(myCbUseExternalBuild.isSelected());
configuration.convertPatterns();
@@ -201,9 +188,7 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura
if (!myDisabledSettings.contains(Setting.CLEAR_OUTPUT_DIR_ON_REBUILD)) {
workspaceConfiguration.CLEAR_OUTPUT_DIRECTORY = myCbClearOutputDirectory.isSelected();
}
boolean wasUsingExternalMake = workspaceConfiguration.useOutOfProcessBuild();
if (!myDisabledSettings.contains(Setting.EXTERNAL_BUILD)) {
workspaceConfiguration.USE_COMPILE_SERVER = myCbUseExternalBuild.isSelected();
if (!myDisabledSettings.contains(Setting.AUTO_MAKE)) {
workspaceConfiguration.MAKE_PROJECT_ON_SAVE = myCbEnableAutomake.isSelected();
}
@@ -234,12 +219,8 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura
String extensionString = myResourcePatternsField.getText().trim();
applyResourcePatterns(extensionString, (CompilerConfigurationImpl)CompilerConfiguration.getInstance(myProject));
}
if (wasUsingExternalMake != workspaceConfiguration.useOutOfProcessBuild()) {
myProject.getMessageBus().syncPublisher(ExternalBuildOptionListener.TOPIC).externalBuildOptionChanged(workspaceConfiguration.useOutOfProcessBuild());
}
if (workspaceConfiguration.useOutOfProcessBuild()) {
BuildManager.getInstance().clearState(myProject);
}
BuildManager.getInstance().clearState(myProject);
}
private static void applyResourcePatterns(String extensionString, final CompilerConfigurationImpl configuration)
@@ -277,8 +258,6 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura
final CompilerWorkspaceConfiguration workspaceConfiguration = CompilerWorkspaceConfiguration.getInstance(myProject);
boolean isModified = !myDisabledSettings.contains(Setting.AUTO_SHOW_FIRST_ERROR_IN_EDITOR)
&& ComparingUtils.isModified(myCbAutoShowFirstError, workspaceConfiguration.AUTO_SHOW_ERRORS_IN_EDITOR);
isModified |= !myDisabledSettings.contains(Setting.EXTERNAL_BUILD)
&& ComparingUtils.isModified(myCbUseExternalBuild, workspaceConfiguration.useOutOfProcessBuild());
isModified |= !myDisabledSettings.contains(Setting.AUTO_MAKE)
&& ComparingUtils.isModified(myCbEnableAutomake, workspaceConfiguration.MAKE_PROJECT_ON_SAVE);
isModified |= !myDisabledSettings.contains(Setting.PARALLEL_COMPILATION)
@@ -325,16 +304,6 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura
public void disposeUIResources() {
}
private void updateExternalMakeOptionControls(boolean enabled) {
myCbEnableAutomake.setEnabled(enabled);
myCbParallelCompilation.setEnabled(enabled);
myCbRebuildOnDependencyChange.setEnabled(enabled);
myHeapSizeField.setEnabled(enabled);
myVMOptionsField.setEnabled(enabled);
myHeapSizeLabel.setEnabled(enabled);
myVMOptionsLabel.setEnabled(enabled);
}
private void createUIComponents() {
myResourcePatternsField = new RawCommandLineEditor(LINE_PARSER, LINE_JOINER);
myResourcePatternsField.setDialogCaption("Resource patterns");
@@ -58,6 +58,7 @@ public class InspectionValidatorWrapper implements Validator {
private final InspectionProjectProfileManager myProfileManager;
private final PsiDocumentManager myPsiDocumentManager;
private static final ThreadLocal<Boolean> ourCompilationThreads = new ThreadLocal<Boolean>() {
@Override
protected Boolean initialValue() {
return Boolean.FALSE;
}
@@ -95,11 +96,13 @@ public class InspectionValidatorWrapper implements Validator {
myVirtualFile = psiFile.getVirtualFile();
}
@Override
@NotNull
public VirtualFile getFile() {
return myVirtualFile;
}
@Override
@Nullable
public ValidityState getValidityState() {
if (myValidityState == null) {
@@ -121,6 +124,7 @@ public class InspectionValidatorWrapper implements Validator {
}
}
@Override
@NotNull
public ProcessingItem[] getProcessingItems(final CompileContext context) {
final Project project = context.getProject();
@@ -129,6 +133,7 @@ public class InspectionValidatorWrapper implements Validator {
}
final ExcludedEntriesConfiguration excludedEntriesConfiguration = ValidationConfiguration.getExcludedEntriesConfiguration(project);
final List<ProcessingItem> items = new ReadAction<List<ProcessingItem>>() {
@Override
protected void run(final Result<List<ProcessingItem>> result) {
final CompileScope compileScope = context.getCompileScope();
if (!myValidator.isAvailableOnScope(compileScope)) return;
@@ -167,6 +172,7 @@ public class InspectionValidatorWrapper implements Validator {
return items.toArray(new ProcessingItem[items.size()]);
}
@Override
public ProcessingItem[] process(final CompileContext context, final ProcessingItem[] items) {
context.getProgressIndicator().setText(myValidator.getProgressIndicatorText());
@@ -307,7 +313,13 @@ public class InspectionValidatorWrapper implements Validator {
final List<ExternalAnnotator> annotators = ExternalLanguageAnnotators.allForFile(StdLanguages.XML, xmlFile);
for (ExternalAnnotator annotator : annotators) {
annotator.annotate(xmlFile, holder);
Object initial = annotator.collectInformation(xmlFile);
if (initial != null) {
Object result = annotator.doAnnotate(initial);
if (result != null) {
annotator.apply(xmlFile, result, holder);
}
}
}
if (!holder.hasAnnotations()) return Collections.emptyMap();
@@ -331,15 +343,18 @@ public class InspectionValidatorWrapper implements Validator {
}
@Override
@NotNull
public String getDescription() {
return myValidator.getDescription();
}
@Override
public boolean validateConfiguration(final CompileScope scope) {
return true;
}
@Override
public ValidityState createValidityState(final DataInput in) throws IOException {
return PsiElementsValidityState.load(in);
}
@@ -28,7 +28,6 @@ import com.intellij.packaging.elements.PackagingElementType;
import com.intellij.packaging.ui.ArtifactEditorContext;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.ArrayList;
@@ -89,11 +88,6 @@ public abstract class FacetBasedPackagingElementType<E extends PackagingElement<
protected abstract String getItemText(F item);
@Nullable
protected Icon getIcon(F item) {
return FacetTypeRegistry.getInstance().findFacetType(myFacetType).getIcon();
}
private class ChooseFacetsDialog extends ChooseElementsDialog<F> {
private ChooseFacetsDialog(Project project, List<? extends F> items, String title, String description) {
super(project, items, title, description, true);
@@ -106,7 +100,7 @@ public abstract class FacetBasedPackagingElementType<E extends PackagingElement<
@Override
protected Icon getItemIcon(F item) {
return FacetBasedPackagingElementType.this.getIcon(item);
return FacetTypeRegistry.getInstance().findFacetType(myFacetType).getIcon();
}
}
}
@@ -43,7 +43,7 @@ public class CompilerWorkspaceConfiguration implements PersistentStateComponent<
public boolean AUTO_SHOW_ERRORS_IN_EDITOR = true;
@Deprecated public boolean CLOSE_MESSAGE_VIEW_IF_SUCCESS = true;
public boolean CLEAR_OUTPUT_DIRECTORY = true;
public boolean USE_COMPILE_SERVER = true;
public boolean USE_OUT_OF_PROCESS_BUILD = true;
public boolean MAKE_PROJECT_ON_SAVE = false; // until we fix problems with several open projects (IDEA-104064), daemon slowness (IDEA-104666)
public boolean PARALLEL_COMPILATION = false;
public int COMPILER_PROCESS_HEAP_SIZE = DEFAULT_COMPILE_PROCESS_HEAP_SIZE;
@@ -63,7 +63,7 @@ public class CompilerWorkspaceConfiguration implements PersistentStateComponent<
}
public boolean useOutOfProcessBuild() {
return USE_COMPILE_SERVER;
return USE_OUT_OF_PROCESS_BUILD;
}
public boolean allowAutoMakeWhileRunningApplication() {
@@ -99,6 +99,7 @@ public class JUnitUtil {
}
public static boolean isTestClass(@NotNull PsiClass psiClass, boolean checkAbstract, boolean checkForTestCaseInheritance) {
if (psiClass.getQualifiedName() == null) return false;
if (!PsiClassUtil.isRunnableClass(psiClass, true, checkAbstract)) return false;
if (checkForTestCaseInheritance && isTestCaseInheritor(psiClass)) return true;
final PsiModifierList modifierList = psiClass.getModifierList();
@@ -30,6 +30,7 @@ import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.JavaSdkVersion;
import com.intellij.openapi.projectRoots.JavaVersionService;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.TextRange;
import com.intellij.pom.java.LanguageLevel;
@@ -37,6 +38,7 @@ import com.intellij.psi.*;
import com.intellij.psi.controlFlow.ControlFlowUtil;
import com.intellij.psi.impl.source.javadoc.PsiDocMethodOrFieldRef;
import com.intellij.psi.impl.source.resolve.JavaResolveUtil;
import com.intellij.psi.impl.source.resolve.graphInference.FunctionalInterfaceParameterizationUtil;
import com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionImpl;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.javadoc.PsiDocTagValue;
@@ -311,16 +313,28 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
myHolder.add(result);
}
else {
for (int i = 0; i < lambdaParameters.length; i++) {
PsiParameter lambdaParameter = lambdaParameters[i];
if (!TypeConversionUtil.isAssignable(lambdaParameter.getType(),
GenericsUtil.eliminateWildcards(
LambdaUtil.getSubstitutor(interfaceMethod, resolveResult)
.substitute(parameters[i].getType())))) {
HighlightInfo result = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(lambdaParameter)
.descriptionAndTooltip(incompatibleTypesMessage).create();
myHolder.add(result);
break;
final PsiSubstitutor substitutor = LambdaUtil.getSubstitutor(interfaceMethod, resolveResult);
if (expression.hasFormalParameterTypes()) {
for (int i = 0; i < lambdaParameters.length; i++) {
if (!Comparing.equal(lambdaParameters[i].getType(), substitutor.substitute(parameters[i].getType()))) {
HighlightInfo result = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(lambdaParameters[i])
.descriptionAndTooltip(incompatibleTypesMessage)
.create();
myHolder.add(result);
break;
}
}
} else {
for (int i = 0; i < lambdaParameters.length; i++) {
PsiParameter lambdaParameter = lambdaParameters[i];
if (!TypeConversionUtil.isAssignable(lambdaParameter.getType(),
GenericsUtil.eliminateWildcards(substitutor.substitute(parameters[i].getType())))) {
HighlightInfo result = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(lambdaParameter)
.descriptionAndTooltip(incompatibleTypesMessage).create();
myHolder.add(result);
break;
}
}
}
}
@@ -58,14 +58,13 @@ public class ExpressionTypeMemoryState extends DfaMemoryStateImpl {
super(factory);
}
@Override
protected DfaMemoryStateImpl createNew() {
return new ExpressionTypeMemoryState(getFactory());
private ExpressionTypeMemoryState(DfaMemoryStateImpl toCopy) {
super(toCopy);
}
@Override
public DfaMemoryStateImpl createCopy() {
final ExpressionTypeMemoryState copy = (ExpressionTypeMemoryState)super.createCopy();
final ExpressionTypeMemoryState copy = new ExpressionTypeMemoryState(this);
copy.myStates.putAll(myStates);
return copy;
}
@@ -139,6 +139,7 @@ public class DataFlowRunner {
}
MultiMapBasedOnSet<BranchingInstruction, DfaMemoryState> processedStates = new MultiMapBasedOnSet<BranchingInstruction, DfaMemoryState>();
MultiMapBasedOnSet<BranchingInstruction, DfaMemoryState> incomingStates = new MultiMapBasedOnSet<BranchingInstruction, DfaMemoryState>();
WorkingTimeMeasurer measurer = new WorkingTimeMeasurer(shouldCheckTimeLimit() ? ourTimeLimit : ourTimeLimit * 42);
int count = 0;
@@ -176,9 +177,13 @@ public class DataFlowRunner {
if (nextInstruction.getIndex() >= endOffset) {
continue;
}
if (nextInstruction instanceof BranchingInstruction &&
processedStates.get((BranchingInstruction)nextInstruction).contains(state.getMemoryState())) {
continue;
if (nextInstruction instanceof BranchingInstruction) {
BranchingInstruction branching = (BranchingInstruction)nextInstruction;
if (processedStates.get(branching).contains(state.getMemoryState()) ||
incomingStates.get(branching).contains(state.getMemoryState())) {
continue;
}
incomingStates.putValue(branching, state.getMemoryState().createCopy());
}
queue.offer(state);
}
@@ -70,11 +70,9 @@ class StateQueue {
private final Set<Pair<Instruction, DfaMemoryState>> mySet = ContainerUtil.newHashSet();
void offer(DfaInstructionState state) {
if (mySet.contains(Pair.create(state.getInstruction(), state.getMemoryState()))) {
return;
if (mySet.add(Pair.create(state.getInstruction(), state.getMemoryState()))) {
myQueue.offer(state);
}
mySet.add(Pair.create(state.getInstruction(), state.getMemoryState().createCopy()));
myQueue.offer(state);
}
boolean isEmpty() {
@@ -26,6 +26,7 @@ package com.intellij.codeInspection.dataFlow;
import com.intellij.codeInspection.dataFlow.value.*;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.util.UnorderedPair;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.util.TypeConversionUtil;
@@ -41,45 +42,55 @@ import java.util.*;
public class DfaMemoryStateImpl implements DfaMemoryState {
private final DfaValueFactory myFactory;
private final List<EqClass> myEqClasses = ContainerUtil.newArrayList();
private final Stack<DfaValue> myStack = new Stack<DfaValue>();
private TIntStack myOffsetStack = new TIntStack(1);
private final TLongHashSet myDistinctClasses = new TLongHashSet();
private final THashMap<DfaVariableValue,DfaVariableState> myVariableStates = new THashMap<DfaVariableValue, DfaVariableState>();
private final THashSet<DfaVariableValue> myUnknownVariables = new THashSet<DfaVariableValue>();
private final List<EqClass> myEqClasses;
private final Stack<DfaValue> myStack;
private final TIntStack myOffsetStack;
private final TLongHashSet myDistinctClasses;
private final Map<DfaVariableValue,DfaVariableState> myVariableStates;
private final Map<DfaVariableValue,DfaVariableState> myDefaultVariableStates;
private final Set<DfaVariableValue> myUnknownVariables;
private boolean myEphemeral;
public DfaMemoryStateImpl(final DfaValueFactory factory) {
myFactory = factory;
myDefaultVariableStates = ContainerUtil.newTroveMap();
myEqClasses = ContainerUtil.newArrayList();
myUnknownVariables = ContainerUtil.newTroveSet();
myVariableStates = ContainerUtil.newTroveMap();
myDistinctClasses = new TLongHashSet();
myOffsetStack = new TIntStack();
myStack = new Stack<DfaValue>();
}
protected DfaMemoryStateImpl(DfaMemoryStateImpl toCopy) {
myFactory = toCopy.myFactory;
myEphemeral = toCopy.myEphemeral;
myDefaultVariableStates = toCopy.myDefaultVariableStates; // shared between all states
myStack = new Stack<DfaValue>(toCopy.myStack);
myDistinctClasses = new TLongHashSet(toCopy.myDistinctClasses.toArray());
myUnknownVariables = new THashSet<DfaVariableValue>(toCopy.myUnknownVariables);
myOffsetStack = new TIntStack(toCopy.myOffsetStack);
myEqClasses = ContainerUtil.newArrayListWithCapacity(toCopy.myEqClasses.size());
for (int i = 0; i < toCopy.myEqClasses.size(); i++) {
EqClass aClass = toCopy.myEqClasses.get(i);
myEqClasses.add(aClass != null ? new EqClass(aClass) : null);
}
myVariableStates = new THashMap<DfaVariableValue, DfaVariableState>(toCopy.myVariableStates);
myCachedDistinctClassPairs = toCopy.myCachedDistinctClassPairs;
myCachedNonTrivialEqClasses = toCopy.myCachedNonTrivialEqClasses;
}
public DfaValueFactory getFactory() {
return myFactory;
}
protected DfaMemoryStateImpl createNew() {
return new DfaMemoryStateImpl(myFactory);
}
@Override
public DfaMemoryStateImpl createCopy() {
DfaMemoryStateImpl newState = createNew();
newState.myEphemeral = myEphemeral;
newState.myStack.addAll(myStack);
newState.myDistinctClasses.addAll(myDistinctClasses.toArray());
newState.myUnknownVariables.addAll(myUnknownVariables);
newState.myOffsetStack = new TIntStack(myOffsetStack);
for (int i = 0; i < myEqClasses.size(); i++) {
EqClass aClass = myEqClasses.get(i);
newState.myEqClasses.add(aClass != null ? new EqClass(aClass) : null);
}
for (DfaVariableValue dfaVariableValue : myVariableStates.keySet()) {
newState.myVariableStates.put(dfaVariableValue, myVariableStates.get(dfaVariableValue).clone());
}
return newState;
return new DfaMemoryStateImpl(this);
}
public boolean equals(Object obj) {
@@ -98,32 +109,17 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
if (myDistinctClasses.size() != that.myDistinctClasses.size()) return false;
if (!getNonTrivialEqClasses().equals(that.getNonTrivialEqClasses())) return false;
if (!getDistinctClassPairs().equals(that.getDistinctClassPairs())) return false;
for (DfaVariableValue var : myVariableStates.keySet()) {
DfaVariableState thatState = that.myVariableStates.get(var);
if (!myVariableStates.get(var).equals(thatState != null ? thatState : createVariableState(var))) {
return false;
}
}
for (DfaVariableValue var : that.myVariableStates.keySet()) {
if (!myVariableStates.containsKey(var) && !that.myVariableStates.get(var).equals(createVariableState(var))) {
return false;
}
}
if (!myVariableStates.equals(that.myVariableStates)) return false;
return true;
}
private Set<Set<EqClass>> myCachedDistinctClassPairs;
Set<Set<EqClass>> getDistinctClassPairs() {
private Set<UnorderedPair<EqClass>> myCachedDistinctClassPairs;
Set<UnorderedPair<EqClass>> getDistinctClassPairs() {
if (myCachedDistinctClassPairs != null) return myCachedDistinctClassPairs;
Set<Set<EqClass>> result = ContainerUtil.newHashSet();
Set<UnorderedPair<EqClass>> result = ContainerUtil.newHashSet();
for (long encodedPair : myDistinctClasses.toArray()) {
THashSet<EqClass> pair = new THashSet<EqClass>(2);
pair.add(myEqClasses.get(low(encodedPair)));
pair.add(myEqClasses.get(high(encodedPair)));
result.add(pair);
result.add(new UnorderedPair<EqClass>(myEqClasses.get(low(encodedPair)), myEqClasses.get(high(encodedPair))));
}
return myCachedDistinctClassPairs = result;
}
@@ -142,7 +138,11 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
}
public int hashCode() {
return ((getNonTrivialEqClasses().hashCode() * 31 + getDistinctClassPairs().hashCode()) * 31 + myStack.hashCode()) * 31 + myUnknownVariables.hashCode();
return (((getNonTrivialEqClasses().hashCode() * 31 +
getDistinctClassPairs().hashCode()) * 31 +
myStack.hashCode()) * 31 +
myUnknownVariables.hashCode()) * 31 +
myVariableStates.hashCode();
}
@SuppressWarnings({"HardCodedStringLiteral"})
@@ -160,8 +160,8 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
if (!myDistinctClasses.isEmpty()) {
result.append("\n distincts: ");
List<String> distincts = new ArrayList<String>();
for (Set<EqClass> pair : getDistinctClassPairs()) {
distincts.add("{" + StringUtil.join(pair, ", ") + "}");
for (UnorderedPair<EqClass> pair : getDistinctClassPairs()) {
distincts.add("{" + pair.first + ", " + pair.second + "}");
}
Collections.sort(distincts);
result.append(StringUtil.join(distincts, " "));
@@ -218,15 +218,14 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
if (var == value) return;
flushVariable(var);
DfaVariableState varState = getVariableState(var);
if (value instanceof DfaUnknownValue) {
varState.setNullable(false);
setVariableState(var, getVariableState(var).withNullable(false));
return;
}
varState.setValue(value);
setVariableState(var, getVariableState(var).withValue(value));
if (value instanceof DfaTypeValue) {
varState.setNullable(((DfaTypeValue)value).isNullable());
setVariableState(var, getVariableState(var).withNullable(((DfaTypeValue)value).isNullable()));
DfaRelationValue dfaInstanceof = myFactory.getRelationFactory().createRelation(var, value, JavaTokenType.INSTANCEOF_KEYWORD, false);
if (((DfaTypeValue)value).isNotNull()) {
applyCondition(dfaInstanceof);
@@ -240,15 +239,15 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
applyCondition(dfaEqual);
if (value instanceof DfaVariableValue) {
myVariableStates.put(var, varState = getVariableState((DfaVariableValue)value).clone());
setVariableState(var, getVariableState((DfaVariableValue)value));
}
else if (value instanceof DfaBoxedValue) {
varState.setNullable(false);
setVariableState(var, getVariableState(var).withNullable(false));
applyCondition(compareToNull(var, true));
}
}
if (varState.isNotNull()) {
if (getVariableState(var).isNotNull()) {
applyCondition(compareToNull(var, true));
}
}
@@ -448,7 +447,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
public boolean isNull(DfaValue dfaValue) {
if (dfaValue instanceof DfaTypeValue && ((DfaTypeValue)dfaValue).isNotNull()) return false;
if (dfaValue instanceof DfaConstValue) return ((DfaConstValue)dfaValue).getConstant() == null;
if (dfaValue instanceof DfaConstValue) return ((DfaConstValue)dfaValue).getValue() == null;
if (dfaValue instanceof DfaVariableValue) {
int c1Index = getEqClassIndex(dfaValue);
@@ -509,7 +508,13 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
DfaVariableValue dfaVar = (DfaVariableValue)left;
DfaTypeValue dfaType = (DfaTypeValue)dfaCond.getRightOperand();
return isNull(dfaVar) || getVariableState(dfaVar).setInstanceofValue(dfaType);
if (isUnknownState(dfaVar) || isNull(dfaVar)) return true;
DfaVariableState newState = getVariableState(dfaVar).withInstanceofValue(dfaType);
if (newState != null) {
setVariableState(dfaVar, newState);
return true;
}
return false;
}
static DfaValue unwrap(DfaValue value) {
@@ -561,12 +566,25 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
if (dfaRight instanceof DfaTypeValue) {
if (dfaLeft instanceof DfaVariableValue) {
DfaVariableState varState = getVariableState((DfaVariableValue)dfaLeft);
DfaVariableValue dfaVar = (DfaVariableValue)dfaLeft;
if (isUnknownState(dfaVar)) return true;
if (isNegated) {
return varState.addNotInstanceofValue((DfaTypeValue)dfaRight) || applyCondition(compareToNull(dfaVar, false));
DfaVariableState newState = getVariableState(dfaVar).withNotInstanceofValue((DfaTypeValue)dfaRight);
if (newState != null) {
setVariableState(dfaVar, newState);
return true;
}
return applyCondition(compareToNull(dfaVar, false));
}
return applyCondition(compareToNull(dfaVar, true)) && varState.setInstanceofValue((DfaTypeValue)dfaRight);
if (applyCondition(compareToNull(dfaVar, true))) {
DfaVariableState newState = getVariableState(dfaVar).withInstanceofValue((DfaTypeValue)dfaRight);
if (newState != null) {
setVariableState(dfaVar, newState);
return true;
}
}
return false;
}
return true;
}
@@ -593,7 +611,9 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
if (isNotNull(dfaVar)) {
return true;
}
getVariableState(dfaVar).setNullable(true);
if (!isUnknownState(dfaVar)) {
setVariableState(dfaVar, getVariableState(dfaVar).withNullability(Nullness.NULLABLE));
}
}
return false;
}
@@ -734,17 +754,33 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
return myFactory.getRelationFactory().createRelation(dfaVar, dfaNull, JavaTokenType.EQEQ, negated);
}
void setVariableState(DfaVariableValue dfaVar, DfaVariableState state) {
assert !myUnknownVariables.contains(dfaVar);
if (state.equals(myDefaultVariableStates.get(dfaVar))) {
myVariableStates.remove(dfaVar);
} else {
myVariableStates.put(dfaVar, state);
}
}
public DfaVariableState getVariableState(DfaVariableValue dfaVar) {
DfaVariableState state = myVariableStates.get(dfaVar);
if (state == null) {
state = createVariableState(dfaVar);
state = myDefaultVariableStates.get(dfaVar);
if (state == null) {
state = createVariableState(dfaVar);
DfaTypeValue initialType = dfaVar.getTypeValue();
if (initialType != null) {
state = state.withInstanceofValue(initialType);
assert state != null;
}
myDefaultVariableStates.put(dfaVar, state);
}
if (isUnknownState(dfaVar)) {
state.setNullable(false);
return state;
return state.withNullable(false);
}
myVariableStates.put(dfaVar, state);
}
return state;
@@ -760,16 +796,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
@Override
public void flushFields(DfaVariableValue[] fields) {
Set<DfaVariableValue> allVars = new HashSet<DfaVariableValue>(myVariableStates.keySet());
Collections.addAll(allVars, fields);
Set<DfaVariableValue> dependencies = new HashSet<DfaVariableValue>();
for (DfaVariableValue variableValue : allVars) {
dependencies.addAll(myFactory.getVarFactory().getAllQualifiedBy(variableValue));
}
allVars.addAll(dependencies);
for (DfaVariableValue value : allVars) {
for (DfaVariableValue value : myFactory.getVarFactory().getAllVariables()) {
if (myVariableStates.containsKey(value) || getEqClassIndex(value) >= 0) {
if (value.isFlushableByCalls()) {
doFlush(value, true);
@@ -163,9 +163,10 @@ public class DfaUtil {
}
@Override
public DfaInstructionState[] visitAssign(AssignInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) {
public DfaInstructionState[] visitAssign(AssignInstruction instruction, DataFlowRunner runner, DfaMemoryState _memState) {
final Instruction nextInstruction = runner.getInstruction(instruction.getIndex() + 1);
ValuableDataFlowRunner.MyDfaMemoryState memState = (ValuableDataFlowRunner.MyDfaMemoryState)_memState;
final DfaValue dfaSource = memState.pop();
final DfaValue dfaDest = memState.pop();
@@ -176,10 +177,10 @@ public class DfaUtil {
final IElementType type = parent instanceof PsiAssignmentExpression
? ((PsiAssignmentExpression)parent).getOperationTokenType() : JavaTokenType.EQ;
// store current value - to use in case of '+='
final PsiExpression prevValue = ((ValuableDataFlowRunner.ValuableDfaVariableState)((ValuableDataFlowRunner.MyDfaMemoryState)memState).getVariableState(var)).myExpression;
final PsiExpression prevValue = ((ValuableDataFlowRunner.ValuableDfaVariableState)memState.getVariableState(var)).myExpression;
memState.setVarValue(var, dfaSource);
// state may have been changed so re-retrieve it
final ValuableDataFlowRunner.ValuableDfaVariableState curState = (ValuableDataFlowRunner.ValuableDfaVariableState)((ValuableDataFlowRunner.MyDfaMemoryState)memState).getVariableState(var);
final ValuableDataFlowRunner.ValuableDfaVariableState curState = (ValuableDataFlowRunner.ValuableDfaVariableState)memState.getVariableState(var);
final PsiExpression curValue = curState.myExpression;
final PsiExpression nextValue;
if (type == JavaTokenType.PLUSEQ && prevValue != null) {
@@ -196,7 +197,7 @@ public class DfaUtil {
else {
nextValue = curValue == null ? rightValue : curValue;
}
curState.myExpression = nextValue;
memState.setVariableState(var, curState.withExpression(nextValue));
}
memState.push(dfaDest);
return new DfaInstructionState[]{new DfaInstructionState(nextInstruction, memState)};
@@ -35,28 +35,24 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class DfaVariableState implements Cloneable {
private final Set<DfaPsiType> myInstanceofValues;
private final Set<DfaPsiType> myNotInstanceofValues;
private Nullness myNullability;
public class DfaVariableState {
protected final Set<DfaPsiType> myInstanceofValues;
protected final Set<DfaPsiType> myNotInstanceofValues;
protected final Nullness myNullability;
public DfaVariableState(@NotNull DfaVariableValue dfaVar) {
myInstanceofValues = ContainerUtil.newTroveSet();
myNotInstanceofValues = ContainerUtil.newTroveSet();
myNullability = dfaVar.getInherentNullability();
DfaTypeValue initialType = dfaVar.getTypeValue();
if (initialType != null) {
setInstanceofValue(initialType);
}
this(Collections.<DfaPsiType>emptySet(), Collections.<DfaPsiType>emptySet(), dfaVar.getInherentNullability());
}
protected DfaVariableState(final DfaVariableState toClone) {
myInstanceofValues = ContainerUtil.newTroveSet(toClone.myInstanceofValues);
myNotInstanceofValues = ContainerUtil.newTroveSet(toClone.myNotInstanceofValues);
myNullability = toClone.myNullability;
protected DfaVariableState(Set<DfaPsiType> instanceofValues,
Set<DfaPsiType> notInstanceofValues, Nullness nullability) {
myInstanceofValues = instanceofValues;
myNotInstanceofValues = notInstanceofValues;
myNullability = nullability;
}
public boolean isNullable() {
@@ -77,48 +73,51 @@ public class DfaVariableState implements Cloneable {
return true;
}
public boolean setInstanceofValue(DfaTypeValue dfaType) {
if (dfaType.isNullable()) {
myNullability = Nullness.NULLABLE;
}
if (dfaType.getDfaType().getPsiType() instanceof PsiPrimitiveType) return true;
@Nullable
public DfaVariableState withInstanceofValue(DfaTypeValue dfaType) {
if (dfaType.getDfaType().getPsiType() instanceof PsiPrimitiveType) return this;
if (checkInstanceofValue(dfaType.getDfaType())) {
myInstanceofValues.add(dfaType.getDfaType());
return true;
DfaVariableState result = dfaType.isNullable() ? withNullability(Nullness.NULLABLE) : this;
if (!myInstanceofValues.contains(dfaType.getDfaType())) {
HashSet<DfaPsiType> newInstanceof = ContainerUtil.newHashSet(myInstanceofValues);
newInstanceof.add(dfaType.getDfaType());
result = createCopy(newInstanceof, myNotInstanceofValues, result.myNullability);
}
return result;
}
return false;
return null;
}
public boolean addNotInstanceofValue(DfaTypeValue dfaType) {
if (myNotInstanceofValues.contains(dfaType.getDfaType())) return true;
@Nullable
public DfaVariableState withNotInstanceofValue(DfaTypeValue dfaType) {
if (myNotInstanceofValues.contains(dfaType.getDfaType())) return this;
for (DfaPsiType dfaTypeValue : myInstanceofValues) {
if (dfaType.getDfaType().isAssignableFrom(dfaTypeValue)) return false;
if (dfaType.getDfaType().isAssignableFrom(dfaTypeValue)) return null;
}
myNotInstanceofValues.add(dfaType.getDfaType());
return true;
HashSet<DfaPsiType> newNotInstanceof = ContainerUtil.newHashSet(myNotInstanceofValues);
newNotInstanceof.add(dfaType.getDfaType());
return createCopy(myInstanceofValues, newNotInstanceof, myNullability);
}
public int hashCode() {
return myInstanceofValues.hashCode() + myNotInstanceofValues.hashCode();
return (myInstanceofValues.hashCode() * 31 + myNotInstanceofValues.hashCode()) * 31 + myNullability.hashCode();
}
public boolean equals(Object obj) {
if (obj == this) return true;
if (!(obj instanceof DfaVariableState)) return false;
DfaVariableState aState = (DfaVariableState) obj;
return myInstanceofValues.equals(aState.myInstanceofValues) &&
myNotInstanceofValues.equals(aState.myNotInstanceofValues) &&
myNullability == aState.myNullability;
return myNullability == aState.myNullability &&
myInstanceofValues.equals(aState.myInstanceofValues) &&
myNotInstanceofValues.equals(aState.myNotInstanceofValues);
}
@Override
protected DfaVariableState clone() {
return new DfaVariableState(this);
protected DfaVariableState createCopy(Set<DfaPsiType> instanceofValues, Set<DfaPsiType> notInstanceofValues, Nullness nullability) {
return new DfaVariableState(instanceofValues, notInstanceofValues, nullability);
}
public String toString() {
@@ -143,13 +142,16 @@ public class DfaVariableState implements Cloneable {
return myNullability == Nullness.NOT_NULL;
}
public void setNullable(final boolean nullable) {
if (myNullability != Nullness.NOT_NULL) {
myNullability = nullable ? Nullness.NULLABLE : Nullness.UNKNOWN;
}
DfaVariableState withNullability(@NotNull Nullness nullness) {
return myNullability == nullness ? this : createCopy(myInstanceofValues, myNotInstanceofValues, nullness);
}
public void setValue(DfaValue value) {
public DfaVariableState withNullable(final boolean nullable) {
return myNullability != Nullness.NOT_NULL ? withNullability(nullable ? Nullness.NULLABLE : Nullness.UNKNOWN) : this;
}
public DfaVariableState withValue(DfaValue value) {
return this;
}
@Nullable
@@ -80,7 +80,7 @@ class StateMerger {
copy.doFlush(unknownVar, true);
}
if (removedState.isNull(var)) {
copy.getVariableState(var).setNullable(true);
copy.setVariableState(var, copy.getVariableState(var).withNullability(Nullness.NULLABLE));
}
}
@@ -172,11 +172,10 @@ class StateMerger {
private static MultiMap<DfaVariableValue, DfaValue> getDistinctsMap(DfaMemoryStateImpl state) {
MultiMap<DfaVariableValue, DfaValue> distincts = new MultiMap<DfaVariableValue, DfaValue>();
for (Set<EqClass> classPair : state.getDistinctClassPairs()) {
EqClass[] array = classPair.toArray(new EqClass[classPair.size()]);
for (DfaValue value1 : array[0].getMemberValues()) {
for (UnorderedPair<EqClass> classPair : state.getDistinctClassPairs()) {
for (DfaValue value1 : classPair.first.getMemberValues()) {
value1 = DfaMemoryStateImpl.unwrap(value1);
for (DfaValue value2 : array[1].getMemberValues()) {
for (DfaValue value2 : classPair.second.getMemberValues()) {
value2 = DfaMemoryStateImpl.unwrap(value2);
if (value1 instanceof DfaVariableValue) {
if (value2 instanceof DfaVariableValue || value2 instanceof DfaConstValue) {
@@ -16,10 +16,14 @@
package com.intellij.codeInspection.dataFlow;
import com.intellij.codeInspection.dataFlow.value.DfaPsiType;
import com.intellij.codeInspection.dataFlow.value.DfaValue;
import com.intellij.codeInspection.dataFlow.value.DfaValueFactory;
import com.intellij.codeInspection.dataFlow.value.DfaVariableValue;
import com.intellij.psi.PsiExpression;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
/**
* @author Gregory.Shrago
@@ -36,9 +40,13 @@ public class ValuableDataFlowRunner extends DataFlowRunner {
super(factory);
}
MyDfaMemoryState(DfaMemoryStateImpl toCopy) {
super(toCopy);
}
@Override
protected DfaMemoryStateImpl createNew() {
return new MyDfaMemoryState(getFactory());
public DfaMemoryStateImpl createCopy() {
return new MyDfaMemoryState(this);
}
@Override
@@ -49,21 +57,37 @@ public class ValuableDataFlowRunner extends DataFlowRunner {
}
static class ValuableDfaVariableState extends DfaVariableState {
DfaValue myValue;
PsiExpression myExpression;
final DfaValue myValue;
final PsiExpression myExpression;
private ValuableDfaVariableState(final DfaVariableValue psiVariable) {
super(psiVariable);
myValue = null;
myExpression = null;
}
protected ValuableDfaVariableState(final ValuableDfaVariableState state) {
super(state);
myExpression = state.myExpression;
private ValuableDfaVariableState(Set<DfaPsiType> instanceofValues,
Set<DfaPsiType> notInstanceofValues,
Nullness nullability, DfaValue value, PsiExpression expression) {
super(instanceofValues, notInstanceofValues, nullability);
myValue = value;
myExpression = expression;
}
@Override
public void setValue(final DfaValue value) {
myValue = value;
protected DfaVariableState createCopy(Set<DfaPsiType> instanceofValues, Set<DfaPsiType> notInstanceofValues, Nullness nullability) {
return new ValuableDfaVariableState(instanceofValues, notInstanceofValues, nullability, myValue, myExpression);
}
@Override
public DfaVariableState withValue(@Nullable final DfaValue value) {
if (value == myValue) return this;
return new ValuableDfaVariableState(myInstanceofValues, myNotInstanceofValues, myNullability, value, myExpression);
}
public ValuableDfaVariableState withExpression(@Nullable final PsiExpression expression) {
if (expression == myExpression) return this;
return new ValuableDfaVariableState(myInstanceofValues, myNotInstanceofValues, myNullability, myValue, expression);
}
@Override
@@ -72,8 +96,25 @@ public class ValuableDataFlowRunner extends DataFlowRunner {
}
@Override
protected ValuableDfaVariableState clone() {
return new ValuableDfaVariableState(this);
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ValuableDfaVariableState)) return false;
if (!super.equals(o)) return false;
ValuableDfaVariableState state = (ValuableDfaVariableState)o;
if (myExpression != null ? !myExpression.equals(state.myExpression) : state.myExpression != null) return false;
if (myValue != null ? !myValue.equals(state.myValue) : state.myValue != null) return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (myValue != null ? myValue.hashCode() : 0);
result = 31 * result + (myExpression != null ? myExpression.hashCode() : 0);
return result;
}
}
}
@@ -74,6 +74,9 @@ public class DfaVariableValue extends DfaValue {
return value.myDependents;
}
public Iterable<? extends DfaVariableValue> getAllVariables() {
return myExistingVars.values();
}
}
private final PsiModifierListOwner myVariable;
@@ -623,7 +623,7 @@ public class MagicConstantInspection extends BaseJavaLocalInspectionTool {
params.dataFlowToThis = true;
params.scope = new AnalysisScope(new LocalSearchScope(scope), manager.getProject());
SliceRootNode rootNode = new SliceRootNode(manager.getProject(), new DuplicateMap(), SliceManager.createRootUsage(argument, params));
SliceRootNode rootNode = new SliceRootNode(manager.getProject(), new DuplicateMap(), SliceUsage.createRootUsage(argument, params));
Collection<? extends AbstractTreeNode> children = rootNode.getChildren().iterator().next().getChildren();
for (AbstractTreeNode child : children) {
@@ -107,11 +107,13 @@ public class JavaFileHighlighter extends SyntaxHighlighterBase {
myLanguageLevel = languageLevel;
}
@Override
@NotNull
public Lexer getHighlightingLexer() {
return new JavaHighlightingLexer(myLanguageLevel);
}
@Override
@NotNull
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
return pack(ourMap1.get(tokenType), ourMap2.get(tokenType));
@@ -45,7 +45,7 @@ public class JavaSyntaxHighlighterFactory extends SyntaxHighlighterFactory imple
*/
@Nullable
@Override
public SyntaxHighlighter create(FileType fileType, @Nullable Project project, @Nullable VirtualFile file) {
public SyntaxHighlighter create(@NotNull FileType fileType, @Nullable Project project, @Nullable VirtualFile file) {
if (project != null && file != null) {
PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
if (psiFile instanceof ClsFileImpl) {
@@ -24,6 +24,7 @@ import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;
import com.intellij.psi.xml.XmlElementType;
import com.intellij.psi.xml.XmlTokenType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
@@ -35,7 +36,7 @@ public class JavaIndexPatternBuilder implements IndexPatternBuilder {
@Override
@Nullable
public Lexer getIndexingLexer(final PsiFile file) {
public Lexer getIndexingLexer(@NotNull final PsiFile file) {
if (file instanceof PsiJavaFile && !(file instanceof JspFile)) {
return JavaParserDefinition.createLexer(((PsiJavaFile)file).getLanguageLevel());
}
@@ -44,7 +45,7 @@ public class JavaIndexPatternBuilder implements IndexPatternBuilder {
@Override
@Nullable
public TokenSet getCommentTokenSet(final PsiFile file) {
public TokenSet getCommentTokenSet(@NotNull final PsiFile file) {
if (file instanceof PsiJavaFile && !(file instanceof ServerPageFile)) {
return TokenSet.orSet(StdTokenSets.COMMENT_BIT_SET, XML_COMMENT_BIT_SET, JavaDocTokenType.ALL_JAVADOC_TOKENS, XML_DATA_CHARS);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,13 +32,14 @@ import com.intellij.psi.jsp.JspFile;
import com.intellij.psi.jsp.JspTokenType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;
/**
* @author yole
*/
public class JspIndexPatternBuilder implements IndexPatternBuilder {
@Override
public Lexer getIndexingLexer(final PsiFile file) {
public Lexer getIndexingLexer(@NotNull final PsiFile file) {
if (JspPsiUtil.isInJspFile(file)) {
EditorHighlighter highlighter = null;
@@ -67,7 +68,7 @@ public class JspIndexPatternBuilder implements IndexPatternBuilder {
}
@Override
public TokenSet getCommentTokenSet(final PsiFile file) {
public TokenSet getCommentTokenSet(@NotNull final PsiFile file) {
final JspFile jspFile = JspPsiUtil.getJspFile(file);
TokenSet commentTokens = TokenSet.orSet(JavaIndexPatternBuilder.XML_COMMENT_BIT_SET, StdTokenSets.COMMENT_BIT_SET);
final ParserDefinition parserDefinition =
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import com.intellij.openapi.editor.highlighter.EditorHighlighter;
import com.intellij.openapi.editor.highlighter.HighlighterIterator;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.text.CharSequenceSubSequence;
import org.jetbrains.annotations.NotNull;
/**
* @author Sergey Evdokimov
@@ -38,7 +39,7 @@ public class LexerEditorHighlighterLexer extends LexerBase {
}
@Override
public void start(CharSequence buffer, int startOffset, int endOffset, int state) {
public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int state) {
if (myAlreadyInitializedHighlighter) {
this.buffer = buffer;
start = startOffset;
@@ -75,6 +76,7 @@ public class LexerEditorHighlighterLexer extends LexerBase {
iterator.advance();
}
@NotNull
@Override
public CharSequence getBufferSequence() {
return buffer;
@@ -21,6 +21,7 @@ import com.intellij.openapi.util.TextRange;
import com.intellij.usageView.UsageInfo;
import gnu.trove.THashMap;
import gnu.trove.TObjectHashingStrategy;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
@@ -43,7 +44,7 @@ public class DuplicateMap {
};
private final Map<SliceUsage, SliceNode> myDuplicates = new THashMap<SliceUsage, SliceNode>(USAGE_INFO_EQUALITY);
public SliceNode putNodeCheckDupe(final SliceNode node) {
public SliceNode putNodeCheckDupe(@NotNull final SliceNode node) {
return ApplicationManager.getApplication().runReadAction(new Computable<SliceNode>() {
@Override
public SliceNode compute() {
@@ -15,12 +15,20 @@
*/
package com.intellij.slicer;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
/**
* @author cdr
*/
public interface MyColoredTreeCellRenderer {
void customizeCellRenderer(SliceUsageCellRenderer renderer,
JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus);
void customizeCellRenderer(@NotNull SliceUsageCellRenderer renderer,
@NotNull JTree tree,
Object value,
boolean selected,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus);
}
@@ -33,7 +33,7 @@ public class SliceDereferenceUsage extends SliceUsage {
}
@Override
public void processChildren(Processor<SliceUsage> processor) {
public void processChildren(@NotNull Processor<SliceUsage> processor) {
// no children
}
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.slicer.forward;
package com.intellij.slicer;
import com.intellij.openapi.util.Pair;
import com.intellij.psi.*;
@@ -22,10 +22,6 @@ import com.intellij.psi.search.searches.OverridingMethodsSearch;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.util.MethodSignatureUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.slicer.SliceDereferenceUsage;
import com.intellij.slicer.SliceManager;
import com.intellij.slicer.SliceUsage;
import com.intellij.slicer.SliceUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Processor;
import gnu.trove.THashSet;
@@ -40,7 +36,7 @@ import java.util.Set;
/**
* @author cdr
*/
public class SliceFUtil {
public class SliceForwardUtil {
public static boolean processUsagesFlownFromThe(@NotNull PsiElement element, @NotNull final Processor<SliceUsage> processor, @NotNull final SliceUsage parent) {
Pair<PsiElement, PsiSubstitutor> pair = getAssignmentTarget(element, parent);
if (pair != null) {
@@ -44,8 +44,8 @@ public class SliceLeafValueClassNode extends SliceLeafValueRootNode {
}
@Override
public void customizeCellRenderer(SliceUsageCellRenderer renderer,
JTree tree,
public void customizeCellRenderer(@NotNull SliceUsageCellRenderer renderer,
@NotNull JTree tree,
Object value,
boolean selected,
boolean expanded,
@@ -40,7 +40,7 @@ public class SliceLeafValueRootNode extends SliceNode implements MyColoredTreeCe
public SliceLeafValueRootNode(@NotNull Project project, PsiElement leafExpression, SliceNode root, List<SliceNode> children,
SliceAnalysisParams params) {
super(project, new SliceUsage(leafExpression, params), root.targetEqualUsages);
super(project, SliceUsage.createRootUsage(leafExpression, params), root.targetEqualUsages);
myCachedChildren = children;
}
@@ -69,8 +69,8 @@ public class SliceLeafValueRootNode extends SliceNode implements MyColoredTreeCe
}
@Override
public void customizeCellRenderer(SliceUsageCellRenderer renderer,
JTree tree,
public void customizeCellRenderer(@NotNull SliceUsageCellRenderer renderer,
@NotNull JTree tree,
Object value,
boolean selected,
boolean expanded,
@@ -99,8 +99,9 @@ public class SliceLeafValueRootNode extends SliceNode implements MyColoredTreeCe
@NotNull final SliceUsageCellRenderer renderer) {
PsiFile file = element.getContainingFile();
List<TextChunk> result = new ArrayList<TextChunk>();
ChunkExtractor.getExtractor(element.getContainingFile()).createTextChunks(usage, file.getText(), element.getTextRange().getStartOffset(), element.getTextRange().getEndOffset(),
false, result);
ChunkExtractor.getExtractor(element.getContainingFile())
.createTextChunks(usage, file.getText(), element.getTextRange().getStartOffset(), element.getTextRange().getEndOffset(),
false, result);
for (TextChunk chunk : result) {
renderer.append(chunk.getText(), chunk.getSimpleAttributesIgnoreBackground());
@@ -124,7 +124,7 @@ public class SliceManager implements PersistentStateComponent<SliceManager.Store
SliceAnalysisParams params = handler.askForParams(element, dataFlowToThis, myStoredSettings, dialogTitle);
if (params == null) return;
SliceRootNode rootNode = new SliceRootNode(myProject, new DuplicateMap(), createRootUsage(element, params));
SliceRootNode rootNode = new SliceRootNode(myProject, new DuplicateMap(), SliceUsage.createRootUsage(element, params));
createToolWindow(dataFlowToThis, rootNode, false, getElementDescription(null, element, null));
}
@@ -179,10 +179,6 @@ public class SliceManager implements PersistentStateComponent<SliceManager.Store
"</body></html>";
}
public static SliceUsage createRootUsage(@NotNull PsiElement element, @NotNull SliceAnalysisParams params) {
return new SliceUsage(element, params);
}
public void checkCanceled() throws ProcessCanceledException {
if (myCanceled) {
throw new ProcessCanceledException();
@@ -20,7 +20,6 @@ import com.intellij.ide.util.treeView.AbstractTreeNode;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.impl.ProgressManagerImpl;
import com.intellij.openapi.progress.util.ProgressIndicatorBase;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
@@ -52,6 +51,7 @@ public class SliceNode extends AbstractTreeNode<SliceUsage> implements Duplicate
this.targetEqualUsages = targetEqualUsages;
}
@NotNull
SliceNode copy() {
SliceUsage newUsage = getValue().copy();
SliceNode newNode = new SliceNode(getProject(), newUsage, targetEqualUsages);
@@ -69,7 +69,7 @@ public class SliceNode extends AbstractTreeNode<SliceUsage> implements Duplicate
indicator.start();
}
final Collection[] nodes = new Collection[1];
((ProgressManagerImpl)ProgressManager.getInstance()).executeProcessUnderProgress(new Runnable(){
ProgressManager.getInstance().executeProcessUnderProgress(new Runnable() {
@Override
public void run() {
nodes[0] = getChildrenUnderProgress(ProgressManager.getInstance().getProgressIndicator());
@@ -89,6 +89,7 @@ public class SliceNode extends AbstractTreeNode<SliceUsage> implements Duplicate
return index == 0 ? null : (SliceNode)parentChildren.get(index - 1);
}
@NotNull
protected List<? extends AbstractTreeNode> getChildrenUnderProgress(ProgressIndicator progress) {
if (isUpToDate()) return myCachedChildren == null ? Collections.<AbstractTreeNode>emptyList() : myCachedChildren;
final List<SliceNode> children = new ArrayList<SliceNode>();
@@ -208,7 +209,7 @@ public class SliceNode extends AbstractTreeNode<SliceUsage> implements Duplicate
}
@Override
public void customizeCellRenderer(SliceUsageCellRenderer renderer, JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
public void customizeCellRenderer(@NotNull SliceUsageCellRenderer renderer, @NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
renderer.setIcon(getPresentation().getIcon(expanded));
if (isValid()) {
SliceUsage sliceUsage = getValue();
@@ -227,6 +228,7 @@ public class SliceNode extends AbstractTreeNode<SliceUsage> implements Duplicate
@Override
public String toString() {
return ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
public String compute() {
return getValue()==null?"<null>":getValue().toString();
}
@@ -189,13 +189,13 @@ public abstract class SlicePanel extends JPanel implements TypeSafeDataProvider,
@NotNull
private JTree createTree() {
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
final Tree tree = new Tree(new DefaultTreeModel(root)){
final Tree tree = new Tree(new DefaultTreeModel(root))/* {
@Override
protected void paintComponent(Graphics g) {
DuplicateNodeRenderer.paintDuplicateNodesBackground(g, this);
super.paintComponent(g);
}
};
}*/;
tree.setOpaque(false);
tree.setToggleClickCount(-1);
@@ -33,7 +33,7 @@ public class SliceRootNode extends SliceNode {
private final SliceUsage myRootUsage;
public SliceRootNode(@NotNull Project project, @NotNull DuplicateMap targetEqualUsages, final SliceUsage rootUsage) {
super(project, new SliceUsage(rootUsage.getElement().getContainingFile(), rootUsage.params), targetEqualUsages);
super(project, SliceUsage.createRootUsage(rootUsage.getElement().getContainingFile(), rootUsage.params), targetEqualUsages);
myRootUsage = rootUsage;
}
@@ -42,6 +42,7 @@ public class SliceRootNode extends SliceNode {
myCachedChildren = Collections.singletonList(node);
}
@NotNull
@Override
SliceRootNode copy() {
SliceUsage newUsage = getValue().copy();
@@ -60,6 +61,7 @@ public class SliceRootNode extends SliceNode {
return myCachedChildren;
}
@NotNull
@Override
public List<? extends AbstractTreeNode> getChildrenUnderProgress(ProgressIndicator progress) {
return (List<? extends AbstractTreeNode>)getChildren();
@@ -80,8 +82,8 @@ public class SliceRootNode extends SliceNode {
@Override
public void customizeCellRenderer(SliceUsageCellRenderer renderer,
JTree tree,
public void customizeCellRenderer(@NotNull SliceUsageCellRenderer renderer,
@NotNull JTree tree,
Object value,
boolean selected,
boolean expanded,
@@ -37,7 +37,7 @@ public class SliceTooComplexDFAUsage extends SliceUsage {
}
@Override
public void processChildren(Processor<SliceUsage> processor) {
public void processChildren(@NotNull Processor<SliceUsage> processor) {
// no children
}
@@ -21,7 +21,6 @@ import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiSubstitutor;
import com.intellij.slicer.forward.SliceFUtil;
import com.intellij.usageView.UsageInfo;
import com.intellij.usages.UsageInfo2UsageAdapter;
import com.intellij.util.CommonProcessors;
@@ -44,14 +43,18 @@ public class SliceUsage extends UsageInfo2UsageAdapter {
params = parent.params;
assert params != null;
}
public SliceUsage(@NotNull PsiElement element, @NotNull SliceAnalysisParams params) {
private SliceUsage(@NotNull PsiElement element, @NotNull SliceAnalysisParams params) {
super(new UsageInfo(element));
myParent = null;
this.params = params;
mySubstitutor = PsiSubstitutor.EMPTY;
}
public void processChildren(Processor<SliceUsage> processor) {
public static SliceUsage createRootUsage(@NotNull PsiElement element, @NotNull SliceAnalysisParams params) {
return new SliceUsage(element, params);
}
public void processChildren(@NotNull Processor<SliceUsage> processor) {
final PsiElement element = getElement();
ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
indicator.checkCanceled();
@@ -76,7 +79,7 @@ public class SliceUsage extends UsageInfo2UsageAdapter {
SliceUtil.processUsagesFlownDownTo(element, uniqueProcessor, SliceUsage.this, mySubstitutor);
}
else {
SliceFUtil.processUsagesFlownFromThe(element, uniqueProcessor, SliceUsage.this);
SliceForwardUtil.processUsagesFlownFromThe(element, uniqueProcessor, SliceUsage.this);
}
}
});
@@ -93,7 +96,7 @@ public class SliceUsage extends UsageInfo2UsageAdapter {
SliceUsage copy() {
PsiElement element = getUsageInfo().getElement();
return getParent() == null ? new SliceUsage(element, params) : new SliceUsage(element, getParent(),mySubstitutor);
return getParent() == null ? createRootUsage(element, params) : new SliceUsage(element, getParent(),mySubstitutor);
}
public PsiSubstitutor getSubstitutor() {
@@ -18,12 +18,14 @@ package com.intellij.slicer;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiFormatUtil;
import com.intellij.psi.util.PsiFormatUtilBase;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.usageView.UsageTreeColors;
import com.intellij.usageView.UsageTreeColorsScheme;
import com.intellij.usages.TextChunk;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
@@ -41,7 +43,7 @@ public class SliceUsageCellRenderer extends ColoredTreeCellRenderer {
}
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
assert value instanceof DefaultMutableTreeNode;
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode)value;
Object userObject = treeNode.getUserObject();
@@ -58,7 +60,7 @@ public class SliceUsageCellRenderer extends ColoredTreeCellRenderer {
}
}
public void customizeCellRendererFor(SliceUsage sliceUsage) {
public void customizeCellRendererFor(@NotNull SliceUsage sliceUsage) {
boolean isForcedLeaf = sliceUsage instanceof SliceDereferenceUsage;
TextChunk[] text = sliceUsage.getPresentation().getText();
@@ -83,12 +85,10 @@ public class SliceUsageCellRenderer extends ColoredTreeCellRenderer {
break;
}
}
int methodOptions = PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS | PsiFormatUtilBase.SHOW_CONTAINING_CLASS;
String location = method != null
? PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME |
PsiFormatUtil.SHOW_PARAMETERS |
PsiFormatUtil.SHOW_CONTAINING_CLASS,
PsiFormatUtil.SHOW_TYPE, 2)
: aClass != null ? PsiFormatUtil.formatClass(aClass, PsiFormatUtil.SHOW_NAME) : null;
? PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, methodOptions, PsiFormatUtilBase.SHOW_TYPE, 2)
: aClass != null ? PsiFormatUtil.formatClass(aClass, PsiFormatUtilBase.SHOW_NAME) : null;
if (location != null) {
SimpleTextAttributes attributes = SimpleTextAttributes.GRAY_ATTRIBUTES;
append(" in " + location, attributes);
@@ -30,7 +30,6 @@ import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.MethodSignatureUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.slicer.forward.SliceFUtil;
import com.intellij.util.ArrayUtilRt;
import com.intellij.util.Processor;
import gnu.trove.THashMap;
@@ -54,7 +53,7 @@ public class SliceUtil {
expression = simplify(expression);
PsiElement original = expression;
if (expression instanceof PsiReferenceExpression) {
PsiElement element = SliceFUtil.complexify(expression);
PsiElement element = SliceForwardUtil.complexify(expression);
if (element instanceof PsiExpression && PsiUtil.isOnAssignmentLeftHand((PsiExpression)element)) {
PsiExpression rightSide = ((PsiAssignmentExpression)element.getParent()).getRExpression();
return rightSide == null || handToProcessor(rightSide, processor, parent, parentSubstitutor);
@@ -238,9 +237,12 @@ public class SliceUtil {
});
}
@NotNull
public static SliceUsage createSliceUsage(@NotNull PsiElement element, @NotNull SliceUsage parent, @NotNull PsiSubstitutor substitutor) {
return new SliceUsage(simplify(element), parent, substitutor);
}
@NotNull
public static SliceUsage createTooComplexDFAUsage(@NotNull PsiElement element, @NotNull SliceUsage parent, @NotNull PsiSubstitutor substitutor) {
return new SliceTooComplexDFAUsage(simplify(element), parent, substitutor);
}
@@ -122,7 +122,7 @@ public class UsageContextDataflowToPanel extends UsageContextPanelBase {
ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.FIND);
SliceAnalysisParams params = createParams(element, dataFlowToThis);
SliceRootNode rootNode = new SliceRootNode(myProject, new DuplicateMap(), SliceManager.createRootUsage(element, params));
SliceRootNode rootNode = new SliceRootNode(myProject, new DuplicateMap(), SliceUsage.createRootUsage(element, params));
return new SlicePanel(myProject, dataFlowToThis, rootNode, false, toolWindow) {
@Override
@@ -35,4 +35,6 @@ public interface PsiMethodReferenceExpression extends PsiReferenceExpression {
*/
@Nullable
PsiType getFunctionalInterfaceType();
boolean isExact();
}
@@ -54,7 +54,7 @@ public class JavaDocLexer extends MergingLexerAdapter {
}
@Override
public final void start(CharSequence buffer, int startOffset, int endOffset, int initialState) {
public final void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) {
myBuffer = buffer;
myBufferIndex = startOffset;
myBufferEndOffset = endOffset;
@@ -68,6 +68,7 @@ public class JavaDocLexer extends MergingLexerAdapter {
return myState;
}
@NotNull
@Override
public CharSequence getBufferSequence() {
return myBuffer;
@@ -175,7 +175,7 @@ public class JavaLexer extends LexerBase {
}
@Override
public final void start(CharSequence buffer, int startOffset, int endOffset, int initialState) {
public final void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) {
myBuffer = buffer;
myBufferArray = CharArrayUtil.fromSequenceWithoutCopying(buffer);
myBufferIndex = startOffset;
@@ -417,6 +417,7 @@ public class JavaLexer extends LexerBase {
return pos;
}
@NotNull
@Override
public CharSequence getBufferSequence() {
return myBuffer;
@@ -0,0 +1,92 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.psi.impl.source.resolve.graphInference;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.resolve.graphInference.constraints.TypeEqualityConstraint;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class FunctionalInterfaceParameterizationUtil {
private static final Logger LOG = Logger.getInstance("#" + FunctionalInterfaceParameterizationUtil.class.getName());
public static boolean isWildcardParameterized(@Nullable PsiType classType) {
if (classType == null) return false;
if (classType instanceof PsiIntersectionType) {
for (PsiType type : ((PsiIntersectionType)classType).getConjuncts()) {
if (!isWildcardParameterized(type)) return false;
}
}
if (classType instanceof PsiClassType) {
for (PsiType type : ((PsiClassType)classType).getParameters()) {
if (type instanceof PsiWildcardType || type instanceof PsiCapturedWildcardType) {
return true;
}
}
return false;
}
LOG.error("Unexpected type: " + classType);
return false;
}
@Nullable
public static PsiType getFunctionalType(@Nullable PsiType psiClassType, PsiLambdaExpression expr) {
if (!expr.hasFormalParameterTypes()) return psiClassType;
if (!isWildcardParameterized(psiClassType)) {
return psiClassType;
}
final PsiParameter[] lambdaParams = expr.getParameterList().getParameters();
if (psiClassType instanceof PsiIntersectionType) {
for (PsiType psiType : ((PsiIntersectionType)psiClassType).getConjuncts()) {
final PsiType functionalType = getFunctionalType(psiType, expr);
if (functionalType != null) return functionalType;
}
return null;
}
LOG.assertTrue(psiClassType instanceof PsiClassType, "Unexpected type: " + psiClassType);
final PsiType[] parameters = ((PsiClassType)psiClassType).getParameters();
final PsiClassType.ClassResolveResult resolveResult = ((PsiClassType)psiClassType).resolveGenerics();
PsiClass psiClass = resolveResult.getElement();
if (psiClass != null) {
final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(resolveResult);
if (interfaceMethod == null) return null;
final InferenceSession session = new InferenceSession(PsiSubstitutor.EMPTY);
PsiTypeParameter[] typeParameters = psiClass.getTypeParameters();
if (typeParameters.length != parameters.length) {
return null;
}
for (int i = 0; i < typeParameters.length; i++) {
session.addVariable(typeParameters[i], parameters[i]);
}
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(psiClass.getProject());
final PsiParameter[] targetMethodParams = interfaceMethod.getParameterList().getParameters();
for (int i = 0; i < targetMethodParams.length; i++) {
session.addConstraint(new TypeEqualityConstraint(lambdaParams[i].getType(), targetMethodParams[i].getType()));
}
final PsiClassType parameterization = elementFactory.createType(psiClass, session.infer());
if (!isWildcardParameterized(parameterization)) return parameterization;
}
return null;
}
}
@@ -19,6 +19,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Pair;
import com.intellij.psi.*;
import com.intellij.psi.impl.PsiImplUtil;
import com.intellij.psi.impl.source.resolve.graphInference.constraints.CheckedExceptionCompatibilityConstraint;
import com.intellij.psi.impl.source.resolve.graphInference.constraints.ConstraintFormula;
import com.intellij.psi.impl.source.resolve.graphInference.constraints.ExpressionCompatibilityConstraint;
import com.intellij.psi.impl.source.resolve.graphInference.constraints.TypeCompatibilityConstraint;
@@ -40,7 +41,6 @@ public class InferenceSession {
private Map<PsiTypeParameter, InferenceVariable> myInferenceVariables = new LinkedHashMap<PsiTypeParameter, InferenceVariable>();
private final List<ConstraintFormula> myConstraints = new ArrayList<ConstraintFormula>();
private final List<ConstraintFormula> myDelayedConstraints = new ArrayList<ConstraintFormula>();
private PsiSubstitutor mySiteSubstitutor;
private PsiManager myManager;
@@ -48,6 +48,10 @@ public class InferenceSession {
private final InferenceIncorporationPhase myIncorporationPhase = new InferenceIncorporationPhase(this);
public InferenceSession(PsiSubstitutor siteSubstitutor) {
mySiteSubstitutor = siteSubstitutor;
}
public InferenceSession(PsiTypeParameter[] typeParams,
PsiType[] leftTypes,
PsiType[] rightTypes,
@@ -80,6 +84,7 @@ public class InferenceSession {
PsiType parameterType = getParameterType(parameters, args, i, mySiteSubstitutor);
if (args[i] != null) {
myConstraints.add(new ExpressionCompatibilityConstraint(args[i], parameterType));
//myConstraints.add(new CheckedExceptionCompatibilityConstraint(args[i], parameterType));
}
}
}
@@ -275,7 +280,7 @@ public class InferenceSession {
List<ConstraintFormula> newConstraints = new ArrayList<ConstraintFormula>();
for (int i = myConstraintIdx; i < myConstraints.size(); i++) {
ConstraintFormula constraint = myConstraints.get(i);
if (!constraint.reduce(this, newConstraints, myDelayedConstraints)) {
if (!constraint.reduce(this, newConstraints)) {
return false;
}
}
@@ -384,4 +389,20 @@ public class InferenceSession {
public Collection<PsiTypeParameter> getTypeParams() {
return myInferenceVariables.keySet();
}
public void addVariable(PsiTypeParameter typeParameter, final PsiType parameter) {
InferenceVariable variable = new InferenceVariable(typeParameter);
if (parameter instanceof PsiWildcardType) {
PsiType bound = ((PsiWildcardType)parameter).getBound();
if (bound != null) {
variable.addBound(bound, ((PsiWildcardType)parameter).isExtends() ? InferenceBound.UPPER : InferenceBound.LOWER);
} else {
variable.addBound(PsiType.getJavaLangObject(typeParameter.getManager(), parameter.getResolveScope()),
InferenceBound.UPPER);
}
} else {
variable.addBound(parameter, InferenceBound.EQ);
}
myInferenceVariables.put(typeParameter, variable);
}
}
@@ -20,7 +20,6 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession;
import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil;
import com.intellij.psi.impl.source.resolve.graphInference.constraints.ConstraintFormula;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.util.Function;
@@ -43,7 +42,7 @@ public class CheckedExceptionCompatibilityConstraint implements ConstraintFormul
}
@Override
public boolean reduce(InferenceSession session, List<ConstraintFormula> constraints, List<ConstraintFormula> delayedConstraints) {
public boolean reduce(InferenceSession session, List<ConstraintFormula> constraints) {
if (!PsiPolyExpressionUtil.isPolyExpression(myExpression) ||
myExpression instanceof PsiCallExpression) {
return true;
@@ -23,5 +23,5 @@ import java.util.List;
* User: anna
*/
public interface ConstraintFormula {
boolean reduce(InferenceSession session, List<ConstraintFormula> constraints, List<ConstraintFormula> delayedConstraints);
boolean reduce(InferenceSession session, List<ConstraintFormula> constraints);
}
@@ -40,7 +40,7 @@ public class ExpressionCompatibilityConstraint implements ConstraintFormula {
}
@Override
public boolean reduce(InferenceSession session, List<ConstraintFormula> constraints, List<ConstraintFormula> delayedConstraints) {
public boolean reduce(InferenceSession session, List<ConstraintFormula> constraints) {
if (session.isProperType(myT)) {
return TypeConversionUtil.areTypesAssignmentCompatible(myT, myExpression);
}
@@ -1,8 +1,8 @@
package com.intellij.psi.impl.source.resolve.graphInference.constraints;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.resolve.graphInference.FunctionalInterfaceParameterizationUtil;
import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession;
import com.intellij.psi.impl.source.resolve.graphInference.InferenceVariable;
import com.intellij.psi.util.PsiUtil;
import java.util.List;
@@ -20,30 +20,21 @@ public class LambdaExpressionCompatibilityConstraint implements ConstraintFormul
}
@Override
public boolean reduce(InferenceSession session, List<ConstraintFormula> constraints, List<ConstraintFormula> delayedConstraints) {
final InferenceVariable inferenceVariable = session.getInferenceVariable(myT);
if (inferenceVariable != null) {
delayedConstraints.add(this);
return true;
}
public boolean reduce(InferenceSession session, List<ConstraintFormula> constraints) {
if (LambdaHighlightingUtil.checkInterfaceFunctional(myT) != null) {
return false;
}
if (myExpression.hasFormalParameterTypes()) {
}
final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(myT);
final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(
FunctionalInterfaceParameterizationUtil.getFunctionalType(myT, myExpression));
final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(resolveResult);
if (interfaceMethod == null) {
return false;
}
final PsiSubstitutor substitutor = LambdaUtil.getSubstitutor(interfaceMethod, PsiUtil.resolveGenericsClassInType(myT));
final PsiSubstitutor substitutor = LambdaUtil.getSubstitutor(interfaceMethod, resolveResult);
final PsiParameter[] parameters = interfaceMethod.getParameterList().getParameters();
for (PsiParameter parameter : parameters) {
if (!session.isProperType(substitutor.substitute(parameter.getType()))) {
delayedConstraints.add(this);
return true;
}
}
final PsiParameter[] lambdaParameters = myExpression.getParameterList().getParameters();
if (lambdaParameters.length != parameters.length) {
@@ -53,20 +44,27 @@ public class LambdaExpressionCompatibilityConstraint implements ConstraintFormul
for (int i = 0; i < lambdaParameters.length; i++) {
constraints.add(new TypeEqualityConstraint(lambdaParameters[i].getType(), substitutor.substitute(parameters[i].getType())));
}
} else {
for (PsiParameter parameter : parameters) {
if (!session.isProperType(substitutor.substitute(parameter.getType()))) {
return false;
}
}
}
final PsiType returnType = interfaceMethod.getReturnType();
if (returnType != null) {
final List<PsiExpression> returnExpressions = LambdaUtil.getReturnExpressions(myExpression);
if (returnType.equals(PsiType.VOID)) {
if (!myExpression.isVoidCompatible() && !(myExpression.getBody() instanceof PsiExpression)) {
if (!returnExpressions.isEmpty() && !(myExpression.getBody() instanceof PsiExpression)) {
return false;
}
} else {
if (myExpression.isVoidCompatible()) { //not value-compatible
if (returnExpressions.isEmpty()) { //not value-compatible
return false;
}
for (PsiExpression returnExpressions : LambdaUtil.getReturnExpressions(myExpression)) {
constraints.add(new ExpressionCompatibilityConstraint(returnExpressions, substitutor.substitute(returnType)));
for (PsiExpression returnExpression : returnExpressions) {
constraints.add(new ExpressionCompatibilityConstraint(returnExpression, substitutor.substitute(returnType)));
}
}
}
@@ -40,12 +40,7 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm
}
@Override
public boolean reduce(InferenceSession session, List<ConstraintFormula> constraints, List<ConstraintFormula> delayedConstraints) {
final InferenceVariable inferenceVariable = session.getInferenceVariable(myT);
if (inferenceVariable != null) {
delayedConstraints.add(this);
return true;
}
public boolean reduce(InferenceSession session, List<ConstraintFormula> constraints) {
if (LambdaHighlightingUtil.checkInterfaceFunctional(myT) != null) {
return false;
}
@@ -59,8 +54,7 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm
final PsiParameter[] parameters = interfaceMethod.getParameterList().getParameters();
for (PsiParameter parameter : parameters) {
if (!session.isProperType(substitutor.substitute(parameter.getType()))) {
delayedConstraints.add(this);
return true;
return false;
}
}
@@ -20,7 +20,6 @@ import com.intellij.psi.impl.source.resolve.graphInference.InferenceBound;
import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession;
import com.intellij.psi.impl.source.resolve.graphInference.InferenceVariable;
import com.intellij.psi.util.TypeConversionUtil;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -39,7 +38,7 @@ public class SubtypingConstraint implements ConstraintFormula {
}
@Override
public boolean reduce(InferenceSession session, List<ConstraintFormula> constraints, List<ConstraintFormula> delayedConstraints) {
public boolean reduce(InferenceSession session, List<ConstraintFormula> constraints) {
if (myIsRefTypes) {
if (session.isProperType(myS) && session.isProperType(myT)) {
if (myT == null || myS == null) return myS == myT;
@@ -37,7 +37,7 @@ public class TypeCompatibilityConstraint implements ConstraintFormula {
}
@Override
public boolean reduce(InferenceSession session, List<ConstraintFormula> constraints, List<ConstraintFormula> delayedConstraints) {
public boolean reduce(InferenceSession session, List<ConstraintFormula> constraints) {
if (session.isProperType(myT) && session.isProperType(myS)) {
return TypeConversionUtil.isAssignable(myS, myT);
}
@@ -38,7 +38,7 @@ public class TypeEqualityConstraint implements ConstraintFormula {
}
@Override
public boolean reduce(InferenceSession session, List<ConstraintFormula> constraints, List<ConstraintFormula> delayedConstraints) {
public boolean reduce(InferenceSession session, List<ConstraintFormula> constraints) {
if (session.isProperType(myT) && session.isProperType(myS)) {
return myT.equals(myS);
}
@@ -18,24 +18,23 @@ package com.intellij.psi.impl.source.tree.java;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.Constants;
import com.intellij.psi.impl.source.tree.*;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ChildRoleBase;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.CharTable;
import org.jetbrains.annotations.NotNull;
public class PsiArrayInitializerExpressionImpl extends ExpressionPsiElement implements PsiArrayInitializerExpression, Constants {
public class PsiArrayInitializerExpressionImpl extends ExpressionPsiElement implements PsiArrayInitializerExpression {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.java.PsiArrayInitializerExpressionImpl");
public PsiArrayInitializerExpressionImpl() {
super(ARRAY_INITIALIZER_EXPRESSION);
super(JavaElementType.ARRAY_INITIALIZER_EXPRESSION);
}
@Override
@NotNull
public PsiExpression[] getInitializers(){
return getChildrenAsPsiElements(EXPRESSION_BIT_SET, PsiExpression.ARRAY_FACTORY);
return getChildrenAsPsiElements(ElementType.EXPRESSION_BIT_SET, PsiExpression.ARRAY_FACTORY);
}
@Override
@@ -69,10 +68,10 @@ public class PsiArrayInitializerExpressionImpl extends ExpressionPsiElement impl
return null;
case ChildRole.LBRACE:
return findChildByType(LBRACE);
return findChildByType(JavaTokenType.LBRACE);
case ChildRole.RBRACE:
return findChildByType(RBRACE);
return findChildByType(JavaTokenType.RBRACE);
}
}
@@ -80,17 +79,17 @@ public class PsiArrayInitializerExpressionImpl extends ExpressionPsiElement impl
public int getChildRole(ASTNode child) {
LOG.assertTrue(child.getTreeParent() == this);
IElementType i = child.getElementType();
if (i == COMMA) {
if (i == JavaTokenType.COMMA) {
return ChildRole.COMMA;
}
else if (i == LBRACE) {
else if (i == JavaTokenType.LBRACE) {
return ChildRole.LBRACE;
}
else if (i == RBRACE) {
else if (i == JavaTokenType.RBRACE) {
return ChildRole.RBRACE;
}
else {
if (EXPRESSION_BIT_SET.contains(child.getElementType())) {
if (ElementType.EXPRESSION_BIT_SET.contains(child.getElementType())) {
return ChildRole.EXPRESSION_IN_LIST;
}
return ChildRoleBase.NONE;
@@ -129,17 +128,17 @@ public class PsiArrayInitializerExpressionImpl extends ExpressionPsiElement impl
if (ElementType.EXPRESSION_BIT_SET.contains(first.getElementType())) {
final CharTable charTab = SharedImplUtil.findCharTableByTree(this);
for (ASTNode child = first.getTreeNext(); child != null; child = child.getTreeNext()) {
if (child.getElementType() == COMMA) break;
if (child.getElementType() == JavaTokenType.COMMA) break;
if (ElementType.EXPRESSION_BIT_SET.contains(child.getElementType())) {
TreeElement comma = Factory.createSingleLeafElement(COMMA, ",", 0, 1, charTab, getManager());
TreeElement comma = Factory.createSingleLeafElement(JavaTokenType.COMMA, ",", 0, 1, charTab, getManager());
super.addInternal(comma, comma, first, Boolean.FALSE);
break;
}
}
for (ASTNode child = first.getTreePrev(); child != null; child = child.getTreePrev()) {
if (child.getElementType() == COMMA) break;
if (child.getElementType() == JavaTokenType.COMMA) break;
if (ElementType.EXPRESSION_BIT_SET.contains(child.getElementType())) {
TreeElement comma = Factory.createSingleLeafElement(COMMA, ",", 0, 1, charTab, getManager());
TreeElement comma = Factory.createSingleLeafElement(JavaTokenType.COMMA, ",", 0, 1, charTab, getManager());
super.addInternal(comma, comma, child, Boolean.FALSE);
break;
}
@@ -19,6 +19,7 @@ import com.intellij.lang.ASTNode;
import com.intellij.psi.*;
import com.intellij.psi.controlFlow.*;
import com.intellij.psi.impl.PsiImplUtil;
import com.intellij.psi.impl.source.resolve.graphInference.FunctionalInterfaceParameterizationUtil;
import com.intellij.psi.impl.source.tree.ChildRole;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.scope.PsiScopeProcessor;
@@ -63,7 +64,7 @@ public class PsiLambdaExpressionImpl extends ExpressionPsiElement implements Psi
@Nullable
@Override
public PsiType getFunctionalInterfaceType() {
return LambdaUtil.getFunctionalInterfaceType(this, true);
return FunctionalInterfaceParameterizationUtil.getFunctionalType(LambdaUtil.getFunctionalInterfaceType(this, true), this);
}
@Override
@@ -71,6 +71,15 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
return LambdaUtil.getFunctionalInterfaceType(this, true);
}
@Override
public boolean isExact() {
PsiElement resolve = resolve();
if (resolve instanceof PsiMethod) {
return !((PsiMethod)resolve).isVarArgs();
}
return true;
}
@Override
public PsiExpression getQualifierExpression() {
final PsiElement qualifier = getQualifier();
@@ -51,15 +51,15 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.scope.conflictResolvers.JavaMethodsConflictResolver");
private final PsiElement myArgumentsList;
private final PsiType[] myActualParameterTypes;
private PsiType[] myActualParameterTypes;
protected LanguageLevel myLanguageLevel;
public JavaMethodsConflictResolver(@NotNull PsiExpressionList list, @NotNull LanguageLevel languageLevel) {
this(list, list.getExpressionTypes(), languageLevel);
this(list, null, languageLevel);
}
public JavaMethodsConflictResolver(@NotNull PsiElement argumentsList,
@NotNull PsiType[] actualParameterTypes,
PsiType[] actualParameterTypes,
@NotNull LanguageLevel languageLevel) {
myArgumentsList = argumentsList;
myActualParameterTypes = actualParameterTypes;
@@ -71,7 +71,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
if (conflicts.isEmpty()) return null;
if (conflicts.size() == 1) return conflicts.get(0);
boolean atLeastOneMatch = checkParametersNumber(conflicts, myActualParameterTypes.length, true);
boolean atLeastOneMatch = checkParametersNumber(conflicts, getActualParameterTypes().length, true);
if (conflicts.size() == 1) return conflicts.get(0);
checkSameSignatures(conflicts);
@@ -80,7 +80,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
checkAccessStaticLevels(conflicts, true);
if (conflicts.size() == 1) return conflicts.get(0);
checkParametersNumber(conflicts, myActualParameterTypes.length, false);
checkParametersNumber(conflicts, getActualParameterTypes().length, false);
if (conflicts.size() == 1) return conflicts.get(0);
final int applicabilityLevel = checkApplicability(conflicts);
@@ -96,7 +96,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
checkSpecifics(conflicts, applicabilityLevel, myLanguageLevel);
if (conflicts.size() == 1) return conflicts.get(0);
checkPrimitiveVarargs(conflicts, myActualParameterTypes.length);
checkPrimitiveVarargs(conflicts, getActualParameterTypes().length);
if (conflicts.size() == 1) return conflicts.get(0);
checkAccessStaticLevels(conflicts, false);
@@ -109,8 +109,8 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
private void checkLambdaApplicable(@NotNull List<CandidateInfo> conflicts, @NotNull LanguageLevel languageLevel) {
if (!languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) return;
for (int i = 0; i < myActualParameterTypes.length; i++) {
PsiType parameterType = myActualParameterTypes[i];
for (int i = 0; i < getActualParameterTypes().length; i++) {
PsiType parameterType = getActualParameterTypes()[i];
if (parameterType instanceof PsiLambdaExpressionType) {
final PsiLambdaExpression lambdaExpression = ((PsiLambdaExpressionType)parameterType).getExpression();
for (Iterator<CandidateInfo> iterator = conflicts.iterator(); iterator.hasNext(); ) {
@@ -141,7 +141,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
}
}
}
checkMoreSpecificReturnType(conflicts, myActualParameterTypes, languageLevel);
checkMoreSpecificReturnType(conflicts, getActualParameterTypes(), languageLevel);
}
public void checkSpecifics(@NotNull List<CandidateInfo> conflicts,
@@ -426,6 +426,14 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
(method.getCurrentFileResolveScope() instanceof PsiImportStaticStatement ? 0 : 1);
}
private PsiType[] getActualParameterTypes() {
if (myActualParameterTypes == null) {
LOG.assertTrue(myArgumentsList instanceof PsiExpressionList, myArgumentsList);
myActualParameterTypes = ((PsiExpressionList)myArgumentsList).getExpressionTypes();
}
return myActualParameterTypes;
}
private enum Specifics {
FIRST,
SECOND,
@@ -489,7 +497,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
ProgressManager.checkCanceled();
PsiType type1 = classSubstitutor1.substitute(types1[i]);
PsiType type2 = classSubstitutor2.substitute(types2[i]);
PsiType argType = i < myActualParameterTypes.length ? myActualParameterTypes[i] : null;
PsiType argType = i < getActualParameterTypes().length ? getActualParameterTypes()[i] : null;
boolean boxingInFirst = false;
if (isBoxingHappened(argType, type1, languageLevel)) {
@@ -0,0 +1,11 @@
public class Test {
interface Predicate<T> {
boolean test(T t);
}
{
Predicate<? super Integer> p = (Number n) -> n.equals(23);
Predicate<Integer> p1 = (<error descr="Incompatible parameter types in lambda expression">Number n</error>) -> n.equals(23);
Predicate<Number> p2 = (Number n) -> n.equals(23);
}
}
@@ -32,6 +32,6 @@ class ReturnTypeCompatibility {
call((String i)->{ return i;});
call(<error descr="Cyclic inference">i->{ return i;}</error>);
call(<error descr="Cyclic inference">i->""</error>);
call<error descr="'call(ReturnTypeCompatibility.I1<java.lang.Integer>)' in 'ReturnTypeCompatibility' cannot be applied to '(<lambda expression>)'">((int i)->{ return i;})</error>;
call((<error descr="Incompatible parameter types in lambda expression">int i</error>)->{ return i;});
}
}
@@ -384,10 +384,4 @@
<description>Condition &lt;code&gt;i&lt;/code&gt; is always &lt;code&gt;true&lt;/code&gt; when reached</description>
</problem>
<problem>
<file>Test.java</file>
<line>62</line>
<module>testUnboxingNPE_7454908424878253728</module>
<description>Switch label&lt;code&gt;case 0:&lt;/code&gt; is unreachable</description>
</problem>
</problems>
@@ -880,7 +880,9 @@ class Foo {
void foo(int aaa, int aaaaa) { }
void bar(int aaa, int aaaaa) { foo(<caret>) }
} """)
type 'a,'
type 'a'
println myFixture.lookupElementStrings
type ','
assert myFixture.editor.document.text.contains('foo(aaa, )')
}
@@ -92,6 +92,7 @@ public class LambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testFunctionalInterfaceCheck() { doTest();}
public void testUnderscores() { doTest(true);}
public void testReturnTypeAmbiguity() { doTest();}
public void testWildcardsAndFormalLambdaParams() {doTest();}
private void doTest() {
doTest(false);
@@ -31,7 +31,6 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.slicer.SliceAnalysisParams;
import com.intellij.slicer.SliceHandler;
import com.intellij.slicer.SliceManager;
import com.intellij.slicer.SliceUsage;
import com.intellij.util.CommonProcessors;
import com.intellij.util.containers.IntArrayList;
@@ -59,7 +58,7 @@ public class SliceBackwardTest extends DaemonAnalyzerTestCase {
params.scope = new AnalysisScope(getProject());
params.dataFlowToThis = true;
SliceUsage usage = SliceManager.createRootUsage(element, params);
SliceUsage usage = SliceUsage.createRootUsage(element, params);
checkUsages(usage, true, myFlownOffsets);
}
@@ -23,7 +23,6 @@ import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.slicer.SliceAnalysisParams;
import com.intellij.slicer.SliceForwardHandler;
import com.intellij.slicer.SliceManager;
import com.intellij.slicer.SliceUsage;
import com.intellij.util.containers.IntArrayList;
import gnu.trove.TIntObjectHashMap;
@@ -49,7 +48,7 @@ public class SliceForwardTest extends DaemonAnalyzerTestCase {
SliceAnalysisParams params = new SliceAnalysisParams();
params.scope = new AnalysisScope(getProject());
params.dataFlowToThis = false;
SliceUsage usage = SliceManager.createRootUsage(element, params);
SliceUsage usage = SliceUsage.createRootUsage(element, params);
SliceBackwardTest.checkUsages(usage, false, myFlownOffsets);
}
@@ -1,11 +1,9 @@
package com.intellij.codeInsight.slice;
import com.intellij.analysis.AnalysisScope;
import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.ide.util.treeView.AbstractTreeNode;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.wm.impl.ToolWindowHeadlessManagerImpl;
@@ -34,7 +32,7 @@ public class SliceTreeTest extends LightDaemonAnalyzerTestCase {
params.scope = new AnalysisScope(getProject());
params.dataFlowToThis = true;
SliceUsage usage = SliceManager.createRootUsage(element, params);
SliceUsage usage = SliceUsage.createRootUsage(element, params);
SlicePanel panel = new SlicePanel(getProject(), true, new SliceRootNode(getProject(), new DuplicateMap(), usage), false, ToolWindowHeadlessManagerImpl.HEADLESS_WINDOW) {
@@ -252,7 +250,7 @@ public class SliceTreeTest extends LightDaemonAnalyzerTestCase {
}
private static void checkStructure(final SliceNode root, @NonNls String dataExpected) {
List<SliceNode> actualNodes = new ArrayList<SliceNode>((Collection<? extends SliceNode>)root.getChildren());
List<SliceNode> actualNodes = new ArrayList<SliceNode>((Collection)root.getChildren());
Collections.sort(actualNodes, SliceTreeBuilder.SLICE_NODE_COMPARATOR);
Object[] actualStrings = ContainerUtil.map2Array(actualNodes, new Function<SliceNode, Object>() {
@@ -15,6 +15,8 @@
*/
package com.intellij.codeInspection;
import com.intellij.codeInsight.completion.SmartTypeCompletionTest;
import com.intellij.codeInsight.slice.SliceBackwardTest;
import com.intellij.codeInsight.slice.SliceTreeTest;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -25,6 +27,8 @@ public class DataFlowInspectionTestSuite {
suite.addTestSuite(DataFlowInspectionTest.class);
suite.addTestSuite(DataFlowInspectionAncientTest.class);
suite.addTestSuite(SliceTreeTest.class);
suite.addTestSuite(SliceBackwardTest.class);
suite.addTestSuite(SmartTypeCompletionTest.class);
return suite;
}
}
+27 -27
View File
@@ -462,12 +462,7 @@
<item name="java.util.Arrays void sort(short[], int, int) 0">
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name="java.util.Calendar void add(int, int) 0" >
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="intValues" val="{java.util.Calendar.ERA, java.util.Calendar.YEAR, java.util.Calendar.MONTH, java.util.Calendar.WEEK_OF_YEAR, java.util.Calendar.WEEK_OF_MONTH, java.util.Calendar.DATE, java.util.Calendar.DAY_OF_MONTH, java.util.Calendar.DAY_OF_YEAR, java.util.Calendar.DAY_OF_WEEK, java.util.Calendar.DAY_OF_WEEK_IN_MONTH, java.util.Calendar.AM_PM, java.util.Calendar.HOUR, java.util.Calendar.HOUR_OF_DAY, java.util.Calendar.MINUTE, java.util.Calendar.SECOND, java.util.Calendar.MILLISECOND, java.util.Calendar.ZONE_OFFSET, java.util.Calendar.DST_OFFSET}" />
</annotation>
</item>
<item name="java.util.Calendar void clear(int) 0" >
<item name="java.util.Calendar boolean isSet(int) 0">
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="intValues" val="{java.util.Calendar.ERA, java.util.Calendar.YEAR, java.util.Calendar.MONTH, java.util.Calendar.WEEK_OF_YEAR, java.util.Calendar.WEEK_OF_MONTH, java.util.Calendar.DATE, java.util.Calendar.DAY_OF_MONTH, java.util.Calendar.DAY_OF_YEAR, java.util.Calendar.DAY_OF_WEEK, java.util.Calendar.DAY_OF_WEEK_IN_MONTH, java.util.Calendar.AM_PM, java.util.Calendar.HOUR, java.util.Calendar.HOUR_OF_DAY, java.util.Calendar.MINUTE, java.util.Calendar.SECOND, java.util.Calendar.MILLISECOND, java.util.Calendar.ZONE_OFFSET, java.util.Calendar.DST_OFFSET}" />
</annotation>
@@ -487,26 +482,6 @@
<val name="intValues" val="{java.util.Calendar.ERA, java.util.Calendar.YEAR, java.util.Calendar.MONTH, java.util.Calendar.WEEK_OF_YEAR, java.util.Calendar.WEEK_OF_MONTH, java.util.Calendar.DATE, java.util.Calendar.DAY_OF_MONTH, java.util.Calendar.DAY_OF_YEAR, java.util.Calendar.DAY_OF_WEEK, java.util.Calendar.DAY_OF_WEEK_IN_MONTH, java.util.Calendar.AM_PM, java.util.Calendar.HOUR, java.util.Calendar.HOUR_OF_DAY, java.util.Calendar.MINUTE, java.util.Calendar.SECOND, java.util.Calendar.MILLISECOND, java.util.Calendar.ZONE_OFFSET, java.util.Calendar.DST_OFFSET}" />
</annotation>
</item>
<item name="java.util.Calendar java.lang.String getDisplayName(int, int, java.util.Locale) 0">
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="intValues" val="{java.util.Calendar.ERA, java.util.Calendar.YEAR, java.util.Calendar.MONTH, java.util.Calendar.WEEK_OF_YEAR, java.util.Calendar.WEEK_OF_MONTH, java.util.Calendar.DATE, java.util.Calendar.DAY_OF_MONTH, java.util.Calendar.DAY_OF_YEAR, java.util.Calendar.DAY_OF_WEEK, java.util.Calendar.DAY_OF_WEEK_IN_MONTH, java.util.Calendar.AM_PM, java.util.Calendar.HOUR, java.util.Calendar.HOUR_OF_DAY, java.util.Calendar.MINUTE, java.util.Calendar.SECOND, java.util.Calendar.MILLISECOND, java.util.Calendar.ZONE_OFFSET, java.util.Calendar.DST_OFFSET}" />
</annotation>
</item>
<item name="java.util.Calendar java.lang.String getDisplayName(int, int, java.util.Locale) 1">
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="intValues" val="{java.util.Calendar.SHORT, java.util.Calendar.LONG}" />
</annotation>
</item>
<item name="java.util.Calendar java.util.Map&lt;java.lang.String,java.lang.Integer&gt; getDisplayNames(int, int, java.util.Locale) 0">
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="intValues" val="{java.util.Calendar.ERA, java.util.Calendar.YEAR, java.util.Calendar.MONTH, java.util.Calendar.WEEK_OF_YEAR, java.util.Calendar.WEEK_OF_MONTH, java.util.Calendar.DATE, java.util.Calendar.DAY_OF_MONTH, java.util.Calendar.DAY_OF_YEAR, java.util.Calendar.DAY_OF_WEEK, java.util.Calendar.DAY_OF_WEEK_IN_MONTH, java.util.Calendar.AM_PM, java.util.Calendar.HOUR, java.util.Calendar.HOUR_OF_DAY, java.util.Calendar.MINUTE, java.util.Calendar.SECOND, java.util.Calendar.MILLISECOND, java.util.Calendar.ZONE_OFFSET, java.util.Calendar.DST_OFFSET}" />
</annotation>
</item>
<item name="java.util.Calendar java.util.Map&lt;java.lang.String,java.lang.Integer&gt; getDisplayNames(int, int, java.util.Locale) 1">
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="intValues" val="{java.util.Calendar.SHORT, java.util.Calendar.LONG, java.util.Calendar.ALL_STYLES}" />
</annotation>
</item>
<item name="java.util.Calendar int getFirstDayOfWeek()">
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="intValues" val="{java.util.Calendar.SUNDAY, java.util.Calendar.MONDAY, java.util.Calendar.TUESDAY, java.util.Calendar.WEDNESDAY, java.util.Calendar.THURSDAY, java.util.Calendar.FRIDAY, java.util.Calendar.SATURDAY}" />
@@ -532,7 +507,32 @@
<val name="intValues" val="{java.util.Calendar.ERA, java.util.Calendar.YEAR, java.util.Calendar.MONTH, java.util.Calendar.WEEK_OF_YEAR, java.util.Calendar.WEEK_OF_MONTH, java.util.Calendar.DATE, java.util.Calendar.DAY_OF_MONTH, java.util.Calendar.DAY_OF_YEAR, java.util.Calendar.DAY_OF_WEEK, java.util.Calendar.DAY_OF_WEEK_IN_MONTH, java.util.Calendar.AM_PM, java.util.Calendar.HOUR, java.util.Calendar.HOUR_OF_DAY, java.util.Calendar.MINUTE, java.util.Calendar.SECOND, java.util.Calendar.MILLISECOND, java.util.Calendar.ZONE_OFFSET, java.util.Calendar.DST_OFFSET}" />
</annotation>
</item>
<item name="java.util.Calendar boolean isSet(int) 0">
<item name="java.util.Calendar java.lang.String getDisplayName(int, int, java.util.Locale) 0">
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="intValues" val="{java.util.Calendar.ERA, java.util.Calendar.YEAR, java.util.Calendar.MONTH, java.util.Calendar.WEEK_OF_YEAR, java.util.Calendar.WEEK_OF_MONTH, java.util.Calendar.DATE, java.util.Calendar.DAY_OF_MONTH, java.util.Calendar.DAY_OF_YEAR, java.util.Calendar.DAY_OF_WEEK, java.util.Calendar.DAY_OF_WEEK_IN_MONTH, java.util.Calendar.AM_PM, java.util.Calendar.HOUR, java.util.Calendar.HOUR_OF_DAY, java.util.Calendar.MINUTE, java.util.Calendar.SECOND, java.util.Calendar.MILLISECOND, java.util.Calendar.ZONE_OFFSET, java.util.Calendar.DST_OFFSET}" />
</annotation>
</item>
<item name="java.util.Calendar java.lang.String getDisplayName(int, int, java.util.Locale) 1">
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="intValues" val="{java.util.Calendar.SHORT, java.util.Calendar.LONG}" />
</annotation>
</item>
<item name="java.util.Calendar java.util.Map&lt;java.lang.String,java.lang.Integer&gt; getDisplayNames(int, int, java.util.Locale) 0">
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="intValues" val="{java.util.Calendar.ERA, java.util.Calendar.YEAR, java.util.Calendar.MONTH, java.util.Calendar.WEEK_OF_YEAR, java.util.Calendar.WEEK_OF_MONTH, java.util.Calendar.DATE, java.util.Calendar.DAY_OF_MONTH, java.util.Calendar.DAY_OF_YEAR, java.util.Calendar.DAY_OF_WEEK, java.util.Calendar.DAY_OF_WEEK_IN_MONTH, java.util.Calendar.AM_PM, java.util.Calendar.HOUR, java.util.Calendar.HOUR_OF_DAY, java.util.Calendar.MINUTE, java.util.Calendar.SECOND, java.util.Calendar.MILLISECOND, java.util.Calendar.ZONE_OFFSET, java.util.Calendar.DST_OFFSET}" />
</annotation>
</item>
<item name="java.util.Calendar java.util.Map&lt;java.lang.String,java.lang.Integer&gt; getDisplayNames(int, int, java.util.Locale) 1">
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="intValues" val="{java.util.Calendar.SHORT, java.util.Calendar.LONG, java.util.Calendar.ALL_STYLES}" />
</annotation>
</item>
<item name="java.util.Calendar void add(int, int) 0" >
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="intValues" val="{java.util.Calendar.ERA, java.util.Calendar.YEAR, java.util.Calendar.MONTH, java.util.Calendar.WEEK_OF_YEAR, java.util.Calendar.WEEK_OF_MONTH, java.util.Calendar.DATE, java.util.Calendar.DAY_OF_MONTH, java.util.Calendar.DAY_OF_YEAR, java.util.Calendar.DAY_OF_WEEK, java.util.Calendar.DAY_OF_WEEK_IN_MONTH, java.util.Calendar.AM_PM, java.util.Calendar.HOUR, java.util.Calendar.HOUR_OF_DAY, java.util.Calendar.MINUTE, java.util.Calendar.SECOND, java.util.Calendar.MILLISECOND, java.util.Calendar.ZONE_OFFSET, java.util.Calendar.DST_OFFSET}" />
</annotation>
</item>
<item name="java.util.Calendar void clear(int) 0" >
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="intValues" val="{java.util.Calendar.ERA, java.util.Calendar.YEAR, java.util.Calendar.MONTH, java.util.Calendar.WEEK_OF_YEAR, java.util.Calendar.WEEK_OF_MONTH, java.util.Calendar.DATE, java.util.Calendar.DAY_OF_MONTH, java.util.Calendar.DAY_OF_YEAR, java.util.Calendar.DAY_OF_WEEK, java.util.Calendar.DAY_OF_WEEK_IN_MONTH, java.util.Calendar.AM_PM, java.util.Calendar.HOUR, java.util.Calendar.HOUR_OF_DAY, java.util.Calendar.MINUTE, java.util.Calendar.SECOND, java.util.Calendar.MILLISECOND, java.util.Calendar.ZONE_OFFSET, java.util.Calendar.DST_OFFSET}" />
</annotation>
@@ -11,6 +11,9 @@
<val name="flagsFromClass" val="java.util.regex.Pattern.class" />
</annotation>
</item>
<item name='java.util.regex.Pattern java.util.regex.Matcher matcher(java.lang.CharSequence)'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
<item name="java.util.regex.Pattern java.util.regex.Pattern compile(java.lang.String) 0">
<annotation name="org.jetbrains.annotations.NonNls" />
<annotation name="org.jetbrains.annotations.NotNull" />
@@ -27,6 +27,7 @@ package org.jetbrains.lang.manifest.parser;
import com.intellij.lexer.LexerBase;
import com.intellij.psi.TokenType;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.lang.manifest.psi.ManifestTokenType;
@@ -63,7 +64,7 @@ public class ManifestLexer extends LexerBase {
private IElementType myTokenType;
@Override
public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) {
public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) {
this.myBuffer = buffer;
this.myEndOffset = endOffset;
myCurrentState = State.values()[initialState];
@@ -104,6 +105,7 @@ public class ManifestLexer extends LexerBase {
return myEndOffset;
}
@NotNull
@Override
public CharSequence getBufferSequence() {
return myBuffer;
@@ -24,8 +24,11 @@ import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.vfs.VirtualFileFilter;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.source.resolve.PsiResolveHelperImpl;
import com.intellij.psi.impl.source.resolve.graphInference.PsiGraphInferenceHelper;
import com.intellij.testFramework.ExpectedHighlightingData;
import com.intellij.testFramework.FileTreeAccessFilter;
import com.intellij.testFramework.HighlightTestInfo;
@@ -80,6 +83,18 @@ public abstract class LightDaemonAnalyzerTestCase extends LightCodeInsightTestCa
doTestConfiguredFile(checkWarnings, checkInfos, filePath);
}
protected void doTestNewInference(@NonNls String filePath, boolean checkWarnings, boolean checkInfos) {
final PsiResolveHelperImpl helper = (PsiResolveHelperImpl)JavaPsiFacade.getInstance(getProject()).getResolveHelper();
helper.setTestHelper(new PsiGraphInferenceHelper(getPsiManager()));
try {
configureByFile(filePath);
doTestConfiguredFile(checkWarnings, checkInfos, filePath);
}
finally {
helper.setTestHelper(null);
}
}
protected void doTest(@NonNls String filePath, boolean checkWarnings, boolean checkWeakWarnings, boolean checkInfos) {
configureByFile(filePath);
doTestConfiguredFile(checkWarnings, checkWeakWarnings, checkInfos, filePath);
@@ -80,7 +80,7 @@ public class CompilerTestUtil {
public static void enableExternalCompiler(final Project project) {
new WriteAction() {
protected void run(final Result result) {
CompilerWorkspaceConfiguration.getInstance(project).USE_COMPILE_SERVER = true;
CompilerWorkspaceConfiguration.getInstance(project).USE_OUT_OF_PROCESS_BUILD = true;
ApplicationManagerEx.getApplicationEx().doNotSave(false);
JavaAwareProjectJdkTableImpl table = JavaAwareProjectJdkTableImpl.getInstanceEx();
table.addJdk(table.getInternalJdk());
@@ -91,7 +91,7 @@ public class CompilerTestUtil {
public static void disableExternalCompiler(final Project project) {
new WriteAction() {
protected void run(final Result result) {
CompilerWorkspaceConfiguration.getInstance(project).USE_COMPILE_SERVER = false;
CompilerWorkspaceConfiguration.getInstance(project).USE_OUT_OF_PROCESS_BUILD = false;
ApplicationManagerEx.getApplicationEx().doNotSave(true);
JavaAwareProjectJdkTableImpl table = JavaAwareProjectJdkTableImpl.getInstanceEx();
table.removeJdk(table.getInternalJdk());
@@ -34,8 +34,6 @@ public class HighlightSeverity implements Comparable<HighlightSeverity>, JDOMExt
public String myName;
public int myVal;
public static final HighlightSeverity SEMANTIC = new HighlightSeverity("SEMANTIC", 5);
/**
* The standard severity level for information annotations.
*/
@@ -1,24 +0,0 @@
package com.intellij.lang.annotation;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.util.TextRange;
import org.jetbrains.annotations.NotNull;
/**
* Allows to crate semantic annotations to highlight similar PSI elements differently depending on their actual meaning. For example,
* static members vs. instance fields and etc. Semantic annotations have lower highlighting level than infos, weak warnings etc. but
* higher than regular syntax.
*
* @author Rustam Vishnyakov
*/
public interface SemanticAnnotationHolder extends AnnotationHolder {
/**
* Creates annotation with a semantic highlighting level.
*
* @param range The text range over which the annotation is created.
* @param attributesKey The attributes key to use for the annotation.
* @return the annotation (which can be modified to set additional annotation parameters).
*/
Annotation createSemanticAnnotation(@NotNull TextRange range, @NotNull TextAttributesKey attributesKey);
}
@@ -17,10 +17,11 @@
package com.intellij.codeInsight.daemon.impl;
import com.intellij.lang.ASTNode;
import com.intellij.lang.annotation.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.lang.annotation.Annotation;
import com.intellij.lang.annotation.AnnotationHolder;
import com.intellij.lang.annotation.AnnotationSession;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VirtualFile;
@@ -35,12 +36,10 @@ import org.jetbrains.annotations.Nullable;
/**
* @author max
*/
public class AnnotationHolderImpl extends SmartList<Annotation> implements SemanticAnnotationHolder {
public class AnnotationHolderImpl extends SmartList<Annotation> implements AnnotationHolder {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.AnnotationHolderImpl");
private final AnnotationSession myAnnotationSession;
private final static boolean isUnitTestMode = ApplicationManager.getApplication().isUnitTestMode();
private final boolean myBatchMode;
public AnnotationHolderImpl(@NotNull AnnotationSession session) {
@@ -158,12 +157,4 @@ public class AnnotationHolderImpl extends SmartList<Annotation> implements Seman
public AnnotationSession getCurrentAnnotationSession() {
return myAnnotationSession;
}
@Override
public Annotation createSemanticAnnotation(@NotNull TextRange range, @NotNull TextAttributesKey key) {
String description = isUnitTestMode ? key.getExternalName() : null;
Annotation annotation = createAnnotation(range, HighlightSeverity.SEMANTIC, description);
annotation.setTextAttributes(key);
return annotation;
}
}
@@ -41,20 +41,23 @@ public class HighlightingSessionImpl implements HighlightingSession {
@NotNull private final ProgressIndicator myProgressIndicator;
private final EditorColorsScheme myEditorColorsScheme;
private final int myPassId;
@NotNull private final TextRange myRestrictRange;
private final Project myProject;
private final Document myDocument;
private Map<TextRange,RangeMarker> myRanges2markersCache;
private final Map<TextRange,RangeMarker> myRanges2markersCache = new THashMap<TextRange, RangeMarker>();
public HighlightingSessionImpl(@NotNull PsiFile psiFile,
@Nullable Editor editor,
@NotNull ProgressIndicator progressIndicator,
EditorColorsScheme editorColorsScheme,
int passId) {
int passId,
@NotNull TextRange restrictRange) {
myPsiFile = psiFile;
myEditor = editor;
myProgressIndicator = progressIndicator;
myEditorColorsScheme = editorColorsScheme;
myPassId = passId;
myRestrictRange = restrictRange;
myProject = psiFile.getProject();
myDocument = PsiDocumentManager.getInstance(myProject).getDocument(psiFile);
}
@@ -97,36 +100,34 @@ public class HighlightingSessionImpl implements HighlightingSession {
return myPassId;
}
private TransferToEDTQueue<HighlightInfo> myAddHighlighterInEDTQueue;
private TransferToEDTQueue<RangeHighlighterEx> myDisposeHighlighterInEDTQueue;
void init(@NotNull final TextRange restrictRange) {
myRanges2markersCache = new THashMap<TextRange, RangeMarker>();
Condition<Object> stopCondition = new Condition<Object>() {
@Override
public boolean value(Object o) {
return myProject.isDisposed() || getProgressIndicator().isCanceled();
}
};
myAddHighlighterInEDTQueue = new TransferToEDTQueue<HighlightInfo>("Apply highlighting results", new Processor<HighlightInfo>() {
@Override
public boolean process(HighlightInfo info) {
final EditorColorsScheme colorsScheme = getColorsScheme();
UpdateHighlightersUtil.addHighlighterToEditorIncrementally(myProject, myDocument, getPsiFile(), restrictRange.getStartOffset(),
restrictRange.getEndOffset(),
info, colorsScheme, Pass.UPDATE_ALL, myRanges2markersCache);
private final TransferToEDTQueue<HighlightInfo> myAddHighlighterInEDTQueue = new TransferToEDTQueue<HighlightInfo>("Apply highlighting results", new Processor<HighlightInfo>() {
@Override
public boolean process(HighlightInfo info) {
final EditorColorsScheme colorsScheme = getColorsScheme();
UpdateHighlightersUtil.addHighlighterToEditorIncrementally(myProject, myDocument, getPsiFile(), myRestrictRange.getStartOffset(),
myRestrictRange.getEndOffset(),
info, colorsScheme, Pass.UPDATE_ALL, myRanges2markersCache);
return true;
}
}, stopCondition, 200);
myDisposeHighlighterInEDTQueue = new TransferToEDTQueue<RangeHighlighterEx>("Dispose abandoned highlighter", new Processor<RangeHighlighterEx>() {
@Override
public boolean process(@NotNull RangeHighlighterEx highlighter) {
highlighter.dispose();
return true;
}
}, stopCondition, 200);
}
return true;
}
}, new Condition<Object>() {
@Override
public boolean value(Object o) {
return myProject.isDisposed() || getProgressIndicator().isCanceled();
}
}, 200);
private final TransferToEDTQueue<RangeHighlighterEx> myDisposeHighlighterInEDTQueue = new TransferToEDTQueue<RangeHighlighterEx>("Dispose abandoned highlighter", new Processor<RangeHighlighterEx>() {
@Override
public boolean process(@NotNull RangeHighlighterEx highlighter) {
highlighter.dispose();
return true;
}
}, new Condition<Object>() {
@Override
public boolean value(Object o) {
return myProject.isDisposed() || getProgressIndicator().isCanceled();
}
}, 200);
void queueHighlightInfo(@NotNull HighlightInfo info) {
myAddHighlighterInEDTQueue.offer(info);
@@ -62,14 +62,13 @@ public abstract class ProgressableTextEditorHighlightingPass extends TextEditorH
@NotNull
private HighlightingSession sessionCreated(@NotNull TextRange restrictRange,
@NotNull PsiFile file,
@Nullable Editor editor,
@NotNull ProgressIndicator progress,
EditorColorsScheme scheme,
int passId) {
HighlightingSessionImpl impl = new HighlightingSessionImpl(file, editor, progress, scheme, passId);
@NotNull PsiFile file,
@Nullable Editor editor,
@NotNull ProgressIndicator progress,
EditorColorsScheme scheme,
int passId) {
HighlightingSessionImpl impl = new HighlightingSessionImpl(file, editor, progress, scheme, passId, restrictRange);
myHighlightingSession = impl;
impl.init(restrictRange);
return impl;
}
@@ -423,9 +423,6 @@ public class UpdateHighlightersUtil {
else if (severity == HighlightInfoType.INJECTED_FRAGMENT_SEVERITY) {
layer = HighlighterLayer.CARET_ROW-1;
}
else if (severity == HighlightSeverity.SEMANTIC) {
layer = HighlighterLayer.SEMANTIC;
}
else {
layer = HighlighterLayer.ADDITIONAL_SYNTAX;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,33 +35,40 @@ public class ArchiveFileType implements FileType {
public static final ArchiveFileType INSTANCE = new ArchiveFileType();
@Override
@NotNull
public String getName() {
return "ARCHIVE";
}
@Override
@NotNull
public String getDescription() {
return IdeBundle.message("filetype.description.archive.files");
}
@Override
@NotNull
public String getDefaultExtension() {
return "";
}
@Override
public Icon getIcon() {
return ICON.getValue();
}
@Override
public boolean isBinary() {
return true;
}
@Override
public boolean isReadOnly() {
return false;
}
@Override
public String getCharset(@NotNull VirtualFile file, final byte[] content) {
return null;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
package com.intellij.lexer;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class DelegateLexer extends LexerBase {
@@ -34,7 +35,7 @@ public class DelegateLexer extends LexerBase {
}
@Override
public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) {
public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) {
myDelegate.start(buffer, startOffset, endOffset, initialState);
}
@@ -64,6 +65,7 @@ public class DelegateLexer extends LexerBase {
myDelegate.advance();
}
@NotNull
@Override
public final CharSequence getBufferSequence() {
return myDelegate.getBufferSequence();
@@ -17,6 +17,7 @@ package com.intellij.lexer;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.text.CharArrayUtil;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@@ -45,7 +46,7 @@ public class DocCommentLexer extends MergingLexerAdapter {
}
@Override
public final void start(CharSequence buffer, int startOffset, int endOffset, int initialState) {
public final void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) {
myBuffer = buffer;
myBufferIndex = startOffset;
myBufferEndOffset = endOffset;
@@ -59,6 +60,7 @@ public class DocCommentLexer extends MergingLexerAdapter {
return myState;
}
@NotNull
@Override
public CharSequence getBufferSequence() {
return myBuffer;
@@ -16,6 +16,7 @@
package com.intellij.lexer;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
public class DummyLexer extends LexerBase {
private CharSequence myBuffer;
@@ -27,43 +28,55 @@ public class DummyLexer extends LexerBase {
myTokenType = type;
}
public void start(final CharSequence buffer, final int startOffset, final int endOffset, final int initialState) {
@Override
public void start(@NotNull final CharSequence buffer, final int startOffset, final int endOffset, final int initialState) {
myBuffer = buffer;
myStartOffset = startOffset;
myEndOffset = endOffset;
}
@NotNull
@Override
public CharSequence getBufferSequence() {
return myBuffer;
}
@Override
public int getState() {
return 0;
}
@Override
public IElementType getTokenType() {
return (myStartOffset < myEndOffset ? myTokenType : null);
return myStartOffset < myEndOffset ? myTokenType : null;
}
@Override
public int getTokenStart() {
return myStartOffset;
}
@Override
public int getTokenEnd() {
return myEndOffset;
}
@Override
public void advance() {
myStartOffset = myEndOffset;
}
@NotNull
@Override
public LexerPosition getCurrentPosition() {
return new LexerPositionImpl(0, getState());
}
public void restore(LexerPosition position) {
@Override
public void restore(@NotNull LexerPosition position) {
}
@Override
public int getBufferEnd() {
return myEndOffset;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package com.intellij.lexer;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@@ -39,7 +40,7 @@ public class FlexAdapter extends LexerBase {
}
@Override
public void start(final CharSequence buffer, int startOffset, int endOffset, final int initialState) {
public void start(@NotNull final CharSequence buffer, int startOffset, int endOffset, final int initialState) {
myText = buffer;
myEnd = endOffset;
myFlex.reset(myText, startOffset, endOffset, initialState);
@@ -76,6 +77,7 @@ public class FlexAdapter extends LexerBase {
myTokenType = null;
}
@NotNull
@Override
public CharSequence getBufferSequence() {
return myText;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package com.intellij.lexer;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.containers.HashMap;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.Map;
@@ -75,7 +76,7 @@ public class LayeredLexer extends DelegateLexer {
}
@Override
public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) {
public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) {
LOG.assertTrue(initialState != IN_LAYER_STATE, "Restoring to layer is not supported.");
myState = initialState;
myCurrentLayerLexer = null;
@@ -157,13 +158,14 @@ public class LayeredLexer extends DelegateLexer {
myState = isLayerActive() ? IN_LAYER_STATE : super.getState();
}
@NotNull
@Override
public LexerPosition getCurrentPosition() {
return new LexerPositionImpl(getTokenStart(), getState());
}
@Override
public void restore(LexerPosition position) {
public void restore(@NotNull LexerPosition position) {
start(getBufferSequence(), position.getOffset(), getBufferEnd(), position.getState());
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package com.intellij.lexer;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
@@ -35,20 +36,22 @@ public abstract class Lexer {
* @param initialState the initial state of the lexer.
* @since IDEA 7
*/
public abstract void start(CharSequence buffer, int startOffset, int endOffset, int initialState);
public abstract void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState);
public final void start(CharSequence buf, int start, int end) {
public final void start(@NotNull CharSequence buf, int start, int end) {
start(buf, start, end, 0);
}
public final void start(CharSequence buf) {
public final void start(@NotNull CharSequence buf) {
start(buf, 0, buf.length(), 0);
}
@NotNull
public CharSequence getTokenSequence() {
return getBufferSequence().subSequence(getTokenStart(), getTokenEnd());
}
@NotNull
public String getTokenText() {
return getTokenSequence().toString();
}
@@ -93,6 +96,7 @@ public abstract class Lexer {
*
* @return the lexer position and state.
*/
@NotNull
public abstract LexerPosition getCurrentPosition();
/**
@@ -100,7 +104,7 @@ public abstract class Lexer {
*
* @param position the state and position to restore to.
*/
public abstract void restore(LexerPosition position);
public abstract void restore(@NotNull LexerPosition position);
/**
* Returns the buffer sequence over which the lexer is running. This method should return the
@@ -108,6 +112,7 @@ public abstract class Lexer {
* @return the lexer buffer.
* @since IDEA 7
*/
@NotNull
public abstract CharSequence getBufferSequence();
/**
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,7 +15,10 @@
*/
package com.intellij.lexer;
import org.jetbrains.annotations.NotNull;
public abstract class LexerBase extends Lexer {
@NotNull
@Override
public LexerPosition getCurrentPosition() {
final int offset = getTokenStart();
@@ -24,7 +27,7 @@ public abstract class LexerBase extends Lexer {
}
@Override
public void restore(LexerPosition position) {
public void restore(@NotNull LexerPosition position) {
start(getBufferSequence(), position.getOffset(), getBufferEnd(), position.getState());
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package com.intellij.lexer;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
public class MergingLexerAdapterBase extends DelegateLexer {
private IElementType myTokenType;
@@ -29,7 +30,7 @@ public class MergingLexerAdapterBase extends DelegateLexer {
}
@Override
public void start(final CharSequence buffer, final int startOffset, final int endOffset, final int initialState) {
public void start(@NotNull final CharSequence buffer, final int startOffset, final int endOffset, final int initialState) {
super.start(buffer, startOffset, endOffset, initialState);
myTokenType = null;
}
@@ -81,7 +82,7 @@ public class MergingLexerAdapterBase extends DelegateLexer {
}
@Override
public void restore(LexerPosition position) {
public void restore(@NotNull LexerPosition position) {
MyLexerPosition pos = (MyLexerPosition)position;
getDelegate().restore(pos.getOriginalPosition());
@@ -90,6 +91,7 @@ public class MergingLexerAdapterBase extends DelegateLexer {
myState = pos.getOldState();
}
@NotNull
@Override
public LexerPosition getCurrentPosition() {
return new MyLexerPosition(myTokenStart, myTokenType, getDelegate().getCurrentPosition(), myState);
@@ -64,7 +64,8 @@ public final class TextAttributesKey implements Comparable<TextAttributesKey>, J
return myExternalName;
}
public int compareTo(TextAttributesKey key) {
@Override
public int compareTo(@NotNull TextAttributesKey key) {
return myExternalName.compareTo(key.myExternalName);
}
@@ -79,10 +80,12 @@ public final class TextAttributesKey implements Comparable<TextAttributesKey>, J
return find(externalName);
}
@Override
public void readExternal(Element element) throws InvalidDataException {
DefaultJDOMExternalizer.readExternal(this, element);
}
@Override
public void writeExternal(Element element) throws WriteExternalException {
DefaultJDOMExternalizer.writeExternal(this, element);
}
@@ -19,6 +19,7 @@
*/
package com.intellij.openapi.editor.markup;
import com.intellij.openapi.util.Comparing;
import com.intellij.util.ConcurrencyUtil;
import com.intellij.util.containers.StripedLockConcurrentHashMap;
import org.intellij.lang.annotations.JdkConstants;
@@ -28,17 +29,29 @@ import org.jetbrains.annotations.NotNull;
import java.awt.*;
public class AttributesFlyweight {
private final int myHashCode;
private static final StripedLockConcurrentHashMap<FlyweightKey, AttributesFlyweight> entries = new StripedLockConcurrentHashMap<FlyweightKey, AttributesFlyweight>();
private static final ThreadLocal<FlyweightKey> ourKey = new ThreadLocal<FlyweightKey>();
private final int myHashCode;
private final Color myForeground;
private final Color myBackground;
@JdkConstants.FontStyle
private final int myFontType;
private final Color myEffectColor;
private final EffectType myEffectType;
private final Color myErrorStripeColor;
private static class FlyweightKey implements Cloneable {
Color foreground;
Color background;
@JdkConstants.FontStyle int fontType;
Color effectColor;
EffectType effectType;
Color errorStripeColor;
private Color foreground;
private Color background;
@JdkConstants.FontStyle
private int fontType;
private Color effectColor;
private EffectType effectType;
private Color errorStripeColor;
private FlyweightKey() {
}
@Override
public boolean equals(Object o) {
@@ -59,13 +72,7 @@ public class AttributesFlyweight {
@Override
public int hashCode() {
int result = foreground != null ? foreground.hashCode() : 0;
result = 31 * result + (background != null ? background.hashCode() : 0);
result = 31 * result + fontType;
result = 31 * result + (effectColor != null ? effectColor.hashCode() : 0);
result = 31 * result + (effectType != null ? effectType.hashCode() : 0);
result = 31 * result + (errorStripeColor != null ? errorStripeColor.hashCode() : 0);
return result;
return calcHashCode(foreground, background, fontType, effectColor, effectType, errorStripeColor);
}
@Override
@@ -102,39 +109,37 @@ public class AttributesFlyweight {
return flyweight;
}
return ConcurrencyUtil.cacheOrGet(entries, key.clone(), new AttributesFlyweight(foreground, background, fontType, effectColor, effectType, errorStripeColor));
AttributesFlyweight newValue = new AttributesFlyweight(foreground, background, fontType, effectColor, effectType, errorStripeColor);
return ConcurrencyUtil.cacheOrGet(entries, key.clone(), newValue);
}
private final Color myForeground;
private final Color myBackground;
@JdkConstants.FontStyle
private final int myFontType;
private final Color myEffectColor ;
private final EffectType myEffectType;
private final Color myErrorStripeColor;
private AttributesFlyweight(Color foreground,
Color background,
@JdkConstants.FontStyle int fontType,
Color effectColor,
EffectType effectType,
Color errorStripeColor) {
Color background,
@JdkConstants.FontStyle int fontType,
Color effectColor,
EffectType effectType,
Color errorStripeColor) {
myForeground = foreground;
myBackground = background;
myFontType = fontType;
myEffectColor = effectColor;
myEffectType = effectType;
myErrorStripeColor = errorStripeColor;
myHashCode = calcHashCode();
myHashCode = calcHashCode(foreground, background, fontType, effectColor, effectType, errorStripeColor);
}
private int calcHashCode() {
int result = myForeground != null ? myForeground.hashCode() : 0;
result = 31 * result + (myBackground != null ? myBackground.hashCode() : 0);
result = 31 * result + myFontType;
result = 31 * result + (myEffectColor != null ? myEffectColor.hashCode() : 0);
result = 31 * result + (myEffectType != null ? myEffectType.hashCode() : 0);
result = 31 * result + (myErrorStripeColor != null ? myErrorStripeColor.hashCode() : 0);
private static int calcHashCode(Color foreground,
Color background,
int fontType,
Color effectColor,
EffectType effectType,
Color errorStripeColor) {
int result = foreground != null ? foreground.hashCode() : 0;
result = 31 * result + (background != null ? background.hashCode() : 0);
result = 31 * result + fontType;
result = 31 * result + (effectColor != null ? effectColor.hashCode() : 0);
result = 31 * result + (effectType != null ? effectType.hashCode() : 0);
result = 31 * result + (errorStripeColor != null ? errorStripeColor.hashCode() : 0);
return result;
}
@@ -163,28 +168,34 @@ public class AttributesFlyweight {
return myErrorStripeColor;
}
public AttributesFlyweight withForeground(Color fore) {
return create(fore, myBackground, myFontType, myEffectColor, myEffectType, myErrorStripeColor);
@NotNull
public AttributesFlyweight withForeground(Color foreground) {
return Comparing.equal(foreground, myForeground) ? this : create(foreground, myBackground, myFontType, myEffectColor, myEffectType, myErrorStripeColor);
}
public AttributesFlyweight withBackground(Color back) {
return create(myForeground, back, myFontType, myEffectColor, myEffectType, myErrorStripeColor);
@NotNull
public AttributesFlyweight withBackground(Color background) {
return Comparing.equal(background, myBackground) ? this : create(myForeground, background, myFontType, myEffectColor, myEffectType, myErrorStripeColor);
}
@NotNull
public AttributesFlyweight withFontType(@JdkConstants.FontStyle int fontType) {
return create(myForeground, myBackground, fontType, myEffectColor, myEffectType, myErrorStripeColor);
return fontType == myFontType ? this : create(myForeground, myBackground, fontType, myEffectColor, myEffectType, myErrorStripeColor);
}
@NotNull
public AttributesFlyweight withEffectColor(Color effectColor) {
return create(myForeground, myBackground, myFontType, effectColor, myEffectType, myErrorStripeColor);
return Comparing.equal(effectColor, myEffectColor) ? this : create(myForeground, myBackground, myFontType, effectColor, myEffectType, myErrorStripeColor);
}
@NotNull
public AttributesFlyweight withEffectType(EffectType effectType) {
return create(myForeground, myBackground, myFontType, myEffectColor, effectType, myErrorStripeColor);
return Comparing.equal(effectType, myEffectType) ? this : create(myForeground, myBackground, myFontType, myEffectColor, effectType, myErrorStripeColor);
}
@NotNull
public AttributesFlyweight withErrorStripeColor(Color stripeColor) {
return create(myForeground, myBackground, myFontType, myEffectColor, myEffectType, stripeColor);
return Comparing.equal(stripeColor, myErrorStripeColor) ? this : create(myForeground, myBackground, myFontType, myEffectColor, myEffectType, stripeColor);
}
@Override
@@ -212,19 +223,7 @@ public class AttributesFlyweight {
@NonNls
@Override
public String toString() {
return "AttributesFlyweight{" +
"myForeground=" +
myForeground +
", myBackground=" +
myBackground +
", myFontType=" +
myFontType +
", myEffectColor=" +
myEffectColor +
", myEffectType=" +
myEffectType +
", myErrorStripeColor=" +
myErrorStripeColor +
'}';
return "AttributesFlyweight{myForeground=" + myForeground + ", myBackground=" + myBackground + ", myFontType=" + myFontType +
", myEffectColor=" + myEffectColor + ", myEffectType=" + myEffectType + ", myErrorStripeColor=" + myErrorStripeColor + '}';
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,13 @@
package com.intellij.openapi.editor.markup;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.DefaultJDOMExternalizer;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.JDOMExternalizable;
import com.intellij.openapi.util.WriteExternalException;
import org.intellij.lang.annotations.JdkConstants;
import org.jdom.Element;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
@@ -34,6 +38,9 @@ public class TextAttributes implements JDOMExternalizable, Cloneable {
private boolean myEnforcedDefaults = false;
@NotNull
private AttributesFlyweight myAttrs;
/**
* Merges (layers) the two given text attributes.
*
@@ -41,6 +48,7 @@ public class TextAttributes implements JDOMExternalizable, Cloneable {
* @param above Text attributes to merge "above", overriding settings from "under".
* @return Merged attributes instance.
*/
@Contract("!null, !null -> !null")
public static TextAttributes merge(TextAttributes under, TextAttributes above) {
if (under == null) return above;
if (above == null) return under;
@@ -154,8 +162,6 @@ public class TextAttributes implements JDOMExternalizable, Cloneable {
}
}
private AttributesFlyweight myAttrs;
public TextAttributes() {
this(null, null, null, EffectType.BOXED, Font.PLAIN);
}
@@ -194,7 +200,7 @@ public class TextAttributes implements JDOMExternalizable, Cloneable {
}
@NotNull
public static TextAttributes fromFlyweight(AttributesFlyweight flyweight) {
public static TextAttributes fromFlyweight(@NotNull AttributesFlyweight flyweight) {
TextAttributes f = new TextAttributes();
f.myAttrs = flyweight;
return f;
@@ -277,12 +283,7 @@ public class TextAttributes implements JDOMExternalizable, Cloneable {
public void readExternal(Element element) throws InvalidDataException {
Externalizable ext = new Externalizable();
ext.readExternal(element);
myAttrs = AttributesFlyweight.create(ext.FOREGROUND,
ext.BACKGROUND,
ext.FONT_TYPE,
ext.EFFECT_COLOR,
ext.getEffectType(),
ext.ERROR_STRIPE_COLOR);
myAttrs = AttributesFlyweight.create(ext.FOREGROUND, ext.BACKGROUND, ext.FONT_TYPE, ext.EFFECT_COLOR, ext.getEffectType(), ext.ERROR_STRIPE_COLOR);
if (isEmpty()) myEnforcedDefaults = true;
}
@@ -302,18 +303,7 @@ public class TextAttributes implements JDOMExternalizable, Cloneable {
@Override
public String toString() {
return "[" +
getForegroundColor() +
"," +
getBackgroundColor() +
"," +
getFontType() +
"," +
getEffectType() +
"," +
getEffectColor() +
"," +
getErrorStripeColor() +
"]";
return "[" + getForegroundColor() + "," + getBackgroundColor() + "," + getFontType() + "," + getEffectType() + "," +
getEffectColor() + "," + getErrorStripeColor() + "]";
}
}
@@ -19,13 +19,14 @@
*/
package com.intellij.openapi.fileTypes;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.KeyedExtensionFactory;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
public class FileTypeExtensionFactory<T> extends KeyedExtensionFactory<T, FileType> {
public FileTypeExtensionFactory(@NotNull final Class<T> interfaceClass, @NonNls @NotNull final String epName) {
super(interfaceClass, epName);
super(interfaceClass, epName, ApplicationManager.getApplication().getPicoContainer());
}
@Override
+1
View File
@@ -11,6 +11,7 @@
<orderEntry type="module" module-name="util" />
<orderEntry type="module" module-name="annotations" />
<orderEntry type="module" module-name="projectModel-api" />
<orderEntry type="module" module-name="indexing-api" />
</component>
</module>
@@ -27,31 +27,38 @@ import org.jetbrains.annotations.NotNull;
public class HighlighterFactory {
private HighlighterFactory() {}
public static EditorHighlighter createHighlighter(SyntaxHighlighter highlighter, EditorColorsScheme settings) {
@NotNull
public static EditorHighlighter createHighlighter(SyntaxHighlighter highlighter, @NotNull EditorColorsScheme settings) {
return EditorHighlighterFactory.getInstance().createEditorHighlighter(highlighter, settings);
}
public static EditorHighlighter createHighlighter(Project project, String fileName) {
@NotNull
public static EditorHighlighter createHighlighter(Project project, @NotNull String fileName) {
return EditorHighlighterFactory.getInstance().createEditorHighlighter(project, fileName);
}
public static EditorHighlighter createHighlighter(Project project, VirtualFile file) {
@NotNull
public static EditorHighlighter createHighlighter(Project project, @NotNull VirtualFile file) {
return EditorHighlighterFactory.getInstance().createEditorHighlighter(project, file);
}
public static EditorHighlighter createHighlighter(Project project, FileType fileType) {
@NotNull
public static EditorHighlighter createHighlighter(Project project, @NotNull FileType fileType) {
return EditorHighlighterFactory.getInstance().createEditorHighlighter(project, fileType);
}
public static EditorHighlighter createHighlighter(EditorColorsScheme settings, String fileName, Project project) {
@NotNull
public static EditorHighlighter createHighlighter(@NotNull EditorColorsScheme settings, @NotNull String fileName, Project project) {
return EditorHighlighterFactory.getInstance().createEditorHighlighter(settings, fileName, project);
}
public static EditorHighlighter createHighlighter(FileType fileType, EditorColorsScheme settings, Project project) {
@NotNull
public static EditorHighlighter createHighlighter(@NotNull FileType fileType, @NotNull EditorColorsScheme settings, Project project) {
return EditorHighlighterFactory.getInstance().createEditorHighlighter(fileType, settings, project);
}
public static EditorHighlighter createHighlighter(@NotNull VirtualFile vFile, EditorColorsScheme settings, Project project) {
@NotNull
public static EditorHighlighter createHighlighter(@NotNull VirtualFile vFile, @NotNull EditorColorsScheme settings, Project project) {
return EditorHighlighterFactory.getInstance().createEditorHighlighter(vFile, settings, project);
}
}
@@ -33,17 +33,24 @@ public abstract class EditorHighlighterFactory {
return ServiceManager.getService(EditorHighlighterFactory.class);
}
public abstract EditorHighlighter createEditorHighlighter(final SyntaxHighlighter syntaxHighlighter, final EditorColorsScheme colors);
@NotNull
public abstract EditorHighlighter createEditorHighlighter(final SyntaxHighlighter syntaxHighlighter, @NotNull EditorColorsScheme colors);
public abstract EditorHighlighter createEditorHighlighter(final FileType fileType, final EditorColorsScheme settings, final Project project);
@NotNull
public abstract EditorHighlighter createEditorHighlighter(@NotNull FileType fileType, @NotNull EditorColorsScheme settings, final Project project);
public abstract EditorHighlighter createEditorHighlighter(final Project project, final FileType fileType);
@NotNull
public abstract EditorHighlighter createEditorHighlighter(final Project project, @NotNull FileType fileType);
public abstract EditorHighlighter createEditorHighlighter(@NotNull final VirtualFile file, final EditorColorsScheme globalScheme, @Nullable final Project project);
@NotNull
public abstract EditorHighlighter createEditorHighlighter(@NotNull final VirtualFile file, @NotNull EditorColorsScheme globalScheme, @Nullable final Project project);
public abstract EditorHighlighter createEditorHighlighter(final Project project, final VirtualFile file);
@NotNull
public abstract EditorHighlighter createEditorHighlighter(final Project project, @NotNull VirtualFile file);
public abstract EditorHighlighter createEditorHighlighter(final Project project, final String fileName);
@NotNull
public abstract EditorHighlighter createEditorHighlighter(final Project project, @NotNull String fileName);
public abstract EditorHighlighter createEditorHighlighter(final EditorColorsScheme settings, final String fileName, @Nullable final Project project);
@NotNull
public abstract EditorHighlighter createEditorHighlighter(@NotNull EditorColorsScheme settings, @NotNull String fileName, @Nullable final Project project);
}
@@ -18,7 +18,6 @@ package com.intellij.openapi.editor.markup;
public interface HighlighterLayer {
int CARET_ROW = 1000;
int SYNTAX = 2000;
int SEMANTIC = 2500;
int ADDITIONAL_SYNTAX = 3000;
int GUARDED_BLOCKS = 3500;
int WARNING = 4000;
@@ -23,13 +23,15 @@ import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
public class PlainSyntaxHighlighter implements SyntaxHighlighter {
private static final TextAttributesKey[] ATTRS = new TextAttributesKey[] {HighlighterColors.TEXT};
private static final TextAttributesKey[] ATTRS = {HighlighterColors.TEXT};
@Override
@NotNull
public Lexer getHighlightingLexer() {
return new EmptyLexer();
}
@Override
@NotNull
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
return ATTRS;
@@ -28,4 +28,4 @@ public class PlainSyntaxHighlighterFactory extends SyntaxHighlighterFactory {
public SyntaxHighlighter getSyntaxHighlighter(final Project project, final VirtualFile virtualFile) {
return new PlainSyntaxHighlighter();
}
}
}

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