Merge remote-tracking branch 'origin/master'

This commit is contained in:
Vladimir.Orlov
2016-03-15 14:51:13 +03:00
9 changed files with 66 additions and 61 deletions
@@ -84,7 +84,7 @@ public abstract class SuppressIntentionAction implements Iconable, IntentionActi
@Override
public final boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (file == null) return false;
if (file == null || editor == null) return false;
PsiElement element = getElement(editor, file);
return element != null && isAvailable(project, editor, element);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -17,6 +17,7 @@ package com.intellij.openapi.roots.impl;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.impl.scopes.JdkScope;
import com.intellij.openapi.module.impl.scopes.LibraryRuntimeClasspathScope;
import com.intellij.openapi.project.Project;
@@ -28,6 +29,7 @@ import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.ConcurrencyUtil;
import com.intellij.util.containers.ConcurrentFactoryMap;
import com.intellij.util.containers.ContainerUtil;
import gnu.trove.THashSet;
import gnu.trove.TObjectHashingStrategy;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -195,12 +197,21 @@ public class LibraryScopeCache {
return scope;
}
private GlobalSearchScope calcLibraryUseScope(List<OrderEntry> entries) {
@NotNull
private GlobalSearchScope calcLibraryUseScope(@NotNull List<OrderEntry> entries) {
List<GlobalSearchScope> united = ContainerUtil.newArrayList();
united.add(getLibrariesOnlyScope());
Set<Module> modulesInvolved = new THashSet<>(entries.size());
for (OrderEntry entry : entries) {
united.add(GlobalSearchScope.moduleWithDependentsScope(entry.getOwnerModule()));
Module ownerModule = entry.getOwnerModule();
united.add(GlobalSearchScope.moduleWithDependentsScope(ownerModule));
modulesInvolved.add(ownerModule);
}
// optimisation: if the library attached to all modules (often the case with JDK) then replace the 'union of all modules' scope with just 'project'
if (modulesInvolved.size() == ModuleManager.getInstance(myProject).getModules().length) {
return GlobalSearchScope.allScope(myProject);
}
return GlobalSearchScope.union(united.toArray(new GlobalSearchScope[united.size()]));
}
@@ -16,6 +16,7 @@
package com.intellij.xdebugger.impl.frame;
import com.intellij.ui.AppUIUtil;
import com.intellij.util.ui.tree.TreeUtil;
import com.intellij.xdebugger.XDebugSession;
import com.intellij.xdebugger.XDebugSessionListener;
import com.intellij.xdebugger.XExpression;
@@ -36,13 +37,15 @@ import javax.swing.*;
public class WatchInplaceEditor extends XDebuggerTreeInplaceEditor {
private final WatchesRootNode myRootNode;
private final XWatchesView myWatchesView;
@Nullable private final WatchNode myOldNode;
private final WatchNode myOldNode;
private WatchEditorSessionListener mySessionListener;
public WatchInplaceEditor(@NotNull WatchesRootNode rootNode,
@Nullable XDebugSession session, XWatchesView watchesView, final WatchNode node,
@NonNls final String historyId,
final @Nullable WatchNode oldNode) {
@Nullable XDebugSession session,
XWatchesView watchesView,
WatchNode node,
@NonNls String historyId,
@Nullable WatchNode oldNode) {
super((XDebuggerTreeNode)node, historyId);
myRootNode = rootNode;
myWatchesView = watchesView;
@@ -66,7 +69,7 @@ public class WatchInplaceEditor extends XDebuggerTreeInplaceEditor {
if (myOldNode == null && index != -1) {
myRootNode.removeChildNode(getNode());
}
getTree().setSelectionRow(index);
TreeUtil.selectNode(myTree, getNode());
}
@Override
@@ -78,7 +81,7 @@ public class WatchInplaceEditor extends XDebuggerTreeInplaceEditor {
if (!XDebuggerUtilImpl.isEmptyExpression(expression) && index != -1) {
myWatchesView.addWatchExpression(expression, index, false);
}
getTree().setSelectionRow(index);
TreeUtil.selectNode(myTree, getNode());
}
@Override
@@ -573,9 +573,10 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver
@Nullable String debuggerSetup,
@NotNull Consumer<String> initScriptConsumer) {
if (!StringUtil.isEmpty(debuggerSetup)) {
final String names = "[\"" + StringUtil.join(taskNames, "\", \"") + "\"]";
final String[] lines = {
"gradle.taskGraph.beforeTask { Task task ->",
" if (task instanceof JavaForkOptions) {",
" if (task instanceof JavaForkOptions && (" + names + ".contains(task.name) || " + names + ".contains(task.path))) {",
" def jvmArgs = task.jvmArgs.findAll{!it?.startsWith('-agentlib') && !it?.startsWith('-Xrunjdwp')}",
" jvmArgs << '" + debuggerSetup.trim() + '\'',
" task.jvmArgs jvmArgs",
@@ -191,6 +191,7 @@ public class InvalidPropertyKeyInspection extends BaseJavaLocalInspectionTool {
}
private void visitPropertyKeyAnnotationParameter(PsiExpression expression, String key) {
if (!(expression.getParent() instanceof PsiExpressionList)) return;
Ref<String> resourceBundleName = new Ref<String>();
if (!JavaI18nUtil.isValidPropertyReference(myManager.getProject(), expression, key, resourceBundleName)) {
String bundleName = resourceBundleName.get();
@@ -429,17 +429,22 @@ public class ResourceBundleEditor extends UserDataHolderBase implements Document
if (oldEditor != null) {
EditorFactory.getInstance().releaseEditor(oldEditor);
}
final Boolean[] isViewer = new Boolean[1];
((EditorEx) editor).addFocusListener(new FocusChangeListener() {
@Override
public void focusGained(final Editor editor) {
mySelectedEditor = editor;
final EditorEx editorEx = (EditorEx)editor;
editorEx.setViewer(ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(propertiesFile.getVirtualFile()).hasReadonlyFiles());
if (isViewer[0] == null) {
final boolean readOnly = ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(propertiesFile.getVirtualFile()).hasReadonlyFiles();
editorEx.setViewer(readOnly);
isViewer[0] = readOnly;
}
}
@Override
public void focusLost(final Editor eventEditor) {
if (propertiesFile.getContainingFile().isValid()) {
if (Boolean.FALSE.equals(isViewer[0]) && propertiesFile.getContainingFile().isValid()) {
writeEditorPropertyValue(null, editor, propertiesFile);
}
}
@@ -21,6 +21,7 @@ import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.lang.properties.psi.Property;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Pair;
import com.intellij.psi.PsiComment;
import com.intellij.psi.PsiElement;
@@ -71,8 +72,11 @@ public class ResourceBundlePropertiesUpdateManager {
public void insertOrUpdateTranslation(String key, String value, final PropertiesFile propertiesFile) throws IncorrectOperationException {
final IProperty property = propertiesFile.findPropertyByKey(key);
if (property != null) {
property.setValue(value);
myCodeStyleManager.reformat(property.getPsiElement());
final String oldValue = property.getValue();
if (!Comparing.equal(oldValue, value)) {
property.setValue(value);
myCodeStyleManager.reformat(property.getPsiElement());
}
return;
}
@@ -80,7 +80,7 @@ public class ResourceBundleRenameUtil {
@Override
public boolean checkInput(final String inputString) {
return inputString.indexOf('.') < 0;
return true;
}
@Override
@@ -65,9 +65,31 @@ public class RelaxSymbolIndex extends ScalarIndexExtension<String> {
public static NavigationItem[] getSymbolsByName(final String name, Project project, boolean includeNonProjectItems) {
final GlobalSearchScope scope = includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
final SymbolCollector processor = new SymbolCollector(name, project, scope);
FileBasedIndex.getInstance().processValues(NAME, name, null, processor, scope);
return processor.getResult();
final Collection<NavigationItem> result = new ArrayList<NavigationItem>();
PsiManager psiManager = PsiManager.getInstance(project);
for(VirtualFile file:FileBasedIndex.getInstance().getContainingFiles(NAME, name, scope)) {
final PsiFile psiFile = psiManager.findFile(file);
if (psiFile instanceof XmlFile) {
final Grammar grammar = GrammarFactory.getGrammar((XmlFile)psiFile);
if (grammar != null) {
grammar.acceptChildren(new CommonElement.Visitor() {
@Override
public void visitDefine(Define define) {
if (name.equals(define.getName())) {
final PsiElement psi = define.getPsiElement();
if (psi != null) {
MyNavigationItem.add((NavigationItem)define.getPsiElement(), result);
}
}
}
});
}
}
}
return result.toArray(new NavigationItem[result.size()]);
}
@NotNull
@@ -171,48 +193,6 @@ public class RelaxSymbolIndex extends ScalarIndexExtension<String> {
return 0;
}
private static class SymbolCollector implements FileBasedIndex.ValueProcessor<Void> {
private final GlobalSearchScope myScope;
private final PsiManager myMgr;
private final String myName;
private final Collection<NavigationItem> myResult = new ArrayList<NavigationItem>();
public SymbolCollector(String name, Project project, GlobalSearchScope scope) {
myMgr = PsiManager.getInstance(project);
myScope = scope;
myName = name;
}
@Override
public boolean process(VirtualFile file, Void kind) {
if (myScope.contains(file)) {
final PsiFile psiFile = myMgr.findFile(file);
if (psiFile instanceof XmlFile) {
final Grammar grammar = GrammarFactory.getGrammar((XmlFile)psiFile);
if (grammar != null) {
grammar.acceptChildren(new CommonElement.Visitor() {
@Override
public void visitDefine(Define define) {
if (myName.equals(define.getName())) {
final PsiElement psi = define.getPsiElement();
if (psi != null) {
MyNavigationItem.add((NavigationItem)define.getPsiElement(), myResult);
}
}
}
});
}
}
}
return true;
}
public NavigationItem[] getResult() {
return myResult.toArray(new NavigationItem[myResult.size()]);
}
}
private static class MyNavigationItem implements PsiElementNavigationItem, ItemPresentation {
private final NavigationItem myItem;
private final ItemPresentation myPresentation;