diff --git a/java/compiler/impl/src/com/intellij/compiler/actions/BuildArtifactAction.java b/java/compiler/impl/src/com/intellij/compiler/actions/BuildArtifactAction.java index fd634a1fe651..9504ec5278df 100644 --- a/java/compiler/impl/src/com/intellij/compiler/actions/BuildArtifactAction.java +++ b/java/compiler/impl/src/com/intellij/compiler/actions/BuildArtifactAction.java @@ -15,88 +15,28 @@ */ package com.intellij.compiler.actions; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.PlatformDataKeys; -import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.compiler.CompilerManager; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.packaging.artifacts.Artifact; -import com.intellij.packaging.artifacts.ArtifactManager; import com.intellij.packaging.impl.compiler.ArtifactCompileScope; -import com.intellij.packaging.impl.compiler.ArtifactsWorkspaceSettings; -import com.intellij.packaging.impl.ui.ChooseArtifactsDialog; -import java.util.ArrayList; import java.util.List; /** * @author nik */ -public class BuildArtifactAction extends AnAction { +public class BuildArtifactAction extends BuildArtifactActionBase { public BuildArtifactAction() { - super("Build Artifact"); + super("Build"); } @Override - public void update(AnActionEvent e) { - final Project project = e.getData(PlatformDataKeys.PROJECT); - final Presentation presentation = e.getPresentation(); - presentation.setEnabled(false); - if (project == null) { - return; - } - final List artifacts = getArtifactWithOutputPaths(project); - if (artifacts.isEmpty()) { - return; - } - presentation.setEnabled(true); - if (artifacts.size() == 1) { - presentation.setText("Build '" + StringUtil.first(artifacts.get(0).getName(), 40, true) + "' artifact"); - } - else { - presentation.setText("Build Artifacts..."); - } + protected String getDescription() { + return "Selected artifacts will be built with all dependencies"; } - private static List getArtifactWithOutputPaths(Project project) { - final List result = new ArrayList(); - for (Artifact artifact : ArtifactManager.getInstance(project).getSortedArtifacts()) { - if (!StringUtil.isEmpty(artifact.getOutputPath())) { - result.add(artifact); - } - } - return result; - } - - public void actionPerformed(AnActionEvent e) { - final Project project = e.getData(PlatformDataKeys.PROJECT); - if (project == null) return; - - final List artifacts = getArtifactWithOutputPaths(project); - if (artifacts.isEmpty()) return; - - if (artifacts.size() == 1) { - buildArtifacts(project, artifacts); - return; - } - - final ChooseArtifactsDialog dialog = new ChooseArtifactsDialog(project, artifacts, "Choose Artifacts to Build", "Selected artifacts will be built with all dependencies"); - final List initialSelection = ArtifactsWorkspaceSettings.getInstance(project).getArtifactsToBuild(); - if (!initialSelection.isEmpty()) { - dialog.selectElements(initialSelection); - } - dialog.show(); - - if (dialog.isOK()) { - final List selected = dialog.getChosenElements(); - ArtifactsWorkspaceSettings.getInstance(project).setArtifactsToBuild(selected); - buildArtifacts(project, selected); - } - } - - private static void buildArtifacts(Project project, final List artifacts) { + @Override + protected void performAction(Project project, final List artifacts) { CompilerManager.getInstance(project).make(ArtifactCompileScope.createArtifactsScope(project, artifacts), null); } } diff --git a/java/compiler/impl/src/com/intellij/compiler/actions/BuildArtifactActionBase.java b/java/compiler/impl/src/com/intellij/compiler/actions/BuildArtifactActionBase.java new file mode 100644 index 000000000000..412641289f5c --- /dev/null +++ b/java/compiler/impl/src/com/intellij/compiler/actions/BuildArtifactActionBase.java @@ -0,0 +1,105 @@ +/* + * Copyright 2000-2011 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.compiler.actions; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.packaging.artifacts.Artifact; +import com.intellij.packaging.artifacts.ArtifactManager; +import com.intellij.packaging.impl.compiler.ArtifactsWorkspaceSettings; +import com.intellij.packaging.impl.ui.ChooseArtifactsDialog; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author nik + */ +public abstract class BuildArtifactActionBase extends AnAction { + private final String myActionName; + + public BuildArtifactActionBase(String actionName) { + super(actionName + " Artifact"); + myActionName = actionName; + } + + @Override + public void update(AnActionEvent e) { + final Project project = e.getData(PlatformDataKeys.PROJECT); + final Presentation presentation = e.getPresentation(); + presentation.setEnabled(false); + if (project == null) { + return; + } + final List artifacts = getArtifactWithOutputPaths(project); + if (artifacts.isEmpty()) { + return; + } + presentation.setEnabled(true); + if (artifacts.size() == 1) { + String first = StringUtil.first(artifacts.get(0).getName(), 40, true); + presentation.setText(myActionName + " '" + first + "' artifact"); + } + else { + presentation.setText(myActionName + " Artifacts..."); + } + } + + public void actionPerformed(AnActionEvent e) { + final Project project = e.getData(PlatformDataKeys.PROJECT); + if (project == null) return; + + final List artifacts = getArtifactWithOutputPaths(project); + if (artifacts.isEmpty()) return; + + if (artifacts.size() == 1) { + performAction(project, artifacts); + return; + } + + final ChooseArtifactsDialog dialog = new ChooseArtifactsDialog(project, artifacts, "Choose Artifacts to " + myActionName, + getDescription()); + final List initialSelection = ArtifactsWorkspaceSettings.getInstance(project).getArtifactsToBuild(); + if (!initialSelection.isEmpty()) { + dialog.selectElements(initialSelection); + } + dialog.show(); + + if (dialog.isOK()) { + final List selected = dialog.getChosenElements(); + ArtifactsWorkspaceSettings.getInstance(project).setArtifactsToBuild(selected); + performAction(project, selected); + } + } + + protected abstract String getDescription(); + + protected abstract void performAction(Project project, List artifacts); + + private static List getArtifactWithOutputPaths(Project project) { + final List result = new ArrayList(); + for (Artifact artifact : ArtifactManager.getInstance(project).getSortedArtifacts()) { + if (!StringUtil.isEmpty(artifact.getOutputPath())) { + result.add(artifact); + } + } + return result; + } +} diff --git a/java/compiler/impl/src/com/intellij/compiler/actions/CleanArtifactAction.java b/java/compiler/impl/src/com/intellij/compiler/actions/CleanArtifactAction.java new file mode 100644 index 000000000000..3be0a2e3604c --- /dev/null +++ b/java/compiler/impl/src/com/intellij/compiler/actions/CleanArtifactAction.java @@ -0,0 +1,63 @@ +/* + * Copyright 2000-2011 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.compiler.actions; + +import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.Task; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.packaging.artifacts.Artifact; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +/** + * @author nik + */ +public class CleanArtifactAction extends BuildArtifactActionBase { + public CleanArtifactAction() { + super("Clean"); + } + + @Override + protected String getDescription() { + return "Output of the selected artifacts will be cleared."; + } + + @Override + protected void performAction(Project project, final List artifacts) { + final List files = new ArrayList(); + for (Artifact artifact : artifacts) { + String outputPath = artifact.getOutputFilePath(); + if (outputPath != null) { + files.add(new File(FileUtil.toSystemDependentName(outputPath))); + } + } + new Task.Backgroundable(project, "Cleaning artifacts...", true) { + @Override + public void run(@NotNull ProgressIndicator indicator) { + for (File file : files) { + indicator.checkCanceled(); + FileUtil.delete(file); + } + LocalFileSystem.getInstance().refreshIoFiles(files, true, true, null); + } + }.queue(); + } +} diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactImpl.java index 29566661c0f2..e0c0ca223c8b 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactImpl.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactImpl.java @@ -16,6 +16,7 @@ package com.intellij.packaging.impl.artifacts; import com.intellij.openapi.util.UserDataHolderBase; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.packaging.artifacts.*; @@ -149,6 +150,12 @@ public class ArtifactImpl extends UserDataHolderBase implements ModifiableArtifa @Override public VirtualFile getOutputFile() { + String filePath = getOutputFilePath(); + return !StringUtil.isEmpty(filePath) ? LocalFileSystem.getInstance().findFileByPath(filePath) : null; + } + + @Override + public String getOutputFilePath() { String filePath; if (myRootElement instanceof ArchivePackagingElement) { filePath = myOutputPath + "/" + ((ArchivePackagingElement)myRootElement).getArchiveFileName(); @@ -156,7 +163,7 @@ public class ArtifactImpl extends UserDataHolderBase implements ModifiableArtifa else { filePath = myOutputPath; } - return LocalFileSystem.getInstance().findFileByPath(filePath); + return filePath; } public void copyFrom(ArtifactImpl modified) { diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.java index c53df72d68d9..56ad74bb9b0d 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/JarArtifactFromModulesDialog.java @@ -25,6 +25,7 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.packaging.elements.PackagingElementResolvingContext; import com.intellij.packaging.impl.elements.ManifestFileUtil; +import com.intellij.ui.ComboboxSpeedSearch; import com.intellij.ui.DocumentAdapter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -77,6 +78,11 @@ public class JarArtifactFromModulesDialog extends DialogWrapper { updateManifestDirField(); myManifestDirField.addBrowseFolderListener(null, null, project, ManifestFileUtil.createDescriptorForManifestDirectory()); + setupModulesCombobox(context); + init(); + } + + private void setupModulesCombobox(PackagingElementResolvingContext context) { final Module[] modules = context.getModulesProvider().getModules().clone(); Arrays.sort(modules, ModulesAlphaComparator.INSTANCE); if (modules.length > 1) { @@ -86,7 +92,12 @@ public class JarArtifactFromModulesDialog extends DialogWrapper { myModuleComboBox.addItem(module); } myModuleComboBox.setRenderer(new ModuleListRenderer(myModuleComboBox)); - init(); + new ComboboxSpeedSearch(myModuleComboBox) { + @Override + protected String getElementText(Object element) { + return element instanceof Module ? ((Module)element).getName() : ""; + } + }; } private void updateManifestDirField() { diff --git a/java/compiler/openapi/src/com/intellij/packaging/artifacts/Artifact.java b/java/compiler/openapi/src/com/intellij/packaging/artifacts/Artifact.java index bfda83b02a3c..8155cf05af6e 100644 --- a/java/compiler/openapi/src/com/intellij/packaging/artifacts/Artifact.java +++ b/java/compiler/openapi/src/com/intellij/packaging/artifacts/Artifact.java @@ -46,4 +46,7 @@ public interface Artifact extends UserDataHolder { @Nullable VirtualFile getOutputFile(); + + @Nullable + String getOutputFilePath(); } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java index 39b4b3df62bc..c496093332ba 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java @@ -78,7 +78,7 @@ public class InplaceIntroduceFieldPopup { private String myFieldName; private boolean myInitListeners = false; - private static BaseExpressionToFieldHandler.InitializationPlace ourLastInitializerPlace; + static BaseExpressionToFieldHandler.InitializationPlace ourLastInitializerPlace; public InplaceIntroduceFieldPopup(PsiLocalVariable localVariable, PsiClass parentClass, diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java index 18d512e77e47..8b9e11d0f09d 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java @@ -22,6 +22,7 @@ import com.intellij.psi.util.PsiTreeUtil; import com.intellij.refactoring.JavaRefactoringSettings; import com.intellij.refactoring.RefactoringBundle; import com.intellij.refactoring.ui.TypeSelectorManager; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.ChangeListener; @@ -33,7 +34,7 @@ import java.awt.event.*; * Date: 4/8/11 */ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { - private JComboBox myInitializerCombo; + private @Nullable JComboBox myInitializerCombo; private JComboBox myVisibilityCombo; private DefaultComboBoxModel myInitialisersPlaceModel; @@ -53,7 +54,7 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { protected void initializeControls(PsiExpression initializerExpression, BaseExpressionToFieldHandler.InitializationPlace ourLastInitializerPlace) { super.initializeControls(initializerExpression, ourLastInitializerPlace); - initializeInitializerPlace(initializerExpression, ourLastInitializerPlace); + String ourLastVisibility = JavaRefactoringSettings.getInstance().INTRODUCE_FIELD_VISIBILITY; setVisibility(ourLastVisibility); } @@ -106,7 +107,10 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { } public BaseExpressionToFieldHandler.InitializationPlace getInitializerPlace() { - return (BaseExpressionToFieldHandler.InitializationPlace)myInitializerCombo.getSelectedItem(); + if (myInitializerCombo != null) { + return (BaseExpressionToFieldHandler.InitializationPlace)myInitializerCombo.getSelectedItem(); + } + return (BaseExpressionToFieldHandler.InitializationPlace)myInitialisersPlaceModel.getElementAt(0); } public String getFieldVisibility() { @@ -122,9 +126,7 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0); gridBagConstraints.insets.top = 5; - final JLabel initLabel = new JLabel(RefactoringBundle.message("initialize.in.border.title") + ":"); - initLabel.setDisplayedMnemonic('i'); - groupPanel.add(initLabel, gridBagConstraints); + myInitialisersPlaceModel = new DefaultComboBoxModel(); myInitialisersPlaceModel.addElement(BaseExpressionToFieldHandler.InitializationPlace.IN_CURRENT_METHOD); @@ -133,40 +135,44 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { if (TestUtil.isTestClass(myParentClass)) { myInitialisersPlaceModel.addElement(BaseExpressionToFieldHandler.InitializationPlace.IN_SETUP_METHOD); } - myInitializerCombo = new JComboBox(myInitialisersPlaceModel); - InplaceIntroduceConstantPopup.appendActions(myInitializerCombo, myParentClass.getProject()); - initLabel.setLabelFor(myInitializerCombo); - myInitializerCombo.setRenderer(new ListCellRendererWrapper(myInitializerCombo) { - @Override - public void customize(JList list, - BaseExpressionToFieldHandler.InitializationPlace value, - int index, - boolean selected, - boolean hasFocus) { - if (value == BaseExpressionToFieldHandler.InitializationPlace.IN_CURRENT_METHOD) { - setText("current method"); - } else if (value == BaseExpressionToFieldHandler.InitializationPlace.IN_CONSTRUCTOR) { - setText("constructor"); - } else if (value == BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION) { - setText("field declaration"); - } else { - setText("setUp"); + initializeInitializerPlace(myInitializerExpression, InplaceIntroduceFieldPopup.ourLastInitializerPlace); + if (myInitialisersPlaceModel.getSize() > 1) { + final JLabel initLabel = new JLabel(RefactoringBundle.message("initialize.in.border.title") + ":"); + initLabel.setDisplayedMnemonic('i'); + groupPanel.add(initLabel, gridBagConstraints); + JComboBox initializersCombo = new JComboBox(myInitialisersPlaceModel); + InplaceIntroduceConstantPopup.appendActions(initializersCombo, myParentClass.getProject()); + initLabel.setLabelFor(initializersCombo); + initializersCombo.setRenderer(new ListCellRendererWrapper(initializersCombo) { + @Override + public void customize(JList list, + BaseExpressionToFieldHandler.InitializationPlace value, + int index, + boolean selected, + boolean hasFocus) { + setText(getPresentableText(value)); } - } - }); - myInitializerCombo.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - itemListener.itemStateChanged(null); - finalUpdater.itemStateChanged(null); - } - }); - gridBagConstraints.gridx = 1; - gridBagConstraints.insets.top = 0; - gridBagConstraints.insets.left = 0; - gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; - groupPanel.add(myInitializerCombo, gridBagConstraints); - + }); + initializersCombo.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + itemListener.itemStateChanged(null); + finalUpdater.itemStateChanged(null); + } + }); + gridBagConstraints.gridx = 1; + gridBagConstraints.insets.top = 0; + gridBagConstraints.insets.left = 0; + gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; + groupPanel.add(initializersCombo, gridBagConstraints); + myInitializerCombo = initializersCombo; + } else { + gridBagConstraints.gridwidth = 2; + groupPanel.add(new JLabel("Initialize field in " + + getPresentableText((BaseExpressionToFieldHandler.InitializationPlace)myInitialisersPlaceModel.getElementAt(0))), + gridBagConstraints); + gridBagConstraints.gridwidth = 1; + } gridBagConstraints.gridx = 0; @@ -180,6 +186,18 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { return mainPanel; } + private static String getPresentableText(BaseExpressionToFieldHandler.InitializationPlace value) { + if (value == BaseExpressionToFieldHandler.InitializationPlace.IN_CURRENT_METHOD) { + return "current method"; + } else if (value == BaseExpressionToFieldHandler.InitializationPlace.IN_CONSTRUCTOR) { + return "constructor"; + } else if (value == BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION) { + return "field declaration"; + } else { + return "setUp"; + } + } + protected boolean setEnabledInitializationPlaces(PsiElement initializerPart, PsiElement initializer) { if (initializerPart instanceof PsiReferenceExpression) { PsiReferenceExpression refExpr = (PsiReferenceExpression) initializerPart; @@ -191,7 +209,6 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { myInitialisersPlaceModel.removeElement(BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION); myInitialisersPlaceModel.removeElement(BaseExpressionToFieldHandler.InitializationPlace.IN_CONSTRUCTOR); myInitialisersPlaceModel.removeElement(BaseExpressionToFieldHandler.InitializationPlace.IN_SETUP_METHOD); - enableFinal(false); return false; } } @@ -213,6 +230,7 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { } public void setInitializeInFieldDeclaration() { + LOG.assertTrue(myInitializerCombo != null); myInitializerCombo.setSelectedItem(BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION); } @@ -222,7 +240,7 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { @Override protected boolean allowFinal() { - final Object selectedItem = myInitializerCombo.getSelectedItem(); + final Object selectedItem = getInitializerPlace(); boolean allowFinal = selectedItem == BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION || (selectedItem == BaseExpressionToFieldHandler.InitializationPlace.IN_CONSTRUCTOR && !myWillBeDeclaredStatic); if (selectedItem == BaseExpressionToFieldHandler.InitializationPlace.IN_CURRENT_METHOD && myIsCurrentMethodConstructor) { diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java index aa4065dd47b0..0bdd2648e1a9 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java @@ -21,6 +21,7 @@ import com.intellij.codeInsight.template.impl.TemplateState; import com.intellij.ide.ui.ListCellRendererWrapper; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.RangeMarker; import com.intellij.openapi.editor.ScrollType; @@ -45,6 +46,7 @@ import com.intellij.usageView.UsageInfo; import com.intellij.util.ui.UIUtil; import gnu.trove.TIntArrayList; import gnu.trove.TIntProcedure; +import sun.util.LocaleServiceProviderPool; import javax.swing.*; import java.awt.*; @@ -76,6 +78,7 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { private JComboBox myReplaceFieldsCb; private boolean myInitialized = false; + private static final Logger LOG = Logger.getInstance("#" + InplaceIntroduceParameterPopup.class.getName()); InplaceIntroduceParameterPopup(final Project project, @@ -204,6 +207,7 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { nameSuggestions.add(parameter.getName()); nameSuggestions.addAll(Arrays.asList(names)); final VariableInplaceRenamer renamer = new ParameterInplaceIntroducer(parameter); + LOG.assertTrue(parameter.isPhysical()); renamer.performInplaceRename(false, nameSuggestions); } } diff --git a/platform/lang-api/src/com/intellij/navigation/GotoRelatedItem.java b/platform/lang-api/src/com/intellij/navigation/GotoRelatedItem.java index 5849ef23b8d1..85de33223f9f 100644 --- a/platform/lang-api/src/com/intellij/navigation/GotoRelatedItem.java +++ b/platform/lang-api/src/com/intellij/navigation/GotoRelatedItem.java @@ -15,7 +15,6 @@ */ package com.intellij.navigation; -import com.intellij.psi.NavigatablePsiElement; import com.intellij.psi.PsiElement; import com.intellij.util.PsiNavigateUtil; import org.jetbrains.annotations.NotNull; @@ -55,9 +54,9 @@ public class GotoRelatedItem { return myElement; } - public static List createItems(@NotNull Collection elements) { + public static List createItems(@NotNull Collection elements) { List items = new ArrayList(elements.size()); - for (NavigatablePsiElement element : elements) { + for (PsiElement element : elements) { items.add(new GotoRelatedItem(element)); } return items; diff --git a/platform/lang-impl/src/com/intellij/find/editorHeaderActions/SwitchToFind.java b/platform/lang-impl/src/com/intellij/find/editorHeaderActions/SwitchToFind.java index 6ac05693cb50..da4bbdeadccf 100644 --- a/platform/lang-impl/src/com/intellij/find/editorHeaderActions/SwitchToFind.java +++ b/platform/lang-impl/src/com/intellij/find/editorHeaderActions/SwitchToFind.java @@ -7,6 +7,9 @@ import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.IdeActions; +import com.intellij.openapi.keymap.Keymap; +import com.intellij.openapi.keymap.KeymapManager; +import com.intellij.openapi.keymap.KeymapUtil; /** * Created by IntelliJ IDEA. @@ -26,6 +29,15 @@ public class SwitchToFind extends EditorHeaderAction { @Override public void actionPerformed(AnActionEvent e) { + if (KeymapUtil.isEmacsKeymap(KeymapManager.getInstance().getActiveKeymap())) { + // Emacs users are accustomed to the editor that executes 'find next' on subsequent pressing of shortcut that + // activates 'incremental search'. Hence, we do the similar hack here for them. + AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_NEXT); + action.update(e); + action.actionPerformed(e); + return; + } + final FindModel findModel = getEditorSearchComponent().getFindModel(); FindUtil.configureFindModel(false, getEditorSearchComponent().getEditor(), findModel); } diff --git a/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplateUtil.java b/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplateUtil.java index 0279c2f74cd5..adc226fb1d91 100644 --- a/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplateUtil.java +++ b/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplateUtil.java @@ -65,14 +65,41 @@ import java.util.*; public class FileTemplateUtil{ private static final Logger LOG = Logger.getInstance("#com.intellij.ide.fileTemplates.FileTemplateUtil"); @NonNls private static final String FILE_RESOURCE_LOADER_INSTANCE = "file.resource.loader.instance"; - private static boolean ourVelocityInitialized = false; private static final CreateFromTemplateHandler ourDefaultCreateFromTemplateHandler = new DefaultCreateFromTemplateHandler(); private FileTemplateUtil() { } + static { + try{ + File modifiedPatternsPath = new File(PathManager.getConfigPath()); + modifiedPatternsPath = new File(modifiedPatternsPath, "fileTemplates"); + modifiedPatternsPath = new File(modifiedPatternsPath, "includes"); + + LogSystem emptyLogSystem = new LogSystem() { + public void init(RuntimeServices runtimeServices) throws Exception { + } + + public void logVelocityMessage(int i, String s) { + //todo[myakovlev] log somethere? + } + }; + Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, emptyLogSystem); + Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "file,class"); + //todo[myakovlev] implement my own Loader, with ability to load templates from classpath + Velocity.setProperty(FILE_RESOURCE_LOADER_INSTANCE, new FileResourceLoader()); + Velocity.setProperty("class.resource.loader.class", MyClasspathResourceLoader.class.getName()); + Velocity.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, modifiedPatternsPath.getAbsolutePath()); + Velocity.setProperty(RuntimeConstants.INPUT_ENCODING, FileTemplate.ourEncoding); + Velocity.setProperty(RuntimeConstants.PARSER_POOL_SIZE, 3); + Velocity.init(); + } + catch (Exception e){ + LOG.error("Unable to init Velocity", e); + } + } + public static String[] calculateAttributes(String templateContent, Properties properties, boolean includeDummies) throws ParseException { - initVelocity(); final Set unsetAttributes = new HashSet(); final Set definedAttributes = new HashSet(); //noinspection HardCodedStringLiteral @@ -161,7 +188,6 @@ public class FileTemplateUtil{ } public static String mergeTemplate(Map attributes, String content) throws IOException{ - initVelocity(); VelocityContext context = new VelocityContext(); for (final Object o : attributes.keySet()) { String name = (String)o; @@ -171,7 +197,6 @@ public class FileTemplateUtil{ } public static String mergeTemplate(Properties attributes, String content) throws IOException{ - initVelocity(); VelocityContext context = new VelocityContext(); Enumeration names = attributes.propertyNames(); while (names.hasMoreElements()){ @@ -182,7 +207,6 @@ public class FileTemplateUtil{ } private static String mergeTemplate(String templateContent, final VelocityContext context) throws IOException { - initVelocity(); StringWriter stringWriter = new StringWriter(); try { Velocity.evaluate(context, stringWriter, "", templateContent); @@ -199,43 +223,8 @@ public class FileTemplateUtil{ return stringWriter.toString(); } - @SuppressWarnings({"HardCodedStringLiteral"}) - private static synchronized void initVelocity(){ - try{ - if (ourVelocityInitialized) { - return; - } - File modifiedPatternsPath = new File(PathManager.getConfigPath()); - modifiedPatternsPath = new File(modifiedPatternsPath, "fileTemplates"); - modifiedPatternsPath = new File(modifiedPatternsPath, "includes"); - - LogSystem emptyLogSystem = new LogSystem() { - public void init(RuntimeServices runtimeServices) throws Exception { - } - - public void logVelocityMessage(int i, String s) { - //todo[myakovlev] log somethere? - } - }; - Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, emptyLogSystem); - Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "file,class"); - //todo[myakovlev] implement my own Loader, with ability to load templates from classpath - Velocity.setProperty(FILE_RESOURCE_LOADER_INSTANCE, new FileResourceLoader()); - Velocity.setProperty("class.resource.loader.class", MyClasspathResourceLoader.class.getName()); - Velocity.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, modifiedPatternsPath.getAbsolutePath()); - Velocity.setProperty(RuntimeConstants.INPUT_ENCODING, FileTemplate.ourEncoding); - Velocity.setProperty(RuntimeConstants.PARSER_POOL_SIZE, 3); - Velocity.init(); - ourVelocityInitialized = true; - } - catch (Exception e){ - LOG.error("Unable to init Velocity", e); - } - } - @TestOnly public static void addResourcesDir(File dir) { - initVelocity(); final FileResourceLoader loader = (FileResourceLoader)Velocity.getProperty(FILE_RESOURCE_LOADER_INSTANCE); try { Field pathsField = FileResourceLoader.class.getDeclaredField("paths"); @@ -341,10 +330,10 @@ public class FileTemplateUtil{ return methodText.replaceAll("\n", "\n" + StringUtil.repeatSymbol(' ',indent)); } - @NonNls private static final String INCLUDES_PATH = "fileTemplates/includes/"; public static class MyClasspathResourceLoader extends ClasspathResourceLoader{ - @NonNls private static final String FT_EXTENSION = ".ft"; + private static final String INCLUDES_PATH = "fileTemplates/includes/"; + private static final String FT_EXTENSION = ".ft"; public synchronized InputStream getResourceStream(String name) throws ResourceNotFoundException{ return super.getResourceStream(INCLUDES_PATH + name + FT_EXTENSION); diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java index 0d7ed191cb03..361ce9d6fb2a 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java @@ -29,6 +29,7 @@ import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.colors.EditorColorsScheme; +import com.intellij.openapi.keymap.Keymap; import com.intellij.openapi.keymap.KeymapManager; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.Project; @@ -61,6 +62,7 @@ import com.intellij.util.containers.ContainerUtil; import com.intellij.util.diff.Diff; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -441,16 +443,30 @@ public abstract class ChooseByNameBase { } }); + final Set upShortcuts = getShortcuts(IdeActions.ACTION_EDITOR_MOVE_CARET_UP); + final Set downShortcuts = getShortcuts(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN); myTextField.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_ENTER && (e.getModifiers() & KeyEvent.SHIFT_MASK) != 0) { + if (e.getKeyCode() == KeyEvent.VK_ENTER && (e.getModifiers() & InputEvent.SHIFT_MASK) != 0) { myClosedByShiftEnter = true; close(true); } if (!myListScrollPane.isVisible()) { return; } - final int keyCode = e.getKeyCode(); + final int keyCode; + + // Add support for user-defined 'caret up/down' shortcuts. + KeyStroke stroke = KeyStroke.getKeyStrokeForEvent(e); + if (upShortcuts.contains(stroke)) { + keyCode = KeyEvent.VK_UP; + } + else if (downShortcuts.contains(stroke)) { + keyCode = KeyEvent.VK_DOWN; + } + else { + keyCode = e.getKeyCode(); + } switch (keyCode) { case KeyEvent.VK_DOWN: ListScrollingUtil.moveDown(myList, e.getModifiersEx()); @@ -529,6 +545,22 @@ public abstract class ChooseByNameBase { } } + private static Set getShortcuts(@NotNull String actionId) { + Set result = new HashSet(); + Keymap keymap = KeymapManager.getInstance().getActiveKeymap(); + Shortcut[] shortcuts = keymap.getShortcuts(actionId); + if (shortcuts == null) { + return result; + } + for (Shortcut shortcut : shortcuts) { + if (shortcut instanceof KeyboardShortcut) { + KeyboardShortcut keyboardShortcut = (KeyboardShortcut)shortcut; + result.add(keyboardShortcut.getFirstKeyStroke()); + } + } + return result; + } + private void hideHint() { if (!myTextFieldPanel.focusRequested()) { doClose(false); @@ -678,7 +710,7 @@ public abstract class ChooseByNameBase { protected void rebuildList(final int pos, final int delay, - final Runnable postRunnable, + final @Nullable Runnable postRunnable, final ModalityState modalityState, final @Nullable ComponentEvent e) { ApplicationManager.getApplication().assertIsDispatchThread(); diff --git a/platform/lang-impl/src/com/intellij/openapi/file/exclude/EnforcedPlainTextFileTypeFactory.java b/platform/lang-impl/src/com/intellij/openapi/file/exclude/EnforcedPlainTextFileTypeFactory.java index e6fba6c7d62d..a4c72e2597ea 100644 --- a/platform/lang-impl/src/com/intellij/openapi/file/exclude/EnforcedPlainTextFileTypeFactory.java +++ b/platform/lang-impl/src/com/intellij/openapi/file/exclude/EnforcedPlainTextFileTypeFactory.java @@ -41,9 +41,8 @@ public class EnforcedPlainTextFileTypeFactory extends FileTypeFactory { private final FileTypeIdentifiableByVirtualFile myFileType; - private static final EnforcedPlainTextFileTypeManager ourManager = EnforcedPlainTextFileTypeManager.getInstance(); - - + + public EnforcedPlainTextFileTypeFactory() { @@ -102,7 +101,9 @@ public class EnforcedPlainTextFileTypeFactory extends FileTypeFactory { } private static boolean isMarkedAsPlainText(VirtualFile file) { - return ourManager != null && ourManager.isMarkedAsPlainText(file); + EnforcedPlainTextFileTypeManager typeManager = EnforcedPlainTextFileTypeManager.getInstance(); + if (typeManager == null) return false; + return typeManager.isMarkedAsPlainText(file); } } diff --git a/platform/lang-impl/src/com/intellij/openapi/file/exclude/EnforcedPlainTextFileTypeManager.java b/platform/lang-impl/src/com/intellij/openapi/file/exclude/EnforcedPlainTextFileTypeManager.java index 235c5c7ba62d..eea79f1c7ac2 100644 --- a/platform/lang-impl/src/com/intellij/openapi/file/exclude/EnforcedPlainTextFileTypeManager.java +++ b/platform/lang-impl/src/com/intellij/openapi/file/exclude/EnforcedPlainTextFileTypeManager.java @@ -60,8 +60,12 @@ public class EnforcedPlainTextFileTypeManager extends PersistentFileSetManager { }); } - private final static EnforcedPlainTextFileTypeManager ourInstance = ServiceManager.getService(EnforcedPlainTextFileTypeManager.class); + private static EnforcedPlainTextFileTypeManager ourInstance; + public static EnforcedPlainTextFileTypeManager getInstance() { + if (ourInstance == null) { + ourInstance = ServiceManager.getService(EnforcedPlainTextFileTypeManager.class); + } return ourInstance; } } diff --git a/platform/platform-api/src/com/intellij/ide/plugins/IdeaPluginDescriptorImpl.java b/platform/platform-api/src/com/intellij/ide/plugins/IdeaPluginDescriptorImpl.java index 4f9e68d2b1da..9dd680be9ab5 100644 --- a/platform/platform-api/src/com/intellij/ide/plugins/IdeaPluginDescriptorImpl.java +++ b/platform/platform-api/src/com/intellij/ide/plugins/IdeaPluginDescriptorImpl.java @@ -21,7 +21,6 @@ import com.intellij.openapi.application.PathManager; import com.intellij.openapi.components.ComponentConfig; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.*; -import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.text.StringUtil; @@ -383,11 +382,13 @@ public class IdeaPluginDescriptorImpl implements IdeaPluginDescriptor { if (this == o) return true; if (!(o instanceof IdeaPluginDescriptorImpl)) return false; - return Comparing.equal(myId, ((IdeaPluginDescriptorImpl)o).myId); + final IdeaPluginDescriptorImpl pluginDescriptor = (IdeaPluginDescriptorImpl)o; + + return myName == null ? pluginDescriptor.myName == null : myName.equals(pluginDescriptor.myName); } public int hashCode() { - return myId != null ? myId.hashCode() : 0; + return myName != null ? myName.hashCode() : 0; } @NotNull diff --git a/platform/platform-api/src/com/intellij/openapi/keymap/KeymapUtil.java b/platform/platform-api/src/com/intellij/openapi/keymap/KeymapUtil.java index b99886fb4a48..b7d282403cc4 100644 --- a/platform/platform-api/src/com/intellij/openapi/keymap/KeymapUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/keymap/KeymapUtil.java @@ -27,6 +27,7 @@ import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.registry.RegistryValue; import com.intellij.openapi.util.registry.RegistryValueListener; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; @@ -39,6 +40,7 @@ import java.util.Set; import java.util.StringTokenizer; public class KeymapUtil { + private static final Icon ourKeyboardShortcutIcon = IconLoader.getIcon("/general/keyboardShortcut.png"); private static final Icon ourMouseShortcutIcon = IconLoader.getIcon("/general/mouseShortcut.png"); @NonNls private static final String APPLE_LAF_AQUA_LOOK_AND_FEEL_CLASS_NAME = "apple.laf.AquaLookAndFeel"; @@ -60,6 +62,9 @@ public class KeymapUtil { private static final Set ourOtherTooltipKeys = new HashSet(); private static RegistryValue ourTooltipKeysProperty; + private KeymapUtil() { + } + public static String getShortcutText(Shortcut shortcut) { String s = ""; @@ -99,6 +104,9 @@ public class KeymapUtil { } /** + * @param button target mouse button + * @param modifiers modifiers used within the target click + * @param clickCount target clicks count * @return string representation of passed mouse shortcut. */ public static String getMouseShortcutText(int button, int modifiers, int clickCount) { @@ -176,12 +184,12 @@ public class KeymapUtil { if (SystemInfo.isMac) { try { Class appleLaf = Class.forName(APPLE_LAF_AQUA_LOOK_AND_FEEL_CLASS_NAME); - Method getModifiers = appleLaf.getMethod(GET_KEY_MODIFIERS_TEXT_METHOD, new Class[]{int.class, boolean.class}); - return (String)getModifiers.invoke(appleLaf, new Object[]{new Integer(modifiers), Boolean.FALSE}); + Method getModifiers = appleLaf.getMethod(GET_KEY_MODIFIERS_TEXT_METHOD, int.class, boolean.class); + return (String)getModifiers.invoke(appleLaf, modifiers, Boolean.FALSE); } catch (Exception e) { if (SystemInfo.isMacOSLeopard) { - return KeymapUtil.getKeyModifiersTextForMacOSLeopard(modifiers); + return getKeyModifiersTextForMacOSLeopard(modifiers); } // OK do nothing here. @@ -198,8 +206,7 @@ public class KeymapUtil { public static String getFirstKeyboardShortcutText(AnAction action) { Shortcut[] shortcuts = action.getShortcutSet().getShortcuts(); - for (int i = 0; i < shortcuts.length; i++) { - Shortcut shortcut = shortcuts[i]; + for (Shortcut shortcut : shortcuts) { if (shortcut instanceof KeyboardShortcut) { return getShortcutText(shortcut); } @@ -211,20 +218,22 @@ public class KeymapUtil { if (shortcuts.length == 0) { return ""; } - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); for (int i = 0; i < shortcuts.length; i++) { Shortcut shortcut = shortcuts[i]; if (i > 0) { buffer.append(' '); } - buffer.append(KeymapUtil.getShortcutText(shortcut)); + buffer.append(getShortcutText(shortcut)); } return buffer.toString(); } /** * Factory method. It parses passed string and creates MouseShortcut. - * + * + * @param keystrokeString target keystroke + * @return shortcut for the given keystroke * @throws InvalidDataException if keystrokeString doesn't represent valid MouseShortcut. */ public static MouseShortcut parseMouseShortcut(String keystrokeString) throws InvalidDataException { @@ -234,19 +243,19 @@ public class KeymapUtil { for (StringTokenizer tokenizer = new StringTokenizer(keystrokeString); tokenizer.hasMoreTokens();) { String token = tokenizer.nextToken(); if (SHIFT.equals(token)) { - modifiers |= MouseEvent.SHIFT_DOWN_MASK; + modifiers |= InputEvent.SHIFT_DOWN_MASK; } else if (CONTROL.equals(token) || CTRL.equals(token)) { - modifiers |= MouseEvent.CTRL_DOWN_MASK; + modifiers |= InputEvent.CTRL_DOWN_MASK; } else if (META.equals(token)) { - modifiers |= MouseEvent.META_DOWN_MASK; + modifiers |= InputEvent.META_DOWN_MASK; } else if (ALT.equals(token)) { - modifiers |= MouseEvent.ALT_DOWN_MASK; + modifiers |= InputEvent.ALT_DOWN_MASK; } else if (ALT_GRAPH.equals(token)) { - modifiers |= MouseEvent.ALT_GRAPH_DOWN_MASK; + modifiers |= InputEvent.ALT_GRAPH_DOWN_MASK; } else if (BUTTON1.equals(token)) { button = MouseEvent.BUTTON1; @@ -268,7 +277,7 @@ public class KeymapUtil { } public static String getKeyModifiersTextForMacOSLeopard(int modifiers) { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); if ((modifiers & InputEvent.META_MASK) != 0) { buf.append(Toolkit.getProperty("AWT.meta", "Meta")); } @@ -324,10 +333,10 @@ public class KeymapUtil { ourTooltipKeys.clear(); ourOtherTooltipKeys.clear(); - processKey(text.contains("meta"), KeyEvent.META_MASK); - processKey(text.contains("control") | text.contains("ctrl"), KeyEvent.CTRL_MASK); - processKey(text.contains("shift"), KeyEvent.SHIFT_MASK); - processKey(text.contains("alt"), KeyEvent.ALT_MASK); + processKey(text.contains("meta"), InputEvent.META_MASK); + processKey(text.contains("control") | text.contains("ctrl"), InputEvent.CTRL_MASK); + processKey(text.contains("shift"), InputEvent.SHIFT_MASK); + processKey(text.contains("alt"), InputEvent.ALT_MASK); } @@ -338,4 +347,13 @@ public class KeymapUtil { ourOtherTooltipKeys.add(value); } } + + public static boolean isEmacsKeymap(@Nullable Keymap keymap) { + for (; keymap != null; keymap = keymap.getParent()) { + if ("Emacs".equalsIgnoreCase(keymap.getName())) { + return true; + } + } + return false; + } } diff --git a/platform/platform-api/src/com/intellij/openapi/ui/LoadingDecorator.java b/platform/platform-api/src/com/intellij/openapi/ui/LoadingDecorator.java index 5b2c78eba050..6070c21a3644 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/LoadingDecorator.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/LoadingDecorator.java @@ -70,6 +70,22 @@ public class LoadingDecorator { Disposer.register(parent, myLoadingLayer.myProgress); } + protected NonOpaquePanel customizeLoadingLayer(JPanel parent, JLabel text, AsyncProcessIcon icon) { + parent.setLayout(new GridBagLayout()); + + final Font font = text.getFont(); + text.setFont(font.deriveFont(font.getStyle(), font.getSize() + 8)); + text.setForeground(Color.black); + + final int gap = new JLabel().getIconTextGap(); + final NonOpaquePanel result = new NonOpaquePanel(new FlowLayout(FlowLayout.CENTER, gap * 3, 0)); + result.add(icon); + result.add(text); + parent.add(result); + + return result; + } + public JComponent getComponent() { return myPane; } @@ -121,8 +137,7 @@ public class LoadingDecorator { } private class LoadingLayer extends JPanel { - - private final JLabel myText; + private final JLabel myText = new JLabel("", SwingConstants.CENTER); private BufferedImage mySnapshot; private Color mySnapshotBg; @@ -137,22 +152,8 @@ public class LoadingDecorator { private LoadingLayer() { setOpaque(false); setVisible(false); - setLayout(new GridBagLayout()); - - myText = new JLabel("", JLabel.CENTER); - final Font font = myText.getFont(); - myText.setFont(font.deriveFont(font.getStyle(), font.getSize() + 8)); - myText.setForeground(Color.black); myProgress.setOpaque(false); - - - final int gap = new JLabel().getIconTextGap(); - myTextComponent = new NonOpaquePanel(new FlowLayout(FlowLayout.CENTER, gap * 3, 0)); - myTextComponent.add(myProgress); - myTextComponent.add(myText); - - add(myTextComponent); - + myTextComponent = customizeLoadingLayer(this, myText, myProgress); myProgress.suspend(); } diff --git a/platform/platform-api/src/com/intellij/openapi/ui/Messages.java b/platform/platform-api/src/com/intellij/openapi/ui/Messages.java index b748b825aa73..24c1dd29f7a9 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/Messages.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/Messages.java @@ -139,7 +139,7 @@ public class Messages { } } - public static int showDialog(String message, String title, String[] options, int defaultOptionIndex, int focusedOptionIndex, Icon icon, DialogWrapper.DoNotAskOption doNotAskOption) { + public static int showDialog(String message, String title, String[] options, int defaultOptionIndex, int focusedOptionIndex, @Nullable Icon icon, @Nullable DialogWrapper.DoNotAskOption doNotAskOption) { if (isApplicationInUnitTestOrHeadless()) { return ourTestImplementation.show(message); } @@ -157,26 +157,26 @@ public class Messages { * @see #showDialog(Project, String, String, String[], int, Icon) * @see #showDialog(Component, String, String, String[], int, Icon) */ - public static int showDialog(String message, String title, String[] options, int defaultOptionIndex, Icon icon, DialogWrapper.DoNotAskOption doNotAskOption) { + public static int showDialog(String message, String title, String[] options, int defaultOptionIndex, @Nullable Icon icon, @Nullable DialogWrapper.DoNotAskOption doNotAskOption) { return showDialog(message, title, options, defaultOptionIndex, -1, icon, doNotAskOption); } - public static int showDialog(String message, String title, String[] options, int defaultOptionIndex, Icon icon) { + public static int showDialog(String message, String title, String[] options, int defaultOptionIndex, @Nullable Icon icon) { return showDialog(message, title, options, defaultOptionIndex, -1, icon); } - public static int showDialog(String message, String title, String[] options, int defaultOptionIndex, int focusedOptionIndex, Icon icon) { + public static int showDialog(String message, String title, String[] options, int defaultOptionIndex, int focusedOptionIndex, @Nullable Icon icon) { return showDialog(message, title, options, defaultOptionIndex, focusedOptionIndex, icon, null); } /** * @see com.intellij.openapi.ui.DialogWrapper#DialogWrapper(Project,boolean) */ - public static void showMessageDialog(Project project, String message, String title, Icon icon) { + public static void showMessageDialog(Project project, String message, String title, @Nullable Icon icon) { showDialog(project, message, title, new String[]{OK_BUTTON}, 0, icon); } - public static void showMessageDialog(Component parent, String message, String title, Icon icon) { + public static void showMessageDialog(Component parent, String message, String title, @Nullable Icon icon) { showDialog(parent, message, title, new String[]{OK_BUTTON}, 0, icon); } @@ -186,21 +186,21 @@ public class Messages { * @see #showMessageDialog(Project, String, String, Icon) * @see #showMessageDialog(Component, String, String, Icon) */ - public static void showMessageDialog(String message, String title, Icon icon) { + public static void showMessageDialog(String message, String title, @Nullable Icon icon) { showDialog(message, title, new String[]{OK_BUTTON}, 0, icon); } /** * @return 0 if user pressed "Yes" and returns 1 if user pressed "No" button. */ - public static int showYesNoDialog(Project project, String message, String title, Icon icon) { + public static int showYesNoDialog(Project project, String message, String title, @Nullable Icon icon) { return showDialog(project, message, title, new String[]{YES_BUTTON, NO_BUTTON}, 0, icon); } /** * @return 0 if user pressed "Yes" and returns 1 if user pressed "No" button. */ - public static int showYesNoDialog(Component parent, String message, String title, Icon icon) { + public static int showYesNoDialog(Component parent, String message, String title, @Nullable Icon icon) { return showDialog(parent, message, title, new String[]{YES_BUTTON, NO_BUTTON}, 0, icon); } @@ -211,7 +211,7 @@ public class Messages { * @see #showYesNoDialog(Project, String, String, Icon) * @see #showYesNoDialog(Component, String, String, Icon) */ - public static int showYesNoDialog(String message, String title, Icon icon) { + public static int showYesNoDialog(String message, String title, @Nullable Icon icon) { return showDialog(message, title, new String[]{YES_BUTTON, NO_BUTTON}, 0, icon); } @@ -657,7 +657,7 @@ public class Messages { super(project, false); } - protected void _init(String title, String message, String[] options, int defaultOptionIndex, int focusedOptionIndex, Icon icon, DoNotAskOption doNotAskOption) { + protected void _init(String title, String message, String[] options, int defaultOptionIndex, int focusedOptionIndex, @Nullable Icon icon, @Nullable DoNotAskOption doNotAskOption) { setTitle(title); myMessage = message; myOptions = options; @@ -694,7 +694,7 @@ public class Messages { return actions; } - private void assignMnemonic(String option, Action action) { + private static void assignMnemonic(String option, Action action) { int mnemoPos = option.indexOf("&"); if (mnemoPos >= 0 && mnemoPos < option.length() - 2) { String mnemoChar = option.substring(mnemoPos + 1, mnemoPos + 2).trim(); diff --git a/platform/platform-api/src/com/intellij/psi/util/CachedValueProvider.java b/platform/platform-api/src/com/intellij/psi/util/CachedValueProvider.java index c9d0dc638713..74991358310b 100644 --- a/platform/platform-api/src/com/intellij/psi/util/CachedValueProvider.java +++ b/platform/platform-api/src/com/intellij/psi/util/CachedValueProvider.java @@ -26,7 +26,7 @@ public interface CachedValueProvider { private final Object[] myDependencyItems; private boolean myLockValue = false; - public Result(T value, Object... dependencyItems) { + public Result(@Nullable T value, Object... dependencyItems) { myValue = value; myDependencyItems = dependencyItems; } @@ -39,11 +39,11 @@ public interface CachedValueProvider { return myDependencyItems; } - public static Result createSingleDependency(T value, Object dependency) { + public static Result createSingleDependency(@Nullable T value, Object dependency) { return create(value, dependency); } - public static Result create(T value, Object... dependencies) { + public static Result create(@Nullable T value, Object... dependencies) { return new Result(value, dependencies); } diff --git a/platform/platform-api/src/com/intellij/ui/EditorNotifications.java b/platform/platform-api/src/com/intellij/ui/EditorNotifications.java index 84c141b66420..40b91e0d4e01 100644 --- a/platform/platform-api/src/com/intellij/ui/EditorNotifications.java +++ b/platform/platform-api/src/com/intellij/ui/EditorNotifications.java @@ -24,6 +24,7 @@ import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileEditor.FileEditorManagerAdapter; import com.intellij.openapi.fileEditor.FileEditorManagerListener; import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.NotNullLazyValue; import com.intellij.openapi.vfs.VirtualFile; @@ -41,9 +42,9 @@ public class EditorNotifications extends AbstractProjectComponent { public interface Provider { - Key getKey(); + @Nullable T createNotificationPanel(VirtualFile file); @@ -110,4 +111,11 @@ public class EditorNotifications extends AbstractProjectComponent { editor.putUserData(key, null); } } + + public static void updateAll() { + Project[] projects = ProjectManager.getInstance().getOpenProjects(); + for (Project project : projects) { + getInstance(project).updateAllNotifications(); + } + } } diff --git a/platform/platform-api/src/com/intellij/ui/components/editors/JBComboBoxTableCellEditorComponent.java b/platform/platform-api/src/com/intellij/ui/components/editors/JBComboBoxTableCellEditorComponent.java index 856364dacf1b..d775dabd88cc 100644 --- a/platform/platform-api/src/com/intellij/ui/components/editors/JBComboBoxTableCellEditorComponent.java +++ b/platform/platform-api/src/com/intellij/ui/components/editors/JBComboBoxTableCellEditorComponent.java @@ -127,6 +127,7 @@ public class JBComboBoxTableCellEditorComponent extends JBLabel { @Override public void run() { myValue = myList.getSelectedValue(); + myTable.setValueAt(myValue, myRow, myColumn); // on Mac getCellEditorValue() called before myValue is set. } }).createPopup() .show(new RelativePoint(myTable, point)); diff --git a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeMouseEventDispatcher.java b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeMouseEventDispatcher.java index 2d9d3f65a19d..a9c030d65126 100644 --- a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeMouseEventDispatcher.java +++ b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeMouseEventDispatcher.java @@ -206,8 +206,9 @@ public final class IdeMouseEventDispatcher { } private static int getScrollAmount(Component c, MouseWheelEvent me, JScrollBar scrollBar) { - final int ratio = Registry.is("ide.smart.horizontal.scrolling") - ? Math.max((int)Math.pow(c.getWidth() / scrollBar.getWidth() , 2), 10) : 10; // do annoying scrolling faster if smart scrolling is on + final int scrollBarWidth = scrollBar.getWidth(); + final int ratio = Registry.is("ide.smart.horizontal.scrolling") && scrollBarWidth > 0 + ? Math.max((int)Math.pow(c.getWidth() / scrollBarWidth, 2), 10) : 10; // do annoying scrolling faster if smart scrolling is on return me.getUnitsToScroll() * scrollBar.getUnitIncrement() * ratio; } diff --git a/platform/util/src/com/intellij/ide/ui/ListCellRendererWrapper.java b/platform/util/src/com/intellij/ide/ui/ListCellRendererWrapper.java index 9c83b38427b6..3c21618515c0 100644 --- a/platform/util/src/com/intellij/ide/ui/ListCellRendererWrapper.java +++ b/platform/util/src/com/intellij/ide/ui/ListCellRendererWrapper.java @@ -15,6 +15,8 @@ */ package com.intellij.ide.ui; +import org.jetbrains.annotations.Nullable; + import javax.swing.*; import java.awt.*; @@ -87,7 +89,7 @@ public abstract class ListCellRendererWrapper implements ListCellRenderer { */ public abstract void customize(final JList list, final T value, final int index, final boolean selected, final boolean hasFocus); - public final void setIcon(final Icon icon) { + public final void setIcon(final @Nullable Icon icon) { myIcon = icon; } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DTree.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DTree.java index a9514f8d3e0e..eaa259090265 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DTree.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DTree.java @@ -52,6 +52,8 @@ public class DTree { private DiffElement myTarget; private DType type; private boolean myVisible = true; + private String mySeparator = null; + private String myPath = null; public DTree(@Nullable DTree parent, @NotNull String name, boolean container) { this.myParent = parent; @@ -209,16 +211,21 @@ public class DTree { } public String getPath() { - final DTree parent = getParent(); - if (parent != null) { - return parent.getPath() + getName() + (isContainer ? getSeparator() : ""); - } else { - return getName() + (isContainer ? getSeparator() : ""); + if (myPath == null) { + final DTree parent = getParent(); + if (parent != null) { + myPath = parent.getPath() + getName() + (isContainer ? getSeparator() : ""); + } else { + myPath = getName() + (isContainer ? getSeparator() : ""); + } } + return myPath; } private String getSeparator() { - final String s = mySource != null ? mySource.getSeparator() : myTarget != null ? myTarget.getSeparator() : ""; - return s; + if (mySeparator == null) { + mySeparator = mySource != null ? mySource.getSeparator() : myTarget != null ? myTarget.getSeparator() : ""; + } + return mySeparator; } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffDialog.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffDialog.java index 7649e0c52844..1c84335c5412 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffDialog.java @@ -39,7 +39,8 @@ public class DirDiffDialog extends DialogWrapper { setTitle("Directory Diff"); init(); final JBTable table = myDiffPanel.getTable(); - table.changeSelection(myModel.getElementAt(0).isSeparator() ? 1 : 0, 3, false, false); + //final DirDiffElement element = myModel.getElementAt(0); + //table.changeSelection(element.isSeparator() ? 1 : 0, 3, false, false); table.setColumnSelectionAllowed(false); table.getTableHeader().setReorderingAllowed(false); table.getTableHeader().setResizingAllowed(false); @@ -61,6 +62,11 @@ public class DirDiffDialog extends DialogWrapper { return myDiffPanel.getTable(); } + @Override + public void show() { + super.show(); + } + @Override public void doCancelAction() { super.doCancelAction(); diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffManagerImpl.java index 65bfcb362a6c..99883ef1e9e3 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffManagerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffManagerImpl.java @@ -17,13 +17,8 @@ package com.intellij.openapi.diff.impl.dir; import com.intellij.ide.diff.DiffElement; import com.intellij.ide.diff.DirDiffSettings; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diff.DirDiffManager; -import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.Messages; import org.jetbrains.annotations.NotNull; /** @@ -38,24 +33,8 @@ public class DirDiffManagerImpl extends DirDiffManager { @Override public void showDiff(@NotNull final DiffElement dir1, @NotNull final DiffElement dir2, final DirDiffSettings settings) { - Task.Backgroundable task = new Task.Backgroundable(myProject, "Directory comparison", true) { - @Override - public void run(@NotNull ProgressIndicator indicator) { - indicator.setText("Calculating differences"); - final DirDiffTableModel model = new DirDiffTableModel(myProject, dir1, dir2, indicator, settings); - final Runnable run = new Runnable() { - public void run() { - if (model.getRowCount() == 0) { - Messages.showInfoMessage(myProject, "No difference has been found", "Directory Diff Tool"); - } else { - new DirDiffDialog(myProject, model, settings).show(); - } - } - }; - ApplicationManager.getApplication().invokeLater(run); - } - }; - ProgressManager.getInstance().run(task); + final DirDiffTableModel model = new DirDiffTableModel(myProject, dir1, dir2, settings); + new DirDiffDialog(myProject, model, settings).show(); } @Override diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.form b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.form index 5fe7a42a6536..bb55dcd135f3 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.form +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.form @@ -1,137 +1,144 @@
- + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java index 1c2c4a1d05c0..f6842c39c008 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java @@ -21,10 +21,13 @@ import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.ActionToolbar; import com.intellij.openapi.diff.impl.dir.actions.DirDiffToolbarActions; import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.LoadingDecorator; import com.intellij.openapi.ui.TextFieldWithBrowseButton; import com.intellij.ui.components.JBLabel; import com.intellij.ui.components.JBScrollPane; +import com.intellij.ui.components.panels.NonOpaquePanel; import com.intellij.ui.table.JBTable; +import com.intellij.util.ui.AsyncProcessIcon; import javax.swing.*; import javax.swing.event.ListSelectionEvent; @@ -32,8 +35,11 @@ import javax.swing.event.ListSelectionListener; import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; import java.awt.*; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; +import java.util.concurrent.atomic.AtomicBoolean; /** * @author Konstantin Bulenkov @@ -52,6 +58,7 @@ public class DirDiffPanel { private JComboBox myFileFilter; private JPanel myToolBarPanel; private JBScrollPane myScrollPane; + private JPanel myRootPanel; private final DirDiffTableModel myModel; public JLabel myErrorLabel; private final DirDiffDialog myDialog; @@ -67,7 +74,10 @@ public class DirDiffPanel { myTargetDirField.setText(model.getTargetDir().getPath()); mySourceDirLabel.setIcon(model.getSourceDir().getIcon()); myTargetDirLabel.setIcon(model.getTargetDir().getIcon()); + myModel.setTable(myTable); + myModel.setDisposableParent(dirDiffDialog.getDisposable()); myTable.setModel(myModel); + final DirDiffTableCellRenderer renderer = new DirDiffTableCellRenderer(myTable); myTable.setDefaultRenderer(Object.class, renderer); myTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); @@ -148,8 +158,41 @@ public class DirDiffPanel { final TableColumn operationColumn = columnModel.getColumn((columnModel.getColumnCount() - 1) / 2); operationColumn.setMaxWidth(25); operationColumn.setMinWidth(25); + for (int i = 0; i < columnModel.getColumnCount(); i++) { + final String name = myModel.getColumnName(i); + final TableColumn column = columnModel.getColumn(i); + if (DirDiffTableModel.COLUMN_DATE.equals(name)) { + column.setMaxWidth(90); + column.setMinWidth(90); + } else if (DirDiffTableModel.COLUMN_SIZE.equals(name)) { + column.setMaxWidth(120); + column.setMinWidth(120); + } + } final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("DirDiff", new DirDiffToolbarActions(myModel), true); myToolBarPanel.add(toolbar.getComponent(), BorderLayout.CENTER); + final LoadingDecorator decorator = new LoadingDecorator(myComponent, dirDiffDialog.getDisposable(), -1) { + @Override + protected NonOpaquePanel customizeLoadingLayer(JPanel parent, JLabel text, AsyncProcessIcon icon) { + final NonOpaquePanel panel = super.customizeLoadingLayer(parent, text, icon); + final Font font = text.getFont(); + text.setFont(font.deriveFont(font.getStyle(), font.getSize() + 6)); + text.setForeground(new Color(0,0,0,150)); + return panel; + } + }; + //mySplitPanel.setTopComponent(decorator.getComponent()); + decorator.getComponent().setMinimumSize(new Dimension(400, 100)); + myTable.putClientProperty(myModel.DECORATOR, decorator); + myTable.addComponentListener(new ComponentAdapter() { + @Override + public void componentShown(ComponentEvent e) { + myTable.removeComponentListener(this); + myModel.reloadModel(); + } + }); + myRootPanel.removeAll(); + myRootPanel.add(decorator.getComponent(), BorderLayout.CENTER); } private JLabel getErrorLabel() { @@ -176,7 +219,7 @@ public class DirDiffPanel { } public JComponent getPanel() { - return myComponent; + return myRootPanel; } public JBTable getTable() { @@ -184,6 +227,21 @@ public class DirDiffPanel { } public void dispose() { + myModel.stopUpdating(); clearDiffPanel(); } + + private void createUIComponents() { + final AtomicBoolean callUpdate = new AtomicBoolean(true); + myRootPanel = new JPanel(new BorderLayout()) { + @Override + protected void paintChildren(Graphics g) { + super.paintChildren(g); + if (callUpdate.get()) { + callUpdate.set(false); + myModel.reloadModel(); + } + } + }; + } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java index 9288efbfeb99..bd30f1da600a 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java @@ -17,14 +17,21 @@ package com.intellij.openapi.diff.impl.dir; import com.intellij.ide.diff.DiffElement; import com.intellij.ide.diff.DirDiffSettings; -import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.Disposable; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.LoadingDecorator; +import com.intellij.ui.table.JBTable; import org.jetbrains.annotations.Nullable; +import javax.swing.*; import javax.swing.table.AbstractTableModel; import java.io.IOException; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; /** * @author Konstantin Bulenkov @@ -37,61 +44,172 @@ public class DirDiffTableModel extends AbstractTableModel { private final DirDiffSettings mySettings; private DiffElement mySrc; private DiffElement myTrg; - final List myElements = new ArrayList(); - private boolean myUpdating = false; + private DTree myTree; + private final List myElements = new ArrayList(); + private final AtomicBoolean myUpdating = new AtomicBoolean(false); + private JBTable myTable; + private Disposable myDisposableParent; + public String DECORATOR = "DIFF_TABLE_DECORATOR"; + public volatile AtomicReference text = new AtomicReference(prepareText("")); + private Updater updater; + + + public static final String EMPTY_STRING = " "; - public DirDiffTableModel(Project project, DiffElement src, DiffElement trg, ProgressIndicator indicator, DirDiffSettings settings) { + public void stopUpdating() { + if (myUpdating.get()) { + myUpdating.set(false); + } + } + + public void applyRemove() { + myUpdating.set(true); + final Iterator i = myElements.iterator(); + while(i.hasNext()) { + final DType type = i.next().getType(); + switch (type) { + case SOURCE: + if (!mySettings.showNewOnSource) i.remove(); + break; + case TARGET: + if (!mySettings.showNewOnTarget) i.remove(); + break; + case SEPARATOR: + break; + case CHANGED: + if (!mySettings.showDifferent) i.remove(); + break; + case EQUAL: + if (!mySettings.showEqual) i.remove(); + break; + } + } + + boolean sep = true; + for (int j = myElements.size() - 1; j >= 0; j--) { + if (myElements.get(j).isSeparator()) { + if (sep) { + myElements.remove(j); + } else { + sep = true; + } + } else { + sep = false; + } + } + fireTableDataChanged(); + myUpdating.set(false); + } + + private static String prepareText(String text) { + final int LEN = EMPTY_STRING.length(); + String right; + if (text == null) { + right = EMPTY_STRING; + } else if (text.length() == LEN) { + right = text; + } else if (text.length() < LEN) { + right = text + EMPTY_STRING.substring(0, LEN - text.length()); + } else { + right = "..." + text.substring(text.length() - LEN + 2); + } + return "Loading... " + right; + } + + public DirDiffTableModel(Project project, DiffElement src, DiffElement trg, DirDiffSettings settings) { myProject = project; mySettings = settings; mySrc = src; myTrg = trg; - reloadModel(indicator); } - public void reloadModel(ProgressIndicator indicator) { - myUpdating = true; - clear(); - final DTree tree = new DTree(null, "", true); - scan(mySrc, tree, true); - scan(myTrg, tree, false); + public void reloadModel() { + myUpdating.set(true); + final LoadingDecorator decorator = getDecorator(); + decorator.startLoading(false); + ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { + public void run() { + try { + updater = new Updater(decorator, 100); + updater.start(); + myTree = new DTree(null, "", true); + scan(mySrc, myTree, true); + scan(myTrg, myTree, false); - tree.setSource(mySrc); - tree.setTarget(myTrg); - tree.update(mySettings); - tree.updateVisibility(mySettings); - - myElements.clear(); - fillElements(tree); - fireTableDataChanged(); - myUpdating = false; + myTree.setSource(mySrc); + myTree.setTarget(myTrg); + myTree.update(mySettings); + applySettings(); + } + catch (Exception e) {// + } + } + }); } - private void fillElements(DTree tree) { + private LoadingDecorator getDecorator() { + return (LoadingDecorator)myTable.getClientProperty(DECORATOR); + } + + public void applySettings() { + if (! myUpdating.get()) myUpdating.set(true); + if (!getDecorator().isLoading()) { + getDecorator().startLoading(false); + if (updater == null) { + updater = new Updater(getDecorator(), 100); + updater.start(); + } + } + ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { + public void run() { + myTree.updateVisibility(mySettings); + final ArrayList elements = new ArrayList(); + fillElements(myTree, elements); + ApplicationManager.getApplication().invokeLater(new Runnable() { + public void run() { + clear(); + myElements.addAll(elements); + myUpdating.set(false); + fireTableDataChanged(); + DirDiffTableModel.this.text.set(""); + if (getDecorator().isLoading()) { + getDecorator().stopLoading(); + } + } + }); + } + }); + } + + private void fillElements(DTree tree, List elements) { + if (!myUpdating.get()) return; boolean separatorAdded = tree.getParent() == null; + text.set(prepareText(tree.getPath())); for (DTree child : tree.getChildren()) { + if (!myUpdating.get()) return; if (!child.isContainer()) { if (child.isVisible()) { if (!separatorAdded) { - myElements.add(DirDiffElement.createDirElement(tree.getSource(), tree.getTarget(), tree.getPath())); + elements.add(DirDiffElement.createDirElement(tree.getSource(), tree.getTarget(), tree.getPath())); separatorAdded = true; } switch (child.getType()) { case SOURCE: - myElements.add(DirDiffElement.createSourceOnly(child.getSource())); + elements.add(DirDiffElement.createSourceOnly(child.getSource())); break; case TARGET: - myElements.add(DirDiffElement.createTargetOnly(child.getTarget())); + elements.add(DirDiffElement.createTargetOnly(child.getTarget())); break; case CHANGED: - myElements.add(DirDiffElement.createChange(child.getSource(), child.getTarget())); + elements.add(DirDiffElement.createChange(child.getSource(), child.getTarget())); break; case EQUAL: - myElements.add(DirDiffElement.createEqual(child.getSource(), child.getTarget())); + elements.add(DirDiffElement.createEqual(child.getSource(), child.getTarget())); break; } } } else { - fillElements(child); + fillElements(child, elements); } } } @@ -104,10 +222,17 @@ public class DirDiffTableModel extends AbstractTableModel { } } - private static void scan(DiffElement element, DTree root, boolean source) { + public void setDisposableParent(Disposable parent) { + myDisposableParent = parent; + } + + private void scan(DiffElement element, DTree root, boolean source) { + if (!myUpdating.get()) return; if (element.isContainer()) { try { + text.set(prepareText(element.getPath())); for (DiffElement child : element.getChildren()) { + if (!myUpdating.get()) return; scan(child, root.addChild(child, source), source); } } @@ -146,6 +271,14 @@ public class DirDiffTableModel extends AbstractTableModel { return count; } + public JBTable getTable() { + return myTable; + } + + public void setTable(JBTable table) { + myTable = table; + } + @Nullable @Override public Object getValueAt(int rowIndex, int columnIndex) { @@ -218,6 +351,41 @@ public class DirDiffTableModel extends AbstractTableModel { } public boolean isUpdating() { - return myUpdating; + return myUpdating.get(); + } + + class Updater extends Thread { + private final LoadingDecorator myDecorator; + private final int mySleep; + + Updater(LoadingDecorator decorator, int sleep) { + super("Loading Updater"); + myDecorator = decorator; + mySleep = sleep; + } + + @Override + public void run() { + if (myDecorator.isLoading()) { + try { + Thread.sleep(mySleep); + } + catch (InterruptedException e) {// + } + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + final String s = text.get(); + if (s != null && myDecorator.isLoading()) { + myDecorator.setLoadingText(s); + } + } + }); + updater = new Updater(myDecorator, mySleep); + updater.start(); + } else { + updater = null; + } + } } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/DirDiffAction.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/DirDiffAction.java index 40b5ab1d23f7..37395bccb0c9 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/DirDiffAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/DirDiffAction.java @@ -42,7 +42,15 @@ public abstract class DirDiffAction extends ToggleAction implements DirDiffIcons @Override public final void setSelected(AnActionEvent e, boolean state) { updateState(state); - getModel().reloadModel(null); + if (this.getClass() == RefreshDirDiffAction.class) { + getModel().reloadModel(); + } else { + if (state) { + getModel().applySettings(); + } else { + getModel().applyRemove(); + } + } } @Override diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovycStubGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovycStubGenerator.java index d57961996d00..5da050e976f0 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovycStubGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovycStubGenerator.java @@ -133,7 +133,7 @@ public class GroovycStubGenerator extends GroovyCompilerBase { indicator.pushState(); try { - final GroovyToJavaGenerator generator = new GroovyToJavaGenerator(myProject, toCompile, false); + final GroovyToJavaGenerator generator = new GroovyToJavaGenerator(myProject, new HashSet(toCompile), false); for (int i = 0; i < toCompile.size(); i++) { indicator.setFraction((double)i / toCompile.size()); @@ -212,21 +212,21 @@ public class GroovycStubGenerator extends GroovyCompilerBase { LOG.debug("Generating stubs for " + item.getName() + "..."); } - final Map output = ApplicationManager.getApplication().runReadAction(new Computable>() { - public Map compute() { + final Map output = ApplicationManager.getApplication().runReadAction(new Computable>() { + public Map compute() { return generator.generateStubs((GroovyFile)PsiManager.getInstance(project).findFile(item)); } }); return writeStubs(outputRootDirectory, output, item); } - private static List writeStubs(VirtualFile outputRootDirectory, Map output, VirtualFile src) { + private static List writeStubs(VirtualFile outputRootDirectory, Map output, VirtualFile src) { final ArrayList stubs = CollectionFactory.arrayList(); for (String relativePath : output.keySet()) { final File stubFile = new File(outputRootDirectory.getPath(), relativePath); FileUtil.createIfDoesntExist(stubFile); try { - FileUtil.writeToFile(stubFile, output.get(relativePath).getBytes(src.getCharset())); + FileUtil.writeToFile(stubFile, output.get(relativePath).toString().getBytes(src.getCharset())); } catch (IOException e) { LOG.error(e); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/arguments/GrArgumentLabelImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/arguments/GrArgumentLabelImpl.java index 7b0ed1d4deeb..599f27ec3236 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/arguments/GrArgumentLabelImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/arguments/GrArgumentLabelImpl.java @@ -30,7 +30,6 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.extensions.GroovyNamedArgumentProvider; import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; import org.jetbrains.plugins.groovy.lang.lexer.TokenSets; -import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes; import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor; import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel; import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument; @@ -70,7 +69,7 @@ public class GrArgumentLabelImpl extends GroovyPsiElementImpl implements GrArgum if (!(nameElement instanceof LeafPsiElement)) return null; IElementType elementType = ((LeafPsiElement)nameElement).getElementType(); - if (elementType != GroovyTokenTypes.mIDENT && !CommonClassNames.JAVA_LANG_STRING.equals(TypesUtil.getPsiTypeName(elementType))) { + if (elementType != GroovyTokenTypes.mIDENT && !CommonClassNames.JAVA_LANG_STRING.equals(TypesUtil.getBoxedTypeName(elementType))) { return null; } @@ -166,7 +165,7 @@ public class GrArgumentLabelImpl extends GroovyPsiElementImpl implements GrArgum return element.getText(); } - if (CommonClassNames.JAVA_LANG_STRING.equals(TypesUtil.getPsiTypeName(elemType))) { + if (CommonClassNames.JAVA_LANG_STRING.equals(TypesUtil.getBoxedTypeName(elemType))) { return GrStringUtil.removeQuotes(element.getText()); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/TypesUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/TypesUtil.java index f9e852621620..b4228b4995dc 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/TypesUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/TypesUtil.java @@ -428,7 +428,7 @@ public class TypesUtil { if (elemType == kNULL) { return PsiType.NULL; } - final String typeName = getPsiTypeName(elemType); + final String typeName = getBoxedTypeName(elemType); if (typeName != null) { return createTypeByFQClassName(typeName, context); } @@ -436,7 +436,7 @@ public class TypesUtil { } @Nullable - public static String getPsiTypeName(IElementType elemType) { + public static String getBoxedTypeName(IElementType elemType) { return ourPrimitiveTypesToClassNames.get(elemType); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/types/GrCodeReferenceElementImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/types/GrCodeReferenceElementImpl.java index 87f1fc660b47..c34cb48d1c61 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/types/GrCodeReferenceElementImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/types/GrCodeReferenceElementImpl.java @@ -162,8 +162,8 @@ public class GrCodeReferenceElementImpl extends GrReferenceElementImpl groovyLiteralExpression(final ElementPattern value) { + public static GroovyElementPattern.Capture groovyLiteralExpression(@Nullable final ElementPattern value) { return new GroovyElementPattern.Capture(new InitialPatternCondition(GrLiteral.class) { public boolean accepts(@Nullable final Object o, final ProcessingContext context) { - return o instanceof GrLiteral - && (value == null || value.accepts(((GrLiteral)o).getValue(), context)); + return o instanceof GrLiteral && (value == null || value.accepts(((GrLiteral)o).getValue(), context)); } }); } @@ -103,8 +102,8 @@ public class GroovyPatterns extends PsiJavaPatterns { PsiElement nameElement = ((GrArgumentLabel)o).getNameElement(); if (nameElement instanceof LeafPsiElement) { IElementType elementType = ((LeafPsiElement)nameElement).getElementType(); - if (elementType == GroovyElementTypes.mIDENT || - CommonClassNames.JAVA_LANG_STRING.equals(TypesUtil.getPsiTypeName(elementType))) { + if (elementType == GroovyTokenTypes.mIDENT || + CommonClassNames.JAVA_LANG_STRING.equals(TypesUtil.getBoxedTypeName(elementType))) { return namePattern == null || namePattern.accepts(((GrArgumentLabel)o).getName()); } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassGenerator.java new file mode 100644 index 000000000000..8313d5b43325 --- /dev/null +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassGenerator.java @@ -0,0 +1,590 @@ +/* + * Copyright 2000-2011 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.refactoring.convertToJava; + +import com.intellij.codeInsight.generation.OverrideImplementUtil; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.*; +import com.intellij.psi.impl.light.LightMethodBuilder; +import com.intellij.psi.util.*; +import com.intellij.util.ArrayUtil; +import com.intellij.util.containers.CollectionFactory; +import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.containers.HashSet; +import gnu.trove.THashSet; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.groovy.lang.psi.GrClassSubstitutor; +import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; +import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult; +import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrConstructorInvocation; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumTypeDefinition; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrConstructor; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstant; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMembersDeclaration; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod; +import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition; +import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement; +import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil; +import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass; +import org.jetbrains.plugins.groovy.lang.psi.util.GrClassImplUtil; + +import java.util.*; + +import static org.jetbrains.plugins.groovy.refactoring.convertToJava.GenerationUtil.writeType; + +/** + * @author Maxim.Medvedev + */ +public class ClassGenerator { + private static final Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.refactoring.convertToJava.ClassGenerator"); + + private Project myProject; + private ClassNameProvider classNameProvider; + + public ClassGenerator(Project project, ClassNameProvider classNameProvider) { + myProject = project; + this.classNameProvider = classNameProvider; + } + + private static void writePackageStatement(StringBuilder text, GrPackageDefinition packageDefinition) { + if (packageDefinition != null) { + text.append("package "); + text.append(packageDefinition.getPackageName()); + text.append(";"); + text.append("\n"); + text.append("\n"); + } + } + + public void writeTypeDefinition(StringBuilder text, @NotNull final PsiClass typeDefinition, boolean toplevel) { + final boolean isScript = typeDefinition instanceof GroovyScriptClass; + + final GroovyFile containingFile = (GroovyFile)typeDefinition.getContainingFile(); + writePackageStatement(text, containingFile.getPackageDefinition()); + + boolean isEnum = typeDefinition.isEnum(); + boolean isAnnotationType = typeDefinition.isAnnotationType(); + boolean isInterface = !isAnnotationType && typeDefinition.isInterface(); + boolean isClassDef = !isInterface && !isEnum && !isAnnotationType && !isScript; + + GenerationUtil.writeClassModifiers(text, typeDefinition.getModifierList(), typeDefinition.isInterface(), toplevel); + + if (isInterface) { + text.append("interface"); + } + else if (isEnum) { + text.append("enum"); + } + else if (isAnnotationType) { + text.append("@interface"); + } + else { + text.append("class"); + } + + text.append(" ").append(typeDefinition.getName()); + + appendTypeParameters(text, typeDefinition); + + text.append(" "); + + if (isScript) { + text.append("extends groovy.lang.Script "); + } + else if (!isEnum && !isAnnotationType) { + final PsiClassType[] extendsClassesTypes = typeDefinition.getExtendsListTypes(); + + if (extendsClassesTypes.length > 0) { + + text.append("extends "); + writeType(text, extendsClassesTypes[0], typeDefinition, classNameProvider); + text.append(" "); + } + + final Collection implementsTypes = new LinkedHashSet(); + Collections.addAll(implementsTypes, typeDefinition.getImplementsListTypes()); + /*for (PsiClass aClass : collectDelegateTypes(typeDefinition)) { + if (aClass.isInterface()) { + implementsTypes.add(JavaPsiFacade.getElementFactory(myProject).createType(aClass)); + } else { + Collections.addAll(implementsTypes, aClass.getImplementsListTypes()); + } + }*/ + + if (!implementsTypes.isEmpty()) { + text.append(isInterface ? "extends " : "implements "); + for (PsiClassType implementsType : implementsTypes) { + writeType(text, implementsType, typeDefinition, classNameProvider); + text.append(", "); + } + if (implementsTypes.size() > 0) text.delete(text.length() - 2, text.length()); + text.append(" "); + } + } + + text.append("{\n"); + + if (isEnum) { + writeEnumConstants(text, (GrEnumTypeDefinition)typeDefinition); + } + + writeAllMethods(text, collectMethods(typeDefinition, isClassDef), typeDefinition); + + if (typeDefinition instanceof GrTypeDefinition) { + for (GrMembersDeclaration declaration : ((GrTypeDefinition)typeDefinition).getMemberDeclarations()) { + if (declaration instanceof GrVariableDeclaration) { + writeVariableDeclarations(text, (GrVariableDeclaration)declaration); + } + } + for (PsiClass inner : typeDefinition.getInnerClasses()) { + writeTypeDefinition(text, inner, false); + text.append("\n"); + } + } + text.append("}"); + } + + + private void writeAllMethods(StringBuilder text, Collection methods, PsiClass aClass) { + Set methodSignatures = new HashSet(); + for (PsiMethod method : methods) { + if (!shouldBeGenerated(method)) { + continue; + } + + if (method instanceof GrConstructor) { + writeConstructor(text, (GrConstructor)method, aClass.isEnum()); + continue; + } + + PsiParameter[] parameters = method.getParameterList().getParameters(); + if (parameters.length > 0) { + PsiParameter[] parametersCopy = new PsiParameter[parameters.length]; + PsiType[] parameterTypes = new PsiType[parameters.length]; + for (int i = 0; i < parameterTypes.length; i++) { + parametersCopy[i] = parameters[i]; + parameterTypes[i] = findOutParameterType(parameters[i]); + } + + for (int i = parameters.length - 1; i >= 0; i--) { + MethodSignature signature = + MethodSignatureUtil.createMethodSignature(method.getName(), parameterTypes, method.getTypeParameters(), PsiSubstitutor.EMPTY); + if (methodSignatures.add(signature)) { + writeMethod(text, method, parametersCopy); + text.append('\n'); + + } + + PsiParameter parameter = parameters[i]; + if (!(parameter instanceof GrParameter) || !((GrParameter)parameter).isOptional()) break; + parameterTypes = ArrayUtil.remove(parameterTypes, parameterTypes.length - 1); + parametersCopy = ArrayUtil.remove(parametersCopy, parametersCopy.length - 1); + } + } + else { + MethodSignature signature = method.getSignature(PsiSubstitutor.EMPTY); + if (methodSignatures.add(signature)) { + writeMethod(text, method, parameters); + text.append('\n'); + } + } + } + } + + private void appendTypeParameters(StringBuilder text, PsiTypeParameterListOwner typeParameterListOwner) { + if (!typeParameterListOwner.hasTypeParameters()) return; + + text.append("<"); + PsiTypeParameter[] parameters = typeParameterListOwner.getTypeParameters(); + final PsiTypeParameterList typeParameterList = typeParameterListOwner.getTypeParameterList(); + for (int i = 0; i < parameters.length; i++) { + if (i > 0) text.append(", "); + PsiTypeParameter parameter = parameters[i]; + text.append(parameter.getName()); + PsiClassType[] extendsListTypes = parameter.getExtendsListTypes(); + if (extendsListTypes.length > 0) { + text.append(" extends "); + for (int j = 0; j < extendsListTypes.length; j++) { + if (j > 0) text.append(" & "); + writeType(text, extendsListTypes[j], typeParameterList, classNameProvider); + } + } + } + text.append(">"); + } + + private void writeParameterList(StringBuilder text, PsiParameter[] parameters) { + text.append("("); + + //writes myParameters + int i = 0; + while (i < parameters.length) { + PsiParameter parameter = parameters[i]; + if (parameter == null) continue; + + if (i > 0) text.append(", "); //append ',' + writeType(text, findOutParameterType(parameter), parameter, classNameProvider); + text.append(" "); + text.append(parameter.getName()); + + i++; + } + text.append(")"); + text.append(" "); + } + + + private void writeThrowsList(StringBuilder text, PsiMethod method) { + final PsiReferenceList throwsList = method.getThrowsList(); + final PsiClassType[] exceptions = throwsList.getReferencedTypes(); + if (exceptions.length > 0) { + text.append("throws "); + for (int i = 0; i < exceptions.length; i++) { + PsiClassType exception = exceptions[i]; + if (i != 0) { + text.append(","); + } + writeType(text, exception, throwsList, classNameProvider); + text.append(" "); + } + + //todo search for all thrown exceptions from this file methods + } + } + + private void writeMethodBody(StringBuilder text, PsiMethod method, PsiType retType) { + if (classNameProvider.forStubs()) { + text.append("{\nreturn "); + text.append(GroovyToJavaGenerator.getDefaultValueText(retType.getCanonicalText())); + text.append(";\n}"); + return; + } + if (method instanceof GrMethod) { + final CodeBlockGenerator blockGenerator = new CodeBlockGenerator(text, myProject); + final GrOpenBlock block = ((GrMethod)method).getBlock(); + LOG.assertTrue(block != null); + block.accept(blockGenerator); + } + } + + private PsiType findOutReturnTypeOfMethod(PsiMethod method) { + final PsiType returnType = method.getReturnType(); + if (returnType != null) return returnType; + + if (classNameProvider.forStubs()) return TypesUtil.getJavaLangObject(method); + + final PsiType smartReturnType = org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.getSmartReturnType(method); + if (smartReturnType != null) return smartReturnType; + + //todo make smarter. search for usages and infer type from them + return TypesUtil.getJavaLangObject(method); + //final Collection collection = MethodReferencesSearch.search(method).findAll(); + } + + private static PsiType findOutParameterType(PsiParameter parameter) { + return parameter.getType(); //todo make smarter + } + + + void writeMethod(StringBuilder text, PsiMethod method, final PsiParameter[] parameters) { + if (method == null) return; + String name = method.getName(); + if (!JavaPsiFacade.getInstance(method.getProject()).getNameHelper().isIdentifier(name)) { + return; //does not have a java image + } + + boolean isAbstract = isAbstractInJava(method); + + PsiModifierList modifierList = method.getModifierList(); + + GenerationUtil.writeModifiers(text, modifierList, GenerationUtil.JAVA_MODIFIERS); + if (method.hasTypeParameters()) { + appendTypeParameters(text, method); + text.append(" "); + } + + //append return type + PsiType retType = findOutReturnTypeOfMethod(method); + + if (!method.hasModifierProperty(PsiModifier.STATIC)) { + final List superSignatures = method.findSuperMethodSignaturesIncludingStatic(true); + for (MethodSignatureBackedByPsiMethod superSignature : superSignatures) { + final PsiType superType = superSignature.getSubstitutor().substitute(superSignature.getMethod().getReturnType()); + if (superType != null && + !superType.isAssignableFrom(retType) && + !(PsiUtil.resolveClassInType(superType) instanceof PsiTypeParameter)) { + retType = superType; + } + } + } + + writeType(text, retType, method, classNameProvider); + text.append(" "); + + text.append(name); + + writeParameterList(text, parameters); + + writeThrowsList(text, method); + + if (!isAbstract) { + /************* body **********/ + writeMethodBody(text, method, retType); + } + else { + text.append(";"); + } + text.append("\n"); + } + + + private void writeVariableDeclarations(StringBuilder text, GrVariableDeclaration variableDeclaration) { + GrTypeElement typeElement = variableDeclaration.getTypeElementGroovy(); + + final GrModifierList modifierList = variableDeclaration.getModifierList(); + final PsiNameHelper nameHelper = JavaPsiFacade.getInstance(variableDeclaration.getProject()).getNameHelper(); + for (final GrVariable variable : variableDeclaration.getVariables()) { + String name = variable.getName(); + if (!nameHelper.isIdentifier(name)) { + continue; //does not have a java image + } + + GenerationUtil.writeModifiers(text, modifierList, GenerationUtil.JAVA_MODIFIERS); + + //type + PsiType declaredType = + typeElement == null ? PsiType.getJavaLangObject(variable.getManager(), variable.getResolveScope()) : typeElement.getType(); + final String initializer = GroovyToJavaGenerator.getDefaultValueText(declaredType.getCanonicalText()); + + writeType(text, declaredType, variableDeclaration, classNameProvider); + text.append(" ").append(name).append(" = ").append(initializer); + text.append(";\n"); + } + } + + + private void writeEnumConstants(StringBuilder text, GrEnumTypeDefinition enumDefinition) { + GrEnumConstant[] enumConstants = enumDefinition.getEnumConstants(); + for (int i = 0; i < enumConstants.length; i++) { + if (i > 0) text.append(", "); + GrEnumConstant enumConstant = enumConstants[i]; + text.append(enumConstant.getName()); + PsiMethod constructor = enumConstant.resolveMethod(); + if (constructor != null) { + text.append("("); + writeStubConstructorInvocation(text, constructor, PsiSubstitutor.EMPTY, enumConstant); + text.append(")"); + } + + GrTypeDefinitionBody block = enumConstant.getAnonymousBlock(); + if (block != null) { + text.append("{\n"); + for (PsiMethod method : block.getMethods()) { + writeMethod(text, method, method.getParameterList().getParameters()); + } + text.append("}"); + } + } + text.append(";\n"); + } + + private static boolean shouldBeGenerated(PsiMethod method) { + for (PsiMethod psiMethod : method.findSuperMethods()) { + if (!psiMethod.hasModifierProperty(PsiModifier.ABSTRACT)) { + final PsiType type = method.getReturnType(); + final PsiType superType = psiMethod.getReturnType(); + if (type != null && superType != null && !superType.isAssignableFrom(type)) { + return false; + } + } + } + return true; + } + + + private Collection collectMethods(PsiClass typeDefinition, boolean classDef) { + List methods = new ArrayList(); + ContainerUtil.addAll(methods, typeDefinition.getMethods()); + if (classDef && classNameProvider.forStubs()) { + final Collection toOverride = OverrideImplementUtil.getMethodSignaturesToOverride(typeDefinition); + for (MethodSignature signature : toOverride) { + if (signature instanceof MethodSignatureBackedByPsiMethod) { + final PsiMethod method = ((MethodSignatureBackedByPsiMethod)signature).getMethod(); + final PsiClass baseClass = method.getContainingClass(); + if (isAbstractInJava(method) && baseClass != null && typeDefinition.isInheritor(baseClass, true)) { + methods.add(mirrorMethod(typeDefinition, method, baseClass, PsiSubstitutor.EMPTY, GenerationUtil.JAVA_MODIFIERS)); + } + } + } + + final PsiElementFactory factory = JavaPsiFacade.getInstance(myProject).getElementFactory(); + methods.add(factory.createMethodFromText("public groovy.lang.MetaClass getMetaClass() {}", null)); + methods.add(factory.createMethodFromText("public void setMetaClass(groovy.lang.MetaClass mc) {}", null)); + methods.add(factory.createMethodFromText("public Object invokeMethod(String name, Object args) {}", null)); + methods.add(factory.createMethodFromText("public Object getProperty(String propertyName) {}", null)); + methods.add(factory.createMethodFromText("public void setProperty(String propertyName, Object newValue) {}", null)); + } + + if (typeDefinition instanceof GrTypeDefinition) { + for (PsiMethod delegatedMethod : GrClassImplUtil.getDelegatedMethods((GrTypeDefinition)typeDefinition)) { + methods.add(delegatedMethod); + } + } + + return methods; + } + + private static LightMethodBuilder mirrorMethod(PsiClass typeDefinition, + PsiMethod method, + PsiClass baseClass, + PsiSubstitutor substitutor, + String... modifierFilter) { + final LightMethodBuilder builder = new LightMethodBuilder(method.getManager(), method.getName()); + substitutor = substitutor.putAll(TypeConversionUtil.getSuperClassSubstitutor(baseClass, typeDefinition, PsiSubstitutor.EMPTY)); + for (PsiParameter parameter : method.getParameterList().getParameters()) { + builder.addParameter(StringUtil.notNullize(parameter.getName()), substitutor.substitute(findOutParameterType(parameter))); + } + builder.setReturnType(substitutor.substitute(method.getReturnType())); + for (String modifier : modifierFilter) { + if (method.hasModifierProperty(modifier)) { + builder.addModifier(modifier); + } + } + return builder; + } + + private static boolean isAbstractInJava(PsiMethod method) { + if (method.hasModifierProperty(PsiModifier.ABSTRACT)) { + return true; + } + + final PsiClass psiClass = method.getContainingClass(); + return psiClass != null && GrClassSubstitutor.getSubstitutedClass(psiClass).isInterface(); + } + + void writeConstructor(final StringBuilder text, final GrConstructor constructor, boolean isEnum) { + if (!isEnum) { + text.append("public "); + //writeModifiers(text, constructor.getModifierList(), JAVA_MODIFIERS); + } + + /************* name **********/ + //append constructor name + text.append(constructor.getName()); + + /************* parameters **********/ + GrParameter[] parameterList = constructor.getParameters(); + + writeParameterList(text, parameterList); + + final Set throwsTypes = collectThrowsTypes(constructor, new THashSet()); + if (!throwsTypes.isEmpty()) { + text.append("throws ").append(StringUtil.join(throwsTypes, ", ")).append(" "); + } + + /************* body **********/ + + text.append("{\n"); + final GrConstructorInvocation invocation = constructor.getChainingConstructorInvocation(); + if (invocation != null) { + final GroovyResolveResult resolveResult = resolveChainingConstructor(constructor); + if (resolveResult != null) { + text.append(invocation.isSuperCall() ? "super(" : "this("); + writeStubConstructorInvocation(text, (PsiMethod)resolveResult.getElement(), resolveResult.getSubstitutor(), invocation); + text.append(");"); + } + } + + text.append("\n}\n"); + } + + private Set collectThrowsTypes(GrConstructor constructor, Set visited) { + final GroovyResolveResult resolveResult = resolveChainingConstructor(constructor); + if (resolveResult == null) { + return Collections.emptySet(); + } + + + final PsiSubstitutor substitutor = resolveResult.getSubstitutor(); + final PsiMethod chainedConstructor = (PsiMethod)resolveResult.getElement(); + assert chainedConstructor != null; + + if (!visited.add(chainedConstructor)) { + return Collections.emptySet(); + } + + final Set result = CollectionFactory.newTroveSet(ArrayUtil.EMPTY_STRING_ARRAY); + for (PsiClassType type : chainedConstructor.getThrowsList().getReferencedTypes()) { + StringBuilder builder = new StringBuilder(); + writeType(builder, substitutor.substitute(type), constructor, classNameProvider); + result.add(builder.toString()); + } + + if (chainedConstructor instanceof GrConstructor) { + result.addAll(collectThrowsTypes((GrConstructor)chainedConstructor, visited)); + } + return result; + } + + @Nullable + private static GroovyResolveResult resolveChainingConstructor(GrConstructor constructor) { + final GrConstructorInvocation constructorInvocation = constructor.getChainingConstructorInvocation(); + if (constructorInvocation == null) { + return null; + } + + GroovyResolveResult resolveResult = constructorInvocation.resolveConstructorGenerics(); + if (resolveResult.getElement() != null) { + return resolveResult; + } + + final GroovyResolveResult[] results = constructorInvocation.multiResolveConstructor(); + if (results.length > 0) { + int i = 0; + while (results.length > i + 1) { + final PsiMethod candidate = (PsiMethod)results[i].getElement(); + final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(constructor.getProject()).getResolveHelper(); + if (candidate != null && candidate != constructor && resolveHelper.isAccessible(candidate, constructorInvocation, null)) { + break; + } + i++; + } + return results[i]; + } + return null; + } + + private void writeStubConstructorInvocation(StringBuilder text, PsiMethod constructor, PsiSubstitutor substitutor, PsiElement invocation) { + final PsiParameter[] superParams = constructor.getParameterList().getParameters(); + for (int j = 0; j < superParams.length; j++) { + if (j > 0) text.append(", "); + text.append("("); + final PsiType type = findOutParameterType(superParams[j]); + writeType(text, substitutor.substitute(type), invocation,classNameProvider); + text.append(")").append(GroovyToJavaGenerator.getDefaultValueText(type.getCanonicalText())); + } + } +} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassNameProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassNameProvider.java new file mode 100644 index 000000000000..fd3b83f08f52 --- /dev/null +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassNameProvider.java @@ -0,0 +1,31 @@ +/* + * Copyright 2000-2011 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.refactoring.convertToJava; + +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.Nullable; + +/** + * @author Maxim.Medvedev + */ +public interface ClassNameProvider { + + @Nullable + String getQualifiedClassName(PsiClass clazz, @Nullable PsiElement context); + + boolean forStubs(); +} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ConvertToJavaProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ConvertToJavaProcessor.java index c4eeebae5882..f9c0114e37fa 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ConvertToJavaProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ConvertToJavaProcessor.java @@ -19,7 +19,11 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.psi.*; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiDocumentManager; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; import com.intellij.refactoring.BaseRefactoringProcessor; import com.intellij.refactoring.ui.UsageViewDescriptorAdapter; import com.intellij.usageView.UsageInfo; @@ -27,9 +31,9 @@ import com.intellij.usageView.UsageViewDescriptor; import com.intellij.util.containers.hash.HashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; -import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.GrTopStatement; import org.jetbrains.plugins.groovy.refactoring.GroovyRefactoringBundle; +import java.util.Map; import java.util.Set; /** @@ -44,6 +48,7 @@ public class ConvertToJavaProcessor extends BaseRefactoringProcessor { myFiles = files; } + @NotNull @Override protected UsageViewDescriptor createUsageViewDescriptor(UsageInfo[] usages) { return new UsageViewDescriptorAdapter() { @@ -69,24 +74,30 @@ public class ConvertToJavaProcessor extends BaseRefactoringProcessor { //private static String @Override protected void performRefactoring(UsageInfo[] usages) { -// final GroovyToJavaGenerator generator = new GroovyToJavaGenerator(myProject, Collections.emptyList(), true); + final HashSet allToCompile = new HashSet(); + for (GroovyFile file : myFiles) { + allToCompile.add(file.getVirtualFile()); + } + final GroovyToJavaGenerator fileGenerator = new GroovyToJavaGenerator(myProject, allToCompile, true); for (GroovyFile file : myFiles) { - final PsiDirectory dir = file.getContainingDirectory(); - LOG.assertTrue(dir != null); + final Map map = fileGenerator.generateStubs(file); + StringBuilder builder = new StringBuilder(); + for (String s : map.keySet()) { + builder.append(map.get(s)).append('\n'); + } + + String fileName = getNewFileName(file); + final PsiFile newFile = (PsiFile)file.setName(fileName); + final Document document = PsiDocumentManager.getInstance(myProject).getDocument(newFile); + LOG.assertTrue(document != null); + document.setText(builder); + } - final PsiFile[] files = dir.getFiles(); - Set fileNames = new HashSet(); - for (PsiFile psiFile : files) { - fileNames.add(psiFile.getName()); - } - String prefix = FileUtil.getNameWithoutExtension(file.getName()); - String fileName = prefix + ".java"; - int index = 1; - while (fileNames.contains(fileName)) { - fileName = prefix + index + ".java"; - } + /* + for (GroovyFile file : myFiles) { + final Project project = file.getProject(); GrTopStatement[] statements = file.getTopStatements(); @@ -96,17 +107,31 @@ public class ConvertToJavaProcessor extends BaseRefactoringProcessor { statement.accept(generator); builder.append("\n"); } - + String fileName = getNewFileName(file); final PsiFile newFile = (PsiFile)file.setName(fileName); final Document document = PsiDocumentManager.getInstance(project).getDocument(newFile); document.setText(builder); - /*final PsiFile created = PsiFileFactory.getInstance(project) - .createFileFromText(file.getScriptClass().getName() + ".java", StdLanguages.JAVA, builder.toString()); - PostprocessReformattingAspect.getInstance(project).doPostponedFormatting(); - file.delete(); - dir.add(created);*/ - //QuickfixUtil.positionCursor(project, created, created.getFirstChild()); } + */ + } + + private static String getNewFileName(GroovyFile file) { + final PsiDirectory dir = file.getContainingDirectory(); + LOG.assertTrue(dir != null); + + + final PsiFile[] files = dir.getFiles(); + Set fileNames = new HashSet(); + for (PsiFile psiFile : files) { + fileNames.add(psiFile.getName()); + } + String prefix = FileUtil.getNameWithoutExtension(file.getName()); + String fileName = prefix + ".java"; + int index = 1; + while (fileNames.contains(fileName)) { + fileName = prefix + index + ".java"; + } + return fileName; } @Override diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java index e8bc9714ac56..8a1a1104fe75 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java @@ -28,7 +28,6 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory; import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap; -import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifier; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrConstructorInvocation; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration; @@ -554,8 +553,6 @@ public class ExpressionGenerator extends Generator { else { builder.append(value); } - - //todo replace with character in some cases } @Override @@ -714,28 +711,10 @@ public class ExpressionGenerator extends Generator { typeElement.accept(this); } - @Override - public void visitArrayTypeElement(GrArrayTypeElement typeElement) { - //todo - throw new UnsupportedOperationException(); - } - - @Override - public void visitBuiltinTypeElement(GrBuiltInTypeElement typeElement) { - //todo - throw new UnsupportedOperationException(); - } - - @Override - public void visitClassTypeElement(GrClassTypeElement typeElement) { - //todo - throw new UnsupportedOperationException(); - } - @Override public void visitBuiltinTypeClassExpression(GrBuiltinTypeClassExpression expression) { final IElementType type = expression.getFirstChild().getNode().getElementType(); - final String boxed = TypesUtil.getPsiTypeName(type); + final String boxed = TypesUtil.getBoxedTypeName(type); builder.append(boxed).append(".class"); } @@ -784,7 +763,7 @@ public class ExpressionGenerator extends Generator { GrClosableBlock[] closures, PsiSubstitutor substitutor, GroovyPsiElement context) { - if (method instanceof GrGdkMethod && !method.hasModifierProperty(GrModifier.STATIC)) { + if (method instanceof GrGdkMethod && !method.hasModifierProperty(PsiModifier.STATIC)) { if (caller == null) { caller = factory.createExpressionFromText("this", context); } @@ -795,8 +774,7 @@ public class ExpressionGenerator extends Generator { return; } - //todo check for private method? - if (method.hasModifierProperty(GrModifier.STATIC)) { + if (method.hasModifierProperty(PsiModifier.STATIC)) { final PsiClass containingClass = method.getContainingClass(); if (containingClass != null) { builder.append(containingClass.getQualifiedName()).append("."); @@ -817,7 +795,6 @@ public class ExpressionGenerator extends Generator { @Override public void visitListOrMap(GrListOrMap listOrMap) { - //todo infer type parameters from context if possible final PsiType type = listOrMap.getType(); //can be PsiArrayType or GrLiteralClassType @@ -825,7 +802,7 @@ public class ExpressionGenerator extends Generator { if (listOrMap.isMap()) { String varName = generateMapVariableDeclaration(listOrMap, type); - generateMapElementInsertions(listOrMap, varName); //todo generate array if possible + generateMapElementInsertions(listOrMap, varName); builder.append(varName); } else { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GenerationUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GenerationUtil.java index 237b6c058524..b3dc221e237f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GenerationUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GenerationUtil.java @@ -17,6 +17,7 @@ package org.jetbrains.plugins.groovy.refactoring.convertToJava; import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.*; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult; @@ -27,6 +28,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlo import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement; import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; +import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil; import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil; import org.jetbrains.plugins.groovy.refactoring.DefaultGroovyVariableNameValidator; @@ -59,6 +61,106 @@ public class GenerationUtil { builder.append(type.getCanonicalText()); //todo make smarter. } + public static void writeType(final StringBuilder builder, + final PsiType type, + final PsiElement context, + final ClassNameProvider classNameProvider) { + if (type instanceof PsiPrimitiveType) { + builder.append(type.getCanonicalText()); + return; + } + + final boolean acceptEllipsis = isLastParameter(context); + + type.accept(new PsiTypeVisitor() { + @Override + public Object visitEllipsisType(PsiEllipsisType ellipsisType) { + final PsiType componentType = ellipsisType.getComponentType(); + componentType.accept(this); + if (acceptEllipsis) { + builder.append("..."); + } + else { + builder.append("[]"); + } + return this; + } + + @Override + public Object visitPrimitiveType(PsiPrimitiveType primitiveType) { + if (classNameProvider.forStubs()) { + builder.append(primitiveType.getCanonicalText()); + return this; + } + final PsiType boxed = TypesUtil.boxPrimitiveType(primitiveType, context.getManager(), context.getResolveScope()); + boxed.accept(this); + return this; + } + + @Override + public Object visitArrayType(PsiArrayType arrayType) { + arrayType.getComponentType().accept(this); + builder.append("[]"); + return this; + } + + @Override + public Object visitClassType(PsiClassType classType) { + final PsiType[] parameters = classType.getParameters(); + final PsiClass psiClass = classType.resolve(); + if (psiClass == null) { + builder.append(classType.getClassName()); + } + else { + final String qname = classNameProvider.getQualifiedClassName(psiClass, context); + builder.append(qname); + } + writeTypeParameters(builder, parameters); + return this; + } + + @Override + public Object visitCapturedWildcardType(PsiCapturedWildcardType capturedWildcardType) { + capturedWildcardType.getWildcard().accept(this); + return this; + } + + @Override + public Object visitWildcardType(PsiWildcardType wildcardType) { + builder.append("?"); + PsiType bound = wildcardType.getBound(); + if (bound == null) return this; + if (wildcardType.isExtends()) { + builder.append(" extends"); + } + else { + builder.append(" super "); + } + bound.accept(this); + return this; + } + + @Override + public Object visitDisjunctionType(PsiDisjunctionType disjunctionType) { + //todo + throw new UnsupportedOperationException(); + } + + @Override + public Object visitType(PsiType type) { + //todo + throw new UnsupportedOperationException(); + } + }); + } + + private static boolean isLastParameter(PsiElement context) { + final PsiElement parent = context.getParent(); + return context instanceof PsiParameter && + parent instanceof PsiParameterList && + ((PsiParameterList)parent).getParameterIndex((PsiParameter)context) == ((PsiParameterList)parent).getParametersCount() - 1; + } + private static void writeTypeParameters(StringBuilder builder, PsiType[] parameters) { if (parameters.length == 0) return; @@ -234,4 +336,14 @@ public class GenerationUtil { writer.writeStatement(statementBuilder, statementContext); writeStatement(builder, statementBuilder, statement, statementContext); } + + @Nullable + static PsiClass findAccessibleSuperClass(@NotNull PsiElement context, @NotNull PsiClass initialClass) { + PsiClass curClass = initialClass; + final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(context.getProject()).getResolveHelper(); + while (curClass != null && !resolveHelper.isAccessible(curClass, context, null)) { + curClass = curClass.getSuperClass(); + } + return curClass; + } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GeneratorClassNameProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GeneratorClassNameProvider.java new file mode 100644 index 000000000000..b7ebfc385b6e --- /dev/null +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GeneratorClassNameProvider.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2011 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.refactoring.convertToJava; + +import com.intellij.psi.CommonClassNames; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.Nullable; + +/** + * @author Maxim.Medvedev + */ +public class GeneratorClassNameProvider implements ClassNameProvider { + + @Override + public String getQualifiedClassName(PsiClass psiClass, @Nullable PsiElement context) { + if (context != null && psiClass != null) { + psiClass = GenerationUtil.findAccessibleSuperClass(context, psiClass); + } + if (psiClass == null) { + return CommonClassNames.JAVA_LANG_OBJECT; + } + + final String name = psiClass.getQualifiedName(); + if (name != null) return name; + return psiClass.getName(); + } + + @Override + public boolean forStubs() { + return false; + } +} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GroovyToJavaGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GroovyToJavaGenerator.java index 2e5982972bdb..e6ad9bf3218f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GroovyToJavaGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GroovyToJavaGenerator.java @@ -15,48 +15,21 @@ */ package org.jetbrains.plugins.groovy.refactoring.convertToJava; -import com.intellij.codeInsight.generation.OverrideImplementUtil; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; -import com.intellij.psi.impl.light.LightMethodBuilder; -import com.intellij.psi.util.*; -import com.intellij.util.ArrayUtil; -import com.intellij.util.Function; -import com.intellij.util.containers.CollectionFactory; -import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.containers.HashSet; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.psi.GrClassSubstitutor; import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; -import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; -import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult; -import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrConstructorInvocation; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumTypeDefinition; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrConstructor; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstant; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMembersDeclaration; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod; -import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.GrTopStatement; import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition; -import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement; -import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil; -import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass; -import org.jetbrains.plugins.groovy.lang.psi.util.GrClassImplUtil; import java.util.*; @@ -80,31 +53,24 @@ public class GroovyToJavaGenerator { typesToInitialValues.put("void", ""); } - private final List myAllToCompile; + private final Set myAllToCompile; private final Project myProject; private final boolean fullConversion; - public GroovyToJavaGenerator(Project project, List allToCompile, boolean fullConversion) { + public GroovyToJavaGenerator(Project project, Set allToCompile, boolean fullConversion) { myProject = project; myAllToCompile = allToCompile; this.fullConversion = fullConversion; } - public Map generateStubs(GroovyFile file) { - GrTopStatement[] statements = getTopStatementsInReadAction(file); - - GrPackageDefinition packageDefinition = null; - if (statements.length > 0 && statements[0] instanceof GrPackageDefinition) { - packageDefinition = (GrPackageDefinition) statements[0]; - } - + public Map generateStubs(GroovyFile file) { Set classNames = new THashSet(); for (final GrTypeDefinition typeDefinition : file.getTypeDefinitions()) { classNames.add(typeDefinition.getName()); } - final Map output = new LinkedHashMap(); + final Map output = new LinkedHashMap(); if (file.isScript()) { VirtualFile virtualFile = file.getVirtualFile(); @@ -114,17 +80,34 @@ public class GroovyToJavaGenerator { !classNames.contains(StringUtil.decapitalize(fileDefinitionName))) { final PsiClass scriptClass = file.getScriptClass(); if (scriptClass != null) { - generateClassStub(scriptClass, packageDefinition, output); + generateClassStub(scriptClass, output); } } } for (final GrTypeDefinition typeDefinition : file.getTypeDefinitions()) { - generateClassStub(GrClassSubstitutor.getSubstitutedClass(typeDefinition), packageDefinition, output); + generateClassStub(GrClassSubstitutor.getSubstitutedClass(typeDefinition), output); } return output; } + private void generateClassStub(PsiClass clazz, Map output) { + final CharSequence text = generateClass(clazz); + final String filename = getFileNameForClass(clazz); + output.put(filename, text); + } + + private String getFileNameForClass(PsiClass clazz) { + if (fullConversion) { + return clazz.getName() + ".java"; + } + else { + final PsiFile containingFile = clazz.getContainingFile(); + final GrPackageDefinition packageDefinition = ((GroovyFile)containingFile).getPackageDefinition(); + return getPackageDirectory(packageDefinition) + clazz.getName() + ".java"; + } + } + private static String getPackageDirectory(@Nullable GrPackageDefinition packageDefinition) { if (packageDefinition == null) return ""; @@ -134,637 +117,44 @@ public class GroovyToJavaGenerator { return prefix.replace('.', '/') + '/'; } - private void generateClassStub(@NotNull PsiClass typeDefinition, GrPackageDefinition packageDefinition, Map output) { - StringBuilder text = new StringBuilder(); + public CharSequence generateClass(@NotNull PsiClass typeDefinition) { try { - writeTypeDefinition(text, typeDefinition, packageDefinition, true); - - - final String fileName; - if (fullConversion) { - fileName = typeDefinition.getName() + ".java"; - } - else { - fileName = getPackageDirectory(packageDefinition) + typeDefinition.getName() + ".java"; - } - output.put(fileName, text.toString()); + StringBuilder text = new StringBuilder(); + final ClassNameProvider classNameProvider = + fullConversion ? new GeneratorClassNameProvider() : new StubClassNameProvider(myAllToCompile); + new ClassGenerator(myProject, classNameProvider).writeTypeDefinition(text, typeDefinition, true); + return text; } catch (ProcessCanceledException e) { throw e; } catch (Throwable e) { LOG.error(e); + return ""; } } - private static GrTopStatement[] getTopStatementsInReadAction(final GroovyFileBase file) { - if (file == null) return new GrTopStatement[0]; - - return ApplicationManager.getApplication().runReadAction(new Computable() { - public GrTopStatement[] compute() { - return file.getTopStatements(); - } - }); - } - - private void writeTypeDefinition(StringBuilder text, - @NotNull final PsiClass typeDefinition, - @Nullable GrPackageDefinition packageDefinition, - boolean toplevel) { - final boolean isScript = typeDefinition instanceof GroovyScriptClass; - - writePackageStatement(text, packageDefinition); - - boolean isEnum = typeDefinition.isEnum(); - boolean isAnnotationType = typeDefinition.isAnnotationType(); - boolean isInterface = !isAnnotationType && typeDefinition.isInterface(); - boolean isClassDef = !isInterface && !isEnum && !isAnnotationType && !isScript; - - GenerationUtil.writeClassModifiers(text, typeDefinition.getModifierList(), typeDefinition.isInterface(), toplevel); - - if (isInterface) { - text.append("interface"); - } - else if (isEnum) { - text.append("enum"); - } - else if (isAnnotationType) { - text.append("@interface"); - } - else { - text.append("class"); - } - - text.append(" ").append(typeDefinition.getName()); - - appendTypeParameters(text, typeDefinition); - - text.append(" "); - - if (isScript) { - text.append("extends groovy.lang.Script "); - } - else if (!isEnum && !isAnnotationType) { - final PsiClassType[] extendsClassesTypes = typeDefinition.getExtendsListTypes(); - - if (extendsClassesTypes.length > 0) { - text.append("extends ").append(getTypeText(extendsClassesTypes[0], typeDefinition, false)).append(" "); - } - - final Collection implementsTypes = new LinkedHashSet(); - Collections.addAll(implementsTypes, typeDefinition.getImplementsListTypes()); - /*for (PsiClass aClass : collectDelegateTypes(typeDefinition)) { - if (aClass.isInterface()) { - implementsTypes.add(JavaPsiFacade.getElementFactory(myProject).createType(aClass)); - } else { - Collections.addAll(implementsTypes, aClass.getImplementsListTypes()); - } - }*/ - - if (!implementsTypes.isEmpty()) { - text.append(isInterface ? "extends " : "implements "); - text.append(StringUtil.join(implementsTypes, new Function() { - @Override - public String fun(PsiClassType psiClassType) { - return getTypeText(psiClassType, typeDefinition, false); - } - }, ", ")); - text.append(" "); - } - } - - text.append("{"); - - if (isEnum) { - writeEnumConstants(text, (GrEnumTypeDefinition)typeDefinition); - } - - writeAllMethods(text, collectMethods(typeDefinition, isClassDef), typeDefinition); - - if (typeDefinition instanceof GrTypeDefinition) { - for (GrMembersDeclaration declaration : ((GrTypeDefinition)typeDefinition).getMemberDeclarations()) { - if (declaration instanceof GrVariableDeclaration) { - writeVariableDeclarations(text, (GrVariableDeclaration)declaration); - } - } - } - for (PsiClass inner : typeDefinition.getInnerClasses()) { - writeTypeDefinition(text, inner, null, false); - text.append("\n"); - } - - text.append("}"); - } - - private void writeAllMethods(StringBuilder text, Collection methods, PsiClass aClass) { - Set methodSignatures = new HashSet(); - for (PsiMethod method : methods) { - if (!shouldBeGenerated(method)) { - continue; - } - - if (method instanceof GrConstructor) { - writeConstructor(text, (GrConstructor)method, aClass.isEnum(), true); - continue; - } - - PsiParameter[] parameters = method.getParameterList().getParameters(); - if (parameters.length > 0) { - PsiParameter[] parametersCopy = new PsiParameter[parameters.length]; - PsiType[] parameterTypes = new PsiType[parameters.length]; - for (int i = 0; i < parameterTypes.length; i++) { - parametersCopy[i] = parameters[i]; - parameterTypes[i] = findOutParameterType(parameters[i]); - } - - for (int i = parameters.length - 1; i >= 0; i--) { - MethodSignature signature = - MethodSignatureUtil.createMethodSignature(method.getName(), parameterTypes, method.getTypeParameters(), PsiSubstitutor.EMPTY); - if (methodSignatures.add(signature)) { - writeMethod(text, method, parametersCopy, true); - } - - PsiParameter parameter = parameters[i]; - if (!(parameter instanceof GrParameter) || !((GrParameter)parameter).isOptional()) break; - parameterTypes = ArrayUtil.remove(parameterTypes, parameterTypes.length - 1); - parametersCopy = ArrayUtil.remove(parametersCopy, parametersCopy.length - 1); - } - } - else { - MethodSignature signature = method.getSignature(PsiSubstitutor.EMPTY); - if (methodSignatures.add(signature)) { - writeMethod(text, method, parameters, true); - } - } - } - } - - private static boolean shouldBeGenerated(PsiMethod method) { - for (PsiMethod psiMethod : method.findSuperMethods()) { - if (!psiMethod.hasModifierProperty(PsiModifier.ABSTRACT)) { - final PsiType type = method.getReturnType(); - final PsiType superType = psiMethod.getReturnType(); - if (type != null && superType != null && !superType.isAssignableFrom(type)) { - return false; - } - } - } - return true; - } - - private Collection collectMethods(PsiClass typeDefinition, boolean classDef) { - List methods = new ArrayList(); - ContainerUtil.addAll(methods, typeDefinition.getMethods()); - if (classDef) { - final Collection toOverride = OverrideImplementUtil.getMethodSignaturesToOverride(typeDefinition); - for (MethodSignature signature : toOverride) { - if (signature instanceof MethodSignatureBackedByPsiMethod) { - final PsiMethod method = ((MethodSignatureBackedByPsiMethod)signature).getMethod(); - final PsiClass baseClass = method.getContainingClass(); - if (isAbstractInJava(method) && baseClass != null && typeDefinition.isInheritor(baseClass, true)) { - methods.add(mirrorMethod(typeDefinition, method, baseClass, PsiSubstitutor.EMPTY, GenerationUtil.JAVA_MODIFIERS)); - } - } - } - - final PsiElementFactory factory = JavaPsiFacade.getInstance(myProject).getElementFactory(); - methods.add(factory.createMethodFromText("public groovy.lang.MetaClass getMetaClass() {}", null)); - methods.add(factory.createMethodFromText("public void setMetaClass(groovy.lang.MetaClass mc) {}", null)); - methods.add(factory.createMethodFromText("public Object invokeMethod(String name, Object args) {}", null)); - methods.add(factory.createMethodFromText("public Object getProperty(String propertyName) {}", null)); - methods.add(factory.createMethodFromText("public void setProperty(String propertyName, Object newValue) {}", null)); - } - - if (typeDefinition instanceof GrTypeDefinition) { - for (PsiMethod delegatedMethod : GrClassImplUtil.getDelegatedMethods((GrTypeDefinition)typeDefinition)) { - methods.add(delegatedMethod); - } - } - - return methods; - } - - private static LightMethodBuilder mirrorMethod(PsiClass typeDefinition, - PsiMethod method, - PsiClass baseClass, - PsiSubstitutor substitutor, - String... modifierFilter) { - final LightMethodBuilder builder = new LightMethodBuilder(method.getManager(), method.getName()); - substitutor = substitutor.putAll(TypeConversionUtil.getSuperClassSubstitutor(baseClass, typeDefinition, PsiSubstitutor.EMPTY)); - for (PsiParameter parameter : method.getParameterList().getParameters()) { - builder.addParameter(StringUtil.notNullize(parameter.getName()), substitutor.substitute(findOutParameterType(parameter))); - } - builder.setReturnType(substitutor.substitute(method.getReturnType())); - for (String modifier : modifierFilter) { - if (method.hasModifierProperty(modifier)) { - builder.addModifier(modifier); - } - } - return builder; - } - - private static boolean isAbstractInJava(PsiMethod method) { - if (method.hasModifierProperty(PsiModifier.ABSTRACT)) { - return true; - } - - final PsiClass psiClass = method.getContainingClass(); - return psiClass != null && GrClassSubstitutor.getSubstitutedClass(psiClass).isInterface(); - } - - private void appendTypeParameters(StringBuilder text, PsiTypeParameterListOwner typeParameterListOwner) { - if (typeParameterListOwner.hasTypeParameters()) { - text.append("<"); - PsiTypeParameter[] parameters = typeParameterListOwner.getTypeParameters(); - for (int i = 0; i < parameters.length; i++) { - if (i > 0) text.append(", "); - PsiTypeParameter parameter = parameters[i]; - text.append(parameter.getName()); - PsiClassType[] extendsListTypes = parameter.getExtendsListTypes(); - if (extendsListTypes.length > 0) { - text.append(" extends "); - for (int j = 0; j < extendsListTypes.length; j++) { - if (j > 0) text.append(" & "); - text.append(getTypeText(extendsListTypes[j], typeParameterListOwner, false)); - } - } - } - text.append(">"); - } - } - - private void writeEnumConstants(StringBuilder text, GrEnumTypeDefinition enumDefinition) { - text.append("\n "); - GrEnumConstant[] enumConstants = enumDefinition.getEnumConstants(); - for (int i = 0; i < enumConstants.length; i++) { - if (i > 0) text.append(", "); - GrEnumConstant enumConstant = enumConstants[i]; - text.append(enumConstant.getName()); - PsiMethod constructor = enumConstant.resolveMethod(); - if (constructor != null) { - text.append("("); - writeStubConstructorInvocation(text, constructor, PsiSubstitutor.EMPTY); - text.append(")"); - } - - GrTypeDefinitionBody block = enumConstant.getAnonymousBlock(); - if (block != null) { - text.append("{\n"); - for (PsiMethod method : block.getMethods()) { - writeMethod(text, method, method.getParameterList().getParameters(), true); - } - text.append("}"); - } - } - text.append(";"); - } - - private void writeStubConstructorInvocation(StringBuilder text, PsiMethod constructor, PsiSubstitutor substitutor) { - final PsiParameter[] superParams = constructor.getParameterList().getParameters(); - for (int j = 0; j < superParams.length; j++) { - if (j > 0) text.append(", "); - String typeText = getTypeText(substitutor.substitute(findOutParameterType(superParams[j])), null, false); - text.append("(").append(typeText).append(")").append(getDefaultValueText(typeText)); - } - } - - private static void writePackageStatement(StringBuilder text, GrPackageDefinition packageDefinition) { - if (packageDefinition != null) { - text.append("package "); - text.append(packageDefinition.getPackageName()); - text.append(";"); - text.append("\n"); - text.append("\n"); - } - } - - private void writeConstructor(final StringBuilder text, final GrConstructor constructor, boolean isEnum, final boolean prefix) { - if (prefix) { - text.append("\n"); - text.append(" "); - } - if (!isEnum) { - text.append("public "); - //writeModifiers(text, constructor.getModifierList(), JAVA_MODIFIERS); - } - - /************* name **********/ - //append constructor name - text.append(constructor.getName()); - - /************* parameters **********/ - GrParameter[] parameterList = constructor.getParameters(); - - writeParameterList(text, parameterList); - - final Set throwsTypes = collectThrowsTypes(constructor, new THashSet()); - if (!throwsTypes.isEmpty()) { - text.append("throws ").append(StringUtil.join(throwsTypes, ", ")).append(" "); - } - - /************* body **********/ - - text.append("{\n"); - final GrConstructorInvocation invocation = constructor.getChainingConstructorInvocation(); - if (invocation != null) { - final GroovyResolveResult resolveResult = resolveChainingConstructor(constructor); - if (resolveResult != null) { - text.append(" "); - text.append(invocation.isSuperCall() ? "super(" : "this("); - writeStubConstructorInvocation(text, (PsiMethod) resolveResult.getElement(), resolveResult.getSubstitutor()); - text.append(");"); - } - } - - text.append("\n }\n"); - } - - private Set collectThrowsTypes(GrConstructor constructor, Set visited) { - final GroovyResolveResult resolveResult = resolveChainingConstructor(constructor); - if (resolveResult == null) { - return Collections.emptySet(); - } - - - final PsiSubstitutor substitutor = resolveResult.getSubstitutor(); - final PsiMethod chainedConstructor = (PsiMethod)resolveResult.getElement(); - assert chainedConstructor != null; - - if (!visited.add(chainedConstructor)) { - return Collections.emptySet(); - } - - final Set result = CollectionFactory.newTroveSet(ArrayUtil.EMPTY_STRING_ARRAY); - for (PsiClassType type : chainedConstructor.getThrowsList().getReferencedTypes()) { - result.add(getTypeText(substitutor.substitute(type), null, false)); - } - - if (chainedConstructor instanceof GrConstructor) { - result.addAll(collectThrowsTypes((GrConstructor)chainedConstructor, visited)); - } - return result; - } - - @Nullable - private static GroovyResolveResult resolveChainingConstructor(GrConstructor constructor) { - final GrConstructorInvocation constructorInvocation = constructor.getChainingConstructorInvocation(); - if (constructorInvocation == null) { - return null; - } - - GroovyResolveResult resolveResult = constructorInvocation.resolveConstructorGenerics(); - if (resolveResult.getElement() != null) { - return resolveResult; - } - - final GroovyResolveResult[] results = constructorInvocation.multiResolveConstructor(); - if (results.length > 0) { - int i = 0; - while (results.length > i+1) { - final PsiMethod candidate = (PsiMethod)results[i].getElement(); - final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(constructor.getProject()).getResolveHelper(); - if (candidate != null && candidate != constructor && resolveHelper.isAccessible(candidate, constructorInvocation, null)) { - break; - } - i++; - } - return results[i]; - } - return null; - } - - private static String getDefaultValueText(String typeCanonicalText) { + public static String getDefaultValueText(String typeCanonicalText) { final String result = typesToInitialValues.get(typeCanonicalText); if (result == null) return "null"; return result; } - private void writeVariableDeclarations(StringBuilder text, GrVariableDeclaration variableDeclaration) { - GrTypeElement typeElement = variableDeclaration.getTypeElementGroovy(); - final String type = typeElement == null ? CommonClassNames.JAVA_LANG_OBJECT : getTypeText(typeElement.getType(), typeElement, false); - final String initializer = getDefaultValueText(type); - - final GrModifierList modifierList = variableDeclaration.getModifierList(); - final PsiNameHelper nameHelper = JavaPsiFacade.getInstance(variableDeclaration.getProject()).getNameHelper(); - for (final GrVariable variable : variableDeclaration.getVariables()) { - String name = variable.getName(); - if (!nameHelper.isIdentifier(name)) { - continue; //does not have a java image - } - - text.append("\n "); - GenerationUtil.writeModifiers(text, modifierList, GenerationUtil.JAVA_MODIFIERS); - - //type - text.append(type).append(" ").append(name).append(" = ").append(initializer); - text.append(";\n"); - } - } - public static String generateMethodStub(@NotNull PsiMethod method) { if (!(method instanceof GroovyPsiElement)) { return method.getText(); } - final GroovyToJavaGenerator generator = new GroovyToJavaGenerator(method.getProject(), Collections.emptyList(), false); + final ClassGenerator generator = + new ClassGenerator(method.getProject(), new StubClassNameProvider(Collections.emptySet())); final StringBuilder buffer = new StringBuilder(); if (method instanceof GrConstructor) { - generator.writeConstructor(buffer, (GrConstructor)method, false, false); + generator.writeConstructor(buffer, (GrConstructor)method, false); } else { - generator.writeMethod(buffer, method, method.getParameterList().getParameters(), false); + generator.writeMethod(buffer, method, method.getParameterList().getParameters()); } return buffer.toString(); } - private void writeMethod(StringBuilder text, PsiMethod method, final PsiParameter[] parameters, final boolean prefix) { - if (method == null) return; - String name = method.getName(); - if (!JavaPsiFacade.getInstance(method.getProject()).getNameHelper().isIdentifier(name)) - return; //does not have a java image - - boolean isAbstract = isAbstractInJava(method); - - PsiModifierList modifierList = method.getModifierList(); - - if (prefix) { - text.append("\n"); - text.append(" "); - } - GenerationUtil.writeModifiers(text, modifierList, GenerationUtil.JAVA_MODIFIERS); - if (method.hasTypeParameters()) { - appendTypeParameters(text, method); - text.append(" "); - } - - //append return type - PsiType retType = findOutReturnTypeOfMethod(method); - - if (!method.hasModifierProperty(PsiModifier.STATIC)) { - final List superSignatures = method.findSuperMethodSignaturesIncludingStatic(true); - for (MethodSignatureBackedByPsiMethod superSignature : superSignatures) { - final PsiType superType = superSignature.getSubstitutor().substitute(superSignature.getMethod().getReturnType()); - if (superType != null && !superType.isAssignableFrom(retType) && !(PsiUtil.resolveClassInType(superType) instanceof PsiTypeParameter)) { - retType = superType; - } - } - } - - text.append(getTypeText(retType, method, false)); - text.append(" "); - - text.append(name); - - writeParameterList(text, parameters); - - writeThrowsList(text, method); - - if (!isAbstract) { - /************* body **********/ - generateMethodBody(text, method, retType); - } - else { - text.append(";"); - } - text.append("\n"); - } - - private void generateMethodBody(StringBuilder text, PsiMethod method, PsiType retType) { - if (!fullConversion) { - text.append("{\n return "); - text.append(getDefaultValueText(getTypeText(retType, method, false))); - text.append(";\n }"); - return; - } - //todo - if (method instanceof GrMethod) { - final CodeBlockGenerator blockGenerator = new CodeBlockGenerator(new StringBuilder(), myProject); - //blockGenerator.generate(); - //todo - } - } - - private void writeThrowsList(StringBuilder text, PsiMethod method) { - final PsiReferenceList throwsList = method.getThrowsList(); - final PsiClassType[] exceptions = throwsList.getReferencedTypes(); - if (exceptions.length > 0) { - text.append("throws "); - for (int i = 0; i < exceptions.length; i++) { - PsiClassType exception = exceptions[i]; - if (i != 0) { - text.append(","); - } - text.append(getTypeText(exception, method, false)); - text.append(" "); - } - - //todo search for all thrown exceptions from this file methods - } - } - - private PsiType findOutReturnTypeOfMethod(PsiMethod method) { - final PsiType returnType = method.getReturnType(); - if (returnType != null) return returnType; - - if (!fullConversion) return TypesUtil.getJavaLangObject(method); - - final PsiType smartReturnType = org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.getSmartReturnType(method); - if (smartReturnType != null) return smartReturnType; - - //todo make smarter. search for usages and infer type from them - return TypesUtil.getJavaLangObject(method); - //final Collection collection = MethodReferencesSearch.search(method).findAll(); - } - - private void writeParameterList(StringBuilder text, PsiParameter[] parameters) { - text.append("("); - - //writes myParameters - int i = 0; - while (i < parameters.length) { - PsiParameter parameter = parameters[i]; - if (parameter == null) continue; - - if (i > 0) text.append(", "); //append ',' - - text.append(getTypeText(findOutParameterType(parameter), parameter, i == parameters.length - 1)); - text.append(" "); - text.append(parameter.getName()); - - i++; - } - text.append(")"); - text.append(" "); - } - - private static PsiType findOutParameterType(PsiParameter parameter) { - return parameter.getType(); //todo make smarter - } - - private String getTypeText(@Nullable PsiType type, @Nullable final PsiElement context, boolean allowVarargs) { - if (type instanceof PsiArrayType) { - String componentText = getTypeText(((PsiArrayType)type).getComponentType(), context, false); - if (allowVarargs && type instanceof PsiEllipsisType) { - return componentText + "..."; - } - return componentText + "[]"; - } - - if (type == null) { - return CommonClassNames.JAVA_LANG_OBJECT; - } - - if (type instanceof PsiClassType) { - final PsiClass raw = ((PsiClassType)type).resolve(); - if (raw != null) { - final String qname = getClassQualifiedName(raw, context); - if (qname != null) { - final PsiType[] parameters = ((PsiClassType)type).getParameters(); - if (parameters.length > 0) { - return qname + "<" + StringUtil.join(parameters, new Function() { - @Override - public String fun(PsiType type) { - return getTypeText(type, context, false); - } - }, ", ") + ">"; - } - return qname; - } - } - } - - String canonicalText = type.getCanonicalText(); - return canonicalText != null ? canonicalText : type.getPresentableText(); - } - - @Nullable - private String getClassQualifiedName(PsiClass psiClass, @Nullable PsiElement context) { - if (context != null) { - psiClass = findAccessibleSuperClass(context, psiClass); - } - if (psiClass == null) { - return null; - } - - if (psiClass instanceof GrTypeDefinition) { - if (!myAllToCompile.contains(psiClass.getContainingFile().getVirtualFile())) { - final PsiClass container = psiClass.getContainingClass(); - if (container != null) { - return getClassQualifiedName(container, null) + "$" + psiClass.getName(); - } - } - } - return psiClass.getQualifiedName(); - } - - @Nullable - private static PsiClass findAccessibleSuperClass(@NotNull PsiElement context, @NotNull PsiClass initialClass) { - PsiClass curClass = initialClass; - final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(context.getProject()).getResolveHelper(); - while (curClass != null && !resolveHelper.isAccessible(curClass, context, null)) { - curClass = curClass.getSuperClass(); - } - return curClass; - } - } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/StubClassNameProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/StubClassNameProvider.java new file mode 100644 index 000000000000..a16158097296 --- /dev/null +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/StubClassNameProvider.java @@ -0,0 +1,61 @@ +/* + * Copyright 2000-2011 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.refactoring.convertToJava; + +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.*; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition; + +import java.util.Set; + +/** + * @author Maxim.Medvedev + */ +public class StubClassNameProvider implements ClassNameProvider { + private Set myAllToCompile; + + public StubClassNameProvider(Set allToCompile) { + myAllToCompile = allToCompile; + } + + @Override + public String getQualifiedClassName(@Nullable PsiClass psiClass, @Nullable PsiElement context) { + if (context != null && psiClass != null) { + psiClass = GenerationUtil.findAccessibleSuperClass(context, psiClass); + } + if (psiClass == null) { + return CommonClassNames.JAVA_LANG_OBJECT; + } + + if (psiClass instanceof GrTypeDefinition) { + if (!myAllToCompile.contains(psiClass.getContainingFile().getVirtualFile())) { + final PsiClass container = psiClass.getContainingClass(); + if (container != null) { + return getQualifiedClassName(container, null) + "$" + psiClass.getName(); + } + } + } + final String name = psiClass.getQualifiedName(); + if (name!=null) return name; + return psiClass.getName(); + } + + @Override + public boolean forStubs() { + return true; + } +} diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GeneratorTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GeneratorTest.java index 4008333a87f2..c3094bb894f8 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GeneratorTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GeneratorTest.java @@ -7,7 +7,7 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; import org.jetbrains.plugins.groovy.refactoring.convertToJava.GroovyToJavaGenerator; import org.jetbrains.plugins.groovy.util.TestUtils; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -99,21 +99,21 @@ public class GeneratorTest extends LightGroovyTestCase { final String relTestPath = getTestName(true) + ".test"; final List data = TestUtils.readInput(getTestDataPath() + "/" + relTestPath); - final StringBuffer buffer = new StringBuffer(); + final StringBuilder builder = new StringBuilder(); final String testName = StringUtil.trimEnd(relTestPath, ".test"); PsiFile psiFile = TestUtils.createPseudoPhysicalFile(getProject(), testName + ".groovy", data.get(0)); - final Map map = - new GroovyToJavaGenerator(getProject(), Arrays.asList(psiFile.getViewProvider().getVirtualFile()), false) + final Map map = + new GroovyToJavaGenerator(getProject(), Collections.singleton(psiFile.getViewProvider().getVirtualFile()), false) .generateStubs((GroovyFile)psiFile); - for (String stubText : map.values()) { - buffer.append(stubText); - buffer.append("\n"); - buffer.append("---"); - buffer.append("\n"); + for (CharSequence stubText : map.values()) { + builder.append(stubText); + builder.append("\n"); + builder.append("---"); + builder.append("\n"); } - assertEquals(data.get(1).trim(), buffer.toString().trim()); + assertEquals(data.get(1).trim(), builder.toString().trim()); } } diff --git a/plugins/groovy/testdata/groovy/stubGenerator/GRVY915.test b/plugins/groovy/testdata/groovy/stubGenerator/GRVY915.test index 6c7e7af0ca1f..923aa948ef30 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/GRVY915.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/GRVY915.test @@ -7,16 +7,15 @@ enum E { } ----- public enum E { - A((int)0){ - - public java.lang.Object foo() { - return null; - } +A((int)0){ +public java.lang.Object foo() { +return null; +} }; - E(int i) { +E(int i) { - } +} +public abstract java.lang.Object foo() ; - public abstract java.lang.Object foo() ; } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/arrayType1.test b/plugins/groovy/testdata/groovy/stubGenerator/arrayType1.test index 8697f191d0e6..0956f4a20b54 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/arrayType1.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/arrayType1.test @@ -7,52 +7,51 @@ class Foo { } ----- public class Foo extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public int[] foo() { - return null; - } +public int[] foo() { +return null; +} - public java.lang.Object[] getObj() { - return null; - } +public java.lang.Object[] getObj() { +return null; +} - public int[] getIntegers() { - return null; - } +public int[] getIntegers() { +return null; +} - public void setIntegers(int[] integers) { - return ; - } +public void setIntegers(int[] integers) { +return ; +} - public java.lang.String[] getStrings() { - return null; - } +public java.lang.String[] getStrings() { +return null; +} - public void setStrings(java.lang.String[] strings) { - return ; - } +public void setStrings(java.lang.String[] strings) { +return ; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - private int[] integers = null; - - private java.lang.String[] strings = null; +private int[] integers = null; +private java.lang.String[] strings = null; } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/atInterface.test b/plugins/groovy/testdata/groovy/stubGenerator/atInterface.test index 62e6d78cfac9..29b0e8fcd988 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/atInterface.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/atInterface.test @@ -4,5 +4,6 @@ import java.lang.annotation.* } ----- -public @interface III {} +public @interface III { +} --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/checkedExceptionInConstructorDelegate.test b/plugins/groovy/testdata/groovy/stubGenerator/checkedExceptionInConstructorDelegate.test index 74c9135b8c41..399d18c028ec 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/checkedExceptionInConstructorDelegate.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/checkedExceptionInConstructorDelegate.test @@ -9,32 +9,31 @@ class Foo extends foo.SuperClass { ----- public class Foo extends foo.SuperClass implements groovy.lang.GroovyObject { - public Foo(Foo p) throws java.io.IOException { - this((java.lang.String)null); - } - - public Foo(java.lang.String s) throws java.io.IOException { - super((java.lang.String)null); - } - - public groovy.lang.MetaClass getMetaClass() { - return null; - } - - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } - - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } - - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } - - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } +public Foo(Foo p) throws java.io.IOException { +this((java.lang.String)null); } ---- +public Foo(java.lang.String s) throws java.io.IOException { +super((java.lang.String)null); +} +public groovy.lang.MetaClass getMetaClass() { +return null; +} + +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} + +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} + +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} + +} +--- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/defInInterface.test b/plugins/groovy/testdata/groovy/stubGenerator/defInInterface.test index 84ed91050be9..5350f1d61dd7 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/defInInterface.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/defInInterface.test @@ -3,6 +3,6 @@ interface Foo { } ----- public interface Foo { - public static final java.lang.Object bar = null; +public static final java.lang.Object bar = null; } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/delegateAnno.test b/plugins/groovy/testdata/groovy/stubGenerator/delegateAnno.test index 8bb62a0e699f..157e44214c6f 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/delegateAnno.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/delegateAnno.test @@ -11,72 +11,72 @@ class DelegateBarImpl { } ----- public interface DelegateFoo { - public java.lang.Object foo() ; +public java.lang.Object foo() ; + } --- public class Doo extends groovy.lang.GroovyObjectSupport implements java.io.Serializable, groovy.lang.GroovyObject { - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- public class DelegateBarImpl extends groovy.lang.GroovyObjectSupport implements DelegateFoo, java.lang.Runnable, java.io.Serializable, groovy.lang.GroovyObject { - public DelegateFoo getFoo() { - return null; - } - - public void setFoo(DelegateFoo foo) { - return ; - } - - public java.lang.Object foo() { - return null; - } - - public void run() { - return ; - } - - public groovy.lang.MetaClass getMetaClass() { - return null; - } - - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } - - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } - - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } - - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } - - private DelegateFoo foo = null; - - private java.lang.Runnable zoo = null; - - private Doo doo = null; +public DelegateFoo getFoo() { +return null; } ---- + +public void setFoo(DelegateFoo foo) { +return ; +} + +public java.lang.Object foo() { +return null; +} + +public void run() { +return ; +} + +public groovy.lang.MetaClass getMetaClass() { +return null; +} + +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} + +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} + +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} + +private DelegateFoo foo = null; +private java.lang.Runnable zoo = null; +private Doo doo = null; +} +--- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/delegationGenerics.test b/plugins/groovy/testdata/groovy/stubGenerator/delegationGenerics.test index e00eff8e74ef..c01f29c3d9cb 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/delegationGenerics.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/delegationGenerics.test @@ -7,38 +7,39 @@ class ConfigNode { } ----- public interface Foo { - public V get(K k) ; +public V get(K k) ; + } --- public class ConfigNode extends groovy.lang.GroovyObjectSupport implements Foo, groovy.lang.GroovyObject { - public final Foo getDelegate() { - return null; - } +public final Foo getDelegate() { +return null; +} - public java.lang.Object get(java.lang.String k) { - return null; - } +public java.lang.Object get(java.lang.String k) { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - private final Foo delegate = null; +private final Foo delegate = null; } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/extends1.test b/plugins/groovy/testdata/groovy/stubGenerator/extends1.test index ff0754e317ab..542672bd0ca4 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/extends1.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/extends1.test @@ -4,46 +4,48 @@ class a extends b { } ----- public class b extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- public class a extends b implements groovy.lang.GroovyObject { - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/extendsImplements.test b/plugins/groovy/testdata/groovy/stubGenerator/extendsImplements.test index 5d6ea06e8b5d..14e347890143 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/extendsImplements.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/extendsImplements.test @@ -2,24 +2,25 @@ class a extends GroovyObjectSupport implements GroovyObject { } ----- public class a extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/getterAlreadyDefined.test b/plugins/groovy/testdata/groovy/stubGenerator/getterAlreadyDefined.test index 9ebcd8396918..633421403434 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/getterAlreadyDefined.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/getterAlreadyDefined.test @@ -4,16 +4,17 @@ def getFoo () { } ----- public class getterAlreadyDefined extends groovy.lang.Script { - public static void main(java.lang.String[] args) { - return ; - } +public static void main(java.lang.String[] args) { +return ; +} - public java.lang.Object run() { - return null; - } +public java.lang.Object run() { +return null; +} + +public java.lang.Object getFoo() { +return null; +} - public java.lang.Object getFoo() { - return null; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/grvy1098.test b/plugins/groovy/testdata/groovy/stubGenerator/grvy1098.test index 85b11227258b..a5c47f4f8ddd 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/grvy1098.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/grvy1098.test @@ -7,54 +7,54 @@ class B extends A { } ----- public class A extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public static final java.lang.Object getTEST() { - return null; - } +public static final java.lang.Object getTEST() { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - private static final java.lang.Object TEST = null; +private static final java.lang.Object TEST = null; } --- public class B extends A implements groovy.lang.GroovyObject { - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - private static final java.lang.Object TEST = null; +private static final java.lang.Object TEST = null; } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/grvy118.test b/plugins/groovy/testdata/groovy/stubGenerator/grvy118.test index 28b76ec0ef6b..7619b518cde0 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/grvy118.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/grvy118.test @@ -9,52 +9,54 @@ class B extends A { } ----- public abstract class A extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public abstract java.lang.Object myMethod() ; +public abstract java.lang.Object myMethod() ; - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- public class B extends A implements groovy.lang.GroovyObject { - public java.lang.Object myMethod() { - return null; - } +public java.lang.Object myMethod() { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/grvy1358.test b/plugins/groovy/testdata/groovy/stubGenerator/grvy1358.test index a33a69828ee1..626ea9094525 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/grvy1358.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/grvy1358.test @@ -3,38 +3,38 @@ class MyClass { } ----- public class MyClass extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public boolean getEnabled() { - return false; - } +public boolean getEnabled() { +return false; +} - public boolean isEnabled() { - return false; - } +public boolean isEnabled() { +return false; +} - public void setEnabled(boolean enabled) { - return ; - } +public void setEnabled(boolean enabled) { +return ; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - private boolean enabled = false; +private boolean enabled = false; } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/grvy1376.test b/plugins/groovy/testdata/groovy/stubGenerator/grvy1376.test index c7b8c01f988c..c7a81d666c0f 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/grvy1376.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/grvy1376.test @@ -5,28 +5,28 @@ class PerformanceLine extends HashMap { } ----- public class PerformanceLine extends java.util.HashMap implements groovy.lang.GroovyObject { - public PerformanceLine(java.lang.String... data) { - super((java.util.Map)null); - } +public PerformanceLine(java.lang.String... data) { +super((java.util.Map)null); +} +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/grvy170.test b/plugins/groovy/testdata/groovy/stubGenerator/grvy170.test index c109f667dfa6..14badc2d418c 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/grvy170.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/grvy170.test @@ -5,29 +5,32 @@ interface Foo extends IBar { class Test1 implements Foo { } ----- -public interface IBar extends groovy.lang.GroovyObject {} +public interface IBar extends groovy.lang.GroovyObject { +} --- -public interface Foo extends IBar {} +public interface Foo extends IBar { +} --- public class Test1 extends groovy.lang.GroovyObjectSupport implements Foo, groovy.lang.GroovyObject { - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/grvy903.test b/plugins/groovy/testdata/groovy/stubGenerator/grvy903.test index e3f32e73229f..e317843929db 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/grvy903.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/grvy903.test @@ -8,32 +8,31 @@ class MyTestClass { } ----- public class MyTestClass extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public MyTestClass(java.lang.String s) { +public MyTestClass(java.lang.String s) { - } +} +public MyTestClass() { +this((java.lang.String)null); +} +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public MyTestClass() { - this((java.lang.String)null); - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } - - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/grvy908.test b/plugins/groovy/testdata/groovy/stubGenerator/grvy908.test index 0b1ca030cc73..40744b02ca33 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/grvy908.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/grvy908.test @@ -9,32 +9,31 @@ class MyClass { } ----- public class MyClass extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public MyClass(int i) { - this((java.lang.Object)null); - } +public MyClass(int i) { +this((java.lang.Object)null); +} +public MyClass(java.lang.Object o) { - public MyClass(java.lang.Object o) { +} +public groovy.lang.MetaClass getMetaClass() { +return null; +} - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } - - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/immutableAnno.test b/plugins/groovy/testdata/groovy/stubGenerator/immutableAnno.test index fbd88a6c7f24..8b12943fee66 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/immutableAnno.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/immutableAnno.test @@ -11,54 +11,56 @@ class FailingA { } ----- public class FailingA extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - protected void act() { - return ; - } +protected void act() { +return ; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- public final class FailingB extends FailingA implements groovy.lang.GroovyObject { - public void act() { - return ; - } +public void act() { +return ; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/implements1.test b/plugins/groovy/testdata/groovy/stubGenerator/implements1.test index a0b9fecd470c..eb148788cce2 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/implements1.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/implements1.test @@ -3,28 +3,29 @@ class A implements Comparable { } ----- public class A extends groovy.lang.GroovyObjectSupport implements java.lang.Comparable, groovy.lang.GroovyObject { - public int compare(A anotherA) { - return 0; - } +public int compare(A anotherA) { +return 0; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/inaccessibleConstructor.test b/plugins/groovy/testdata/groovy/stubGenerator/inaccessibleConstructor.test index 00b1a7fa022c..5af82f6c4f22 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/inaccessibleConstructor.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/inaccessibleConstructor.test @@ -11,62 +11,60 @@ class ExtensionLoader extends Foo { } ----- public class Foo extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public Foo(java.lang.Void v, Foo p) { +public Foo(java.lang.Void v, Foo p) { - } +} +public Foo(Foo p) { - public Foo(Foo p) { +} +public Foo() { - } +} +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public Foo() { +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } - - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } - - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- public class ExtensionLoader extends Foo implements groovy.lang.GroovyObject { - public ExtensionLoader(java.lang.Object parent) { - super((Foo)null); - } +public ExtensionLoader(java.lang.Object parent) { +super((Foo)null); +} +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/inaccessiblePropertyType.test b/plugins/groovy/testdata/groovy/stubGenerator/inaccessiblePropertyType.test index 65b42357aed6..bf9819c9ec35 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/inaccessiblePropertyType.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/inaccessiblePropertyType.test @@ -4,34 +4,34 @@ class Foo { ----- public class Foo extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public java.lang.Object getProp() { - return null; - } +public java.lang.Object getProp() { +return null; +} - public void setProp(java.lang.Object prop) { - return ; - } +public void setProp(java.lang.Object prop) { +return ; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - private java.lang.Object prop = null; +private java.lang.Object prop = null; } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/kireyev.test b/plugins/groovy/testdata/groovy/stubGenerator/kireyev.test index 28658bdc46c3..cfdbc743198d 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/kireyev.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/kireyev.test @@ -8,36 +8,37 @@ public T next() { throw new UnsupportedOperationException("This method is not av } ----- public class BugSample extends groovy.lang.GroovyObjectSupport implements java.util.Iterator, groovy.lang.GroovyObject { - public boolean hasNext() { - return false; - } +public boolean hasNext() { +return false; +} - public void remove() { - return ; - } +public void remove() { +return ; +} - public T next() { - return null; - } +public T next() { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/methodTypeParameters.test b/plugins/groovy/testdata/groovy/stubGenerator/methodTypeParameters.test index 7e822d39bddb..5f8be7dfb8cd 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/methodTypeParameters.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/methodTypeParameters.test @@ -3,28 +3,29 @@ class Foo { } ----- public class Foo extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public java.lang.Object f() { - return null; - } +public java.lang.Object f() { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/optionalParameter.test b/plugins/groovy/testdata/groovy/stubGenerator/optionalParameter.test index d48ff774e7fa..f1dcd9e3cb0d 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/optionalParameter.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/optionalParameter.test @@ -3,40 +3,41 @@ class Test { } ----- public class Test extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public java.lang.Object foo(java.lang.Object h, java.lang.Object i, java.lang.Object j, java.lang.Object k) { - return null; - } +public java.lang.Object foo(java.lang.Object h, java.lang.Object i, java.lang.Object j, java.lang.Object k) { +return null; +} - public java.lang.Object foo(java.lang.Object h, java.lang.Object i, java.lang.Object j) { - return null; - } +public java.lang.Object foo(java.lang.Object h, java.lang.Object i, java.lang.Object j) { +return null; +} - public java.lang.Object foo(java.lang.Object h, java.lang.Object i) { - return null; - } +public java.lang.Object foo(java.lang.Object h, java.lang.Object i) { +return null; +} - public java.lang.Object foo(java.lang.Object h) { - return null; - } +public java.lang.Object foo(java.lang.Object h) { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/overrideFinalGetter.test b/plugins/groovy/testdata/groovy/stubGenerator/overrideFinalGetter.test index 32113a32b9a4..49ddff2fc4b2 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/overrideFinalGetter.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/overrideFinalGetter.test @@ -7,56 +7,57 @@ class Derived extends Base { } ----- public class Base extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public final int getP() { - return 0; - } +public final int getP() { +return 0; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- public class Derived extends Base implements groovy.lang.GroovyObject { - public void setP(int p) { - return ; - } +public void setP(int p) { +return ; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - private int p = 0; +private int p = 0; } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/package1.test b/plugins/groovy/testdata/groovy/stubGenerator/package1.test index 3a582e5f39bd..11c8b87751f0 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/package1.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/package1.test @@ -6,24 +6,25 @@ class D { package a.b; public class D extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/parameterReturnType.test b/plugins/groovy/testdata/groovy/stubGenerator/parameterReturnType.test index 46d5f7df8738..f99c06ce230e 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/parameterReturnType.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/parameterReturnType.test @@ -19,28 +19,29 @@ class Impl implements GwtActionService { ----- public class Impl extends groovy.lang.GroovyObjectSupport implements GwtActionService, groovy.lang.GroovyObject { - public java.lang.CharSequence execute(java.util.List action) { - return null; - } +public java.lang.CharSequence execute(java.util.List action) { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/rawReturnTypeInImplementation.test b/plugins/groovy/testdata/groovy/stubGenerator/rawReturnTypeInImplementation.test index 47955abef2d9..4ed7d6faf6c3 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/rawReturnTypeInImplementation.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/rawReturnTypeInImplementation.test @@ -8,32 +8,34 @@ class Cl implements Callable { ----- public interface Callable { - public V call() throws java.lang.Exception ; +public V call() throws java.lang.Exception ; + } --- public class Cl extends groovy.lang.GroovyObjectSupport implements Callable, groovy.lang.GroovyObject { - public java.lang.String call() { - return null; - } +public java.lang.String call() { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/script.test b/plugins/groovy/testdata/groovy/stubGenerator/script.test index ffc121622e3f..15f82aa0f6c7 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/script.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/script.test @@ -1,12 +1,13 @@ println "bugaga" ----- public class script extends groovy.lang.Script { - public static void main(java.lang.String[] args) { - return ; - } +public static void main(java.lang.String[] args) { +return ; +} + +public java.lang.Object run() { +return null; +} - public java.lang.Object run() { - return null; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/setUpper1.test b/plugins/groovy/testdata/groovy/stubGenerator/setUpper1.test index 463c38bdfa84..c85fe0faed49 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/setUpper1.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/setUpper1.test @@ -3,24 +3,25 @@ class F { } ----- public class F extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/setterAlreadyDefined1.test b/plugins/groovy/testdata/groovy/stubGenerator/setterAlreadyDefined1.test index d0e4bafdb6e9..ae4e82d0abd8 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/setterAlreadyDefined1.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/setterAlreadyDefined1.test @@ -4,34 +4,34 @@ class D { } ----- public class D extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public void setDDD(java.lang.Object ddd) { - return ; - } +public void setDDD(java.lang.Object ddd) { +return ; +} - public java.lang.Object getDDD() { - return null; - } +public java.lang.Object getDDD() { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - private java.lang.Object DDD = null; +private java.lang.Object DDD = null; } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/singletonConstructor.test b/plugins/groovy/testdata/groovy/stubGenerator/singletonConstructor.test index e311fa531ffc..12a6b5b0d7cf 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/singletonConstructor.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/singletonConstructor.test @@ -3,28 +3,28 @@ class Foo { } ----- public class Foo extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public Foo() { +public Foo() { - } +} +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/stringMethodName.test b/plugins/groovy/testdata/groovy/stubGenerator/stringMethodName.test index f1e5561e5b52..eaeacf5a1c87 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/stringMethodName.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/stringMethodName.test @@ -15,56 +15,58 @@ class StringMethodName { } ----- public class StringMethodName extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public java.lang.Object foo0() { - return null; - } +public java.lang.Object foo0() { +return null; +} - public java.lang.Object foo1() { - return null; - } +public java.lang.Object foo1() { +return null; +} - public java.lang.Integer foo2() { - return null; - } +public java.lang.Integer foo2() { +return null; +} - public int foo3() { - return 0; - } +public int foo3() { +return 0; +} - public java.lang.Integer foo4(java.lang.Object x) { - return null; - } +public java.lang.Integer foo4(java.lang.Object x) { +return null; +} - public java.lang.Object getFoo5() { - return null; - } +public java.lang.Object getFoo5() { +return null; +} - private boolean fooFalse() { - return false; - } +private boolean fooFalse() { +return false; +} - public java.lang.Object fooDef() { - return null; - } +public java.lang.Object fooDef() { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} + +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/subclassProperty.test b/plugins/groovy/testdata/groovy/stubGenerator/subclassProperty.test index a530803096e3..1b18fa7f5145 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/subclassProperty.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/subclassProperty.test @@ -7,56 +7,57 @@ class Sub extends Super { ----- public class Super extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public java.lang.String getFoo() { - return null; - } +public java.lang.String getFoo() { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- public class Sub extends Super implements groovy.lang.GroovyObject { - public void setFoo(java.lang.Object foo) { - return ; - } +public void setFoo(java.lang.Object foo) { +return ; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - private java.lang.Object foo = null; +private java.lang.Object foo = null; } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/superInvocation.test b/plugins/groovy/testdata/groovy/stubGenerator/superInvocation.test index 2f6e09440dd5..f1b60f81172c 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/superInvocation.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/superInvocation.test @@ -9,54 +9,54 @@ class Derived extends Base { } ----- public class Base extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public Base(java.lang.String s, int i) { +public Base(java.lang.String s, int i) { - } +} +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- public class Derived extends Base implements groovy.lang.GroovyObject { - public Derived() { - super((java.lang.String)null, (int)0); - } - - public groovy.lang.MetaClass getMetaClass() { - return null; - } - - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } - - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } - - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } - - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } +public Derived() { +super((java.lang.String)null, (int)0); } ---- +public groovy.lang.MetaClass getMetaClass() { +return null; +} + +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} + +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} + +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} + +} +--- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/superInvocation1.test b/plugins/groovy/testdata/groovy/stubGenerator/superInvocation1.test index f4f69afbb773..8636d40d8e76 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/superInvocation1.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/superInvocation1.test @@ -9,54 +9,54 @@ class Derived extends Base { } ----- public class Base extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public Base(java.lang.String s, int i) { +public Base(java.lang.String s, int i) { - } +} +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- public class Derived extends Base implements groovy.lang.GroovyObject { - public Derived() throws java.lang.Exception { - super((java.lang.String)null, (int)0); - } +public Derived() throws java.lang.Exception { +super((java.lang.String)null, (int)0); +} +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/synchronizedProperty.test b/plugins/groovy/testdata/groovy/stubGenerator/synchronizedProperty.test index 58b4a547b1b3..ce06ebc6c039 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/synchronizedProperty.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/synchronizedProperty.test @@ -3,34 +3,34 @@ class Foo { } ----- public class Foo extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public java.lang.Object getBar() { - return null; - } +public java.lang.Object getBar() { +return null; +} - public void setBar(java.lang.Object bar) { - return ; - } +public void setBar(java.lang.Object bar) { +return ; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - private java.lang.Object bar = null; +private java.lang.Object bar = null; } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/throwsCheckedException.test b/plugins/groovy/testdata/groovy/stubGenerator/throwsCheckedException.test index 7990f3b43cad..184a0f3f73f2 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/throwsCheckedException.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/throwsCheckedException.test @@ -3,28 +3,29 @@ class Foo { } ----- public class Foo extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public java.lang.Object foo() throws java.io.IOException { - return null; - } +public java.lang.Object foo() throws java.io.IOException { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/toGenerate.test b/plugins/groovy/testdata/groovy/stubGenerator/toGenerate.test index 6f294679256f..a8ba2c80c181 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/toGenerate.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/toGenerate.test @@ -2,24 +2,25 @@ class s { } ----- public class s extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/toGenerate1.test b/plugins/groovy/testdata/groovy/stubGenerator/toGenerate1.test index cb7a7cc83cbd..43b302ff51e4 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/toGenerate1.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/toGenerate1.test @@ -4,34 +4,36 @@ class s { println "foo" ----- public class toGenerate1 extends groovy.lang.Script { - public static void main(java.lang.String[] args) { - return ; - } +public static void main(java.lang.String[] args) { +return ; +} + +public java.lang.Object run() { +return null; +} - public java.lang.Object run() { - return null; - } } --- public class s extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/vararg1.test b/plugins/groovy/testdata/groovy/stubGenerator/vararg1.test index 547781aa225e..b114c6130c70 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/vararg1.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/vararg1.test @@ -4,32 +4,33 @@ class Foo { } ----- public class Foo extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public void foo(java.lang.String... foo) { - return ; - } +public void foo(java.lang.String... foo) { +return ; +} - public void foo(java.lang.String[] foo, java.lang.Object bar) { - return ; - } +public void foo(java.lang.String[] foo, java.lang.Object bar) { +return ; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} + +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/stubGenerator/varargs.test b/plugins/groovy/testdata/groovy/stubGenerator/varargs.test index 88ae946b5e20..e849953e50fa 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/varargs.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/varargs.test @@ -10,58 +10,58 @@ class Derived { } ----- public class Foo extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public Foo(java.lang.String... s) { +public Foo(java.lang.String... s) { - } +} +public java.lang.Object foo(java.lang.String... s) { +return null; +} - public java.lang.Object foo(java.lang.String... s) { - return null; - } +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- public class Derived extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { - public Derived(java.lang.String... s) { - super(); - } +public Derived(java.lang.String... s) { +super(); +} +public groovy.lang.MetaClass getMetaClass() { +return null; +} - public groovy.lang.MetaClass getMetaClass() { - return null; - } +public void setMetaClass(groovy.lang.MetaClass mc) { +return ; +} - public void setMetaClass(groovy.lang.MetaClass mc) { - return ; - } +public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { +return null; +} - public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { - return null; - } +public java.lang.Object getProperty(java.lang.String propertyName) { +return null; +} - public java.lang.Object getProperty(java.lang.String propertyName) { - return null; - } +public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { +return ; +} - public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { - return ; - } } --- \ No newline at end of file diff --git a/resources/src/idea/IdeaActions.xml b/resources/src/idea/IdeaActions.xml index 5d07dcd316b7..840522251c3c 100644 --- a/resources/src/idea/IdeaActions.xml +++ b/resources/src/idea/IdeaActions.xml @@ -197,6 +197,7 @@ +