mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote branch 'origin/master'
This commit is contained in:
+3
-1
@@ -297,7 +297,8 @@ public class DocumentationManager {
|
||||
}
|
||||
}, keyboardShortcut != null ? keyboardShortcut.getFirstKeyStroke() : null)); // Null keyStroke is ok here
|
||||
|
||||
final JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component)
|
||||
boolean hasLookup = LookupManager.getActiveLookup(myEditor) != null;
|
||||
final JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component)
|
||||
.setRequestFocusCondition(project, NotLookupOrSearchCondition.INSTANCE)
|
||||
.setProject(project)
|
||||
.addListener(updateProcessor)
|
||||
@@ -308,6 +309,7 @@ public class DocumentationManager {
|
||||
.setResizable(true)
|
||||
.setMovable(true)
|
||||
.setRequestFocus(requestFocus)
|
||||
.setCancelOnClickOutside(!hasLookup) // otherwise selecting lookup items by mouse would close the doc
|
||||
.setTitle(getTitle(element, false))
|
||||
.setCouldPin(pinCallback)
|
||||
.setCancelCallback(new Computable<Boolean>() {
|
||||
|
||||
+20
-8
@@ -65,10 +65,8 @@ import javax.swing.table.TableCellEditor;
|
||||
import java.awt.*;
|
||||
import java.awt.event.FocusAdapter;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
@@ -370,16 +368,30 @@ public abstract class ChangeSignatureDialogBase<P extends ParameterInfo, M exten
|
||||
|
||||
protected JPanel createParametersPanel(boolean hasTabsInDialog) {
|
||||
myParametersTable = new TableView<ParameterTableModelItemBase<P>>(myParametersTableModel) {
|
||||
|
||||
public void removeEditor() {
|
||||
clearEditorListeners();
|
||||
super.removeEditor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void editingStopped(ChangeEvent e) {
|
||||
super.editingStopped(e);
|
||||
repaint(); // to update disabled cells background
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TableCellEditor getCellEditor(final int row, final int column) {
|
||||
final TableCellEditor editor = super.getCellEditor(row, column);
|
||||
private void clearEditorListeners() {
|
||||
final TableCellEditor editor = getCellEditor();
|
||||
if (editor instanceof StringTableCellEditor) {
|
||||
final StringTableCellEditor ed = (StringTableCellEditor)editor;
|
||||
ed.clearListeners();
|
||||
}
|
||||
else if (editor instanceof CodeFragmentTableCellEditorBase) {
|
||||
((CodeFragmentTableCellEditorBase)editor).clearListeners();
|
||||
}
|
||||
}
|
||||
|
||||
public Component prepareEditor(final TableCellEditor editor, final int row, final int column) {
|
||||
final DocumentAdapter listener = new DocumentAdapter() {
|
||||
@Override
|
||||
public void documentChanged(DocumentEvent e) {
|
||||
@@ -400,7 +412,7 @@ public abstract class ChangeSignatureDialogBase<P extends ParameterInfo, M exten
|
||||
else if (editor instanceof CodeFragmentTableCellEditorBase) {
|
||||
((CodeFragmentTableCellEditorBase)editor).addDocumentListener(listener);
|
||||
}
|
||||
return editor;
|
||||
return super.prepareEditor(editor, row, column);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler;
|
||||
@@ -44,6 +45,7 @@ import java.util.TreeMap;
|
||||
* @author dsl
|
||||
*/
|
||||
public class RenameHandlerRegistry {
|
||||
public static final Key<Boolean> SELECT_ALL = Key.create("rename.selectAll");
|
||||
private final Set<RenameHandler> myHandlers = new HashSet<RenameHandler>();
|
||||
private static final RenameHandlerRegistry INSTANCE = new RenameHandlerRegistry();
|
||||
private final PsiElementRenameHandler myDefaultElementRenameHandler;
|
||||
|
||||
+20
-6
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.intellij.refactoring.rename.inplace;
|
||||
|
||||
import com.intellij.codeInsight.completion.InsertHandler;
|
||||
import com.intellij.codeInsight.completion.InsertionContext;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl;
|
||||
import com.intellij.codeInsight.highlighting.HighlightManager;
|
||||
@@ -72,10 +74,7 @@ import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.rename.AutomaticRenamingDialog;
|
||||
import com.intellij.refactoring.rename.NameSuggestionProvider;
|
||||
import com.intellij.refactoring.rename.RenameProcessor;
|
||||
import com.intellij.refactoring.rename.RenameUtil;
|
||||
import com.intellij.refactoring.rename.*;
|
||||
import com.intellij.refactoring.rename.naming.AutomaticRenamer;
|
||||
import com.intellij.refactoring.rename.naming.AutomaticRenamerFactory;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
@@ -465,7 +464,8 @@ public class VariableInplaceRenamer {
|
||||
}
|
||||
|
||||
protected boolean shouldSelectAll() {
|
||||
return false;
|
||||
final Boolean selectAll = myEditor.getUserData(RenameHandlerRegistry.SELECT_ALL);
|
||||
return selectAll != null && selectAll.booleanValue();
|
||||
}
|
||||
|
||||
protected void navigateToAlreadyStarted(Document oldDocument, int exitCode) {
|
||||
@@ -826,7 +826,21 @@ public class VariableInplaceRenamer {
|
||||
myLookupItems = new LookupElement[names.size()];
|
||||
final Iterator<String> iterator = names.iterator();
|
||||
for (int i = 0; i < myLookupItems.length; i++) {
|
||||
myLookupItems[i] = LookupElementBuilder.create(iterator.next());
|
||||
final String suggestion = iterator.next();
|
||||
myLookupItems[i] = LookupElementBuilder.create(suggestion).setInsertHandler(new InsertHandler<LookupElement>() {
|
||||
@Override
|
||||
public void handleInsert(InsertionContext context, LookupElement item) {
|
||||
if (shouldSelectAll()) return;
|
||||
final Editor topLevelEditor = InjectedLanguageUtil.getTopLevelEditor(myEditor);
|
||||
final TemplateState templateState = TemplateManagerImpl.getTemplateState(topLevelEditor);
|
||||
if (templateState != null) {
|
||||
final TextRange range = templateState.getCurrentVariableRange();
|
||||
if (range != null) {
|
||||
myEditor.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), suggestion);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -86,4 +86,8 @@ public class CodeFragmentTableCellEditorBase extends AbstractCellEditor implemen
|
||||
public void addDocumentListener(DocumentListener listener) {
|
||||
myListeners.add(listener);
|
||||
}
|
||||
|
||||
public void clearListeners() {
|
||||
myListeners.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,4 +62,8 @@ public class StringTableCellEditor extends AbstractCellEditor implements TableCe
|
||||
public void addDocumentListener(DocumentListener listener) {
|
||||
myListeners.add(listener);
|
||||
}
|
||||
|
||||
public void clearListeners() {
|
||||
myListeners.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,12 +87,12 @@ public class LogicalPosition implements Comparable<LogicalPosition> {
|
||||
*/
|
||||
public final int foldingColumnDiff;
|
||||
|
||||
public LogicalPosition(int line, int column) {
|
||||
public LogicalPosition(int line, int column) throws IllegalArgumentException {
|
||||
this(line, column, 0, 0, 0, 0, 0, false);
|
||||
}
|
||||
|
||||
public LogicalPosition(int line, int column, int softWrapLinesBeforeCurrentLogicalLine, int softWrapLinesOnCurrentLogicalLine,
|
||||
int softWrapColumnDiff, int foldedLines, int foldingColumnDiff)
|
||||
int softWrapColumnDiff, int foldedLines, int foldingColumnDiff) throws IllegalArgumentException
|
||||
{
|
||||
this(
|
||||
line, column, softWrapLinesBeforeCurrentLogicalLine, softWrapLinesOnCurrentLogicalLine, softWrapColumnDiff, foldedLines,
|
||||
@@ -102,7 +102,16 @@ public class LogicalPosition implements Comparable<LogicalPosition> {
|
||||
|
||||
private LogicalPosition(int line, int column, int softWrapLinesBeforeCurrentLogicalLine, int softWrapLinesOnCurrentLogicalLine,
|
||||
int softWrapColumnDiff, int foldedLines, int foldingColumnDiff, boolean visualPositionAware)
|
||||
{
|
||||
throws IllegalArgumentException {
|
||||
if (column + softWrapColumnDiff + foldingColumnDiff < 0) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Attempt to create %s with invalid arguments - resulting column is negative (%d). Given arguments: line=%d, column=%d, "
|
||||
+ "soft wrap lines before: %d, soft wrap lines current: %d, soft wrap column diff: %d, folded lines: %d, folding column "
|
||||
+ "diff: %d, visual position aware: %b",
|
||||
getClass().getName(), column + softWrapColumnDiff + foldingColumnDiff, line, column, softWrapLinesBeforeCurrentLogicalLine,
|
||||
softWrapLinesOnCurrentLogicalLine, softWrapColumnDiff, foldedLines, foldingColumnDiff, visualPositionAware
|
||||
));
|
||||
}
|
||||
this.line = line;
|
||||
this.column = column;
|
||||
this.softWrapLinesBeforeCurrentLogicalLine = softWrapLinesBeforeCurrentLogicalLine;
|
||||
@@ -147,9 +156,9 @@ public class LogicalPosition implements Comparable<LogicalPosition> {
|
||||
? ""
|
||||
: "; soft wrap: lines=" + (softWrapLinesBeforeCurrentLogicalLine + softWrapLinesOnCurrentLogicalLine)
|
||||
+ " (before=" + softWrapLinesBeforeCurrentLogicalLine + "; current=" + softWrapLinesOnCurrentLogicalLine + ")")
|
||||
+ (softWrapColumnDiff == 0 ? "" : "columns diff=" + softWrapColumnDiff + ";" )
|
||||
+ (foldedLines == 0? "" : " folding: lines = " + foldedLines + ";")
|
||||
+ (foldingColumnDiff == 0 ? "" : " columns diff=" + foldingColumnDiff);
|
||||
+ (softWrapColumnDiff == 0 ? "" : "; columns diff=" + softWrapColumnDiff + ";" )
|
||||
+ (foldedLines == 0? "" : "; folding: lines = " + foldedLines + ";")
|
||||
+ (foldingColumnDiff == 0 ? "" : "; columns diff=" + foldingColumnDiff);
|
||||
}
|
||||
|
||||
public int compareTo(LogicalPosition position) {
|
||||
|
||||
@@ -149,8 +149,8 @@
|
||||
</constraints>
|
||||
<properties>
|
||||
<selected value="true"/>
|
||||
<text value="Use "safe write" (save changes to a temp. file first)"/>
|
||||
<toolTipText value="<html>Save changes to a temporary file first.<br/>Replace original file if write succeeded, leave original file untouched if write failed.</html> "/>
|
||||
<text value="Use "safe write" (save changes to a temporary file first)"/>
|
||||
<toolTipText value="<html>If this check box is selected, a changed file will be first saved to a temporary file;<br>if the save operation is completed successfully, the original file is deleted, and the temporary file is renamed.</html> "/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
|
||||
+28
-6
@@ -136,11 +136,20 @@ public class NotificationsManagerImpl extends NotificationsManager implements No
|
||||
}
|
||||
|
||||
final NotificationSettings settings = NotificationsConfigurationImpl.getSettings(notification.getGroupId());
|
||||
if (settings.isShouldLog() && settings.getDisplayType() != NotificationDisplayType.NONE) {
|
||||
boolean shouldLog = settings.isShouldLog();
|
||||
boolean displayable = settings.getDisplayType() != NotificationDisplayType.NONE;
|
||||
if (shouldLog && displayable) {
|
||||
myModel.add(notification, project);
|
||||
}
|
||||
|
||||
showWhenVisible(notification, project);
|
||||
boolean willBeShown = displayable && NotificationsConfigurationImpl.getNotificationsConfigurationImpl().SHOW_BALLOONS;
|
||||
if (!shouldLog && !willBeShown) {
|
||||
notification.expire();
|
||||
}
|
||||
|
||||
if (NotificationsConfigurationImpl.getNotificationsConfigurationImpl().SHOW_BALLOONS) {
|
||||
showWhenVisible(notification, project);
|
||||
}
|
||||
}
|
||||
|
||||
private static void showWhenVisible(final Notification notification, final Project project) {
|
||||
@@ -187,8 +196,18 @@ public class NotificationsManagerImpl extends NotificationsManager implements No
|
||||
case STICKY_BALLOON:
|
||||
case BALLOON:
|
||||
default:
|
||||
if (NotificationsConfigurationImpl.getNotificationsConfigurationImpl().SHOW_BALLOONS) {
|
||||
notifyByBalloon(notification, type, project);
|
||||
Balloon balloon = notifyByBalloon(notification, type, project);
|
||||
if (!settings.isShouldLog()) {
|
||||
if (balloon == null) {
|
||||
notification.expire();
|
||||
} else {
|
||||
balloon.addListener(new JBPopupAdapter() {
|
||||
@Override
|
||||
public void onClosed(LightweightWindowEvent event) {
|
||||
notification.expire();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TOOL_WINDOW:
|
||||
@@ -216,10 +235,11 @@ public class NotificationsManagerImpl extends NotificationsManager implements No
|
||||
}
|
||||
}
|
||||
|
||||
private static void notifyByBalloon(final Notification notification,
|
||||
@Nullable
|
||||
private static Balloon notifyByBalloon(final Notification notification,
|
||||
final NotificationDisplayType displayType,
|
||||
@Nullable final Project project) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) return;
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) return null;
|
||||
|
||||
Window window = findWindowForBalloon(project);
|
||||
if (window instanceof IdeFrameImpl) {
|
||||
@@ -240,7 +260,9 @@ public class NotificationsManagerImpl extends NotificationsManager implements No
|
||||
}
|
||||
});
|
||||
}
|
||||
return balloon;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -542,8 +542,26 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener,
|
||||
"Adjusting caret position by moving it before soft wrap. Moving to visual position %s%n", visualPosition
|
||||
));
|
||||
}
|
||||
moveToVisualPosition(visualPosition);
|
||||
return;
|
||||
final LogicalPosition logicalPosition = myEditor.visualToLogicalPosition(visualPosition);
|
||||
final int tmpOffset = myEditor.logicalPositionToOffset(logicalPosition);
|
||||
if (tmpOffset == myOffset) {
|
||||
boolean restore = myReportCaretMoves;
|
||||
myReportCaretMoves = false;
|
||||
try {
|
||||
moveToVisualPosition(visualPosition);
|
||||
return;
|
||||
}
|
||||
finally {
|
||||
myReportCaretMoves = restore;
|
||||
}
|
||||
}
|
||||
else {
|
||||
LogMessageEx.error(LOG, "Invalid editor dimension mapping", String.format(
|
||||
"Expected to map visual position '%s' to offset %d but got the following: -> logical position '%s'; -> offset %d. "
|
||||
+ "State: %s", visualPosition, myOffset, logicalPosition, tmpOffset, myEditor.dumpState()
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
<extensions defaultExtensionNs="org.intellij.groovy">
|
||||
<positionManagerDelegate implementation="org.jetbrains.plugins.gradle.config.GradlePositionManager"/>
|
||||
<scriptTypeDetector implementation="org.jetbrains.plugins.gradle.config.GradleScriptTypeDetector"/>
|
||||
<defaultImportContributor implementation="org.jetbrains.plugins.gradle.config.GradleDefaultImportContributor"/>
|
||||
</extensions>
|
||||
|
||||
<project-components>
|
||||
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.gradle.config;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.extensions.GroovyScriptTypeDetector;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.DefaultImportContributor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class GradleDefaultImportContributor extends DefaultImportContributor {
|
||||
|
||||
@Override
|
||||
public List<String> appendImplicitlyImportedPackages(@NotNull GroovyFile file) {
|
||||
if (file.isScript() && GroovyScriptTypeDetector.getScriptType(file) instanceof GradleScriptType) {
|
||||
return Arrays.asList(
|
||||
"org.gradle",
|
||||
"org.gradle.util",
|
||||
"org.gradle.api",
|
||||
"org.gradle.api.artifacts",
|
||||
"org.gradle.api.artifacts.dsl",
|
||||
"org.gradle.api.artifacts.specs",
|
||||
"org.gradle.api.dependencies",
|
||||
"org.gradle.api.execution",
|
||||
"org.gradle.api.file",
|
||||
"org.gradle.api.logging",
|
||||
"org.gradle.api.initialization",
|
||||
"org.gradle.api.invocation",
|
||||
"org.gradle.api.plugins",
|
||||
"org.gradle.api.plugins.quality",
|
||||
"org.gradle.api.specs",
|
||||
"org.gradle.api.tasks",
|
||||
"org.gradle.api.tasks.bundling",
|
||||
"org.gradle.api.tasks.compile",
|
||||
"org.gradle.api.tasks.javadoc",
|
||||
"org.gradle.api.tasks.testing",
|
||||
"org.gradle.api.tasks.util",
|
||||
"org.gradle.api.tasks.wrapper"
|
||||
);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -57,9 +57,7 @@ import org.jetbrains.plugins.groovy.util.GroovyUtils;
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -279,33 +277,4 @@ public class GradleScriptType extends GroovyScriptType {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> appendImplicitImports(@NotNull GroovyFile file) {
|
||||
return Arrays.asList(
|
||||
"org.gradle",
|
||||
"org.gradle.util",
|
||||
"org.gradle.api",
|
||||
"org.gradle.api.artifacts",
|
||||
"org.gradle.api.artifacts.dsl",
|
||||
"org.gradle.api.artifacts.specs",
|
||||
"org.gradle.api.dependencies",
|
||||
"org.gradle.api.execution",
|
||||
"org.gradle.api.file",
|
||||
"org.gradle.api.logging",
|
||||
"org.gradle.api.initialization",
|
||||
"org.gradle.api.invocation",
|
||||
"org.gradle.api.plugins",
|
||||
"org.gradle.api.plugins.quality",
|
||||
"org.gradle.api.specs",
|
||||
"org.gradle.api.tasks",
|
||||
"org.gradle.api.tasks.bundling",
|
||||
"org.gradle.api.tasks.compile",
|
||||
"org.gradle.api.tasks.javadoc",
|
||||
"org.gradle.api.tasks.testing",
|
||||
"org.gradle.api.tasks.util",
|
||||
"org.gradle.api.tasks.wrapper"
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
<extensionPoints>
|
||||
<extensionPoint name="membersContributor" interface="org.jetbrains.plugins.groovy.lang.resolve.NonCodeMembersContributor"/>
|
||||
<extensionPoint name="defaultImportContributor" interface="org.jetbrains.plugins.groovy.lang.resolve.DefaultImportContributor"/>
|
||||
<extensionPoint name="astTransformContributor" interface="org.jetbrains.plugins.groovy.lang.resolve.AstTransformContributor"/>
|
||||
<extensionPoint name="closureMissingMethodContributor" interface="org.jetbrains.plugins.groovy.lang.resolve.ClosureMissingMethodContributor"/>
|
||||
<extensionPoint name="variableEnhancer" interface="org.jetbrains.plugins.groovy.lang.psi.GrVariableEnhancer"/>
|
||||
@@ -117,6 +118,7 @@
|
||||
|
||||
<mvc.framework implementation="org.jetbrains.plugins.groovy.griffon.GriffonFramework"/>
|
||||
<groovyFrameworkConfigNotification implementation="org.jetbrains.plugins.groovy.griffon.GriffonConfigureNotification"/>
|
||||
<defaultImportContributor implementation="org.jetbrains.plugins.groovy.griffon.GriffonDefaultImportContributor"/>
|
||||
|
||||
</extensions>
|
||||
|
||||
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.griffon;
|
||||
|
||||
import com.intellij.lang.properties.IProperty;
|
||||
import com.intellij.lang.properties.psi.PropertiesFile;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.psi.util.PsiModificationTracker;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.DefaultImportContributor;
|
||||
import org.jetbrains.plugins.groovy.mvc.MvcFramework;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class GriffonDefaultImportContributor extends DefaultImportContributor {
|
||||
|
||||
private Pair<List<String>, List<String>> getDefaultImports(@NotNull final Module module) {
|
||||
return CachedValuesManager.getManager(module.getProject()).getCachedValue(module, new CachedValueProvider<Pair<List<String>, List<String>>>() {
|
||||
@Override
|
||||
public Result<Pair<List<String>, List<String>>> compute() {
|
||||
PsiPackage aPackage = JavaPsiFacade.getInstance(module.getProject()).findPackage("META-INF");
|
||||
if (aPackage != null) {
|
||||
for (PsiDirectory directory : aPackage.getDirectories(GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module))) {
|
||||
PsiFile file = directory.findFile("griffon-default-imports.properties");
|
||||
if (file instanceof PropertiesFile) {
|
||||
List<String> modelImports = tokenize(((PropertiesFile)file).findPropertyByKey("models"));
|
||||
List<String> viewImports = tokenize(((PropertiesFile)file).findPropertyByKey("views"));
|
||||
return Result.create(Pair.create(modelImports, viewImports), PsiModificationTracker.MODIFICATION_COUNT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Result.create(new Pair<List<String>, List<String>>(new ArrayList<String>(), new ArrayList<String>()),
|
||||
PsiModificationTracker.MODIFICATION_COUNT);
|
||||
}
|
||||
|
||||
private List<String> tokenize(IProperty models) {
|
||||
List<String> modelImports = new ArrayList<String>();
|
||||
if (models != null) {
|
||||
String value = models.getValue();
|
||||
if (value != null) {
|
||||
String[] split = value.split(", ");
|
||||
for (String s : split) {
|
||||
modelImports.add(StringUtil.trimEnd(s, "."));
|
||||
}
|
||||
}
|
||||
}
|
||||
return modelImports;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> appendImplicitlyImportedPackages(@NotNull GroovyFile file) {
|
||||
Module module = ModuleUtil.findModuleForPsiElement(file);
|
||||
MvcFramework framework = MvcFramework.getInstance(module);
|
||||
if (framework instanceof GriffonFramework) {
|
||||
ArrayList<String> result = new ArrayList<String>();
|
||||
result.add("griffon.core");
|
||||
result.add("griffon.util");
|
||||
|
||||
VirtualFile griffonApp = framework.findAppDirectory(file);
|
||||
if (griffonApp != null) {
|
||||
VirtualFile models = griffonApp.findChild("models");
|
||||
VirtualFile views = griffonApp.findChild("views");
|
||||
VirtualFile vFile = file.getOriginalFile().getVirtualFile();
|
||||
|
||||
assert vFile != null;
|
||||
assert module != null;
|
||||
if (models != null && VfsUtilCore.isAncestor(models, vFile, true)) {
|
||||
result.addAll(getDefaultImports(module).first);
|
||||
}
|
||||
else if (views != null && VfsUtilCore.isAncestor(views, vFile, true)) {
|
||||
result.addAll(getDefaultImports(module).second);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.impl.ElementBase;
|
||||
import com.intellij.psi.impl.file.PsiPackageImpl;
|
||||
import com.intellij.psi.scope.DelegatingScopeProcessor;
|
||||
import com.intellij.psi.scope.PsiScopeProcessor;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
@@ -55,12 +54,14 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightParameter;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.stubs.GrFileStub;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.DefaultImportContributor;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.MethodTypeInferencer;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.processors.ClassHint;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -222,12 +223,14 @@ public class GroovyFileImpl extends GroovyFileBaseImpl implements GroovyFile {
|
||||
}
|
||||
|
||||
|
||||
private List<String> getImplicitlyImportedPackages() {
|
||||
final ArrayList<String> result = new ArrayList<String>();
|
||||
private LinkedHashSet<String> getImplicitlyImportedPackages() {
|
||||
final LinkedHashSet<String> result = new LinkedHashSet<String>();
|
||||
ContainerUtil.addAll(result, IMPLICITLY_IMPORTED_PACKAGES);
|
||||
if (isScript()) {
|
||||
result.addAll(GroovyScriptTypeDetector.getScriptType(this).appendImplicitImports(this));
|
||||
|
||||
for (DefaultImportContributor contributor : DefaultImportContributor.EP_NAME.getExtensions()) {
|
||||
result.addAll(contributor.appendImplicitlyImportedPackages(this));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.lang.resolve;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public abstract class DefaultImportContributor {
|
||||
public static final ExtensionPointName<DefaultImportContributor> EP_NAME = ExtensionPointName.create("org.intellij.groovy.defaultImportContributor");
|
||||
|
||||
public List<String> appendImplicitlyImportedPackages(@NotNull GroovyFile file) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -94,39 +94,7 @@ public class TestPackage extends TestObject {
|
||||
@Override
|
||||
public void startNotified(ProcessEvent event) {
|
||||
super.startNotified(event);
|
||||
final JUnitConfiguration.Data data = myConfiguration.getPersistentData();
|
||||
final TestClassFilter filter;
|
||||
try {
|
||||
filter = getClassFilter(data);
|
||||
}
|
||||
catch (CantRunException e) {
|
||||
//should not happen
|
||||
return;
|
||||
}
|
||||
tasks[0] = findTestsWithProgress(new FindCallback() {
|
||||
public void found(@NotNull final Collection<PsiClass> classes, final boolean isJunit4) {
|
||||
try {
|
||||
addClassesListToJavaParameters(classes, new Function<PsiElement, String>() {
|
||||
@Nullable
|
||||
public String fun(PsiElement element) {
|
||||
if (element instanceof PsiClass) {
|
||||
return JavaExecutionUtil.getRuntimeQualifiedName((PsiClass)element);
|
||||
}
|
||||
else if (element instanceof PsiMethod) {
|
||||
PsiMethod method = (PsiMethod)element;
|
||||
return JavaExecutionUtil.getRuntimeQualifiedName(method.getContainingClass()) + "," + method.getName();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}, getPackage(data).getQualifiedName(), false, isJunit4);
|
||||
}
|
||||
catch (CantRunException e) {
|
||||
//can't be here
|
||||
}
|
||||
}
|
||||
}, filter);
|
||||
tasks[0] = (MySearchForTestsTask)findTests();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,6 +110,43 @@ public class TestPackage extends TestObject {
|
||||
return handler;
|
||||
}
|
||||
|
||||
public Task findTests() {
|
||||
final JUnitConfiguration.Data data = myConfiguration.getPersistentData();
|
||||
final TestClassFilter filter;
|
||||
try {
|
||||
filter = getClassFilter(data);
|
||||
}
|
||||
catch (CantRunException e) {
|
||||
//should not happen
|
||||
return null;
|
||||
}
|
||||
|
||||
return findTestsWithProgress(new FindCallback() {
|
||||
public void found(@NotNull final Collection<PsiClass> classes, final boolean isJunit4) {
|
||||
try {
|
||||
addClassesListToJavaParameters(classes, new Function<PsiElement, String>() {
|
||||
@Nullable
|
||||
public String fun(PsiElement element) {
|
||||
if (element instanceof PsiClass) {
|
||||
return JavaExecutionUtil.getRuntimeQualifiedName((PsiClass)element);
|
||||
}
|
||||
else if (element instanceof PsiMethod) {
|
||||
PsiMethod method = (PsiMethod)element;
|
||||
return JavaExecutionUtil.getRuntimeQualifiedName(method.getContainingClass()) + "," + method.getName();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}, getPackage(data).getQualifiedName(), false, isJunit4);
|
||||
}
|
||||
catch (CantRunException e) {
|
||||
//can't be here
|
||||
}
|
||||
}
|
||||
}, filter);
|
||||
}
|
||||
|
||||
protected void initialize() throws ExecutionException {
|
||||
super.initialize();
|
||||
final JUnitConfiguration.Data data = myConfiguration.getPersistentData();
|
||||
|
||||
@@ -25,12 +25,12 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.fileEditor.impl.text.TextEditorPsiDataProvider;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.intellij.refactoring.actions.RenameElementAction;
|
||||
import com.intellij.refactoring.rename.NameSuggestionProvider;
|
||||
import com.intellij.refactoring.rename.RenameHandlerRegistry;
|
||||
import com.intellij.spellchecker.util.SpellCheckerBundle;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -104,21 +104,20 @@ public class RenameTo extends ShowSuggestions implements SpellCheckerQuickFix {
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
DataContext dataContext = SimpleDataContext.getSimpleContext(map, DataManager.getInstance().getDataContext(editor.getComponent()));
|
||||
AnAction action = new RenameElementAction();
|
||||
final boolean hadSelection = editor.getSelectionModel().hasSelection();
|
||||
final TextRange range = psiElement.getTextRange();
|
||||
if (range != null) {
|
||||
editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset());
|
||||
|
||||
final Boolean selectAll = editor.getUserData(RenameHandlerRegistry.SELECT_ALL);
|
||||
try {
|
||||
editor.putUserData(RenameHandlerRegistry.SELECT_ALL, true);
|
||||
DataContext dataContext = SimpleDataContext.getSimpleContext(map, DataManager.getInstance().getDataContext(editor.getComponent()));
|
||||
AnAction action = new RenameElementAction();
|
||||
AnActionEvent event = new AnActionEvent(null, dataContext, "", action.getTemplatePresentation(), ActionManager.getInstance(), 0);
|
||||
action.actionPerformed(event);
|
||||
if (provider != null) {
|
||||
provider.setActive(false);
|
||||
}
|
||||
}
|
||||
AnActionEvent event = new AnActionEvent(null, dataContext, "", action.getTemplatePresentation(), ActionManager.getInstance(), 0);
|
||||
action.actionPerformed(event);
|
||||
if (provider != null) {
|
||||
provider.setActive(false);
|
||||
}
|
||||
if (!hadSelection) {
|
||||
editor.getSelectionModel().removeSelection();
|
||||
finally {
|
||||
editor.putUserData(RenameHandlerRegistry.SELECT_ALL, selectAll);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user