diff --git a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java index 5c4f66307ede..adc4e58fb191 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java @@ -360,7 +360,8 @@ public class BuildManager implements ApplicationComponent{ private void addMakeRequest(Runnable runnable) { myAlarm.cancelAllRequests(); - myAlarm.addRequest(runnable, MAKE_TRIGGER_DELAY); + final int delay = Math.max(50, Registry.intValue("compiler.automake.trigger.delay", MAKE_TRIGGER_DELAY)); + myAlarm.addRequest(runnable, delay); } private void runAutoMake() { diff --git a/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java b/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java index 366a7099d0da..b9b3e748665e 100644 --- a/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java +++ b/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java @@ -35,6 +35,7 @@ import junit.framework.Assert; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.util.JpsPathUtil; +import javax.swing.*; import java.io.File; import java.io.IOException; import java.util.Arrays; @@ -209,10 +210,10 @@ public abstract class BaseCompilerTestCase extends ModuleTestCase { private CompilationLog compile(final ParameterizedRunnable action) { final Ref result = Ref.create(null); final Semaphore semaphore = new Semaphore(); + semaphore.down(); UIUtil.invokeAndWaitIfNeeded(new Runnable() { @Override public void run() { - semaphore.down(); CompilerManagerImpl.testSetup(); final CompileStatusNotification callback = new CompileStatusNotification() { @@ -240,14 +241,18 @@ public abstract class BaseCompilerTestCase extends ModuleTestCase { } }); - long start = System.currentTimeMillis(); + final long start = System.currentTimeMillis(); while (!semaphore.waitFor(10)) { if (System.currentTimeMillis() - start > 60 * 1000) { throw new RuntimeException("timeout"); } + if (SwingUtilities.isEventDispatchThread()) { + UIUtil.dispatchAllInvocationEvents(); + } + } + if (SwingUtilities.isEventDispatchThread()) { UIUtil.dispatchAllInvocationEvents(); } - UIUtil.dispatchAllInvocationEvents(); return result.get(); } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java index cc7aaaa8c9aa..9e9889493213 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java @@ -799,11 +799,9 @@ public class BreakpointManager implements JDOMExternalizable { } private void removeInvalidBreakpoints() { - ApplicationManager.getApplication().assertIsDispatchThread(); ArrayList toDelete = new ArrayList(); - for (Iterator it = getBreakpoints().listIterator(); it.hasNext();) { - Breakpoint breakpoint = (Breakpoint)it.next(); + for (Breakpoint breakpoint : getBreakpoints()) { if (!breakpoint.isValid()) { toDelete.add(breakpoint); } diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateStep.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateStep.java index bd879e4c11c3..98b69580fc32 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateStep.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateStep.java @@ -89,19 +89,29 @@ public class SelectTemplateStep extends ModuleWizardStep { Messages.installHyperlinkSupport(myDescriptionPane); ProjectTemplatesFactory[] factories = ProjectTemplatesFactory.EP_NAME.getExtensions(); - final MultiMap groups = new MultiMap(); + final MultiMap groups = new MultiMap(); for (ProjectTemplatesFactory factory : factories) { for (String string : factory.getGroups()) { - groups.putValue(string, factory); + groups.putValues(string, Arrays.asList(factory.createTemplates(string, context))); + } + } + final MultiMap sorted = new MultiMap(); + // put single leafs under "Other" + for (Map.Entry> entry : groups.entrySet()) { + if (entry.getValue().size() > 1 || ArchivedTemplatesFactory.CUSTOM_GROUP.equals(entry.getKey())) { + sorted.put(entry.getKey(), entry.getValue()); + } + else { + sorted.putValues("Other", entry.getValue()); } } SimpleTreeStructure.Impl structure = new SimpleTreeStructure.Impl(new SimpleNode() { @Override public SimpleNode[] getChildren() { - return ContainerUtil.map2Array(groups.entrySet(), NO_CHILDREN, new Function>, SimpleNode>() { + return ContainerUtil.map2Array(sorted.entrySet(), NO_CHILDREN, new Function>, SimpleNode>() { @Override - public SimpleNode fun(Map.Entry> entry) { + public SimpleNode fun(Map.Entry> entry) { return new GroupNode(entry.getKey(), entry.getValue()); } }); @@ -171,33 +181,10 @@ public class SelectTemplateStep extends ModuleWizardStep { myTemplatesTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { - if (mySettingsPanel.getComponentCount() > 0) { - mySettingsPanel.remove(0); - } ProjectTemplate template = getSelectedTemplate(); - if (template != null) { - JComponent settingsPanel = template.getSettingsPanel(); - if (settingsPanel != null) { - mySettingsPanel.add(settingsPanel, BorderLayout.NORTH); - } - mySettingsPanel.setVisible(settingsPanel != null); - String description = template.getDescription(); - if (description != null) { - StringBuilder sb = new StringBuilder("'); - sb.append(description).append(""); - description = sb.toString(); - } - - myDescriptionPane.setText(description); - myDescriptionPanel.setVisible(StringUtil.isNotEmpty(description)); - } - else { - mySettingsPanel.setVisible(false); - myDescriptionPanel.setVisible(false); - } - mySettingsPanel.revalidate(); - mySettingsPanel.repaint(); + setupPanels(template); + mySequence.setType(template == null ? null : template.createModuleBuilder().getBuilderId()); + myContext.requestWizardButtonsUpdate(); } }); @@ -213,13 +200,6 @@ public class SelectTemplateStep extends ModuleWizardStep { myDescriptionPanel.setVisible(false); mySettingsPanel.setVisible(false); - TreeState state = SelectTemplateSettings.getInstance().getTreeState(); - if (state != null) { - state.applyTo(myTemplatesTree, (DefaultMutableTreeNode)myTemplatesTree.getModel().getRoot()); - } - else { - myBuilder.expandAll(null); - } new AnAction() { @Override @@ -234,12 +214,53 @@ public class SelectTemplateStep extends ModuleWizardStep { case KeyEvent.VK_DOWN: myTemplatesTree.setSelectionRow(row < myTemplatesTree.getRowCount() - 1 ? row + 1 : 0); break; - case KeyEvent.VK_ENTER: - myTemplatesTree.expandRow(row); } } } - }.registerCustomShortcutSet(new CustomShortcutSet(KeyEvent.VK_UP, KeyEvent.VK_DOWN, KeyEvent.VK_ENTER), mySearchField); + }.registerCustomShortcutSet(new CustomShortcutSet(KeyEvent.VK_UP, KeyEvent.VK_DOWN), mySearchField); + + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + TreeState state = SelectTemplateSettings.getInstance().getTreeState(); + if (state != null) { + state.applyTo(myTemplatesTree, (DefaultMutableTreeNode)myTemplatesTree.getModel().getRoot()); + } + else { + myBuilder.expandAll(null); + } + } + }); + + } + + private void setupPanels(@Nullable ProjectTemplate template) { + if (mySettingsPanel.getComponentCount() > 0) { + mySettingsPanel.remove(0); + } + if (template != null) { + JComponent settingsPanel = template.getSettingsPanel(); + if (settingsPanel != null) { + mySettingsPanel.add(settingsPanel, BorderLayout.NORTH); + } + mySettingsPanel.setVisible(settingsPanel != null); + String description = template.getDescription(); + if (StringUtil.isNotEmpty(description)) { + StringBuilder sb = new StringBuilder("'); + sb.append(description).append(""); + description = sb.toString(); + } + + myDescriptionPane.setText(description); + myDescriptionPanel.setVisible(StringUtil.isNotEmpty(description)); + } + else { + mySettingsPanel.setVisible(false); + myDescriptionPanel.setVisible(false); + } + mySettingsPanel.revalidate(); + mySettingsPanel.repaint(); } @Override @@ -368,23 +389,20 @@ public class SelectTemplateStep extends ModuleWizardStep { mySearchField = new SearchTextField(false); } - private class GroupNode extends SimpleNode { + private static class GroupNode extends SimpleNode { private final String myGroup; - private final Collection myFactories; + private final Collection myTemplates; - public GroupNode(String group, Collection factories) { + public GroupNode(String group, Collection templates) { myGroup = group; - myFactories = factories; + myTemplates = templates; } @Override public SimpleNode[] getChildren() { List children = new ArrayList(); - for (ProjectTemplatesFactory factory : myFactories) { - ProjectTemplate[] templates = factory.createTemplates(myGroup, myContext); - for (ProjectTemplate template : templates) { - children.add(new TemplateNode(template)); - } + for (ProjectTemplate template : myTemplates) { + children.add(new TemplateNode(template)); } return children.toArray(new SimpleNode[children.size()]); } diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/WizardArrowUI.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/WizardArrowUI.java index b3a51094d109..f4e4f6899dd0 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/WizardArrowUI.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/WizardArrowUI.java @@ -106,6 +106,7 @@ class WizardArrowUI extends BasicButtonUI { textRect.x = 2; textRect.y-=7; c.setForeground(UIUtil.getListForeground(myButton.isSelected())); + GraphicsUtil.setupAntialiasing(g); paintText(g, c, textRect, myButton.getText()); } } diff --git a/java/idea-ui/src/com/intellij/platform/templates/ArchivedProjectTemplate.java b/java/idea-ui/src/com/intellij/platform/templates/ArchivedProjectTemplate.java index 8e26316e3a52..07608f4d665e 100644 --- a/java/idea-ui/src/com/intellij/platform/templates/ArchivedProjectTemplate.java +++ b/java/idea-ui/src/com/intellij/platform/templates/ArchivedProjectTemplate.java @@ -15,32 +15,16 @@ */ package com.intellij.platform.templates; -import com.intellij.ide.util.newProjectWizard.modes.ImportImlMode; import com.intellij.ide.util.projectWizard.ModuleBuilder; import com.intellij.ide.util.projectWizard.WizardContext; -import com.intellij.openapi.module.ModifiableModuleModel; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleType; -import com.intellij.openapi.module.ModuleWithNameAlreadyExists; -import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.roots.ModifiableRootModel; import com.intellij.openapi.ui.ValidationInfo; import com.intellij.openapi.util.Condition; -import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.io.StreamUtil; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.newvfs.RefreshQueue; import com.intellij.platform.ProjectTemplate; -import com.intellij.platform.templates.github.ZipUtil; -import com.intellij.util.containers.ContainerUtil; -import org.jdom.JDOMException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.io.File; import java.io.IOException; import java.net.URL; import java.util.zip.ZipEntry; @@ -74,11 +58,22 @@ public class ArchivedProjectTemplate implements ProjectTemplate { @Override public String getDescription() { + return readEntry(new Condition() { + @Override + public boolean value(ZipEntry entry) { + return entry.getName().endsWith(DESCRIPTION_PATH); + } + }); + } + + @Nullable + String readEntry(Condition condition) { + ZipInputStream stream = null; try { - ZipInputStream stream = getStream(); + stream = getStream(); ZipEntry entry; while ((entry = stream.getNextEntry()) != null) { - if (entry.getName().endsWith(DESCRIPTION_PATH)) { + if (condition.value(entry)) { return StreamUtil.readText(stream); } } @@ -86,58 +81,26 @@ public class ArchivedProjectTemplate implements ProjectTemplate { catch (IOException e) { return null; } + finally { + StreamUtil.closeStream(stream); + } return null; } @NotNull @Override public ModuleBuilder createModuleBuilder() { - return new ModuleBuilder() { - @Override - public void setupRootModel(ModifiableRootModel modifiableRootModel) throws ConfigurationException { - - } - - @Override - public ModuleType getModuleType() { - return null; - } - - @NotNull - @Override - public Module createModule(@NotNull ModifiableModuleModel moduleModel) - throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException { - final String path = getContentEntryPath(); - String iml; - try { - File dir = new File(path); - ZipInputStream zipInputStream = getStream(); - ZipUtil.unzip(ProgressManager.getInstance().getProgressIndicator(), dir, zipInputStream); - VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(dir); - iml = ContainerUtil.find(dir.list(), new Condition() { - @Override - public boolean value(String s) { - return s.endsWith(".iml"); - } - }); - new File(path, iml).renameTo(new File(getModuleFilePath())); - RefreshQueue.getInstance().refresh(false, true, null, virtualFile); - } - catch (IOException e) { - throw new RuntimeException(e); - } - return ImportImlMode.setUpLoader(getModuleFilePath()).createModule(moduleModel); - } - }; + return new TemplateModuleBuilder(this); } + @Nullable @Override public ValidationInfo validateSettings() { return null; } - private ZipInputStream getStream() throws IOException { + ZipInputStream getStream() throws IOException { return new ZipInputStream(myArchivePath.openStream()); } diff --git a/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java b/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java index 861717875b44..26a014774434 100644 --- a/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java +++ b/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java @@ -99,7 +99,7 @@ public class ArchivedTemplatesFactory implements ProjectTemplatesFactory { } static String getCustomTemplatesPath() { - return PathManager.getConfigPath() + "/projectTemplates"; + return PathManager.getConfigPath() + "/resources/projectTemplates"; } @NotNull diff --git a/java/idea-ui/src/com/intellij/platform/templates/EmptyModuleTemplatesFactory.java b/java/idea-ui/src/com/intellij/platform/templates/EmptyModuleTemplatesFactory.java index 934420591f08..eb8a1fa8477d 100644 --- a/java/idea-ui/src/com/intellij/platform/templates/EmptyModuleTemplatesFactory.java +++ b/java/idea-ui/src/com/intellij/platform/templates/EmptyModuleTemplatesFactory.java @@ -39,48 +39,65 @@ public class EmptyModuleTemplatesFactory implements ProjectTemplatesFactory { @NotNull @Override public String[] getGroups() { - return new String[] {GROUP_NAME}; + List builders = ModuleBuilder.getAllBuilders(); + return ContainerUtil.map2Array(builders, String.class, new Function() { + @Override + public String fun(ModuleBuilder builder) { + return getGroupName(builder); + } + }); } @NotNull @Override public ProjectTemplate[] createTemplates(String group, WizardContext context) { List builders = ModuleBuilder.getAllBuilders(); - return ContainerUtil.map2Array(builders, ProjectTemplate.class, new Function() { - @Override - public ProjectTemplate fun(final ModuleBuilder builder) { - return new ProjectTemplate() { - @NotNull - @Override - public String getName() { - return builder.getPresentableName(); - } + for (ModuleBuilder builder : builders) { + if (getGroupName(builder).equals(group)) return new ProjectTemplate[] {new EmptyModuleTemplate(builder)}; + } + return new ProjectTemplate[0]; + } - @Nullable - @Override - public String getDescription() { - return builder.getDescription(); - } + private static String getGroupName(ModuleBuilder builder) { + String name = builder.getPresentableName(); + return name.split(" ")[0]; + } - @Nullable - @Override - public JComponent getSettingsPanel() { - return null; - } + private static class EmptyModuleTemplate implements ProjectTemplate { + private final ModuleBuilder myBuilder; - @NotNull - @Override - public ModuleBuilder createModuleBuilder() { - return builder; - } + public EmptyModuleTemplate(ModuleBuilder builder) { + myBuilder = builder; + } - @Nullable - @Override - public ValidationInfo validateSettings() { - return null; - } - }; - } - }); + @NotNull + @Override + public String getName() { + return myBuilder.getPresentableName(); + } + + @Nullable + @Override + public String getDescription() { + return myBuilder.getDescription(); + } + + @Nullable + @Override + public JComponent getSettingsPanel() { + return null; + } + + @NotNull + @Override + public ModuleBuilder createModuleBuilder() { + return myBuilder; + } + + @Nullable + @Override + public ValidationInfo validateSettings() { + return null; + } } } diff --git a/java/idea-ui/src/com/intellij/platform/templates/TemplateModuleBuilder.java b/java/idea-ui/src/com/intellij/platform/templates/TemplateModuleBuilder.java new file mode 100644 index 000000000000..b852c890992d --- /dev/null +++ b/java/idea-ui/src/com/intellij/platform/templates/TemplateModuleBuilder.java @@ -0,0 +1,108 @@ +/* + * Copyright 2000-2012 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.platform.templates; + +import com.intellij.ide.util.newProjectWizard.modes.ImportImlMode; +import com.intellij.ide.util.projectWizard.ModuleBuilder; +import com.intellij.openapi.module.*; +import com.intellij.openapi.options.ConfigurationException; +import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.roots.ModifiableRootModel; +import com.intellij.openapi.util.Condition; +import com.intellij.openapi.util.InvalidDataException; +import com.intellij.openapi.util.JDOMUtil; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.newvfs.RefreshQueue; +import com.intellij.platform.templates.github.ZipUtil; +import com.intellij.util.containers.ContainerUtil; +import org.jdom.Document; +import org.jdom.JDOMException; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.io.IOException; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +/** +* @author Dmitry Avdeev +* Date: 10/19/12 +*/ +class TemplateModuleBuilder extends ModuleBuilder { + private final ModuleType myType; + private ArchivedProjectTemplate myTemplate; + + public TemplateModuleBuilder(ArchivedProjectTemplate template) { + myTemplate = template; + myType = computeModuleType(myTemplate); + } + + @NotNull + private static ModuleType computeModuleType(ArchivedProjectTemplate template) { + String iml = template.readEntry(new Condition() { + @Override + public boolean value(ZipEntry entry) { + return entry.getName().endsWith(".iml"); + } + }); + if (iml == null) return ModuleType.EMPTY; + try { + Document document = JDOMUtil.loadDocument(iml); + String type = document.getRootElement().getAttributeValue(Module.ELEMENT_TYPE); + return ModuleTypeManager.getInstance().findByID(type); + } + catch (Exception e) { + return ModuleType.EMPTY; + } + } + + @Override + public void setupRootModel(ModifiableRootModel modifiableRootModel) throws ConfigurationException { + + } + + @Override + public ModuleType getModuleType() { + return myType; + } + + @NotNull + @Override + public Module createModule(@NotNull ModifiableModuleModel moduleModel) + throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException { + final String path = getContentEntryPath(); + String iml; + try { + File dir = new File(path); + ZipInputStream zipInputStream = myTemplate.getStream(); + ZipUtil.unzip(ProgressManager.getInstance().getProgressIndicator(), dir, zipInputStream); + VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(dir); + iml = ContainerUtil.find(dir.list(), new Condition() { + @Override + public boolean value(String s) { + return s.endsWith(".iml"); + } + }); + new File(path, iml).renameTo(new File(getModuleFilePath())); + RefreshQueue.getInstance().refresh(false, true, null, virtualFile); + } + catch (IOException e) { + throw new RuntimeException(e); + } + return ImportImlMode.setUpLoader(getModuleFilePath()).createModule(moduleModel); + } +} diff --git a/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java b/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java index 40f9d755ee95..e2e135a661f2 100644 --- a/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java +++ b/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java @@ -1037,6 +1037,7 @@ public class ExpectedTypesProvider { @NotNull final PsiMethod method, @NotNull final PsiSubstitutor substitutor, @NotNull final Set array) { + LOG.assertTrue(substitutor.isValid()); PsiParameter[] parameters = method.getParameterList().getParameters(); if (!forCompletion && parameters.length != args.length) return; if (parameters.length <= index && !method.isVarArgs()) return; @@ -1172,6 +1173,7 @@ public class ExpectedTypesProvider { private static PsiType getParameterType(@NotNull PsiParameter parameter, @NotNull PsiSubstitutor substitutor) { PsiType type = parameter.getType(); + LOG.assertTrue(type.isValid()); if (parameter.isVarArgs()) { if (type instanceof PsiArrayType) { type = ((PsiArrayType)type).getComponentType(); diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java index ca2c38a8f61b..f229536f13cc 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java @@ -376,11 +376,15 @@ public class JavaMemberNameCompletionContributor extends CompletionContributor { for (final PsiField field : fields) { if (field == element) continue; - assert field.isValid(); + + assert field.isValid() : "invalid field: " + field; + PsiType fieldType = field.getType(); + assert fieldType.isValid() : "invalid field type: " + field + "; " + fieldType; + final PsiModifierList modifierList = field.getModifierList(); if (staticContext && (modifierList != null && !modifierList.hasModifierProperty(PsiModifier.STATIC))) continue; - if (field.getType().equals(varType)) { + if (fieldType.equals(varType)) { final String getterName = PropertyUtil.suggestGetterName(field.getProject(), field); if ((psiClass.findMethodsByName(getterName, true).length == 0 || psiClass.findMethodBySignature(PropertyUtil.generateGetterPrototype(field), true) == null)) { diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java index 370d479a1a89..98a8e90fcc45 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java @@ -1280,16 +1280,23 @@ public class GenericsHighlightUtil { if (refParamList.getTypeArguments().length == 0) return null; JavaResolveResult resolveResult = null; PsiElement parent = refParamList.getParent(); + PsiElement qualifier = null; if (parent instanceof PsiJavaCodeReferenceElement) { resolveResult = ((PsiJavaCodeReferenceElement)parent).advancedResolve(false); + qualifier = ((PsiJavaCodeReferenceElement)parent).getQualifier(); } else if (parent instanceof PsiCallExpression) { resolveResult = ((PsiCallExpression)parent).resolveMethodGenerics(); + if (parent instanceof PsiMethodCallExpression) { + final PsiReferenceExpression methodExpression = ((PsiMethodCallExpression)parent).getMethodExpression(); + qualifier = methodExpression.getQualifier(); + } } if (resolveResult != null) { PsiElement element = resolveResult.getElement(); if (!(element instanceof PsiTypeParameterListOwner)) return null; if (((PsiModifierListOwner)element).hasModifierProperty(PsiModifier.STATIC)) return null; + if (qualifier instanceof PsiJavaCodeReferenceElement && ((PsiJavaCodeReferenceElement)qualifier).resolve() instanceof PsiTypeParameter) return null; PsiClass containingClass = ((PsiMember)element).getContainingClass(); if (containingClass != null && PsiUtil.isRawSubstitutor(containingClass, resolveResult.getSubstitutor())) { if ((parent instanceof PsiCallExpression || parent instanceof PsiMethodReferenceExpression) && PsiUtil.isLanguageLevel7OrHigher(parent)) { diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index 81eb619e0d43..9e74e12ad914 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -1819,13 +1819,13 @@ public class HighlightUtil { type = ((PsiReferenceExpression)qualifier).getType(); referencedClass = PsiUtil.resolveClassInType(type); } - else if (qualifier instanceof PsiThisExpression || qualifier == null) { - @SuppressWarnings({"unchecked"}) PsiMethod parent = PsiTreeUtil.getParentOfType(expression, PsiMethod.class, true, PsiMember.class); - resolved = parent; - expression = qualifier == null ? expression : qualifier; + else if (qualifier == null) { + resolved = PsiTreeUtil.getParentOfType(expression, PsiMethod.class, true, PsiMember.class); if (resolved != null) { referencedClass = ((PsiMethod)resolved).getContainingClass(); } + } else if (qualifier instanceof PsiThisExpression) { + referencedClass = PsiUtil.resolveClassInType(((PsiThisExpression)qualifier).getType()); } } if (resolved instanceof PsiField) { diff --git a/java/java-impl/src/com/intellij/codeInspection/nullable/NullableStuffInspection.java b/java/java-impl/src/com/intellij/codeInspection/nullable/NullableStuffInspection.java index 6530c36e7f55..bfd78c78ca48 100644 --- a/java/java-impl/src/com/intellij/codeInspection/nullable/NullableStuffInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/nullable/NullableStuffInspection.java @@ -174,13 +174,25 @@ public class NullableStuffInspection extends BaseLocalInspectionTool { new AddAnnotationFix(anno, parameter, ArrayUtil.toStringArray(annoToRemove))); } else if (annotated.isDeclaredNullable && manager.isNotNull(parameter, false)) { - final PsiIdentifier nameIdentifier2 = parameter.getNameIdentifier(); - assert nameIdentifier2 != null : parameter; - holder.registerProblem(nameIdentifier2, InspectionsBundle.message( - "inspection.nullable.problems.annotated.field.constructor.parameter.conflict", StringUtil.getShortName(anno), - notNullSimpleName), - ProblemHighlightType.GENERIC_ERROR_OR_WARNING, - new AddAnnotationFix(anno, parameter, ArrayUtil.toStringArray(annoToRemove))); + boolean usedAsQualifier = !ReferencesSearch.search(parameter).forEach(new Processor() { + @Override + public boolean process(PsiReference reference) { + final PsiElement element = reference.getElement(); + if (element instanceof PsiReferenceExpression && element.getParent() instanceof PsiReferenceExpression) { + return false; + } + return true; + } + }); + if (!usedAsQualifier) { + final PsiIdentifier nameIdentifier2 = parameter.getNameIdentifier(); + assert nameIdentifier2 != null : parameter; + holder.registerProblem(nameIdentifier2, InspectionsBundle.message( + "inspection.nullable.problems.annotated.field.constructor.parameter.conflict", StringUtil.getShortName(anno), + notNullSimpleName), + ProblemHighlightType.GENERIC_ERROR_OR_WARNING, + new AddAnnotationFix(anno, parameter, ArrayUtil.toStringArray(annoToRemove))); + } } } diff --git a/java/java-impl/src/resources/projectTemplates/Java/Java_Command_Line_Application.zip b/java/java-impl/src/resources/projectTemplates/Java/Java_Command_Line_Application.zip new file mode 100644 index 000000000000..528f43e665e7 Binary files /dev/null and b/java/java-impl/src/resources/projectTemplates/Java/Java_Command_Line_Application.zip differ diff --git a/java/java-indexing-api/src/com/intellij/psi/search/searches/ClassInheritorsSearch.java b/java/java-indexing-api/src/com/intellij/psi/search/searches/ClassInheritorsSearch.java index bf7b89870d83..233bb4251508 100644 --- a/java/java-indexing-api/src/com/intellij/psi/search/searches/ClassInheritorsSearch.java +++ b/java/java-indexing-api/src/com/intellij/psi/search/searches/ClassInheritorsSearch.java @@ -58,7 +58,7 @@ public class ClassInheritorsSearch extends ExtensibleQueryFactory() { diff --git a/java/java-indexing-impl/src/com/intellij/psi/impl/search/AllClassesSearchExecutor.java b/java/java-indexing-impl/src/com/intellij/psi/impl/search/AllClassesSearchExecutor.java index 84ca70fbd3b9..bae61557780e 100644 --- a/java/java-indexing-impl/src/com/intellij/psi/impl/search/AllClassesSearchExecutor.java +++ b/java/java-indexing-impl/src/com/intellij/psi/impl/search/AllClassesSearchExecutor.java @@ -66,7 +66,7 @@ public class AllClassesSearchExecutor implements QueryExecutor(); substitutorMap.put(parameter, null); } - return baseSubstitutor.putAll(PsiSubstitutorImpl.createSubstitutor(substitutorMap)); + return PsiSubstitutorImpl.createSubstitutor(substitutorMap).putAll(baseSubstitutor); } @NotNull diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsFileImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsFileImpl.java index 05cb4212fded..908095984e8c 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsFileImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsFileImpl.java @@ -305,7 +305,7 @@ public class ClsFileImpl extends ClsRepositoryPsiElement final ASTNode mirrorTreeElement = SourceTreeToPsiMap.psiElementToTree(mirror); //IMPORTANT: do not take lock too early - FileDocumentManager.getInstance().saveToString() can run write action... - final NonCancelableSection section = ProgressIndicatorProvider.getInstance().startNonCancelableSection(); + final NonCancelableSection section = ProgressIndicatorProvider.startNonCancelableSectionIfSupported(); try { setMirror((TreeElement)mirrorTreeElement); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImmediateClassType.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImmediateClassType.java index f2436d2270ee..d815bab4235f 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImmediateClassType.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImmediateClassType.java @@ -86,6 +86,7 @@ public class PsiImmediateClassType extends PsiClassType { myClass = aClass; myManager = aClass.getManager(); mySubstitutor = substitutor; + assert substitutor.isValid(); } @Override @@ -140,6 +141,7 @@ public class PsiImmediateClassType extends PsiClassType { @Override public String getCanonicalText() { if (myCanonicalText == null) { + assert mySubstitutor.isValid(); final StringBuilder buffer = new StringBuilder(); buildText(myClass, mySubstitutor, buffer, true, false); myCanonicalText = buffer.toString(); @@ -207,12 +209,14 @@ public class PsiImmediateClassType extends PsiClassType { pineBuffer.append('<'); for (int i = 0; i < typeParameters.length; i++) { PsiTypeParameter typeParameter = typeParameters[i]; + assert typeParameter.isValid(); if (i > 0) pineBuffer.append(','); final PsiType substitutionResult = substitutor.substitute(typeParameter); if (substitutionResult == null) { pineBuffer = null; break; } + assert substitutionResult.isValid(); if (canonical) { if (internal) { pineBuffer.append(substitutionResult.getInternalCanonicalText()); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java index ad1a5689aa34..e4e25c9b00c1 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java @@ -216,8 +216,8 @@ public class PsiMethodCallExpressionImpl extends ExpressionPsiElement implements } if (is15OrHigher) { final PsiSubstitutor substitutor = result.getSubstitutor(); - if (PsiUtil.isRawSubstitutor(method, substitutor)) return TypeConversionUtil.erasure(ret); PsiType substitutedReturnType = substitutor.substitute(ret); + if (substitutedReturnType == null) return TypeConversionUtil.erasure(ret); PsiType lowerBound = PsiType.NULL; if (substitutedReturnType instanceof PsiCapturedWildcardType) { lowerBound = ((PsiCapturedWildcardType)substitutedReturnType).getLowerBound(); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ThisBeforeSuper.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ThisBeforeSuper.java new file mode 100644 index 000000000000..a54084f533fa --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ThisBeforeSuper.java @@ -0,0 +1,17 @@ +class A +{ + class B + { + } +} + + +class C extends A +{ + class D extends B + { + D(){ + C.this.super(); + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/aClassLoader_hl.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/aClassLoader_hl.java index c7f959b6a630..5ad3d729e363 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/aClassLoader_hl.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/aClassLoader_hl.java @@ -1723,7 +1723,7 @@ class SystemClassLoaderAction implements (cls, true, parent); - ctor = c.getDeclaredConstructor(cp); + ctor = c.getDeclaredConstructor(cp); sys = (ClassLoader) ctor.newInstance(params); Thread.currentThread().setContextClassLoader(sys); return sys; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/TypeArgumentsGivenOnRawType.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/TypeArgumentsGivenOnRawType.java new file mode 100644 index 000000000000..147fd862fe77 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/TypeArgumentsGivenOnRawType.java @@ -0,0 +1,31 @@ +class A { + abstract class C { + void foo(T.C x) { + Integer bar = x.bar(); + } + + void foo1(A.C x) { + Integer bar = x.bar(); + } + + void foo2(A.C x) { + Integer bar = x.bar(); + } + + abstract S bar(); + } +} + +class A1 { + abstract class C { + void foo(T.C x) { + Integer bar = x.bar(); + } + + void foo1(A1.C x) { + Integer bar = x.bar(); + } + + abstract S bar(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/nullableProblems/nullableFieldNotnullParam/expected.xml b/java/java-tests/testData/inspection/nullableProblems/nullableFieldNotnullParam/expected.xml new file mode 100644 index 000000000000..407582e86f53 --- /dev/null +++ b/java/java-tests/testData/inspection/nullableProblems/nullableFieldNotnullParam/expected.xml @@ -0,0 +1,9 @@ + + + + Test.java + 8 + Constructor parameter for @Nullable field is annotated @NotNull + + + diff --git a/java/java-tests/testData/inspection/nullableProblems/nullableFieldNotnullParam/src/Test.java b/java/java-tests/testData/inspection/nullableProblems/nullableFieldNotnullParam/src/Test.java new file mode 100644 index 000000000000..5cebab7f41c0 --- /dev/null +++ b/java/java-tests/testData/inspection/nullableProblems/nullableFieldNotnullParam/src/Test.java @@ -0,0 +1,21 @@ +import org.jetbrains.annotations.*; + +class Test { + @Nullable private final String baseFile; + @Nullable private final String baseFile1; + + + public Test(@NotNull String baseFile) { + this.baseFile = baseFile; + this.baseFile1 = null; + } + + public Test(@NotNull String baseFile1, boolean a) { + this.baseFile1 = baseFile1; + if (baseFile1.contains("foo")) { + this.baseFile = null; + } else { + this.baseFile = null; + } + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java index 3ebc98e69a9c..55404d58c1ce 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java @@ -151,6 +151,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { public void testIncompatibleReturnType() throws Exception { doTest(false); } public void testContinueInferenceAfterFirstRawResult() throws Exception { doTest(false); } public void testStaticOverride() throws Exception { doTest(false); } + public void testTypeArgumentsGivenOnRawType() throws Exception { doTest(false); } public void testJavaUtilCollections_NoVerify() throws Exception { PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule())); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingPerformanceTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingPerformanceTest.java index a331e33c9cc6..92ce7d60ceac 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingPerformanceTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingPerformanceTest.java @@ -119,7 +119,7 @@ public class LightAdvHighlightingPerformanceTest extends LightDaemonAnalyzerTest public void testAClassLoader() throws Exception { List errors = doTest(Math.max(1000, 10000 - JobSchedulerImpl.CORES_COUNT * 1000)); - if (173 != errors.size()) { + if (174 != errors.size()) { doTest(getFilePath("_hl"), false, false); fail("Actual: " + errors.size()); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java index 9deb8c636bc5..9d3b286eb4cc 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java @@ -357,4 +357,5 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase { public void testClassicRethrow() throws Exception { doTest(false, false); } public void testRegexp() throws Exception { doTest(false, false); } public void testUnsupportedFeatures() throws Exception { doTest(false, false); } + public void testThisBeforeSuper() throws Exception { doTest(false, false); } } diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java index cc843df1316e..7299acd8c8e2 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/NullableStuffInspectionTest.java @@ -43,6 +43,7 @@ public class NullableStuffInspectionTest extends InspectionTestCase { public void testProblems() throws Exception{ doTest(); } public void testProblems2() throws Exception{ doTest(); } + public void testNullableFieldNotnullParam() throws Exception{ doTest(); } public void testJdk14() throws Exception{ doTest14(); } public void testGetterSetterProblems() throws Exception{ doTest(); } diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContext.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContext.java index 1c559f9da881..c03ce272ba8a 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContext.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContext.java @@ -49,6 +49,8 @@ public interface CompileContext extends UserDataHolder, MessageHandler { long getCompilationStartStamp(); + void updateCompilationStartStamp(); + void markNonIncremental(ModuleBuildTarget target); void clearNonIncrementalMark(ModuleBuildTarget target); diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContextImpl.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContextImpl.java index 853fa414bfe4..140fdb432dc9 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContextImpl.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContextImpl.java @@ -5,7 +5,8 @@ import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.util.EventDispatcher; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jps.*; +import org.jetbrains.jps.ModuleChunk; +import org.jetbrains.jps.ProjectPaths; import org.jetbrains.jps.api.CanceledStatus; import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType; import org.jetbrains.jps.builders.logging.BuildLoggingManager; @@ -34,7 +35,7 @@ public class CompileContextImpl extends UserDataHolderBase implements CompileCon private final Set myNonIncrementalModules = new HashSet(); private final ProjectPaths myProjectPaths; - private final long myCompilationStartStamp; + private volatile long myCompilationStartStamp; private final ProjectDescriptor myProjectDescriptor; private final Map myBuilderParams; private final CanceledStatus myCancelStatus; @@ -64,6 +65,11 @@ public class CompileContextImpl extends UserDataHolderBase implements CompileCon return myCompilationStartStamp; } + @Override + public void updateCompilationStartStamp() { + myCompilationStartStamp = System.currentTimeMillis(); + } + @Override public ProjectPaths getProjectPaths() { return myProjectPaths; diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java index cd5d40998a25..b335e4fbd32a 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java @@ -466,6 +466,7 @@ public class IncProjectBuilder { } } finally { + context.updateCompilationStartStamp(); pd.dataManager.closeSourceToOutputStorages(groupChunks); pd.dataManager.flush(true); } @@ -478,6 +479,7 @@ public class IncProjectBuilder { buildChunkIfAffected(context, scope, chunk); } finally { + context.updateCompilationStartStamp(); pd.dataManager.closeSourceToOutputStorages(Collections.singleton(chunk)); pd.dataManager.flush(true); } diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactRootDescriptor.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactRootDescriptor.java index 46cd3a56a584..2b3ca83ff73b 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactRootDescriptor.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactRootDescriptor.java @@ -94,6 +94,6 @@ public abstract class ArtifactRootDescriptor extends BuildRootDescriptor { @Override public boolean isGenerated() { - return true;//todo[nik] we cannot detect if this root is generated by some other compiler (e.g. javac) so threat all roots as generated for now + return false;//todo[nik] we cannot detect if this root is generated by some other compiler (e.g. javac) so treat all roots as non-generated for now } } diff --git a/platform/core-api/src/com/intellij/openapi/progress/ProgressIndicatorProvider.java b/platform/core-api/src/com/intellij/openapi/progress/ProgressIndicatorProvider.java index 31c7e5b0b1eb..70e1757acea5 100644 --- a/platform/core-api/src/com/intellij/openapi/progress/ProgressIndicatorProvider.java +++ b/platform/core-api/src/com/intellij/openapi/progress/ProgressIndicatorProvider.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.progress; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -33,8 +34,23 @@ public abstract class ProgressIndicatorProvider { protected abstract void doCheckCanceled() throws ProcessCanceledException; + @Nullable + public static ProgressIndicator getGlobalProgressIndicator() { + return ourInstance != null ? ourInstance.getProgressIndicator() : null; + } + public abstract NonCancelableSection startNonCancelableSection(); + @NotNull + public static NonCancelableSection startNonCancelableSectionIfSupported() { + return ourInstance != null ? ourInstance.startNonCancelableSection() : new NonCancelableSection() { + @Override + public void done() { + // do nothing + } + }; + } + public static boolean ourNeedToCheckCancel = false; public static void checkCanceled() throws ProcessCanceledException { // smart optimization! There's a thread started in ProgressManagerImpl, that set's this flag up once in 10 milliseconds diff --git a/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java b/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java index 9602e9463bc2..f98f1ffe1737 100644 --- a/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java +++ b/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java @@ -125,25 +125,7 @@ public class CoreApplicationEnvironment { registerApplicationExtensionPoint(ContentBasedFileSubstitutor.EP_NAME, ContentBasedFileSubstitutor.class); registerExtensionPoint(Extensions.getRootArea(), BinaryFileStubBuilders.EP_NAME, FileTypeExtensionPoint.class); - ProgressIndicatorProvider.ourInstance = new ProgressIndicatorProvider() { - @Override - public ProgressIndicator getProgressIndicator() { - return new EmptyProgressIndicator(); - } - - @Override - protected void doCheckCanceled() throws ProcessCanceledException { - } - - @Override - public NonCancelableSection startNonCancelableSection() { - return new NonCancelableSection() { - @Override - public void done() { - } - }; - } - }; + ProgressIndicatorProvider.ourInstance = createProgressIndicatorProvider(); myApplication.registerService(JobLauncher.class, new JobLauncher() { @Override @@ -194,6 +176,28 @@ public class CoreApplicationEnvironment { } + protected ProgressIndicatorProvider createProgressIndicatorProvider() { + return new ProgressIndicatorProvider() { + @Override + public ProgressIndicator getProgressIndicator() { + return new EmptyProgressIndicator(); + } + + @Override + protected void doCheckCanceled() throws ProcessCanceledException { + } + + @Override + public NonCancelableSection startNonCancelableSection() { + return new NonCancelableSection() { + @Override + public void done() { + } + }; + } + }; + } + protected VirtualFileSystem createJarFileSystem() { return new CoreJarFileSystem(); } diff --git a/platform/core-impl/src/com/intellij/extapi/psi/StubBasedPsiElementBase.java b/platform/core-impl/src/com/intellij/extapi/psi/StubBasedPsiElementBase.java index 06fbbd248ba0..aa3cb9a2c57a 100644 --- a/platform/core-impl/src/com/intellij/extapi/psi/StubBasedPsiElementBase.java +++ b/platform/core-impl/src/com/intellij/extapi/psi/StubBasedPsiElementBase.java @@ -73,7 +73,7 @@ public class StubBasedPsiElementBase extends ASTDelegateP synchronized (file.getStubLock()) { node = myNode; if (node == null) { - NonCancelableSection criticalSection = ProgressIndicatorProvider.getInstance().startNonCancelableSection(); + NonCancelableSection criticalSection = ProgressIndicatorProvider.startNonCancelableSectionIfSupported(); try { if (!file.isValid()) throw new PsiInvalidElementAccessException(this); FileElement treeElement = file.getTreeElement(); diff --git a/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java b/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java index eb8e7e9aaf3a..36f78f255abe 100644 --- a/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java +++ b/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java @@ -1053,8 +1053,7 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder, AS final MyTreeStructure treeStructure = new MyTreeStructure(newRoot, null); final MyComparator comparator = new MyComparator(getUserDataUnprotected(CUSTOM_COMPARATOR), treeStructure); - final ProgressIndicatorProvider provider = ProgressIndicatorProvider.getInstance(); - final ProgressIndicator indicator = provider != null ? provider.getProgressIndicator() : null; + final ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator(); BlockSupportImpl.diffTrees(oldRoot, builder, comparator, treeStructure, indicator); return diffLog; } diff --git a/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java index 8e14a3bb733d..5b7dff1258d3 100644 --- a/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java @@ -230,8 +230,7 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements @Nullable protected static ProgressIndicator getProgressIndicator() { - final ProgressIndicatorProvider progressManager = ProgressIndicatorProvider.getInstance(); - return progressManager != null ? progressManager.getProgressIndicator() : null; + return ProgressIndicatorProvider.getGlobalProgressIndicator(); } protected double getPercentageOfComponentsLoaded() { diff --git a/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java b/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java index 096e4958d37b..90f411c3b023 100644 --- a/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java +++ b/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java @@ -119,7 +119,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper { if (text.length() == 0) { throw new IllegalArgumentException("Cannot search for elements with empty text"); } - final ProgressIndicator progress = ProgressIndicatorProvider.getInstance().getProgressIndicator(); + final ProgressIndicator progress = ProgressIndicatorProvider.getGlobalProgressIndicator(); if (searchScope instanceof GlobalSearchScope) { StringSearcher searcher = new StringSearcher(text, caseSensitively, true); @@ -344,7 +344,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper { if (qName.length() == 0) { throw new IllegalArgumentException("Cannot search for elements with empty text"); } - final ProgressIndicator progress = ProgressIndicatorProvider.getInstance().getProgressIndicator(); + final ProgressIndicator progress = ProgressIndicatorProvider.getGlobalProgressIndicator(); int dotIndex = qName.lastIndexOf('.'); int dollarIndex = qName.lastIndexOf('$'); @@ -487,7 +487,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper { appendCollectorsFromQueryRequests(collectors); - ProgressIndicator progress = ProgressIndicatorProvider.getInstance().getProgressIndicator(); + ProgressIndicator progress = ProgressIndicatorProvider.getGlobalProgressIndicator(); do { final MultiMap, RequestWithProcessor> globals = new MultiMap, RequestWithProcessor>(); final List> customs = ContainerUtil.newArrayList(); diff --git a/platform/lang-api/src/com/intellij/formatting/ChildAttributes.java b/platform/lang-api/src/com/intellij/formatting/ChildAttributes.java index ca4265c7fb5d..88317c76b050 100644 --- a/platform/lang-api/src/com/intellij/formatting/ChildAttributes.java +++ b/platform/lang-api/src/com/intellij/formatting/ChildAttributes.java @@ -15,6 +15,8 @@ */ package com.intellij.formatting; +import org.jetbrains.annotations.Nullable; + /** * Defines the indent and alignment settings which are applied to a new child block * added to a formatting model block. Used for auto-indenting when the Enter key is pressed. @@ -35,7 +37,7 @@ public class ChildAttributes { * @param childIndent the indent for the child block. * @param alignment the alignment for the child block. */ - public ChildAttributes(final Indent childIndent, final Alignment alignment) { + public ChildAttributes(@Nullable final Indent childIndent, @Nullable final Alignment alignment) { myChildIndent = childIndent; myAlignment = alignment; } @@ -45,6 +47,7 @@ public class ChildAttributes { * * @return the indent setting. */ + @Nullable public Indent getChildIndent() { return myChildIndent; } @@ -54,6 +57,7 @@ public class ChildAttributes { * * @return the alignment setting. */ + @Nullable public Alignment getAlignment() { return myAlignment; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/QuickFixAction.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/QuickFixAction.java index e7a18342cee7..d920e2570c72 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/QuickFixAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/QuickFixAction.java @@ -94,7 +94,7 @@ public final class QuickFixAction { doRegister(info, action, null, null, fixRange, null); } - public static void unregisterQuickFixAction(HighlightInfo info, Condition condition) { + public static void unregisterQuickFixAction(@NotNull HighlightInfo info, Condition condition) { for (Iterator> it = info.quickFixActionRanges.iterator(); it.hasNext();) { Pair pair = it.next(); if (condition.value(pair.first.getAction())) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java index a51deeb2d26c..0057f067e225 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java @@ -152,6 +152,7 @@ public class IntentionHintComponent extends JPanel implements Disposable, Scroll @Override public void dispose() { + ApplicationManager.getApplication().assertIsDispatchThread(); myDisposed = true; myComponentHint.hide(); super.hide(); @@ -420,7 +421,7 @@ public class IntentionHintComponent extends JPanel implements Disposable, Scroll myPopupShown = true; } - private void recreateMyPopup(IntentionListStep step) { + private void recreateMyPopup(@NotNull IntentionListStep step) { if (myPopup != null) { Disposer.dispose(myPopup); } diff --git a/platform/lang-impl/src/com/intellij/lang/javascript/boilerplate/GithubTagListProvider.java b/platform/lang-impl/src/com/intellij/lang/javascript/boilerplate/GithubTagListProvider.java index 5deb52c5dae2..b240f62fb541 100644 --- a/platform/lang-impl/src/com/intellij/lang/javascript/boilerplate/GithubTagListProvider.java +++ b/platform/lang-impl/src/com/intellij/lang/javascript/boilerplate/GithubTagListProvider.java @@ -9,9 +9,6 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.progress.Task; import com.intellij.platform.templates.github.DownloadUtil; import com.intellij.platform.templates.github.GeneratorException; import com.intellij.platform.templates.github.GithubTagInfo; @@ -53,36 +50,30 @@ public class GithubTagListProvider { return null; } - public Task.Backgroundable updateTagListAsynchronously(final GithubProjectGeneratorPeer peer) { + public void updateTagListAsynchronously(final GithubProjectGeneratorPeer peer) { final String url = formatTagListDownloadUrl(); - Task.Backgroundable task = - new Task.Backgroundable(null, "Updating versions of " + GithubTagListProvider.this.myRepositoryName + " repository...", true, null) { - - @Override - public void run(@NotNull ProgressIndicator indicator) { - File cacheFile = getCacheFile(); - try { - DownloadUtil.downloadAtomically(indicator, url, cacheFile, myUserName, myRepositoryName); - final ImmutableSet infos = readTagsFromFile(cacheFile); - peer.setErrorMessage(null); - UIUtil.invokeLaterIfNeeded(new Runnable() { - public void run() { - peer.updateTagList(infos); - } - }); - } - catch (IOException e) { - peer.setErrorMessage("Can not fetch tag list from '" + url + "'!"); - } - catch (GeneratorException e) { - peer.setErrorMessage(getGeneratorName() + " cache update failed"); - } - } - }; - LOG.info(getGeneratorName() + " starting cache update from " + url + " ..."); - ProgressManager.getInstance().run(task); - return task; + ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { + public void run() { + File cacheFile = getCacheFile(); + try { + DownloadUtil.downloadAtomically(null, url, cacheFile, myUserName, myRepositoryName); + final ImmutableSet infos = readTagsFromFile(cacheFile); + peer.setErrorMessage(null); + UIUtil.invokeLaterIfNeeded(new Runnable() { + public void run() { + peer.updateTagList(infos); + } + }); + } + catch (IOException e) { + peer.setErrorMessage("Can not fetch tag list from '" + url + "'!"); + } + catch (GeneratorException e) { + peer.setErrorMessage(getGeneratorName() + " cache update failed"); + } + } + }); } private String getGeneratorName() { diff --git a/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java b/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java index 0075de8abdb5..5359ba955b2f 100644 --- a/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java @@ -71,7 +71,7 @@ public class ModuleStoreImpl extends BaseFileConfigurableStoreImpl implements IM super.load(); final ModuleFileData storageData = getMainStorageData(); - final String moduleTypeId = storageData.myOptions.get(ModuleImpl.ELEMENT_TYPE); + final String moduleTypeId = storageData.myOptions.get(Module.ELEMENT_TYPE); myModule.setOption(Module.ELEMENT_TYPE, ModuleTypeManager.getInstance().findByID(moduleTypeId).getId()); if (ApplicationManager.getApplication().isHeadlessEnvironment() || ApplicationManager.getApplication().isUnitTestMode()) return; diff --git a/platform/lang-impl/src/com/intellij/openapi/util/objectTree/DisposerDebugger.java b/platform/lang-impl/src/com/intellij/openapi/util/objectTree/DisposerDebugger.java index 7b4785f14c1b..388d8cbc8f58 100644 --- a/platform/lang-impl/src/com/intellij/openapi/util/objectTree/DisposerDebugger.java +++ b/platform/lang-impl/src/com/intellij/openapi/util/objectTree/DisposerDebugger.java @@ -29,10 +29,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.ui.Splitter; import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.objectTree.ObjectNode; -import com.intellij.openapi.util.objectTree.ObjectTree; -import com.intellij.openapi.util.objectTree.ObjectTreeListener; -import com.intellij.openapi.vcs.history.TextTransferrable; +import com.intellij.util.ui.TextTransferrable; import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.debugger.UiDebuggerExtension; import com.intellij.ui.speedSearch.ElementFilter; diff --git a/platform/lang-impl/src/com/intellij/platform/templates/github/DownloadUtil.java b/platform/lang-impl/src/com/intellij/platform/templates/github/DownloadUtil.java index 810a43c1fb6f..ffafbffb62eb 100644 --- a/platform/lang-impl/src/com/intellij/platform/templates/github/DownloadUtil.java +++ b/platform/lang-impl/src/com/intellij/platform/templates/github/DownloadUtil.java @@ -16,8 +16,6 @@ import org.jetbrains.annotations.Nullable; import java.io.*; import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLConnection; import java.util.Locale; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; @@ -121,7 +119,7 @@ public class DownloadUtil { }, new Producer() { @Override public Boolean produce() { - return IOExceptionDialog.showErrorDialog("Download Error", "Can not download " + url + ""); + return IOExceptionDialog.showErrorDialog("Download Error", "Can not download '" + url + "'"); } } ); @@ -204,13 +202,7 @@ public class DownloadUtil { if (progress != null) { progress.setText2("Downloading " + location); } - URL url = new URL(location); - try { - HttpConfigurable.getInstance().prepareURL(location); - } catch (IOException e) { - LOG.info("Can not prepareURL '" + location + "'", e); - } - URLConnection urlConnection = url.openConnection(); + HttpURLConnection urlConnection = HttpConfigurable.getInstance().openHttpConnection(location); try { int timeout = (int) TimeUnit.MINUTES.toMillis(2); urlConnection.setConnectTimeout(timeout); @@ -221,16 +213,21 @@ public class DownloadUtil { substituteContentLength(progress, originalText, contentLength); NetUtils.copyStreamContent(progress, in, output, contentLength); } catch (IOException e) { - if (urlConnection instanceof HttpURLConnection) { - HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection; - LOG.warn("Can not download '" + location - + "', response code: " + httpURLConnection.getResponseCode() - + ", response message: " + httpURLConnection.getResponseMessage() - + ", headers: " + httpURLConnection.getHeaderFields() - ); - } + LOG.warn("Can not download '" + location + + "', response code: " + urlConnection.getResponseCode() + + ", response message: " + urlConnection.getResponseMessage() + + ", headers: " + urlConnection.getHeaderFields(), + e + ); throw e; } + finally { + try { + urlConnection.disconnect(); + } catch (Exception e) { + LOG.warn("Exception at disconnect()", e); + } + } } private static void substituteContentLength(@Nullable ProgressIndicator progress, @Nullable String text, int contentLengthInBytes) { diff --git a/platform/lang-impl/src/com/intellij/ui/popup/util/DetailViewImpl.java b/platform/lang-impl/src/com/intellij/ui/popup/util/DetailViewImpl.java index ba498473a21c..1d4b60920cec 100644 --- a/platform/lang-impl/src/com/intellij/ui/popup/util/DetailViewImpl.java +++ b/platform/lang-impl/src/com/intellij/ui/popup/util/DetailViewImpl.java @@ -193,7 +193,7 @@ public class DetailViewImpl extends JPanel implements DetailView, UserDataHolder if (panel != null) { if (myDetailPanelWrapper == null) { myDetailPanelWrapper = new JPanel(new GridLayout(1, 1)); - myDetailPanelWrapper.setBorder(IdeBorderFactory.createEmptyBorder(5, 30, 5, 30)); + myDetailPanelWrapper.setBorder(IdeBorderFactory.createEmptyBorder(5, 30, 5, 5)); myDetailPanelWrapper.add(panel); add(myDetailPanelWrapper, BorderLayout.NORTH); diff --git a/platform/lang-impl/src/com/intellij/ui/popup/util/MasterDetailPopupBuilder.java b/platform/lang-impl/src/com/intellij/ui/popup/util/MasterDetailPopupBuilder.java index adb3af88de43..f985ab989e1c 100644 --- a/platform/lang-impl/src/com/intellij/ui/popup/util/MasterDetailPopupBuilder.java +++ b/platform/lang-impl/src/com/intellij/ui/popup/util/MasterDetailPopupBuilder.java @@ -22,6 +22,7 @@ import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.JBPopupListener; import com.intellij.openapi.ui.popup.LightweightWindowEvent; import com.intellij.openapi.ui.popup.PopupChooserBuilder; +import com.intellij.openapi.util.DimensionService; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.ui.*; @@ -30,6 +31,7 @@ import com.intellij.ui.speedSearch.FilteringListModel; import com.intellij.util.Function; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.tree.TreeUtil; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -58,6 +60,7 @@ public class MasterDetailPopupBuilder implements MasterController { private boolean myCancelOnClickOutside; private final DetailController myDetailController = new DetailController(this); + private JSplitPane mySplitPane; public String getDimensionServiceKey() { @@ -152,11 +155,6 @@ public class MasterDetailPopupBuilder implements MasterController { setCancelOnClickOutside(myCancelOnClickOutside); - if (myAddDetailViewToEast) { - builder. - setEastComponent((JComponent)myDetailView); - } - if (myDoneRunnable != null) { ActionListener actionListener = new ActionListener() { @@ -220,6 +218,11 @@ public class MasterDetailPopupBuilder implements MasterController { @Override public void onClosed(LightweightWindowEvent event) { myDetailView.clearEditor(); + if (mySplitPane != null) { + final DimensionService dimensionService = DimensionService.getInstance(); + dimensionService.setSize(getSplitterDimensionKey(), + new Dimension(mySplitPane.getDividerLocation(), 0)); + } } }); @@ -244,10 +247,10 @@ public class MasterDetailPopupBuilder implements MasterController { private PopupChooserBuilder createInnerBuilder() { if (myChooserComponent instanceof JList) { - return new PopupChooserBuilder((JList)myChooserComponent); + return new MyPopupChooserBuilder((JList)myChooserComponent); } else if (myChooserComponent instanceof JTree) { - return new PopupChooserBuilder((JTree)myChooserComponent); + return new MyPopupChooserBuilder((JTree)myChooserComponent); } return null; } @@ -338,6 +341,9 @@ public class MasterDetailPopupBuilder implements MasterController { } } else { + if (!allowedToRemoveItems(getSelectedItems()) ) { + return; + } final Object[] items = getSelectedItems(); JTree tree = (JTree)myChooserComponent; TreeUtil.removeSelected(tree); @@ -445,4 +451,40 @@ public class MasterDetailPopupBuilder implements MasterController { return this; } } + + private class MyPopupChooserBuilder extends PopupChooserBuilder { + public MyPopupChooserBuilder(@NotNull JList list) { + super(list); + } + + private MyPopupChooserBuilder(@NotNull JTree tree) { + super(tree); + } + + @Override + protected void addCenterComponentToContentPane(JPanel contentPane, JComponent component) { + if (myAddDetailViewToEast) { + mySplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, component, (JComponent)myDetailView); + + final DimensionService dimensionService = DimensionService.getInstance(); + Dimension size = dimensionService.getSize(getSplitterDimensionKey()); + if (size != null) { + mySplitPane.setDividerLocation((int)size.getWidth()); + } + + mySplitPane.setResizeWeight(0.5); + mySplitPane.setOneTouchExpandable(true); + mySplitPane.setContinuousLayout(true); + + contentPane.add(mySplitPane, BorderLayout.CENTER); + } + else { + super.addCenterComponentToContentPane(contentPane, component); + } + } + } + + private String getSplitterDimensionKey() { + return myDimensionServiceKey + ".splitter"; + } } diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java index ff8b4b37f30a..29a65da83d73 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java @@ -736,11 +736,11 @@ public class AbstractTreeUi { expand(getRootNode(), true); } ActionCallback callback; - if (!willUpdate) { - callback = updateNodeChildren(getRootNode(), pass, null, false, false, false, true, true); + if (willUpdate) { + callback = new ActionCallback.Done(); } else { - callback = new ActionCallback.Done(); + callback = updateNodeChildren(getRootNode(), pass, null, false, false, false, true, true); } callback.doWhenDone(new Runnable() { @Override @@ -912,7 +912,7 @@ public class AbstractTreeUi { @Override public void run(final Boolean changes) { if (changes) { - invokeLaterIfNeeded(false, new Runnable() { + invokeLaterIfNeeded(true, new Runnable() { @Override public void run() { Object element = nodeDescriptor.getElement(); @@ -2177,11 +2177,6 @@ public class AbstractTreeUi { } } - private void scheduleMaybeReady() { - myMaybeReady.cancelAllRequests(); - myMaybeReady.addRequest(myMaybeReadyRunnable, Registry.intValue("ide.tree.waitForReadySchedule")); - } - private void flushPendingNodeActions() { final DefaultMutableTreeNode[] nodes = myPendingNodeActions.toArray(new DefaultMutableTreeNode[myPendingNodeActions.size()]); myPendingNodeActions.clear(); @@ -4020,10 +4015,6 @@ public class AbstractTreeUi { myRevalidatedObjects.add(element); AsyncResult revalidated = getBuilder().revalidateElement(element); - if (revalidated == null) { - runDone(onDone); - return; - } revalidated.doWhenDone(new AsyncResult.Handler() { @Override diff --git a/platform/platform-api/src/com/intellij/openapi/ui/popup/PopupChooserBuilder.java b/platform/platform-api/src/com/intellij/openapi/ui/popup/PopupChooserBuilder.java index 64008547fe74..47af5ebc3716 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/popup/PopupChooserBuilder.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/popup/PopupChooserBuilder.java @@ -19,6 +19,7 @@ package com.intellij.openapi.ui.popup; import com.intellij.openapi.actionSystem.DataProvider; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.util.Computable; +import com.intellij.openapi.util.DimensionService; import com.intellij.openapi.util.Pair; import com.intellij.ui.*; import com.intellij.ui.awt.RelativePoint; @@ -263,18 +264,18 @@ public class PopupChooserBuilder { ((JComponent)myScrollPane.getViewport().getView()).setBorder(BorderFactory.createEmptyBorder(viewportPadding.top, viewportPadding.left, viewportPadding.bottom, viewportPadding.right)); if (myChooserComponent instanceof ListWithFilter) { - contentPane.add(myChooserComponent, BorderLayout.CENTER); + addCenterComponentToContentPane(contentPane, myChooserComponent); } else { - contentPane.add(myScrollPane, BorderLayout.CENTER); + addCenterComponentToContentPane(contentPane, myScrollPane); } if (mySouthComponent != null) { - contentPane.add(mySouthComponent, BorderLayout.SOUTH); + addSouthComponentToContentPane(contentPane, mySouthComponent); } if (myEastComponent != null) { - contentPane.add(myEastComponent, BorderLayout.EAST); + addEastComponentToContentPane(contentPane, myEastComponent); } ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(contentPane, myChooserComponent); @@ -314,6 +315,19 @@ public class PopupChooserBuilder { return myPopup; } + protected void addEastComponentToContentPane(JPanel contentPane, JComponent component) { + contentPane.add(component, BorderLayout.EAST); + } + + protected void addSouthComponentToContentPane(JPanel contentPane, JComponent component) { + contentPane.add(component, BorderLayout.SOUTH); + } + + protected void addCenterComponentToContentPane(JPanel contentPane, JComponent component) { + contentPane.add(component, BorderLayout.CENTER); + } + + public PopupChooserBuilder setMinSize(final Dimension dimension) { myMinSize = dimension; return this; diff --git a/platform/platform-api/src/com/intellij/util/net/HttpConfigurable.java b/platform/platform-api/src/com/intellij/util/net/HttpConfigurable.java index 81751a2f6793..0625791eff97 100644 --- a/platform/platform-api/src/com/intellij/util/net/HttpConfigurable.java +++ b/platform/platform-api/src/com/intellij/util/net/HttpConfigurable.java @@ -16,6 +16,7 @@ package com.intellij.util.net; import com.btr.proxy.search.ProxySearch; +import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.components.*; import com.intellij.openapi.options.ShowSettingsUtil; import com.intellij.openapi.util.InvalidDataException; @@ -28,6 +29,7 @@ import com.intellij.util.xmlb.XmlSerializerUtil; import com.intellij.util.xmlb.annotations.Transient; import org.apache.commons.codec.binary.Base64; import org.jdom.Element; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.io.IOException; @@ -104,7 +106,7 @@ public class HttpConfigurable implements PersistentStateComponent 0) { - final ProgressIndicator progressIndicator = myProject.isDefault() ? null : ProgressIndicatorProvider.getInstance().getProgressIndicator(); + final ProgressIndicator progressIndicator = myProject.isDefault() ? null : ProgressIndicatorProvider.getGlobalProgressIndicator(); if (progressIndicator != null) { progressIndicator.setText("Loading modules..."); progressIndicator.setText2(""); diff --git a/platform/projectModel-impl/src/com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java index 3d4624840112..be9715fff9a5 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java @@ -32,6 +32,7 @@ import com.intellij.util.containers.ContainerUtil; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashSet; @@ -89,7 +90,7 @@ public class ProjectJdkImpl extends UserDataHolderBase implements JDOMExternaliz } @Override - public final void setVersionString(String versionString) { + public final void setVersionString(@Nullable String versionString) { myVersionString = versionString == null || versionString.isEmpty() ? null : versionString; myVersionDefined = true; } diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java index 6844fc83e74d..d6b4c35c6824 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java @@ -634,8 +634,7 @@ public class DirectoryIndexImpl extends DirectoryIndex { } protected void doInitialize(boolean reverseAllSets/* for testing order independence*/) { - final ProgressIndicatorProvider progressIndicatorProvider = ProgressIndicatorProvider.getInstance(); - ProgressIndicator progress = progressIndicatorProvider == null ? null : progressIndicatorProvider.getProgressIndicator(); + ProgressIndicator progress = ProgressIndicatorProvider.getGlobalProgressIndicator(); if (progress == null) progress = new EmptyProgressIndicator(); progress.pushState(); diff --git a/platform/util/src/com/intellij/util/containers/LimitedPool.java b/platform/util/src/com/intellij/util/containers/LimitedPool.java index 8bca28605496..61344fa9bdce 100644 --- a/platform/util/src/com/intellij/util/containers/LimitedPool.java +++ b/platform/util/src/com/intellij/util/containers/LimitedPool.java @@ -57,7 +57,7 @@ public class LimitedPool { } private void ensureCapacity() { - if (storage.length <= index + 1) { + if (storage.length <= index) { int newCapacity = Math.min(capacity, storage.length * 3 / 2); Object[] newStorage = new Object[newCapacity]; System.arraycopy(storage, 0, newStorage, 0, storage.length); diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/FileHolder.java b/platform/vcs-api/src/com/intellij/openapi/vcs/FileHolder.java index ee27e55cd0ea..ebe2cc62577e 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/FileHolder.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/FileHolder.java @@ -76,4 +76,13 @@ public class FileHolder { public void setIsDir(boolean isDir) { myIsDir = isDir; } + + @Override + public String toString() { + return "FileHolder{" + + "myIoFile=" + myIoFile + + ", myFile=" + myFile + + ", myIsDir=" + myIsDir + + '}'; + } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/CopyRevisionNumberAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/CopyRevisionNumberAction.java index 4d42e9eabdb2..65632a112022 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/CopyRevisionNumberAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/CopyRevisionNumberAction.java @@ -21,7 +21,7 @@ import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.localVcs.UpToDateLineNumberProvider; import com.intellij.openapi.vcs.annotate.FileAnnotation; import com.intellij.openapi.vcs.annotate.LineNumberListener; -import com.intellij.openapi.vcs.history.TextTransferrable; +import com.intellij.util.ui.TextTransferrable; import com.intellij.openapi.vcs.history.VcsRevisionNumber; /** diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java index 15e71e12cb1e..19f91605f350 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java @@ -633,11 +633,12 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec handleUpdateException(e); } } + } catch (ProcessCanceledException ignore) { } catch (Throwable t) { LOG.debug(t); Rethrow.reThrowRuntime(t); } finally { - if (! myUpdater.isStopped()) { + if (!myUpdater.isStopped()) { dataHolder.notifyDoneProcessingChanges(); } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsDirtyScopeImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsDirtyScopeImpl.java index c2542fb3bfda..de0d9b6fa6a0 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsDirtyScopeImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsDirtyScopeImpl.java @@ -419,7 +419,7 @@ public class VcsDirtyScopeImpl extends VcsModifiableDirtyScope { THashSet dirsByRoot = myDirtyDirectoriesRecursively.get(root); if (dirsByRoot != null) { for (FilePath dir : dirsByRoot) { - final VirtualFile vFile = dir.getVirtualFile(); + final VirtualFile vFile = obtainVirtualFile(dir); if (vFile != null && vFile.isValid()) { myVcsManager.iterateVfUnderVcsRoot(vFile, processor); } @@ -431,13 +431,13 @@ public class VcsDirtyScopeImpl extends VcsModifiableDirtyScope { final THashSet files = myDirtyFiles.get(root); if (files != null) { for (FilePath file : files) { - if (file.getVirtualFile() != null) { - processor.process(file.getVirtualFile()); - } - final VirtualFile vFile = file.getVirtualFile(); - if (vFile != null && vFile.isValid() && vFile.isDirectory()) { - for (VirtualFile child : vFile.getChildren()) { - processor.process(child); + VirtualFile vFile = obtainVirtualFile(file); + if (vFile != null && vFile.isValid()) { + processor.process(vFile); + if (vFile.isDirectory()) { + for (VirtualFile child : vFile.getChildren()) { + processor.process(child); + } } } } @@ -445,6 +445,12 @@ public class VcsDirtyScopeImpl extends VcsModifiableDirtyScope { } } + @Nullable + private static VirtualFile obtainVirtualFile(FilePath file) { + VirtualFile vFile = file.getVirtualFile(); + return vFile == null ? VfsUtil.findFileByIoFile(file.getIOFile(), false) : vFile; + } + @Override public boolean isEmpty() { return myDirtyDirectoriesRecursively.isEmpty() && myDirtyFiles.isEmpty(); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/IncomingChangesIndicator.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/IncomingChangesIndicator.java index 225d9089ea35..6ff8cee677f1 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/IncomingChangesIndicator.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/IncomingChangesIndicator.java @@ -22,10 +22,7 @@ import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; -import com.intellij.openapi.vcs.AbstractVcs; -import com.intellij.openapi.vcs.ProjectLevelVcsManager; -import com.intellij.openapi.vcs.VcsBundle; -import com.intellij.openapi.vcs.VcsListener; +import com.intellij.openapi.vcs.*; import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager; import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList; import com.intellij.openapi.wm.*; @@ -98,7 +95,8 @@ public class IncomingChangesIndicator { private boolean needIndicator() { final AbstractVcs[] vcss = ProjectLevelVcsManager.getInstance(myProject).getAllActiveVcss(); for (AbstractVcs vcs : vcss) { - if (vcs.getCachingCommittedChangesProvider() != null) { + CachingCommittedChangesProvider provider = vcs.getCachingCommittedChangesProvider(); + if (provider != null && provider.supportsIncomingChanges()) { return true; } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/OutdatedVersionNotifier.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/OutdatedVersionNotifier.java index 7554afd4f093..03df6d2e2fd6 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/OutdatedVersionNotifier.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/OutdatedVersionNotifier.java @@ -25,6 +25,7 @@ import com.intellij.openapi.fileEditor.FileEditorManagerListener; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.vcs.CachingCommittedChangesProvider; import com.intellij.openapi.vcs.VcsBundle; import com.intellij.openapi.vcs.changes.Change; import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList; @@ -150,6 +151,9 @@ public class OutdatedVersionNotifier implements ProjectComponent { } private void initPanel(final CommittedChangeList list, final Change c, final FileEditor editor) { + if (!isIncomingChangesSupported(list)) { + return; + } final OutdatedRevisionPanel component = new OutdatedRevisionPanel(list, c); editor.putUserData(PANEL_KEY, component); myFileEditorManager.addTopComponent(editor, component); @@ -205,4 +209,9 @@ public class OutdatedVersionNotifier implements ProjectComponent { updateLabelText(c); } } + + private static boolean isIncomingChangesSupported(@NotNull CommittedChangeList list) { + CachingCommittedChangesProvider provider = list.getVcs().getCachingCommittedChangesProvider(); + return provider != null && provider.supportsIncomingChanges(); + } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java index b4f3038e1957..08ce3adf78e2 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java @@ -67,10 +67,7 @@ import com.intellij.ui.dualView.DualViewColumnInfo; import com.intellij.ui.table.TableView; import com.intellij.util.*; import com.intellij.util.text.DateFormatUtil; -import com.intellij.util.ui.ColumnInfo; -import com.intellij.util.ui.StatusText; -import com.intellij.util.ui.TableViewModel; -import com.intellij.util.ui.UIUtil; +import com.intellij.util.ui.*; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/imports/ImportsAreUsedVisitor.java b/plugins/InspectionGadgets/src/com/siyeh/ig/imports/ImportsAreUsedVisitor.java index 6753839eb83d..ecdfbbb4be33 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/imports/ImportsAreUsedVisitor.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/imports/ImportsAreUsedVisitor.java @@ -44,14 +44,12 @@ class ImportsAreUsedVisitor extends JavaRecursiveElementVisitor { } @Override - public void visitReferenceElement( - @NotNull PsiJavaCodeReferenceElement reference) { + public void visitReferenceElement(@NotNull PsiJavaCodeReferenceElement reference) { followReferenceToImport(reference); super.visitReferenceElement(reference); } - private void followReferenceToImport( - PsiJavaCodeReferenceElement reference) { + private void followReferenceToImport(PsiJavaCodeReferenceElement reference) { if (reference.getQualifier() != null) { // it's already fully qualified, so the import statement wasn't // responsible @@ -89,8 +87,14 @@ class ImportsAreUsedVisitor extends JavaRecursiveElementVisitor { final String referenceName; if (element instanceof PsiMember) { final PsiMember member = (PsiMember)element; - referenceClass = member.getContainingClass(); - referenceName = member.getName(); + if (member instanceof PsiClass && !member.hasModifierProperty(PsiModifier.STATIC)) { + referenceClass = null; + referenceName = null; + } + else { + referenceClass = member.getContainingClass(); + referenceName = member.getName(); + } } else { referenceClass = null; diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/imports/unused/Constants.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/imports/unused/Constants.java index 6d8e9caff9ff..8aeb52ef35be 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/imports/unused/Constants.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/imports/unused/Constants.java @@ -4,4 +4,7 @@ public class Constants { public static final int SIZE = 213; + private int field = 0; // I'm not an utility class. + public static void instanceMatMethod() {} + @SuppressWarnings("InnerClassMayBeStatic") public class InstanceInnerMaterial {} } \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/imports/unused/UnusedImport.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/imports/unused/UnusedImport.java index adab39f11837..bbe03b5073f7 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/imports/unused/UnusedImport.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/imports/unused/UnusedImport.java @@ -6,6 +6,8 @@ import static java.lang.Math.*; import static java.lang.Integer.SIZE; import java.util.List; import java.util.ArrayList; +import static com.siyeh.igtest.imports.unused.Constants.*; +import com.siyeh.igtest.imports.unused.Constants.*; public class UnusedImport { @@ -22,4 +24,9 @@ public class UnusedImport { list.add(i); Entry entry; } + + public void context() { + instanceMatMethod(); + InstanceInnerMaterial innerMaterial = new Constants().new InstanceInnerMaterial(); + } } \ No newline at end of file diff --git a/plugins/android/src/org/jetbrains/android/uipreview/SimpleLogger.java b/plugins/android/src/org/jetbrains/android/uipreview/SimpleLogger.java index c0197f417194..368cceedf544 100644 --- a/plugins/android/src/org/jetbrains/android/uipreview/SimpleLogger.java +++ b/plugins/android/src/org/jetbrains/android/uipreview/SimpleLogger.java @@ -38,7 +38,12 @@ class SimpleLogger extends LayoutLog implements ISdkLog, ILogger { myLog.debug(s); if (myProject != null) { - myMessages.add(FixableIssueMessage.createExceptionIssue(myProject, s, throwable)); + if (throwable != null) { + myMessages.add(FixableIssueMessage.createExceptionIssue(myProject, s, throwable)); + } + else { + myMessages.add(new FixableIssueMessage(s)); + } } } @@ -56,7 +61,12 @@ class SimpleLogger extends LayoutLog implements ISdkLog, ILogger { myLog.debug(s); if (myProject != null) { - myMessages.add(FixableIssueMessage.createExceptionIssue(myProject, s, throwable)); + if (throwable != null) { + myMessages.add(FixableIssueMessage.createExceptionIssue(myProject, s, throwable)); + } + else { + myMessages.add(new FixableIssueMessage(s)); + } } } @@ -74,7 +84,12 @@ class SimpleLogger extends LayoutLog implements ISdkLog, ILogger { myLog.debug(s); if (myProject != null) { - myMessages.add(FixableIssueMessage.createExceptionIssue(myProject, s, t)); + if (t != null) { + myMessages.add(FixableIssueMessage.createExceptionIssue(myProject, s, t)); + } + else { + myMessages.add(new FixableIssueMessage(s)); + } } } diff --git a/plugins/eclipse/src/org/jetbrains/idea/eclipse/config/EclipseModuleManager.java b/plugins/eclipse/src/org/jetbrains/idea/eclipse/config/EclipseModuleManager.java index 69b6268935e8..90e4356661e7 100644 --- a/plugins/eclipse/src/org/jetbrains/idea/eclipse/config/EclipseModuleManager.java +++ b/plugins/eclipse/src/org/jetbrains/idea/eclipse/config/EclipseModuleManager.java @@ -208,6 +208,8 @@ public class EclipseModuleManager implements PersistentStateComponent{ } public void loadState(Element state) { + clear(); + for (Object o : state.getChildren(LIBELEMENT)) { myEclipseUrls.add(((Element)o).getAttributeValue(VALUE_ATTR)); } @@ -233,6 +235,13 @@ public class EclipseModuleManager implements PersistentStateComponent{ } } + private void clear() { + myEclipseUrls.clear(); + myEclipseVariablePaths.clear(); + myUnknownCons.clear(); + mySrcPlace.clear(); + } + public void setExpectedModuleSourcePlace(int expectedModuleSourcePlace) { myExpectedModuleSourcePlace = expectedModuleSourcePlace; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/constructors/GroovyGenerateConstructorHandler.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/constructors/GroovyGenerateConstructorHandler.java index ae9e07820f3d..c2a94b4e9cea 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/constructors/GroovyGenerateConstructorHandler.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/constructors/GroovyGenerateConstructorHandler.java @@ -16,6 +16,7 @@ package org.jetbrains.plugins.groovy.actions.generate.constructors; import com.intellij.codeInsight.generation.*; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; @@ -39,6 +40,7 @@ import java.util.List; * Date: 21.05.2008 */ public class GroovyGenerateConstructorHandler extends GenerateConstructorHandler { + private static final Logger LOG = Logger.getInstance(GroovyGenerateConstructorHandler.class); private static final String DEF_PSEUDO_ANNO = "_____intellij_idea_rulez_def_"; @@ -53,6 +55,8 @@ public class GroovyGenerateConstructorHandler extends GenerateConstructorHandler if (classMember instanceof PsiMethodMember) { final PsiMethod method = ((PsiMethodMember)classMember).getElement(); final PsiMethod copy = (PsiMethod)method.copy(); + LOG.assertTrue(copy != null, method.getClass().getName()); + if (copy instanceof GrMethod) { for (GrParameter parameter : ((GrMethod)copy).getParameterList().getParameters()) { if (parameter.getTypeElementGroovy() == null) { @@ -62,11 +66,13 @@ public class GroovyGenerateConstructorHandler extends GenerateConstructorHandler } res.add(new PsiMethodMember(factory.createMethodFromText(GroovyToJavaGenerator.generateMethodStub(copy), method))); - } else if (classMember instanceof PsiFieldMember) { - final PsiField field = ((PsiFieldMember) classMember).getElement(); + } + else if (classMember instanceof PsiFieldMember) { + final PsiField field = ((PsiFieldMember)classMember).getElement(); String prefix = field instanceof GrField && ((GrField)field).getTypeElementGroovy() == null ? DEF_PSEUDO_ANNO : ""; - res.add(new PsiFieldMember(factory.createFieldFromText(field.getType().getCanonicalText() + " " + prefix + field.getName(), aClass))); + res.add( + new PsiFieldMember(factory.createFieldFromText(field.getType().getCanonicalText() + " " + prefix + field.getName(), aClass))); } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/untypedUnresolvedAccess/GrUnresolvedAccessInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/untypedUnresolvedAccess/GrUnresolvedAccessInspection.java index 8391df9b3e8a..7a166c589df3 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/untypedUnresolvedAccess/GrUnresolvedAccessInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/untypedUnresolvedAccess/GrUnresolvedAccessInspection.java @@ -220,9 +220,10 @@ public class GrUnresolvedAccessInspection extends GroovySuppressableInspectionTo if (cannotBeDynamic || shouldHighlightAsUnresolved(ref)) { HighlightInfo info = createAnnotationForRef(ref, cannotBeDynamic, GroovyBundle.message("cannot.resolve", ref.getReferenceName())); + LOG.assertTrue(info != null); HighlightDisplayKey displayKey = HighlightDisplayKey.find(SHORT_NAME); - if (isCall(ref)) { + if (ref.getParent() instanceof GrMethodCall) { registerStaticImportFix(ref, info, displayKey); } else { @@ -377,7 +378,7 @@ public class GrUnresolvedAccessInspection extends GroovySuppressableInspectionTo return HighlightInfo.createHighlightInfo(highlightInfoType, refNameElement, message); } - private static void registerStaticImportFix(GrReferenceExpression referenceExpression, HighlightInfo info, final HighlightDisplayKey key) { + private static void registerStaticImportFix(@NotNull GrReferenceExpression referenceExpression, @Nullable HighlightInfo info, @Nullable final HighlightDisplayKey key) { final String referenceName = referenceExpression.getReferenceName(); if (StringUtil.isEmpty(referenceName)) return; if (referenceExpression.getQualifier() != null) return; @@ -436,7 +437,7 @@ public class GrUnresolvedAccessInspection extends GroovySuppressableInspectionTo } } - private static void registerAddImportFixes(GrReferenceElement refElement, HighlightInfo info, final HighlightDisplayKey key) { + private static void registerAddImportFixes(GrReferenceElement refElement, @Nullable HighlightInfo info, final HighlightDisplayKey key) { final String referenceName = refElement.getReferenceName(); //noinspection ConstantConditions if (StringUtil.isEmpty(referenceName)) return; @@ -446,7 +447,7 @@ public class GrUnresolvedAccessInspection extends GroovySuppressableInspectionTo QuickFixAction.registerQuickFixAction(info, new GroovyAddImportAction(refElement), key); } - private static void registerCreateClassByTypeFix(GrReferenceElement refElement, HighlightInfo info, final HighlightDisplayKey key) { + private static void registerCreateClassByTypeFix(GrReferenceElement refElement, @Nullable HighlightInfo info, final HighlightDisplayKey key) { GrPackageDefinition packageDefinition = PsiTreeUtil.getParentOfType(refElement, GrPackageDefinition.class); if (packageDefinition != null) return; @@ -505,7 +506,7 @@ public class GrUnresolvedAccessInspection extends GroovySuppressableInspectionTo private final HighlightInfo myInfo; private HighlightDisplayKey myKey; - public QuickFixActionRegistrarAdapter(HighlightInfo info, HighlightDisplayKey displayKey) { + public QuickFixActionRegistrarAdapter(@Nullable HighlightInfo info, HighlightDisplayKey displayKey) { myInfo = info; myKey = displayKey; } @@ -523,7 +524,9 @@ public class GrUnresolvedAccessInspection extends GroovySuppressableInspectionTo @Override public void unregister(Condition condition) { - QuickFixAction.unregisterQuickFixAction(myInfo, condition); + if (myInfo != null) { + QuickFixAction.unregisterQuickFixAction(myInfo, condition); + } } } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyCodeStyleSettings.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyCodeStyleSettings.java index 201b06bba2f7..de942838e2dc 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyCodeStyleSettings.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyCodeStyleSettings.java @@ -48,6 +48,7 @@ public class GroovyCodeStyleSettings extends CustomCodeStyleSettings { public boolean SPACE_WITHIN_LIST_OR_MAP = false; public boolean ALIGN_NAMED_ARGS_IN_MAP = false; public boolean SPACE_BEFORE_CLOSURE_LBRACE = true; + public boolean SPACE_WITHIN_GSTRING_INJECTION_BRACES = false; //imports public boolean USE_FQ_CLASS_NAMES = false; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyLanguageCodeStyleSettingsProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyLanguageCodeStyleSettingsProvider.java index 0fb03ade0981..a92af5b822c8 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyLanguageCodeStyleSettingsProvider.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyLanguageCodeStyleSettingsProvider.java @@ -118,6 +118,7 @@ public class GroovyLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSe consumer.showCustomOption(GroovyCodeStyleSettings.class, "SPACE_IN_NAMED_ARGUMENT", "In named argument after ':'", CodeStyleSettingsCustomizable.SPACES_OTHER); consumer.showCustomOption(GroovyCodeStyleSettings.class, "SPACE_WITHIN_LIST_OR_MAP", "List and maps literals", CodeStyleSettingsCustomizable.SPACES_WITHIN); consumer.showCustomOption(GroovyCodeStyleSettings.class, "SPACE_BEFORE_CLOSURE_LBRACE", "Closure left brace in method calls", CodeStyleSettingsCustomizable.SPACES_BEFORE_LEFT_BRACE); + consumer.showCustomOption(GroovyCodeStyleSettings.class, "SPACE_WITHIN_GSTRING_INJECTION_BRACES", "Space within GString injection braces", CodeStyleSettingsCustomizable.SPACES_WITHIN); return; } consumer.showAllStandardOptions(); @@ -127,6 +128,7 @@ public class GroovyLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSe public CommonCodeStyleSettings getDefaultCommonSettings() { CommonCodeStyleSettings defaultSettings = new CommonCodeStyleSettings(GroovyFileType.GROOVY_LANGUAGE); defaultSettings.initIndentOptions(); + defaultSettings.SPACE_WITHIN_BRACES = true; return defaultSettings; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/ClosureBodyBlock.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/ClosureBodyBlock.java new file mode 100644 index 000000000000..c9b3e028619d --- /dev/null +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/ClosureBodyBlock.java @@ -0,0 +1,73 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.plugins.groovy.formatter; + +import com.intellij.formatting.Block; +import com.intellij.formatting.Indent; +import com.intellij.formatting.Wrap; +import com.intellij.lang.ASTNode; +import com.intellij.openapi.util.TextRange; +import com.intellij.psi.codeStyle.CommonCodeStyleSettings; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.groovy.codeStyle.GroovyCodeStyleSettings; + +import java.util.List; + +/** + * @author Max Medvedev + */ +public class ClosureBodyBlock extends GroovyBlock { + private TextRange myTextRange; + + public ClosureBodyBlock(@NotNull ASTNode node, + @NotNull Indent indent, + @Nullable Wrap wrap, + CommonCodeStyleSettings settings, + GroovyCodeStyleSettings groovySettings, + @NotNull AlignmentProvider alignmentProvider) { + super(node, indent, wrap, settings, groovySettings, alignmentProvider); + } + + @NotNull + @Override + public TextRange getTextRange() { + init(); + return myTextRange; + } + + private void init() { + if (mySubBlocks == null) { + GroovyBlockGenerator generator = new GroovyBlockGenerator(this); + List children = GroovyBlockGenerator.getClosureBodyVisibleChildren(myNode.getTreeParent()); + + mySubBlocks = generator.generateSubBlockForCodeBlocks(false, children); + + //at least -> exists + assert !mySubBlocks.isEmpty(); + TextRange firstRange = mySubBlocks.get(0).getTextRange(); + TextRange lastRange = mySubBlocks.get(mySubBlocks.size() - 1).getTextRange(); + myTextRange = new TextRange(firstRange.getStartOffset(), lastRange.getEndOffset()); + } + } + + @NotNull + @Override + public List getSubBlocks() { + init(); + return mySubBlocks; + } +} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlock.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlock.java index 36b3a5cf8a45..f8cea6ef822c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlock.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlock.java @@ -155,13 +155,16 @@ public class GroovyBlock implements Block, GroovyElementTypes, ASTBlock { */ @Nullable public Spacing getSpacing(Block child1, @NotNull Block child2) { - if ((child1 instanceof GroovyBlock) && (child2 instanceof GroovyBlock)) { + if (child1 instanceof GroovyBlock && child2 instanceof GroovyBlock) { if (((GroovyBlock)child1).getNode() == ((GroovyBlock)child2).getNode()) { return Spacing.getReadOnlySpacing(); } Spacing spacing = new GroovySpacingProcessor(((GroovyBlock)child2).getNode(), mySettings, myGroovySettings).getSpacing(); - return spacing != null ? spacing : GroovySpacingProcessorBasic.getSpacing(((GroovyBlock)child1), ((GroovyBlock)child2), mySettings); + if (spacing != null) { + return spacing; + } + return GroovySpacingProcessorBasic.getSpacing(((GroovyBlock)child1), ((GroovyBlock)child2), mySettings, myGroovySettings); } return null; } @@ -214,7 +217,7 @@ public class GroovyBlock implements Block, GroovyElementTypes, ASTBlock { return new ChildAttributes(Indent.getContinuationWithoutFirstIndent(), null); } if (psiParent instanceof GrParameterList) { - return new ChildAttributes(this.getIndent(), this.getAlignment()); + return new ChildAttributes(getIndent(), getAlignment()); } if (psiParent instanceof GrListOrMap) { return new ChildAttributes(Indent.getContinuationIndent(), null); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlockGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlockGenerator.java index e8deb158bf80..886b35d10694 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlockGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlockGenerator.java @@ -55,6 +55,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaratio import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel; import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList; import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression; @@ -101,6 +102,31 @@ public class GroovyBlockGenerator implements GroovyElementTypes { myGroovySettings = myBlock.getGroovySettings(); } + static List getClosureBodyVisibleChildren(final ASTNode node) { + List children = visibleChildren(node); + + if (!children.isEmpty()) { + ASTNode first = children.get(0); + if (first.getElementType() == GroovyTokenTypes.mLCURLY) children.remove(0); + } + +/* if (!children.isEmpty()) { + ASTNode second = children.get(0); + if (second.getElementType() == GroovyElementTypes.PARAMETERS_LIST) children.remove(0); + } + + if (!children.isEmpty()) { + ASTNode second = children.get(0); + if (second.getElementType() == GroovyTokenTypes.mCLOSABLE_BLOCK_OP) children.remove(0); + }*/ + + if (!children.isEmpty()) { + ASTNode last = children.get(children.size() - 1); + if (last.getElementType() == GroovyTokenTypes.mRCURLY) children.remove(children.size() - 1); + } + return children; + } + public List generateSubBlocks() { @@ -188,22 +214,54 @@ public class GroovyBlockGenerator implements GroovyElementTypes { } boolean classLevel = blockPsi instanceof GrTypeDefinitionBody; - if (blockPsi instanceof GrCodeBlock || blockPsi instanceof GroovyFile || classLevel) { - List children = visibleChildren(myNode); - calculateAlignments(children, classLevel); - final ArrayList subBlocks = new ArrayList(); + if (blockPsi instanceof GrClosableBlock && + ((GrClosableBlock)blockPsi).getArrow() != null && + ((GrClosableBlock)blockPsi).getParameters().length > 0 && + !getClosureBodyVisibleChildren(myNode).isEmpty()) { + GrClosableBlock closableBlock = (GrClosableBlock)blockPsi; - if (classLevel && myAlignment != null) { - final AlignmentProvider.Aligner aligner = myAlignmentProvider.createAligner(true); - for (ASTNode child : children) { - aligner.append(child.getPsi()); - } + ArrayList blocks = new ArrayList(); + + PsiElement lbrace = closableBlock.getLBrace(); + if (lbrace != null) { + ASTNode node = lbrace.getNode(); + Indent indent = GroovyIndentProcessor.getChildIndent(myBlock, node); + blocks.add(new GroovyBlock(node, indent, myWrap, mySettings, myGroovySettings, myAlignmentProvider)); } - for (ASTNode childNode : children) { - final Indent indent = GroovyIndentProcessor.getChildIndent(myBlock, childNode); - subBlocks.add(new GroovyBlock(childNode, indent, myWrap, mySettings, myGroovySettings, myAlignmentProvider)); + + /* { + Indent indent = GroovyIndentProcessor.getChildIndent(myBlock, parameterListNode); + GroovyBlock block = new GroovyBlock(parameterListNode, indent, myWrap, mySettings, myGroovySettings, myAlignmentProvider); + blocks.add(block); } - return subBlocks; + + { + PsiElement arrow = closableBlock.getArrow(); + ASTNode node = arrow.getNode(); + Indent indent = GroovyIndentProcessor.getChildIndent(myBlock, node); + GroovyBlock block = new GroovyBlock(node, indent, myWrap, mySettings, myGroovySettings, myAlignmentProvider); + blocks.add(block); + }*/ + + { + Indent indent = Indent.getNormalIndent(); + ASTNode parameterListNode = closableBlock.getParameterList().getNode(); + ClosureBodyBlock bodyBlock = new ClosureBodyBlock(parameterListNode, indent, myWrap, mySettings, myGroovySettings, myAlignmentProvider); + blocks.add(bodyBlock); + } + + PsiElement rbrace = closableBlock.getRBrace(); + if (rbrace != null) { + ASTNode node = rbrace.getNode(); + Indent indent = GroovyIndentProcessor.getChildIndent(myBlock, node); + blocks.add(new GroovyBlock(node, indent, myWrap, mySettings, myGroovySettings, myAlignmentProvider)); + } + + return blocks; + } + + if (blockPsi instanceof GrCodeBlock || blockPsi instanceof GroovyFile || classLevel) { + return generateSubBlockForCodeBlocks(classLevel, visibleChildren(myNode)); } // For other cases @@ -214,7 +272,25 @@ public class GroovyBlockGenerator implements GroovyElementTypes { } return subBlocks; } - + + public List generateSubBlockForCodeBlocks(boolean classLevel, final List children) { + + calculateAlignments(children, classLevel); + final ArrayList subBlocks = new ArrayList(); + + if (classLevel && myAlignment != null) { + final AlignmentProvider.Aligner aligner = myAlignmentProvider.createAligner(true); + for (ASTNode child : children) { + aligner.append(child.getPsi()); + } + } + for (ASTNode childNode : children) { + final Indent indent = GroovyIndentProcessor.getChildIndent(myBlock, childNode); + subBlocks.add(new GroovyBlock(childNode, indent, myWrap, mySettings, myGroovySettings, myAlignmentProvider)); + } + return subBlocks; + } + private void calculateAlignments(List children, boolean classLevel) { List currentGroup = null; @@ -330,7 +406,7 @@ public class GroovyBlockGenerator implements GroovyElementTypes { return psi instanceof GrBinaryExpression && (mBOR == ((GrBinaryExpression)psi).getOperationTokenType() || mLOR == ((GrBinaryExpression)psi).getOperationTokenType()); } - private static List visibleChildren(ASTNode node) { + public static List visibleChildren(ASTNode node) { ArrayList list = new ArrayList(); for (ASTNode astNode : getGroovyChildren(node)) { if (canBeCorrectBlock(astNode)) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java index aea939055570..3349602a01b2 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java @@ -25,6 +25,7 @@ import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.GroovyFileType; +import org.jetbrains.plugins.groovy.formatter.ClosureBodyBlock; import org.jetbrains.plugins.groovy.formatter.GroovyBlock; import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment; import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocTag; @@ -85,9 +86,13 @@ public abstract class GroovyIndentProcessor implements GroovyElementTypes { } } + if (child.getElementType() == GroovyElementTypes.PARAMETERS_LIST && parent instanceof ClosureBodyBlock) { + return Indent.getNoneIndent(); + } + // For common code block if (BLOCK_SET.contains(astNode.getElementType()) && - !BLOCK_STATEMENT.equals(astNode.getElementType())) { + !BLOCK_STATEMENT.equals(astNode.getElementType()) || parent instanceof ClosureBodyBlock) { return indentForBlock(psiParent, child); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessor.java index 96b7e8272daf..451d78084289 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessor.java @@ -247,19 +247,20 @@ public class GroovySpacingProcessor extends GroovyElementVisitor { myResult = Spacing.createSpacing(0, 0, 0, true, 100, 0); } } - else if (myType1 == mLCURLY && myType2 != PARAMETERS_LIST && myType2 != mCLOSABLE_BLOCK_OP || myType2 == mRCURLY) { - myResult = Spacing - .createDependentLFSpacing(mySettings.SPACE_WITHIN_BRACES ? 1 : 0, 1, closure.getTextRange(), mySettings.KEEP_LINE_BREAKS, - mySettings.KEEP_BLANK_LINES_IN_CODE); + else if (myType1 == mLCURLY && myType2 == mRCURLY) { //empty closure + myResult = Spacing.createSpacing(0, 0, 0, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); + } + else if (closure.getParameters().length == 0 && (myType1 == mLCURLY && myType2 != PARAMETERS_LIST && myType2 != mCLOSABLE_BLOCK_OP || myType2 == mRCURLY)) { //spaces between statements + + boolean spacesWithinBraces = closure.getParent() instanceof GrStringInjection + ? myGroovySettings.SPACE_WITHIN_GSTRING_INJECTION_BRACES + : mySettings.SPACE_WITHIN_BRACES; + int minSpaces = spacesWithinBraces ? 1 : 0; + myResult = Spacing.createDependentLFSpacing(minSpaces, 1, closure.getTextRange(), mySettings.KEEP_LINE_BREAKS, + mySettings.KEEP_BLANK_LINES_IN_CODE); } else if (myType1 == mCLOSABLE_BLOCK_OP) { - GrStatement[] statements = closure.getStatements(); - if (statements.length > 0) { - TextRange range = - new TextRange(statements[0].getTextRange().getStartOffset(), statements[statements.length - 1].getTextRange().getEndOffset()); - myResult = - Spacing.createDependentLFSpacing(1, Integer.MAX_VALUE, range, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); - } + myResult = GroovySpacingProcessorBasic.createDependentSpacingForClosure(mySettings, myGroovySettings, closure, true); } } @@ -269,6 +270,9 @@ public class GroovySpacingProcessor extends GroovyElementVisitor { myResult = Spacing.createSpacing(1, 1, 1, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); } } + else if (myType1 == mLCURLY && myType2 == mRCURLY) { + myResult = Spacing.createSpacing(0, 0, 0, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); + } else if (myType1 == mLCURLY && !GrStringUtil.isMultilineStringElement(myChild2) || myType2 == mRCURLY && !GrStringUtil.isMultilineStringElement(myChild1)) { final int spaceWithinBraces = mySettings.SPACE_WITHIN_BRACES ? 1 : 0; @@ -280,7 +284,8 @@ public class GroovySpacingProcessor extends GroovyElementVisitor { public void visitNewExpression(GrNewExpression newExpression) { if (myType1 == kNEW) { createSpaceInCode(true); - } else if (myType2 == ARGUMENTS) { + } + else if (myType2 == ARGUMENTS) { createSpaceInCode(mySettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES); } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessorBasic.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessorBasic.java index d758275b6368..43df2267b5e8 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessorBasic.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessorBasic.java @@ -18,17 +18,22 @@ package org.jetbrains.plugins.groovy.formatter.processors; import com.intellij.formatting.Spacing; import com.intellij.lang.ASTNode; +import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiErrorElement; import com.intellij.psi.codeStyle.CommonCodeStyleSettings; import com.intellij.psi.tree.IElementType; +import org.jetbrains.plugins.groovy.codeStyle.GroovyCodeStyleSettings; +import org.jetbrains.plugins.groovy.formatter.ClosureBodyBlock; import org.jetbrains.plugins.groovy.formatter.GroovyBlock; import org.jetbrains.plugins.groovy.formatter.MethodCallWithoutQualifierBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrConditionalExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrUnaryExpression; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrStringInjection; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeArgumentList; @@ -57,7 +62,10 @@ public abstract class GroovySpacingProcessorBasic { private static final Spacing IMPORT_OTHER_SPACING = Spacing.createSpacing(0, 0, 2, true, 100); private static final Spacing LAZY_SPACING = Spacing.createSpacing(0, 239, 0, true, 100); - public static Spacing getSpacing(GroovyBlock child1, GroovyBlock child2, CommonCodeStyleSettings settings) { + public static Spacing getSpacing(GroovyBlock child1, + GroovyBlock child2, + CommonCodeStyleSettings settings, + GroovyCodeStyleSettings groovySettings) { ASTNode leftNode = child1.getNode(); ASTNode rightNode = child2.getNode(); @@ -69,12 +77,20 @@ public abstract class GroovySpacingProcessorBasic { //Braces Placement // For multi-line strings - if (!mirrorsAst(child1) || !mirrorsAst(child2)) { + if (!(mirrorsAst(child1) && mirrorsAst(child2))) { return NO_SPACING; } - if (leftType == mGDOC_COMMENT_START && rightType == mGDOC_COMMENT_DATA - || leftType == mGDOC_COMMENT_DATA && rightType == mGDOC_COMMENT_END) { + if (child2 instanceof ClosureBodyBlock) { + return settings.SPACE_WITHIN_BRACES ? COMMON_SPACING : NO_SPACING_WITH_NEWLINE; + } + + if (child1 instanceof ClosureBodyBlock) { + return createDependentSpacingForClosure(settings, groovySettings, (GrClosableBlock)left.getParent(), false); + } + + if (leftType == mGDOC_COMMENT_START && rightType == mGDOC_COMMENT_DATA || + leftType == mGDOC_COMMENT_DATA && rightType == mGDOC_COMMENT_END) { return LAZY_SPACING; } @@ -240,7 +256,26 @@ public abstract class GroovySpacingProcessorBasic { return COMMON_SPACING; } + static Spacing createDependentSpacingForClosure(CommonCodeStyleSettings settings, + GroovyCodeStyleSettings groovySettings, GrClosableBlock closure, + final boolean forArrow) { + boolean spaceWithinBraces = closure.getParent() instanceof GrStringInjection + ? groovySettings.SPACE_WITHIN_GSTRING_INJECTION_BRACES + : settings.SPACE_WITHIN_BRACES; + GrStatement[] statements = closure.getStatements(); + if (statements.length > 0) { + int start = statements[0].getTextRange().getStartOffset(); + int end = statements[statements.length - 1].getTextRange().getEndOffset(); + TextRange range = new TextRange(start, end); + + int minSpaces = spaceWithinBraces || forArrow ? 1 : 0; + int maxSpaces = spaceWithinBraces || forArrow ? 1 : 0; + return Spacing.createDependentLFSpacing(minSpaces, maxSpaces, range, settings.KEEP_LINE_BREAKS, settings.KEEP_BLANK_LINES_IN_CODE); + } + return spaceWithinBraces || forArrow ? COMMON_SPACING : NO_SPACING_WITH_NEWLINE; + } + private static boolean mirrorsAst(GroovyBlock block) { - return block.getNode().getTextRange().equals(block.getTextRange()) || block instanceof MethodCallWithoutQualifierBlock; + return block.getNode().getTextRange().equals(block.getTextRange()) || block instanceof MethodCallWithoutQualifierBlock || block instanceof ClosureBodyBlock; } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java index 9399ab730406..a76b07cbad8f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java @@ -138,8 +138,13 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory { } public GrReferenceExpression createReferenceExpressionFromText(String idText, PsiElement context) { - PsiFile file = createGroovyFile(idText, false, context); - return (GrReferenceExpression) ((GroovyFileBase) file).getTopStatements()[0]; + GroovyFile file = createGroovyFile(idText, false, context); + GrTopStatement[] statements = file.getTopStatements(); + + if (statements.length != 1) throw new IncorrectOperationException("refText: " + idText); + if (!(statements[0] instanceof GrReferenceExpression)) throw new IncorrectOperationException("refText: " + idText); + + return (GrReferenceExpression)statements[0]; } @Override @@ -608,13 +613,15 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory { @Override public GrStatement createStatementFromText(String text, @Nullable PsiElement context) { - try { - PsiFile file = createGroovyFile(text, false, context); - return (GrStatement)((GroovyFileBase)file).getTopStatements()[0]; + GroovyFile file = createGroovyFile(text, false, context); + GrTopStatement[] statements = file.getTopStatements(); + if (statements.length != 1) { + throw new IncorrectOperationException("count = " + statements.length + ", " + text); } - catch (RuntimeException e) { - throw new IncorrectOperationException(text); + if (!(statements[0] instanceof GrStatement)) { + throw new IncorrectOperationException("type = " + statements[0].getClass().getName() + ", " + text); } + return (GrStatement)statements[0]; } public GrBlockStatement createBlockStatement(@NonNls GrStatement... statements) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrConstructorInvocationImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrConstructorInvocationImpl.java index e26c782fdabc..611ddfd9c3ec 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrConstructorInvocationImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrConstructorInvocationImpl.java @@ -93,7 +93,10 @@ public class GrConstructorInvocationImpl extends GrCallImpl implements GrConstru } public GroovyResolveResult[] multiResolveClass() { - return new GroovyResolveResult[]{new GroovyResolveResultImpl(getDelegatedClass(), this, null, PsiSubstitutor.EMPTY, true, true)}; + PsiClass aClass = getDelegatedClass(); + if (aClass == null) return GroovyResolveResult.EMPTY_ARRAY; + + return new GroovyResolveResult[]{new GroovyResolveResultImpl(aClass, this, null, PsiSubstitutor.EMPTY, true, true)}; } public PsiMethod resolveMethod() { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrSyntheticTypeElement.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrSyntheticTypeElement.java index f144f4a06026..c5833ee7c951 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrSyntheticTypeElement.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GrSyntheticTypeElement.java @@ -18,8 +18,10 @@ package org.jetbrains.plugins.groovy.lang.psi.impl.synthetic; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; import com.intellij.psi.impl.light.LightElement; +import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement; import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; @@ -48,7 +50,7 @@ public class GrSyntheticTypeElement extends LightElement implements PsiTypeEleme @Override public PsiAnnotationOwner getOwner(PsiAnnotation annotation) { - return null; + return this; } @Override @@ -84,6 +86,17 @@ public class GrSyntheticTypeElement extends LightElement implements PsiTypeEleme return "Synthetic PsiTypeElement"; } + @Override + public PsiElement replace(@NotNull PsiElement newElement) throws IncorrectOperationException { + if (newElement instanceof PsiTypeElement) { + GrTypeElement groovyTypeElement = GroovyPsiElementFactory.getInstance(getProject()).createTypeElement(newElement.getText(), newElement); + return myElement.replace(groovyTypeElement); + } + else { + return super.replace(newElement); + } + } + @Override public TextRange getTextRange() { return myElement.getTextRange(); diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/style/parameterToEntry/ParameterToMapEntryTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/style/parameterToEntry/ParameterToMapEntryTest.java index e170b12a3618..7ae3ac3608a9 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/style/parameterToEntry/ParameterToMapEntryTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/style/parameterToEntry/ParameterToMapEntryTest.java @@ -118,8 +118,9 @@ public class ParameterToMapEntryTest extends GroovyFormatterTestCase { PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting(); final String result = file.getText(); //System.out.println(result); - String expected = getExpectedResult(filePath); - Assert.assertEquals(expected, result); + myFixture.checkResultByFile(filePath.replace(".groovy", ".test"), true); +// String expected = getExpectedResult(filePath); +// Assert.assertEquals(expected, result); } private String getExpectedResult(final String filePath) { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/ExtractClosureTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/ExtractClosureTest.groovy index c43e87ff601c..8e054bc3dd36 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/ExtractClosureTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/ExtractClosureTest.groovy @@ -61,6 +61,7 @@ public abstract class ExtractClosureTest extends LightGroovyTestCase { } handler.invoke myFixture.project, myFixture.editor, myFixture.file, null + doPostponedFormatting(myFixture.project) myFixture.checkResult after } diff --git a/plugins/groovy/testdata/groovy/actions/smartEnter/gotoParentInIf.test b/plugins/groovy/testdata/groovy/actions/smartEnter/gotoParentInIf.test index 2806efba3af0..70732cb6cbef 100644 --- a/plugins/groovy/testdata/groovy/actions/smartEnter/gotoParentInIf.test +++ b/plugins/groovy/testdata/groovy/actions/smartEnter/gotoParentInIf.test @@ -5,7 +5,7 @@ if (suitable) { } ----- if (suitable) { - expectations.each {pattern, action -> + expectations.each { pattern, action -> if (cloud.match(pattern, action)) { } diff --git a/plugins/groovy/testdata/groovy/codeStyle/try1.test b/plugins/groovy/testdata/groovy/codeStyle/try1.test index 3f28692533da..a27631678668 100644 --- a/plugins/groovy/testdata/groovy/codeStyle/try1.test +++ b/plugins/groovy/testdata/groovy/codeStyle/try1.test @@ -4,7 +4,7 @@ try {foo()} catch (E e) {} finally {bar()} ----- try -{foo()} catch (E e) +{ foo() } catch (E e) {} finally -{bar()} \ No newline at end of file +{ bar() } \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/codeStyle/try2.test b/plugins/groovy/testdata/groovy/codeStyle/try2.test index d55aa574a845..850d5a441355 100644 --- a/plugins/groovy/testdata/groovy/codeStyle/try2.test +++ b/plugins/groovy/testdata/groovy/codeStyle/try2.test @@ -1,8 +1,8 @@ -try {foo()} +try {foo()} catch (E e) {} finally {bar()} ----- -try {foo()} -catch (E e) {} finally {bar()} \ No newline at end of file +try { foo() } +catch (E e) {} finally { bar() } \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/formatter/clo1.test b/plugins/groovy/testdata/groovy/formatter/clo1.test index 9b39c1380b06..ad3ab79625bd 100644 --- a/plugins/groovy/testdata/groovy/formatter/clo1.test +++ b/plugins/groovy/testdata/groovy/formatter/clo1.test @@ -1,3 +1,3 @@ def a={a,b->c} ----- -def a = {a, b -> c} \ No newline at end of file +def a = { a, b -> c } \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/formatter/clo2.test b/plugins/groovy/testdata/groovy/formatter/clo2.test index 0af496445175..a8b2403e7009 100644 --- a/plugins/groovy/testdata/groovy/formatter/clo2.test +++ b/plugins/groovy/testdata/groovy/formatter/clo2.test @@ -1,3 +1,3 @@ foo{a-> a+1} ----- -foo {a -> a + 1} \ No newline at end of file +foo { a -> a + 1 } \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/formatter/clo3.test b/plugins/groovy/testdata/groovy/formatter/clo3.test index b266d67a5332..0c5096710957 100644 --- a/plugins/groovy/testdata/groovy/formatter/clo3.test +++ b/plugins/groovy/testdata/groovy/formatter/clo3.test @@ -1,3 +1,3 @@ foo (1,2) {a->3} ----- -foo(1, 2) {a -> 3} +foo(1, 2) { a -> 3 } diff --git a/plugins/groovy/testdata/groovy/formatter/geese6.test b/plugins/groovy/testdata/groovy/formatter/geese6.test index 532c4d563ecc..b9936f06a3c3 100644 --- a/plugins/groovy/testdata/groovy/formatter/geese6.test +++ b/plugins/groovy/testdata/groovy/formatter/geese6.test @@ -4,5 +4,5 @@ ----- foo(2) { foo(2) { - foo(2) {print f} + foo(2) { print f } } } \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/formatter/geese7.test b/plugins/groovy/testdata/groovy/formatter/geese7.test index 1ce0e2900eae..3b7bd7e820dd 100644 --- a/plugins/groovy/testdata/groovy/formatter/geese7.test +++ b/plugins/groovy/testdata/groovy/formatter/geese7.test @@ -5,5 +5,5 @@ ----- foo(2) { foo(2) { - foo(2) {print f} + foo(2) { print f } } } \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/formatter/param2.test b/plugins/groovy/testdata/groovy/formatter/param2.test index 89e3b3cad969..95a55eaa8c93 100644 --- a/plugins/groovy/testdata/groovy/formatter/param2.test +++ b/plugins/groovy/testdata/groovy/formatter/param2.test @@ -4,8 +4,8 @@ def boo = {def a, a+b+c } ----- -def boo = {def a, - def int b, - def final c -> +def boo = { def a, + def int b, + def final c -> a + b + c } diff --git a/plugins/groovy/testdata/groovy/refactoring/extractMethod/clos_em.test b/plugins/groovy/testdata/groovy/refactoring/extractMethod/clos_em.test index 0d7a4beef570..f36c0caa7040 100644 --- a/plugins/groovy/testdata/groovy/refactoring/extractMethod/clos_em.test +++ b/plugins/groovy/testdata/groovy/refactoring/extractMethod/clos_em.test @@ -6,7 +6,7 @@ def foo = { ----- def foo = { int x, int y -> - testMethod(x, y) + testMethod(x, y) } private testMethod(int x, int y) { diff --git a/plugins/groovy/testdata/groovy/refactoring/extractMethod/output1.test b/plugins/groovy/testdata/groovy/refactoring/extractMethod/output1.test index e1738a81d52c..1dbded0ea099 100644 --- a/plugins/groovy/testdata/groovy/refactoring/extractMethod/output1.test +++ b/plugins/groovy/testdata/groovy/refactoring/extractMethod/output1.test @@ -22,7 +22,7 @@ class S { } private Closure testMethod() { - Closure sin = {x -> Math.sin(x)} + Closure sin = { x -> Math.sin(x) } return sin } } \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg1.test b/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg1.test index 63cdbe6e2c58..9dc7b98a2529 100644 --- a/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg1.test +++ b/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg1.test @@ -6,7 +6,7 @@ def qwerty(Closure cl){ return call; } ----- -def call = {int x -> return x + 1}.call() +def call = { int x -> return x + 1 }.call() println(call) def cl = call diff --git a/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg2.test b/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg2.test index 33c0f44a62e9..b64a2c353fd4 100644 --- a/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg2.test +++ b/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg2.test @@ -7,8 +7,8 @@ def cl = qwerty{int x -> return x + 1}{int x -> return x return call + call1; } ----- -def call = {int x -> return x + 1}(42) -def call1 = {int x -> return x + 1}(45) +def call = { int x -> return x + 1 }(42) +def call1 = { int x -> return x + 1 }(45) println(call) def cl = call + call1 diff --git a/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg3.test b/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg3.test index 084ca5f7ac87..3fc29c5c247d 100644 --- a/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg3.test +++ b/plugins/groovy/testdata/groovy/refactoring/inlineMethod/clos_arg3.test @@ -6,7 +6,7 @@ def cl = qwerty(45){int x -> return x + 1} return call + i; } ----- -def call = {int x -> return x + 1}(42) +def call = { int x -> return x + 1 }(42) println(call) def cl = call + 45 diff --git a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos1.test b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos1.test index bbe93eb3c17b..e68e03a5fed8 100644 --- a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos1.test +++ b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos1.test @@ -1,4 +1,4 @@ foo(1, 2, 3) {x->x} ----- -def preved = {x -> x} +def preved = { x -> x } foo(1, 2, 3, preved) \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos2.test b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos2.test index feb204d954bf..4fa1f214ad41 100644 --- a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos2.test +++ b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos2.test @@ -1,4 +1,4 @@ foo(1, 2, 3) {x -> x} {x -> y} {x->x} {x -> z} ----- -def preved = {x -> x} -foo(1, 2, 3, preved, {x -> y}, preved) {x -> z} \ No newline at end of file +def preved = { x -> x } +foo(1, 2, 3, preved, { x -> y }, preved) {x -> z} \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos3.test b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos3.test index 42569a75d9a6..45d7ba3d84e5 100644 --- a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos3.test +++ b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos3.test @@ -1,4 +1,4 @@ foo(1, 2, 3) {x -> x} {x -> y} {x->x} {x -> z} ----- -def preved = {x -> x} -foo(1, 2, 3, {x -> x}, {x -> y}, preved) {x -> z} \ No newline at end of file +def preved = { x -> x } +foo(1, 2, 3, { x -> x }, { x -> y }, preved) {x -> z} \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos4.test b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos4.test index 10636307bd93..ad2e141f1b85 100644 --- a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos4.test +++ b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/clos4.test @@ -2,6 +2,6 @@ foo {x->x} {x->x} {x->x} (3) {x->x} ----- -def preved = {x -> x} +def preved = { x -> x } foo(preved, preved, preved)(3, preved) diff --git a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/if1.test b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/if1.test index 02df2be7784c..c83b6e0aee53 100644 --- a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/if1.test +++ b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/if1.test @@ -3,5 +3,5 @@ if (true) ({x -> 1}) ----- foo {x->x} if (true) { - def preved = {x -> 1} + def preved = { x -> 1 } } \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/if2.test b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/if2.test index 561c55284efd..7fd0de759ace 100644 --- a/plugins/groovy/testdata/groovy/refactoring/introduceVariable/if2.test +++ b/plugins/groovy/testdata/groovy/refactoring/introduceVariable/if2.test @@ -1,5 +1,5 @@ {x->x} if (true) ({x->x}) ----- -def preved = {x -> x} +def preved = { x -> x } if (true) preved \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRenameOfClosureImplicitParameter_after.groovy b/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRenameOfClosureImplicitParameter_after.groovy index 3df1f7df5488..ba0d65ac4651 100644 --- a/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRenameOfClosureImplicitParameter_after.groovy +++ b/plugins/groovy/testdata/groovy/refactoring/rename/InplaceRenameOfClosureImplicitParameter_after.groovy @@ -1,3 +1,3 @@ -[1, 2, 3].each {int foo -> +[1, 2, 3].each { int foo -> print foo } \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/refactoring/rename/closureIt.test b/plugins/groovy/testdata/groovy/refactoring/rename/closureIt.test index 92e9d71240f9..9069e1ccc9be 100644 --- a/plugins/groovy/testdata/groovy/refactoring/rename/closureIt.test +++ b/plugins/groovy/testdata/groovy/refactoring/rename/closureIt.test @@ -2,6 +2,6 @@ def c = { it } ----- -def c = {def newName -> +def c = { def newName -> newName } \ No newline at end of file diff --git a/plugins/groovy/testdata/intentions/convertGStringToString/ComplicatedCase_after.groovy b/plugins/groovy/testdata/intentions/convertGStringToString/ComplicatedCase_after.groovy index affe87857c31..9bda9867751b 100644 --- a/plugins/groovy/testdata/intentions/convertGStringToString/ComplicatedCase_after.groovy +++ b/plugins/groovy/testdata/intentions/convertGStringToString/ComplicatedCase_after.groovy @@ -1,4 +1,4 @@ def x=5; def y=7; def name="abc" -print String.valueOf(x++ + ++y) + ' is very "strange" \'expression\'. x=' + String.valueOf(x) + String.valueOf(y) + '=y; ' + name + ' ' + String.valueOf(name.collect {true}) + ' \n wow\\' \ No newline at end of file +print String.valueOf(x++ + ++y) + ' is very "strange" \'expression\'. x=' + String.valueOf(x) + String.valueOf(y) + '=y; ' + name + ' ' + String.valueOf(name.collect { true }) + ' \n wow\\' \ No newline at end of file diff --git a/plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureToMethodWithFieldUsages_after.groovy b/plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureToMethodWithFieldUsages_after.groovy index be1d6ffc2ac8..216ece3cacce 100644 --- a/plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureToMethodWithFieldUsages_after.groovy +++ b/plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureToMethodWithFieldUsages_after.groovy @@ -1,5 +1,5 @@ class X { - def foo(def it = null) {print it} + def foo(def it = null) { print it } def bar() { foo(2) diff --git a/plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureWithoutModifiersToMethod_after.groovy b/plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureWithoutModifiersToMethod_after.groovy index f02d6a0a1cbd..2978ea962c30 100644 --- a/plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureWithoutModifiersToMethod_after.groovy +++ b/plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureWithoutModifiersToMethod_after.groovy @@ -1,3 +1,3 @@ class C { - def clos(def it = null) {/* do smth */} + def clos(def it = null) {/* do smth */ } } \ No newline at end of file diff --git a/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodFromReference_after.groovy b/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodFromReference_after.groovy index 47d97c3ee2e8..6a0b8b57c074 100644 --- a/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodFromReference_after.groovy +++ b/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodFromReference_after.groovy @@ -1,7 +1,7 @@ class X{ def a; - def foo = {def x, def y -> + def foo = { def x, def y -> print x + a; print y; } diff --git a/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodToClosureWithMemberPointer_after.groovy b/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodToClosureWithMemberPointer_after.groovy index e98b38456fd4..971d12a2950e 100644 --- a/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodToClosureWithMemberPointer_after.groovy +++ b/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodToClosureWithMemberPointer_after.groovy @@ -1,5 +1,5 @@ class X { - def foo = {def it = null -> print it} + def foo = { def it = null -> print it } def bar() { print this.foo diff --git a/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodToClosure_after.groovy b/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodToClosure_after.groovy index 73f3e9030cfd..7124f3fe067c 100644 --- a/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodToClosure_after.groovy +++ b/plugins/groovy/testdata/intentions/convertMethodToClosure/MethodToClosure_after.groovy @@ -1,7 +1,7 @@ class X{ def a; - def foo = {def x, def y -> + def foo = { def x, def y -> print x + a; print y; } diff --git a/plugins/groovy/testdata/intentions/convertMethodToClosure/StaticMethodToClosure_after.groovy b/plugins/groovy/testdata/intentions/convertMethodToClosure/StaticMethodToClosure_after.groovy index a86b57f68a66..17bd83682448 100644 --- a/plugins/groovy/testdata/intentions/convertMethodToClosure/StaticMethodToClosure_after.groovy +++ b/plugins/groovy/testdata/intentions/convertMethodToClosure/StaticMethodToClosure_after.groovy @@ -1,7 +1,7 @@ class X{ def a; - static private final def foo = {def x, def y -> + static private final def foo = { def x, def y -> print x + a; print y; } diff --git a/plugins/groovy/testdata/paramToMap/callMethod/A.test b/plugins/groovy/testdata/paramToMap/callMethod/A.test index 0b7f54921e34..cf97c08adf83 100644 --- a/plugins/groovy/testdata/paramToMap/callMethod/A.test +++ b/plugins/groovy/testdata/paramToMap/callMethod/A.test @@ -1,3 +1,3 @@ def clos = { Map attrs -> println(attrs.i) } clos(i: 1) -clos.call(i: 1) +clos.call(i: 1) \ No newline at end of file diff --git a/plugins/groovy/testdata/paramToMap/closureAtEnd/A.test b/plugins/groovy/testdata/paramToMap/closureAtEnd/A.test index e000ffc6e5c4..3b396e414521 100644 --- a/plugins/groovy/testdata/paramToMap/closureAtEnd/A.test +++ b/plugins/groovy/testdata/paramToMap/closureAtEnd/A.test @@ -1,5 +1,5 @@ -def test = {Map attrs, x -> +def test = { Map attrs, x -> attrs.cl.call() } -test(1, cl: {x -> x}) \ No newline at end of file +test(1, cl: { x -> x }) \ No newline at end of file diff --git a/plugins/groovy/testdata/paramToMap/gettersAndCallMethod/A.test b/plugins/groovy/testdata/paramToMap/gettersAndCallMethod/A.test index 1325a319cb5d..dcdd127ed17d 100644 --- a/plugins/groovy/testdata/paramToMap/gettersAndCallMethod/A.test +++ b/plugins/groovy/testdata/paramToMap/gettersAndCallMethod/A.test @@ -1,5 +1,5 @@ class C { - def clos = {Map attrs -> print attrs.p} + def clos = { Map attrs -> print attrs.p } def foo() { clos(p: 1) @@ -15,4 +15,3 @@ c.clos.call(p: 6) c.getClos()(p: 7) c.getClos().call(p: 8) - diff --git a/plugins/groovy/testdata/paramToMap/newMap/A.test b/plugins/groovy/testdata/paramToMap/newMap/A.test index 96fa6395cee0..0d18b86bb844 100644 --- a/plugins/groovy/testdata/paramToMap/newMap/A.test +++ b/plugins/groovy/testdata/paramToMap/newMap/A.test @@ -1,4 +1,4 @@ -def foo = {Map attrs, a -> +def foo = { Map attrs, a -> a + attrs.b } diff --git a/plugins/groovy/testdata/paramToMap/secondClosure/A.test b/plugins/groovy/testdata/paramToMap/secondClosure/A.test index 8d7c37ab7949..eb3ff57c616a 100644 --- a/plugins/groovy/testdata/paramToMap/secondClosure/A.test +++ b/plugins/groovy/testdata/paramToMap/secondClosure/A.test @@ -1,6 +1,6 @@ -def foo = {Map attrs, cl1 -> +def foo = { Map attrs, cl1 -> cl1.call() attrs.cl2.call() } -foo(cl2: {y -> y}) {x->x} \ No newline at end of file +foo(cl2: { y -> y }) {x->x} \ No newline at end of file diff --git a/plugins/groovy/testdata/refactoring/introduceParameterGroovy/delegaterInSuper/DelegaterInSuperMyClass_after.groovy b/plugins/groovy/testdata/refactoring/introduceParameterGroovy/delegaterInSuper/DelegaterInSuperMyClass_after.groovy index 7fada3f18b85..ea3413825f70 100644 --- a/plugins/groovy/testdata/refactoring/introduceParameterGroovy/delegaterInSuper/DelegaterInSuperMyClass_after.groovy +++ b/plugins/groovy/testdata/refactoring/introduceParameterGroovy/delegaterInSuper/DelegaterInSuperMyClass_after.groovy @@ -11,5 +11,5 @@ class Inh extends Base { foo(123) } - def foo(int anObject) {print anObject} + def foo(int anObject) {print anObject } } \ No newline at end of file diff --git a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/CorrectOccurrencesForLocalVar_after.groovy b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/CorrectOccurrencesForLocalVar_after.groovy index 06d25974456e..61d4070988c7 100644 --- a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/CorrectOccurrencesForLocalVar_after.groovy +++ b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/CorrectOccurrencesForLocalVar_after.groovy @@ -4,7 +4,7 @@ clos = {print "foo"} clos() clos.call() -clos = {String anObject -> print anObject} +clos = {String anObject -> print anObject } clos("foo") clos.call("foo") diff --git a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/DontReplaceWithGetter_after.groovy b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/DontReplaceWithGetter_after.groovy index 013c4dd7a253..331e16e92a37 100644 --- a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/DontReplaceWithGetter_after.groovy +++ b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/DontReplaceWithGetter_after.groovy @@ -3,7 +3,7 @@ class X { def getFoo(){foo} - def bar = {final def anObject -> + def bar = { final def anObject -> print anObject } } diff --git a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/ReplaceGetterCall_after.groovy b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/ReplaceGetterCall_after.groovy index 74a5a34ea929..6eda3ff61c42 100644 --- a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/ReplaceGetterCall_after.groovy +++ b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/ReplaceGetterCall_after.groovy @@ -1,7 +1,7 @@ class X { def foo - def bar = {final def anObject -> + def bar = { final def anObject -> print anObject } } diff --git a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/ReplaceWithGetter_after.groovy b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/ReplaceWithGetter_after.groovy index 5b800e3e8da7..cdbd4a164b7f 100644 --- a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/ReplaceWithGetter_after.groovy +++ b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/ReplaceWithGetter_after.groovy @@ -1,7 +1,7 @@ class X { def foo - def bar = {final def anObject -> + def bar = { final def anObject -> print anObject } } diff --git a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/SimpleClosure_after.groovy b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/SimpleClosure_after.groovy index 943a4ad11c28..38a206abe8ae 100644 --- a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/SimpleClosure_after.groovy +++ b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/SimpleClosure_after.groovy @@ -1,3 +1,3 @@ -print {int anObject -> +print { int anObject -> print anObject } \ No newline at end of file diff --git a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/VarAssignedToClosure_after.groovy b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/VarAssignedToClosure_after.groovy index 8c9fd877dd94..d8e8cbe1ee8f 100644 --- a/plugins/groovy/testdata/refactoring/introduceParameterInClosure/VarAssignedToClosure_after.groovy +++ b/plugins/groovy/testdata/refactoring/introduceParameterInClosure/VarAssignedToClosure_after.groovy @@ -1,4 +1,4 @@ Closure clos -clos= {String anObject -> print anObject} +clos= {String anObject -> print anObject } clos("foo") clos.call("foo") diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/SelectionTool.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/SelectionTool.java index 65e5913e6f1e..eed759966137 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/SelectionTool.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/SelectionTool.java @@ -214,7 +214,7 @@ public class SelectionTool extends InputTool { } else if (myToolProvider != null && !area.isTree() && Character.isLetterOrDigit(event.getKeyChar()) && - (event.getModifiers() & (InputEvent.ALT_MASK | InputEvent.CTRL_MASK)) == 0) { + (event.getModifiers() & (InputEvent.ALT_MASK | InputEvent.CTRL_MASK | InputEvent.META_MASK)) == 0) { myToolProvider.startInplaceEditing(new InplaceContext(event.getKeyChar())); } }