diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 81c07f1ae53f..f72680d37aad 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -5,6 +5,7 @@ \ No newline at end of file diff --git a/.idea/libraries/hamcrest.xml b/.idea/libraries/hamcrest.xml new file mode 100644 index 000000000000..b58fc0f06bcc --- /dev/null +++ b/.idea/libraries/hamcrest.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/bin/scripts/unix/idea.sh b/bin/scripts/unix/idea.sh index 03d086d3b5f0..f20ed48714d5 100755 --- a/bin/scripts/unix/idea.sh +++ b/bin/scripts/unix/idea.sh @@ -136,7 +136,10 @@ if [ -n "$@@product_uc@@_PROPERTIES" ]; then IDE_PROPERTIES_PROPERTY="-Didea.properties.file=$@@product_uc@@_PROPERTIES" fi -vm_options_file="$OS_SPECIFIC_BIN_DIR/@@vm_options@@$BITS.vmoptions" +vm_options_file="$IDE_BIN_HOME/@@vm_options@@$BITS.vmoptions" +if [ ! -r "$vm_options_file" ]; then + vm_options_file="$OS_SPECIFIC_BIN_DIR/@@vm_options@@$BITS.vmoptions" +fi user_vm_options_file="$HOME/.@@system_selector@@/@@vm_options@@$BITS.vmoptions" if [ -r "$user_vm_options_file" ]; then vm_options_file="$user_vm_options_file" @@ -184,6 +187,5 @@ LD_LIBRARY_PATH="$IDE_BIN_HOME:$LD_LIBRARY_PATH" "$JDK/jre/bin/java" \ com.intellij.idea.Main \ "$@" EC=$? -exit $EC -# test $EC -ne 88 && exit $EC -# exec "$0" "$@" +test $EC -ne 88 && exit $EC +exec "$0" "$@" diff --git a/build/conf/nsis/idea.nsi b/build/conf/nsis/idea.nsi index b763f60c489c..73c5c50deb06 100644 --- a/build/conf/nsis/idea.nsi +++ b/build/conf/nsis/idea.nsi @@ -852,10 +852,15 @@ skip_properties: ; set the current time for installation files under $INSTDIR\bin ExecCmd::exec 'copy "$INSTDIR\bin\*.*s" +,,' call winVersion - ${If} $0 == "1" + ${If} $0 == "1" ;ExecCmd::exec 'icacls "$INSTDIR" /grant %username%:F /T >"$INSTDIR"\installation_log.txt 2>"$INSTDIR"\installation_error.txt' AccessControl::GrantOnFile \ "$INSTDIR" "(S-1-5-32-545)" "GenericRead + GenericExecute" + AccessControl::GrantOnFile \ + "$INSTDIR\bin\${PRODUCT_EXE_FILE}.vmoptions" "(S-1-5-32-545)" "GenericRead + GenericWrite" + ${StrRep} $0 ${PRODUCT_EXE_FILE} ".exe" "64.exe.vmoptions" + AccessControl::GrantOnFile \ + "$INSTDIR\bin\$0" "(S-1-5-32-545)" "GenericRead + GenericWrite" ${EndIf} SectionEnd diff --git a/build/scripts/layouts.gant b/build/scripts/layouts.gant index 3beeffaec822..c120b00ad958 100644 --- a/build/scripts/layouts.gant +++ b/build/scripts/layouts.gant @@ -666,6 +666,15 @@ public def layoutCommunityPlugins(String home, boolean maySkipAndroidPlugin = fa } } +def setPluginVersionAndSince(String moduleName, String version) { + def file = new File(projectBuilder.moduleOutput(findModule(moduleName)) + "/META-INF/plugin.xml") + if (file.isFile()) { + def text = file.text + if (!text.contains("")) { + file.text = text.replace("", "\n ${version}\n \n") + } + } +} def layoutPlugin(String moduleName) { layoutPlugin(moduleName, moduleName, {}) @@ -697,6 +706,8 @@ def layoutPlugin(String pluginName, String moduleName, String jarName, Closure c return } + setPluginVersionAndSince(moduleName, requireProperty("buildNumber", requireProperty("build.number", snapshot))) + dir(pluginName) { dir("lib") { jar("${jarName}.jar") { diff --git a/java/compiler/impl/src/com/intellij/compiler/actions/GenerateAntBuildDialog.java b/java/compiler/impl/src/com/intellij/compiler/actions/GenerateAntBuildDialog.java index 8d7f05cb3daf..d19015f2677d 100644 --- a/java/compiler/impl/src/com/intellij/compiler/actions/GenerateAntBuildDialog.java +++ b/java/compiler/impl/src/com/intellij/compiler/actions/GenerateAntBuildDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -27,6 +27,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.MultiLineLabelUI; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.IdeBorderFactory; import com.intellij.ui.ScrollPaneFactory; import com.intellij.util.ArrayUtil; @@ -129,19 +130,13 @@ public class GenerateAntBuildDialog extends DialogWrapper { private void saveSettings() { final PropertiesComponent properties = PropertiesComponent.getInstance(myProject); - properties.setValue(SINGLE_FILE_PROPERTY, Boolean.toString(myRbGenerateSingleFileBuild.isSelected())); - properties.setValue(UI_FORM_PROPERTY, Boolean.toString(myCbEnableUIFormsCompilation.isSelected())); - properties.setValue(FORCE_TARGET_JDK_PROPERTY, Boolean.toString(myCbForceTargetJdk.isSelected())); - properties.setValue(BACKUP_FILES_PROPERTY, Boolean.toString(myRbBackupFiles.isSelected())); - properties.setValue(INLINE_RUNTIME_CLASSPATH_PROPERTY, Boolean.toString(myCbInlineRuntimeClasspath.isSelected())); - properties.setValue(GENERATE_IDEA_HOME_PROPERTY, Boolean.toString(myGenerateIdeaHomeProperty.isSelected())); - final String outputFileName = getOutputFileName(); - if (outputFileName.length() > 0) { - properties.setValue(OUTPUT_FILE_NAME_PROPERTY, outputFileName); - } - else { - properties.unsetValue(OUTPUT_FILE_NAME_PROPERTY); - } + properties.setValue(SINGLE_FILE_PROPERTY, myRbGenerateSingleFileBuild.isSelected()); + properties.setValue(UI_FORM_PROPERTY, myCbEnableUIFormsCompilation.isSelected()); + properties.setValue(FORCE_TARGET_JDK_PROPERTY, myCbForceTargetJdk.isSelected()); + properties.setValue(BACKUP_FILES_PROPERTY, myRbBackupFiles.isSelected()); + properties.setValue(INLINE_RUNTIME_CLASSPATH_PROPERTY, myCbInlineRuntimeClasspath.isSelected()); + properties.setValue(GENERATE_IDEA_HOME_PROPERTY, myGenerateIdeaHomeProperty.isSelected()); + properties.setValue(OUTPUT_FILE_NAME_PROPERTY, StringUtil.nullize(getOutputFileName())); } public void dispose() { diff --git a/java/compiler/impl/src/com/intellij/compiler/classFilesIndex/chainsSearch/completion/lookup/ChainCompletionMethodCallLookupElement.java b/java/compiler/impl/src/com/intellij/compiler/classFilesIndex/chainsSearch/completion/lookup/ChainCompletionMethodCallLookupElement.java index d49ac3e04cfd..a9b369bf0ae9 100644 --- a/java/compiler/impl/src/com/intellij/compiler/classFilesIndex/chainsSearch/completion/lookup/ChainCompletionMethodCallLookupElement.java +++ b/java/compiler/impl/src/com/intellij/compiler/classFilesIndex/chainsSearch/completion/lookup/ChainCompletionMethodCallLookupElement.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 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,8 +18,8 @@ package com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup; import com.intellij.codeInsight.completion.InsertionContext; import com.intellij.codeInsight.completion.JavaMethodCallElement; import com.intellij.codeInsight.completion.StaticallyImportable; -import com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.sub.SubLookupElement; import com.intellij.codeInsight.lookup.AutoCompletionPolicy; +import com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.sub.SubLookupElement; import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.application.ApplicationManager; import com.intellij.psi.PsiClass; @@ -64,7 +64,7 @@ public class ChainCompletionMethodCallLookupElement extends JavaMethodCallElemen private void configureAutoCompletionPolicy() { if (ApplicationManager.getApplication().isUnitTestMode()) { - if (PropertiesComponent.getInstance(myMethod.getProject()).getBoolean(PROP_METHODS_CHAIN_COMPLETION_AUTO_COMPLETION, false)) { + if (PropertiesComponent.getInstance(myMethod.getProject()).getBoolean(PROP_METHODS_CHAIN_COMPLETION_AUTO_COMPLETION)) { setAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE); } } diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/JavaSmartStepIntoHandler.java b/java/debugger/impl/src/com/intellij/debugger/actions/JavaSmartStepIntoHandler.java index e23f017b6de3..4cfc4ba97d7d 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/JavaSmartStepIntoHandler.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/JavaSmartStepIntoHandler.java @@ -126,6 +126,24 @@ public class JavaSmartStepIntoHandler extends JvmSmartStepIntoHandler { } } + @Override + public void visitField(PsiField field) { + TextRange range = field.getTextRange(); + if (lineRange.intersects(range)) { + //textRange.set(textRange.get().union(range)); + super.visitField(field); + } + } + + @Override + public void visitMethod(PsiMethod method) { + TextRange range = method.getTextRange(); + if (lineRange.intersects(range)) { + //textRange.set(textRange.get().union(range)); + super.visitMethod(method); + } + } + @Override public void visitStatement(PsiStatement statement) { TextRange range = statement.getTextRange(); diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/ObjectMarkupPropertiesDialog.java b/java/debugger/impl/src/com/intellij/debugger/actions/ObjectMarkupPropertiesDialog.java index 454b130307cf..727cb31f7b41 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/ObjectMarkupPropertiesDialog.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/ObjectMarkupPropertiesDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -31,6 +31,7 @@ import java.awt.*; */ public class ObjectMarkupPropertiesDialog extends ValueMarkerPresentationDialogBase { @NonNls private static final String MARK_ALL_REFERENCED_VALUES_KEY = "debugger.mark.all.referenced.values"; + private static final boolean MARK_ALL_REFERENCED_VALUES_DEFAULT_VALUE = true; private JCheckBox myCbMarkAdditionalFields; private final boolean mySuggestAdditionalMarkup; private JPanel myAdditionalPropertiesPanel; @@ -41,14 +42,14 @@ public class ObjectMarkupPropertiesDialog extends ValueMarkerPresentationDialogB mySuggestAdditionalMarkup = suggestAdditionalMarkup; myDescriptionLabel.setText("If the value is referenced by a constant field of an abstract class,\n" + "IDEA could additionally mark all values referenced from this class with the names of referencing fields."); - myCbMarkAdditionalFields.setSelected(PropertiesComponent.getInstance().getBoolean(MARK_ALL_REFERENCED_VALUES_KEY, true)); + myCbMarkAdditionalFields.setSelected(PropertiesComponent.getInstance().getBoolean(MARK_ALL_REFERENCED_VALUES_KEY, MARK_ALL_REFERENCED_VALUES_DEFAULT_VALUE)); init(); } @Override protected void doOKAction() { if (mySuggestAdditionalMarkup) { - PropertiesComponent.getInstance().setValue(MARK_ALL_REFERENCED_VALUES_KEY, Boolean.toString(myCbMarkAdditionalFields.isSelected())); + PropertiesComponent.getInstance().setValue(MARK_ALL_REFERENCED_VALUES_KEY, myCbMarkAdditionalFields.isSelected(), MARK_ALL_REFERENCED_VALUES_DEFAULT_VALUE); } super.doOKAction(); } diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerParametersRunnerConfigurable.java b/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerParametersRunnerConfigurable.java index 59073f3cd373..baf7072785b9 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerParametersRunnerConfigurable.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerParametersRunnerConfigurable.java @@ -26,7 +26,6 @@ import com.intellij.openapi.options.ShowSettingsUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.util.text.StringUtilRt; -import com.intellij.ui.PortField; import com.intellij.xdebugger.impl.settings.DebuggerConfigurable; import org.jetbrains.annotations.NotNull; @@ -40,7 +39,7 @@ public class GenericDebuggerParametersRunnerConfigurable extends SettingsEditor< private JTextField myAddressField; private JPanel myShMemPanel; private JPanel myPortPanel; - private PortField myPortField; + private JTextField myPortField; private boolean myIsLocal = false; private JButton myDebuggerSettings; private JRadioButton mySocketTransport; @@ -94,7 +93,6 @@ public class GenericDebuggerParametersRunnerConfigurable extends SettingsEditor< myPortPanel.setVisible(isSocket()); myShMemPanel.setVisible(!isSocket()); myAddressField.setEditable(!myIsLocal); - myPortField.setEditable(!myIsLocal); mySocketTransport.setEnabled(!myIsLocal); myShmemTransport.setEnabled(!myIsLocal); } @@ -142,7 +140,7 @@ public class GenericDebuggerParametersRunnerConfigurable extends SettingsEditor< private String getPort() { if (isSocket()) { - return String.valueOf(myPortField.getNumber()); + return String.valueOf(myPortField.getText()); } else { return myAddressField.getText(); @@ -150,10 +148,18 @@ public class GenericDebuggerParametersRunnerConfigurable extends SettingsEditor< } private void checkPort() throws ConfigurationException { - if (isSocket() && !myPortField.isSpecified()) { + if (isSocket() && parsePort() == 0) { throw new ConfigurationException(DebuggerBundle.message("error.text.invalid.port")); } } + private int parsePort() { + try { + return Math.max(0, Integer.parseInt(myPortField.getText())); + } + catch (NumberFormatException e) { + return 0; + } + } private void setTransport(int transport) { mySocketTransport.setSelected(transport == DebuggerSettings.SOCKET_TRANSPORT); @@ -168,7 +174,7 @@ public class GenericDebuggerParametersRunnerConfigurable extends SettingsEditor< private void setPort(String port) { if (isSocket()) { - myPortField.setNumber(StringUtilRt.parseInt(port, 0)); + myPortField.setText(String.valueOf(StringUtilRt.parseInt(port, 0))); } else { myAddressField.setText(port); diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/GenericDebuggerParametersPatcherConfigurable.form b/java/debugger/impl/src/com/intellij/debugger/ui/GenericDebuggerParametersPatcherConfigurable.form index 3cb1ef9bf190..d4c5f184e324 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/GenericDebuggerParametersPatcherConfigurable.form +++ b/java/debugger/impl/src/com/intellij/debugger/ui/GenericDebuggerParametersPatcherConfigurable.form @@ -52,11 +52,13 @@ - + - + + + diff --git a/java/execution/impl/src/com/intellij/execution/application/ApplicationRunLineMarkerProvider.java b/java/execution/impl/src/com/intellij/execution/application/ApplicationRunLineMarkerProvider.java index 47ebf9379eb9..f2297167207c 100644 --- a/java/execution/impl/src/com/intellij/execution/application/ApplicationRunLineMarkerProvider.java +++ b/java/execution/impl/src/com/intellij/execution/application/ApplicationRunLineMarkerProvider.java @@ -32,13 +32,17 @@ public class ApplicationRunLineMarkerProvider extends RunLineMarkerContributor { @Nullable @Override public Info getInfo(PsiElement e) { - if (e instanceof PsiIdentifier) { + if (isIdentifier(e)) { PsiElement element = e.getParent(); if (element instanceof PsiClass && PsiMethodUtil.findMainInClass((PsiClass)element) != null) - return new Info(ApplicationConfigurationType.getInstance().getIcon(), null, ExecutorAction.ACTIONS); + return new Info(ApplicationConfigurationType.getInstance().getIcon(), null, ExecutorAction.getActions(0)); if (element instanceof PsiMethod && "main".equals(((PsiMethod)element).getName()) && PsiMethodUtil.isMainMethod((PsiMethod)element)) - return new Info(ApplicationConfigurationType.getInstance().getIcon(), null, ExecutorAction.ACTIONS); + return new Info(ApplicationConfigurationType.getInstance().getIcon(), null, ExecutorAction.getActions(0)); } return null; } + + protected boolean isIdentifier(PsiElement e) { + return e instanceof PsiIdentifier; + } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/LibraryEditingUtil.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/LibraryEditingUtil.java index 5be63aa9861c..01bae640c333 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/LibraryEditingUtil.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/LibraryEditingUtil.java @@ -182,7 +182,7 @@ public class LibraryEditingUtil { @Override public Icon getIconFor(LibraryType aValue) { - return aValue != null ? aValue.getIcon() : PlatformIcons.LIBRARY_ICON; + return aValue != null ? aValue.getIcon(null) : PlatformIcons.LIBRARY_ICON; } @Override diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/impl/LibraryPresentationManagerImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/impl/LibraryPresentationManagerImpl.java index d5db34bcb5d3..39036239ebe3 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/impl/LibraryPresentationManagerImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/impl/LibraryPresentationManagerImpl.java @@ -38,6 +38,31 @@ import java.util.*; public class LibraryPresentationManagerImpl extends LibraryPresentationManager { private Map> myPresentationProviders; + public static List getLibraryKinds(@NotNull Library library, @Nullable StructureConfigurableContext context) { + final List result = new SmartList(); + final LibraryKind kind = ((LibraryEx)library).getKind(); + if (kind != null) { + result.add(kind); + } + final VirtualFile[] files = getLibraryFiles(library, context); + LibraryDetectionManager.getInstance().processProperties(Arrays.asList(files), new LibraryDetectionManager.LibraryPropertiesProcessor() { + @Override + public

boolean processProperties(@NotNull LibraryKind kind, @NotNull P properties) { + result.add(kind); + return true; + } + }); + return result; + } + + @NotNull + private static VirtualFile[] getLibraryFiles(@NotNull Library library, @Nullable StructureConfigurableContext context) { + if (((LibraryEx)library).isDisposed()) { + return VirtualFile.EMPTY_ARRAY; + } + return context != null ? context.getLibraryFiles(library, OrderRootType.CLASSES) : library.getFiles(OrderRootType.CLASSES); + } + private

LibraryPresentationProvider

getPresentationProvider(LibraryKind kind) { if (myPresentationProviders == null) { final Map> providers = new HashMap>(); @@ -62,9 +87,10 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager { @Override public Icon getCustomIcon(@NotNull Library library, StructureConfigurableContext context) { - final LibraryKind kind = ((LibraryEx)library).getKind(); + LibraryEx libraryEx = (LibraryEx)library; + final LibraryKind kind = libraryEx.getKind(); if (kind != null) { - return LibraryType.findByKind(kind).getIcon(); + return LibraryType.findByKind(kind).getIcon(libraryEx.getProperties()); } final List icons = getCustomIcons(library, context); if (icons.size() == 1) { @@ -83,7 +109,7 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager { public

boolean processProperties(@NotNull LibraryKind kind, @NotNull P properties) { final LibraryPresentationProvider

provider = getPresentationProvider(kind); if (provider != null) { - ContainerUtil.addIfNotNull(icons, provider.getIcon()); + ContainerUtil.addIfNotNull(icons, provider.getIcon(properties)); } return true; } @@ -117,23 +143,6 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager { }); } - public static List getLibraryKinds(@NotNull Library library, @Nullable StructureConfigurableContext context) { - final List result = new SmartList(); - final LibraryKind kind = ((LibraryEx)library).getKind(); - if (kind != null) { - result.add(kind); - } - final VirtualFile[] files = getLibraryFiles(library, context); - LibraryDetectionManager.getInstance().processProperties(Arrays.asList(files), new LibraryDetectionManager.LibraryPropertiesProcessor() { - @Override - public

boolean processProperties(@NotNull LibraryKind kind, @NotNull P properties) { - result.add(kind); - return true; - } - }); - return result; - } - @NotNull @Override public List getDescriptions(@NotNull Library library, StructureConfigurableContext context) { @@ -141,14 +150,6 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager { return getDescriptions(files, Collections.emptySet()); } - @NotNull - private static VirtualFile[] getLibraryFiles(@NotNull Library library, @Nullable StructureConfigurableContext context) { - if (((LibraryEx)library).isDisposed()) { - return VirtualFile.EMPTY_ARRAY; - } - return context != null ? context.getLibraryFiles(library, OrderRootType.CLASSES) : library.getFiles(OrderRootType.CLASSES); - } - @NotNull @Override public List getDescriptions(@NotNull VirtualFile[] classRoots, final Set excludedKinds) { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryAction.java index 42861a4e84e4..6da7c1c6a004 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryAction.java @@ -61,20 +61,6 @@ public class CreateNewLibraryAction extends DumbAwareAction { myProject = project; } - @Override - public void actionPerformed(AnActionEvent e) { - Library library = - createLibrary(myType, myLibrariesConfigurable.getTree(), myProject, myLibrariesConfigurable.getModelProvider().getModifiableModel()); - if (library == null) return; - - final BaseLibrariesConfigurable rootConfigurable = ProjectStructureConfigurable.getInstance(myProject).getConfigurableFor(library); - final DefaultMutableTreeNode - libraryNode = MasterDetailsComponent.findNodeByObject((TreeNode)rootConfigurable.getTree().getModel().getRoot(), library); - rootConfigurable.selectNodeInTree(libraryNode); - LibraryEditingUtil.showDialogAndAddLibraryToDependencies(library, myProject, true); - } - - @Nullable public static Library createLibrary(@Nullable final LibraryType type, @NotNull final JComponent parentComponent, @NotNull final Project project, @NotNull final LibrariesModifiableModel modifiableModel) { @@ -82,7 +68,8 @@ public class CreateNewLibraryAction extends DumbAwareAction { if (configuration == null) return null; final LibraryType libraryType = configuration.getLibraryType(); final Library library = modifiableModel.createLibrary( - LibraryEditingUtil.suggestNewLibraryName(modifiableModel, configuration.getDefaultLibraryName()), libraryType != null ? libraryType.getKind() : null); + LibraryEditingUtil.suggestNewLibraryName(modifiableModel, configuration.getDefaultLibraryName()), + libraryType != null ? libraryType.getKind() : null); final NewLibraryEditor editor = new NewLibraryEditor(libraryType, configuration.getProperties()); configuration.addRoots(editor); @@ -136,9 +123,22 @@ public class CreateNewLibraryAction extends DumbAwareAction { for (LibraryType type : suitableTypes) { final String actionName = type.getCreateActionName(); if (actionName != null) { - actions.add(new CreateNewLibraryAction(actionName, type.getIcon(), type, librariesConfigurable, project)); + actions.add(new CreateNewLibraryAction(actionName, type.getIcon(null), type, librariesConfigurable, project)); } } return actions.toArray(new AnAction[actions.size()]); } + + @Override + public void actionPerformed(AnActionEvent e) { + Library library = + createLibrary(myType, myLibrariesConfigurable.getTree(), myProject, myLibrariesConfigurable.getModelProvider().getModifiableModel()); + if (library == null) return; + + final BaseLibrariesConfigurable rootConfigurable = ProjectStructureConfigurable.getInstance(myProject).getConfigurableFor(library); + final DefaultMutableTreeNode + libraryNode = MasterDetailsComponent.findNodeByObject((TreeNode)rootConfigurable.getTree().getModel().getRoot(), library); + rootConfigurable.selectNodeInTree(libraryNode); + LibraryEditingUtil.showDialogAndAddLibraryToDependencies(library, myProject, true); + } } diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java index af88115801c4..0f44a9171846 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java @@ -182,7 +182,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh highlight.run(); progress.checkCanceled(); HighlightingSession highlightingSession = HighlightingSessionImpl.getHighlightingSession(file, progress); - PostHighlightingVisitor highlightingVisitor = new PostHighlightingVisitor(file, document, refCountHolder, highlightingSession); + PostHighlightingVisitor highlightingVisitor = new PostHighlightingVisitor(file, document, refCountHolder); highlightingVisitor.collectHighlights(file, holder, progress); } }); diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/PostHighlightingVisitor.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/PostHighlightingVisitor.java index 3f89ae26ff55..1d1644d7dfd5 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/PostHighlightingVisitor.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/PostHighlightingVisitor.java @@ -73,7 +73,6 @@ class PostHighlightingVisitor { @NotNull private final Project myProject; private final PsiFile myFile; @NotNull private final Document myDocument; - @NotNull private final HighlightingSession myHighlightingSession; private boolean myHasRedundantImports; private int myCurrentEntryIndex; @@ -94,19 +93,19 @@ class PostHighlightingVisitor { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { - if (myProject.isDisposed() || !myFile.isValid()) return; + if (myProject.isDisposed() || !myFile.isValid() || !myFile.isWritable()) return; IntentionAction optimizeImportsFix = QuickFixFactory.getInstance().createOptimizeImportsFix(true); - if (optimizeImportsFix.isAvailable(myProject, null, myFile) && myFile.isWritable()) { + if (optimizeImportsFix.isAvailable(myProject, null, myFile)) { optimizeImportsFix.invoke(myProject, null, myFile); } } }); } }; - Disposer.register(myHighlightingSession, invokeFixLater); + Disposer.register((DaemonProgressIndicator)progress, invokeFixLater); if (progress.isCanceled()) { Disposer.dispose(invokeFixLater); - Disposer.dispose(myHighlightingSession); + Disposer.dispose((DaemonProgressIndicator)progress); progress.checkCanceled(); } } @@ -114,9 +113,7 @@ class PostHighlightingVisitor { PostHighlightingVisitor(@NotNull PsiFile file, @NotNull Document document, - @NotNull RefCountHolder refCountHolder, - @NotNull HighlightingSession highlightingSession) throws ProcessCanceledException { - myHighlightingSession = highlightingSession; + @NotNull RefCountHolder refCountHolder) throws ProcessCanceledException { myProject = file.getProject(); myFile = file; myDocument = document; diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java index 0ae52adb5325..ade25c7b1d5d 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java @@ -206,16 +206,15 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection return false; } - public static PsiLambdaExpression replacePsiElementWithLambda(@NotNull PsiElement element, final boolean ignoreEqualsMethod) { + public static PsiExpression replacePsiElementWithLambda(@NotNull PsiElement element, final boolean ignoreEqualsMethod) { if (element instanceof PsiNewExpression) { if (!FileModificationService.getInstance().preparePsiElementForWrite(element)) return null; final PsiAnonymousClass anonymousClass = ((PsiNewExpression)element).getAnonymousClass(); - LOG.assertTrue(anonymousClass != null); + if (anonymousClass == null) return null; ChangeContextUtil.encodeContextInfo(anonymousClass, true); final PsiElement lambdaContext = anonymousClass.getParent().getParent(); - boolean validContext = LambdaUtil.isValidLambdaContext(lambdaContext); final String canonicalText = anonymousClass.getBaseClassType().getCanonicalText(); final PsiMethod method; @@ -230,10 +229,10 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection } else { method = anonymousClass.getMethods()[0]; } - LOG.assertTrue(method != null); + if (method == null) return null; final PsiCodeBlock body = method.getBody(); - LOG.assertTrue(body != null); + if (body == null) return null; final ForbiddenRefsChecker checker = new ForbiddenRefsChecker(method, anonymousClass); body.accept(checker); @@ -254,8 +253,7 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection ReplaceWithLambdaFix .giveUniqueNames(project, anonymousClass, elementFactory, body, conflictingLocals.toArray(new PsiVariable[conflictingLocals.size()])); - final String lambdaWithTypesDeclared = ReplaceWithLambdaFix.composeLambdaText(method, true); - final String withoutTypesDeclared = ReplaceWithLambdaFix.composeLambdaText(method, false); + final String withoutTypesDeclared = ReplaceWithLambdaFix.composeLambdaText(method); PsiLambdaExpression lambdaExpression = (PsiLambdaExpression)elementFactory.createExpressionFromText(withoutTypesDeclared, anonymousClass); @@ -275,47 +273,24 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection lambdaExpression.getBody().replace(singleExpr); } ChangeContextUtil.decodeContextInfo(lambdaExpression, null, null); - if (!validContext) { - final PsiParenthesizedExpression typeCast = - (PsiParenthesizedExpression)elementFactory.createExpressionFromText("((" + canonicalText + ")" + withoutTypesDeclared + ")", lambdaExpression); - final PsiExpression typeCastExpr = typeCast.getExpression(); - LOG.assertTrue(typeCastExpr != null); - final PsiExpression typeCastOperand = ((PsiTypeCastExpression)typeCastExpr).getOperand(); - LOG.assertTrue(typeCastOperand != null); - final PsiElement fromText = ((PsiLambdaExpression)typeCastOperand).getBody(); - LOG.assertTrue(fromText != null); - lambdaBody = lambdaExpression.getBody(); - LOG.assertTrue(lambdaBody != null); - fromText.replace(lambdaBody); - lambdaExpression.replace(typeCast); - return lambdaExpression; - } - PsiType interfaceType = lambdaExpression.getFunctionalInterfaceType(); - if (ReplaceWithLambdaFix.isInferred(lambdaExpression, interfaceType)) { - final PsiLambdaExpression withTypes = - (PsiLambdaExpression)elementFactory.createExpressionFromText(lambdaWithTypesDeclared, lambdaExpression); - final PsiElement withTypesBody = withTypes.getBody(); - LOG.assertTrue(withTypesBody != null); - lambdaBody = lambdaExpression.getBody(); - LOG.assertTrue(lambdaBody != null); - withTypesBody.replace(lambdaBody); - lambdaExpression = (PsiLambdaExpression)lambdaExpression.replace(withTypes); - - interfaceType = lambdaExpression.getFunctionalInterfaceType(); - if (ReplaceWithLambdaFix.isInferred(lambdaExpression, interfaceType)) { - final PsiTypeCastExpression typeCast = (PsiTypeCastExpression)elementFactory.createExpressionFromText("(" + canonicalText + ")" + withoutTypesDeclared, lambdaExpression); - final PsiExpression typeCastOperand = typeCast.getOperand(); - LOG.assertTrue(typeCastOperand instanceof PsiLambdaExpression); - final PsiElement fromText = ((PsiLambdaExpression)typeCastOperand).getBody(); - LOG.assertTrue(fromText != null); - lambdaBody = lambdaExpression.getBody(); - LOG.assertTrue(lambdaBody != null); - fromText.replace(lambdaBody); - lambdaExpression.replace(typeCast); - } + PsiTypeCastExpression typeCast = (PsiTypeCastExpression)elementFactory + .createExpressionFromText("(" + canonicalText + ")" + withoutTypesDeclared, lambdaExpression); + final PsiExpression typeCastOperand = typeCast.getOperand(); + LOG.assertTrue(typeCastOperand instanceof PsiLambdaExpression); + final PsiElement fromText = ((PsiLambdaExpression)typeCastOperand).getBody(); + LOG.assertTrue(fromText != null); + lambdaBody = lambdaExpression.getBody(); + LOG.assertTrue(lambdaBody != null); + fromText.replace(lambdaBody); + ((PsiLambdaExpression)typeCastOperand).getParameterList().replace(lambdaExpression.getParameterList()); + typeCast = (PsiTypeCastExpression)lambdaExpression.replace(typeCast); + if (RedundantCastUtil.isCastRedundant(typeCast)) { + final PsiExpression operand = typeCast.getOperand(); + LOG.assertTrue(operand != null); + return (PsiExpression)typeCast.replace(operand); } - return lambdaExpression; + return (PsiExpression)JavaCodeStyleManager.getInstance(project).shortenClassReferences(typeCast); } return null; } @@ -385,45 +360,32 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection } } - private static boolean isInferred(PsiLambdaExpression lambdaExpression, PsiType interfaceType) { - return interfaceType == null || !LambdaUtil.isLambdaFullyInferred(lambdaExpression, interfaceType) || !LambdaUtil.isFunctionalType(interfaceType); - } - - private static String composeLambdaText(PsiMethod method, final boolean appendType) { + private static String composeLambdaText(PsiMethod method) { final StringBuilder buf = new StringBuilder(); final PsiParameter[] parameters = method.getParameterList().getParameters(); - if (parameters.length != 1 || appendType) { + if (parameters.length != 1) { buf.append("("); } buf.append(StringUtil.join(parameters, new Function() { @Override public String fun(PsiParameter parameter) { - return composeParameter(parameter, appendType); + return composeParameter(parameter); } }, ",")); - if (parameters.length != 1 || appendType) { + if (parameters.length != 1) { buf.append(")"); } buf.append("-> {}"); return buf.toString(); } - private static String composeParameter(PsiParameter parameter, - boolean appendType) { - final String parameterType; - if (appendType) { - final PsiTypeElement typeElement = parameter.getTypeElement(); - parameterType = typeElement != null ? (typeElement.getText() + " ") : ""; - } - else { - parameterType = ""; - } + private static String composeParameter(PsiParameter parameter) { String parameterName = parameter.getName(); if (parameterName == null) { parameterName = ""; } - return parameterType + parameterName; + return parameterName; } } diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/LambdaCanBeMethodReferenceInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/LambdaCanBeMethodReferenceInspection.java index 6b0b3b12928c..ff96f4025ca5 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/LambdaCanBeMethodReferenceInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/LambdaCanBeMethodReferenceInspection.java @@ -19,6 +19,8 @@ import com.intellij.codeInsight.FileModificationService; import com.intellij.codeInsight.daemon.GroupNames; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Condition; +import com.intellij.openapi.util.Conditions; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; import com.intellij.psi.codeStyle.JavaCodeStyleManager; @@ -217,7 +219,26 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp } private static boolean checkQualifier(PsiElement qualifier) { - return !(qualifier instanceof PsiCallExpression); + if (qualifier == null) { + return true; + } + final Condition callExpressionCondition = Conditions.instanceOf(PsiCallExpression.class); + final Condition nonFinalFieldRefCondition = new Condition() { + @Override + public boolean value(PsiElement expression) { + if (expression instanceof PsiReferenceExpression) { + PsiElement element = ((PsiReferenceExpression)expression).resolve(); + if (element instanceof PsiField && !((PsiField)element).hasModifierProperty(PsiModifier.FINAL)) { + return true; + } + } + return false; + } + }; + return SyntaxTraverser + .psiTraverser() + .withRoot(qualifier) + .filter(Conditions.or(callExpressionCondition, nonFinalFieldRefCondition)).toList().isEmpty(); } @Nullable diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java b/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java index 64a16addf3c3..4c81a4e2a87a 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java @@ -178,7 +178,7 @@ public class ConstructorInsertHandler implements InsertHandler implements Type presentation.setIcon(DefaultLookupItemRenderer.getRawIcon(this, presentation.isReal())); presentation.setStrikeout(JavaElementLookupRenderer.isToStrikeout(this)); - presentation.setItemTextBold(getAttribute(HIGHLIGHTED_ATTR) != null); MemberLookupHelper helper = myHelper != null ? myHelper : new MemberLookupHelper(myMethod, myContainingClass, false, false); final Boolean qualify = getAttribute(FORCE_QUALIFY) != null ? Boolean.TRUE : myHelper == null ? Boolean.FALSE : null; diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaPsiClassReferenceElement.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaPsiClassReferenceElement.java index a5fcdadeaf06..6a4f29ec6020 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaPsiClassReferenceElement.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaPsiClassReferenceElement.java @@ -16,10 +16,7 @@ package com.intellij.codeInsight.completion; import com.intellij.codeInsight.TailType; -import com.intellij.codeInsight.lookup.DefaultLookupItemRenderer; -import com.intellij.codeInsight.lookup.LookupElementPresentation; -import com.intellij.codeInsight.lookup.LookupItem; -import com.intellij.codeInsight.lookup.PsiTypeLookupItem; +import com.intellij.codeInsight.lookup.*; import com.intellij.codeInsight.lookup.impl.JavaElementLookupRenderer; import com.intellij.openapi.util.ClassConditionKey; import com.intellij.openapi.util.Comparing; @@ -41,7 +38,7 @@ import java.util.Set; /** * @author peter */ -public class JavaPsiClassReferenceElement extends LookupItem { +public class JavaPsiClassReferenceElement extends LookupItem implements TypedLookupItem { public static final Key PACKAGE_NAME = Key.create("PACKAGE_NAME"); public static final ClassConditionKey CLASS_CONDITION_KEY = ClassConditionKey.create(JavaPsiClassReferenceElement.class); private final Object myClass; @@ -63,6 +60,14 @@ public class JavaPsiClassReferenceElement extends LookupItem { return myForcedPresentableName; } + @Nullable + @Override + public PsiType getType() { + PsiClass psiClass = getObject(); + final PsiSubstitutor substitutor = (PsiSubstitutor)getAttribute(LookupItem.SUBSTITUTOR); + return JavaPsiFacade.getElementFactory(psiClass.getProject()).createType(psiClass, substitutor == null ? PsiSubstitutor.EMPTY : substitutor); + } + @NotNull @Override public String getLookupString() { @@ -147,11 +152,9 @@ public class JavaPsiClassReferenceElement extends LookupItem { presentation.setIcon(DefaultLookupItemRenderer.getRawIcon(item, presentation.isReal())); } - final boolean bold = item.getAttribute(LookupItem.HIGHLIGHTED_ATTR) != null; boolean strikeout = JavaElementLookupRenderer.isToStrikeout(item); presentation.setItemText(getName(psiClass, item, diamond)); presentation.setStrikeout(strikeout); - presentation.setItemTextBold(bold); String tailText = getLocationString(item); PsiSubstitutor substitutor = (PsiSubstitutor)item.getAttribute(LookupItem.SUBSTITUTOR); diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/NullSmartCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/NullSmartCompletionContributor.java index fdfd1b3f93f0..6e433c81d280 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/NullSmartCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/NullSmartCompletionContributor.java @@ -20,7 +20,6 @@ import com.intellij.codeInsight.lookup.LookupItem; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiKeyword; import com.intellij.psi.PsiPrimitiveType; -import com.intellij.psi.PsiType; import java.util.Collection; import java.util.LinkedHashSet; @@ -53,7 +52,6 @@ public class NullSmartCompletionContributor extends CompletionContributor{ for (final ExpectedTypeInfo info : infos) { if (!(info.getType() instanceof PsiPrimitiveType)) { final LookupItem item = (LookupItem)BasicExpressionCompletionContributor.createKeywordLookupItem(parameters.getPosition(), PsiKeyword.NULL); - item.setAttribute(LookupItem.TYPE, PsiType.NULL); result.addElement(JavaSmartCompletionContributor.decorate(item, infos)); return; } diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/SmartCompletionTemplateItem.java b/java/java-impl/src/com/intellij/codeInsight/completion/SmartCompletionTemplateItem.java index 3936b22bf89d..fd5cd78f3b8d 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/SmartCompletionTemplateItem.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/SmartCompletionTemplateItem.java @@ -1,32 +1,29 @@ package com.intellij.codeInsight.completion; -import com.intellij.codeInsight.lookup.LookupItem; import com.intellij.codeInsight.lookup.TypedLookupItem; import com.intellij.codeInsight.template.Template; +import com.intellij.codeInsight.template.impl.LiveTemplateLookupElementImpl; import com.intellij.codeInsight.template.impl.TemplateImpl; import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiExpression; import com.intellij.psi.PsiType; import com.intellij.util.IncorrectOperationException; -import org.jetbrains.annotations.NonNls; /** * @author peter */ -public class SmartCompletionTemplateItem extends LookupItem