diff --git a/.idea/modules.xml b/.idea/modules.xml index 7dd2c78681b2..8720385396a2 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -71,6 +71,7 @@ + diff --git a/bin/log.xml b/bin/log.xml index a85a744b1c38..d8fca779f651 100644 --- a/bin/log.xml +++ b/bin/log.xml @@ -1,6 +1,6 @@ - + @@ -29,9 +29,9 @@ - - - + + + @@ -52,19 +52,10 @@ - - - + diff --git a/community-resources/src/idea/IdeaApplicationInfo.xml b/community-resources/src/idea/IdeaApplicationInfo.xml index 035e49f13af7..081eac6c941c 100644 --- a/community-resources/src/idea/IdeaApplicationInfo.xml +++ b/community-resources/src/idea/IdeaApplicationInfo.xml @@ -5,7 +5,7 @@ - + diff --git a/community-resources/src/idea/PlatformLangXmlApplicationInfo.xml b/community-resources/src/idea/PlatformLangXmlApplicationInfo.xml index 1bcdca8d3b40..4b701bebb5cd 100644 --- a/community-resources/src/idea/PlatformLangXmlApplicationInfo.xml +++ b/community-resources/src/idea/PlatformLangXmlApplicationInfo.xml @@ -4,7 +4,7 @@ - + diff --git a/images/src/org/intellij/images/editor/impl/ImageEditorUI.java b/images/src/org/intellij/images/editor/impl/ImageEditorUI.java index c4f80c1742cf..e8589aaf0949 100644 --- a/images/src/org/intellij/images/editor/impl/ImageEditorUI.java +++ b/images/src/org/intellij/images/editor/impl/ImageEditorUI.java @@ -24,6 +24,7 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiManager; +import com.intellij.ui.PopupHandler; import com.intellij.ui.ScrollPaneFactory; import org.intellij.images.ImagesBundle; import org.intellij.images.editor.ImageDocument; @@ -318,24 +319,21 @@ final class ImageEditorUI extends JPanel implements DataProvider { } private class FocusRequester extends MouseAdapter { - public void mouseClicked(MouseEvent e) { + public void mousePressed(MouseEvent e) { requestFocus(); } } - private static final class EditorMouseAdapter extends MouseAdapter { - public void mouseClicked(MouseEvent e) { - if (MouseEvent.BUTTON3 == e.getButton() && e.getClickCount() == 1) { + private static final class EditorMouseAdapter extends PopupHandler { + @Override + public void invokePopup(Component comp, int x, int y) { // Single right click ActionManager actionManager = ActionManager.getInstance(); ActionGroup actionGroup = (ActionGroup) actionManager.getAction(ImageEditorActions.GROUP_POPUP); ActionPopupMenu menu = actionManager.createActionPopupMenu(ImageEditorActions.ACTION_PLACE, actionGroup); JPopupMenu popupMenu = menu.getComponent(); popupMenu.pack(); - popupMenu.show(e.getComponent(), e.getX(), e.getY()); - - e.consume(); - } + popupMenu.show(comp, x, y); } } diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/DebuggerAction.java b/java/debugger/impl/src/com/intellij/debugger/actions/DebuggerAction.java index d149e8c388f0..8aebe9e5a86c 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/DebuggerAction.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/DebuggerAction.java @@ -31,11 +31,11 @@ import com.intellij.ide.DataManager; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.project.Project; +import com.intellij.ui.DoubleClickListener; import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.tree.TreePath; -import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; @@ -114,22 +114,23 @@ public abstract class DebuggerAction extends AnAction { } public static Disposable installEditAction(final JTree tree, String actionName) { - final MouseAdapter mouseListener = new MouseAdapter() { - public void mouseClicked(MouseEvent e) { - if (e.getClickCount() != 2) return; - if (tree.getPathForLocation(e.getX(), e.getY()) == null) return; + final DoubleClickListener listener = new DoubleClickListener() { + @Override + protected boolean onDoubleClick(MouseEvent e) { + if (tree.getPathForLocation(e.getX(), e.getY()) == null) return false; DataContext dataContext = DataManager.getInstance().getDataContext(tree); GotoFrameSourceAction.doAction(dataContext); + return true; } }; - tree.addMouseListener(mouseListener); - + listener.installOn(tree); + final AnAction action = ActionManager.getInstance().getAction(actionName); action.registerCustomShortcutSet(CommonShortcuts.getEditSource(), tree); return new Disposable() { public void dispose() { - tree.removeMouseListener(mouseListener); + listener.uninstall(tree); action.unregisterCustomShortcutSet(tree); } }; diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerEditorImpl.java b/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerEditorImpl.java index 68c6049d4cdc..6153608513de 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerEditorImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerEditorImpl.java @@ -38,13 +38,13 @@ import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.ui.ClickListener; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.border.EmptyBorder; import java.awt.*; -import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -102,18 +102,18 @@ public abstract class DebuggerEditorImpl extends CompletionEditor{ myChooseFactory.setToolTipText("Click to change the language"); myChooseFactory.setBorder(new EmptyBorder(0, 3, 0, 3)); - myChooseFactory.addMouseListener(new MouseAdapter() { + new ClickListener() { @Override - public void mouseClicked(MouseEvent e) { + public boolean onClick(MouseEvent e, int clickCount) { ListPopup oldPopup = myPopup != null ? myPopup.get() : null; if (oldPopup != null && !oldPopup.isDisposed()) { oldPopup.cancel(); myPopup = null; - return; + return true; } if (!myChooseFactory.isEnabled()) { - return; + return true; } DefaultActionGroup actions = new DefaultActionGroup(); @@ -134,8 +134,9 @@ public abstract class DebuggerEditorImpl extends CompletionEditor{ false); popup.showUnderneathOf(myChooseFactory); myPopup = new WeakReference(popup); + return true; } - }); + }.installOn(myChooseFactory); } @Override diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/GetJPDADialog.java b/java/debugger/impl/src/com/intellij/debugger/ui/GetJPDADialog.java index 7348beedcc76..f6504b525357 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/GetJPDADialog.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/GetJPDADialog.java @@ -21,17 +21,16 @@ */ package com.intellij.debugger.ui; +import com.intellij.debugger.DebuggerBundle; import com.intellij.ide.BrowserUtil; import com.intellij.openapi.ui.DialogWrapper; -import com.intellij.debugger.DebuggerBundle; +import com.intellij.ui.DoubleClickListener; +import org.jetbrains.annotations.NonNls; import javax.swing.*; import java.awt.*; -import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import org.jetbrains.annotations.NonNls; - public class GetJPDADialog extends DialogWrapper { private static final @NonNls String JPDA_URL = "http://java.sun.com/products/jpda"; @@ -55,14 +54,13 @@ public class GetJPDADialog extends DialogWrapper { JLabel label1 = new JLabel(DebuggerBundle.message("label.get.jpda.dialog.prompt")); //label1.setForeground(Color.black); JLabel label2 = new JLabel(JPDA_URL); - label2.addMouseListener( - new MouseAdapter() { - public void mouseClicked(MouseEvent e) { - BrowserUtil.launchBrowser(JPDA_URL); - } - + new DoubleClickListener() { + @Override + protected boolean onDoubleClick(MouseEvent e) { + BrowserUtil.launchBrowser(JPDA_URL); + return true; } - ); + }.installOn(label2); label2.setForeground(Color.blue.darker()); label2.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); _panel2.add(new JLabel(DebuggerBundle.message("label.get.jpda.dialog.error.description")), BorderLayout.NORTH); diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointChooser.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointChooser.java index 3eaf0476498e..cc94f6be4b59 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointChooser.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointChooser.java @@ -24,7 +24,9 @@ import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.JBPopupListener; import com.intellij.openapi.ui.popup.LightweightWindowEvent; import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.ui.popup.util.DetailView; +import com.intellij.ui.popup.util.ItemWrapper; import com.intellij.xdebugger.breakpoints.ui.BreakpointItem; import com.intellij.xdebugger.impl.breakpoints.ui.tree.BreakpointMasterDetailPopupBuilder; import org.jetbrains.annotations.NotNull; @@ -62,8 +64,7 @@ public class BreakpointChooser { public void setSelectedBreakpoint(Object selectedBreakpoint) { mySelectedBreakpoint = selectedBreakpoint; myBreakpointItem = selectedBreakpoint != null ? new JavaBreakpointItem(null, (Breakpoint)selectedBreakpoint) : null; - updatePresentation(myComboBoxAction.getTemplatePresentation(), myBreakpointItem); - myActionToolbar.getComponent().repaint(); + updatePresentation(myComboBoxAction.getTemplatePresentation(), myBreakpointItem); } private void pop(DetailView.PreviewEditorState pushed) { @@ -80,7 +81,7 @@ public class BreakpointChooser { void breakpointChosen(Project project, BreakpointItem breakpointItem, JBPopup popup); } - public BreakpointChooser(Project project, Delegate delegate) { + public BreakpointChooser(Project project, Delegate delegate, Breakpoint baseBreakpoint) { myProject = project; myDelegate = delegate; @@ -146,7 +147,7 @@ public class BreakpointChooser { return null; } }; - + setSelectedBreakpoint(baseBreakpoint); myActionToolbar = ActionManager.getInstance().createActionToolbar("asdad", new DefaultActionGroup(myComboBoxAction), true); } @@ -156,7 +157,7 @@ public class BreakpointChooser { } private void updatePresentation(Presentation presentation, BreakpointItem breakpointItem) { - if (breakpointItem != null) { + if (breakpointItem != null && breakpointItem.getBreakpoint() != null) { presentation.setIcon(breakpointItem.getIcon()); presentation.setText(breakpointItem.getDisplayText()); } @@ -173,9 +174,11 @@ public class BreakpointChooser { private class MyDetailView implements DetailView { private final PreviewEditorState myPushed; + private ItemWrapper myCurrentItem; public MyDetailView(PreviewEditorState pushed) { myPushed = pushed; + putUserData(BreakpointItem.EDITOR_ONLY, Boolean.TRUE); } @Override @@ -210,14 +213,30 @@ public class BreakpointChooser { return myDetailView.getEditorState(); } + public void setCurrentItem(ItemWrapper currentItem) { + myCurrentItem = currentItem; + } + + @Override + public ItemWrapper getCurrentItem() { + return myCurrentItem; + } + + @Override + public boolean hasEditorOnly() { + return true; + } + + UserDataHolderBase myDataHolderBase = new UserDataHolderBase(); + @Override public T getUserData(@NotNull Key key) { - return myDetailView.getUserData(key); + return myDataHolderBase.getUserData(key); } @Override public void putUserData(@NotNull Key key, @Nullable T value) { - myDetailView.putUserData(key, value); + myDataHolderBase.putUserData(key, value); } } } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointPropertiesPanel.form b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointPropertiesPanel.form index aa9ca7fb74a4..a447e37e0e09 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointPropertiesPanel.form +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointPropertiesPanel.form @@ -82,7 +82,7 @@ - + diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointPropertiesPanel.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointPropertiesPanel.java index ce2bc0a5a938..c4dee4bc0638 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointPropertiesPanel.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointPropertiesPanel.java @@ -20,6 +20,7 @@ */ package com.intellij.debugger.ui.breakpoints; +import com.intellij.debugger.DebuggerBundle; import com.intellij.debugger.DebuggerManagerEx; import com.intellij.debugger.InstanceFilter; import com.intellij.debugger.engine.evaluation.CodeFragmentKind; @@ -42,6 +43,7 @@ import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.ui.FieldPanel; import com.intellij.ui.MultiLineTooltipUI; +import com.intellij.ui.SimpleColoredComponent; import com.intellij.ui.components.JBCheckBox; import com.intellij.ui.popup.util.DetailView; import com.intellij.util.IJSwingUtilities; @@ -61,7 +63,7 @@ import java.util.List; public abstract class BreakpointPropertiesPanel { - private final BreakpointChooser myMasterBreakpointChooser; + private BreakpointChooser myMasterBreakpointChooser; public void setDetailView(DetailView detailView) { myDetailView = detailView; @@ -284,24 +286,6 @@ public abstract class BreakpointPropertiesPanel { myLogExpressionCombo = new DebuggerExpressionComboBox(project, "LineBreakpoint logMessage"); - myMasterBreakpointChooser = new BreakpointChooser(project, new BreakpointChooser.Delegate() { - @Override - public void breakpointChosen(Project project, BreakpointItem item, JBPopup popup) { - final boolean enabled = item != null && item.getBreakpoint() != null; - myLeaveEnabledRadioButton.setEnabled(enabled); - myDisableAgainRadio.setEnabled(enabled); - myEnableOrDisableLabel.setEnabled(enabled); - - if (item != null) { - - saveMasterBreakpoint(); - } - - updateMasterBreakpointPanel(findMasterBreakpointRule()); - - } - }); - myInstanceFiltersField = new FieldPanel(new MyTextField(), "", null, new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -357,8 +341,7 @@ public abstract class BreakpointPropertiesPanel { insert(myConditionComboPanel, conditionPanel); insert(myLogExpressionComboPanel, myLogExpressionCombo); - //insert(myDependentBreakpointComboPanel, baseBreakpointCombo); - insert(myDependentBreakpointComboPanel, myMasterBreakpointChooser.getComponent()); + insert(myInstanceFiltersFieldPanel, myInstanceFiltersField); insert(myClassFiltersFieldPanel, myClassFiltersField); @@ -390,6 +373,68 @@ public abstract class BreakpointPropertiesPanel { break; } } + items.add(new BreakpointItem() { + @Override + public Object getBreakpoint() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public boolean isEnabled() { + return false; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public void setEnabled(boolean state) { + //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + protected void setupGenericRenderer(SimpleColoredComponent renderer, boolean plainView) { + renderer.clear(); + renderer.append(getDisplayText()); + } + + @Override + public Icon getIcon() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public String getDisplayText() { + return DebuggerBundle.message("value.none"); + } + + @Override + public boolean navigate() { + return false; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public String speedSearchText() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public String footerText() { + return ""; + } + + @Override + protected void doUpdateDetailView(DetailView panel, boolean editorOnly) { + //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public boolean allowedToRemove() { + return false; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public void removed(Project project) { + //To change body of implemented methods use File | Settings | File Templates. + } + }); return items; } @@ -414,9 +459,13 @@ public abstract class BreakpointPropertiesPanel { else { EnableBreakpointRule rule = findMasterBreakpointRule(); boolean selected = myLeaveEnabledRadioButton.isSelected(); - if (rule != null && (rule.getMasterBreakpoint() != masterBreakpoint || rule.isLeaveEnabled() != selected ) ) { - getBreakpointManager(myProject).removeBreakpointRule(rule); - + if (rule != null) { + if (rule.getMasterBreakpoint() != masterBreakpoint || rule.isLeaveEnabled() != selected) { + getBreakpointManager(myProject).removeBreakpointRule(rule); + } + else { + return; + } } getBreakpointManager(myProject).addBreakpointRule(new EnableBreakpointRule(getBreakpointManager(myProject), masterBreakpoint, @@ -569,14 +618,35 @@ public abstract class BreakpointPropertiesPanel { } private void initMasterBreakpointPanel() { - myMasterBreakpointChooser.setBreakpointItems(getBreakpointItemsExceptMy()); - final EnableBreakpointRule rule = findMasterBreakpointRule(); final Breakpoint baseBreakpoint = rule != null ? rule.getMasterBreakpoint() : null; updateMasterBreakpointPanel(rule); - myMasterBreakpointChooser.setSelectedBreakpoint(baseBreakpoint); + + myMasterBreakpointChooser = new BreakpointChooser(myProject, new BreakpointChooser.Delegate() { + @Override + public void breakpointChosen(Project project, BreakpointItem item, JBPopup popup) { + final boolean enabled = item != null && item.getBreakpoint() != null; + myLeaveEnabledRadioButton.setEnabled(enabled); + myDisableAgainRadio.setEnabled(enabled); + myEnableOrDisableLabel.setEnabled(enabled); + + if (item != null) { + + saveMasterBreakpoint(); + } + + updateMasterBreakpointPanel(findMasterBreakpointRule()); + + } + }, baseBreakpoint); + + insert(myDependentBreakpointComboPanel, myMasterBreakpointChooser.getComponent()); + + + myMasterBreakpointChooser.setBreakpointItems(getBreakpointItemsExceptMy()); + } private @Nullable EnableBreakpointRule findMasterBreakpointRule() { @@ -793,37 +863,6 @@ public abstract class BreakpointPropertiesPanel { return myPanel; } - private static class ComboboxItem { - private final Breakpoint breakpoint; - - public ComboboxItem() { - breakpoint = null; - } - - public ComboboxItem(@NotNull final Breakpoint breakpoint) { - this.breakpoint = breakpoint; - } - - public Breakpoint getBreakpoint() { - return breakpoint; - } - - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - final ComboboxItem comboboxItem = (ComboboxItem)o; - - if (breakpoint != null ? !breakpoint.equals(comboboxItem.breakpoint) : comboboxItem.breakpoint != null) return false; - - return true; - } - - public int hashCode() { - return breakpoint != null ? breakpoint.hashCode() : 0; - } - } - private BreakpointManager getBreakpointManager(Project project) { return DebuggerManagerEx.getInstanceEx(project).getBreakpointManager(); } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointWithHighlighter.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointWithHighlighter.java index 7ef5417ca915..a285463aeea4 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointWithHighlighter.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointWithHighlighter.java @@ -25,6 +25,7 @@ import com.intellij.debugger.engine.events.DebuggerCommandImpl; import com.intellij.debugger.engine.requests.RequestManagerImpl; import com.intellij.debugger.impl.DebuggerContextImpl; import com.intellij.debugger.settings.DebuggerSettings; +import com.intellij.debugger.ui.JavaDebuggerSupport; import com.intellij.idea.ActionsBundle; import com.intellij.openapi.actionSystem.ActionGroup; import com.intellij.openapi.actionSystem.AnAction; @@ -49,6 +50,7 @@ import com.intellij.psi.PsiManager; import com.intellij.psi.jsp.JspFile; import com.intellij.ui.classFilter.ClassFilter; import com.intellij.util.StringBuilderSpinAllocator; +import com.intellij.xdebugger.impl.DebuggerSupport; import com.intellij.xdebugger.impl.actions.EditBreakpointAction; import com.intellij.xdebugger.impl.actions.ViewBreakpointsAction; import com.intellij.xdebugger.impl.actions.XDebuggerActions; @@ -594,67 +596,6 @@ public abstract class BreakpointWithHighlighter extends Breakpoint { } } - @NotNull - private ActionGroup createMenuActions() { - final BreakpointManager breakpointManager = DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager(); - /** - * Used from Popup Menu - */ - class RemoveAction extends AnAction { - @Nullable private Breakpoint myBreakpoint; - - public RemoveAction(Breakpoint breakpoint) { - super(DebuggerBundle.message("action.remove.text")); - myBreakpoint = breakpoint; - } - - @Override - public void actionPerformed(AnActionEvent e) { - if (myBreakpoint != null) { - breakpointManager.removeBreakpoint(myBreakpoint); - myBreakpoint = null; - } - } - } - - /** - * Used from Popup Menu - */ - class SetEnabledAction extends AnAction { - private final boolean myNewValue; - private final Breakpoint myBreakpoint; - - public SetEnabledAction(Breakpoint breakpoint, boolean newValue) { - super(newValue ? DebuggerBundle.message("action.enable.text") : DebuggerBundle.message("action.disable.text")); - myBreakpoint = breakpoint; - myNewValue = newValue; - } - - @Override - public void actionPerformed(AnActionEvent e) { - myBreakpoint.ENABLED = myNewValue; - breakpointManager.fireBreakpointChanged(myBreakpoint); - myBreakpoint.updateUI(); - } - } - - - AnAction viewBreakpointsAction = - new ViewBreakpointsAction(ActionsBundle.actionText(XDebuggerActions.VIEW_BREAKPOINTS), this); - - DefaultActionGroup group = new DefaultActionGroup(); - RangeHighlighter highlighter = getHighlighter(); - if (highlighter != null) { - group.add(new EditBreakpointAction()); - group.addSeparator(); - } - group.add(new SetEnabledAction(this, !ENABLED)); - group.add(new RemoveAction(this)); - group.addSeparator(); - group.add(viewBreakpointsAction); - return group; - } - private class MyGutterIconRenderer extends GutterIconRenderer { private final Icon myIcon; private final String myDescription; @@ -699,7 +640,63 @@ public abstract class BreakpointWithHighlighter extends Breakpoint { @Override public ActionGroup getPopupMenuActions() { - return createMenuActions(); + final BreakpointManager breakpointManager = DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager(); + /** + * Used from Popup Menu + */ + class RemoveAction extends AnAction { + @Nullable private Breakpoint myBreakpoint; + + public RemoveAction(Breakpoint breakpoint) { + super(DebuggerBundle.message("action.remove.text")); + myBreakpoint = breakpoint; + } + + @Override + public void actionPerformed(AnActionEvent e) { + if (myBreakpoint != null) { + breakpointManager.removeBreakpoint(myBreakpoint); + myBreakpoint = null; + } + } + } + + /** + * Used from Popup Menu + */ + class SetEnabledAction extends AnAction { + private final boolean myNewValue; + private final Breakpoint myBreakpoint; + + public SetEnabledAction(Breakpoint breakpoint, boolean newValue) { + super(newValue ? DebuggerBundle.message("action.enable.text") : DebuggerBundle.message("action.disable.text")); + myBreakpoint = breakpoint; + myNewValue = newValue; + } + + @Override + public void actionPerformed(AnActionEvent e) { + myBreakpoint.ENABLED = myNewValue; + breakpointManager.fireBreakpointChanged(myBreakpoint); + myBreakpoint.updateUI(); + } + } + + + AnAction viewBreakpointsAction = + new ViewBreakpointsAction(ActionsBundle.actionText(XDebuggerActions.VIEW_BREAKPOINTS), BreakpointWithHighlighter.this); + + DefaultActionGroup group = new DefaultActionGroup(); + RangeHighlighter highlighter = getHighlighter(); + if (highlighter != null) { + group.add(new EditBreakpointAction.ContextAction(this, BreakpointWithHighlighter.this, DebuggerSupport.getDebuggerSupport(JavaDebuggerSupport.class))); + group.addSeparator(); + } + group.add(new SetEnabledAction(BreakpointWithHighlighter.this, !ENABLED)); + group.add(new RemoveAction(BreakpointWithHighlighter.this)); + group.addSeparator(); + group.add(viewBreakpointsAction); + return group; } @Override diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaBreakpointItem.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaBreakpointItem.java index 170eec164c2f..e46e7103fd45 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaBreakpointItem.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaBreakpointItem.java @@ -72,21 +72,23 @@ class JavaBreakpointItem extends BreakpointItem { } @Override - protected void doUpdateDetailView(DetailView panel) { - BreakpointPropertiesPanel breakpointPropertiesPanel = myBreakpointFactory != null ? myBreakpointFactory - .createBreakpointPropertiesPanel(myBreakpoint.getProject(), false) : null; - if (breakpointPropertiesPanel != null) { - breakpointPropertiesPanel.setSaveOnRemove(true); - breakpointPropertiesPanel.setDetailView(panel); - } + protected void doUpdateDetailView(DetailView panel, boolean editorOnly) { + if (!editorOnly) { + BreakpointPropertiesPanel breakpointPropertiesPanel = myBreakpointFactory != null ? myBreakpointFactory + .createBreakpointPropertiesPanel(myBreakpoint.getProject(), false) : null; - if (breakpointPropertiesPanel != null) { - breakpointPropertiesPanel.initFrom(myBreakpoint, true); - final JPanel mainPanel = breakpointPropertiesPanel.getPanel(); - panel.setDetailPanel(mainPanel); - } - else { - panel.setDetailPanel(null); + if (breakpointPropertiesPanel != null) { + breakpointPropertiesPanel.initFrom(myBreakpoint, true); + + breakpointPropertiesPanel.setSaveOnRemove(true); + breakpointPropertiesPanel.setDetailView(panel); + + final JPanel mainPanel = breakpointPropertiesPanel.getPanel(); + panel.setDetailPanel(mainPanel); + } + else { + panel.setDetailPanel(null); + } } if (myBreakpoint instanceof BreakpointWithHighlighter) { @@ -98,6 +100,15 @@ class JavaBreakpointItem extends BreakpointItem { } } + @Override + public boolean navigate() { + if (myBreakpoint instanceof BreakpointWithHighlighter) { + ((BreakpointWithHighlighter)myBreakpoint).getSourcePosition().navigate(true); + return true; + } + return false; + } + @Override public boolean allowedToRemove() { return myBreakpointFactory != null && myBreakpointFactory.breakpointCanBeRemoved(myBreakpoint); diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/impl/MainWatchPanel.java b/java/debugger/impl/src/com/intellij/debugger/ui/impl/MainWatchPanel.java index 1674be4a3b11..d890a4601813 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/impl/MainWatchPanel.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/impl/MainWatchPanel.java @@ -52,7 +52,6 @@ import javax.swing.*; import java.awt.*; import java.awt.datatransfer.DataFlavor; import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public class MainWatchPanel extends WatchPanel implements DataProvider { @@ -67,25 +66,25 @@ public class MainWatchPanel extends WatchPanel implements DataProvider { final AnAction newWatchAction = ActionManager.getInstance().getAction(DebuggerActions.NEW_WATCH); newWatchAction.registerCustomShortcutSet(CommonShortcuts.INSERT, watchTree); - final MouseAdapter mouseListener = new MouseAdapter() { - public void mouseClicked(MouseEvent e) { - if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { - AnAction editWatchAction = ActionManager.getInstance().getAction(DebuggerActions.EDIT_WATCH); - Presentation presentation = (Presentation)editWatchAction.getTemplatePresentation().clone(); - DataContext context = DataManager.getInstance().getDataContext(watchTree); + final ClickListener mouseListener = new DoubleClickListener() { + @Override + protected boolean onDoubleClick(MouseEvent e) { + AnAction editWatchAction = ActionManager.getInstance().getAction(DebuggerActions.EDIT_WATCH); + Presentation presentation = editWatchAction.getTemplatePresentation().clone(); + DataContext context = DataManager.getInstance().getDataContext(watchTree); - AnActionEvent actionEvent = new AnActionEvent(null, context, "WATCH_TREE", presentation, ActionManager.getInstance(), 0); - editWatchAction.actionPerformed(actionEvent); - } + AnActionEvent actionEvent = new AnActionEvent(null, context, "WATCH_TREE", presentation, ActionManager.getInstance(), 0); + editWatchAction.actionPerformed(actionEvent); + return true; } }; - ListenerUtil.addMouseListener(watchTree, mouseListener); + ListenerUtil.addClickListener(watchTree, mouseListener); final AnAction editWatchAction = ActionManager.getInstance().getAction(DebuggerActions.EDIT_WATCH); editWatchAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0)), watchTree); registerDisposable(new Disposable() { public void dispose() { - ListenerUtil.removeMouseListener(watchTree, mouseListener); + ListenerUtil.removeClickListener(watchTree, mouseListener); removeWatchesAction.unregisterCustomShortcutSet(watchTree); newWatchAction.unregisterCustomShortcutSet(watchTree); editWatchAction.unregisterCustomShortcutSet(watchTree); diff --git a/java/idea-ui/src/com/intellij/ide/palette/impl/PaletteManager.java b/java/idea-ui/src/com/intellij/ide/palette/impl/PaletteManager.java index b3c8af6564d8..5aa1bf611e7a 100644 --- a/java/idea-ui/src/com/intellij/ide/palette/impl/PaletteManager.java +++ b/java/idea-ui/src/com/intellij/ide/palette/impl/PaletteManager.java @@ -71,7 +71,7 @@ public class PaletteManager implements ProjectComponent { ToolWindowAnchor.RIGHT, myProject, true); - myPaletteToolWindow.setIcon(AllIcons.General.ToolWindowPalette); + myPaletteToolWindow.setIcon(AllIcons.Toolwindows.ToolWindowPalette); setContent(); final MyFileEditorManagerListener myListener = new MyFileEditorManagerListener(); myFileEditorManager.addFileEditorManagerListener(myListener, myProject); diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectCreateModeStep.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectCreateModeStep.java index c507c78e8063..81a02dee1a7e 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectCreateModeStep.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectCreateModeStep.java @@ -29,6 +29,7 @@ import com.intellij.ide.util.projectWizard.WizardContext; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.util.Disposer; +import com.intellij.ui.DoubleClickListener; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -37,7 +38,6 @@ import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; @@ -91,14 +91,13 @@ public class ProjectCreateModeStep extends ModuleWizardStep { setMode(mode); } }); - rb.addMouseListener(new MouseAdapter() { + new DoubleClickListener() { @Override - public void mouseClicked(MouseEvent e) { - if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { - wizardContext.requestNextStep(); - } + protected boolean onDoubleClick(MouseEvent e) { + wizardContext.requestNextStep(); + return true; } - }); + }.installOn(rb); myWholePanel.add(rb, gc); group.add(rb); diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectNameWithTypeStep.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectNameWithTypeStep.java index f90961a0ba77..90a5f94e794e 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectNameWithTypeStep.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectNameWithTypeStep.java @@ -40,6 +40,7 @@ import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.DocumentAdapter; +import com.intellij.ui.DoubleClickListener; import com.intellij.ui.components.JBScrollPane; import com.intellij.util.IJSwingUtilities; import com.intellij.util.ui.UIUtil; @@ -47,7 +48,10 @@ import com.intellij.util.ui.UIUtil; import javax.swing.*; import javax.swing.event.*; import java.awt.*; -import java.awt.event.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; import java.io.File; import java.util.List; @@ -153,13 +157,13 @@ public class ProjectNameWithTypeStep extends ProjectNameStep { } }); myTypesList.setSelectedIndex(0); - myTypesList.addMouseListener(new MouseAdapter() { - public void mouseClicked(MouseEvent e) { - if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { - myWizardContext.requestNextStep(); - } + new DoubleClickListener() { + @Override + protected boolean onDoubleClick(MouseEvent e) { + myWizardContext.requestNextStep(); + return true; } - }); + }.installOn(myTypesList); final Dimension preferredSize = calcTypeListPreferredSize(ModuleBuilder.getAllBuilders()); final JBScrollPane pane = IJSwingUtilities.findParentOfType(myTypesList, JBScrollPane.class); diff --git a/java/idea-ui/src/com/intellij/ide/util/projectWizard/JdkChooserPanel.java b/java/idea-ui/src/com/intellij/ide/util/projectWizard/JdkChooserPanel.java index 20234f22f4b2..42a3e3265160 100644 --- a/java/idea-ui/src/com/intellij/ide/util/projectWizard/JdkChooserPanel.java +++ b/java/idea-ui/src/com/intellij/ide/util/projectWizard/JdkChooserPanel.java @@ -30,6 +30,8 @@ import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.wm.ex.WindowManagerEx; +import com.intellij.ui.ClickListener; +import com.intellij.ui.DoubleClickListener; import com.intellij.ui.ListScrollingUtil; import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.components.JBList; @@ -42,7 +44,6 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import java.awt.*; import java.awt.event.ActionEvent; -import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.*; @@ -66,13 +67,15 @@ public class JdkChooserPanel extends JPanel { myCurrentJdk = (Sdk)myList.getSelectedValue(); } }); - myList.addMouseListener(new MouseAdapter() { - public void mouseClicked(MouseEvent e) { - if (e.getClickCount() == 2 && myProject == null) { + new ClickListener() { + @Override + public boolean onClick(MouseEvent e, int clickCount) { + if (myProject == null) { editJdkTable(); } + return true; } - }); + }.installOn(myList); JPanel panel = new JPanel(new BorderLayout()); panel.add(ScrollPaneFactory.createScrollPane(myList), BorderLayout.CENTER); @@ -219,14 +222,13 @@ public class JdkChooserPanel extends JPanel { } else { ListScrollingUtil.ensureSelectionExists(jdkChooserPanel.myList); } - jdkChooserPanel.myList.addMouseListener(new MouseAdapter() { + new DoubleClickListener() { @Override - public void mouseClicked(final MouseEvent e) { - if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { - dialog.clickDefaultButton(); - } + protected boolean onDoubleClick(MouseEvent e) { + dialog.clickDefaultButton(); + return true; } - }); + }.installOn(jdkChooserPanel.myList); dialog.show(); return dialog.isOK() ? jdkChooserPanel.getChosenJdk() : null; } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java index 9713f136b917..52b7802daf6e 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java @@ -74,7 +74,10 @@ import javax.swing.event.ListSelectionListener; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; import java.awt.*; -import java.awt.event.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -188,13 +191,13 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel { myEntryTable.getSelectionModel().setSelectionInterval(0,0); } - myEntryTable.addMouseListener(new MouseAdapter() { - public void mouseClicked(MouseEvent e) { - if (e.getClickCount() == 2){ - navigate(true); - } + new DoubleClickListener() { + @Override + protected boolean onDoubleClick(MouseEvent e) { + navigate(true); + return true; } - }); + }.installOn(myEntryTable); DefaultActionGroup actionGroup = new DefaultActionGroup(); final AnAction navigateAction = new AnAction(ProjectBundle.message("classpath.panel.navigate.action.text")) { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java index c583216282ec..40837d333a15 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java @@ -925,7 +925,7 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple private class AddModuleAction extends AnAction implements DumbAware { public AddModuleAction() { - super(ProjectBundle.message("add.new.module.text.full"), null, AllIcons.Actions.Modul); + super(ProjectBundle.message("add.new.module.text.full"), null, AllIcons.Actions.Module); } public void actionPerformed(final AnActionEvent e) { diff --git a/java/idea-ui/src/com/intellij/projectImport/ImportChooserStep.java b/java/idea-ui/src/com/intellij/projectImport/ImportChooserStep.java index 08b6334ea172..0ce3cee53834 100644 --- a/java/idea-ui/src/com/intellij/projectImport/ImportChooserStep.java +++ b/java/idea-ui/src/com/intellij/projectImport/ImportChooserStep.java @@ -24,6 +24,7 @@ import com.intellij.ide.util.PropertiesComponent; import com.intellij.ide.util.newProjectWizard.StepSequence; import com.intellij.ide.util.projectWizard.WizardContext; import com.intellij.openapi.util.Comparing; +import com.intellij.ui.DoubleClickListener; import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.components.JBList; import org.jetbrains.annotations.NonNls; @@ -32,7 +33,6 @@ import javax.swing.*; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import java.awt.*; -import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.Collections; @@ -87,14 +87,14 @@ public class ImportChooserStep extends ProjectImportWizardStep { } } } - myList.addMouseListener(new MouseAdapter() { + + new DoubleClickListener() { @Override - public void mouseClicked(MouseEvent e) { - if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { - context.requestNextStep(); - } + protected boolean onDoubleClick(MouseEvent e) { + context.requestNextStep(); + return true; } - }); + }.installOn(myList); } private static List sorted(ProjectImportProvider[] providers) { diff --git a/java/idea-ui/src/com/intellij/util/ui/classpath/ChooseLibrariesDialogBase.java b/java/idea-ui/src/com/intellij/util/ui/classpath/ChooseLibrariesDialogBase.java index 97649e847afb..d63545c3cecf 100644 --- a/java/idea-ui/src/com/intellij/util/ui/classpath/ChooseLibrariesDialogBase.java +++ b/java/idea-ui/src/com/intellij/util/ui/classpath/ChooseLibrariesDialogBase.java @@ -44,6 +44,7 @@ import com.intellij.openapi.roots.ui.OrderEntryAppearanceService; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.ui.DoubleClickListener; import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.SimpleColoredComponent; import com.intellij.ui.SimpleTextAttributes; @@ -66,7 +67,6 @@ import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import java.awt.*; import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.*; import java.util.List; @@ -188,15 +188,17 @@ public abstract class ChooseLibrariesDialogBase extends DialogWrapper { updateOKAction(); } }); - myTree.addMouseListener(new MouseAdapter() { + new DoubleClickListener() { @Override - public void mouseClicked(final MouseEvent e) { - if (e.getClickCount() != 2) return; + protected boolean onDoubleClick(MouseEvent e) { if (isOKActionEnabled()) { doOKAction(); + return true; } + return false; } - }); + }.installOn(myTree); + myTree.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ENTER"); myTree.getActionMap().put("ENTER", getOKAction()); final JScrollPane pane = ScrollPaneFactory.createScrollPane(myTree); diff --git a/java/java-impl/java-impl.iml b/java/java-impl/java-impl.iml index d19011b3e584..9735a4a7fad1 100644 --- a/java/java-impl/java-impl.iml +++ b/java/java-impl/java-impl.iml @@ -32,7 +32,6 @@ - diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java index 5bb12243485f..b9b531f20153 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -417,7 +417,7 @@ public class JavaMemberNameCompletionContributor extends CompletionContributor { element = LookupElementDecorator.withInsertHandler(element, new InsertHandler>() { @Override public void handleInsert(InsertionContext context, LookupElementDecorator item) { - callback.nameChoosen(item.getLookupString()); + callback.nameChosen(item.getLookupString()); } }); } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaLineMarkerProvider.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaLineMarkerProvider.java index bf7305100d6f..4ab59906589d 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaLineMarkerProvider.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaLineMarkerProvider.java @@ -22,6 +22,7 @@ import com.intellij.codeInsight.daemon.LineMarkerProvider; import com.intellij.codeInsight.daemon.MergeableLineMarkerInfo; import com.intellij.icons.AllIcons; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.colors.CodeInsightColors; import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.colors.EditorColorsScheme; @@ -32,6 +33,8 @@ import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.search.searches.AllOverridingMethodsSearch; import com.intellij.psi.search.searches.ClassInheritorsSearch; @@ -71,8 +74,9 @@ public class JavaLineMarkerProvider implements LineMarkerProvider, DumbAware { @Override @Nullable public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) { - if (element instanceof PsiIdentifier && element.getParent() instanceof PsiMethod) { - PsiMethod method = (PsiMethod)element.getParent(); + PsiElement parent; + if (element instanceof PsiIdentifier && (parent = element.getParent()) instanceof PsiMethod) { + PsiMethod method = (PsiMethod)parent; MethodSignatureBackedByPsiMethod superSignature = null; try { superSignature = SuperMethodsSearch.search(method, null, true, false).findFirst(); @@ -101,13 +105,19 @@ public class JavaLineMarkerProvider implements LineMarkerProvider, DumbAware { } } if (isMember && !(element1 instanceof PsiAnonymousClass || element1.getParent() instanceof PsiAnonymousClass)) { + PsiFile file = element1.getContainingFile(); + Document document = file == null ? null : PsiDocumentManager.getInstance(file.getProject()).getDocument(file); boolean drawSeparator = false; - int category = getCategory(element1); - for (PsiElement child = element1.getPrevSibling(); child != null; child = child.getPrevSibling()) { - int category1 = getCategory(child); - if (category1 == 0) continue; - drawSeparator = category != 1 || category1 != 1; - break; + + if (document != null) { + CharSequence documentChars = document.getCharsSequence(); + int category = getCategory(element1, documentChars); + for (PsiElement child = element1.getPrevSibling(); child != null; child = child.getPrevSibling()) { + int category1 = getCategory(child, documentChars); + if (category1 == 0) continue; + drawSeparator = category != 1 || category1 != 1; + break; + } } if (drawSeparator) { @@ -125,20 +135,18 @@ public class JavaLineMarkerProvider implements LineMarkerProvider, DumbAware { return null; } - protected static int getCategory(PsiElement element) { + protected static int getCategory(@NotNull PsiElement element, @NotNull CharSequence documentChars) { if (element instanceof PsiField || element instanceof PsiTypeParameter) return 1; if (element instanceof PsiClass || element instanceof PsiClassInitializer) return 2; if (element instanceof PsiMethod) { if (((PsiMethod)element).hasModifierProperty(PsiModifier.ABSTRACT)) { return 1; } - String text = element.getText(); - if (text.indexOf('\n') < 0 && text.indexOf('\r') < 0) { - return 1; - } - else { - return 2; - } + TextRange textRange = element.getTextRange(); + int start = textRange.getStartOffset(); + int end = Math.min(documentChars.length(), textRange.getEndOffset()); + int crlf = StringUtil.getLineBreakCount(documentChars.subSequence(start, end)); + return crlf == 0 ? 1 : 2; } return 0; } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/PullAsAbstractUpFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/PullAsAbstractUpFix.java index 883c17f21592..399b5d624ef0 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/PullAsAbstractUpFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/PullAsAbstractUpFix.java @@ -17,6 +17,7 @@ package com.intellij.codeInsight.daemon.impl.quickfix; import com.intellij.codeInsight.CodeInsightUtilBase; import com.intellij.codeInsight.daemon.impl.HighlightInfo; +import com.intellij.codeInsight.intention.impl.RunRefactoringAction; import com.intellij.codeInsight.navigation.NavigationUtil; import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement; import com.intellij.ide.util.PsiClassListCellRenderer; @@ -163,13 +164,13 @@ public class PullAsAbstractUpFix extends LocalQuickFixAndIntentionActionOnPsiEle name+= " and make it abstract"; } } - QuickFixAction.registerQuickFixAction(highlightInfo, new RunRefactoringIntention(new ExtractInterfaceHandler(), "Extract interface")); - QuickFixAction.registerQuickFixAction(highlightInfo, new RunRefactoringIntention(new ExtractSuperclassHandler(), "Extract superclass")); + QuickFixAction.registerQuickFixAction(highlightInfo, new RunRefactoringAction(new ExtractInterfaceHandler(), "Extract interface")); + QuickFixAction.registerQuickFixAction(highlightInfo, new RunRefactoringAction(new ExtractSuperclassHandler(), "Extract superclass")); } if (canBePulledUp) { - QuickFixAction.registerQuickFixAction(highlightInfo, new RunRefactoringIntention(new JavaPullUpHandler(), "Pull members up")); + QuickFixAction.registerQuickFixAction(highlightInfo, new RunRefactoringAction(new JavaPullUpHandler(), "Pull members up")); } QuickFixAction.registerQuickFixAction(highlightInfo, new PullAsAbstractUpFix(methodWithOverrides, name)); } diff --git a/java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilder.java b/java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilder.java index 7a74b3b31fef..9ec174fdf21c 100644 --- a/java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilder.java +++ b/java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilder.java @@ -569,7 +569,7 @@ public class JavaFoldingBuilder extends CustomFoldingBuilder implements DumbAwar } } - private static boolean hasOnlyOneMethod(@NotNull PsiAnonymousClass anonymousClass, boolean checkResolve) { + private static boolean hasOnlyOneLambdaMethod(@NotNull PsiAnonymousClass anonymousClass, boolean checkResolve) { PsiField[] fields = anonymousClass.getFields(); if (fields.length != 0) { if (fields.length == 1 && HighlightUtil.SERIAL_VERSION_UID_FIELD_NAME.equals(fields[0].getName()) && @@ -590,8 +590,13 @@ public class JavaFoldingBuilder extends CustomFoldingBuilder implements DumbAwar return false; } + PsiMethod method = anonymousClass.getMethods()[0]; + if (method.hasModifierProperty(PsiModifier.SYNCHRONIZED)) { + return false; + } + if (checkResolve) { - PsiReferenceList throwsList = anonymousClass.getMethods()[0].getThrowsList(); + PsiReferenceList throwsList = method.getThrowsList(); for (PsiClassType type : throwsList.getReferencedTypes()) { if (type.resolve() == null) { return false; @@ -617,7 +622,7 @@ public class JavaFoldingBuilder extends CustomFoldingBuilder implements DumbAwar final PsiExpressionList argumentList = expression.getArgumentList(); if (argumentList != null && argumentList.getExpressions().length == 0) { final PsiMethod[] methods = anonymousClass.getMethods(); - if (hasOnlyOneMethod(anonymousClass, !quick) && (quick || seemsLikeLambda(anonymousClass.getBaseClassType().resolve()))) { + if (hasOnlyOneLambdaMethod(anonymousClass, !quick) && (quick || seemsLikeLambda(anonymousClass.getBaseClassType().resolve()))) { final PsiMethod method = methods[0]; final PsiCodeBlock body = method.getBody(); if (body != null) { diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/ui/SimpleFieldChooser.java b/java/java-impl/src/com/intellij/codeInsight/generation/ui/SimpleFieldChooser.java index ff013dec0d16..26360dbb9f8a 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/ui/SimpleFieldChooser.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/ui/SimpleFieldChooser.java @@ -21,11 +21,11 @@ import com.intellij.psi.PsiField; import com.intellij.psi.PsiSubstitutor; import com.intellij.psi.util.PsiFormatUtil; import com.intellij.psi.util.PsiFormatUtilBase; +import com.intellij.ui.DoubleClickListener; import com.intellij.ui.components.JBList; import javax.swing.*; import java.awt.*; -import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; /** @@ -48,17 +48,16 @@ public class SimpleFieldChooser extends DialogWrapper { } myList = new JBList(model); myList.setCellRenderer(new MyListCellRenderer()); - myList.addMouseListener( - new MouseAdapter() { - public void mouseClicked(MouseEvent e) { - if (e.getClickCount() == 2) { - if (myList.getSelectedValues().length > 0) { - doOKAction(); - } - } + new DoubleClickListener() { + @Override + protected boolean onDoubleClick(MouseEvent e) { + if (myList.getSelectedValues().length > 0) { + doOKAction(); + return true; } + return false; } - ); + }.installOn(myList); myList.setPreferredSize(new Dimension(300, 400)); return myList; diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/BaseRunRefactoringAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/BaseRunRefactoringAction.java new file mode 100644 index 000000000000..b9fbab23fa76 --- /dev/null +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/BaseRunRefactoringAction.java @@ -0,0 +1,49 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.intention.impl; + +import com.intellij.codeInsight.CodeInsightBundle; +import com.intellij.codeInsight.intention.IntentionAction; +import com.intellij.codeInsight.intention.LowPriorityAction; +import com.intellij.icons.AllIcons; +import com.intellij.openapi.util.Iconable; +import com.intellij.refactoring.RefactoringActionHandler; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; + +/** + * @author Danila Ponomarenko + */ +public abstract class BaseRunRefactoringAction implements IntentionAction, Iconable, LowPriorityAction { + public static final Icon REFACTORING_BULB = AllIcons.Actions.RefactoringBulb; + + @NotNull + @Override + public final String getFamilyName() { + return CodeInsightBundle.message("intention.refactoring.family"); + } + + @Override + public final boolean startInWriteAction() { + return false; + } + + @Override + public final Icon getIcon(int flags) { + return REFACTORING_BULB; + } +} \ No newline at end of file diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateFieldFromParameterAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateFieldFromParameterAction.java index 5cefd9fbfd20..20ee44b6ee3a 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateFieldFromParameterAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateFieldFromParameterAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -351,7 +351,7 @@ public class CreateFieldFromParameterAction implements IntentionAction { fieldNameToCalc = dialog.getEnteredName(); isFinalToCalc = dialog.isDeclareFinal(); - suggestedNameInfo.nameChoosen(fieldNameToCalc); + suggestedNameInfo.nameChosen(fieldNameToCalc); } else { isFinalToCalc = !isMethodStatic && method.isConstructor(); diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/EncapsulateFieldAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/EncapsulateFieldAction.java new file mode 100644 index 000000000000..685f37b375b0 --- /dev/null +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/EncapsulateFieldAction.java @@ -0,0 +1,86 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.intention.impl; + +import com.intellij.codeInsight.CodeInsightBundle; +import com.intellij.openapi.editor.CaretModel; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; +import com.intellij.psi.*; +import com.intellij.refactoring.encapsulateFields.EncapsulateFieldsHandler; +import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Danila Ponomarenko + */ +public class EncapsulateFieldAction extends BaseRunRefactoringAction { + + @NotNull + @Override + public String getText() { + return CodeInsightBundle.message("intention.encapsulate.field.text"); + } + + @Override + public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + final PsiField field = getField(getElement(editor, file)); + return field != null && !field.hasModifierProperty(PsiModifier.FINAL) && !field.hasModifierProperty(PsiModifier.PRIVATE); + } + + + @Override + public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { + final PsiField field = getField(getElement(editor, file)); + if (field == null) { + return; + } + + new EncapsulateFieldsHandler().invoke(project, new PsiElement[]{field}, null); + } + + @Nullable + protected static PsiField getField(@Nullable PsiElement element) { + if (element == null || !(element instanceof PsiIdentifier)) { + return null; + } + + final PsiElement parent = element.getParent(); + if (parent == null || !(parent instanceof PsiReferenceExpression)) { + return null; + } + final PsiReferenceExpression ref = (PsiReferenceExpression)parent; + final PsiExpression qualifier = ref.getQualifierExpression(); + if (qualifier == null || qualifier instanceof PsiThisExpression) { + return null; + } + + final PsiElement resolved = ref.resolve(); + if (resolved == null || !(resolved instanceof PsiField)) { + return null; + } + return (PsiField)resolved; + } + + @Nullable + protected static PsiElement getElement(Editor editor, @NotNull PsiFile file) { + if (!file.getManager().isInProject(file)) return null; + final CaretModel caretModel = editor.getCaretModel(); + final int position = caretModel.getOffset(); + return file.findElementAt(position); + } +} \ No newline at end of file diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ExtractIfConditionAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ExtractIfConditionAction.java new file mode 100644 index 000000000000..4328e37054fb --- /dev/null +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ExtractIfConditionAction.java @@ -0,0 +1,253 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.intention.impl; + +import com.intellij.codeInsight.CodeInsightBundle; +import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.TextRange; +import com.intellij.psi.*; +import com.intellij.psi.codeStyle.CodeStyleManager; +import com.intellij.psi.tree.IElementType; +import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Danila Ponomarenko + */ +public class ExtractIfConditionAction extends PsiElementBaseIntentionAction { + @Override + public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { + final PsiIfStatement ifStatement = PsiTreeUtil.getParentOfType(element, PsiIfStatement.class); + if (ifStatement == null || ifStatement.getCondition() == null) { + return false; + } + + final PsiExpression condition = ifStatement.getCondition(); + + if (condition == null || !(condition instanceof PsiPolyadicExpression)) { + return false; + } + + final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)condition; + final PsiType expressionType = polyadicExpression.getType(); + if (expressionType == null || !PsiType.BOOLEAN.isAssignableFrom(expressionType)) { + return false; + } + + final IElementType operation = polyadicExpression.getOperationTokenType(); + + if (operation != JavaTokenType.OROR && operation != JavaTokenType.ANDAND) { + return false; + } + + final PsiExpression operand = findOperand(element, polyadicExpression); + + if (operand == null) { + return false; + } + setText(CodeInsightBundle.message("intention.extract.if.condition.text", operand.getText())); + return true; + } + + @Override + public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { + final PsiIfStatement ifStatement = PsiTreeUtil.getParentOfType(element, PsiIfStatement.class); + if (ifStatement == null) { + return; + } + + final PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory(); + final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project); + + final PsiStatement newIfStatement = create(factory, ifStatement, element); + if (newIfStatement == null) { + return; + } + + ifStatement.replace(codeStyleManager.reformat(newIfStatement)); + } + + @Nullable + private static PsiStatement create(@NotNull PsiElementFactory factory, + @NotNull PsiIfStatement ifStatement, + @NotNull PsiElement element) { + + final PsiExpression condition = ifStatement.getCondition(); + + if (condition == null || !(condition instanceof PsiPolyadicExpression)) { + return null; + } + + final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)condition; + + final PsiExpression operand = findOperand(element, polyadicExpression); + + if (operand == null) { + return null; + } + + + return create( + factory, + ifStatement.getThenBranch(), ifStatement.getElseBranch(), + operand, + removeOperand(factory, polyadicExpression, operand), + polyadicExpression.getOperationTokenType() + ); + } + + @NotNull + private static PsiExpression removeOperand(@NotNull PsiElementFactory factory, + @NotNull PsiPolyadicExpression expression, + @NotNull PsiExpression operand) { + final StringBuilder sb = new StringBuilder(); + for (PsiExpression e : expression.getOperands()) { + if (e == operand) continue; + final PsiJavaToken token = expression.getTokenBeforeOperand(e); + if (token != null && sb.length() != 0) { + sb.append(token.getText()).append(" "); + } + sb.append(e.getText()); + } + return factory.createExpressionFromText(sb.toString(), expression); + } + + @Nullable + private static PsiStatement create(@NotNull PsiElementFactory factory, + @Nullable PsiStatement thenBranch, + @Nullable PsiStatement elseBranch, + @NotNull PsiExpression extract, + @NotNull PsiExpression leave, + @NotNull IElementType operation) { + if (thenBranch == null) { + return null; + } + + if (operation == JavaTokenType.OROR) { + return createOrOr(factory, thenBranch, elseBranch, extract, leave); + } + if (operation == JavaTokenType.ANDAND) { + return createAndAnd(factory, thenBranch, elseBranch, extract, leave); + } + + return null; + } + + @NotNull + private static PsiStatement createAndAnd(@NotNull PsiElementFactory factory, + @NotNull PsiStatement thenBranch, + @Nullable PsiStatement elseBranch, + @NotNull PsiExpression extract, + @NotNull PsiExpression leave) { + + return factory.createStatementFromText( + createIfString(extract, + createIfString(leave, thenBranch, elseBranch), + elseBranch + ), + thenBranch + ); + } + + @NotNull + private static PsiStatement createOrOr(@NotNull PsiElementFactory factory, + @NotNull PsiStatement thenBranch, + @Nullable PsiStatement elseBranch, + @NotNull PsiExpression extract, + @NotNull PsiExpression leave) { + + return factory.createStatementFromText( + createIfString(extract, thenBranch, + createIfString(leave, thenBranch, elseBranch) + ), + thenBranch + ); + } + + @NotNull + private static String createIfString(@NotNull PsiExpression condition, + @NotNull PsiStatement thenBranch, + @Nullable PsiStatement elseBranch) { + return createIfString(condition.getText(), toThenBranchString(thenBranch), toElseBranchString(elseBranch)); + } + + @NotNull + private static String createIfString(@NotNull PsiExpression condition, + @NotNull PsiStatement thenBranch, + @Nullable String elseBranch) { + return createIfString(condition.getText(), toThenBranchString(thenBranch), elseBranch); + } + + @NotNull + private static String createIfString(@NotNull PsiExpression condition, + @NotNull String thenBranch, + @Nullable PsiStatement elseBranch) { + return createIfString(condition.getText(), thenBranch, toElseBranchString(elseBranch)); + } + + @NotNull + private static String createIfString(@NotNull String condition, + @NotNull String thenBranch, + @Nullable String elseBranch) { + final String elsePart = elseBranch != null ? " else " + elseBranch : ""; + return "if (" + condition + ")\n" + thenBranch + elsePart; + } + + @NotNull + private static String toThenBranchString(@NotNull PsiStatement statement) { + if (!(statement instanceof PsiBlockStatement)) { + return "{ " + statement.getText() + " }"; + } + + return statement.getText(); + } + + @Nullable + private static String toElseBranchString(@Nullable PsiStatement statement) { + if (statement == null) { + return null; + } + + if (statement instanceof PsiBlockStatement || statement instanceof PsiIfStatement) { + return statement.getText(); + } + + return "{ " + statement.getText() + " }"; + } + + @Nullable + private static PsiExpression findOperand(@NotNull PsiElement e, @NotNull PsiPolyadicExpression expression) { + final TextRange elementTextRange = e.getTextRange(); + + for (PsiExpression operand : expression.getOperands()) { + final TextRange operandTextRange = operand.getTextRange(); + if (operandTextRange != null && operandTextRange.contains(elementTextRange)) { + return operand; + } + } + return null; + } + + @NotNull + @Override + public String getFamilyName() { + return CodeInsightBundle.message("intention.extract.if.condition.family"); + } +} diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/IntroduceVariableAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/IntroduceVariableAction.java index c3244099a525..f629c1bfc21c 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/IntroduceVariableAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/IntroduceVariableAction.java @@ -16,14 +16,12 @@ package com.intellij.codeInsight.intention.impl; import com.intellij.codeInsight.CodeInsightBundle; -import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.openapi.editor.CaretModel; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.refactoring.JavaRefactoringActionHandlerFactory; -import com.intellij.refactoring.RefactoringActionHandler; +import com.intellij.refactoring.introduceVariable.IntroduceVariableHandler; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -31,7 +29,7 @@ import org.jetbrains.annotations.Nullable; /** * @author Danila Ponomarenko */ -public class IntroduceVariableAction implements IntentionAction { +public class IntroduceVariableAction extends BaseRunRefactoringAction { @NotNull @Override @@ -39,30 +37,30 @@ public class IntroduceVariableAction implements IntentionAction { return CodeInsightBundle.message("intention.introduce.variable.text"); } - @NotNull - @Override - public String getFamilyName() { - return getText(); - } - @Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { final PsiElement element = getElement(editor, file); if (element == null) { return false; } - final PsiStatement statement = PsiTreeUtil.getParentOfType(element, PsiStatement.class, false); - if (statement == null || !(statement instanceof PsiExpressionStatement)) { + final PsiExpression expression = getExpression(element); + if (expression == null || !(expression.getParent() instanceof PsiExpressionStatement)) { return false; } - final PsiExpressionStatement expressionStatement = (PsiExpressionStatement)statement; - final PsiExpression expression = expressionStatement.getExpression(); - return expression.getType() != PsiType.VOID && !(expression instanceof PsiAssignmentExpression); } + @Nullable + private static PsiExpression getExpression(@NotNull PsiElement element) { + PsiExpression expression = PsiTreeUtil.getParentOfType(element, PsiExpression.class, false); + while (expression != null && expression instanceof PsiReferenceExpression) { + expression = PsiTreeUtil.getParentOfType(expression, PsiExpression.class, true); + } + return expression; + } + @Nullable protected static PsiElement getElement(Editor editor, @NotNull PsiFile file) { if (!file.getManager().isInProject(file)) return null; @@ -73,12 +71,6 @@ public class IntroduceVariableAction implements IntentionAction { @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { - final RefactoringActionHandler refactoringActionHandler = JavaRefactoringActionHandlerFactory.getInstance().createIntroduceVariableHandler(); - refactoringActionHandler.invoke(project, editor, file, null); - } - - @Override - public boolean startInWriteAction() { - return true; + new IntroduceVariableHandler().invoke(project, editor, file, null); } } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RunRefactoringIntention.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/RunRefactoringAction.java similarity index 59% rename from java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RunRefactoringIntention.java rename to java/java-impl/src/com/intellij/codeInsight/intention/impl/RunRefactoringAction.java index f053a18527b7..6462dbe404b9 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RunRefactoringIntention.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/RunRefactoringAction.java @@ -13,31 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.codeInsight.daemon.impl.quickfix; +package com.intellij.codeInsight.intention.impl; -import com.intellij.codeInsight.intention.IntentionAction; -import com.intellij.codeInsight.intention.LowPriorityAction; -import com.intellij.icons.AllIcons; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Iconable; import com.intellij.psi.PsiFile; import com.intellij.refactoring.RefactoringActionHandler; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; -import javax.swing.*; - /** * User: anna * Date: 9/5/11 */ -public class RunRefactoringIntention implements IntentionAction, Iconable, LowPriorityAction { - public static final Icon REFACTORING_BULB = AllIcons.Actions.RefactoringBulb; +public class RunRefactoringAction extends BaseRunRefactoringAction { private final RefactoringActionHandler myHandler; private final String myCommandName; - public RunRefactoringIntention(RefactoringActionHandler handler, String commandName) { + public RunRefactoringAction(RefactoringActionHandler handler, String commandName) { myHandler = handler; myCommandName = commandName; } @@ -48,29 +41,13 @@ public class RunRefactoringIntention implements IntentionAction, Iconable, LowPr return myCommandName; } - @NotNull - @Override - public String getFamilyName() { - return "Refactorings"; - } - @Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { return true; } @Override - public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { + public final void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { myHandler.invoke(project, editor, file, null); } - - @Override - public boolean startInWriteAction() { - return false; - } - - @Override - public Icon getIcon(int flags) { - return REFACTORING_BULB; - } } diff --git a/java/java-impl/src/com/intellij/codeInsight/unwrap/JavaMethodParameterUnwrapper.java b/java/java-impl/src/com/intellij/codeInsight/unwrap/JavaMethodParameterUnwrapper.java index 42704f238231..c0b79edc33cb 100644 --- a/java/java-impl/src/com/intellij/codeInsight/unwrap/JavaMethodParameterUnwrapper.java +++ b/java/java-impl/src/com/intellij/codeInsight/unwrap/JavaMethodParameterUnwrapper.java @@ -32,7 +32,7 @@ public class JavaMethodParameterUnwrapper extends JavaUnwrapper { public String getDescription(PsiElement e) { String text = e.getText(); if (text.length() > 20) text = text.substring(0, 17) + "..."; - return CodeInsightBundle.message("unwrap.method.parameter", text); + return CodeInsightBundle.message("unwrap.with.placeholder", text); } public boolean isApplicableTo(PsiElement e) { diff --git a/java/java-impl/src/com/intellij/codeInsight/unwrap/JavaPolyadicExpressionUnwrapper.java b/java/java-impl/src/com/intellij/codeInsight/unwrap/JavaPolyadicExpressionUnwrapper.java new file mode 100644 index 000000000000..1fa629365025 --- /dev/null +++ b/java/java-impl/src/com/intellij/codeInsight/unwrap/JavaPolyadicExpressionUnwrapper.java @@ -0,0 +1,79 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.unwrap; + +import com.intellij.codeInsight.CodeInsightBundle; +import com.intellij.openapi.util.TextRange; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiExpression; +import com.intellij.psi.PsiPolyadicExpression; +import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Danila Ponomarenko + */ +public class JavaPolyadicExpressionUnwrapper extends JavaUnwrapper { + public JavaPolyadicExpressionUnwrapper() { + super(""); + } + + @Override + public String getDescription(PsiElement e) { + return CodeInsightBundle.message("unwrap.with.placeholder", e.getText()); + } + + @Override + public boolean isApplicableTo(PsiElement e) { + if (!(e.getParent() instanceof PsiPolyadicExpression)) { + return false; + } + + final PsiPolyadicExpression expression = (PsiPolyadicExpression)e.getParent(); + + final PsiExpression operand = findOperand(e, expression); + + return operand != null; + } + + @Override + protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException { + final PsiPolyadicExpression parent = (PsiPolyadicExpression)element.getParent(); + + final PsiExpression operand = findOperand(element, parent); + + if (operand == null) { + return; + } + + context.extractElement(operand, parent); + context.delete(parent); + } + + @Nullable + private static PsiExpression findOperand(@NotNull PsiElement e, @NotNull PsiPolyadicExpression expression) { + final TextRange elementTextRange = e.getTextRange(); + + for (PsiExpression operand : expression.getOperands()) { + final TextRange operandTextRange = operand.getTextRange(); + if (operandTextRange != null && operandTextRange.contains(elementTextRange)) { + return operand; + } + } + return null; + } +} diff --git a/java/java-impl/src/com/intellij/codeInsight/unwrap/JavaUnwrapDescriptor.java b/java/java-impl/src/com/intellij/codeInsight/unwrap/JavaUnwrapDescriptor.java index 7a5a48883908..ead2eff79ade 100644 --- a/java/java-impl/src/com/intellij/codeInsight/unwrap/JavaUnwrapDescriptor.java +++ b/java/java-impl/src/com/intellij/codeInsight/unwrap/JavaUnwrapDescriptor.java @@ -32,7 +32,8 @@ public class JavaUnwrapDescriptor extends UnwrapDescriptorBase { new JavaCatchRemover(), new JavaSynchronizedUnwrapper(), new JavaAnonymousUnwrapper(), - new JavaConditionalUnwrapper() + new JavaConditionalUnwrapper(), + new JavaPolyadicExpressionUnwrapper() }; } } diff --git a/java/java-impl/src/com/intellij/psi/impl/PsiDiamondTypeUtil.java b/java/java-impl/src/com/intellij/psi/impl/PsiDiamondTypeUtil.java index 502055854d22..c5037ac91c3f 100644 --- a/java/java-impl/src/com/intellij/psi/impl/PsiDiamondTypeUtil.java +++ b/java/java-impl/src/com/intellij/psi/impl/PsiDiamondTypeUtil.java @@ -40,6 +40,18 @@ public class PsiDiamondTypeUtil { public static boolean canCollapseToDiamond(final PsiNewExpression expression, final PsiNewExpression context, final @Nullable PsiType expectedType) { + return canCollapseToDiamond(expression, context, expectedType, false); + } + + public static boolean canChangeContextForDiamond(final PsiNewExpression expression, final PsiType expectedType) { + final PsiNewExpression copy = (PsiNewExpression)expression.copy(); + return canCollapseToDiamond(copy, copy, expectedType, true); + } + + private static boolean canCollapseToDiamond(final PsiNewExpression expression, + final PsiNewExpression context, + final @Nullable PsiType expectedType, + boolean skipDiamonds) { if (PsiUtil.getLanguageLevel(context).isAtLeast(LanguageLevel.JDK_1_7)) { final PsiJavaCodeReferenceElement classReference = expression.getClassOrAnonymousClassReference(); if (classReference != null) { @@ -47,7 +59,7 @@ public class PsiDiamondTypeUtil { if (parameterList != null) { final PsiTypeElement[] typeElements = parameterList.getTypeParameterElements(); if (typeElements.length > 0) { - if (typeElements.length == 1 && typeElements[0].getType() instanceof PsiDiamondType) return false; + if (!skipDiamonds && typeElements.length == 1 && typeElements[0].getType() instanceof PsiDiamondType) return false; final PsiDiamondTypeImpl.DiamondInferenceResult inferenceResult = PsiDiamondTypeImpl.resolveInferredTypes(expression, context); if (inferenceResult.getErrorMessage() == null) { final List types = inferenceResult.getInferredTypes(); diff --git a/java/java-impl/src/com/intellij/psi/impl/beanProperties/BeanProperty.java b/java/java-impl/src/com/intellij/psi/impl/beanProperties/BeanProperty.java index 1fd0d8e03a8d..3c5fd4d6e88e 100644 --- a/java/java-impl/src/com/intellij/psi/impl/beanProperties/BeanProperty.java +++ b/java/java-impl/src/com/intellij/psi/impl/beanProperties/BeanProperty.java @@ -28,6 +28,9 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; +/** + * Provide {@link com.intellij.refactoring.rename.BeanPropertyRenameHandler} if necessary. + */ @Presentation(icon = "AllIcons.Nodes.Property") public class BeanProperty { @@ -104,5 +107,4 @@ public class BeanProperty { public static BeanProperty createBeanProperty(@NotNull PsiMethod method) { return PropertyUtil.isSimplePropertyAccessor(method) ? new BeanProperty(method) : null; } - } diff --git a/java/java-impl/src/com/intellij/psi/impl/light/LightParameter.java b/java/java-impl/src/com/intellij/psi/impl/light/LightParameter.java index b78e9cd0e11e..611992bd2914 100644 --- a/java/java-impl/src/com/intellij/psi/impl/light/LightParameter.java +++ b/java/java-impl/src/com/intellij/psi/impl/light/LightParameter.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.psi.impl.light; import com.intellij.lang.Language; @@ -9,6 +24,7 @@ import org.jetbrains.annotations.NotNull; */ public class LightParameter extends LightVariableBuilder implements PsiParameter { public static final LightParameter[] EMPTY_ARRAY = new LightParameter[0]; + private final String myName; private final PsiElement myDeclarationScope; private final boolean myVarArgs; @@ -46,16 +62,9 @@ public class LightParameter extends LightVariableBuilder i return myVarArgs; } - @Override - @NotNull - public PsiAnnotation[] getAnnotations() { - return PsiAnnotation.EMPTY_ARRAY; - } - @Override @NotNull public String getName() { return myName; } - } diff --git a/java/java-impl/src/com/intellij/psi/impl/smartPointers/SmartTypePointerManagerImpl.java b/java/java-impl/src/com/intellij/psi/impl/smartPointers/SmartTypePointerManagerImpl.java index 175b3a143b4a..5d86dc4ec0a0 100644 --- a/java/java-impl/src/com/intellij/psi/impl/smartPointers/SmartTypePointerManagerImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/smartPointers/SmartTypePointerManagerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,6 +42,11 @@ import java.util.Set; public class SmartTypePointerManagerImpl extends SmartTypePointerManager { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.smartPointers.SmartTypePointerManagerImpl"); + private static final SmartTypePointer NULL_POINTER = new SmartTypePointer() { + @Override + public PsiType getType() { return null; } + }; + private final SmartPointerManager myPsiPointerManager; private final Project myProject; @@ -53,7 +58,8 @@ public class SmartTypePointerManagerImpl extends SmartTypePointerManager { @Override @NotNull public SmartTypePointer createSmartTypePointer(@NotNull PsiType type) { - return type.accept(new SmartTypeCreatingVisitor()); + final SmartTypePointer pointer = type.accept(new SmartTypeCreatingVisitor()); + return pointer != null ? pointer : NULL_POINTER; } private static class SimpleTypePointer implements SmartTypePointer { @@ -77,6 +83,7 @@ public class SmartTypePointerManagerImpl extends SmartTypePointerManager { myComponentTypePointer = componentTypePointer; } + @Nullable @Override protected PsiArrayType calcType() { final PsiType type = myComponentTypePointer.getType(); @@ -164,6 +171,7 @@ public class SmartTypePointerManagerImpl extends SmartTypePointerManager { return myType; } + @Nullable protected abstract T calcType(); } @@ -228,7 +236,8 @@ public class SmartTypePointerManagerImpl extends SmartTypePointerManager { @Override public SmartTypePointer visitArrayType(PsiArrayType arrayType) { - return new ArrayTypePointer(arrayType, arrayType.getComponentType().accept(this)); + final SmartTypePointer componentTypePointer = arrayType.getComponentType().accept(this); + return componentTypePointer != null ? new ArrayTypePointer(arrayType, componentTypePointer) : null; } @Override diff --git a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/JavaCodeStyleManagerImpl.java b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/JavaCodeStyleManagerImpl.java index 55d19be86fc5..5047b0f7c4e2 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/JavaCodeStyleManagerImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/JavaCodeStyleManagerImpl.java @@ -245,7 +245,7 @@ public class JavaCodeStyleManagerImpl extends JavaCodeStyleManager { final PsiType _type = type; return new SuggestedNameInfo(namesArray) { @Override - public void nameChoosen(String name) { + public void nameChosen(String name) { if (_propertyName != null || _type != null && _type.isValid()) { JavaStatisticsManager.incVariableNameUseCount(name, kind, _propertyName, _type); } @@ -862,8 +862,8 @@ public class JavaCodeStyleManagerImpl extends JavaCodeStyleManager { return new SuggestedNameInfo(ArrayUtil.toStringArray(uniqueNames)) { @Override - public void nameChoosen(String name) { - baseNameInfo.nameChoosen(name); + public void nameChosen(String name) { + baseNameInfo.nameChosen(name); } }; } diff --git a/java/java-impl/src/com/intellij/refactoring/anonymousToInner/AnonymousToInnerHandler.java b/java/java-impl/src/com/intellij/refactoring/anonymousToInner/AnonymousToInnerHandler.java index f53f8523253b..5ae7c8613e07 100644 --- a/java/java-impl/src/com/intellij/refactoring/anonymousToInner/AnonymousToInnerHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/anonymousToInner/AnonymousToInnerHandler.java @@ -26,6 +26,7 @@ import com.intellij.openapi.editor.ScrollType; import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleManager; +import com.intellij.psi.impl.PsiDiamondTypeUtil; import com.intellij.psi.search.LocalSearchScope; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PsiTreeUtil; @@ -184,8 +185,12 @@ public class AnonymousToInnerHandler implements RefactoringActionHandler { } } buf.append(")"); - PsiExpression newClassExpression = JavaPsiFacade.getInstance(myManager.getProject()).getElementFactory().createExpressionFromText(buf.toString(), null); - newExpr.replace(newClassExpression); + PsiNewExpression newClassExpression = + (PsiNewExpression)JavaPsiFacade.getInstance(myManager.getProject()).getElementFactory().createExpressionFromText(buf.toString(), null); + newClassExpression = (PsiNewExpression)newExpr.replace(newClassExpression); + if (PsiDiamondTypeUtil.canCollapseToDiamond(newClassExpression, newClassExpression, newClassExpression.getType())) { + PsiDiamondTypeUtil.replaceExplicitWithDiamond(newClassExpression.getClassOrAnonymousClassReference().getParameterList()); + } } @Nullable @@ -240,7 +245,7 @@ public class AnonymousToInnerHandler implements RefactoringActionHandler { } private Boolean cachedNeedsThis = null; - private boolean needsThis() { + public boolean needsThis() { if(cachedNeedsThis == null) { ElementNeedsThis memberNeedsThis = new ElementNeedsThis(myTargetClass, myAnonClass); diff --git a/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureUsageProcessor.java b/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureUsageProcessor.java index 2d99c94337d0..a5ead200d950 100644 --- a/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureUsageProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureUsageProcessor.java @@ -741,8 +741,13 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr final JavaParameterInfo[] primaryNewParms = changeInfo.getNewParameters(); PsiSubstitutor substitutor = baseMethod == null ? PsiSubstitutor.EMPTY : ChangeSignatureProcessor.calculateSubstitutor(caller, baseMethod); + final PsiClass aClass = changeInfo.getMethod().getContainingClass(); + final PsiClass callerContainingClass = caller.getContainingClass(); + final PsiSubstitutor psiSubstitutor = aClass != null && callerContainingClass != null && callerContainingClass.isInheritor(aClass, true) + ? TypeConversionUtil.getSuperClassSubstitutor(aClass, callerContainingClass, substitutor) + : PsiSubstitutor.EMPTY; for (JavaParameterInfo info : primaryNewParms) { - if (info.getOldIndex() < 0) newParameters.add(createNewParameter(changeInfo, info, substitutor)); + if (info.getOldIndex() < 0) newParameters.add(createNewParameter(changeInfo, info, psiSubstitutor, substitutor)); } PsiParameter[] arrayed = newParameters.toArray(new PsiParameter[newParameters.size()]); boolean[] toRemoveParm = new boolean[arrayed.length]; @@ -802,10 +807,13 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr } private static PsiParameter createNewParameter(JavaChangeInfo changeInfo, JavaParameterInfo newParm, - PsiSubstitutor substitutor) throws IncorrectOperationException { + PsiSubstitutor... substitutor) throws IncorrectOperationException { final PsiParameterList list = changeInfo.getMethod().getParameterList(); final PsiElementFactory factory = JavaPsiFacade.getInstance(list.getProject()).getElementFactory(); - final PsiType type = substitutor.substitute(newParm.createType(list, list.getManager())); + PsiType type = newParm.createType(list, list.getManager()); + for (PsiSubstitutor psiSubstitutor : substitutor) { + type = psiSubstitutor.substitute(type); + } return factory.createParameter(newParm.getName(), type); } diff --git a/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureUsageSearcher.java b/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureUsageSearcher.java index 46ca81d384f7..80fd509f233e 100644 --- a/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureUsageSearcher.java +++ b/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureUsageSearcher.java @@ -116,7 +116,8 @@ class JavaChangeSignatureUsageSearcher { final int oldParameterIndex = parameterInfo.getOldIndex(); final String newName = parameterInfo.getName(); if (oldParameterIndex >= 0 ) { - if (isOriginal&& oldParameterIndex < parameters.length) { //Name changes take place only in primary method + if (isOriginal && oldParameterIndex < parameters.length && !newName.equals(myChangeInfo.getOldParameterNames()[oldParameterIndex])) { + //Name changes take place only in primary method when name was actually changed final PsiParameter parameter = parameters[oldParameterIndex]; if (!newName.equals(parameter.getName())) { JavaUnresolvableLocalCollisionDetector.visitLocalsCollisions( diff --git a/java/java-impl/src/com/intellij/refactoring/convertToInstanceMethod/ConvertToInstanceMethodDialog.java b/java/java-impl/src/com/intellij/refactoring/convertToInstanceMethod/ConvertToInstanceMethodDialog.java index df96bfd2a8c8..be2b088dd6b4 100644 --- a/java/java-impl/src/com/intellij/refactoring/convertToInstanceMethod/ConvertToInstanceMethodDialog.java +++ b/java/java-impl/src/com/intellij/refactoring/convertToInstanceMethod/ConvertToInstanceMethodDialog.java @@ -23,12 +23,11 @@ import com.intellij.psi.PsiVariable; import com.intellij.refactoring.HelpID; import com.intellij.refactoring.RefactoringBundle; import com.intellij.refactoring.move.moveInstanceMethod.MoveInstanceMethodDialogBase; +import com.intellij.ui.DoubleClickListener; import com.intellij.util.ui.UIUtil; import javax.swing.*; -import javax.swing.border.LineBorder; import java.awt.*; -import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; /** @@ -66,16 +65,17 @@ public class ConvertToInstanceMethodDialog extends MoveInstanceMethodDialogBase @Override protected JList createTargetVariableChooser() { final JList variableChooser = super.createTargetVariableChooser(); - variableChooser.addMouseListener(new MouseAdapter() { - public void mouseClicked(MouseEvent e) { - if (e.getClickCount() != 2) return; + new DoubleClickListener() { + @Override + protected boolean onDoubleClick(MouseEvent e) { Point point = e.getPoint(); int index = variableChooser.locationToIndex(point); - if (index == -1) return; - if (!variableChooser.getCellBounds(index, index).contains(point)) return; + if (index == -1) return false; + if (!variableChooser.getCellBounds(index, index).contains(point)) return false; doRefactorAction(); + return true; } - }); + }.installOn(variableChooser); return variableChooser; } } diff --git a/java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java b/java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java index aae30f20540f..ff4bc6f5b392 100644 --- a/java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java @@ -138,10 +138,14 @@ public class CopyClassesHandler extends CopyHandlerDelegateBase { private static void fillResultsMap(Map result, PsiFile containingFile, PsiClass[] topLevelClasses) { PsiClass[] classes = result.get(containingFile); - if (classes != null) { - topLevelClasses = ArrayUtil.mergeArrays(classes, topLevelClasses, PsiClass.ARRAY_FACTORY); + if (topLevelClasses != null) { + if (classes != null) { + topLevelClasses = ArrayUtil.mergeArrays(classes, topLevelClasses, PsiClass.ARRAY_FACTORY); + } + result.put(containingFile, topLevelClasses); + } else { + result.put(containingFile, classes); } - result.put(containingFile, topLevelClasses); } public void doCopy(PsiElement[] elements, PsiDirectory defaultTargetDirectory) { diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodHandler.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodHandler.java index e56b93ec3f5b..7aef0d8214f1 100644 --- a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodHandler.java @@ -22,6 +22,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.ReadonlyStatusHandler; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.refactoring.HelpID; import com.intellij.refactoring.RefactoringBundle; import com.intellij.refactoring.util.CommonRefactoringUtil; @@ -87,10 +88,14 @@ class InlineMethodHandler extends JavaInlineActionHandler { CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.INLINE_CONSTRUCTOR); return; } - if (!isChainingConstructor(method)) { - String message = RefactoringBundle.message("refactoring.cannot.be.applied.to.inline.non.chaining.constructors", REFACTORING_NAME); - CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.INLINE_CONSTRUCTOR); - return; + final boolean chainingConstructor = isChainingConstructor(method); + if (!chainingConstructor) { + if (!isThisReference(reference)) { + String message = RefactoringBundle.message("refactoring.cannot.be.applied.to.inline.non.chaining.constructors", REFACTORING_NAME); + CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.INLINE_CONSTRUCTOR); + return; + } + allowInlineThisOnly = true; } if (reference != null) { final PsiElement refElement = reference.getElement(); @@ -148,4 +153,16 @@ class InlineMethodHandler extends JavaInlineActionHandler { return false; } + + public static boolean isThisReference(PsiReference reference) { + if (reference != null) { + final PsiElement referenceElement = reference.getElement(); + if (referenceElement instanceof PsiJavaCodeReferenceElement && + referenceElement.getParent() instanceof PsiMethodCallExpression && + "this".equals(((PsiJavaCodeReferenceElement)referenceElement).getReferenceName())) { + return true; + } + } + return false; + } } \ No newline at end of file diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java index 8dd9acaed0dc..a64a4cc75298 100644 --- a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java @@ -323,7 +323,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor { private void doRefactoring(UsageInfo[] usages) { try { if (myInlineThisOnly) { - if (myMethod.isConstructor()) { + if (myMethod.isConstructor() && InlineMethodHandler.isChainingConstructor(myMethod)) { PsiCall constructorCall = RefactoringUtil.getEnclosingConstructorCall(myReference); if (constructorCall != null) { inlineConstructorCall(constructorCall); diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineToAnonymousClassHandler.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineToAnonymousClassHandler.java index 3f5442e637e7..00501d5d6b49 100644 --- a/java/java-impl/src/com/intellij/refactoring/inline/InlineToAnonymousClassHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineToAnonymousClassHandler.java @@ -83,8 +83,13 @@ public class InlineToAnonymousClassHandler extends JavaInlineActionHandler { return inheritors.size() == 0; } - public boolean canInlineElementInEditor(PsiElement element) { - return canInlineElement(element); + @Override + public boolean canInlineElementInEditor(PsiElement element, Editor editor) { + if (canInlineElement(element)) { + PsiReference reference = editor != null ? TargetElementUtilBase.findReference(editor, editor.getCaretModel().getOffset()) : null; + return !InlineMethodHandler.isThisReference(reference); + } + return false; } public void inlineElement(final Project project, final Editor editor, final PsiElement psiElement) { diff --git a/java/java-impl/src/com/intellij/refactoring/inlineSuperClass/InlineSuperClassRefactoringProcessor.java b/java/java-impl/src/com/intellij/refactoring/inlineSuperClass/InlineSuperClassRefactoringProcessor.java index c98e6b8da9d4..453dc14687dd 100644 --- a/java/java-impl/src/com/intellij/refactoring/inlineSuperClass/InlineSuperClassRefactoringProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/inlineSuperClass/InlineSuperClassRefactoringProcessor.java @@ -221,7 +221,7 @@ public class InlineSuperClassRefactoringProcessor extends FixableUsagesRefactori super.performRefactoring(pushDownUsages); RefactoringUtil.sortDepthFirstRightLeftOrder(usages); for (UsageInfo usageInfo : usages) { - if (!(usageInfo instanceof ReplaceExtendsListUsageInfo)) { + if (!(usageInfo instanceof ReplaceExtendsListUsageInfo || usageInfo instanceof RemoveImportUsageInfo)) { try { ((FixableUsageInfo)usageInfo).fixUsage(); } @@ -234,8 +234,8 @@ public class InlineSuperClassRefactoringProcessor extends FixableUsagesRefactori //postpone broken hierarchy for (UsageInfo usage : usages) { - if (usage instanceof ReplaceExtendsListUsageInfo) { - ((ReplaceExtendsListUsageInfo)usage).fixUsage(); + if (usage instanceof ReplaceExtendsListUsageInfo || usage instanceof RemoveImportUsageInfo) { + ((FixableUsageInfo)usage).fixUsage(); } } try { diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/JavaIntroduceParameterMethodUsagesProcessor.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/JavaIntroduceParameterMethodUsagesProcessor.java index 827540c785a4..3f16cfb1e0eb 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/JavaIntroduceParameterMethodUsagesProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/JavaIntroduceParameterMethodUsagesProcessor.java @@ -94,7 +94,9 @@ public class JavaIntroduceParameterMethodUsagesProcessor implements IntroducePar ExpressionConverter.getExpression(data.getParameterInitializer().getExpression(), StdLanguages.JAVA, data.getProject()); assert initializer instanceof PsiExpression; if (initializer instanceof PsiNewExpression) { - initializer = PsiDiamondTypeUtil.expandTopLevelDiamondsInside((PsiNewExpression)initializer); + if (!PsiDiamondTypeUtil.canChangeContextForDiamond((PsiNewExpression)initializer, ((PsiNewExpression)initializer).getType())) { + initializer = PsiDiamondTypeUtil.expandTopLevelDiamondsInside((PsiNewExpression)initializer); + } } substituteTypeParametersInInitializer(initializer, callExpression, argList, methodToSearchFor); ChangeContextUtil.encodeContextInfo(initializer, true); diff --git a/java/java-impl/src/com/intellij/refactoring/memberPullUp/PullUpHelper.java b/java/java-impl/src/com/intellij/refactoring/memberPullUp/PullUpHelper.java index aa7f8d617d00..71305101c8d1 100644 --- a/java/java-impl/src/com/intellij/refactoring/memberPullUp/PullUpHelper.java +++ b/java/java-impl/src/com/intellij/refactoring/memberPullUp/PullUpHelper.java @@ -33,8 +33,10 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.Ref; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleSettings; @@ -62,6 +64,7 @@ import com.intellij.util.IncorrectOperationException; import com.intellij.util.Query; import com.intellij.util.VisibilityUtil; import com.intellij.util.containers.HashMap; +import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -148,7 +151,7 @@ public class PullUpHelper extends BaseRefactoringProcessor{ final Set methodsToSearchDuplicates = new HashSet(); for (PsiMember psiMember : myMembersAfterMove) { if (psiMember instanceof PsiMethod && ((PsiMethod)psiMember).getBody() != null) { - methodsToSearchDuplicates.add((PsiMethod)psiMember); + methodsToSearchDuplicates.add(psiMember); } } @@ -289,7 +292,7 @@ public class PullUpHelper extends BaseRefactoringProcessor{ PsiJavaCodeReferenceElement ref = mySourceClass.equals(sourceReferenceList.getParent()) ? RefactoringUtil.removeFromReferenceList(sourceReferenceList, aClass) : RefactoringUtil.findReferenceToClass(sourceReferenceList, aClass); - if (ref != null) { + if (ref != null && !myTargetSuperClass.isInheritor(aClass, false)) { RefactoringUtil.replaceMovedMemberTypeParameters(ref, PsiUtil.typeParametersIterable(mySourceClass), substitutor, elementFactory); final PsiReferenceList referenceList = myTargetSuperClass.isInterface() ? myTargetSuperClass.getExtendsList() : myTargetSuperClass.getImplementsList(); diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerDialog.java b/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerDialog.java index c2e1399893ab..1d4afb77e665 100644 --- a/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerDialog.java +++ b/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -288,7 +288,7 @@ public class MoveInnerDialog extends RefactoringDialog { JavaRefactoringSettings.getInstance().MOVE_INNER_PREVIEW_USAGES = isPreviewUsages(); if (myCbPassOuterClass.isSelected() && mySuggestedNameInfo != null) { - mySuggestedNameInfo.nameChoosen(getParameterName()); + mySuggestedNameInfo.nameChosen(getParameterName()); } final PsiElement target = getTargetContainer(); diff --git a/java/java-impl/src/com/intellij/refactoring/rename/BeanPropertyRenameHandler.java b/java/java-impl/src/com/intellij/refactoring/rename/BeanPropertyRenameHandler.java index 0b6366742815..4c41a438cffc 100644 --- a/java/java-impl/src/com/intellij/refactoring/rename/BeanPropertyRenameHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/rename/BeanPropertyRenameHandler.java @@ -44,12 +44,16 @@ public abstract class BeanPropertyRenameHandler implements RenameHandler { } public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) { - final BeanProperty property = getProperty(dataContext); - new PropertyRenameDialog(property, editor).show(); + performInvoke(editor, dataContext); } public void invoke(@NotNull Project project, @NotNull PsiElement[] elements, DataContext dataContext) { + performInvoke(null, dataContext); + } + private void performInvoke(@Nullable Editor editor, DataContext dataContext) { + final BeanProperty property = getProperty(dataContext); + new PropertyRenameDialog(property, editor).show(); } public static void doRename(@NotNull final BeanProperty property, final String newName, final boolean searchInComments) { @@ -89,6 +93,5 @@ public abstract class BeanPropertyRenameHandler implements RenameHandler { doRename(myProperty, newName, searchInComments); close(DialogWrapper.OK_EXIT_CODE); } - } } diff --git a/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaClassProcessor.java b/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaClassProcessor.java index 9069c92bf963..d98870a493f6 100644 --- a/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaClassProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/rename/RenameJavaClassProcessor.java @@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Pair; import com.intellij.psi.*; +import com.intellij.psi.impl.light.LightElement; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.LocalSearchScope; import com.intellij.psi.search.SearchScope; @@ -134,10 +135,11 @@ public class RenameJavaClassProcessor extends RenamePsiElementProcessor { final PsiElement prototype = ((PsiMirrorElement)constructor).getPrototype(); if (prototype instanceof PsiNamedElement) { allRenames.put(prototype, newName); - continue; } } - allRenames.put(constructor, newName); + else if (!(constructor instanceof LightElement)) { + allRenames.put(constructor, newName); + } } } diff --git a/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeEvaluator.java b/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeEvaluator.java index 7b12bc349967..67e643841567 100644 --- a/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeEvaluator.java +++ b/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeEvaluator.java @@ -200,8 +200,7 @@ public class TypeEvaluator { return elseType; case 3: - LOG.error("Condition type conflict."); - return null; + return expr.getType(); default: LOG.error("Must not happen."); diff --git a/java/java-impl/src/com/intellij/refactoring/ui/NameSuggestionsManager.java b/java/java-impl/src/com/intellij/refactoring/ui/NameSuggestionsManager.java index dd3673b0e1cf..95377dccfa91 100644 --- a/java/java-impl/src/com/intellij/refactoring/ui/NameSuggestionsManager.java +++ b/java/java-impl/src/com/intellij/refactoring/ui/NameSuggestionsManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,7 +53,7 @@ public class NameSuggestionsManager { SuggestedNameInfo nameInfo = myTypesToSuggestions.get(myTypeSelector.getSelectedType()); if (nameInfo != null) { - nameInfo.nameChoosen(myNameField.getEnteredName()); + nameInfo.nameChosen(myNameField.getEnteredName()); } } diff --git a/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java b/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java index 2eda3ad6425f..1da9d5095981 100644 --- a/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java +++ b/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java @@ -175,7 +175,11 @@ public class RefactoringUtil { public int compare(final UsageInfo usage1, final UsageInfo usage2) { final PsiElement element1 = usage1.getElement(); final PsiElement element2 = usage2.getElement(); - if (element1 == null || element2 == null) return 0; + if (element1 == null) { + if (element2 == null) return 0; + return 1; + } + if (element2 == null) return -1; return element2.getTextRange().getStartOffset() - element1.getTextRange().getStartOffset(); } }); @@ -1200,13 +1204,13 @@ public class RefactoringUtil { } @Nullable - public static PsiTypeParameterList createTypeParameterListWithUsedTypeParameters(final PsiTypeParameterList fromList, + public static PsiTypeParameterList createTypeParameterListWithUsedTypeParameters(@Nullable final PsiTypeParameterList fromList, @NotNull final PsiElement... elements) { return createTypeParameterListWithUsedTypeParameters(fromList, Condition.TRUE, elements); } @Nullable - public static PsiTypeParameterList createTypeParameterListWithUsedTypeParameters(final PsiTypeParameterList fromList, + public static PsiTypeParameterList createTypeParameterListWithUsedTypeParameters(@Nullable final PsiTypeParameterList fromList, Condition filter, @NotNull final PsiElement... elements) { if (elements.length == 0) return null; diff --git a/java/java-impl/src/com/intellij/refactoring/util/classMembers/ElementNeedsThis.java b/java/java-impl/src/com/intellij/refactoring/util/classMembers/ElementNeedsThis.java index 97a898a3cf0b..9531eccdace8 100644 --- a/java/java-impl/src/com/intellij/refactoring/util/classMembers/ElementNeedsThis.java +++ b/java/java-impl/src/com/intellij/refactoring/util/classMembers/ElementNeedsThis.java @@ -41,9 +41,14 @@ public class ElementNeedsThis extends ClassThisReferencesVisitor { if (classMember == null || classMember.equals(myMember)) return; if (classMember.hasModifierProperty(PsiModifier.STATIC)) return; + if (ignoreUsedTypeParams() && classMember instanceof PsiTypeParameter) return; myResult = true; } + protected boolean ignoreUsedTypeParams() { + return myMember != null; + } + protected void visitExplicitThis(PsiClass referencedClass, PsiThisExpression reference) { myResult = true; } diff --git a/java/java-impl/src/com/intellij/testIntegration/createTest/CreateTestDialog.java b/java/java-impl/src/com/intellij/testIntegration/createTest/CreateTestDialog.java index 3b38008516db..573a8c7dba60 100644 --- a/java/java-impl/src/com/intellij/testIntegration/createTest/CreateTestDialog.java +++ b/java/java-impl/src/com/intellij/testIntegration/createTest/CreateTestDialog.java @@ -69,6 +69,7 @@ import java.util.List; public class CreateTestDialog extends DialogWrapper { private static final String RECENTS_KEY = "CreateTestDialog.RecentsKey"; + private static final String RECENT_SUPERS_KEY = "CreateTestDialog.Recents.Supers"; private static final String DEFAULT_LIBRARY_NAME_PROPERTY = CreateTestDialog.class.getName() + ".defaultLibrary"; private static final String SHOW_INHERITED_MEMBERS_PROPERTY = CreateTestDialog.class.getName() + ".includeInheritedMembers"; @@ -81,7 +82,7 @@ public class CreateTestDialog extends DialogWrapper { private final List myLibraryButtons = new ArrayList(); private EditorTextField myTargetClassNameField; - private ReferenceEditorWithBrowseButton mySuperClassField; + private ReferenceEditorComboWithBrowseButton mySuperClassField; private ReferenceEditorComboWithBrowseButton myTargetPackageField; private JCheckBox myGenerateBeforeBox; private JCheckBox myGenerateAfterBox; @@ -176,7 +177,8 @@ public class CreateTestDialog extends DialogWrapper { } }); - mySuperClassField = JavaReferenceEditorUtil.createReferenceEditorWithBrowseButton(new MyChooseSuperClassAction(), "", myProject, true); + mySuperClassField = new ReferenceEditorComboWithBrowseButton(new MyChooseSuperClassAction(), null, myProject, true, + JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE, RECENT_SUPERS_KEY); mySuperClassField.setMinimumSize(mySuperClassField.getPreferredSize()); String targetPackageName = targetPackage != null ? targetPackage.getQualifiedName() : ""; @@ -209,7 +211,7 @@ public class CreateTestDialog extends DialogWrapper { myFixLibraryPanel.setVisible(!descriptor.isLibraryAttached(myTargetModule)); String superClass = descriptor.getDefaultSuperClass(); - mySuperClassField.setText(superClass == null ? "" : superClass); + mySuperClassField.appendItem(superClass == null ? "" : superClass); mySelectedFramework = descriptor; } @@ -416,6 +418,7 @@ public class CreateTestDialog extends DialogWrapper { protected void doOKAction() { RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, myTargetPackageField.getText()); + RecentsManager.getInstance(myProject).registerRecentEntry(RECENT_SUPERS_KEY, mySuperClassField.getText()); String errorMessage; try { diff --git a/java/java-impl/src/com/intellij/ui/ReferenceEditorComboWithBrowseButton.java b/java/java-impl/src/com/intellij/ui/ReferenceEditorComboWithBrowseButton.java index 286e897e82ec..718a8c2fcdc7 100644 --- a/java/java-impl/src/com/intellij/ui/ReferenceEditorComboWithBrowseButton.java +++ b/java/java-impl/src/com/intellij/ui/ReferenceEditorComboWithBrowseButton.java @@ -19,6 +19,7 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComponentWithBrowseButton; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.util.ArrayUtil; import org.jetbrains.annotations.NotNull; @@ -42,7 +43,7 @@ public class ReferenceEditorComboWithBrowseButton extends ComponentWithBrowseBut @NotNull final Project project, boolean toAcceptClasses, final JavaCodeFragment.VisibilityChecker visibilityChecker, final String recentsKey) { - super(new EditorComboBox(createDocument(text, project, toAcceptClasses, visibilityChecker), project, StdFileTypes.JAVA), + super(new EditorComboBox(createDocument(StringUtil.isEmpty(text) ? "" : text, project, toAcceptClasses, visibilityChecker), project, StdFileTypes.JAVA), browseActionListener); final List recentEntries = RecentsManager.getInstance(project).getRecentEntries(recentsKey); if (recentEntries != null) { @@ -82,4 +83,8 @@ public class ReferenceEditorComboWithBrowseButton extends ComponentWithBrowseBut public void prependItem(String item) { getChildComponent().prependItem(item); } + + public void appendItem(String item) { + getChildComponent().appendItem(item); + } } diff --git a/java/java-psi-api/src/com/intellij/psi/PsiLambdaExpression.java b/java/java-psi-api/src/com/intellij/psi/PsiLambdaExpression.java index 43633328c66d..471597a0a529 100644 --- a/java/java-psi-api/src/com/intellij/psi/PsiLambdaExpression.java +++ b/java/java-psi-api/src/com/intellij/psi/PsiLambdaExpression.java @@ -22,14 +22,6 @@ import org.jetbrains.annotations.Nullable; * Represents a Java lambda expression. */ public interface PsiLambdaExpression extends PsiExpression { - /** - * Returns this lambda expression's type parameter list (if any). - * - * @return type parameter list or null. - */ - @Nullable - PsiTypeParameterList getTypeParameterList(); - /** * Returns this lambda expression's parameter list. * diff --git a/java/java-psi-api/src/com/intellij/psi/PsiParameter.java b/java/java-psi-api/src/com/intellij/psi/PsiParameter.java index 5ea7e84e2fca..025d37ff5b37 100644 --- a/java/java-psi-api/src/com/intellij/psi/PsiParameter.java +++ b/java/java-psi-api/src/com/intellij/psi/PsiParameter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,13 +51,6 @@ public interface PsiParameter extends PsiVariable { */ boolean isVarArgs(); - /** - * @return the list of annotations. - * @use getModifierList().getAnnotations() - */ - @Deprecated - @NotNull PsiAnnotation[] getAnnotations(); - /** * {@inheritDoc} */ diff --git a/java/java-psi-api/src/com/intellij/psi/PsiType.java b/java/java-psi-api/src/com/intellij/psi/PsiType.java index 5ed21bd5fdd0..2c3af2dd9499 100644 --- a/java/java-psi-api/src/com/intellij/psi/PsiType.java +++ b/java/java-psi-api/src/com/intellij/psi/PsiType.java @@ -174,6 +174,7 @@ public abstract class PsiType implements PsiAnnotationOwner { * @param visitor the visitor to accept the type. * @return the value returned by the visitor. */ + @Nullable public abstract A accept(@NotNull PsiTypeVisitor visitor); /** diff --git a/java/java-psi-api/src/com/intellij/psi/PsiTypeVisitor.java b/java/java-psi-api/src/com/intellij/psi/PsiTypeVisitor.java index bd2add5b490a..29b1bce17fb4 100644 --- a/java/java-psi-api/src/com/intellij/psi/PsiTypeVisitor.java +++ b/java/java-psi-api/src/com/intellij/psi/PsiTypeVisitor.java @@ -15,44 +15,55 @@ */ package com.intellij.psi; +import org.jetbrains.annotations.Nullable; + /** * Visitor which can be used to visit Java types. * * @author dsl */ public class PsiTypeVisitor { + @Nullable public A visitType(PsiType type) { return null; } + @Nullable public A visitPrimitiveType(PsiPrimitiveType primitiveType) { return visitType(primitiveType); } + @Nullable public A visitArrayType(PsiArrayType arrayType) { return visitType(arrayType); } + @Nullable public A visitClassType(PsiClassType classType) { return visitType(classType); } + @Nullable public A visitCapturedWildcardType(PsiCapturedWildcardType capturedWildcardType) { return visitWildcardType(capturedWildcardType.getWildcard()); } + @Nullable public A visitWildcardType(PsiWildcardType wildcardType) { return visitType(wildcardType); } + @Nullable public A visitEllipsisType(PsiEllipsisType ellipsisType) { return visitArrayType(ellipsisType); } + @Nullable public A visitDisjunctionType(PsiDisjunctionType disjunctionType) { return visitType(disjunctionType); } - + + @Nullable public A visitDiamondType(PsiDiamondType diamondType) { return visitType(diamondType); } diff --git a/java/java-psi-impl/src/com/intellij/lang/java/parser/ExpressionParser.java b/java/java-psi-impl/src/com/intellij/lang/java/parser/ExpressionParser.java index a0cc7a36a34c..ff2f21a5e07d 100644 --- a/java/java-psi-impl/src/com/intellij/lang/java/parser/ExpressionParser.java +++ b/java/java-psi-impl/src/com/intellij/lang/java/parser/ExpressionParser.java @@ -163,7 +163,7 @@ public class ExpressionParser { return parseBinary(builder, ExprType.UNARY, MULTIPLICATIVE_OPS); case UNARY: - return parseUnary(builder, false); + return parseUnary(builder); case TYPE: return myParser.getReferenceParser().parseType(builder, ReferenceParser.EAT_LAST_DOT | ReferenceParser.WILDCARD); @@ -246,14 +246,14 @@ public class ExpressionParser { } @Nullable - private PsiBuilder.Marker parseUnary(final PsiBuilder builder, final boolean afterCast) { + private PsiBuilder.Marker parseUnary(final PsiBuilder builder) { final IElementType tokenType = builder.getTokenType(); if (PREFIX_OPS.contains(tokenType)) { final PsiBuilder.Marker unary = builder.mark(); builder.advanceLexer(); - final PsiBuilder.Marker operand = parseUnary(builder, false); + final PsiBuilder.Marker operand = parseUnary(builder); if (operand == null) { error(builder, JavaErrorMessages.message("expected.expression")); } @@ -269,19 +269,19 @@ public class ExpressionParser { myParser.getReferenceParser().parseTypeInfo(builder, ReferenceParser.EAT_LAST_DOT | ReferenceParser.WILDCARD); if (typeInfo == null || !expect(builder, JavaTokenType.RPARENTH)) { typeCast.rollbackTo(); - return parsePostfix(builder, false); + return parsePostfix(builder); } if (PREF_ARITHMETIC_OPS.contains(builder.getTokenType()) && !typeInfo.isPrimitive) { typeCast.rollbackTo(); - return parsePostfix(builder, false); + return parsePostfix(builder); } - final PsiBuilder.Marker expr = parseUnary(builder, true); + final PsiBuilder.Marker expr = parseUnary(builder); if (expr == null) { if (!typeInfo.isParameterized) { // cannot parse correct parenthesized expression after correct parameterized type typeCast.rollbackTo(); - return parsePostfix(builder, false); + return parsePostfix(builder); } else { error(builder, JavaErrorMessages.message("expected.expression")); @@ -292,13 +292,13 @@ public class ExpressionParser { return typeCast; } else { - return parsePostfix(builder, afterCast); + return parsePostfix(builder); } } @Nullable - private PsiBuilder.Marker parsePostfix(final PsiBuilder builder, final boolean afterCast) { - PsiBuilder.Marker operand = parsePrimary(builder, null, -1, afterCast); + private PsiBuilder.Marker parsePostfix(final PsiBuilder builder) { + PsiBuilder.Marker operand = parsePrimary(builder, null, -1); if (operand == null) return null; while (POSTFIX_OPS.contains(builder.getTokenType())) { @@ -315,13 +315,10 @@ public class ExpressionParser { // todo[r.sh] make 'this', 'super' and 'class' reference expressions @Nullable - private PsiBuilder.Marker parsePrimary(final PsiBuilder builder, - @Nullable final BreakPoint breakPoint, - final int breakOffset, - final boolean afterCast) { + private PsiBuilder.Marker parsePrimary(final PsiBuilder builder, @Nullable final BreakPoint breakPoint, final int breakOffset) { PsiBuilder.Marker startMarker = builder.mark(); - PsiBuilder.Marker expr = parsePrimaryExpressionStart(builder, afterCast); + PsiBuilder.Marker expr = parsePrimaryExpressionStart(builder); if (expr == null) { startMarker.drop(); return null; @@ -349,7 +346,7 @@ public class ExpressionParser { final PsiBuilder.Marker classObjAccess = parseClassAccessOrMethodReference(builder); if (classObjAccess == null || builder.getCurrentOffset() < offset) { copy.rollbackTo(); - return parsePrimary(builder, BreakPoint.P1, offset, false); + return parsePrimary(builder, BreakPoint.P1, offset); } startMarker = copy; @@ -373,13 +370,13 @@ public class ExpressionParser { final PsiBuilder.Marker ref = myParser.getReferenceParser().parseJavaCodeReference(builder, false, true, false, false, false); if (ref == null || builder.getTokenType() != JavaTokenType.DOT || builder.getCurrentOffset() != dotOffset) { copy.rollbackTo(); - return parsePrimary(builder, BreakPoint.P2, offset, false); + return parsePrimary(builder, BreakPoint.P2, offset); } builder.advanceLexer(); if (builder.getTokenType() != dotTokenType) { copy.rollbackTo(); - return parsePrimary(builder, BreakPoint.P2, offset, false); + return parsePrimary(builder, BreakPoint.P2, offset); } builder.advanceLexer(); @@ -420,7 +417,7 @@ public class ExpressionParser { final PsiBuilder.Marker copy = startMarker.precede(); startMarker.rollbackTo(); - final PsiBuilder.Marker qualifier = parsePrimaryExpressionStart(builder, false); + final PsiBuilder.Marker qualifier = parsePrimaryExpressionStart(builder); if (qualifier != null) { final PsiBuilder.Marker refExpr = qualifier.precede(); if (builder.getTokenType() == JavaTokenType.DOT) { @@ -436,7 +433,7 @@ public class ExpressionParser { } copy.rollbackTo(); - return parsePrimary(builder, BreakPoint.P3, -1, false); + return parsePrimary(builder, BreakPoint.P3, -1); } else { startMarker.drop(); @@ -465,7 +462,7 @@ public class ExpressionParser { final PsiBuilder.Marker classObjAccess = parseClassAccessOrMethodReference(builder); if (classObjAccess == null || builder.getCurrentOffset() <= pos) { copy.rollbackTo(); - return parsePrimary(builder, BreakPoint.P4, -1, false); + return parsePrimary(builder, BreakPoint.P4, -1); } startMarker = copy; @@ -505,7 +502,7 @@ public class ExpressionParser { } @Nullable - private PsiBuilder.Marker parsePrimaryExpressionStart(final PsiBuilder builder, final boolean afterCast) { + private PsiBuilder.Marker parsePrimaryExpressionStart(final PsiBuilder builder) { IElementType tokenType = builder.getTokenType(); if (LITERALS.contains(tokenType)) { @@ -597,29 +594,6 @@ public class ExpressionParser { if (tokenType == JavaTokenType.LT) { expr = builder.mark(); - if (!afterCast) { - final PsiBuilder.Marker typeParams = myParser.getReferenceParser().parseTypeParameters(builder, true); - - if (typeParams != null) { - tokenType = builder.getTokenType(); - - PsiBuilder.Marker lambda = null; - if (tokenType == JavaTokenType.LPARENTH) { - lambda = parseLambdaAfterParenth(builder, typeParams); - } - else if (tokenType == JavaTokenType.IDENTIFIER && builder.lookAhead(1) == JavaTokenType.ARROW) { - lambda = parseLambdaExpression(builder, false, typeParams); - } - if (lambda != null) { - expr.drop(); - return lambda; - } - - expr.rollbackTo(); - expr = builder.mark(); - } - } - if (!myParser.getReferenceParser().parseReferenceParameterList(builder, false, false)) { expr.rollbackTo(); return null; diff --git a/java/java-psi-impl/src/com/intellij/lang/java/parser/ReferenceParser.java b/java/java-psi-impl/src/com/intellij/lang/java/parser/ReferenceParser.java index 1eca52592faa..0555b567fcaa 100644 --- a/java/java-psi-impl/src/com/intellij/lang/java/parser/ReferenceParser.java +++ b/java/java-psi-impl/src/com/intellij/lang/java/parser/ReferenceParser.java @@ -297,13 +297,6 @@ public class ReferenceParser { @NotNull public PsiBuilder.Marker parseTypeParameters(final PsiBuilder builder) { - final PsiBuilder.Marker marker = parseTypeParameters(builder, false); - assert marker != null; - return marker; - } - - @Nullable - public PsiBuilder.Marker parseTypeParameters(final PsiBuilder builder, final boolean stopOnErrors) { final PsiBuilder.Marker list = builder.mark(); if (!expect(builder, JavaTokenType.LT)) { list.done(JavaElementType.TYPE_PARAMETER_LIST); @@ -313,10 +306,6 @@ public class ReferenceParser { while (true) { final PsiBuilder.Marker param = parseTypeParameter(builder); if (param == null) { - if (stopOnErrors) { - list.rollbackTo(); - return null; - } error(builder, JavaErrorMessages.message("expected.type.parameter")); } if (!expect(builder, JavaTokenType.COMMA)) { @@ -325,11 +314,6 @@ public class ReferenceParser { } if (!expect(builder, JavaTokenType.GT)) { - if (stopOnErrors) { - list.rollbackTo(); - return null; - } - // hack for completion if (builder.getTokenType() == JavaTokenType.IDENTIFIER) { if (builder.lookAhead(1) == JavaTokenType.GT) { diff --git a/java/java-psi-impl/src/com/intellij/psi/Bottom.java b/java/java-psi-impl/src/com/intellij/psi/Bottom.java index 4b640f1b3b92..942d7792d80e 100644 --- a/java/java-psi-impl/src/com/intellij/psi/Bottom.java +++ b/java/java-psi-impl/src/com/intellij/psi/Bottom.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,7 +66,9 @@ public class Bottom extends PsiType { if (visitor instanceof PsiTypeVisitorEx) { return ((PsiTypeVisitorEx)visitor).visitBottom(this); } - return visitor.visitType(this); + else { + return visitor.visitType(this); + } } @Override diff --git a/java/java-psi-impl/src/com/intellij/psi/PsiTypeVariable.java b/java/java-psi-impl/src/com/intellij/psi/PsiTypeVariable.java index 8625b26292a0..872c8ded71ea 100644 --- a/java/java-psi-impl/src/com/intellij/psi/PsiTypeVariable.java +++ b/java/java-psi-impl/src/com/intellij/psi/PsiTypeVariable.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,8 @@ public abstract class PsiTypeVariable extends PsiType { if (visitor instanceof PsiTypeVisitorEx) { return ((PsiTypeVisitorEx)visitor).visitTypeVariable(this); } - - return visitor.visitType(this); + else { + return visitor.visitType(this); + } } } diff --git a/java/java-psi-impl/src/com/intellij/psi/PsiTypeVisitorEx.java b/java/java-psi-impl/src/com/intellij/psi/PsiTypeVisitorEx.java index eb31de2bcbc8..47eac032290e 100644 --- a/java/java-psi-impl/src/com/intellij/psi/PsiTypeVisitorEx.java +++ b/java/java-psi-impl/src/com/intellij/psi/PsiTypeVisitorEx.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,14 +15,18 @@ */ package com.intellij.psi; +import org.jetbrains.annotations.Nullable; + /** * @author ven */ public class PsiTypeVisitorEx extends PsiTypeVisitor { + @Nullable public A visitTypeVariable(PsiTypeVariable var) { return visitType(var); } + @Nullable public A visitBottom (Bottom bottom) { return visitType(bottom); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiImplUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiImplUtil.java index 102087ed75c0..0187be53a9fa 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiImplUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiImplUtil.java @@ -187,7 +187,7 @@ public class PsiImplUtil { final boolean fromBody = lastParent instanceof PsiCodeBlock; final PsiTypeParameterList typeParameterList = method.getTypeParameterList(); final PsiParameterList parameterList = method.getParameterList(); - return processDeclarationsInMethodLike(method, processor, state, fromBody, place, typeParameterList, parameterList); + return processDeclarationsInMethodLike(method, processor, state, place, fromBody, typeParameterList, parameterList); } public static boolean processDeclarationsInLambda(@NotNull final PsiLambdaExpression lambda, @@ -196,23 +196,24 @@ public class PsiImplUtil { final PsiElement lastParent, @NotNull final PsiElement place) { final boolean fromBody = lastParent != null && lastParent == lambda.getBody(); - final PsiTypeParameterList typeParameterList = lambda.getTypeParameterList(); final PsiParameterList parameterList = lambda.getParameterList(); - return processDeclarationsInMethodLike(lambda, processor, state, fromBody, place, typeParameterList, parameterList); + return processDeclarationsInMethodLike(lambda, processor, state, place, fromBody, null, parameterList); } private static boolean processDeclarationsInMethodLike(@NotNull final PsiElement element, @NotNull final PsiScopeProcessor processor, @NotNull final ResolveState state, - final boolean fromBody, @NotNull final PsiElement place, + final boolean fromBody, @Nullable final PsiTypeParameterList typeParameterList, @NotNull final PsiParameterList parameterList) { processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, element); - final ElementClassHint hint = processor.getHint(ElementClassHint.KEY); - if (hint == null || hint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) { - if (typeParameterList != null && !typeParameterList.processDeclarations(processor, state, null, place)) return false; + if (typeParameterList != null) { + final ElementClassHint hint = processor.getHint(ElementClassHint.KEY); + if (hint == null || hint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) { + if (!typeParameterList.processDeclarations(processor, state, null, place)) return false; + } } if (fromBody) { diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java index 99107f54c2cd..e510a8dfeecc 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java @@ -17,7 +17,10 @@ package com.intellij.psi.impl; import com.intellij.ide.highlighter.JavaFileType; import com.intellij.lang.PsiBuilder; -import com.intellij.lang.java.parser.*; +import com.intellij.lang.java.parser.DeclarationParser; +import com.intellij.lang.java.parser.JavaParser; +import com.intellij.lang.java.parser.JavaParserUtil; +import com.intellij.lang.java.parser.ReferenceParser; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.roots.LanguageLevelProjectExtension; import com.intellij.openapi.util.text.StringUtil; @@ -46,6 +49,8 @@ public class PsiJavaParserFacadeImpl implements PsiJavaParserFacade { protected final PsiManager myManager; private PsiJavaFile myDummyJavaFile; + private static final String DUMMY_FILE_NAME = "_Dummy_." + JavaFileType.INSTANCE.getDefaultExtension(); + public PsiJavaParserFacadeImpl(PsiManager manager) { myManager = manager; } @@ -323,9 +328,8 @@ public class PsiJavaParserFacadeImpl implements PsiJavaParserFacade { } protected PsiJavaFile createDummyJavaFile(final String text) { - final String fileName = "_Dummy_." + JavaFileType.INSTANCE.getDefaultExtension(); final FileType type = JavaFileType.INSTANCE; - return (PsiJavaFile)PsiFileFactory.getInstance(myManager.getProject()).createFileFromText(type, fileName, text, 0, text.length()); + return (PsiJavaFile)PsiFileFactory.getInstance(myManager.getProject()).createFileFromText(DUMMY_FILE_NAME, type, text); } @NotNull diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterImpl.java index 593fd3ac4180..6e2856937e46 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -253,12 +253,6 @@ public class ClsParameterImpl extends ClsRepositoryPsiElement return method.isVarArgs() && getIndex() == paramList.getParametersCount() - 1; } - @Override - @NotNull - public PsiAnnotation[] getAnnotations() { - return getModifierList().getAnnotations(); - } - @Override protected boolean isVisibilitySupported() { return true; diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiParameterImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiParameterImpl.java index 0a569cf4a33e..fd0b61ab31c1 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiParameterImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiParameterImpl.java @@ -251,12 +251,6 @@ public class PsiParameterImpl extends JavaStubPsiElement imple return typeElement != null && SourceTreeToPsiMap.psiToTreeNotNull(typeElement).findChildByType(JavaTokenType.ELLIPSIS) != null; } - @Override - @NotNull - public PsiAnnotation[] getAnnotations() { - return getModifierList().getAnnotations(); - } - @Override public ItemPresentation getPresentation() { return ItemPresentationProviders.getItemPresentation(this); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiLambdaExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiLambdaExpressionImpl.java index 3d80882b8d53..8ca6fce91d88 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiLambdaExpressionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiLambdaExpressionImpl.java @@ -27,12 +27,6 @@ public class PsiLambdaExpressionImpl extends ExpressionPsiElement implements Psi super(JavaElementType.LAMBDA_EXPRESSION); } - @Override - public PsiTypeParameterList getTypeParameterList() { - final PsiElement element = getFirstChild(); - return element instanceof PsiTypeParameterList ? (PsiTypeParameterList)element : null; - } - @NotNull @Override public PsiParameterList getParameterList() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InnerClassesShadowing.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InnerClassesShadowing.java index e7a5e3d51d99..e87c5db28998 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InnerClassesShadowing.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InnerClassesShadowing.java @@ -1,16 +1,98 @@ +import java.io.*; + +public class Main { + static interface A + { + interface B { } + } + + static class D implements A + { + private interface B { } + } + + + static class C extends D implements A + { + interface E extends B { } + interface E1 extends D.B { } + interface E2 extends A.B { } + } + +} + + + +class Main1 { + static interface A + { + interface B { } + } + + static class D implements A + { + interface B { } + } + + + static class C extends D implements A + { + interface E extends B { } + interface E1 extends D.B { + } + interface E2 extends A.B { } + } + +} + + interface A { + interface B { } interface B1 { } } class D implements A { + private interface B { } interface B1 { } } class C extends D implements A { + interface E extends B { } + interface E1 extends D.B { } + interface E2 extends A.B { } + interface F extends B1 { } + interface F1 extends D.B1 { } + interface F2 extends A.B1 { } + } + +class AO {} +class BAO { + AO bar = new AO(); + { + bar.foo(); + } + private class AO { + void foo(){} + } + +} + +class WithFileInputStream { + private static final Runnable runn = new Runnable() { + public void run() { + new FileInputStream("path"); + } + }; + + private static class FileInputStream { + private FileInputStream(String str) { + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/LambdaExpressions.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/LambdaExpressions.java index 14ce1ba5cffd..9a979bf22893 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/LambdaExpressions.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/LambdaExpressions.java @@ -26,15 +26,14 @@ class C { int parse(String s); } - interface ListProducer { - List produce(); - } - void test() { Simplest simplest = () -> { }; use(() -> { }); IntParser intParser = (String s) -> Integer.parseInt(s); - ListProducer listProducer = () -> new ArrayList(); + } + + Runnable foo() { + return () -> { System.out.println("foo"); }; } } \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/encapsulateField/beforeFinal.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/encapsulateField/beforeFinal.java new file mode 100644 index 000000000000..e082b01cf8fb --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/encapsulateField/beforeFinal.java @@ -0,0 +1,13 @@ +// "Encapsulate field" "false" + +class A { + public final boolean m_bool; +} + +public class B { + void method() { + A a = new A(); + + a.m_bool = true; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/encapsulateField/beforePrivate.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/encapsulateField/beforePrivate.java new file mode 100644 index 000000000000..061d152e95e6 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/encapsulateField/beforePrivate.java @@ -0,0 +1,13 @@ +// "Encapsulate field" "false" + +class A { + private boolean m_bool; +} + +public class B { + void method() { + A a = new A(); + + a.m_bool = true; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/encapsulateField/beforeThisClass.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/encapsulateField/beforeThisClass.java new file mode 100644 index 000000000000..4721b752ed5e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/encapsulateField/beforeThisClass.java @@ -0,0 +1,9 @@ +// "Encapsulate field" "false" + +class A { + public final boolean m_bool; + + void method() { + m_bool = true; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/encapsulateField/beforeThisClassQualified.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/encapsulateField/beforeThisClassQualified.java new file mode 100644 index 000000000000..a4aa102c4a85 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/encapsulateField/beforeThisClassQualified.java @@ -0,0 +1,9 @@ +// "Encapsulate field" "false" + +class A { + public final boolean m_bool; + + void method() { + this.m_bool = true; + } +} diff --git a/java/java-tests/testData/psi/parser-partial/expressions/LambdaExpression12.txt b/java/java-tests/testData/psi/parser-partial/expressions/LambdaExpression12.txt index ca651c993104..576a40ebec84 100644 --- a/java/java-tests/testData/psi/parser-partial/expressions/LambdaExpression12.txt +++ b/java/java-tests/testData/psi/parser-partial/expressions/LambdaExpression12.txt @@ -1,33 +1,18 @@ PsiJavaFile:LambdaExpression12.java - PsiLambdaExpression:() -> new C() - PsiTypeParameterList - PsiJavaToken:LT('<') - PsiTypeParameter:T - PsiIdentifier:T('T') - PsiElement(EXTENDS_BOUND_LIST) - - PsiJavaToken:GT('>') - PsiParameterList:() - PsiJavaToken:LPARENTH('(') - PsiJavaToken:RPARENTH(')') + PsiErrorElement:Unparsed tokens + PsiJavaToken:LT('<') + PsiIdentifier:T('T') + PsiJavaToken:GT('>') + PsiJavaToken:LPARENTH('(') + PsiJavaToken:RPARENTH(')') PsiWhiteSpace(' ') PsiJavaToken:ARROW('->') PsiWhiteSpace(' ') - PsiNewExpression:new C() - PsiKeyword:new('new') - PsiReferenceParameterList - - PsiWhiteSpace(' ') - PsiJavaCodeReferenceElement:C - PsiIdentifier:C('C') - PsiReferenceParameterList - PsiJavaToken:LT('<') - PsiTypeElement:T - PsiJavaCodeReferenceElement:T - PsiIdentifier:T('T') - PsiReferenceParameterList - - PsiJavaToken:GT('>') - PsiExpressionList - PsiJavaToken:LPARENTH('(') - PsiJavaToken:RPARENTH(')') \ No newline at end of file + PsiKeyword:new('new') + PsiWhiteSpace(' ') + PsiIdentifier:C('C') + PsiJavaToken:LT('<') + PsiIdentifier:T('T') + PsiJavaToken:GT('>') + PsiJavaToken:LPARENTH('(') + PsiJavaToken:RPARENTH(')') \ No newline at end of file diff --git a/java/java-tests/testData/psi/parser-partial/expressions/LambdaExpression13.txt b/java/java-tests/testData/psi/parser-partial/expressions/LambdaExpression13.txt index 2d0cfcd4ed32..2b6c6786cfbb 100644 --- a/java/java-tests/testData/psi/parser-partial/expressions/LambdaExpression13.txt +++ b/java/java-tests/testData/psi/parser-partial/expressions/LambdaExpression13.txt @@ -1,21 +1,10 @@ PsiJavaFile:LambdaExpression13.java - PsiLambdaExpression:t -> t - PsiTypeParameterList - PsiJavaToken:LT('<') - PsiTypeParameter:T - PsiIdentifier:T('T') - PsiElement(EXTENDS_BOUND_LIST) - - PsiJavaToken:GT('>') - PsiParameterList:t - PsiParameter:t - PsiModifierList: - - PsiIdentifier:t('t') + PsiErrorElement:Unparsed tokens + PsiJavaToken:LT('<') + PsiIdentifier:T('T') + PsiJavaToken:GT('>') + PsiIdentifier:t('t') PsiWhiteSpace(' ') PsiJavaToken:ARROW('->') PsiWhiteSpace(' ') - PsiReferenceExpression:t - PsiReferenceParameterList - - PsiIdentifier:t('t') \ No newline at end of file + PsiIdentifier:t('t') \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/anonymousToInner/canBeStatic.java b/java/java-tests/testData/refactoring/anonymousToInner/canBeStatic.java new file mode 100644 index 000000000000..dd7ca4915b75 --- /dev/null +++ b/java/java-tests/testData/refactoring/anonymousToInner/canBeStatic.java @@ -0,0 +1,14 @@ +public class Foo { + public void foo() { + Predicate predicate = new Predicate() { + @Override + public boolean test(T t) { + return false; + } + }; + } + + private interface Predicate { + boolean test(K t); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/anonymousToInner/canBeStatic_after.java b/java/java-tests/testData/refactoring/anonymousToInner/canBeStatic_after.java new file mode 100644 index 000000000000..4bcfab1cb5bd --- /dev/null +++ b/java/java-tests/testData/refactoring/anonymousToInner/canBeStatic_after.java @@ -0,0 +1,16 @@ +public class Foo { + public void foo() { + Predicate predicate = new MyPredicate<>(); + } + + private interface Predicate { + boolean test(K t); + } + + private static class MyPredicate implements Predicate { + @Override + public boolean test(T t) { + return false; + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/anonymousToInner/collapseDiamonds.java b/java/java-tests/testData/refactoring/anonymousToInner/collapseDiamonds.java new file mode 100644 index 000000000000..dd7ca4915b75 --- /dev/null +++ b/java/java-tests/testData/refactoring/anonymousToInner/collapseDiamonds.java @@ -0,0 +1,14 @@ +public class Foo { + public void foo() { + Predicate predicate = new Predicate() { + @Override + public boolean test(T t) { + return false; + } + }; + } + + private interface Predicate { + boolean test(K t); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/anonymousToInner/collapseDiamonds_after.java b/java/java-tests/testData/refactoring/anonymousToInner/collapseDiamonds_after.java new file mode 100644 index 000000000000..4bcfab1cb5bd --- /dev/null +++ b/java/java-tests/testData/refactoring/anonymousToInner/collapseDiamonds_after.java @@ -0,0 +1,16 @@ +public class Foo { + public void foo() { + Predicate predicate = new MyPredicate<>(); + } + + private interface Predicate { + boolean test(K t); + } + + private static class MyPredicate implements Predicate { + @Override + public boolean test(T t) { + return false; + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/anonymousToInner/genericTypeParameters_after.java b/java/java-tests/testData/refactoring/anonymousToInner/genericTypeParameters_after.java index aa7fe1d30f5d..9ee35687cb2a 100644 --- a/java/java-tests/testData/refactoring/anonymousToInner/genericTypeParameters_after.java +++ b/java/java-tests/testData/refactoring/anonymousToInner/genericTypeParameters_after.java @@ -2,7 +2,7 @@ import java.util.*; class A { public Iterator> iterator(long revision) { - return new MyIterator(); + return new MyIterator<>(); } private static class MyIterator implements Iterator> { diff --git a/java/java-tests/testData/refactoring/changeSignature/ParamNameNoConflict.java b/java/java-tests/testData/refactoring/changeSignature/ParamNameNoConflict.java new file mode 100644 index 000000000000..a98e37640762 --- /dev/null +++ b/java/java-tests/testData/refactoring/changeSignature/ParamNameNoConflict.java @@ -0,0 +1,11 @@ +class D { + void foo(Object o){} +} + +class DImpl extends D { + void foo(Object o1) { + super.foo(o1); + int o = 0; + System.out.println(o); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/changeSignature/ParamNameNoConflict_after.java b/java/java-tests/testData/refactoring/changeSignature/ParamNameNoConflict_after.java new file mode 100644 index 000000000000..6b29466ed297 --- /dev/null +++ b/java/java-tests/testData/refactoring/changeSignature/ParamNameNoConflict_after.java @@ -0,0 +1,11 @@ +class D { + void foo(Object o, boolean b){} +} + +class DImpl extends D { + void foo(Object o1, boolean b) { + super.foo(o1, b); + int o = 0; + System.out.println(o); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/changeSignaturePropagation/ParamTypeSubst.java b/java/java-tests/testData/refactoring/changeSignaturePropagation/ParamTypeSubst.java new file mode 100644 index 000000000000..374f3cccbad1 --- /dev/null +++ b/java/java-tests/testData/refactoring/changeSignaturePropagation/ParamTypeSubst.java @@ -0,0 +1,10 @@ +class Base { + void m() { + } +} + +class A extends Base { + void x() { + m(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/changeSignaturePropagation/ParamTypeSubst.java.after b/java/java-tests/testData/refactoring/changeSignaturePropagation/ParamTypeSubst.java.after new file mode 100644 index 000000000000..070698a3d8c6 --- /dev/null +++ b/java/java-tests/testData/refactoring/changeSignaturePropagation/ParamTypeSubst.java.after @@ -0,0 +1,10 @@ +class Base { + void m(T clazz) { + } +} + +class A extends Base { + void x(String clazz) { + m(clazz); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/inlineMethod/ChainedConstructor.java b/java/java-tests/testData/refactoring/inlineMethod/ChainedConstructor.java new file mode 100644 index 000000000000..a64d2759ef10 --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineMethod/ChainedConstructor.java @@ -0,0 +1,21 @@ +public class InlineThis { + public InlineThis() { + System.out.println("code block here"); + } + + public InlineThis(int i) { + this(); + } + + public InlineThis(String str) { + this(Integer.parseInt(str)); + } + + + + + public static void main(String[] args) { + InlineThis aInlineThis = new InlineThis(); + InlineThis aInlineThis1 = new InlineThis(1); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/inlineMethod/ChainedConstructor.java.after b/java/java-tests/testData/refactoring/inlineMethod/ChainedConstructor.java.after new file mode 100644 index 000000000000..104f8b3722a1 --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineMethod/ChainedConstructor.java.after @@ -0,0 +1,21 @@ +public class InlineThis { + public InlineThis() { + System.out.println("code block here"); + } + + public InlineThis(int i) { + System.out.println("code block here"); + } + + public InlineThis(String str) { + this(Integer.parseInt(str)); + } + + + + + public static void main(String[] args) { + InlineThis aInlineThis = new InlineThis(); + InlineThis aInlineThis1 = new InlineThis(1); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/inlineMethod/ChainedConstructor1.java b/java/java-tests/testData/refactoring/inlineMethod/ChainedConstructor1.java new file mode 100644 index 000000000000..a99133cd1594 --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineMethod/ChainedConstructor1.java @@ -0,0 +1,21 @@ +public class InlineThis { + public InlineThis() { + System.out.println("code block here"); + } + + public InlineThis(int i) { + this(); + } + + public InlineThis(String str) { + this(Integer.parseInt(str)); + } + + + + + public static void main(String[] args) { + InlineThis aInlineThis = new InlineThis(); + InlineThis aInlineThis1 = new InlineThis(1); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/inlineMethod/ChainedConstructor1.java.after b/java/java-tests/testData/refactoring/inlineMethod/ChainedConstructor1.java.after new file mode 100644 index 000000000000..5143141fd436 --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineMethod/ChainedConstructor1.java.after @@ -0,0 +1,17 @@ +public class InlineThis { + public InlineThis() { + System.out.println("code block here"); + } + + public InlineThis(String str) { + this(); + } + + + + + public static void main(String[] args) { + InlineThis aInlineThis = new InlineThis(); + InlineThis aInlineThis1 = new InlineThis(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/introduceParameter/afterPreserveDiamondOccurrences.java b/java/java-tests/testData/refactoring/introduceParameter/afterPreserveDiamondOccurrences.java new file mode 100644 index 000000000000..4f62137d7950 --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceParameter/afterPreserveDiamondOccurrences.java @@ -0,0 +1,22 @@ + +public class TestCompletion { + + public static ParallelPipeline test(T base, V newStage, T upstream, final ParallelPipeline anObject) { + if (base != null){ + return anObject; + } + else { + return new ParallelPipeline<>(upstream, newStage); + } + + } + + + void f() { + test(null, null, null, new ParallelPipeline<>(null, null)); + } + private static class ParallelPipeline { + public ParallelPipeline(T p0, V p1) { + } + } +} diff --git a/java/java-tests/testData/refactoring/introduceParameter/beforePreserveDiamondOccurrences.java b/java/java-tests/testData/refactoring/introduceParameter/beforePreserveDiamondOccurrences.java new file mode 100644 index 000000000000..2bf9a854544d --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceParameter/beforePreserveDiamondOccurrences.java @@ -0,0 +1,22 @@ + +public class TestCompletion { + + public static ParallelPipeline test(T base, V newStage, T upstream) { + if (base != null){ + return new ParallelPipeline<>(base, newStage); + } + else { + return new ParallelPipeline<>(upstream, newStage); + } + + } + + + void f() { + test(null, null, null); + } + private static class ParallelPipeline { + public ParallelPipeline(T p0, V p1) { + } + } +} diff --git a/java/java-tests/testData/refactoring/pullUp/MergeInterfaces.java b/java/java-tests/testData/refactoring/pullUp/MergeInterfaces.java new file mode 100644 index 000000000000..68f3d11cf803 --- /dev/null +++ b/java/java-tests/testData/refactoring/pullUp/MergeInterfaces.java @@ -0,0 +1,3 @@ +class Base implements I {} +class Test extends Base implements I {} +interface I{} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/pullUp/MergeInterfaces_after.java b/java/java-tests/testData/refactoring/pullUp/MergeInterfaces_after.java new file mode 100644 index 000000000000..dfad6f6eb34f --- /dev/null +++ b/java/java-tests/testData/refactoring/pullUp/MergeInterfaces_after.java @@ -0,0 +1,3 @@ +class Base implements I {} +class Test extends Base {} +interface I{} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingTest.groovy index a362c06bff2f..178087bf8e8d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/folding/JavaFoldingTest.groovy @@ -283,6 +283,22 @@ class Test { assert !foldingModel.getCollapsedRegionAtOffset(text.indexOf("Runnable")) } + public void "test no closure folding for synchronized methods"() { + def text = """\ +class Test { + void test() { new Runnable() { + public synchronized void run() { + System.out.println(); + } + }; + } +} +""" + configure text + def foldingModel = myFixture.editor.foldingModel as FoldingModelImpl + assert !foldingModel.getCollapsedRegionAtOffset(text.indexOf("Runnable")) + } + public void testFindInFolding() { def text = """\ class Test { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/intention/EncapsulateFieldTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/intention/EncapsulateFieldTest.java new file mode 100644 index 000000000000..165073beedbd --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/intention/EncapsulateFieldTest.java @@ -0,0 +1,31 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.intention; + +import com.intellij.codeInsight.daemon.LightIntentionActionTestCase; + +/** + * @author Danila Ponomarenko + */ +public class EncapsulateFieldTest extends LightIntentionActionTestCase { + + public void test() throws Exception { doAllTests(); } + + @Override + protected String getBasePath() { + return "/codeInsight/daemonCodeAnalyzer/quickFix/encapsulateField"; + } +} diff --git a/java/java-tests/testSrc/com/intellij/lang/java/parser/partial/ExpressionParserTest.java b/java/java-tests/testSrc/com/intellij/lang/java/parser/partial/ExpressionParserTest.java index f54cc3443386..8f5726aba7f3 100644 --- a/java/java-tests/testSrc/com/intellij/lang/java/parser/partial/ExpressionParserTest.java +++ b/java/java-tests/testSrc/com/intellij/lang/java/parser/partial/ExpressionParserTest.java @@ -134,8 +134,8 @@ public class ExpressionParserTest extends JavaParsingTestCase { public void testLambdaExpression9() { doParserTest("(I)p -> null"); } public void testLambdaExpression10() { doParserTest("(I)(p -> null)"); } public void testLambdaExpression11() { doParserTest("() -> { }"); } - public void testLambdaExpression12() { doParserTest("() -> new C()"); } - public void testLambdaExpression13() { doParserTest("t -> t"); } + public void testLambdaExpression12() { doParserTest("() -> new C()"); } // these two expressions + public void testLambdaExpression13() { doParserTest("t -> t"); } // should no longer be parsed public void testLambdaExpression14() { doParserTest("(String t) -> t"); } public void testLambdaExpression15() { doParserTest("(int a, int b) -> a + b"); } public void testLambdaExpression16() { doParserTest("(final int x) -> x"); } diff --git a/java/java-tests/testSrc/com/intellij/psi/PsiModificationTrackerTest.java b/java/java-tests/testSrc/com/intellij/psi/PsiModificationTrackerTest.java index 0dc335947726..7cba4a83f4a3 100644 --- a/java/java-tests/testSrc/com/intellij/psi/PsiModificationTrackerTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/PsiModificationTrackerTest.java @@ -3,8 +3,10 @@ package com.intellij.psi; import com.intellij.ide.highlighter.JavaFileType; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.SelectionModel; +import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.util.PsiModificationTracker; +import com.intellij.testFramework.IdeaTestCase; import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; import com.intellij.util.Processor; import org.jetbrains.annotations.NonNls; @@ -15,6 +17,12 @@ import java.io.IOException; * @author Dmitry Avdeev */ public class PsiModificationTrackerTest extends LightPlatformCodeInsightFixtureTestCase { + @Override + public void setUp() throws Exception { + IdeaTestCase.initPlatformPrefix(); + super.setUp(); + } + public void testAnnotationNotChanged() throws Exception { doReplaceTest("@SuppressWarnings(\"zz\")\n" + "public class Foo { }", @@ -86,6 +94,7 @@ public class PsiModificationTrackerTest extends LightPlatformCodeInsightFixtureT try { final VirtualFile vFile = psiFile.getVirtualFile(); assert vFile != null : psiFile; + FileEditorManager.getInstance(getProject()).closeFile(vFile); vFile.delete(this); } catch (IOException e) { diff --git a/java/java-tests/testSrc/com/intellij/refactoring/AnonymousToInnerTest.java b/java/java-tests/testSrc/com/intellij/refactoring/AnonymousToInnerTest.java index 171393c03a47..71fa16179846 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/AnonymousToInnerTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/AnonymousToInnerTest.java @@ -37,6 +37,26 @@ public class AnonymousToInnerTest extends LightCodeInsightTestCase { public void testInsideInterface() throws Exception { // IDEADEV-29446 doTest("MyRunnable", true); } + + public void testCollapseDiamonds() throws Exception { // IDEADEV-29446 + doTest("MyPredicate", true); + } + + public void testCanBeStatic() throws Exception { + configureByFile(TEST_ROOT + getTestName(true) + ".java"); + AnonymousToInnerHandler handler = new AnonymousToInnerHandler(){ + @Override + protected boolean showRefactoringDialog() { + myNewClassName = "MyPredicate"; + myMakeStatic = !needsThis(); + return true; + } + }; + handler.invoke(getProject(), myEditor, myFile, null); + assertFalse(handler.needsThis()); + checkResultByFile(TEST_ROOT + getTestName(true) + "_after.java"); + } + private void doTest(final String newClassName, final boolean makeStatic) throws Exception { configureByFile(TEST_ROOT + getTestName(true) + ".java"); diff --git a/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignaturePropagationTest.java b/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignaturePropagationTest.java index bdb1445df3ce..6daec4d62b1d 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignaturePropagationTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignaturePropagationTest.java @@ -6,6 +6,8 @@ import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.searches.ClassInheritorsSearch; import com.intellij.psi.search.searches.MethodReferencesSearch; +import com.intellij.psi.search.searches.ReferencesSearch; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.refactoring.changeSignature.ChangeSignatureProcessor; import com.intellij.refactoring.changeSignature.JavaThrownExceptionInfo; import com.intellij.refactoring.changeSignature.ParameterInfoImpl; @@ -29,6 +31,18 @@ public class ChangeSignaturePropagationTest extends LightRefactoringTestCase { parameterPropagationTest(); } + public void testParamTypeSubst() throws Exception { + final PsiMethod method = getPrimaryMethod(); + final HashSet methods = new HashSet(); + for (PsiReference reference : ReferencesSearch.search(method)) { + final PsiMethod psiMethod = PsiTreeUtil.getParentOfType(reference.getElement(), PsiMethod.class); + if (psiMethod != null) { + methods.add(psiMethod); + } + } + parameterPropagationTest(method, methods, JavaPsiFacade.getElementFactory(getProject()).createTypeByFQClassName("T")); + } + public void testExceptionSimple() throws Exception { exceptionPropagationTest(); } @@ -39,7 +53,7 @@ public class ChangeSignaturePropagationTest extends LightRefactoringTestCase { public void testParamWithNoConstructor() throws Exception { final PsiMethod method = getPrimaryMethod(); - parameterPropagationTest(method, collectNonPhysicalMethodsToPropagate(method)); + parameterPropagationTest(method, collectNonPhysicalMethodsToPropagate(method), JavaPsiFacade.getElementFactory(getProject()).createTypeByFQClassName("java.lang.Class", GlobalSearchScope.allScope(getProject()))); } public void testExceptionWithNoConstructor() throws Exception { @@ -62,12 +76,12 @@ public class ChangeSignaturePropagationTest extends LightRefactoringTestCase { public void testParamWithImplicitConstructor() throws Exception { final PsiMethod method = getPrimaryMethod(); - parameterPropagationTest(method, collectDefaultConstructorsToPropagate(method)); + parameterPropagationTest(method, collectDefaultConstructorsToPropagate(method), JavaPsiFacade.getElementFactory(getProject()).createTypeByFQClassName("java.lang.Class", GlobalSearchScope.allScope(getProject()))); } public void testParamWithImplicitConstructors() throws Exception { final PsiMethod method = getPrimaryMethod(); - parameterPropagationTest(method, collectDefaultConstructorsToPropagate(method)); + parameterPropagationTest(method, collectDefaultConstructorsToPropagate(method), JavaPsiFacade.getElementFactory(getProject()).createTypeByFQClassName("java.lang.Class", GlobalSearchScope.allScope(getProject()))); } public void testExceptionWithImplicitConstructor() throws Exception { @@ -84,13 +98,18 @@ public class ChangeSignaturePropagationTest extends LightRefactoringTestCase { } private void parameterPropagationTest() throws Exception { - final PsiMethod method = getPrimaryMethod(); - parameterPropagationTest(method, new HashSet(Arrays.asList(method.getContainingClass().getMethods()))); + parameterPropagationTest(JavaPsiFacade.getElementFactory(getProject()) + .createTypeByFQClassName("java.lang.Class", GlobalSearchScope.allScope(getProject()))); } - private void parameterPropagationTest(final PsiMethod method, final HashSet psiMethods) throws Exception { - PsiType newParamType = JavaPsiFacade.getElementFactory(getProject()).createTypeByFQClassName("java.lang.Class", GlobalSearchScope.allScope(getProject())); - final ParameterInfoImpl[] newParameters = new ParameterInfoImpl[]{new ParameterInfoImpl(-1, "clazz", newParamType, "null")}; + private void parameterPropagationTest(final PsiClassType paramType) throws Exception { + final PsiMethod method = getPrimaryMethod(); + parameterPropagationTest(method, new HashSet(Arrays.asList(method.getContainingClass().getMethods())), + paramType); + } + + private void parameterPropagationTest(final PsiMethod method, final HashSet psiMethods, final PsiType paramType) throws Exception { + final ParameterInfoImpl[] newParameters = new ParameterInfoImpl[]{new ParameterInfoImpl(-1, "clazz", paramType, "null")}; doTest(newParameters, new ThrownExceptionInfo[0], psiMethods, null, method); } diff --git a/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureTest.java b/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureTest.java index 77d7fcdea41e..41acb241a84c 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureTest.java @@ -134,6 +134,13 @@ public class ChangeSignatureTest extends LightRefactoringTestCase { }, false); } + public void testParamNameNoConflict() throws Exception { + doTest(null, new ParameterInfoImpl[]{ + new ParameterInfoImpl(0), + new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN) + }, false); + } + public void testParamJavadoc() throws Exception { doTest(null, new ParameterInfoImpl[] { new ParameterInfoImpl(1, "z", PsiType.INT), diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java index 4893ce72e001..0cad5462136e 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java @@ -275,6 +275,10 @@ public class IntroduceParameterTest extends LightRefactoringTestCase { doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL, true, false, true, false); } + public void testPreserveDiamondOccurrences() throws Exception { + doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL, true, false, true, false); + } + public void testSubstituteTypeParams() throws Exception { doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL, true, false, true, false); } diff --git a/java/java-tests/testSrc/com/intellij/refactoring/PullUpTest.java b/java/java-tests/testSrc/com/intellij/refactoring/PullUpTest.java index b17563b2f75c..c4f5a7aa0e89 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/PullUpTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/PullUpTest.java @@ -111,6 +111,10 @@ public class PullUpTest extends LightRefactoringTestCase { doTest(false, new RefactoringTestUtil.MemberDescriptor("foo", PsiMethod.class)); } + public void testMergeInterfaces() throws Exception { + doTest(false, new RefactoringTestUtil.MemberDescriptor("I", PsiClass.class)); + } + private void doTest(RefactoringTestUtil.MemberDescriptor... membersToFind) throws Exception { doTest(true, membersToFind); } diff --git a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java index 99b98075ce1d..8870d33c8791 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java @@ -176,6 +176,14 @@ public class InlineMethodTest extends LightRefactoringTestCase { doTest(); } + public void testChainedConstructor() throws Exception { + doTestInlineThisOnly(); + } + + public void testChainedConstructor1() throws Exception { + doTest(); + } + public void testMethodUsedInJavadoc() throws Exception { try { doTest(); @@ -187,6 +195,10 @@ public class InlineMethodTest extends LightRefactoringTestCase { } public void testInlineRunnableRun() throws Exception { + doTestInlineThisOnly(); + } + + private void doTestInlineThisOnly() { @NonNls String fileName = "/refactoring/inlineMethod/" + getTestName(false) + ".java"; configureByFile(fileName); performAction(new MockInlineMethodOptions(){ diff --git a/java/openapi/src/com/intellij/psi/search/scope/packageSet/PatternPackageSet.java b/java/openapi/src/com/intellij/psi/search/scope/packageSet/PatternPackageSet.java index ac7e6d84061b..fa8b3faf6e67 100644 --- a/java/openapi/src/com/intellij/psi/search/scope/packageSet/PatternPackageSet.java +++ b/java/openapi/src/com/intellij/psi/search/scope/packageSet/PatternPackageSet.java @@ -106,6 +106,7 @@ public class PatternPackageSet extends PatternBasedPackageSet { return StringUtil.getQualifiedName(fileIndex.getPackageNameByDirectory(file.isDirectory() ? file : file.getParent()), file.getNameWithoutExtension()); } + @NotNull @Override public PackageSet createCopy() { return new PatternPackageSet(myAspectJSyntaxPattern, myScope, myModulePatternText); @@ -116,6 +117,7 @@ public class PatternPackageSet extends PatternBasedPackageSet { return 0; } + @NotNull @Override public String getText() { StringBuilder buf = new StringBuilder(); diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/storage/BuildDataManager.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/storage/BuildDataManager.java index e1a634a869ae..8b1e97111783 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/storage/BuildDataManager.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/storage/BuildDataManager.java @@ -18,7 +18,7 @@ import java.util.Map; * Date: 10/7/11 */ public class BuildDataManager implements StorageOwner { - private static final int VERSION = 3; + private static final int VERSION = 4; private static final Logger LOG = Logger.getInstance("#org.jetbrains.jps.incremental.storage.BuildDataManager"); private static final String SRC_TO_OUTPUTS_STORAGE = "src-out"; private static final String SRC_TO_FORM_STORAGE = "src-form"; diff --git a/jps/model-api/src/org/jetbrains/jps/model/JpsElementFactory.java b/jps/model-api/src/org/jetbrains/jps/model/JpsElementFactory.java index 1e25c2197573..d94c2711bf68 100644 --- a/jps/model-api/src/org/jetbrains/jps/model/JpsElementFactory.java +++ b/jps/model-api/src/org/jetbrains/jps/model/JpsElementFactory.java @@ -1,8 +1,12 @@ package org.jetbrains.jps.model; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.model.library.JpsLibrary; import org.jetbrains.jps.model.library.JpsLibraryReference; +import org.jetbrains.jps.model.library.JpsLibraryType; +import org.jetbrains.jps.model.module.JpsModule; import org.jetbrains.jps.model.module.JpsModuleReference; +import org.jetbrains.jps.model.module.JpsModuleType; import org.jetbrains.jps.service.JpsServiceManager; /** @@ -13,6 +17,10 @@ public abstract class JpsElementFactory { return JpsServiceManager.getInstance().getService(JpsElementFactory.class); } + public abstract JpsModule createModule(String name, JpsModuleType> type); + + public abstract JpsLibrary createLibrary(@NotNull String name, @NotNull JpsLibraryType> type); + @NotNull public abstract JpsModuleReference createModuleReference(@NotNull String moduleName); @@ -20,4 +28,9 @@ public abstract class JpsElementFactory { public abstract JpsLibraryReference createLibraryReference(@NotNull String libraryName, @NotNull JpsElementReference extends JpsCompositeElement> parentReference); + @NotNull + public abstract JpsElementReference createProjectReference(); + + @NotNull + public abstract JpsElementReference createGlobalReference(); } diff --git a/jps/model-api/src/org/jetbrains/jps/model/JpsProject.java b/jps/model-api/src/org/jetbrains/jps/model/JpsProject.java index 0beb26b8a514..9855a4b3d5d8 100644 --- a/jps/model-api/src/org/jetbrains/jps/model/JpsProject.java +++ b/jps/model-api/src/org/jetbrains/jps/model/JpsProject.java @@ -24,4 +24,8 @@ public interface JpsProject extends JpsCompositeElement, JpsReferenceableElement @NotNull List extends JpsModule> getModules(); + + void addModule(JpsModule module); + + void addLibrary(JpsLibrary library); } diff --git a/jps/model-api/src/org/jetbrains/jps/model/java/ExplodedDirectoryModuleExtension.java b/jps/model-api/src/org/jetbrains/jps/model/java/ExplodedDirectoryModuleExtension.java new file mode 100644 index 000000000000..a1fcdb97e3e8 --- /dev/null +++ b/jps/model-api/src/org/jetbrains/jps/model/java/ExplodedDirectoryModuleExtension.java @@ -0,0 +1,18 @@ +package org.jetbrains.jps.model.java; + +import org.jetbrains.jps.model.JpsElement; + +/** + * @author nik + */ +//todo[nik] move to j2me plugin +public interface ExplodedDirectoryModuleExtension extends JpsElement { + + String getExplodedUrl(); + + void setExplodedUrl(String explodedUrl); + + boolean isExcludeExploded(); + + void setExcludeExploded(boolean excludeExploded); +} diff --git a/jps/model-api/src/org/jetbrains/jps/model/java/JpsAnnotationRootType.java b/jps/model-api/src/org/jetbrains/jps/model/java/JpsAnnotationRootType.java new file mode 100644 index 000000000000..51669166ac94 --- /dev/null +++ b/jps/model-api/src/org/jetbrains/jps/model/java/JpsAnnotationRootType.java @@ -0,0 +1,10 @@ +package org.jetbrains.jps.model.java; + +import org.jetbrains.jps.model.library.JpsOrderRootType; + +/** + * @author nik + */ +public class JpsAnnotationRootType extends JpsOrderRootType { + public static final JpsAnnotationRootType INSTANCE = new JpsAnnotationRootType(); +} diff --git a/jps/model-api/src/org/jetbrains/jps/model/java/JpsJavaExtensionService.java b/jps/model-api/src/org/jetbrains/jps/model/java/JpsJavaExtensionService.java new file mode 100644 index 000000000000..a7334ea52c87 --- /dev/null +++ b/jps/model-api/src/org/jetbrains/jps/model/java/JpsJavaExtensionService.java @@ -0,0 +1,31 @@ +package org.jetbrains.jps.model.java; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.model.JpsElementKind; +import org.jetbrains.jps.model.module.JpsDependencyElement; +import org.jetbrains.jps.model.module.JpsModule; +import org.jetbrains.jps.service.JpsServiceManager; + +/** + * @author nik + */ +public abstract class JpsJavaExtensionService { + public static JpsJavaExtensionService getInstance() { + return JpsServiceManager.getInstance().getService(JpsJavaExtensionService.class); + } + + @NotNull + public abstract JpsJavaModuleExtension getOrCreateModuleExtension(@NotNull JpsModule module); + + @NotNull + public abstract JpsJavaDependencyExtension getOrCreateDependencyExtension(@NotNull JpsDependencyElement dependency); + + @NotNull + public abstract JpsElementKind extends JpsJavaModuleExtension> getModuleExtensionKind(); + + @NotNull + public abstract JpsElementKind extends JpsJavaDependencyExtension> getDependencyExtensionKind(); + + @NotNull + public abstract ExplodedDirectoryModuleExtension getOrCreateExplodedDirectoryExtension(@NotNull JpsModule module); +} diff --git a/jps/model-api/src/org/jetbrains/jps/model/java/JavaModuleExtension.java b/jps/model-api/src/org/jetbrains/jps/model/java/JpsJavaModuleExtension.java similarity index 51% rename from jps/model-api/src/org/jetbrains/jps/model/java/JavaModuleExtension.java rename to jps/model-api/src/org/jetbrains/jps/model/java/JpsJavaModuleExtension.java index 1ac6c18b42a4..f2c7bdcc2986 100644 --- a/jps/model-api/src/org/jetbrains/jps/model/java/JavaModuleExtension.java +++ b/jps/model-api/src/org/jetbrains/jps/model/java/JpsJavaModuleExtension.java @@ -1,11 +1,15 @@ package org.jetbrains.jps.model.java; import org.jetbrains.jps.model.JpsElement; +import org.jetbrains.jps.model.JpsUrlList; /** * @author nik */ -public interface JavaModuleExtension extends JpsElement { +public interface JpsJavaModuleExtension extends JpsElement { + JpsUrlList getJavadocRoots(); + + JpsUrlList getAnnotationRoots(); String getOutputUrl(); @@ -18,4 +22,12 @@ public interface JavaModuleExtension extends JpsElement { LanguageLevel getLanguageLevel(); void setLanguageLevel(LanguageLevel languageLevel); + + boolean isInheritOutput(); + + void setInheritOutput(boolean inheritOutput); + + boolean isExcludeOutput(); + + void setExcludeOutput(boolean excludeOutput); } diff --git a/jps/model-api/src/org/jetbrains/jps/model/library/JpsLibraryRootType.java b/jps/model-api/src/org/jetbrains/jps/model/library/JpsLibraryRootType.java index 70afc3f5e8ee..707344331440 100644 --- a/jps/model-api/src/org/jetbrains/jps/model/library/JpsLibraryRootType.java +++ b/jps/model-api/src/org/jetbrains/jps/model/library/JpsLibraryRootType.java @@ -4,14 +4,16 @@ package org.jetbrains.jps.model.library; * @author nik */ public class JpsLibraryRootType { - public static final JpsLibraryRootType COMPILED = new JpsLibraryRootType(JpsOrderRootType.COMPILED, false); - public static final JpsLibraryRootType SOURCES = new JpsLibraryRootType(JpsOrderRootType.SOURCES, false); + public static final JpsLibraryRootType COMPILED = new JpsLibraryRootType(JpsOrderRootType.COMPILED, false, false); + public static final JpsLibraryRootType SOURCES = new JpsLibraryRootType(JpsOrderRootType.SOURCES, false, false); private final boolean myJarDirectory; + private final boolean myRecursive; private final JpsOrderRootType myType; - public JpsLibraryRootType(JpsOrderRootType type, boolean jarDirectory) { - myType = type; + public JpsLibraryRootType(JpsOrderRootType type, boolean jarDirectory, boolean recursive) { myJarDirectory = jarDirectory; + myRecursive = recursive; + myType = type; } public boolean isJarDirectory() { @@ -21,4 +23,8 @@ public class JpsLibraryRootType { public JpsOrderRootType getType() { return myType; } + + public boolean isRecursive() { + return myRecursive; + } } diff --git a/jps/model-api/src/org/jetbrains/jps/model/module/JpsModule.java b/jps/model-api/src/org/jetbrains/jps/model/module/JpsModule.java index fdc54705c502..88aa5b375f8e 100644 --- a/jps/model-api/src/org/jetbrains/jps/model/module/JpsModule.java +++ b/jps/model-api/src/org/jetbrains/jps/model/module/JpsModule.java @@ -42,6 +42,9 @@ public interface JpsModule extends JpsNamedElement, JpsReferenceableElement type, @NotNull String name); + @NotNull + JpsLibrary addModuleLibrary(@NotNull JpsLibrary library); + void delete(); @NotNull diff --git a/jps/model-api/src/org/jetbrains/jps/service/JpsServiceManager.java b/jps/model-api/src/org/jetbrains/jps/service/JpsServiceManager.java index d24524ca3664..2f86a7898341 100644 --- a/jps/model-api/src/org/jetbrains/jps/service/JpsServiceManager.java +++ b/jps/model-api/src/org/jetbrains/jps/service/JpsServiceManager.java @@ -12,8 +12,11 @@ public abstract class JpsServiceManager { public abstract T getService(Class serviceClass); + public abstract Iterable getExtensions(Class extensionClass); + private static class InstanceHolder { private static final JpsServiceManager INSTANCE; + static { INSTANCE = ServiceLoader.load(JpsServiceManager.class).iterator().next(); } diff --git a/jps/model-impl/src/META-INF/services/org.jetbrains.jps.model.java.JpsJavaExtensionService b/jps/model-impl/src/META-INF/services/org.jetbrains.jps.model.java.JpsJavaExtensionService new file mode 100644 index 000000000000..3d58916622f6 --- /dev/null +++ b/jps/model-impl/src/META-INF/services/org.jetbrains.jps.model.java.JpsJavaExtensionService @@ -0,0 +1 @@ +org.jetbrains.jps.model.java.impl.JpsJavaExtensionServiceImpl \ No newline at end of file diff --git a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementBase.java b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementBase.java index df9e701f815e..dd53713729d0 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementBase.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementBase.java @@ -10,7 +10,7 @@ import org.jetbrains.jps.model.*; */ public abstract class JpsElementBase> implements JpsElement, JpsElement.BulkModificationSupport { private static final Logger LOG = Logger.getInstance("#org.jetbrains.jps.model.impl.JpsElementBase"); - protected JpsElementBase> myParent; + protected JpsElementBase myParent; protected JpsElementBase() { } @@ -60,7 +60,7 @@ public abstract class JpsElementBase> implemen public abstract void applyChanges(@NotNull Self modified); - public JpsElementBase> getParent() { + public JpsElementBase getParent() { return myParent; } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementCollectionKind.java b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementCollectionKind.java index aae141b3b861..288f33e97dc2 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementCollectionKind.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementCollectionKind.java @@ -6,11 +6,12 @@ import org.jetbrains.jps.model.*; /** * @author nik */ -public class JpsElementCollectionKind extends JpsElementKind> +public class JpsElementCollectionKind extends JpsElementKindBase> implements JpsElementCreator> { private final JpsElementKind myElementKind; public JpsElementCollectionKind(JpsElementKind elementKind) { + super("collection of " + elementKind); myElementKind = elementKind; } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementFactoryImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementFactoryImpl.java index 70492b460fe7..21902607503a 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementFactoryImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementFactoryImpl.java @@ -2,15 +2,32 @@ package org.jetbrains.jps.model.impl; import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.model.*; +import org.jetbrains.jps.model.library.JpsLibrary; import org.jetbrains.jps.model.library.JpsLibraryReference; +import org.jetbrains.jps.model.library.JpsLibraryType; +import org.jetbrains.jps.model.library.impl.JpsLibraryImpl; import org.jetbrains.jps.model.library.impl.JpsLibraryReferenceImpl; +import org.jetbrains.jps.model.module.JpsModule; import org.jetbrains.jps.model.module.JpsModuleReference; +import org.jetbrains.jps.model.module.JpsModuleType; +import org.jetbrains.jps.model.module.impl.JpsModuleImpl; import org.jetbrains.jps.model.module.impl.JpsModuleReferenceImpl; /** * @author nik */ public class JpsElementFactoryImpl extends JpsElementFactory { + + @Override + public JpsModule createModule(String name, JpsModuleType> type) { + return new JpsModuleImpl(type, name); + } + + @Override + public JpsLibrary createLibrary(@NotNull String name, @NotNull JpsLibraryType> type) { + return new JpsLibraryImpl(name, type); + } + @NotNull @Override public JpsModuleReference createModuleReference(@NotNull String moduleName) { @@ -23,4 +40,16 @@ public class JpsElementFactoryImpl extends JpsElementFactory { @NotNull JpsElementReference extends JpsCompositeElement> parentReference) { return new JpsLibraryReferenceImpl(libraryName, parentReference); } + + @NotNull + @Override + public JpsElementReference createProjectReference() { + return new JpsProjectElementReference(); + } + + @NotNull + @Override + public JpsElementReference createGlobalReference() { + return new JpsGlobalElementReference(); + } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementKindBase.java b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementKindBase.java new file mode 100644 index 000000000000..faf964675b97 --- /dev/null +++ b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsElementKindBase.java @@ -0,0 +1,20 @@ +package org.jetbrains.jps.model.impl; + +import org.jetbrains.jps.model.JpsElement; +import org.jetbrains.jps.model.JpsElementKind; + +/** + * @author nik + */ +public class JpsElementKindBase extends JpsElementKind { + private String myDebugName; + + public JpsElementKindBase(String debugName) { + myDebugName = debugName; + } + + @Override + public String toString() { + return myDebugName; + } +} diff --git a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsGlobalImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsGlobalImpl.java index c5bb2c500b64..f48ad0d0f365 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsGlobalImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsGlobalImpl.java @@ -23,7 +23,7 @@ public class JpsGlobalImpl extends JpsRootElementBase implements @NotNull @Override public JpsLibrary addLibrary(@NotNull JpsLibraryType libraryType, @NotNull final String name) { - final JpsElementCollectionImpl collection = myContainer.getChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND); + final JpsElementCollectionImpl collection = myContainer.getChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND); return collection.addChild(new JpsLibraryImpl(name, libraryType)); } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsNamedElementReferenceBase.java b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsNamedElementReferenceBase.java index 3e00ac907e7e..94bbe930b864 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsNamedElementReferenceBase.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsNamedElementReferenceBase.java @@ -9,7 +9,7 @@ import java.util.List; * @author nik */ public abstract class JpsNamedElementReferenceBase> extends JpsCompositeElementBase implements JpsElementReference { - private static final JpsElementKind> PARENT_REFERENCE_KIND = new JpsElementKind>(); + private static final JpsElementKind> PARENT_REFERENCE_KIND = new JpsElementKindBase>("parent"); private final JpsElementCollectionKind extends T> myCollectionKind; protected final String myElementName; diff --git a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsProjectImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsProjectImpl.java index 3720c0ba1190..e70099f276da 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsProjectImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsProjectImpl.java @@ -17,7 +17,8 @@ import java.util.List; * @author nik */ public class JpsProjectImpl extends JpsRootElementBase implements JpsProject { - private static final JpsElementCollectionKind> EXTERNAL_REFERENCES_COLLECTION_KIND = new JpsElementCollectionKind>(new JpsElementKind>()); + private static final JpsElementCollectionKind> EXTERNAL_REFERENCES_COLLECTION_KIND = + new JpsElementCollectionKind>(new JpsElementKindBase>("external reference")); public JpsProjectImpl(JpsModel model, JpsEventDispatcher eventDispatcher) { super(model, eventDispatcher); @@ -37,14 +38,14 @@ public class JpsProjectImpl extends JpsRootElementBase implement @NotNull @Override public JpsModule addModule(@NotNull JpsModuleType> moduleType, @NotNull final String name) { - final JpsElementCollectionImpl collection = myContainer.getChild(JpsModuleKind.MODULE_COLLECTION_KIND); + final JpsElementCollectionImpl collection = myContainer.getChild(JpsModuleKind.MODULE_COLLECTION_KIND); return collection.addChild(new JpsModuleImpl(moduleType, name)); } @NotNull @Override public JpsLibrary addLibrary(@NotNull JpsLibraryType> libraryType, @NotNull final String name) { - final JpsElementCollectionImpl collection = myContainer.getChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND); + final JpsElementCollectionImpl collection = myContainer.getChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND); return collection.addChild(new JpsLibraryImpl(name, libraryType)); } @@ -60,6 +61,16 @@ public class JpsProjectImpl extends JpsRootElementBase implement return myContainer.getChild(JpsModuleKind.MODULE_COLLECTION_KIND).getElements(); } + @Override + public void addModule(JpsModule module) { + myContainer.getChild(JpsModuleKind.MODULE_COLLECTION_KIND).addChild(module); + } + + @Override + public void addLibrary(JpsLibrary library) { + myContainer.getChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND).addChild(library); + } + @NotNull @Override public JpsElementReference createReference() { diff --git a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsTypedDataKind.java b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsTypedDataKind.java index 16805bb40611..7033d720cda2 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsTypedDataKind.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsTypedDataKind.java @@ -1,10 +1,12 @@ package org.jetbrains.jps.model.impl; -import org.jetbrains.jps.model.JpsElementKind; import org.jetbrains.jps.model.JpsElementType; /** * @author nik */ -public class JpsTypedDataKind> extends JpsElementKind> { +public class JpsTypedDataKind> extends JpsElementKindBase> { + public JpsTypedDataKind() { + super("typed data"); + } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsUrlListKind.java b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsUrlListKind.java new file mode 100644 index 000000000000..95c6f2e1ac0f --- /dev/null +++ b/jps/model-impl/src/org/jetbrains/jps/model/impl/JpsUrlListKind.java @@ -0,0 +1,20 @@ +package org.jetbrains.jps.model.impl; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.model.JpsElementCreator; +import org.jetbrains.jps.model.JpsUrlList; + +/** + * @author nik + */ +public class JpsUrlListKind extends JpsElementKindBase implements JpsElementCreator { + public JpsUrlListKind(String debugName) { + super(debugName); + } + + @NotNull + @Override + public JpsUrlList create() { + return new JpsUrlListImpl(); + } +} diff --git a/jps/model-impl/src/org/jetbrains/jps/model/impl/SimpleJpsElementKind.java b/jps/model-impl/src/org/jetbrains/jps/model/impl/SimpleJpsElementKind.java index 9e670f918f04..d7bd4ea531b6 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/impl/SimpleJpsElementKind.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/impl/SimpleJpsElementKind.java @@ -1,11 +1,13 @@ package org.jetbrains.jps.model.impl; -import org.jetbrains.jps.model.JpsElementKind; import org.jetbrains.jps.model.JpsElementProperties; /** * @author nik */ public class SimpleJpsElementKind> extends - JpsElementKind> { + JpsElementKindBase> { + public SimpleJpsElementKind(String debugName) { + super(debugName); + } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/ExplodedDirectoryModuleExtensionImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/ExplodedDirectoryModuleExtensionImpl.java new file mode 100644 index 000000000000..e8a03bf27cb2 --- /dev/null +++ b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/ExplodedDirectoryModuleExtensionImpl.java @@ -0,0 +1,65 @@ +package org.jetbrains.jps.model.java.impl; + +import com.intellij.openapi.util.Comparing; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.model.impl.JpsElementBase; +import org.jetbrains.jps.model.impl.JpsElementKindBase; +import org.jetbrains.jps.model.java.ExplodedDirectoryModuleExtension; + +/** + * @author nik + */ +public class ExplodedDirectoryModuleExtensionImpl extends JpsElementBase implements + ExplodedDirectoryModuleExtension { + public static final JpsElementKindBase KIND = + new JpsElementKindBase("exploded directory"); + + private String myExplodedUrl; + private boolean myExcludeExploded; + + public ExplodedDirectoryModuleExtensionImpl() { + } + + public ExplodedDirectoryModuleExtensionImpl(ExplodedDirectoryModuleExtensionImpl original) { + myExcludeExploded = original.myExcludeExploded; + myExplodedUrl = original.myExplodedUrl; + } + + @Override + public String getExplodedUrl() { + return myExplodedUrl; + } + + @Override + public void setExplodedUrl(String explodedUrl) { + if (!Comparing.equal(myExplodedUrl, explodedUrl)) { + myExplodedUrl = explodedUrl; + fireElementChanged(); + } + } + + @Override + public boolean isExcludeExploded() { + return myExcludeExploded; + } + + @Override + public void setExcludeExploded(boolean excludeExploded) { + if (myExcludeExploded != excludeExploded) { + myExcludeExploded = excludeExploded; + fireElementChanged(); + } + } + + @NotNull + @Override + public ExplodedDirectoryModuleExtensionImpl createCopy() { + return new ExplodedDirectoryModuleExtensionImpl(this); + } + + @Override + public void applyChanges(@NotNull ExplodedDirectoryModuleExtensionImpl modified) { + setExcludeExploded(modified.myExcludeExploded); + setExplodedUrl(modified.myExplodedUrl); + } +} diff --git a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaModuleExtensionImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaModuleExtensionImpl.java deleted file mode 100644 index 4bf2a2b70bc5..000000000000 --- a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaModuleExtensionImpl.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.jetbrains.jps.model.java.impl; - -import com.intellij.openapi.util.Comparing; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.impl.JpsElementBase; -import org.jetbrains.jps.model.java.JavaModuleExtension; -import org.jetbrains.jps.model.java.LanguageLevel; - -/** - * @author nik - */ -public class JavaModuleExtensionImpl extends JpsElementBase implements JavaModuleExtension { - private String myOutputUrl; - private String myTestOutputUrl; - private LanguageLevel myLanguageLevel; - - public JavaModuleExtensionImpl() { - } - - public JavaModuleExtensionImpl(JavaModuleExtensionImpl original) { - myOutputUrl = original.myOutputUrl; - myTestOutputUrl = original.myTestOutputUrl; - myLanguageLevel = original.myLanguageLevel; - } - - @NotNull - @Override - public JavaModuleExtensionImpl createCopy() { - return new JavaModuleExtensionImpl(this); - } - - @Override - public String getOutputUrl() { - return myOutputUrl; - } - - @Override - public void setOutputUrl(String outputUrl) { - if (!Comparing.equal(myOutputUrl, outputUrl)) { - myOutputUrl = outputUrl; - fireElementChanged(); - } - } - - @Override - public String getTestOutputUrl() { - return myTestOutputUrl; - } - - @Override - public void setTestOutputUrl(String testOutputUrl) { - if (!Comparing.equal(myTestOutputUrl, testOutputUrl)) { - myTestOutputUrl = testOutputUrl; - fireElementChanged(); - } - } - - @Override - public LanguageLevel getLanguageLevel() { - return myLanguageLevel; - } - - @Override - public void setLanguageLevel(LanguageLevel languageLevel) { - if (!Comparing.equal(myLanguageLevel, languageLevel)) { - myLanguageLevel = languageLevel; - fireElementChanged(); - } - } - - public void applyChanges(@NotNull JavaModuleExtensionImpl modified) { - setLanguageLevel(modified.myLanguageLevel); - setOutputUrl(modified.myOutputUrl); - setTestOutputUrl(modified.myTestOutputUrl); - } -} diff --git a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaModuleExtensionKind.java b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaModuleExtensionKind.java index 2bf771e90fc1..d46529ff5010 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaModuleExtensionKind.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaModuleExtensionKind.java @@ -1,28 +1,23 @@ package org.jetbrains.jps.model.java.impl; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.*; -import org.jetbrains.jps.model.java.JavaModuleExtension; -import org.jetbrains.jps.model.module.JpsModule; +import org.jetbrains.jps.model.JpsElementCreator; +import org.jetbrains.jps.model.impl.JpsElementKindBase; /** * @author nik */ -public class JavaModuleExtensionKind extends JpsElementKind implements JpsElementCreator { - private static final JavaModuleExtensionKind INSTANCE = new JavaModuleExtensionKind(); +public class JavaModuleExtensionKind extends JpsElementKindBase + implements JpsElementCreator { + public static final JavaModuleExtensionKind INSTANCE = new JavaModuleExtensionKind(); + + private JavaModuleExtensionKind() { + super("java module extension"); + } @NotNull @Override - public JavaModuleExtensionImpl create() { - return new JavaModuleExtensionImpl(); - } - - @NotNull - public static JavaModuleExtension getExtension(@NotNull JpsModule module) { - JavaModuleExtension child = module.getContainer().getChild(INSTANCE); - if (child == null) { - child = module.getContainer().setChild(INSTANCE); - } - return child; + public JpsJavaModuleExtensionImpl create() { + return new JpsJavaModuleExtensionImpl(); } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaDependencyExtensionKind.java b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaDependencyExtensionKind.java index c15df483d74e..48555c5b7de7 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaDependencyExtensionKind.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaDependencyExtensionKind.java @@ -1,28 +1,24 @@ package org.jetbrains.jps.model.java.impl; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.*; -import org.jetbrains.jps.model.java.JpsJavaDependencyExtension; +import org.jetbrains.jps.model.JpsElementCreator; +import org.jetbrains.jps.model.impl.JpsElementKindBase; import org.jetbrains.jps.model.java.JpsJavaDependencyScope; -import org.jetbrains.jps.model.module.JpsDependencyElement; /** * @author nik */ -public class JpsJavaDependencyExtensionKind extends JpsElementKind implements JpsElementCreator { +public class JpsJavaDependencyExtensionKind extends JpsElementKindBase + implements JpsElementCreator { public static final JpsJavaDependencyExtensionKind INSTANCE = new JpsJavaDependencyExtensionKind(); + private JpsJavaDependencyExtensionKind() { + super("java dependency extension"); + } + @NotNull @Override public JpsJavaDependencyExtensionImpl create() { return new JpsJavaDependencyExtensionImpl(false, JpsJavaDependencyScope.COMPILE); } - - public static JpsJavaDependencyExtension getExtension(@NotNull JpsDependencyElement element) { - JpsJavaDependencyExtensionImpl extension = element.getContainer().getChild(INSTANCE); - if (extension == null) { - extension = element.getContainer().setChild(INSTANCE); - } - return extension; - } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaExtensionServiceImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaExtensionServiceImpl.java new file mode 100644 index 000000000000..c85f1ec5746f --- /dev/null +++ b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaExtensionServiceImpl.java @@ -0,0 +1,57 @@ +package org.jetbrains.jps.model.java.impl; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.model.JpsElementKind; +import org.jetbrains.jps.model.java.ExplodedDirectoryModuleExtension; +import org.jetbrains.jps.model.java.JpsJavaModuleExtension; +import org.jetbrains.jps.model.java.JpsJavaDependencyExtension; +import org.jetbrains.jps.model.java.JpsJavaExtensionService; +import org.jetbrains.jps.model.module.JpsDependencyElement; +import org.jetbrains.jps.model.module.JpsModule; + +/** + * @author nik + */ +public class JpsJavaExtensionServiceImpl extends JpsJavaExtensionService { + @NotNull + @Override + public JpsJavaModuleExtension getOrCreateModuleExtension(@NotNull JpsModule module) { + JpsJavaModuleExtension child = module.getContainer().getChild(JavaModuleExtensionKind.INSTANCE); + if (child == null) { + child = module.getContainer().setChild(JavaModuleExtensionKind.INSTANCE); + } + return child; + } + + @NotNull + @Override + public JpsJavaDependencyExtension getOrCreateDependencyExtension(@NotNull JpsDependencyElement dependency) { + JpsJavaDependencyExtensionImpl extension = dependency.getContainer().getChild(JpsJavaDependencyExtensionKind.INSTANCE); + if (extension == null) { + extension = dependency.getContainer().setChild(JpsJavaDependencyExtensionKind.INSTANCE); + } + return extension; + } + + @NotNull + @Override + public JpsElementKind extends JpsJavaModuleExtension> getModuleExtensionKind() { + return JavaModuleExtensionKind.INSTANCE; + } + + @NotNull + @Override + public JpsElementKind extends JpsJavaDependencyExtension> getDependencyExtensionKind() { + return JpsJavaDependencyExtensionKind.INSTANCE; + } + + @Override + @NotNull + public ExplodedDirectoryModuleExtension getOrCreateExplodedDirectoryExtension(@NotNull JpsModule module) { + ExplodedDirectoryModuleExtension extension = module.getContainer().getChild(ExplodedDirectoryModuleExtensionImpl.KIND); + if (extension == null) { + extension = module.getContainer().setChild(ExplodedDirectoryModuleExtensionImpl.KIND, new ExplodedDirectoryModuleExtensionImpl()); + } + return extension; + } +} diff --git a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaModuleExtensionImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaModuleExtensionImpl.java new file mode 100644 index 000000000000..0dba7526275a --- /dev/null +++ b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaModuleExtensionImpl.java @@ -0,0 +1,121 @@ +package org.jetbrains.jps.model.java.impl; + +import com.intellij.openapi.util.Comparing; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.model.JpsUrlList; +import org.jetbrains.jps.model.impl.JpsCompositeElementBase; +import org.jetbrains.jps.model.impl.JpsUrlListKind; +import org.jetbrains.jps.model.java.JpsJavaModuleExtension; +import org.jetbrains.jps.model.java.LanguageLevel; + +/** + * @author nik + */ +public class JpsJavaModuleExtensionImpl extends JpsCompositeElementBase implements JpsJavaModuleExtension { + private static final JpsUrlListKind JAVADOC_ROOTS_KIND = new JpsUrlListKind("javadoc roots"); + private static final JpsUrlListKind ANNOTATIONS_ROOTS_KIND = new JpsUrlListKind("annotation roots"); + private String myOutputUrl; + private String myTestOutputUrl; + private boolean myInheritOutput; + private boolean myExcludeOutput; + private LanguageLevel myLanguageLevel; + + public JpsJavaModuleExtensionImpl() { + myContainer.setChild(JAVADOC_ROOTS_KIND); + myContainer.setChild(ANNOTATIONS_ROOTS_KIND); + } + + public JpsJavaModuleExtensionImpl(JpsJavaModuleExtensionImpl original) { + super(original); + myOutputUrl = original.myOutputUrl; + myTestOutputUrl = original.myTestOutputUrl; + myLanguageLevel = original.myLanguageLevel; + } + + @NotNull + @Override + public JpsJavaModuleExtensionImpl createCopy() { + return new JpsJavaModuleExtensionImpl(this); + } + + @Override + public JpsUrlList getAnnotationRoots() { + return myContainer.getChild(ANNOTATIONS_ROOTS_KIND); + } + + @Override + public JpsUrlList getJavadocRoots() { + return myContainer.getChild(JAVADOC_ROOTS_KIND); + } + + @Override + public String getOutputUrl() { + return myOutputUrl; + } + + @Override + public void setOutputUrl(String outputUrl) { + if (!Comparing.equal(myOutputUrl, outputUrl)) { + myOutputUrl = outputUrl; + fireElementChanged(); + } + } + + @Override + public String getTestOutputUrl() { + return myTestOutputUrl; + } + + @Override + public void setTestOutputUrl(String testOutputUrl) { + if (!Comparing.equal(myTestOutputUrl, testOutputUrl)) { + myTestOutputUrl = testOutputUrl; + fireElementChanged(); + } + } + + @Override + public LanguageLevel getLanguageLevel() { + return myLanguageLevel; + } + + @Override + public void setLanguageLevel(LanguageLevel languageLevel) { + if (!Comparing.equal(myLanguageLevel, languageLevel)) { + myLanguageLevel = languageLevel; + fireElementChanged(); + } + } + + public void applyChanges(@NotNull JpsJavaModuleExtensionImpl modified) { + setLanguageLevel(modified.myLanguageLevel); + setOutputUrl(modified.myOutputUrl); + setTestOutputUrl(modified.myTestOutputUrl); + } + + @Override + public boolean isInheritOutput() { + return myInheritOutput; + } + + @Override + public void setInheritOutput(boolean inheritOutput) { + if (myInheritOutput != inheritOutput) { + myInheritOutput = inheritOutput; + fireElementChanged(); + } + } + + @Override + public boolean isExcludeOutput() { + return myExcludeOutput; + } + + @Override + public void setExcludeOutput(boolean excludeOutput) { + if (myExcludeOutput != excludeOutput) { + myExcludeOutput = excludeOutput; + fireElementChanged(); + } + } +} diff --git a/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryImpl.java index fb3794aae814..beb49333b109 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryImpl.java @@ -15,7 +15,8 @@ import java.util.List; * @author nik */ public class JpsLibraryImpl extends JpsNamedCompositeElementBase implements JpsLibrary { - private static final JpsElementCollectionKind LIBRARY_ROOTS_COLLECTION = new JpsElementCollectionKind(JpsLibraryRootKind.INSTANCE); + private static final JpsElementCollectionKind LIBRARY_ROOTS_COLLECTION = + new JpsElementCollectionKind(JpsLibraryRootKind.INSTANCE); private static final JpsTypedDataKind> TYPED_DATA_KIND = new JpsTypedDataKind>(); public JpsLibraryImpl(@NotNull String name, @NotNull JpsLibraryType> type) { @@ -65,8 +66,9 @@ public class JpsLibraryImpl extends JpsNamedCompositeElementBase getParent() { - return (JpsElementCollectionImpl)myParent; + public JpsElementCollectionImpl getParent() { + //noinspection unchecked + return (JpsElementCollectionImpl)myParent; } @NotNull @@ -79,7 +81,8 @@ public class JpsLibraryImpl extends JpsNamedCompositeElementBase parentReference = ((JpsReferenceableElement)getParent().getParent()).createReference(); + final JpsElementReference parentReference = + ((JpsReferenceableElement)getParent().getParent()).createReference(); return new JpsLibraryReferenceImpl(getName(), parentReference); } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryKind.java b/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryKind.java index 834ada9984fb..c6da7110d833 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryKind.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryKind.java @@ -1,28 +1,30 @@ package org.jetbrains.jps.model.library.impl; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.JpsElementKind; import org.jetbrains.jps.model.JpsEventDispatcher; import org.jetbrains.jps.model.impl.JpsElementCollectionKind; +import org.jetbrains.jps.model.impl.JpsElementKindBase; +import org.jetbrains.jps.model.library.JpsLibrary; import org.jetbrains.jps.model.library.JpsLibraryListener; /** * @author nik */ -public class JpsLibraryKind extends JpsElementKind { +public class JpsLibraryKind extends JpsElementKindBase { public static final JpsLibraryKind INSTANCE = new JpsLibraryKind(); - public static final JpsElementCollectionKind LIBRARIES_COLLECTION_KIND = new JpsElementCollectionKind(INSTANCE); + public static final JpsElementCollectionKind LIBRARIES_COLLECTION_KIND = new JpsElementCollectionKind(INSTANCE); private JpsLibraryKind() { + super("library"); } @Override - public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsLibraryImpl element) { + public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsLibrary element) { dispatcher.getPublisher(JpsLibraryListener.class).libraryAdded(element); } @Override - public void fireElementRemoved(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsLibraryImpl element) { + public void fireElementRemoved(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsLibrary element) { dispatcher.getPublisher(JpsLibraryListener.class).libraryRemoved(element); } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryRootKind.java b/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryRootKind.java index 4043b76287ce..f01d8cc843c6 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryRootKind.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryRootKind.java @@ -1,16 +1,20 @@ package org.jetbrains.jps.model.library.impl; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.JpsElementKind; +import org.jetbrains.jps.model.impl.JpsElementKindBase; import org.jetbrains.jps.model.JpsEventDispatcher; import org.jetbrains.jps.model.library.JpsLibraryRootListener; /** * @author nik */ -public class JpsLibraryRootKind extends JpsElementKind { +public class JpsLibraryRootKind extends JpsElementKindBase { public static final JpsLibraryRootKind INSTANCE = new JpsLibraryRootKind(); + public JpsLibraryRootKind() { + super("library root"); + } + @Override public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsLibraryRootImpl element) { dispatcher.getPublisher(JpsLibraryRootListener.class).rootAdded(element); diff --git a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsDependenciesListImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsDependenciesListImpl.java index e5c04b68cacb..6281eb2ed117 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsDependenciesListImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsDependenciesListImpl.java @@ -1,7 +1,7 @@ package org.jetbrains.jps.model.module.impl; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.JpsElementKind; +import org.jetbrains.jps.model.impl.JpsElementKindBase; import org.jetbrains.jps.model.impl.JpsCompositeElementBase; import org.jetbrains.jps.model.impl.JpsElementCollectionKind; import org.jetbrains.jps.model.library.JpsLibrary; @@ -15,8 +15,8 @@ import java.util.List; * @author nik */ public class JpsDependenciesListImpl extends JpsCompositeElementBase implements JpsDependenciesList { - public static final JpsElementKind> DEPENDENCY_ELEMENT_KIND = new JpsElementKind>(); - public static final JpsElementCollectionKind> DEPENDENCY_COLLECTION_KIND = new JpsElementCollectionKind>(DEPENDENCY_ELEMENT_KIND); + public static final JpsElementCollectionKind> DEPENDENCY_COLLECTION_KIND = + new JpsElementCollectionKind>(new JpsElementKindBase>("dependency")); public JpsDependenciesListImpl() { super(); diff --git a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsLibraryDependencyImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsLibraryDependencyImpl.java index 7e2eba50a317..d9586addd602 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsLibraryDependencyImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsLibraryDependencyImpl.java @@ -2,6 +2,7 @@ package org.jetbrains.jps.model.module.impl; import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.model.*; +import org.jetbrains.jps.model.impl.JpsElementKindBase; import org.jetbrains.jps.model.library.JpsLibraryReference; import org.jetbrains.jps.model.module.JpsLibraryDependency; @@ -9,7 +10,7 @@ import org.jetbrains.jps.model.module.JpsLibraryDependency; * @author nik */ public class JpsLibraryDependencyImpl extends JpsDependencyElementBase implements JpsLibraryDependency { - public static final JpsElementKind LIBRARY_REFERENCE_KIND = new JpsElementKind(); + public static final JpsElementKind LIBRARY_REFERENCE_KIND = new JpsElementKindBase("library reference"); public JpsLibraryDependencyImpl(final JpsLibraryReference reference) { super(); diff --git a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleDependencyImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleDependencyImpl.java index 6fe796883168..143702c104cf 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleDependencyImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleDependencyImpl.java @@ -2,6 +2,7 @@ package org.jetbrains.jps.model.module.impl; import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.model.*; +import org.jetbrains.jps.model.impl.JpsElementKindBase; import org.jetbrains.jps.model.module.JpsModuleDependency; import org.jetbrains.jps.model.module.JpsModuleReference; @@ -9,7 +10,7 @@ import org.jetbrains.jps.model.module.JpsModuleReference; * @author nik */ public class JpsModuleDependencyImpl extends JpsDependencyElementBase implements JpsModuleDependency { - private static final JpsElementKind MODULE_REFERENCE_KIND = new JpsElementKind(); + private static final JpsElementKind MODULE_REFERENCE_KIND = new JpsElementKindBase("module reference"); public JpsModuleDependencyImpl(final JpsModuleReference moduleReference) { super(); diff --git a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleImpl.java index 7aabc147cae2..adb148b5da3d 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleImpl.java @@ -16,16 +16,17 @@ import java.util.List; */ public class JpsModuleImpl extends JpsNamedCompositeElementBase implements JpsModule { private static final JpsTypedDataKind> TYPED_DATA_KIND = new JpsTypedDataKind>(); - private static final JpsElementKind CONTENT_ROOTS_KIND = new JpsElementKind(); - private static final JpsElementKind EXCLUDED_ROOTS_KIND = new JpsElementKind(); - public static final JpsElementKind DEPENDENCIES_LIST_KIND = new JpsElementKind(); + private static final JpsUrlListKind CONTENT_ROOTS_KIND = new JpsUrlListKind("content roots"); + private static final JpsUrlListKind EXCLUDED_ROOTS_KIND = new JpsUrlListKind("excluded roots"); + public static final JpsElementKind DEPENDENCIES_LIST_KIND = + new JpsElementKindBase("dependencies"); public JpsModuleImpl(JpsModuleType type, @NotNull String name) { super(name); myContainer.setChild(TYPED_DATA_KIND, new JpsTypedDataImpl>(type)); - myContainer.setChild(CONTENT_ROOTS_KIND, new JpsUrlListImpl()); - myContainer.setChild(EXCLUDED_ROOTS_KIND, new JpsUrlListImpl()); + myContainer.setChild(CONTENT_ROOTS_KIND); + myContainer.setChild(EXCLUDED_ROOTS_KIND); myContainer.setChild(DEPENDENCIES_LIST_KIND, new JpsDependenciesListImpl()); myContainer.setChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND); myContainer.setChild(JpsModuleSourceRootKind.ROOT_COLLECTION_KIND); @@ -115,7 +116,12 @@ public class JpsModuleImpl extends JpsNamedCompositeElementBase type, @NotNull String name) { - final JpsElementCollectionImpl collection = myContainer.getChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND); - return collection.addChild(new JpsLibraryImpl(name, type)); + return addModuleLibrary(new JpsLibraryImpl(name, type)); + } + + @NotNull + @Override + public JpsLibrary addModuleLibrary(final @NotNull JpsLibrary library) { + return myContainer.getChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND).addChild(library); } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleKind.java b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleKind.java index 74621d367f0c..affce588f0b5 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleKind.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleKind.java @@ -4,22 +4,28 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.model.JpsElementKind; import org.jetbrains.jps.model.JpsEventDispatcher; import org.jetbrains.jps.model.impl.JpsElementCollectionKind; +import org.jetbrains.jps.model.impl.JpsElementKindBase; +import org.jetbrains.jps.model.module.JpsModule; import org.jetbrains.jps.model.module.JpsModuleListener; /** * @author nik */ -public class JpsModuleKind extends JpsElementKind { - public static final JpsElementKind INSTANCE = new JpsModuleKind(); - public static final JpsElementCollectionKind MODULE_COLLECTION_KIND = new JpsElementCollectionKind(INSTANCE); +public class JpsModuleKind extends JpsElementKindBase { + public static final JpsElementKind INSTANCE = new JpsModuleKind(); + public static final JpsElementCollectionKind MODULE_COLLECTION_KIND = new JpsElementCollectionKind(INSTANCE); + + public JpsModuleKind() { + super("module"); + } @Override - public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsModuleImpl element) { + public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsModule element) { dispatcher.getPublisher(JpsModuleListener.class).moduleAdded(element); } @Override - public void fireElementRemoved(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsModuleImpl element) { + public void fireElementRemoved(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsModule element) { dispatcher.getPublisher(JpsModuleListener.class).moduleRemoved(element); } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleSourceRootKind.java b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleSourceRootKind.java index 70e25abff2dc..11532f8a5f1b 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleSourceRootKind.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleSourceRootKind.java @@ -1,7 +1,7 @@ package org.jetbrains.jps.model.module.impl; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.JpsElementKind; +import org.jetbrains.jps.model.impl.JpsElementKindBase; import org.jetbrains.jps.model.JpsEventDispatcher; import org.jetbrains.jps.model.impl.JpsElementCollectionKind; import org.jetbrains.jps.model.module.JpsModuleSourceRootListener; @@ -9,10 +9,14 @@ import org.jetbrains.jps.model.module.JpsModuleSourceRootListener; /** * @author nik */ -public class JpsModuleSourceRootKind extends JpsElementKind { +public class JpsModuleSourceRootKind extends JpsElementKindBase { public static final JpsModuleSourceRootKind INSTANCE = new JpsModuleSourceRootKind(); public static final JpsElementCollectionKind ROOT_COLLECTION_KIND = new JpsElementCollectionKind(INSTANCE); + public JpsModuleSourceRootKind() { + super("module source root"); + } + @Override public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsModuleSourceRootImpl element) { dispatcher.getPublisher(JpsModuleSourceRootListener.class).sourceRootAdded(element); diff --git a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsSdkReferencesTableImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsSdkReferencesTableImpl.java index 4b7c81cbecd6..b8c0462ffcb7 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsSdkReferencesTableImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsSdkReferencesTableImpl.java @@ -2,6 +2,7 @@ package org.jetbrains.jps.model.module.impl; import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.model.JpsElementKind; +import org.jetbrains.jps.model.impl.JpsElementKindBase; import org.jetbrains.jps.model.impl.JpsCompositeElementBase; import org.jetbrains.jps.model.library.JpsLibraryReference; import org.jetbrains.jps.model.library.JpsSdkType; @@ -11,7 +12,7 @@ import org.jetbrains.jps.model.module.JpsSdkReferencesTable; * @author nik */ public class JpsSdkReferencesTableImpl extends JpsCompositeElementBase implements JpsSdkReferencesTable { - public static final JpsElementKind KIND = new JpsElementKind(); + public static final JpsElementKind KIND = new JpsElementKindBase("sdk references"); public JpsSdkReferencesTableImpl() { super(); @@ -37,10 +38,11 @@ public class JpsSdkReferencesTableImpl extends JpsCompositeElementBase { + private static class JpsSdkReferenceKind extends JpsElementKindBase { private final JpsSdkType> myType; private JpsSdkReferenceKind(@NotNull JpsSdkType> type) { + super("sdk reference " + type); myType = type; } diff --git a/jps/model-impl/src/org/jetbrains/jps/service/impl/JpsServiceManagerImpl.java b/jps/model-impl/src/org/jetbrains/jps/service/impl/JpsServiceManagerImpl.java index 4f9c546a4cef..960bcff17879 100644 --- a/jps/model-impl/src/org/jetbrains/jps/service/impl/JpsServiceManagerImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/service/impl/JpsServiceManagerImpl.java @@ -3,6 +3,7 @@ package org.jetbrains.jps.service.impl; import org.jetbrains.jps.service.JpsServiceManager; import java.util.Iterator; +import java.util.List; import java.util.ServiceConfigurationError; import java.util.ServiceLoader; import java.util.concurrent.ConcurrentHashMap; @@ -12,6 +13,7 @@ import java.util.concurrent.ConcurrentHashMap; */ public class JpsServiceManagerImpl extends JpsServiceManager { private final ConcurrentHashMap myServices = new ConcurrentHashMap(); + private final ConcurrentHashMap> myExtensions = new ConcurrentHashMap>(); @Override public T getService(Class serviceClass) { @@ -24,10 +26,16 @@ public class JpsServiceManagerImpl extends JpsServiceManager { } service = iterator.next(); if (iterator.hasNext()) { - throw new ServiceConfigurationError("More than one implementation for " + serviceClass + " found: " + service.getClass() + " and " + iterator.next().getClass()); + throw new ServiceConfigurationError( + "More than one implementation for " + serviceClass + " found: " + service.getClass() + " and " + iterator.next().getClass()); } myServices.putIfAbsent(serviceClass, service); } return service; } + + @Override + public Iterable getExtensions(Class extensionClass) { + return ServiceLoader.load(extensionClass); + } } diff --git a/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsJavaExtensionTest.java b/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsJavaExtensionTest.java index 0b5609390503..3e66b86643d5 100644 --- a/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsJavaExtensionTest.java +++ b/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsJavaExtensionTest.java @@ -1,11 +1,6 @@ package org.jetbrains.jps.model; -import org.jetbrains.jps.model.java.JpsJavaDependencyExtension; -import org.jetbrains.jps.model.java.JpsJavaDependencyScope; -import org.jetbrains.jps.model.java.JpsJavaLibraryType; -import org.jetbrains.jps.model.java.JpsJavaModuleType; -import org.jetbrains.jps.model.java.impl.JavaModuleExtensionKind; -import org.jetbrains.jps.model.java.impl.JpsJavaDependencyExtensionKind; +import org.jetbrains.jps.model.java.*; import org.jetbrains.jps.model.library.JpsLibrary; import org.jetbrains.jps.model.module.JpsDependencyElement; import org.jetbrains.jps.model.module.JpsLibraryDependency; @@ -17,8 +12,10 @@ import org.jetbrains.jps.model.module.JpsModule; public class JpsJavaExtensionTest extends JpsModelTestCase { public void testModule() { final JpsModule module = myModel.getProject().addModule(JpsJavaModuleType.INSTANCE, "m"); - JavaModuleExtensionKind.getExtension(module).setOutputUrl("file://path"); - assertEquals("file://path", JavaModuleExtensionKind.getExtension(module).getOutputUrl()); + final JpsJavaModuleExtension extension = JpsJavaExtensionService.getInstance().getOrCreateModuleExtension(module); + extension.setOutputUrl("file://path"); + assertEquals("file://path", + module.getContainer().getChild(JpsJavaExtensionService.getInstance().getModuleExtensionKind()).getOutputUrl()); } public void testDependency() { @@ -26,12 +23,14 @@ public class JpsJavaExtensionTest extends JpsModelTestCase { final JpsModule module = model.getProject().addModule(JpsJavaModuleType.INSTANCE, "m"); final JpsLibrary library = model.getProject().addLibrary(JpsJavaLibraryType.INSTANCE, "l"); final JpsLibraryDependency dependency = module.getDependenciesList().addLibraryDependency(library); - JpsJavaDependencyExtensionKind.getExtension(dependency).setScope(JpsJavaDependencyScope.TEST); - JpsJavaDependencyExtensionKind.getExtension(dependency).setExported(true); + JpsJavaExtensionService.getInstance().getOrCreateDependencyExtension(dependency).setScope(JpsJavaDependencyScope.TEST); + JpsJavaExtensionService.getInstance().getOrCreateDependencyExtension(dependency).setExported(true); model.commit(); - final JpsDependencyElement dep = assertOneElement(assertOneElement(myModel.getProject().getModules()).getDependenciesList().getDependencies()); - final JpsJavaDependencyExtension extension = dep.getContainer().getChild(JpsJavaDependencyExtensionKind.INSTANCE); + final JpsDependencyElement dep = + assertOneElement(assertOneElement(myModel.getProject().getModules()).getDependenciesList().getDependencies()); + final JpsJavaDependencyExtension extension = + dep.getContainer().getChild(JpsJavaExtensionService.getInstance().getDependencyExtensionKind()); assertTrue(extension.isExported()); assertSame(JpsJavaDependencyScope.TEST, extension.getScope()); } diff --git a/jps/model-serialization/jps-model-serialization.iml b/jps/model-serialization/jps-model-serialization.iml new file mode 100644 index 000000000000..2ed39f108303 --- /dev/null +++ b/jps/model-serialization/jps-model-serialization.iml @@ -0,0 +1,19 @@ + +
> extends - JpsElementKind> { + JpsElementKindBase> { + public SimpleJpsElementKind(String debugName) { + super(debugName); + } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/ExplodedDirectoryModuleExtensionImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/ExplodedDirectoryModuleExtensionImpl.java new file mode 100644 index 000000000000..e8a03bf27cb2 --- /dev/null +++ b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/ExplodedDirectoryModuleExtensionImpl.java @@ -0,0 +1,65 @@ +package org.jetbrains.jps.model.java.impl; + +import com.intellij.openapi.util.Comparing; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.model.impl.JpsElementBase; +import org.jetbrains.jps.model.impl.JpsElementKindBase; +import org.jetbrains.jps.model.java.ExplodedDirectoryModuleExtension; + +/** + * @author nik + */ +public class ExplodedDirectoryModuleExtensionImpl extends JpsElementBase implements + ExplodedDirectoryModuleExtension { + public static final JpsElementKindBase KIND = + new JpsElementKindBase("exploded directory"); + + private String myExplodedUrl; + private boolean myExcludeExploded; + + public ExplodedDirectoryModuleExtensionImpl() { + } + + public ExplodedDirectoryModuleExtensionImpl(ExplodedDirectoryModuleExtensionImpl original) { + myExcludeExploded = original.myExcludeExploded; + myExplodedUrl = original.myExplodedUrl; + } + + @Override + public String getExplodedUrl() { + return myExplodedUrl; + } + + @Override + public void setExplodedUrl(String explodedUrl) { + if (!Comparing.equal(myExplodedUrl, explodedUrl)) { + myExplodedUrl = explodedUrl; + fireElementChanged(); + } + } + + @Override + public boolean isExcludeExploded() { + return myExcludeExploded; + } + + @Override + public void setExcludeExploded(boolean excludeExploded) { + if (myExcludeExploded != excludeExploded) { + myExcludeExploded = excludeExploded; + fireElementChanged(); + } + } + + @NotNull + @Override + public ExplodedDirectoryModuleExtensionImpl createCopy() { + return new ExplodedDirectoryModuleExtensionImpl(this); + } + + @Override + public void applyChanges(@NotNull ExplodedDirectoryModuleExtensionImpl modified) { + setExcludeExploded(modified.myExcludeExploded); + setExplodedUrl(modified.myExplodedUrl); + } +} diff --git a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaModuleExtensionImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaModuleExtensionImpl.java deleted file mode 100644 index 4bf2a2b70bc5..000000000000 --- a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaModuleExtensionImpl.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.jetbrains.jps.model.java.impl; - -import com.intellij.openapi.util.Comparing; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.impl.JpsElementBase; -import org.jetbrains.jps.model.java.JavaModuleExtension; -import org.jetbrains.jps.model.java.LanguageLevel; - -/** - * @author nik - */ -public class JavaModuleExtensionImpl extends JpsElementBase implements JavaModuleExtension { - private String myOutputUrl; - private String myTestOutputUrl; - private LanguageLevel myLanguageLevel; - - public JavaModuleExtensionImpl() { - } - - public JavaModuleExtensionImpl(JavaModuleExtensionImpl original) { - myOutputUrl = original.myOutputUrl; - myTestOutputUrl = original.myTestOutputUrl; - myLanguageLevel = original.myLanguageLevel; - } - - @NotNull - @Override - public JavaModuleExtensionImpl createCopy() { - return new JavaModuleExtensionImpl(this); - } - - @Override - public String getOutputUrl() { - return myOutputUrl; - } - - @Override - public void setOutputUrl(String outputUrl) { - if (!Comparing.equal(myOutputUrl, outputUrl)) { - myOutputUrl = outputUrl; - fireElementChanged(); - } - } - - @Override - public String getTestOutputUrl() { - return myTestOutputUrl; - } - - @Override - public void setTestOutputUrl(String testOutputUrl) { - if (!Comparing.equal(myTestOutputUrl, testOutputUrl)) { - myTestOutputUrl = testOutputUrl; - fireElementChanged(); - } - } - - @Override - public LanguageLevel getLanguageLevel() { - return myLanguageLevel; - } - - @Override - public void setLanguageLevel(LanguageLevel languageLevel) { - if (!Comparing.equal(myLanguageLevel, languageLevel)) { - myLanguageLevel = languageLevel; - fireElementChanged(); - } - } - - public void applyChanges(@NotNull JavaModuleExtensionImpl modified) { - setLanguageLevel(modified.myLanguageLevel); - setOutputUrl(modified.myOutputUrl); - setTestOutputUrl(modified.myTestOutputUrl); - } -} diff --git a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaModuleExtensionKind.java b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaModuleExtensionKind.java index 2bf771e90fc1..d46529ff5010 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaModuleExtensionKind.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaModuleExtensionKind.java @@ -1,28 +1,23 @@ package org.jetbrains.jps.model.java.impl; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.*; -import org.jetbrains.jps.model.java.JavaModuleExtension; -import org.jetbrains.jps.model.module.JpsModule; +import org.jetbrains.jps.model.JpsElementCreator; +import org.jetbrains.jps.model.impl.JpsElementKindBase; /** * @author nik */ -public class JavaModuleExtensionKind extends JpsElementKind implements JpsElementCreator { - private static final JavaModuleExtensionKind INSTANCE = new JavaModuleExtensionKind(); +public class JavaModuleExtensionKind extends JpsElementKindBase + implements JpsElementCreator { + public static final JavaModuleExtensionKind INSTANCE = new JavaModuleExtensionKind(); + + private JavaModuleExtensionKind() { + super("java module extension"); + } @NotNull @Override - public JavaModuleExtensionImpl create() { - return new JavaModuleExtensionImpl(); - } - - @NotNull - public static JavaModuleExtension getExtension(@NotNull JpsModule module) { - JavaModuleExtension child = module.getContainer().getChild(INSTANCE); - if (child == null) { - child = module.getContainer().setChild(INSTANCE); - } - return child; + public JpsJavaModuleExtensionImpl create() { + return new JpsJavaModuleExtensionImpl(); } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaDependencyExtensionKind.java b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaDependencyExtensionKind.java index c15df483d74e..48555c5b7de7 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaDependencyExtensionKind.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaDependencyExtensionKind.java @@ -1,28 +1,24 @@ package org.jetbrains.jps.model.java.impl; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.*; -import org.jetbrains.jps.model.java.JpsJavaDependencyExtension; +import org.jetbrains.jps.model.JpsElementCreator; +import org.jetbrains.jps.model.impl.JpsElementKindBase; import org.jetbrains.jps.model.java.JpsJavaDependencyScope; -import org.jetbrains.jps.model.module.JpsDependencyElement; /** * @author nik */ -public class JpsJavaDependencyExtensionKind extends JpsElementKind implements JpsElementCreator { +public class JpsJavaDependencyExtensionKind extends JpsElementKindBase + implements JpsElementCreator { public static final JpsJavaDependencyExtensionKind INSTANCE = new JpsJavaDependencyExtensionKind(); + private JpsJavaDependencyExtensionKind() { + super("java dependency extension"); + } + @NotNull @Override public JpsJavaDependencyExtensionImpl create() { return new JpsJavaDependencyExtensionImpl(false, JpsJavaDependencyScope.COMPILE); } - - public static JpsJavaDependencyExtension getExtension(@NotNull JpsDependencyElement element) { - JpsJavaDependencyExtensionImpl extension = element.getContainer().getChild(INSTANCE); - if (extension == null) { - extension = element.getContainer().setChild(INSTANCE); - } - return extension; - } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaExtensionServiceImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaExtensionServiceImpl.java new file mode 100644 index 000000000000..c85f1ec5746f --- /dev/null +++ b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaExtensionServiceImpl.java @@ -0,0 +1,57 @@ +package org.jetbrains.jps.model.java.impl; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.model.JpsElementKind; +import org.jetbrains.jps.model.java.ExplodedDirectoryModuleExtension; +import org.jetbrains.jps.model.java.JpsJavaModuleExtension; +import org.jetbrains.jps.model.java.JpsJavaDependencyExtension; +import org.jetbrains.jps.model.java.JpsJavaExtensionService; +import org.jetbrains.jps.model.module.JpsDependencyElement; +import org.jetbrains.jps.model.module.JpsModule; + +/** + * @author nik + */ +public class JpsJavaExtensionServiceImpl extends JpsJavaExtensionService { + @NotNull + @Override + public JpsJavaModuleExtension getOrCreateModuleExtension(@NotNull JpsModule module) { + JpsJavaModuleExtension child = module.getContainer().getChild(JavaModuleExtensionKind.INSTANCE); + if (child == null) { + child = module.getContainer().setChild(JavaModuleExtensionKind.INSTANCE); + } + return child; + } + + @NotNull + @Override + public JpsJavaDependencyExtension getOrCreateDependencyExtension(@NotNull JpsDependencyElement dependency) { + JpsJavaDependencyExtensionImpl extension = dependency.getContainer().getChild(JpsJavaDependencyExtensionKind.INSTANCE); + if (extension == null) { + extension = dependency.getContainer().setChild(JpsJavaDependencyExtensionKind.INSTANCE); + } + return extension; + } + + @NotNull + @Override + public JpsElementKind extends JpsJavaModuleExtension> getModuleExtensionKind() { + return JavaModuleExtensionKind.INSTANCE; + } + + @NotNull + @Override + public JpsElementKind extends JpsJavaDependencyExtension> getDependencyExtensionKind() { + return JpsJavaDependencyExtensionKind.INSTANCE; + } + + @Override + @NotNull + public ExplodedDirectoryModuleExtension getOrCreateExplodedDirectoryExtension(@NotNull JpsModule module) { + ExplodedDirectoryModuleExtension extension = module.getContainer().getChild(ExplodedDirectoryModuleExtensionImpl.KIND); + if (extension == null) { + extension = module.getContainer().setChild(ExplodedDirectoryModuleExtensionImpl.KIND, new ExplodedDirectoryModuleExtensionImpl()); + } + return extension; + } +} diff --git a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaModuleExtensionImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaModuleExtensionImpl.java new file mode 100644 index 000000000000..0dba7526275a --- /dev/null +++ b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaModuleExtensionImpl.java @@ -0,0 +1,121 @@ +package org.jetbrains.jps.model.java.impl; + +import com.intellij.openapi.util.Comparing; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.model.JpsUrlList; +import org.jetbrains.jps.model.impl.JpsCompositeElementBase; +import org.jetbrains.jps.model.impl.JpsUrlListKind; +import org.jetbrains.jps.model.java.JpsJavaModuleExtension; +import org.jetbrains.jps.model.java.LanguageLevel; + +/** + * @author nik + */ +public class JpsJavaModuleExtensionImpl extends JpsCompositeElementBase implements JpsJavaModuleExtension { + private static final JpsUrlListKind JAVADOC_ROOTS_KIND = new JpsUrlListKind("javadoc roots"); + private static final JpsUrlListKind ANNOTATIONS_ROOTS_KIND = new JpsUrlListKind("annotation roots"); + private String myOutputUrl; + private String myTestOutputUrl; + private boolean myInheritOutput; + private boolean myExcludeOutput; + private LanguageLevel myLanguageLevel; + + public JpsJavaModuleExtensionImpl() { + myContainer.setChild(JAVADOC_ROOTS_KIND); + myContainer.setChild(ANNOTATIONS_ROOTS_KIND); + } + + public JpsJavaModuleExtensionImpl(JpsJavaModuleExtensionImpl original) { + super(original); + myOutputUrl = original.myOutputUrl; + myTestOutputUrl = original.myTestOutputUrl; + myLanguageLevel = original.myLanguageLevel; + } + + @NotNull + @Override + public JpsJavaModuleExtensionImpl createCopy() { + return new JpsJavaModuleExtensionImpl(this); + } + + @Override + public JpsUrlList getAnnotationRoots() { + return myContainer.getChild(ANNOTATIONS_ROOTS_KIND); + } + + @Override + public JpsUrlList getJavadocRoots() { + return myContainer.getChild(JAVADOC_ROOTS_KIND); + } + + @Override + public String getOutputUrl() { + return myOutputUrl; + } + + @Override + public void setOutputUrl(String outputUrl) { + if (!Comparing.equal(myOutputUrl, outputUrl)) { + myOutputUrl = outputUrl; + fireElementChanged(); + } + } + + @Override + public String getTestOutputUrl() { + return myTestOutputUrl; + } + + @Override + public void setTestOutputUrl(String testOutputUrl) { + if (!Comparing.equal(myTestOutputUrl, testOutputUrl)) { + myTestOutputUrl = testOutputUrl; + fireElementChanged(); + } + } + + @Override + public LanguageLevel getLanguageLevel() { + return myLanguageLevel; + } + + @Override + public void setLanguageLevel(LanguageLevel languageLevel) { + if (!Comparing.equal(myLanguageLevel, languageLevel)) { + myLanguageLevel = languageLevel; + fireElementChanged(); + } + } + + public void applyChanges(@NotNull JpsJavaModuleExtensionImpl modified) { + setLanguageLevel(modified.myLanguageLevel); + setOutputUrl(modified.myOutputUrl); + setTestOutputUrl(modified.myTestOutputUrl); + } + + @Override + public boolean isInheritOutput() { + return myInheritOutput; + } + + @Override + public void setInheritOutput(boolean inheritOutput) { + if (myInheritOutput != inheritOutput) { + myInheritOutput = inheritOutput; + fireElementChanged(); + } + } + + @Override + public boolean isExcludeOutput() { + return myExcludeOutput; + } + + @Override + public void setExcludeOutput(boolean excludeOutput) { + if (myExcludeOutput != excludeOutput) { + myExcludeOutput = excludeOutput; + fireElementChanged(); + } + } +} diff --git a/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryImpl.java index fb3794aae814..beb49333b109 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryImpl.java @@ -15,7 +15,8 @@ import java.util.List; * @author nik */ public class JpsLibraryImpl extends JpsNamedCompositeElementBase implements JpsLibrary { - private static final JpsElementCollectionKind LIBRARY_ROOTS_COLLECTION = new JpsElementCollectionKind(JpsLibraryRootKind.INSTANCE); + private static final JpsElementCollectionKind LIBRARY_ROOTS_COLLECTION = + new JpsElementCollectionKind(JpsLibraryRootKind.INSTANCE); private static final JpsTypedDataKind> TYPED_DATA_KIND = new JpsTypedDataKind>(); public JpsLibraryImpl(@NotNull String name, @NotNull JpsLibraryType> type) { @@ -65,8 +66,9 @@ public class JpsLibraryImpl extends JpsNamedCompositeElementBase getParent() { - return (JpsElementCollectionImpl)myParent; + public JpsElementCollectionImpl getParent() { + //noinspection unchecked + return (JpsElementCollectionImpl)myParent; } @NotNull @@ -79,7 +81,8 @@ public class JpsLibraryImpl extends JpsNamedCompositeElementBase parentReference = ((JpsReferenceableElement)getParent().getParent()).createReference(); + final JpsElementReference parentReference = + ((JpsReferenceableElement)getParent().getParent()).createReference(); return new JpsLibraryReferenceImpl(getName(), parentReference); } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryKind.java b/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryKind.java index 834ada9984fb..c6da7110d833 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryKind.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryKind.java @@ -1,28 +1,30 @@ package org.jetbrains.jps.model.library.impl; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.JpsElementKind; import org.jetbrains.jps.model.JpsEventDispatcher; import org.jetbrains.jps.model.impl.JpsElementCollectionKind; +import org.jetbrains.jps.model.impl.JpsElementKindBase; +import org.jetbrains.jps.model.library.JpsLibrary; import org.jetbrains.jps.model.library.JpsLibraryListener; /** * @author nik */ -public class JpsLibraryKind extends JpsElementKind { +public class JpsLibraryKind extends JpsElementKindBase { public static final JpsLibraryKind INSTANCE = new JpsLibraryKind(); - public static final JpsElementCollectionKind LIBRARIES_COLLECTION_KIND = new JpsElementCollectionKind(INSTANCE); + public static final JpsElementCollectionKind LIBRARIES_COLLECTION_KIND = new JpsElementCollectionKind(INSTANCE); private JpsLibraryKind() { + super("library"); } @Override - public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsLibraryImpl element) { + public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsLibrary element) { dispatcher.getPublisher(JpsLibraryListener.class).libraryAdded(element); } @Override - public void fireElementRemoved(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsLibraryImpl element) { + public void fireElementRemoved(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsLibrary element) { dispatcher.getPublisher(JpsLibraryListener.class).libraryRemoved(element); } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryRootKind.java b/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryRootKind.java index 4043b76287ce..f01d8cc843c6 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryRootKind.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryRootKind.java @@ -1,16 +1,20 @@ package org.jetbrains.jps.model.library.impl; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.JpsElementKind; +import org.jetbrains.jps.model.impl.JpsElementKindBase; import org.jetbrains.jps.model.JpsEventDispatcher; import org.jetbrains.jps.model.library.JpsLibraryRootListener; /** * @author nik */ -public class JpsLibraryRootKind extends JpsElementKind { +public class JpsLibraryRootKind extends JpsElementKindBase { public static final JpsLibraryRootKind INSTANCE = new JpsLibraryRootKind(); + public JpsLibraryRootKind() { + super("library root"); + } + @Override public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsLibraryRootImpl element) { dispatcher.getPublisher(JpsLibraryRootListener.class).rootAdded(element); diff --git a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsDependenciesListImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsDependenciesListImpl.java index e5c04b68cacb..6281eb2ed117 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsDependenciesListImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsDependenciesListImpl.java @@ -1,7 +1,7 @@ package org.jetbrains.jps.model.module.impl; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.JpsElementKind; +import org.jetbrains.jps.model.impl.JpsElementKindBase; import org.jetbrains.jps.model.impl.JpsCompositeElementBase; import org.jetbrains.jps.model.impl.JpsElementCollectionKind; import org.jetbrains.jps.model.library.JpsLibrary; @@ -15,8 +15,8 @@ import java.util.List; * @author nik */ public class JpsDependenciesListImpl extends JpsCompositeElementBase implements JpsDependenciesList { - public static final JpsElementKind> DEPENDENCY_ELEMENT_KIND = new JpsElementKind>(); - public static final JpsElementCollectionKind> DEPENDENCY_COLLECTION_KIND = new JpsElementCollectionKind>(DEPENDENCY_ELEMENT_KIND); + public static final JpsElementCollectionKind> DEPENDENCY_COLLECTION_KIND = + new JpsElementCollectionKind>(new JpsElementKindBase>("dependency")); public JpsDependenciesListImpl() { super(); diff --git a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsLibraryDependencyImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsLibraryDependencyImpl.java index 7e2eba50a317..d9586addd602 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsLibraryDependencyImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsLibraryDependencyImpl.java @@ -2,6 +2,7 @@ package org.jetbrains.jps.model.module.impl; import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.model.*; +import org.jetbrains.jps.model.impl.JpsElementKindBase; import org.jetbrains.jps.model.library.JpsLibraryReference; import org.jetbrains.jps.model.module.JpsLibraryDependency; @@ -9,7 +10,7 @@ import org.jetbrains.jps.model.module.JpsLibraryDependency; * @author nik */ public class JpsLibraryDependencyImpl extends JpsDependencyElementBase implements JpsLibraryDependency { - public static final JpsElementKind LIBRARY_REFERENCE_KIND = new JpsElementKind(); + public static final JpsElementKind LIBRARY_REFERENCE_KIND = new JpsElementKindBase("library reference"); public JpsLibraryDependencyImpl(final JpsLibraryReference reference) { super(); diff --git a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleDependencyImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleDependencyImpl.java index 6fe796883168..143702c104cf 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleDependencyImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleDependencyImpl.java @@ -2,6 +2,7 @@ package org.jetbrains.jps.model.module.impl; import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.model.*; +import org.jetbrains.jps.model.impl.JpsElementKindBase; import org.jetbrains.jps.model.module.JpsModuleDependency; import org.jetbrains.jps.model.module.JpsModuleReference; @@ -9,7 +10,7 @@ import org.jetbrains.jps.model.module.JpsModuleReference; * @author nik */ public class JpsModuleDependencyImpl extends JpsDependencyElementBase implements JpsModuleDependency { - private static final JpsElementKind MODULE_REFERENCE_KIND = new JpsElementKind(); + private static final JpsElementKind MODULE_REFERENCE_KIND = new JpsElementKindBase("module reference"); public JpsModuleDependencyImpl(final JpsModuleReference moduleReference) { super(); diff --git a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleImpl.java index 7aabc147cae2..adb148b5da3d 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleImpl.java @@ -16,16 +16,17 @@ import java.util.List; */ public class JpsModuleImpl extends JpsNamedCompositeElementBase implements JpsModule { private static final JpsTypedDataKind> TYPED_DATA_KIND = new JpsTypedDataKind>(); - private static final JpsElementKind CONTENT_ROOTS_KIND = new JpsElementKind(); - private static final JpsElementKind EXCLUDED_ROOTS_KIND = new JpsElementKind(); - public static final JpsElementKind DEPENDENCIES_LIST_KIND = new JpsElementKind(); + private static final JpsUrlListKind CONTENT_ROOTS_KIND = new JpsUrlListKind("content roots"); + private static final JpsUrlListKind EXCLUDED_ROOTS_KIND = new JpsUrlListKind("excluded roots"); + public static final JpsElementKind DEPENDENCIES_LIST_KIND = + new JpsElementKindBase("dependencies"); public JpsModuleImpl(JpsModuleType type, @NotNull String name) { super(name); myContainer.setChild(TYPED_DATA_KIND, new JpsTypedDataImpl>(type)); - myContainer.setChild(CONTENT_ROOTS_KIND, new JpsUrlListImpl()); - myContainer.setChild(EXCLUDED_ROOTS_KIND, new JpsUrlListImpl()); + myContainer.setChild(CONTENT_ROOTS_KIND); + myContainer.setChild(EXCLUDED_ROOTS_KIND); myContainer.setChild(DEPENDENCIES_LIST_KIND, new JpsDependenciesListImpl()); myContainer.setChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND); myContainer.setChild(JpsModuleSourceRootKind.ROOT_COLLECTION_KIND); @@ -115,7 +116,12 @@ public class JpsModuleImpl extends JpsNamedCompositeElementBase type, @NotNull String name) { - final JpsElementCollectionImpl collection = myContainer.getChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND); - return collection.addChild(new JpsLibraryImpl(name, type)); + return addModuleLibrary(new JpsLibraryImpl(name, type)); + } + + @NotNull + @Override + public JpsLibrary addModuleLibrary(final @NotNull JpsLibrary library) { + return myContainer.getChild(JpsLibraryKind.LIBRARIES_COLLECTION_KIND).addChild(library); } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleKind.java b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleKind.java index 74621d367f0c..affce588f0b5 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleKind.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleKind.java @@ -4,22 +4,28 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.model.JpsElementKind; import org.jetbrains.jps.model.JpsEventDispatcher; import org.jetbrains.jps.model.impl.JpsElementCollectionKind; +import org.jetbrains.jps.model.impl.JpsElementKindBase; +import org.jetbrains.jps.model.module.JpsModule; import org.jetbrains.jps.model.module.JpsModuleListener; /** * @author nik */ -public class JpsModuleKind extends JpsElementKind { - public static final JpsElementKind INSTANCE = new JpsModuleKind(); - public static final JpsElementCollectionKind MODULE_COLLECTION_KIND = new JpsElementCollectionKind(INSTANCE); +public class JpsModuleKind extends JpsElementKindBase { + public static final JpsElementKind INSTANCE = new JpsModuleKind(); + public static final JpsElementCollectionKind MODULE_COLLECTION_KIND = new JpsElementCollectionKind(INSTANCE); + + public JpsModuleKind() { + super("module"); + } @Override - public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsModuleImpl element) { + public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsModule element) { dispatcher.getPublisher(JpsModuleListener.class).moduleAdded(element); } @Override - public void fireElementRemoved(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsModuleImpl element) { + public void fireElementRemoved(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsModule element) { dispatcher.getPublisher(JpsModuleListener.class).moduleRemoved(element); } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleSourceRootKind.java b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleSourceRootKind.java index 70e25abff2dc..11532f8a5f1b 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleSourceRootKind.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleSourceRootKind.java @@ -1,7 +1,7 @@ package org.jetbrains.jps.model.module.impl; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.JpsElementKind; +import org.jetbrains.jps.model.impl.JpsElementKindBase; import org.jetbrains.jps.model.JpsEventDispatcher; import org.jetbrains.jps.model.impl.JpsElementCollectionKind; import org.jetbrains.jps.model.module.JpsModuleSourceRootListener; @@ -9,10 +9,14 @@ import org.jetbrains.jps.model.module.JpsModuleSourceRootListener; /** * @author nik */ -public class JpsModuleSourceRootKind extends JpsElementKind { +public class JpsModuleSourceRootKind extends JpsElementKindBase { public static final JpsModuleSourceRootKind INSTANCE = new JpsModuleSourceRootKind(); public static final JpsElementCollectionKind ROOT_COLLECTION_KIND = new JpsElementCollectionKind(INSTANCE); + public JpsModuleSourceRootKind() { + super("module source root"); + } + @Override public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull JpsModuleSourceRootImpl element) { dispatcher.getPublisher(JpsModuleSourceRootListener.class).sourceRootAdded(element); diff --git a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsSdkReferencesTableImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsSdkReferencesTableImpl.java index 4b7c81cbecd6..b8c0462ffcb7 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsSdkReferencesTableImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsSdkReferencesTableImpl.java @@ -2,6 +2,7 @@ package org.jetbrains.jps.model.module.impl; import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.model.JpsElementKind; +import org.jetbrains.jps.model.impl.JpsElementKindBase; import org.jetbrains.jps.model.impl.JpsCompositeElementBase; import org.jetbrains.jps.model.library.JpsLibraryReference; import org.jetbrains.jps.model.library.JpsSdkType; @@ -11,7 +12,7 @@ import org.jetbrains.jps.model.module.JpsSdkReferencesTable; * @author nik */ public class JpsSdkReferencesTableImpl extends JpsCompositeElementBase implements JpsSdkReferencesTable { - public static final JpsElementKind KIND = new JpsElementKind(); + public static final JpsElementKind KIND = new JpsElementKindBase("sdk references"); public JpsSdkReferencesTableImpl() { super(); @@ -37,10 +38,11 @@ public class JpsSdkReferencesTableImpl extends JpsCompositeElementBase { + private static class JpsSdkReferenceKind extends JpsElementKindBase { private final JpsSdkType> myType; private JpsSdkReferenceKind(@NotNull JpsSdkType> type) { + super("sdk reference " + type); myType = type; } diff --git a/jps/model-impl/src/org/jetbrains/jps/service/impl/JpsServiceManagerImpl.java b/jps/model-impl/src/org/jetbrains/jps/service/impl/JpsServiceManagerImpl.java index 4f9c546a4cef..960bcff17879 100644 --- a/jps/model-impl/src/org/jetbrains/jps/service/impl/JpsServiceManagerImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/service/impl/JpsServiceManagerImpl.java @@ -3,6 +3,7 @@ package org.jetbrains.jps.service.impl; import org.jetbrains.jps.service.JpsServiceManager; import java.util.Iterator; +import java.util.List; import java.util.ServiceConfigurationError; import java.util.ServiceLoader; import java.util.concurrent.ConcurrentHashMap; @@ -12,6 +13,7 @@ import java.util.concurrent.ConcurrentHashMap; */ public class JpsServiceManagerImpl extends JpsServiceManager { private final ConcurrentHashMap myServices = new ConcurrentHashMap(); + private final ConcurrentHashMap> myExtensions = new ConcurrentHashMap>(); @Override public T getService(Class serviceClass) { @@ -24,10 +26,16 @@ public class JpsServiceManagerImpl extends JpsServiceManager { } service = iterator.next(); if (iterator.hasNext()) { - throw new ServiceConfigurationError("More than one implementation for " + serviceClass + " found: " + service.getClass() + " and " + iterator.next().getClass()); + throw new ServiceConfigurationError( + "More than one implementation for " + serviceClass + " found: " + service.getClass() + " and " + iterator.next().getClass()); } myServices.putIfAbsent(serviceClass, service); } return service; } + + @Override + public Iterable getExtensions(Class extensionClass) { + return ServiceLoader.load(extensionClass); + } } diff --git a/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsJavaExtensionTest.java b/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsJavaExtensionTest.java index 0b5609390503..3e66b86643d5 100644 --- a/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsJavaExtensionTest.java +++ b/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsJavaExtensionTest.java @@ -1,11 +1,6 @@ package org.jetbrains.jps.model; -import org.jetbrains.jps.model.java.JpsJavaDependencyExtension; -import org.jetbrains.jps.model.java.JpsJavaDependencyScope; -import org.jetbrains.jps.model.java.JpsJavaLibraryType; -import org.jetbrains.jps.model.java.JpsJavaModuleType; -import org.jetbrains.jps.model.java.impl.JavaModuleExtensionKind; -import org.jetbrains.jps.model.java.impl.JpsJavaDependencyExtensionKind; +import org.jetbrains.jps.model.java.*; import org.jetbrains.jps.model.library.JpsLibrary; import org.jetbrains.jps.model.module.JpsDependencyElement; import org.jetbrains.jps.model.module.JpsLibraryDependency; @@ -17,8 +12,10 @@ import org.jetbrains.jps.model.module.JpsModule; public class JpsJavaExtensionTest extends JpsModelTestCase { public void testModule() { final JpsModule module = myModel.getProject().addModule(JpsJavaModuleType.INSTANCE, "m"); - JavaModuleExtensionKind.getExtension(module).setOutputUrl("file://path"); - assertEquals("file://path", JavaModuleExtensionKind.getExtension(module).getOutputUrl()); + final JpsJavaModuleExtension extension = JpsJavaExtensionService.getInstance().getOrCreateModuleExtension(module); + extension.setOutputUrl("file://path"); + assertEquals("file://path", + module.getContainer().getChild(JpsJavaExtensionService.getInstance().getModuleExtensionKind()).getOutputUrl()); } public void testDependency() { @@ -26,12 +23,14 @@ public class JpsJavaExtensionTest extends JpsModelTestCase { final JpsModule module = model.getProject().addModule(JpsJavaModuleType.INSTANCE, "m"); final JpsLibrary library = model.getProject().addLibrary(JpsJavaLibraryType.INSTANCE, "l"); final JpsLibraryDependency dependency = module.getDependenciesList().addLibraryDependency(library); - JpsJavaDependencyExtensionKind.getExtension(dependency).setScope(JpsJavaDependencyScope.TEST); - JpsJavaDependencyExtensionKind.getExtension(dependency).setExported(true); + JpsJavaExtensionService.getInstance().getOrCreateDependencyExtension(dependency).setScope(JpsJavaDependencyScope.TEST); + JpsJavaExtensionService.getInstance().getOrCreateDependencyExtension(dependency).setExported(true); model.commit(); - final JpsDependencyElement dep = assertOneElement(assertOneElement(myModel.getProject().getModules()).getDependenciesList().getDependencies()); - final JpsJavaDependencyExtension extension = dep.getContainer().getChild(JpsJavaDependencyExtensionKind.INSTANCE); + final JpsDependencyElement dep = + assertOneElement(assertOneElement(myModel.getProject().getModules()).getDependenciesList().getDependencies()); + final JpsJavaDependencyExtension extension = + dep.getContainer().getChild(JpsJavaExtensionService.getInstance().getDependencyExtensionKind()); assertTrue(extension.isExported()); assertSame(JpsJavaDependencyScope.TEST, extension.getScope()); } diff --git a/jps/model-serialization/jps-model-serialization.iml b/jps/model-serialization/jps-model-serialization.iml new file mode 100644 index 000000000000..2ed39f108303 --- /dev/null +++ b/jps/model-serialization/jps-model-serialization.iml @@ -0,0 +1,19 @@ + +