mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -34,7 +34,7 @@ public abstract class DownloadableLibraryTypeBase extends DownloadableLibraryTyp
|
||||
@NotNull String groupId,
|
||||
@NotNull Icon icon,
|
||||
@NotNull URL... localUrls) {
|
||||
super(new PersistentLibraryKind<LibraryVersionProperties>(libraryTypeId, false) {
|
||||
super(new PersistentLibraryKind<LibraryVersionProperties>(libraryTypeId) {
|
||||
@NotNull
|
||||
@Override
|
||||
public LibraryVersionProperties createDefaultProperties() {
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ class ItemElementDescriptor extends NodeDescriptor<ItemElement> {
|
||||
myElement = element;
|
||||
final String url = element.getUrl();
|
||||
myName = getPresentablePath(url).replace('/', File.separatorChar);
|
||||
myIcon = getIconForUrl(url, element.isValid(), element.isJarDirectory());
|
||||
setIcon(getIconForUrl(url, element.isValid(), element.isJarDirectory()));
|
||||
}
|
||||
|
||||
public boolean update() {
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ public class OrderRootTypeElementDescriptor extends NodeDescriptor<OrderRootType
|
||||
OrderRootTypeElement element, String text, Icon icon) {
|
||||
super(null, parentDescriptor);
|
||||
myElement = element;
|
||||
myIcon = icon;
|
||||
setIcon(icon);
|
||||
myName = text;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,14 +15,11 @@
|
||||
*/
|
||||
package com.intellij.application.options;
|
||||
|
||||
import com.intellij.application.options.codeStyle.arrangement.ArrangementNodeDisplayManager;
|
||||
import com.intellij.application.options.codeStyle.arrangement.ArrangementSettingsPanel;
|
||||
import com.intellij.ide.highlighter.JavaFileType;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.arrangement.Rearranger;
|
||||
import com.intellij.psi.codeStyle.arrangement.settings.ArrangementStandardSettingsAware;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -32,7 +29,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class JavaArrangementPanel extends ArrangementSettingsPanel {
|
||||
|
||||
public JavaArrangementPanel(@NotNull CodeStyleSettings settings) {
|
||||
super(settings, (ArrangementStandardSettingsAware)Rearranger.EXTENSION.forLanguage(JavaLanguage.INSTANCE));
|
||||
super(settings, JavaLanguage.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -709,7 +709,7 @@ public class JavaCompletionData extends JavaAwareCompletionData {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static class OverrideableSpace extends TailTypeDecorator<LookupElement> {
|
||||
public static class OverrideableSpace extends TailTypeDecorator<LookupElement> {
|
||||
private final TailType myTail;
|
||||
|
||||
public OverrideableSpace(LookupElement keyword, TailType tail) {
|
||||
|
||||
+35
-23
@@ -19,12 +19,9 @@ import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.codeInsight.ExternalAnnotationsManager;
|
||||
import com.intellij.codeInsight.daemon.GroupNames;
|
||||
import com.intellij.codeInspection.BaseJavaLocalInspectionTool;
|
||||
import com.intellij.codeInspection.LocalInspectionToolSession;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -88,8 +85,12 @@ public class MagicConstantInspection extends BaseJavaLocalInspectionTool {
|
||||
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder,
|
||||
boolean isOnTheFly,
|
||||
@NotNull LocalInspectionToolSession session) {
|
||||
checkAnnotationsJarAttached(session);
|
||||
return new JavaElementVisitor() {
|
||||
@Override
|
||||
public void visitJavaFile(PsiJavaFile file) {
|
||||
checkAnnotationsJarAttached(file, holder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitCallExpression(PsiCallExpression callExpression) {
|
||||
checkCall(callExpression, holder);
|
||||
@@ -156,8 +157,7 @@ public class MagicConstantInspection extends BaseJavaLocalInspectionTool {
|
||||
};
|
||||
}
|
||||
|
||||
private static void checkAnnotationsJarAttached(@NotNull LocalInspectionToolSession session) {
|
||||
PsiFile file = session.getFile();
|
||||
private static void checkAnnotationsJarAttached(@NotNull PsiFile file, @NotNull ProblemsHolder holder) {
|
||||
final Project project = file.getProject();
|
||||
PsiClass event = JavaPsiFacade.getInstance(project).findClass("java.awt.event.InputEvent", GlobalSearchScope.allScope(project));
|
||||
if (event == null) return; // no jdk to attach
|
||||
@@ -177,24 +177,36 @@ public class MagicConstantInspection extends BaseJavaLocalInspectionTool {
|
||||
}
|
||||
}
|
||||
if (jdk == null) return; // no jdk to attach
|
||||
final Sdk finalJdk = jdk;
|
||||
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
final Sdk finalJdk = jdk;
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
attachJdkAnnotations(finalJdk);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, ModalityState.NON_MODAL, project.getDisposed());
|
||||
}
|
||||
String path = finalJdk.getHomePath();
|
||||
String text = "No annotations attached to the JDK " + finalJdk.getName() + (path == null ? "" : " (" + FileUtil.toSystemDependentName(path) + ")");
|
||||
holder.registerProblem(file, text, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new LocalQuickFix() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Attach annotations to the JDK";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
attachJdkAnnotations(finalJdk);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void attachJdkAnnotations(Sdk jdk) {
|
||||
private static void attachJdkAnnotations(@NotNull Sdk jdk) {
|
||||
LocalFileSystem lfs = LocalFileSystem.getInstance();
|
||||
// community idea under idea
|
||||
VirtualFile root = lfs.findFileByPath(FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/java/jdkAnnotations");
|
||||
@@ -282,7 +294,7 @@ public class MagicConstantInspection extends BaseJavaLocalInspectionTool {
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = values != null ? Arrays.hashCode(values) : 0;
|
||||
int result = Arrays.hashCode(values);
|
||||
result = 31 * result + (canBeOred ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public final class CallHierarchyNodeDescriptor extends HierarchyNodeDescriptor i
|
||||
|
||||
public final boolean update(){
|
||||
final CompositeAppearance oldText = myHighlightedText;
|
||||
final Icon oldIcon = myIcon;
|
||||
final Icon oldIcon = getIcon();
|
||||
|
||||
int flags = Iconable.ICON_FLAG_VISIBILITY;
|
||||
if (isMarkReadOnly()) {
|
||||
@@ -109,13 +109,14 @@ public final class CallHierarchyNodeDescriptor extends HierarchyNodeDescriptor i
|
||||
return true;
|
||||
}
|
||||
|
||||
myIcon = enclosingElement.getIcon(flags);
|
||||
Icon newIcon = enclosingElement.getIcon(flags);
|
||||
if (changes && myIsBase) {
|
||||
final LayeredIcon icon = new LayeredIcon(2);
|
||||
icon.setIcon(myIcon, 0);
|
||||
icon.setIcon(newIcon, 0);
|
||||
icon.setIcon(AllIcons.Hierarchy.Base, 1, -AllIcons.Hierarchy.Base.getIconWidth() / 2, 0);
|
||||
myIcon = icon;
|
||||
newIcon = icon;
|
||||
}
|
||||
setIcon(newIcon);
|
||||
|
||||
myHighlightedText = new CompositeAppearance();
|
||||
TextAttributes mainTextAttributes = null;
|
||||
@@ -168,7 +169,7 @@ public final class CallHierarchyNodeDescriptor extends HierarchyNodeDescriptor i
|
||||
|
||||
if (
|
||||
!Comparing.equal(myHighlightedText, oldText) ||
|
||||
!Comparing.equal(myIcon, oldIcon)
|
||||
!Comparing.equal(getIcon(), oldIcon)
|
||||
){
|
||||
changes = true;
|
||||
}
|
||||
|
||||
+1
-1
@@ -123,7 +123,7 @@ public final class MethodHierarchyNodeDescriptor extends HierarchyNodeDescriptor
|
||||
newIcon = icon;
|
||||
}
|
||||
|
||||
myIcon = newIcon;
|
||||
setIcon(newIcon);
|
||||
}
|
||||
|
||||
final CompositeAppearance oldText = myHighlightedText;
|
||||
|
||||
@@ -56,9 +56,9 @@ public final class TypeHierarchyNodeDescriptor extends HierarchyNodeDescriptor {
|
||||
|
||||
if (changes && myIsBase) {
|
||||
final LayeredIcon icon = new LayeredIcon(2);
|
||||
icon.setIcon(myIcon, 0);
|
||||
icon.setIcon(getIcon(), 0);
|
||||
icon.setIcon(AllIcons.Hierarchy.Base, 1, -AllIcons.Hierarchy.Base.getIconWidth() / 2, 0);
|
||||
myIcon = icon;
|
||||
setIcon(icon);
|
||||
}
|
||||
|
||||
final PsiClass psiClass = getPsiClass();
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryType;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.ArrangementModifier;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.*;
|
||||
import com.intellij.psi.codeStyle.arrangement.settings.ArrangementConditionsGrouper;
|
||||
import com.intellij.psi.codeStyle.arrangement.settings.ArrangementStandardSettingsAware;
|
||||
@@ -67,6 +68,42 @@ public class JavaRearranger implements Rearranger<JavaElementArrangementEntry>,
|
||||
MODIFIERS_BY_TYPE.put(FIELD, concat(commonModifiers, TRANSIENT, VOLATILE));
|
||||
}
|
||||
|
||||
private static final List<StdArrangementRule> DEFAULT_RULES = new ArrayList<StdArrangementRule>();
|
||||
static {
|
||||
ArrangementModifier[] visibility = {PUBLIC, PROTECTED, PACKAGE_PRIVATE, PRIVATE};
|
||||
for (ArrangementModifier modifier : visibility) {
|
||||
and(FIELD, STATIC, FINAL, modifier);
|
||||
}
|
||||
for (ArrangementModifier modifier : visibility) {
|
||||
and(FIELD, STATIC, modifier);
|
||||
}
|
||||
for (ArrangementModifier modifier : visibility) {
|
||||
and(FIELD, FINAL, modifier);
|
||||
}
|
||||
for (ArrangementModifier modifier : visibility) {
|
||||
and(FIELD, modifier);
|
||||
}
|
||||
and(METHOD);
|
||||
and(ENUM);
|
||||
and(INTERFACE);
|
||||
and(CLASS);
|
||||
}
|
||||
|
||||
private static void and(@NotNull Object... conditions) {
|
||||
if (conditions.length == 1) {
|
||||
DEFAULT_RULES.add(new StdArrangementRule(new StdArrangementEntryMatcher(new ArrangementAtomMatchCondition(
|
||||
ArrangementUtil.parseType(conditions[0]), conditions[0]
|
||||
))));
|
||||
return;
|
||||
}
|
||||
|
||||
ArrangementCompositeMatchCondition composite = new ArrangementCompositeMatchCondition(ArrangementOperator.AND);
|
||||
for (Object condition : conditions) {
|
||||
composite.addOperand(new ArrangementAtomMatchCondition(ArrangementUtil.parseType(condition), condition));
|
||||
}
|
||||
DEFAULT_RULES.add(new StdArrangementRule(new StdArrangementEntryMatcher(composite)));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Set<ArrangementModifier> concat(@NotNull Set<ArrangementModifier> base, ArrangementModifier... modifiers) {
|
||||
EnumSet<ArrangementModifier> result = EnumSet.copyOf(base);
|
||||
@@ -169,4 +206,10 @@ public class JavaRearranger implements Rearranger<JavaElementArrangementEntry>,
|
||||
});
|
||||
return result.get();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<StdArrangementRule> getDefaultRules() {
|
||||
return DEFAULT_RULES;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import java.util.Set;
|
||||
public abstract class RenameJavaMemberProcessor extends RenamePsiElementProcessor {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.rename.RenameJavaMemberProcessor");
|
||||
|
||||
protected static void qualifyMember(PsiMember member, PsiElement occurence, String newName) throws IncorrectOperationException {
|
||||
public static void qualifyMember(PsiMember member, PsiElement occurence, String newName) throws IncorrectOperationException {
|
||||
qualifyMember(occurence, newName, member.getContainingClass(), member.hasModifierProperty(PsiModifier.STATIC));
|
||||
}
|
||||
|
||||
|
||||
+2
-22
@@ -20,6 +20,7 @@ import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.rename.RenameJavaMemberProcessor;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
@@ -74,28 +75,7 @@ class JavaResolveSnapshot extends ResolveSnapshotProvider.ResolveSnapshot {
|
||||
if (!ref.isQualified() && hidingLocalName.equals(ref.getReferenceName())) {
|
||||
final PsiElement newlyResolved = ref.resolve();
|
||||
if (referee.getManager().areElementsEquivalent(newlyResolved, referee)) return;
|
||||
PsiClass refereeClass = ((PsiField) referee).getContainingClass();
|
||||
PsiClass referentClass = PsiTreeUtil.getParentOfType(referent, PsiClass.class);
|
||||
if (refereeClass != null && referentClass != null &&
|
||||
PsiTreeUtil.isAncestor(refereeClass, referentClass, false)) {
|
||||
if (refereeClass == referentClass ||
|
||||
refereeClass.getName() != null) { //otherwise cannot qualify anonymous referee class
|
||||
@NonNls String qualifer;
|
||||
if (RefactoringUtil.isInStaticContext(ref, refereeClass)) {
|
||||
qualifer = refereeClass.getName();
|
||||
} else {
|
||||
qualifer = refereeClass == referentClass ? "this" : refereeClass.getName() + ".this";
|
||||
}
|
||||
String qualifiedRefText = qualifer + "." + ref.getText();
|
||||
PsiElementFactory elementFactory = JavaPsiFacade.getInstance(referentClass.getProject()).getElementFactory();
|
||||
try {
|
||||
PsiReferenceExpression qualifiedRef = (PsiReferenceExpression) elementFactory.createExpressionFromText(qualifiedRefText, null);
|
||||
ref.replace(qualifiedRef);
|
||||
} catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
RenameJavaMemberProcessor.qualifyMember((PsiField)referee, referent, hidingLocalName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-5
@@ -39,6 +39,7 @@ public class AutomaticVariableRenamer extends AutomaticRenamer {
|
||||
private final Set<PsiNamedElement> myToUnpluralize = new HashSet<PsiNamedElement>();
|
||||
|
||||
public AutomaticVariableRenamer(PsiClass aClass, String newClassName, Collection<UsageInfo> usages) {
|
||||
final String oldClassName = aClass.getName();
|
||||
for (final UsageInfo info : usages) {
|
||||
final PsiElement element = info.getElement();
|
||||
if (!(element instanceof PsiJavaCodeReferenceElement)) continue;
|
||||
@@ -46,23 +47,23 @@ public class AutomaticVariableRenamer extends AutomaticRenamer {
|
||||
if (statement != null) {
|
||||
for(PsiElement declaredElement: statement.getDeclaredElements()) {
|
||||
if (declaredElement instanceof PsiVariable) {
|
||||
checkRenameVariable(element, (PsiVariable) declaredElement);
|
||||
checkRenameVariable(element, (PsiVariable) declaredElement, oldClassName);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
PsiVariable variable = PsiTreeUtil.getParentOfType(element, PsiVariable.class);
|
||||
if (variable != null) {
|
||||
checkRenameVariable(element, variable);
|
||||
checkRenameVariable(element, variable, oldClassName);
|
||||
if (variable instanceof PsiField) {
|
||||
for(PsiField field: getFieldsInSameDeclaration((PsiField) variable)) {
|
||||
checkRenameVariable(element, field);
|
||||
checkRenameVariable(element, field, oldClassName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
suggestAllNames(aClass.getName(), newClassName);
|
||||
suggestAllNames(oldClassName, newClassName);
|
||||
}
|
||||
|
||||
private static List<PsiField> getFieldsInSameDeclaration(final PsiField variable) {
|
||||
@@ -81,11 +82,13 @@ public class AutomaticVariableRenamer extends AutomaticRenamer {
|
||||
return result;
|
||||
}
|
||||
|
||||
private void checkRenameVariable(final PsiElement element, final PsiVariable variable) {
|
||||
private void checkRenameVariable(final PsiElement element, final PsiVariable variable, final String oldClassName) {
|
||||
final PsiTypeElement typeElement = variable.getTypeElement();
|
||||
if (typeElement == null) return;
|
||||
final PsiJavaCodeReferenceElement ref = typeElement.getInnermostComponentReferenceElement();
|
||||
if (ref == null) return;
|
||||
final String variableName = variable.getName();
|
||||
if (variableName != null && !StringUtil.containsIgnoreCase(variableName, oldClassName)) return;
|
||||
if (ref.equals(element)) {
|
||||
myElements.add(variable);
|
||||
if (variable.getType() instanceof PsiArrayType) {
|
||||
|
||||
@@ -262,7 +262,16 @@ public class LambdaUtil {
|
||||
public static boolean dependsOnTypeParams(PsiType type,
|
||||
PsiLambdaExpression expr,
|
||||
PsiTypeParameter param2Check) {
|
||||
final TypeParamsChecker visitor = new TypeParamsChecker(expr);
|
||||
return depends(type, param2Check, new TypeParamsChecker(expr));
|
||||
}
|
||||
|
||||
public static boolean dependsOnTypeParams(PsiType type,
|
||||
PsiClass aClass,
|
||||
PsiMethod aMethod) {
|
||||
return depends(type, null, new TypeParamsChecker(aMethod, aClass));
|
||||
}
|
||||
|
||||
private static boolean depends(PsiType type, PsiTypeParameter param2Check, TypeParamsChecker visitor) {
|
||||
if (!visitor.startedInference()) return false;
|
||||
final Boolean accept = type.accept(visitor);
|
||||
if (param2Check != null) {
|
||||
@@ -328,8 +337,8 @@ public class LambdaUtil {
|
||||
}
|
||||
|
||||
final PsiElement gParent = expressionList.getParent();
|
||||
if (gParent instanceof PsiMethodCallExpression) {
|
||||
final PsiMethodCallExpression contextCall = (PsiMethodCallExpression)gParent;
|
||||
if (gParent instanceof PsiCallExpression) {
|
||||
final PsiCallExpression contextCall = (PsiCallExpression)gParent;
|
||||
final JavaResolveResult resolveResult = contextCall.resolveMethodGenerics();
|
||||
final PsiElement resolve = resolveResult.getElement();
|
||||
if (resolve instanceof PsiMethod) {
|
||||
@@ -403,6 +412,11 @@ public class LambdaUtil {
|
||||
private final PsiClass myClass;
|
||||
private final Set<PsiTypeParameter> myUsedTypeParams = new HashSet<PsiTypeParameter>();
|
||||
|
||||
private TypeParamsChecker(PsiMethod method, PsiClass aClass) {
|
||||
myMethod = method;
|
||||
myClass = aClass;
|
||||
}
|
||||
|
||||
public TypeParamsChecker(PsiLambdaExpression expression) {
|
||||
myClass = PsiUtil.resolveGenericsClassInType(getFunctionalInterfaceType(expression, false)).getElement();
|
||||
PsiElement parent = expression.getParent();
|
||||
|
||||
+14
-1
@@ -106,8 +106,21 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
|
||||
if (method != null) {
|
||||
final PsiParameter[] methodParameters = method.getParameterList().getParameters();
|
||||
final PsiParameter param = i < methodParameters.length ? methodParameters[i] : methodParameters[methodParameters.length - 1];
|
||||
if (!LambdaUtil.isAcceptable(lambdaExpression, param.getType())) {
|
||||
final PsiType paramType = param.getType();
|
||||
if (!LambdaUtil.isAcceptable(lambdaExpression, paramType)) {
|
||||
iterator.remove();
|
||||
} else {
|
||||
/*todo
|
||||
final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(paramType);
|
||||
final PsiMethod functionalInterfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(paramType);
|
||||
if (functionalInterfaceMethod != null) {
|
||||
for (PsiParameter parameter : functionalInterfaceMethod.getParameterList().getParameters()) {
|
||||
if (LambdaUtil.dependsOnTypeParams(resolveResult.getSubstitutor().substitute(parameter.getType()), resolveResult.getElement(), method)) {
|
||||
iterator.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+207
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
interface Foo<T> {
|
||||
void foo(T t);
|
||||
}
|
||||
|
||||
interface IntFoo {
|
||||
void foo(int i);
|
||||
}
|
||||
|
||||
interface ObjectFoo<T> {
|
||||
void foo(int i);
|
||||
}
|
||||
|
||||
interface FooList<T> {
|
||||
void foo(List<T> tList);
|
||||
}
|
||||
|
||||
<T> void f(Foo<T> foo) {
|
||||
System.out.println("Foo<T>");
|
||||
}
|
||||
|
||||
<T> void f(FooList<T> foo) {
|
||||
System.out.println("FooList<T>");
|
||||
}
|
||||
/*void f(IntFoo foo) {
|
||||
System.out.println("IntFoo");
|
||||
}*/
|
||||
|
||||
/*void f(ObjectFoo foo) {
|
||||
System.out.println("ObjectFoo");
|
||||
}*/
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Test().f<error descr="Ambiguous method call: both 'Test.f(Foo<Object>)' and 'Test.f(FooList<Object>)' match">(null)</error>;
|
||||
new Test().<error descr="Cannot resolve method 'f(<lambda expression>)'">f</error>(x -> {});
|
||||
}
|
||||
}
|
||||
|
||||
class Test1 {
|
||||
interface Foo<T> {
|
||||
void foo(T t);
|
||||
}
|
||||
|
||||
interface IntFoo {
|
||||
void foo(int i);
|
||||
}
|
||||
|
||||
interface ObjectFoo<T> {
|
||||
void foo(int i);
|
||||
}
|
||||
|
||||
interface FooList<T> {
|
||||
void foo(List<T> tList);
|
||||
}
|
||||
|
||||
<T> void f(Foo<T> foo) {
|
||||
System.out.println("Foo<T>");
|
||||
}
|
||||
|
||||
<T> void f(FooList<T> foo) {
|
||||
System.out.println("FooList<T>");
|
||||
}
|
||||
|
||||
void f(IntFoo foo) {
|
||||
System.out.println("IntFoo");
|
||||
}
|
||||
|
||||
/*void f(ObjectFoo foo) {
|
||||
System.out.println("ObjectFoo");
|
||||
}*/
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Test1().f<error descr="Ambiguous method call: both 'Test1.f(Foo<Object>)' and 'Test1.f(FooList<Object>)' match">(null)</error>;
|
||||
new Test1().f(x -> {});
|
||||
}
|
||||
}
|
||||
|
||||
class Test2 {
|
||||
interface Foo<T> {
|
||||
void foo(T t);
|
||||
}
|
||||
|
||||
interface IntFoo {
|
||||
void foo(int i);
|
||||
}
|
||||
|
||||
interface ObjectFoo<T> {
|
||||
void foo(int i);
|
||||
}
|
||||
|
||||
interface FooList<T> {
|
||||
void foo(List<T> tList);
|
||||
}
|
||||
|
||||
<T> void f(Foo<T> foo) {
|
||||
System.out.println("Foo<T>");
|
||||
}
|
||||
|
||||
<T> void f(FooList<T> foo) {
|
||||
System.out.println("FooList<T>");
|
||||
}
|
||||
void f(IntFoo foo) {
|
||||
System.out.println("IntFoo");
|
||||
}
|
||||
|
||||
void f(ObjectFoo foo) {
|
||||
System.out.println("ObjectFoo");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Test2().f<error descr="Ambiguous method call: both 'Test2.f(Foo<Object>)' and 'Test2.f(FooList<Object>)' match">(null)</error>;
|
||||
new Test2().f<error descr="Ambiguous method call: both 'Test2.f(IntFoo)' and 'Test2.f(ObjectFoo)' match">(x -> {})</error>;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Test3 {
|
||||
interface Foo<T> {
|
||||
void foo(T t);
|
||||
}
|
||||
|
||||
interface IntFoo {
|
||||
void foo(int i);
|
||||
}
|
||||
|
||||
interface ObjectFoo<T> {
|
||||
void foo(int i);
|
||||
}
|
||||
|
||||
interface FooList<T> {
|
||||
void foo(List<T> tList);
|
||||
}
|
||||
|
||||
<T> void f(Foo<T> foo) {
|
||||
System.out.println("Foo<T>");
|
||||
}
|
||||
|
||||
<T> void f(FooList<T> foo) {
|
||||
System.out.println("FooList<T>");
|
||||
}
|
||||
/*void f(IntFoo foo) {
|
||||
System.out.println("IntFoo");
|
||||
}*/
|
||||
|
||||
void f(ObjectFoo foo) {
|
||||
System.out.println("ObjectFoo");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Test3().f<error descr="Ambiguous method call: both 'Test3.f(Foo<Object>)' and 'Test3.f(FooList<Object>)' match">(null)</error>;
|
||||
new Test3().f(x -> {});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Test {
|
||||
interface Foo<T> {
|
||||
void foo(T t, T t1);
|
||||
}
|
||||
interface Foo1<T> {
|
||||
void foo(T t, String t1);
|
||||
}
|
||||
interface Foo2<T> {
|
||||
void foo(String t, String t1);
|
||||
}
|
||||
|
||||
<T> void f(Foo<T> foo) {
|
||||
System.out.println("Foo<T>");
|
||||
}
|
||||
|
||||
<T> void f(Foo1<T> foo) {
|
||||
System.out.println("FooList<T>");
|
||||
}
|
||||
<T> void f(Foo2<T> foo) {
|
||||
System.out.println("FooList<T>");
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
new Test().f((String x, String y) -> {});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+11
-1
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
class Test1 {
|
||||
{
|
||||
Comparable<? extends Integer> c = (Integer o)->{
|
||||
@@ -46,3 +46,13 @@ class Test2<U> {
|
||||
}
|
||||
}
|
||||
|
||||
class TestNewExpression<E> {
|
||||
public TestNewExpression(Comparator<? super E> comparator) {
|
||||
//some code
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
TestNewExpression<String> strs = new TestNewExpression<String>((o1, o2) -> {
|
||||
return o2.compareToIgnoreCase(o1);
|
||||
});
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// "Replace with lambda" "true"
|
||||
class Test {
|
||||
{
|
||||
Comparable<String> c = o->{
|
||||
Comparable<String> c = o -> {
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// "Replace with lambda" "true"
|
||||
class Test {
|
||||
{
|
||||
Comparable<String> c = o->{
|
||||
Comparable<String> c = o -> {
|
||||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ class Test2 {
|
||||
static <T> I<T> bar(I<T> i){return i;}
|
||||
|
||||
{
|
||||
bar((List<String> list)->{
|
||||
bar((List<String> list) -> {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
});
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// "Replace with lambda" "true"
|
||||
class Test {
|
||||
{
|
||||
Runnable r = ()->{
|
||||
Runnable r = () -> {
|
||||
System.out.println("");
|
||||
};
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// "Replace with lambda" "true"
|
||||
class Test {
|
||||
{
|
||||
Runnable[] r = new Runnable[] {()->{
|
||||
Runnable[] r = new Runnable[] {() -> {
|
||||
System.out.println("");
|
||||
}};
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// "Remove redundant types" "true"
|
||||
class Test {
|
||||
{
|
||||
Comparable<String> r = o-> 1;
|
||||
Comparable<String> r = o -> 1;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -11,6 +11,6 @@ class Test2 {
|
||||
static <T> I<T> bar(I<T> i){return i;}
|
||||
|
||||
{
|
||||
Test2.<String>bar(y-> y.t);
|
||||
Test2.<String>bar(y -> y.t);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -10,6 +10,6 @@ class ReturnTypeCompatibility {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
call("", i-> "");
|
||||
call("", i -> "");
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ interface SAM<X> {
|
||||
|
||||
class Foo {
|
||||
void test() {
|
||||
SAM<Integer> c = (i, j)->i + j;
|
||||
SAM<Integer> c = (i, j) -> i + j;
|
||||
m(c);
|
||||
}
|
||||
void m(SAM<Integer> s) { }
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ interface SAM<X> {
|
||||
|
||||
class Foo {
|
||||
void test() {
|
||||
SAM<String> c = (i, j)->"" + i + j;
|
||||
SAM<String> c = (i, j) -> "" + i + j;
|
||||
SAM<Integer> s3 = m(c);
|
||||
}
|
||||
<X> SAM<X> m(SAM<X> s) { return null; }
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
class Test1 {
|
||||
class A {
|
||||
int a;
|
||||
}
|
||||
class B extends A {
|
||||
B(int <caret>b) {
|
||||
a = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
class Test1 {
|
||||
class A {
|
||||
int a;
|
||||
}
|
||||
class B extends A {
|
||||
B(int a) {
|
||||
this.a = a;
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -17,8 +17,10 @@ package com.intellij.application.options.codeStyle.arrangement;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.codeStyle.arrangement.JavaRearranger;
|
||||
import com.intellij.psi.codeStyle.arrangement.StdArrangementRule;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryType;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.ArrangementModifier;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.ArrangementSettingType;
|
||||
@@ -57,7 +59,9 @@ public abstract class AbstractArrangementRuleEditingModelTest {
|
||||
}
|
||||
|
||||
protected void configure(@NotNull ArrangementMatchCondition matchCondition) {
|
||||
Pair<ArrangementRuleEditingModelImpl,TIntIntHashMap> pair = myBuilder.build(matchCondition, myTree, myRoot, null, myGrouper);
|
||||
Pair<ArrangementRuleEditingModelImpl,TIntIntHashMap> pair = myBuilder.build(
|
||||
new StdArrangementRule(new StdArrangementEntryMatcher(matchCondition)), myTree, myRoot, null, myGrouper
|
||||
);
|
||||
myRowMappings.put(pair.first.getRow(), pair.first);
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -42,7 +42,7 @@ public class ArrangementRuleEditingModelImplTest extends AbstractArrangementRule
|
||||
assertNotNull(child);
|
||||
ArrangementMatchCondition expectedMatchCondition = and(atom(PUBLIC), atom(STATIC));
|
||||
assertEquals(expectedMatchCondition, child.getBackingCondition());
|
||||
assertEquals(expectedMatchCondition, model.getMatchCondition());
|
||||
assertEquals(expectedMatchCondition, model.getCondition());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -55,7 +55,7 @@ public class ArrangementRuleEditingModelImplTest extends AbstractArrangementRule
|
||||
model.addAndCondition(atom(FIELD));
|
||||
|
||||
assertEquals(2, model.getRow());
|
||||
assertEquals(and(atom(FIELD), atom(PUBLIC)), model.getMatchCondition());
|
||||
assertEquals(and(atom(FIELD), atom(PUBLIC)), model.getCondition());
|
||||
|
||||
ArrangementTreeNode fieldNode = myRoot.getFirstChild();
|
||||
assertNotNull(fieldNode);
|
||||
@@ -77,7 +77,7 @@ public class ArrangementRuleEditingModelImplTest extends AbstractArrangementRule
|
||||
|
||||
assertEquals(1, myRowMappings.size());
|
||||
assertSame(model, myRowMappings.get(2));
|
||||
assertEquals(and(atom(FIELD), atom(PUBLIC), atom(STATIC)), model.getMatchCondition());
|
||||
assertEquals(and(atom(FIELD), atom(PUBLIC), atom(STATIC)), model.getCondition());
|
||||
|
||||
ArrangementTreeNode fieldNode = myRoot.getFirstChild();
|
||||
assertNotNull(fieldNode);
|
||||
@@ -99,7 +99,7 @@ public class ArrangementRuleEditingModelImplTest extends AbstractArrangementRule
|
||||
|
||||
assertEquals(1, myRowMappings.size());
|
||||
assertSame(model, myRowMappings.get(2));
|
||||
assertEquals(and(atom(FIELD), atom(STATIC)), model.getMatchCondition());
|
||||
assertEquals(and(atom(FIELD), atom(STATIC)), model.getCondition());
|
||||
|
||||
ArrangementTreeNode fieldNode = myRoot.getFirstChild();
|
||||
assertNotNull(fieldNode);
|
||||
@@ -122,7 +122,7 @@ public class ArrangementRuleEditingModelImplTest extends AbstractArrangementRule
|
||||
model.removeAndCondition(atom(PUBLIC));
|
||||
|
||||
assertEquals(1, model.getRow());
|
||||
assertEquals(atom(FIELD), model.getMatchCondition());
|
||||
assertEquals(atom(FIELD), model.getCondition());
|
||||
|
||||
ArrangementTreeNode fieldNode = myRoot.getFirstChild();
|
||||
assertNotNull(fieldNode);
|
||||
@@ -146,10 +146,10 @@ public class ArrangementRuleEditingModelImplTest extends AbstractArrangementRule
|
||||
modelToChange.removeAndCondition(atom(PUBLIC));
|
||||
|
||||
assertSame(1, modelToChange.getRow());
|
||||
assertEquals(atom(FIELD), modelToChange.getMatchCondition());
|
||||
assertEquals(atom(FIELD), modelToChange.getCondition());
|
||||
|
||||
assertSame(3, siblingModel.getRow());
|
||||
assertEquals(and(atom(FIELD), atom(STATIC)), siblingModel.getMatchCondition());
|
||||
assertEquals(and(atom(FIELD), atom(STATIC)), siblingModel.getCondition());
|
||||
|
||||
ArrangementTreeNode atomFieldNode = myRoot.getFirstChild();
|
||||
assertNotNull(atomFieldNode);
|
||||
@@ -180,10 +180,10 @@ public class ArrangementRuleEditingModelImplTest extends AbstractArrangementRule
|
||||
|
||||
assertEquals(2, myRowMappings.size());
|
||||
assertSame(siblingModel, myRowMappings.get(2));
|
||||
assertEquals(and(atom(FIELD), atom(PUBLIC)), siblingModel.getMatchCondition());
|
||||
assertEquals(and(atom(FIELD), atom(PUBLIC)), siblingModel.getCondition());
|
||||
|
||||
assertSame(modelToChange, myRowMappings.get(3));
|
||||
assertEquals(atom(FIELD), modelToChange.getMatchCondition());
|
||||
assertEquals(atom(FIELD), modelToChange.getCondition());
|
||||
|
||||
ArrangementTreeNode compositeFieldNode = myRoot.getFirstChild();
|
||||
assertNotNull(compositeFieldNode);
|
||||
|
||||
+4
@@ -72,6 +72,10 @@ public class LambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testAmbiguity1() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void _testAmbiguity2() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAmbiguityVarargs() throws Exception {
|
||||
doTest();
|
||||
|
||||
+52
-33
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.roots;
|
||||
package com.intellij.openapi.roots.impl;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
@@ -25,8 +25,6 @@ import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.module.StdModuleTypes;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.roots.ex.ProjectRootManagerEx;
|
||||
import com.intellij.openapi.roots.impl.DirectoryIndex;
|
||||
import com.intellij.openapi.roots.impl.DirectoryInfo;
|
||||
import com.intellij.openapi.util.EmptyRunnable;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.*;
|
||||
@@ -38,7 +36,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
@PlatformTestCase.WrapInCommand
|
||||
public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
@@ -57,6 +60,9 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
private VirtualFile myTestSrc1;
|
||||
private VirtualFile myPack1Dir;
|
||||
private VirtualFile myPack2Dir;
|
||||
private VirtualFile myFileLibDir;
|
||||
private VirtualFile myFileLibSrc;
|
||||
private VirtualFile myFileLibCls;
|
||||
private VirtualFile myLibDir;
|
||||
private VirtualFile myLibSrcDir;
|
||||
private VirtualFile myLibClsDir;
|
||||
@@ -75,10 +81,11 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
myRootVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(root);
|
||||
assertNotNull(myRootVFile);
|
||||
/*
|
||||
root
|
||||
lib
|
||||
file.src
|
||||
file.cls
|
||||
module1
|
||||
src1
|
||||
pack1
|
||||
@@ -95,16 +102,21 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
out
|
||||
module1
|
||||
*/
|
||||
myRootVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(root);
|
||||
assertNotNull(myRootVFile);
|
||||
|
||||
myFileLibDir = myRootVFile.createChildDirectory(DirectoryIndexImplTest.this, "lib");
|
||||
myFileLibSrc = myFileLibDir.createChildData(DirectoryIndexImplTest.this, "file.src");
|
||||
myFileLibCls = myFileLibDir.createChildData(DirectoryIndexImplTest.this, "file.cls");
|
||||
myModule1Dir = myRootVFile.createChildDirectory(DirectoryIndexImplTest.this, "module1");
|
||||
mySrcDir1 = myModule1Dir.createChildDirectory(DirectoryIndexImplTest.this, "src1");
|
||||
myPack1Dir = mySrcDir1.createChildDirectory(DirectoryIndexImplTest.this, "pack1");
|
||||
myTestSrc1 = mySrcDir1.createChildDirectory(DirectoryIndexImplTest.this, "testSrc");
|
||||
myPack2Dir = myTestSrc1.createChildDirectory(DirectoryIndexImplTest.this, "pack2");
|
||||
|
||||
myLibDir = myModule1Dir.createChildDirectory(DirectoryIndexImplTest.this, "lib");
|
||||
myLibSrcDir = myLibDir.createChildDirectory(DirectoryIndexImplTest.this, "src");
|
||||
myLibClsDir = myLibDir.createChildDirectory(DirectoryIndexImplTest.this, "cls");
|
||||
|
||||
myModule2Dir = myModule1Dir.createChildDirectory(DirectoryIndexImplTest.this, "module2");
|
||||
mySrcDir2 = myModule2Dir.createChildDirectory(DirectoryIndexImplTest.this, "src2");
|
||||
myCvsDir = mySrcDir2.createChildDirectory(DirectoryIndexImplTest.this, "CVS");
|
||||
@@ -116,6 +128,7 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
myModule1OutputDir = myOutputDir.createChildDirectory(DirectoryIndexImplTest.this, "module1");
|
||||
|
||||
getCompilerProjectExtension().setCompilerOutputUrl(myOutputDir.getUrl());
|
||||
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
|
||||
|
||||
// fill roots of module1
|
||||
{
|
||||
@@ -123,10 +136,10 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
PsiTestUtil.addContentRoot(myModule, myModule1Dir);
|
||||
PsiTestUtil.addSourceRoot(myModule, mySrcDir1);
|
||||
PsiTestUtil.addSourceRoot(myModule, myTestSrc1, true);
|
||||
ModuleRootModificationUtil.addModuleLibrary(myModule, "lib.js",
|
||||
singletonList(myFileLibCls.getUrl()), singletonList(myFileLibSrc.getUrl()));
|
||||
}
|
||||
|
||||
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
|
||||
|
||||
// fill roots of module2
|
||||
{
|
||||
VirtualFile moduleFile = myModule2Dir.createChildData(DirectoryIndexImplTest.this, "module2.iml");
|
||||
@@ -135,8 +148,8 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
PsiTestUtil.addContentRoot(myModule2, myModule2Dir);
|
||||
PsiTestUtil.addSourceRoot(myModule2, mySrcDir2);
|
||||
PsiTestUtil.addExcludedRoot(myModule2, myExcludeDir);
|
||||
ModuleRootModificationUtil.addModuleLibrary(myModule2, "lib", Collections.singletonList(myLibClsDir.getUrl()),
|
||||
Collections.singletonList(myLibSrcDir.getUrl()));
|
||||
ModuleRootModificationUtil.addModuleLibrary(myModule2, "lib",
|
||||
singletonList(myLibClsDir.getUrl()), singletonList(myLibSrcDir.getUrl()));
|
||||
}
|
||||
|
||||
// fill roots of module3
|
||||
@@ -166,28 +179,32 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
public void testDirInfos() {
|
||||
checkInfoNull(myRootVFile);
|
||||
|
||||
checkInfo(myModule1Dir, myModule, false, false, false, false, null, new Module[]{});
|
||||
checkInfo(mySrcDir1, myModule, true, false, false, false, "", new Module[]{myModule});
|
||||
checkInfo(myPack1Dir, myModule, true, false, false, false, "pack1", new Module[]{myModule});
|
||||
checkInfo(myTestSrc1, myModule, true, true, false, false, "", new Module[]{myModule});
|
||||
checkInfo(myPack2Dir, myModule, true, true, false, false, "pack2", new Module[]{myModule});
|
||||
checkInfo(myLibDir, myModule, false, false, false, false, null, new Module[]{});
|
||||
// beware: files in directory index
|
||||
checkInfo(myFileLibSrc, null, false, false, false, true, "");
|
||||
checkInfo(myFileLibCls, null, false, false, true, false, "");
|
||||
|
||||
checkInfo(myLibSrcDir, myModule, false, false, false, true, "", new Module[]{myModule2});
|
||||
checkInfo(myLibClsDir, myModule, false, false, true, false, "", new Module[]{myModule2});
|
||||
checkInfo(myModule1Dir, myModule, false, false, false, false, null);
|
||||
checkInfo(mySrcDir1, myModule, true, false, false, false, "", myModule);
|
||||
checkInfo(myPack1Dir, myModule, true, false, false, false, "pack1", myModule);
|
||||
checkInfo(myTestSrc1, myModule, true, true, false, false, "", myModule);
|
||||
checkInfo(myPack2Dir, myModule, true, true, false, false, "pack2", myModule);
|
||||
|
||||
checkInfo(myModule2Dir, myModule2, false, false, false, false, null, new Module[]{});
|
||||
checkInfo(mySrcDir2, myModule2, true, false, false, false, "", new Module[]{myModule2, myModule3});
|
||||
checkInfo(myLibDir, myModule, false, false, false, false, null);
|
||||
checkInfo(myLibSrcDir, myModule, false, false, false, true, "", myModule2);
|
||||
checkInfo(myLibClsDir, myModule, false, false, true, false, "", myModule2);
|
||||
|
||||
checkInfo(myModule2Dir, myModule2, false, false, false, false, null);
|
||||
checkInfo(mySrcDir2, myModule2, true, false, false, false, "", myModule2, myModule3);
|
||||
checkInfoNull(myCvsDir);
|
||||
checkInfoNull(myExcludeDir);
|
||||
|
||||
checkInfo(myModule3Dir, myModule3, false, false, false, false, null, new Module[]{});
|
||||
checkInfo(myModule3Dir, myModule3, false, false, false, false, null);
|
||||
}
|
||||
|
||||
public void testDirsByPackageName() {
|
||||
checkPackage(new VirtualFile[]{mySrcDir1, myTestSrc1, myLibSrcDir, myLibClsDir, mySrcDir2}, "");
|
||||
checkPackage(new VirtualFile[]{myPack1Dir}, "pack1");
|
||||
checkPackage(new VirtualFile[]{myPack2Dir}, "pack2");
|
||||
checkPackage("", myFileLibSrc, myFileLibCls, mySrcDir1, myTestSrc1, myLibSrcDir, myLibClsDir, mySrcDir2);
|
||||
checkPackage("pack1", myPack1Dir);
|
||||
checkPackage("pack2", myPack2Dir);
|
||||
}
|
||||
|
||||
public void testCreateDir() throws Exception {
|
||||
@@ -312,8 +329,8 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
|
||||
myIndex.checkConsistency();
|
||||
|
||||
checkInfo(myModule2Dir, myModule2, false, false, false, false, null, new Module[]{});
|
||||
checkInfo(mySrcDir2, myModule2, true, false, false, false, "", new Module[]{myModule2, myModule3});
|
||||
checkInfo(myModule2Dir, myModule2, false, false, false, false, null);
|
||||
checkInfo(mySrcDir2, myModule2, true, false, false, false, "", myModule2, myModule3);
|
||||
}
|
||||
|
||||
public void testResettingProjectOutputPath() throws Exception {
|
||||
@@ -466,8 +483,8 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
|
||||
myIndex.checkConsistency();
|
||||
|
||||
checkInfo(myModule1Dir, myModule, false, false, true, false, "", new Module[]{myModule});
|
||||
checkInfo(mySrcDir1, myModule, true, false, true, false, "", new Module[]{myModule});
|
||||
checkInfo(myModule1Dir, myModule, false, false, true, false, "", myModule);
|
||||
checkInfo(mySrcDir1, myModule, true, false, true, false, "", myModule);
|
||||
}
|
||||
|
||||
|
||||
@@ -479,13 +496,13 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
}
|
||||
|
||||
private void checkInfo(VirtualFile dir,
|
||||
Module module,
|
||||
@Nullable Module module,
|
||||
boolean isInModuleSource,
|
||||
boolean isTestSource,
|
||||
boolean isInLibrary,
|
||||
boolean isInLibrarySource,
|
||||
@Nullable String packageName,
|
||||
Module[] modulesOfOrderEntries) {
|
||||
Module... modulesOfOrderEntries) {
|
||||
DirectoryInfo info = myIndex.getInfoForDirectory(dir);
|
||||
assertNotNull(info);
|
||||
assertEquals(module, info.module);
|
||||
@@ -495,7 +512,9 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
assertEquals(isInLibrarySource, info.isInLibrarySource);
|
||||
|
||||
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
|
||||
assertEquals(packageName, fileIndex.getPackageNameByDirectory(dir));
|
||||
if (dir.isDirectory()) {
|
||||
assertEquals(packageName, fileIndex.getPackageNameByDirectory(dir));
|
||||
}
|
||||
|
||||
assertEquals(modulesOfOrderEntries.length, info.getOrderEntries().size());
|
||||
for (Module aModule : modulesOfOrderEntries) {
|
||||
@@ -515,7 +534,7 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
assertNull(info);
|
||||
}
|
||||
|
||||
private void checkPackage(VirtualFile[] expectedDirs, String packageName) {
|
||||
private void checkPackage(String packageName, VirtualFile... expectedDirs) {
|
||||
VirtualFile[] actualDirs = myIndex.getDirectoriesByPackageName(packageName, true).toArray(VirtualFile.EMPTY_ARRAY);
|
||||
assertNotNull(actualDirs);
|
||||
HashSet<VirtualFile> set1 = new HashSet<VirtualFile>();
|
||||
+4
-4
@@ -54,7 +54,7 @@ class Test2 {
|
||||
public void test() {
|
||||
}
|
||||
}''',
|
||||
[new ArrangementRule(atom(ArrangementEntryType.FIELD))]
|
||||
[rule(atom(ArrangementEntryType.FIELD))]
|
||||
)
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ class Test {
|
||||
return null;
|
||||
}
|
||||
}''',
|
||||
[new ArrangementRule(atom(ArrangementEntryType.FIELD))]
|
||||
[rule(atom(ArrangementEntryType.FIELD))]
|
||||
)
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ class Test {
|
||||
});
|
||||
}
|
||||
}''',
|
||||
[new ArrangementRule(atom(ArrangementEntryType.FIELD))]
|
||||
[rule(atom(ArrangementEntryType.FIELD))]
|
||||
)
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ class Test {
|
||||
});
|
||||
}
|
||||
}''',
|
||||
[new ArrangementRule(atom(ArrangementEntryType.FIELD))]
|
||||
[rule(atom(ArrangementEntryType.FIELD))]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,10 @@ public class RenameLocalTest extends LightRefactoringTestCase {
|
||||
public void testRenameInPlaceQualifyFieldReference() throws Exception {
|
||||
doTestInplaceRename("myI");
|
||||
}
|
||||
|
||||
public void testRenameInPlaceThisNeeded() throws Exception {
|
||||
doTestInplaceRename("a");
|
||||
}
|
||||
|
||||
public void testRenameInPlaceParamInOverriderAutomaticRenamer() throws Exception {
|
||||
doTestInplaceRename("pp");
|
||||
|
||||
@@ -30,8 +30,8 @@ public abstract class PsiDocumentManager {
|
||||
public abstract boolean isCommitted(@NotNull Document document);
|
||||
|
||||
/**
|
||||
* Defer action until all documents are committed
|
||||
* must be called from EDT only
|
||||
* Defer action until all documents are committed.
|
||||
* Must be called from the EDT only.
|
||||
*
|
||||
* @param action to run when all documents committed
|
||||
* @return true if action was run immediately (i.e. all documents are already committed)
|
||||
|
||||
@@ -32,7 +32,10 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiLock;
|
||||
import com.intellij.psi.impl.DebugUtil;
|
||||
import com.intellij.psi.impl.FreeThreadedFileViewProvider;
|
||||
import com.intellij.psi.impl.source.*;
|
||||
import com.intellij.psi.impl.source.DummyHolder;
|
||||
import com.intellij.psi.impl.source.DummyHolderElement;
|
||||
import com.intellij.psi.impl.source.DummyHolderFactory;
|
||||
import com.intellij.psi.impl.source.SourceTreeToPsiMap;
|
||||
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
@@ -102,9 +105,19 @@ public class CompositeElement extends TreeElement {
|
||||
|
||||
@Override
|
||||
public void clearCaches() {
|
||||
assertThreading();
|
||||
myCachedLength = NOT_CACHED;
|
||||
|
||||
myModificationsCount++;
|
||||
myHC = -1;
|
||||
|
||||
clearRelativeOffsets(rawFirstChild());
|
||||
}
|
||||
|
||||
public void assertThreading() {
|
||||
if (ASSERT_THREADING) {
|
||||
boolean ok = ApplicationManager.getApplication().isWriteAccessAllowed() ||
|
||||
Thread.holdsLock(START_OFFSET_LOCK) ||
|
||||
//Thread.holdsLock(START_OFFSET_LOCK) ||
|
||||
isNonPhysicalOrInjected();
|
||||
if (!ok) {
|
||||
FileElement fileElement;
|
||||
@@ -122,12 +135,6 @@ public class CompositeElement extends TreeElement {
|
||||
);
|
||||
}
|
||||
}
|
||||
myCachedLength = NOT_CACHED;
|
||||
|
||||
myModificationsCount++;
|
||||
myHC = -1;
|
||||
|
||||
clearRelativeOffsets(rawFirstChild());
|
||||
}
|
||||
|
||||
private boolean isNonPhysicalOrInjected() {
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.psi.codeStyle.arrangement.ArrangementRule;
|
||||
import com.intellij.psi.codeStyle.arrangement.ArrangementUtil;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryMatcher;
|
||||
import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters;
|
||||
import com.intellij.util.xmlb.XmlSerializer;
|
||||
import org.intellij.lang.annotations.MagicConstant;
|
||||
@@ -45,7 +46,8 @@ public class CommonCodeStyleSettings {
|
||||
|
||||
@NonNls private static final String ARRANGEMENT_ELEMENT_NAME = "arrangementRules";
|
||||
|
||||
private final List<ArrangementRule> myArrangementRules = new ArrayList<ArrangementRule>();
|
||||
private final List<ArrangementRule> myArrangementRules
|
||||
= new ArrayList<ArrangementRule>();
|
||||
private final Language myLanguage;
|
||||
private CodeStyleSettings myRootSettings;
|
||||
private IndentOptions myIndentOptions;
|
||||
@@ -126,11 +128,12 @@ public class CommonCodeStyleSettings {
|
||||
return myArrangementRules;
|
||||
}
|
||||
|
||||
public void setArrangementRules(@NotNull List<ArrangementRule> rules) {
|
||||
public void setArrangementRules(@NotNull List<? extends ArrangementRule> rules) {
|
||||
myArrangementRules.clear();
|
||||
myArrangementRules.addAll(rules);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public CommonCodeStyleSettings clone(@NotNull CodeStyleSettings rootSettings) {
|
||||
CommonCodeStyleSettings commonSettings = new CommonCodeStyleSettings(myLanguage, getFileType());
|
||||
copyPublicFields(this, commonSettings);
|
||||
@@ -139,6 +142,9 @@ public class CommonCodeStyleSettings {
|
||||
IndentOptions targetIndentOptions = commonSettings.initIndentOptions();
|
||||
targetIndentOptions.copyFrom(myIndentOptions);
|
||||
}
|
||||
if (!myArrangementRules.isEmpty()) {
|
||||
rootSettings.setArrangementRules(getArrangementRules());
|
||||
}
|
||||
return commonSettings;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
package com.intellij.psi.codeStyle.arrangement;
|
||||
|
||||
import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryMatcher;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition;
|
||||
import com.intellij.psi.codeStyle.arrangement.order.ArrangementEntryOrderType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -33,20 +31,18 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public class ArrangementRule {
|
||||
|
||||
@NotNull private final ArrangementEntryMatcher myMatcher;
|
||||
@NotNull private final ArrangementEntryOrderType mySortType;
|
||||
@NotNull public static final ArrangementEntryOrderType DEFAULT_ORDER_TYPE = ArrangementEntryOrderType.KEEP;
|
||||
|
||||
public ArrangementRule(@NotNull ArrangementMatchCondition condition) {
|
||||
this(new StdArrangementEntryMatcher(condition));
|
||||
}
|
||||
@NotNull private final ArrangementEntryMatcher myMatcher;
|
||||
@NotNull private final ArrangementEntryOrderType myOrderType;
|
||||
|
||||
public ArrangementRule(@NotNull ArrangementEntryMatcher matcher) {
|
||||
this(matcher, ArrangementEntryOrderType.KEEP);
|
||||
this(matcher, DEFAULT_ORDER_TYPE);
|
||||
}
|
||||
|
||||
public ArrangementRule(@NotNull ArrangementEntryMatcher matcher, @NotNull ArrangementEntryOrderType type) {
|
||||
myMatcher = matcher;
|
||||
mySortType = type;
|
||||
myOrderType = type;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -55,14 +51,14 @@ public class ArrangementRule {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ArrangementEntryOrderType getSorter() {
|
||||
return mySortType;
|
||||
public ArrangementEntryOrderType getOrderType() {
|
||||
return myOrderType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = myMatcher.hashCode();
|
||||
result = 31 * result + mySortType.hashCode();
|
||||
result = 31 * result + myOrderType.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -72,11 +68,11 @@ public class ArrangementRule {
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ArrangementRule that = (ArrangementRule)o;
|
||||
return mySortType == that.mySortType && myMatcher.equals(that.myMatcher);
|
||||
return myOrderType == that.myOrderType && myMatcher.equals(that.myMatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("matcher: %s, sort type: %s", myMatcher, mySortType);
|
||||
return String.format("matcher: %s, sort type: %s", myMatcher, myOrderType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,9 @@ package com.intellij.psi.codeStyle.arrangement;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchConditionVisitor;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryType;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.ArrangementModifier;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.*;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -211,4 +210,19 @@ public class ArrangementUtil {
|
||||
return TextRange.create(startOffsetToUse, endOffsetToUse);
|
||||
}
|
||||
//endregion
|
||||
|
||||
@NotNull
|
||||
public static ArrangementSettingType parseType(@NotNull Object condition) throws IllegalArgumentException {
|
||||
if (condition instanceof ArrangementEntryType) {
|
||||
return ArrangementSettingType.TYPE;
|
||||
}
|
||||
else if (condition instanceof ArrangementModifier) {
|
||||
return ArrangementSettingType.MODIFIER;
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Can't parse type for the given condition of class '%s': %s", condition.getClass(), condition
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-13
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.intellij.psi.codeStyle.arrangement;
|
||||
|
||||
import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryMatcher;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.DefaultArrangementEntryMatcherSerializer;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher;
|
||||
import com.intellij.psi.codeStyle.arrangement.order.ArrangementEntryOrderType;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -30,22 +30,21 @@ public class DefaultArrangementRuleSerializer implements ArrangementRuleSerializ
|
||||
|
||||
public static final ArrangementRuleSerializer INSTANCE = new DefaultArrangementRuleSerializer();
|
||||
|
||||
@NotNull @NonNls private static final String RULE_ELEMENT_NAME = "rule";
|
||||
@NotNull @NonNls private static final String MATCHER_ELEMENT_NAME = "match";
|
||||
@NotNull @NonNls private static final String SORT_TYPE_ELEMENT_NAME = "sort";
|
||||
@NotNull @NonNls private static final String RULE_ELEMENT_NAME = "rule";
|
||||
@NotNull @NonNls private static final String MATCHER_ELEMENT_NAME = "match";
|
||||
@NotNull @NonNls private static final String ORDER_TYPE_ELEMENT_NAME = "order";
|
||||
|
||||
@NotNull private final DefaultArrangementEntryMatcherSerializer myMatcherSerializer = new DefaultArrangementEntryMatcherSerializer();
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ArrangementRule deserialize(@NotNull Element element) {
|
||||
public StdArrangementRule deserialize(@NotNull Element element) {
|
||||
Element matcherElement = element.getChild(MATCHER_ELEMENT_NAME);
|
||||
if (matcherElement == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ArrangementEntryMatcher matcher = null;
|
||||
StdArrangementEntryMatcher matcher = null;
|
||||
for (Object o : matcherElement.getChildren()) {
|
||||
matcher = myMatcherSerializer.deserialize((Element)o);
|
||||
if (matcher != null) {
|
||||
@@ -57,13 +56,13 @@ public class DefaultArrangementRuleSerializer implements ArrangementRuleSerializ
|
||||
return null;
|
||||
}
|
||||
|
||||
Element sortElement = element.getChild(SORT_TYPE_ELEMENT_NAME);
|
||||
ArrangementEntryOrderType sortType = ArrangementEntryOrderType.KEEP;
|
||||
if (sortElement != null) {
|
||||
sortType = ArrangementEntryOrderType.valueOf(sortElement.getText());
|
||||
Element orderTypeElement = element.getChild(ORDER_TYPE_ELEMENT_NAME);
|
||||
ArrangementEntryOrderType orderType = ArrangementRule.DEFAULT_ORDER_TYPE;
|
||||
if (orderTypeElement != null) {
|
||||
orderType = ArrangementEntryOrderType.valueOf(orderTypeElement.getText());
|
||||
}
|
||||
|
||||
return new ArrangementRule(matcher, sortType);
|
||||
return new StdArrangementRule(matcher, orderType);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -76,7 +75,9 @@ public class DefaultArrangementRuleSerializer implements ArrangementRuleSerializ
|
||||
|
||||
Element result = new Element(RULE_ELEMENT_NAME);
|
||||
result.addContent(new Element(MATCHER_ELEMENT_NAME).addContent(matcherElement));
|
||||
result.addContent(new Element(SORT_TYPE_ELEMENT_NAME).setText(rule.getSorter().toString()));
|
||||
if (rule.getOrderType() != ArrangementRule.DEFAULT_ORDER_TYPE) {
|
||||
result.addContent(new Element(ORDER_TYPE_ELEMENT_NAME).setText(rule.getOrderType().toString()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.codeStyle.arrangement;
|
||||
|
||||
import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher;
|
||||
import com.intellij.psi.codeStyle.arrangement.order.ArrangementEntryOrderType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Arrangement rule which uses {@link StdArrangementEntryMatcher standard settings-based matcher}.
|
||||
* <p/>
|
||||
* Not thread-safe.
|
||||
*
|
||||
* @author Denis Zhdanov
|
||||
* @since 8/28/12 2:59 PM
|
||||
*/
|
||||
public class StdArrangementRule extends ArrangementRule {
|
||||
|
||||
public StdArrangementRule(@NotNull StdArrangementEntryMatcher matcher) {
|
||||
super(matcher);
|
||||
}
|
||||
|
||||
public StdArrangementRule(@NotNull StdArrangementEntryMatcher matcher, @NotNull ArrangementEntryOrderType type) {
|
||||
super(matcher, type);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public StdArrangementEntryMatcher getMatcher() {
|
||||
return (StdArrangementEntryMatcher)super.getMatcher();
|
||||
}
|
||||
}
|
||||
+8
@@ -32,6 +32,14 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public interface ArrangementEntryMatcher {
|
||||
|
||||
@NotNull
|
||||
ArrangementEntryMatcher EMPTY = new ArrangementEntryMatcher() {
|
||||
@Override
|
||||
public boolean isMatched(@NotNull ArrangementEntry entry) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Allows to check if given entry is matched by the current rule.
|
||||
* <p/>
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ public class DefaultArrangementEntryMatcherSerializer {
|
||||
|
||||
@SuppressWarnings("MethodMayBeStatic")
|
||||
@Nullable
|
||||
public ArrangementEntryMatcher deserialize(@NotNull Element matcherElement) {
|
||||
public StdArrangementEntryMatcher deserialize(@NotNull Element matcherElement) {
|
||||
ArrangementMatchCondition condition = deserializeCondition(matcherElement);
|
||||
return condition == null ? null : new StdArrangementEntryMatcher(condition);
|
||||
}
|
||||
|
||||
+26
-1
@@ -57,6 +57,29 @@ public class StdArrangementEntryMatcher implements ArrangementEntryMatcher {
|
||||
return myDelegate.isMatched(entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return myCondition.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
StdArrangementEntryMatcher matcher = (StdArrangementEntryMatcher)o;
|
||||
return myCondition.equals(matcher.myCondition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return myCondition.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ArrangementEntryMatcher doBuildMatcher(@NotNull ArrangementMatchCondition condition) {
|
||||
MyVisitor visitor = new MyVisitor();
|
||||
@@ -103,7 +126,9 @@ public class StdArrangementEntryMatcher implements ArrangementEntryMatcher {
|
||||
public ArrangementEntryMatcher getMatcher() {
|
||||
ByTypeArrangementEntryMatcher byType = myTypes.isEmpty() ? null : new ByTypeArrangementEntryMatcher(myTypes);
|
||||
ByModifierArrangementEntryMatcher byModifiers = myModifiers.isEmpty() ? null : new ByModifierArrangementEntryMatcher(myModifiers);
|
||||
assert byType != null || byModifiers != null || (myOperator != null && !myMatchers.isEmpty());
|
||||
if (byType == null && byModifiers == null && (myOperator == null || myMatchers.isEmpty())) {
|
||||
return ArrangementEntryMatcher.EMPTY;
|
||||
}
|
||||
if (myMatchers.isEmpty() && (byType == null ^ byModifiers == null)) {
|
||||
return byModifiers == null ? byType : byModifiers;
|
||||
}
|
||||
|
||||
+2
-2
@@ -44,8 +44,8 @@ public class ArrangementCompositeMatchCondition implements ArrangementMatchCondi
|
||||
return myOperands;
|
||||
}
|
||||
|
||||
public ArrangementCompositeMatchCondition addOperand(@NotNull ArrangementMatchCondition node) {
|
||||
myOperands.add(node);
|
||||
public ArrangementCompositeMatchCondition addOperand(@NotNull ArrangementMatchCondition condition) {
|
||||
myOperands.add(condition);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
+9
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.psi.codeStyle.arrangement.settings;
|
||||
|
||||
import com.intellij.psi.codeStyle.arrangement.StdArrangementRule;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryType;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.ArrangementModifier;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition;
|
||||
@@ -22,6 +23,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -32,6 +34,13 @@ import java.util.Set;
|
||||
* @since 8/6/12 2:26 PM
|
||||
*/
|
||||
public interface ArrangementStandardSettingsAware {
|
||||
|
||||
/**
|
||||
* @return list of rules to use by default, i.e. when a user hasn't been explicitly modified arrangement settings;
|
||||
* <code>null</code> as an indication that no default rules are available
|
||||
*/
|
||||
@Nullable
|
||||
List<StdArrangementRule> getDefaultRules();
|
||||
|
||||
/**
|
||||
* Allows to answer if given entry type can be applied for the rule specified by the given settings node.
|
||||
|
||||
+2
-2
@@ -56,8 +56,8 @@ public class ArrangementConfigUtil {
|
||||
* @return map which contains information on what new new settings are available at the current situation
|
||||
*/
|
||||
@NotNull
|
||||
public static Map<ArrangementSettingType, Collection<?>> buildAvailableOptions(@NotNull ArrangementStandardSettingsAware filter,
|
||||
@Nullable ArrangementMatchCondition condition)
|
||||
public static Map<ArrangementSettingType, Collection<?>> buildAvailableConditions(@NotNull ArrangementStandardSettingsAware filter,
|
||||
@Nullable ArrangementMatchCondition condition)
|
||||
{
|
||||
Map<ArrangementSettingType, Collection<?>> result = new EnumMap<ArrangementSettingType, Collection<?>>(ArrangementSettingType.class);
|
||||
processData(filter, condition, result, ArrangementSettingType.TYPE, ArrangementEntryType.values());
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ public class ArrangementNodeDisplayManager {
|
||||
@NotNull ArrangementStandardSettingsRepresentationAware representationManager)
|
||||
{
|
||||
myRepresentationManager = representationManager;
|
||||
Map<ArrangementSettingType, Collection<?>> map = ArrangementConfigUtil.buildAvailableOptions(filter, null);
|
||||
Map<ArrangementSettingType, Collection<?>> map = ArrangementConfigUtil.buildAvailableConditions(filter, null);
|
||||
for (Map.Entry<ArrangementSettingType, Collection<?>> entry : map.entrySet()) {
|
||||
myMaxWidths.put(entry.getKey(), maxWidth(entry.getValue()));
|
||||
}
|
||||
|
||||
+20
-8
@@ -15,9 +15,13 @@
|
||||
*/
|
||||
package com.intellij.application.options.codeStyle.arrangement;
|
||||
|
||||
import com.intellij.psi.codeStyle.arrangement.ArrangementOperator;
|
||||
import com.intellij.psi.codeStyle.arrangement.StdArrangementRule;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryType;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.ArrangementModifier;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -31,9 +35,17 @@ import org.jetbrains.annotations.NotNull;
|
||||
* @since 8/15/12 1:04 PM
|
||||
*/
|
||||
public interface ArrangementRuleEditingModel {
|
||||
|
||||
|
||||
@NotNull
|
||||
ArrangementMatchCondition getMatchCondition();
|
||||
StdArrangementRule EMPTY_RULE = new StdArrangementRule(new StdArrangementEntryMatcher(
|
||||
new ArrangementCompositeMatchCondition(ArrangementOperator.AND)
|
||||
));
|
||||
|
||||
@NotNull
|
||||
ArrangementMatchCondition getCondition();
|
||||
|
||||
@NotNull
|
||||
StdArrangementRule getRule();
|
||||
|
||||
/**
|
||||
* Asks current model to destroy itself.
|
||||
@@ -41,17 +53,17 @@ public interface ArrangementRuleEditingModel {
|
||||
* The key concern here is to perform necessary tree modification.
|
||||
*/
|
||||
void destroy();
|
||||
|
||||
|
||||
/**
|
||||
* Allows to answer if current model has a registered condition for the given key. A key is expected to be one of the standard
|
||||
* keys, e.g. {@link ArrangementEntryType type}, {@link ArrangementModifier modifier} etc.
|
||||
*
|
||||
*
|
||||
* @param key target key
|
||||
* @return <code>true</code> if current model has a registered mapping for the given key;
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
boolean hasCondition(@NotNull Object key);
|
||||
|
||||
|
||||
void addAndCondition(@NotNull ArrangementAtomMatchCondition condition);
|
||||
|
||||
void removeAndCondition(@NotNull ArrangementMatchCondition condition);
|
||||
@@ -60,12 +72,12 @@ public interface ArrangementRuleEditingModel {
|
||||
* We need to be able to replace one condition by another. Most of the time it can be simulated by
|
||||
* {@link #removeAndCondition(ArrangementMatchCondition) 'remove old'} and
|
||||
* {@link #addAndCondition(ArrangementAtomMatchCondition) 'add new'} actions sequence but that doesn't work when
|
||||
* {@link #getMatchCondition() underlying condition} has the only atom condition. Removing it eliminates the condition at all.
|
||||
*
|
||||
* {@link #getRule() underlying condition} has the only atom condition. Removing it eliminates the condition at all.
|
||||
*
|
||||
* @param from condition which should be replaced
|
||||
* @param to replacement condition
|
||||
* @throws IllegalArgumentException when given 'from' condition is not a part of the
|
||||
* {@link #getMatchCondition() underlying match condition}
|
||||
* {@link #getRule() underlying match condition}
|
||||
*/
|
||||
void replaceCondition(@NotNull ArrangementAtomMatchCondition from, @NotNull ArrangementAtomMatchCondition to)
|
||||
throws IllegalArgumentException;
|
||||
|
||||
+5
-4
@@ -16,6 +16,7 @@
|
||||
package com.intellij.application.options.codeStyle.arrangement;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.codeStyle.arrangement.StdArrangementRule;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.ArrangementModifier;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.HierarchicalArrangementConditionNode;
|
||||
@@ -58,7 +59,7 @@ public class ArrangementRuleEditingModelBuilder {
|
||||
* </ol>
|
||||
* </pre>
|
||||
*
|
||||
* @param matchCondition target settings to process
|
||||
* @param rule target rule to process
|
||||
* @param tree UI tree which shows arrangement matcher rules
|
||||
* @param root UI tree settings root to use (may be not the same as the tree root)
|
||||
* @param anchor node after which should be previous sibling for the root node of the inserted condition;
|
||||
@@ -70,13 +71,13 @@ public class ArrangementRuleEditingModelBuilder {
|
||||
*/
|
||||
@SuppressWarnings("MethodMayBeStatic")
|
||||
public Pair<ArrangementRuleEditingModelImpl, TIntIntHashMap> build(
|
||||
@NotNull ArrangementMatchCondition matchCondition,
|
||||
@NotNull StdArrangementRule rule,
|
||||
@NotNull JTree tree,
|
||||
@NotNull ArrangementTreeNode root,
|
||||
@Nullable ArrangementTreeNode anchor,
|
||||
@NotNull ArrangementConditionsGrouper grouper)
|
||||
{
|
||||
HierarchicalArrangementConditionNode grouped = grouper.group(matchCondition);
|
||||
HierarchicalArrangementConditionNode grouped = grouper.group(rule.getMatcher().getCondition());
|
||||
DefaultTreeModel treeModel = (DefaultTreeModel)tree.getModel();
|
||||
Pair<ArrangementTreeNode, Integer> pair = ArrangementConfigUtil.map(null, grouped, null);
|
||||
ArrangementTreeNode topMostNode = ArrangementConfigUtil.getRoot(pair.first);
|
||||
@@ -95,7 +96,7 @@ public class ArrangementRuleEditingModelBuilder {
|
||||
int row = ArrangementConfigUtil.getRow(pair.first, tree.isRootVisible());
|
||||
ArrangementRuleEditingModelImpl model = new ArrangementRuleEditingModelImpl(
|
||||
treeModel,
|
||||
matchCondition,
|
||||
rule,
|
||||
topMostNode,
|
||||
pair.first,
|
||||
grouper,
|
||||
|
||||
+36
-26
@@ -18,6 +18,8 @@ package com.intellij.application.options.codeStyle.arrangement;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.codeStyle.arrangement.ArrangementUtil;
|
||||
import com.intellij.psi.codeStyle.arrangement.StdArrangementRule;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.*;
|
||||
import com.intellij.psi.codeStyle.arrangement.settings.ArrangementConditionsGrouper;
|
||||
import com.intellij.util.containers.hash.HashSet;
|
||||
@@ -46,17 +48,17 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
|
||||
@NotNull private final ArrangementConditionsGrouper myGrouper;
|
||||
private final boolean myRootVisible;
|
||||
|
||||
@NotNull private ArrangementTreeNode myTopMost;
|
||||
@NotNull private ArrangementTreeNode myBottomMost;
|
||||
@NotNull private ArrangementMatchCondition myMatchCondition;
|
||||
private int myRow;
|
||||
@NotNull private ArrangementTreeNode myTopMost;
|
||||
@NotNull private ArrangementTreeNode myBottomMost;
|
||||
@NotNull private StdArrangementRule myRule;
|
||||
private int myRow;
|
||||
|
||||
/**
|
||||
* Creates new <code>ArrangementRuleEditingModelImpl</code> object.
|
||||
*
|
||||
* @param model tree model which holds target ui nodes. Basically, we need to perform ui nodes modification via it in order
|
||||
* to generate corresponding events automatically
|
||||
* @param node backing settings node
|
||||
* @param rule backing arrangement rule
|
||||
* @param topMost there is a possible case that a single settings node is shown in more than one visual line
|
||||
* ({@link HierarchicalArrangementConditionNode}). This argument is the top-most UI node used for the
|
||||
* settings node representation
|
||||
@@ -66,7 +68,7 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
|
||||
* @param rootVisible determines if the root should be count during rows calculations
|
||||
*/
|
||||
public ArrangementRuleEditingModelImpl(@NotNull DefaultTreeModel model,
|
||||
@NotNull ArrangementMatchCondition node,
|
||||
@NotNull StdArrangementRule rule,
|
||||
@NotNull ArrangementTreeNode topMost,
|
||||
@NotNull ArrangementTreeNode bottomMost,
|
||||
@NotNull ArrangementConditionsGrouper grouper,
|
||||
@@ -74,7 +76,7 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
|
||||
boolean rootVisible)
|
||||
{
|
||||
myTreeModel = model;
|
||||
myMatchCondition = node;
|
||||
myRule = rule;
|
||||
myTopMost = topMost;
|
||||
myBottomMost = bottomMost;
|
||||
myGrouper = grouper;
|
||||
@@ -87,7 +89,7 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
|
||||
myConditions.clear();
|
||||
CONDITIONS_BUILDER.conditions = myConditions;
|
||||
try {
|
||||
myMatchCondition.invite(CONDITIONS_BUILDER);
|
||||
getCondition().invite(CONDITIONS_BUILDER);
|
||||
}
|
||||
finally {
|
||||
CONDITIONS_BUILDER.conditions = null;
|
||||
@@ -96,8 +98,14 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ArrangementMatchCondition getMatchCondition() {
|
||||
return myMatchCondition;
|
||||
public ArrangementMatchCondition getCondition() {
|
||||
return myRule.getMatcher().getCondition();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public StdArrangementRule getRule() {
|
||||
return myRule;
|
||||
}
|
||||
|
||||
public int getRow() {
|
||||
@@ -143,10 +151,10 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
|
||||
public void addAndCondition(@NotNull ArrangementAtomMatchCondition condition) {
|
||||
if (ArrangementConstants.LOG_RULE_MODIFICATION) {
|
||||
LOG.info(String.format(
|
||||
"Arrangement rule modification - adding a condition '%s'. Model: '%s', row: %d", condition, myMatchCondition, myRow
|
||||
"Arrangement rule modification - adding a condition '%s'. Model: '%s', row: %d", condition, myRule, myRow
|
||||
));
|
||||
}
|
||||
ArrangementMatchCondition newCondition = ArrangementUtil.and(myMatchCondition.clone(), condition);
|
||||
ArrangementMatchCondition newCondition = ArrangementUtil.and(getCondition().clone(), condition);
|
||||
applyNewCondition(newCondition);
|
||||
}
|
||||
|
||||
@@ -154,16 +162,17 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
|
||||
public void removeAndCondition(@NotNull ArrangementMatchCondition condition) {
|
||||
if (ArrangementConstants.LOG_RULE_MODIFICATION) {
|
||||
LOG.info(String.format(
|
||||
"Arrangement rule modification - removing a condition '%s'. Model: '%s', row: %d", condition, myMatchCondition, myRow
|
||||
"Arrangement rule modification - removing a condition '%s'. Model: '%s', row: %d", condition, myRule, myRow
|
||||
));
|
||||
}
|
||||
if (myMatchCondition.equals(condition)) {
|
||||
ArrangementMatchCondition matchCondition = getCondition();
|
||||
if (matchCondition.equals(condition)) {
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
assert myMatchCondition instanceof ArrangementCompositeMatchCondition;
|
||||
ArrangementMatchCondition newCondition = myMatchCondition.clone();
|
||||
assert matchCondition instanceof ArrangementCompositeMatchCondition;
|
||||
ArrangementMatchCondition newCondition = matchCondition.clone();
|
||||
ArrangementCompositeMatchCondition composite = (ArrangementCompositeMatchCondition)newCondition;
|
||||
composite.getOperands().remove(condition);
|
||||
if (composite.getOperands().size() == 1) {
|
||||
@@ -172,9 +181,9 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
|
||||
applyNewCondition(newCondition);
|
||||
}
|
||||
|
||||
private void applyNewCondition(@NotNull ArrangementMatchCondition newNode) {
|
||||
myMatchCondition = newNode;
|
||||
HierarchicalArrangementConditionNode grouped = myGrouper.group(newNode);
|
||||
private void applyNewCondition(@NotNull ArrangementMatchCondition newCondition) {
|
||||
myRule = new StdArrangementRule(new StdArrangementEntryMatcher(newCondition));
|
||||
HierarchicalArrangementConditionNode grouped = myGrouper.group(newCondition);
|
||||
Pair<ArrangementTreeNode, Integer> replacement = ArrangementConfigUtil.map(null, grouped, null);
|
||||
ArrangementTreeNode newBottom = replacement.first;
|
||||
ArrangementTreeNode newTop = ArrangementConfigUtil.getRoot(newBottom);
|
||||
@@ -193,7 +202,7 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
|
||||
}
|
||||
|
||||
if (ArrangementConstants.LOG_RULE_MODIFICATION) {
|
||||
LOG.info(String.format("Arrangement rule is modified: '%s', row: %d", myMatchCondition, myRow));
|
||||
LOG.info(String.format("Arrangement rule is modified: '%s', row: %d", myRule, myRow));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,16 +210,17 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
|
||||
public void replaceCondition(@NotNull ArrangementAtomMatchCondition from, @NotNull ArrangementAtomMatchCondition to) {
|
||||
if (ArrangementConstants.LOG_RULE_MODIFICATION) {
|
||||
LOG.info(String.format(
|
||||
"Arrangement rule modification - replacing condition '%s' by '%s'. Model: '%s', row: %d", from, to, myMatchCondition, myRow
|
||||
"Arrangement rule modification - replacing condition '%s' by '%s'. Model: '%s', row: %d", from, to, myRule, myRow
|
||||
));
|
||||
}
|
||||
ArrangementMatchCondition newCondition;
|
||||
if (myMatchCondition.equals(from)) {
|
||||
ArrangementMatchCondition matchCondition = getCondition();
|
||||
if (matchCondition.equals(from)) {
|
||||
newCondition = to;
|
||||
}
|
||||
else {
|
||||
assert myMatchCondition instanceof ArrangementCompositeMatchCondition;
|
||||
ArrangementCompositeMatchCondition composite = (ArrangementCompositeMatchCondition)myMatchCondition;
|
||||
assert matchCondition instanceof ArrangementCompositeMatchCondition;
|
||||
ArrangementCompositeMatchCondition composite = (ArrangementCompositeMatchCondition)matchCondition;
|
||||
ArrangementCompositeMatchCondition newComposite = composite.clone();
|
||||
newComposite.getOperands().remove(from);
|
||||
newComposite.getOperands().add(to);
|
||||
@@ -222,7 +232,7 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
|
||||
@Override
|
||||
public void destroy() {
|
||||
if (ArrangementConstants.LOG_RULE_MODIFICATION) {
|
||||
LOG.info(String.format("Arrangement rule modification - destroy. Model: '%s', row: %d", myMatchCondition, myRow));
|
||||
LOG.info(String.format("Arrangement rule modification - destroy. Model: '%s', row: %d", myRule, myRow));
|
||||
}
|
||||
for (Listener listener : myListeners) {
|
||||
listener.beforeModelDestroy(this);
|
||||
@@ -239,7 +249,7 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "model for " + myMatchCondition;
|
||||
return "model for " + myRule;
|
||||
}
|
||||
|
||||
private static class MyConditionsBuilder implements ArrangementMatchConditionVisitor {
|
||||
|
||||
+3
-3
@@ -63,7 +63,7 @@ public class ArrangementRuleEditor extends JPanel {
|
||||
private void init(@NotNull ArrangementNodeDisplayManager displayManager) {
|
||||
setLayout(new GridBagLayout());
|
||||
|
||||
Map<ArrangementSettingType, Collection<?>> supportedSettings = ArrangementConfigUtil.buildAvailableOptions(myFilter, null);
|
||||
Map<ArrangementSettingType, Collection<?>> supportedSettings = ArrangementConfigUtil.buildAvailableConditions(myFilter, null);
|
||||
addRowIfPossible(ArrangementSettingType.TYPE, supportedSettings, displayManager);
|
||||
addRowIfPossible(ArrangementSettingType.MODIFIER, supportedSettings, displayManager);
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public class ArrangementRuleEditor extends JPanel {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<ArrangementSettingType, Collection<?>> available = ArrangementConfigUtil.buildAvailableOptions(myFilter, model.getMatchCondition());
|
||||
Map<ArrangementSettingType, Collection<?>> available = ArrangementConfigUtil.buildAvailableConditions(myFilter, model.getRule().getMatcher().getCondition());
|
||||
for (Collection<?> ids : available.values()) {
|
||||
for (Object id : ids) {
|
||||
ArrangementAtomNodeComponent component = myComponents.get(id);
|
||||
@@ -157,7 +157,7 @@ public class ArrangementRuleEditor extends JPanel {
|
||||
myModel.replaceCondition(componentToDeselect.getMatchCondition(), chosenCondition);
|
||||
for (ArrangementAtomNodeComponent componentToCheck : myComponents.values()) {
|
||||
Object value = componentToCheck.getMatchCondition().getValue();
|
||||
if (myModel.hasCondition(value) && !ArrangementConfigUtil.isEnabled(value, myFilter, myModel.getMatchCondition())) {
|
||||
if (myModel.hasCondition(value) && !ArrangementConfigUtil.isEnabled(value, myFilter, myModel.getCondition())) {
|
||||
myModel.removeAndCondition(componentToCheck.getMatchCondition());
|
||||
}
|
||||
}
|
||||
|
||||
+52
-40
@@ -18,13 +18,10 @@ package com.intellij.application.options.codeStyle.arrangement;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.codeStyle.arrangement.ArrangementOperator;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryType;
|
||||
import com.intellij.psi.codeStyle.arrangement.match.ArrangementModifier;
|
||||
import com.intellij.psi.codeStyle.arrangement.StdArrangementRule;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition;
|
||||
import com.intellij.psi.codeStyle.arrangement.model.ArrangementSettingType;
|
||||
import com.intellij.psi.codeStyle.arrangement.settings.ArrangementConditionsGrouper;
|
||||
import com.intellij.ui.treeStructure.Tree;
|
||||
import com.intellij.util.Alarm;
|
||||
@@ -42,6 +39,7 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
@@ -79,7 +77,10 @@ public class ArrangementRuleTree {
|
||||
private boolean myExplicitSelectionChange;
|
||||
private boolean mySkipSelectionChange;
|
||||
|
||||
public ArrangementRuleTree(@NotNull ArrangementConditionsGrouper grouper, @NotNull ArrangementNodeDisplayManager displayManager) {
|
||||
public ArrangementRuleTree(@NotNull List<StdArrangementRule> rules,
|
||||
@NotNull ArrangementConditionsGrouper grouper,
|
||||
@NotNull ArrangementNodeDisplayManager displayManager)
|
||||
{
|
||||
myGrouper = grouper;
|
||||
myFactory = new ArrangementNodeComponentFactory(displayManager, new Consumer<ArrangementAtomMatchCondition>() {
|
||||
@Override
|
||||
@@ -179,37 +180,10 @@ public class ArrangementRuleTree {
|
||||
}
|
||||
});
|
||||
|
||||
List<ArrangementMatchCondition> rules = new ArrayList<ArrangementMatchCondition>();
|
||||
rules.add(new ArrangementCompositeMatchCondition(ArrangementOperator.AND)
|
||||
.addOperand(new ArrangementAtomMatchCondition(ArrangementSettingType.TYPE, ArrangementEntryType.FIELD))
|
||||
.addOperand(new ArrangementAtomMatchCondition(ArrangementSettingType.MODIFIER, ArrangementModifier.PUBLIC))
|
||||
.addOperand(new ArrangementAtomMatchCondition(ArrangementSettingType.MODIFIER, ArrangementModifier.STATIC))
|
||||
.addOperand(new ArrangementAtomMatchCondition(ArrangementSettingType.MODIFIER, ArrangementModifier.FINAL)));
|
||||
rules.add(new ArrangementCompositeMatchCondition(ArrangementOperator.AND)
|
||||
.addOperand(new ArrangementAtomMatchCondition(ArrangementSettingType.TYPE, ArrangementEntryType.FIELD))
|
||||
.addOperand(new ArrangementAtomMatchCondition(ArrangementSettingType.MODIFIER, ArrangementModifier.PRIVATE)));
|
||||
rules.add(new ArrangementCompositeMatchCondition(ArrangementOperator.AND)
|
||||
.addOperand(new ArrangementAtomMatchCondition(ArrangementSettingType.TYPE, ArrangementEntryType.METHOD))
|
||||
.addOperand(new ArrangementAtomMatchCondition(ArrangementSettingType.MODIFIER, ArrangementModifier.PUBLIC)));
|
||||
rules.add(new ArrangementCompositeMatchCondition(ArrangementOperator.AND)
|
||||
.addOperand(new ArrangementAtomMatchCondition(ArrangementSettingType.TYPE, ArrangementEntryType.METHOD))
|
||||
.addOperand(new ArrangementAtomMatchCondition(ArrangementSettingType.MODIFIER, ArrangementModifier.PRIVATE)));
|
||||
map(rules);
|
||||
|
||||
expandAll(myTree, new TreePath(myRoot));
|
||||
setRules(rules);
|
||||
|
||||
myTree.setShowsRootHandles(false);
|
||||
myTree.setCellRenderer(new MyCellRenderer());
|
||||
|
||||
if (ArrangementConstants.LOG_RULE_MODIFICATION) {
|
||||
LOG.info("Arrangement tree is constructed. Models:");
|
||||
myModels.forEachValue(new TObjectProcedure<ArrangementRuleEditingModelImpl>() {
|
||||
@Override
|
||||
public boolean execute(ArrangementRuleEditingModelImpl model) {
|
||||
LOG.info(String.format(" row %d, model '%s'", model.getRow(), model.getMatchCondition()));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void selectPreviousRule() {
|
||||
@@ -335,9 +309,9 @@ public class ArrangementRuleTree {
|
||||
tree.expandPath(parent);
|
||||
}
|
||||
|
||||
private void map(@NotNull List<ArrangementMatchCondition> matchConditions) {
|
||||
for (ArrangementMatchCondition matchCondition : matchConditions) {
|
||||
Pair<ArrangementRuleEditingModelImpl, TIntIntHashMap> pair = myModelBuilder.build(matchCondition, myTree, myRoot, null, myGrouper);
|
||||
private void map(@NotNull List<StdArrangementRule> rules) {
|
||||
for (StdArrangementRule rule : rules) {
|
||||
Pair<ArrangementRuleEditingModelImpl, TIntIntHashMap> pair = myModelBuilder.build(rule, myTree, myRoot, null, myGrouper);
|
||||
myModels.put(pair.first.getRow(), pair.first);
|
||||
pair.first.addListener(myModelChangeListener);
|
||||
}
|
||||
@@ -377,6 +351,44 @@ public class ArrangementRuleTree {
|
||||
return myTree;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return rules configured at the current tree at the moment
|
||||
*/
|
||||
@NotNull
|
||||
public List<StdArrangementRule> getRules() {
|
||||
int[] rows = myModels.keys();
|
||||
Arrays.sort(rows);
|
||||
List<StdArrangementRule> result = new ArrayList<StdArrangementRule>();
|
||||
for (int row : rows) {
|
||||
result.add(myModels.get(row).getRule());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setRules(@NotNull List<StdArrangementRule> rules) {
|
||||
myRenderers.clear();
|
||||
myModels.clear();
|
||||
while (myRoot.getChildCount() > 0)
|
||||
myTreeModel.removeNodeFromParent(myRoot.getFirstChild());
|
||||
map(rules);
|
||||
expandAll(myTree, new TreePath(myRoot));
|
||||
|
||||
if (ArrangementConstants.LOG_RULE_MODIFICATION) {
|
||||
LOG.info("Arrangement tree is refreshed. Given rules:");
|
||||
for (StdArrangementRule rule : rules) {
|
||||
LOG.info(" " + rule.toString());
|
||||
}
|
||||
LOG.info("Following models have been built:");
|
||||
myModels.forEachValue(new TObjectProcedure<ArrangementRuleEditingModelImpl>() {
|
||||
@Override
|
||||
public boolean execute(ArrangementRuleEditingModelImpl model) {
|
||||
LOG.info(String.format(" row %d, model '%s'", model.getRow(), model.getRule()));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ArrangementNodeComponent getNodeComponentAt(int row, @NotNull ArrangementMatchCondition condition) {
|
||||
ArrangementNodeComponent result = myRenderers.get(row);
|
||||
@@ -547,7 +559,7 @@ public class ArrangementRuleTree {
|
||||
final ArrangementTreeNode anchor = activeModel == null ? null : activeModel.getBottomMost();
|
||||
doClearSelection();
|
||||
Pair<ArrangementRuleEditingModelImpl,TIntIntHashMap> pair = myModelBuilder.build(
|
||||
new ArrangementCompositeMatchCondition(ArrangementOperator.AND), myTree, myRoot, anchor, myGrouper
|
||||
ArrangementRuleEditingModel.EMPTY_RULE, myTree, myRoot, anchor, myGrouper
|
||||
);
|
||||
processRowChanges(pair.second);
|
||||
myModels.put(pair.first.getRow(), pair.first);
|
||||
@@ -690,7 +702,7 @@ public class ArrangementRuleTree {
|
||||
boolean emptyRuleRemoved = false;
|
||||
for (Object value : values) {
|
||||
ArrangementRuleEditingModelImpl model = (ArrangementRuleEditingModelImpl)value;
|
||||
if (model != null && model != activeModel && isEmptyCondition(model.getMatchCondition())) {
|
||||
if (model != null && model != activeModel && model.getRule() == ArrangementRuleEditingModel.EMPTY_RULE) {
|
||||
model.destroy();
|
||||
emptyRuleRemoved = true;
|
||||
}
|
||||
@@ -702,7 +714,7 @@ public class ArrangementRuleTree {
|
||||
|
||||
for (Object value : myModels.getValues()) {
|
||||
ArrangementRuleEditingModelImpl model = (ArrangementRuleEditingModelImpl)value;
|
||||
if (activeModel.getMatchCondition().equals(model.getMatchCondition())) {
|
||||
if (activeModel.getRule().equals(model.getRule())) {
|
||||
mySelectionModel.setSelectionPath(new TreePath(activeModel.getBottomMost().getPath()));
|
||||
}
|
||||
}
|
||||
|
||||
+72
-22
@@ -20,12 +20,16 @@ import com.intellij.application.options.codeStyle.arrangement.action.AddArrangem
|
||||
import com.intellij.application.options.codeStyle.arrangement.action.RemoveArrangementRuleAction;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.ide.ui.customization.CustomizationUtil;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.application.ApplicationBundle;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsScheme;
|
||||
import com.intellij.openapi.editor.highlighter.EditorHighlighter;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.arrangement.ArrangementRule;
|
||||
import com.intellij.psi.codeStyle.arrangement.Rearranger;
|
||||
import com.intellij.psi.codeStyle.arrangement.StdArrangementRule;
|
||||
import com.intellij.psi.codeStyle.arrangement.settings.*;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.SideBorder;
|
||||
@@ -42,6 +46,7 @@ import java.awt.*;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -54,16 +59,24 @@ public abstract class ArrangementSettingsPanel extends CodeStyleAbstractPanel {
|
||||
|
||||
@NotNull private final JPanel myContent = new JPanel(new GridBagLayout());
|
||||
|
||||
public ArrangementSettingsPanel(@NotNull CodeStyleSettings settings, @NotNull final ArrangementStandardSettingsAware filter) {
|
||||
@NotNull private final Language myLanguage;
|
||||
@NotNull private final ArrangementStandardSettingsAware mySettingsAware;
|
||||
@NotNull private final ArrangementRuleTree myRuleTree;
|
||||
|
||||
public ArrangementSettingsPanel(@NotNull CodeStyleSettings settings, @NotNull Language language) {
|
||||
super(settings);
|
||||
myLanguage = language;
|
||||
Rearranger<?> rearranger = Rearranger.EXTENSION.forLanguage(language);
|
||||
assert rearranger instanceof ArrangementStandardSettingsAware;
|
||||
mySettingsAware = (ArrangementStandardSettingsAware)rearranger;
|
||||
ArrangementStandardSettingsRepresentationAware representationManager = DefaultArrangementSettingsRepresentationManager.INSTANCE;
|
||||
if (filter instanceof ArrangementStandardSettingsRepresentationAware) {
|
||||
representationManager = (ArrangementStandardSettingsRepresentationAware)filter;
|
||||
if (mySettingsAware instanceof ArrangementStandardSettingsRepresentationAware) {
|
||||
representationManager = (ArrangementStandardSettingsRepresentationAware)mySettingsAware;
|
||||
}
|
||||
final ArrangementNodeDisplayManager displayManager = new ArrangementNodeDisplayManager(filter, representationManager);
|
||||
final ArrangementNodeDisplayManager displayManager = new ArrangementNodeDisplayManager(mySettingsAware, representationManager);
|
||||
ArrangementConditionsGrouper grouper = DefaultArrangementSettingsGrouper.INSTANCE;
|
||||
if (filter instanceof ArrangementConditionsGrouper) {
|
||||
grouper = (ArrangementConditionsGrouper)filter;
|
||||
if (mySettingsAware instanceof ArrangementConditionsGrouper) {
|
||||
grouper = (ArrangementConditionsGrouper)mySettingsAware;
|
||||
}
|
||||
|
||||
final ActionManager actionManager = ActionManager.getInstance();
|
||||
@@ -73,9 +86,9 @@ public abstract class ArrangementSettingsPanel extends CodeStyleAbstractPanel {
|
||||
toolbarControl.add(actionToolbar.getComponent(), new GridBag().anchor(GridBagConstraints.WEST).weightx(1).fillCellHorizontally());
|
||||
toolbarControl.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT | SideBorder.TOP | SideBorder.RIGHT));
|
||||
myContent.add(toolbarControl, new GridBag().weightx(1).fillCellHorizontally().coverLine());
|
||||
|
||||
final ArrangementRuleTree ruleTree = new ArrangementRuleTree(grouper, displayManager);
|
||||
final Tree treeComponent = ruleTree.getTreeComponent();
|
||||
|
||||
myRuleTree = new ArrangementRuleTree(getRules(settings), grouper, displayManager);
|
||||
final Tree treeComponent = myRuleTree.getTreeComponent();
|
||||
actionToolbar.setTargetComponent(treeComponent);
|
||||
myContent.add(new JBScrollPane(treeComponent), new GridBag().weightx(1).weighty(1).fillCell().coverLine());
|
||||
CustomizationUtil.installPopupHandler(
|
||||
@@ -83,13 +96,22 @@ public abstract class ArrangementSettingsPanel extends CodeStyleAbstractPanel {
|
||||
);
|
||||
|
||||
final JXTaskPane editorPane = new JXTaskPane(ApplicationBundle.message("arrangement.title.editor"));
|
||||
final ArrangementRuleEditor ruleEditor = new ArrangementRuleEditor(filter, displayManager);
|
||||
final ArrangementRuleEditor ruleEditor = new ArrangementRuleEditor(mySettingsAware, displayManager);
|
||||
ruleEditor.applyBackground(treeComponent.getBackground());
|
||||
editorPane.getContentPane().setBackground(treeComponent.getBackground());
|
||||
editorPane.add(ruleEditor);
|
||||
editorPane.setCollapsed(true);
|
||||
final Ref<Boolean> resetEditor = new Ref<Boolean>(Boolean.TRUE);
|
||||
myContent.add(editorPane, new GridBag().weightx(1).fillCellHorizontally().coverLine());
|
||||
final Ref<Boolean> resetEditor = new Ref<Boolean>(Boolean.TRUE);
|
||||
linkTreeAndEditor(editorPane, ruleEditor, resetEditor);
|
||||
setupRuleManagementActions(treeComponent, editorPane, ruleEditor, resetEditor);
|
||||
setupKeyboardActions(actionManager, treeComponent);
|
||||
}
|
||||
|
||||
private void linkTreeAndEditor(@NotNull final JXTaskPane editorPane,
|
||||
@NotNull final ArrangementRuleEditor ruleEditor,
|
||||
@NotNull final Ref<Boolean> resetEditor)
|
||||
{
|
||||
editorPane.addPropertyChangeListener("collapsed", new PropertyChangeListener() {
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
@@ -98,7 +120,7 @@ public abstract class ArrangementSettingsPanel extends CodeStyleAbstractPanel {
|
||||
}
|
||||
}
|
||||
});
|
||||
ruleTree.addEditingListener(new ArrangementRuleSelectionListener() {
|
||||
myRuleTree.addEditingListener(new ArrangementRuleSelectionListener() {
|
||||
@Override
|
||||
public void onSelected(@NotNull ArrangementRuleEditingModel model) {
|
||||
ruleEditor.updateState(model);
|
||||
@@ -116,11 +138,18 @@ public abstract class ArrangementSettingsPanel extends CodeStyleAbstractPanel {
|
||||
editorPane.setCollapsed(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupRuleManagementActions(@NotNull final Tree treeComponent,
|
||||
@NotNull final JXTaskPane editorPane,
|
||||
@NotNull final ArrangementRuleEditor ruleEditor,
|
||||
@NotNull final Ref<Boolean> resetEditor)
|
||||
{
|
||||
final Runnable newRuleFunction = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
treeComponent.requestFocus();
|
||||
ArrangementRuleEditingModel model = ruleTree.newModel();
|
||||
ArrangementRuleEditingModel model = myRuleTree.newModel();
|
||||
ruleEditor.updateState(model);
|
||||
resetEditor.set(Boolean.FALSE);
|
||||
try {
|
||||
@@ -135,7 +164,7 @@ public abstract class ArrangementSettingsPanel extends CodeStyleAbstractPanel {
|
||||
@Override
|
||||
public void run() {
|
||||
treeComponent.requestFocus();
|
||||
ArrangementRuleEditingModelImpl model = ruleTree.getActiveModel();
|
||||
ArrangementRuleEditingModelImpl model = myRuleTree.getActiveModel();
|
||||
if (model != null) {
|
||||
model.destroy();
|
||||
}
|
||||
@@ -154,7 +183,29 @@ public abstract class ArrangementSettingsPanel extends CodeStyleAbstractPanel {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
setupKeyboardActions(actionManager, treeComponent);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@NotNull
|
||||
private List<StdArrangementRule> getRules(@NotNull CodeStyleSettings settings) {
|
||||
List<ArrangementRule> storedRules = settings.getCommonSettings(myLanguage).getArrangementRules();
|
||||
if (storedRules.isEmpty()) {
|
||||
List<StdArrangementRule> defaultRules = mySettingsAware.getDefaultRules();
|
||||
if (defaultRules != null) {
|
||||
return defaultRules;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// We use unchecked cast here in assumption that current rearranger is based on standard settings if it uses standard
|
||||
// settings-based rule editor.
|
||||
// Note: unchecked cast for the whole collection doesn't work here (compiler error).
|
||||
List<StdArrangementRule> result = new ArrayList<StdArrangementRule>();
|
||||
for (ArrangementRule rule : storedRules) {
|
||||
result.add((StdArrangementRule)rule);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private static void setupKeyboardActions(@NotNull ActionManager actionManager, @NotNull Tree treeComponent) {
|
||||
@@ -180,19 +231,18 @@ public abstract class ArrangementSettingsPanel extends CodeStyleAbstractPanel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified(CodeStyleSettings settings) {
|
||||
// TODO den implement
|
||||
return false;
|
||||
public boolean isModified(@NotNull CodeStyleSettings settings) {
|
||||
return !getRules(settings).equals(myRuleTree.getRules());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(CodeStyleSettings settings) {
|
||||
// TODO den implement
|
||||
public void apply(@NotNull CodeStyleSettings settings) {
|
||||
settings.getCommonSettings(myLanguage).setArrangementRules(myRuleTree.getRules());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void resetImpl(CodeStyleSettings settings) {
|
||||
// TODO den implement
|
||||
protected void resetImpl(@NotNull CodeStyleSettings settings) {
|
||||
myRuleTree.setRules(getRules(settings));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -322,8 +322,7 @@ public class ExecutionManagerImpl extends ExecutionManager implements ProjectCom
|
||||
private void forgetRunContentDescriptor(RunContentDescriptor runContentDescriptor) {
|
||||
for (Trinity<RunContentDescriptor, RunnerAndConfigurationSettings, Executor> trinity : myRunningConfigurations) {
|
||||
if (trinity.getFirst() == runContentDescriptor) {
|
||||
//runContentDescriptor.dispose();
|
||||
myRunningConfigurations.remove(trinity);
|
||||
Disposer.dispose(runContentDescriptor);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,6 +143,7 @@ public class BookmarkManager extends AbstractProjectComponent implements Persist
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public List<Bookmark> getValidBookmarks() {
|
||||
List<Bookmark> answer = new ArrayList<Bookmark>();
|
||||
for (Bookmark bookmark : myBookmarks) {
|
||||
@@ -258,6 +259,7 @@ public class BookmarkManager extends AbstractProjectComponent implements Persist
|
||||
Collections.reverse(reversed);
|
||||
|
||||
for (Bookmark bookmark : reversed) {
|
||||
if (!bookmark.isValid()) continue;
|
||||
Element bookmarkElement = new Element("bookmark");
|
||||
|
||||
bookmarkElement.setAttribute("url", bookmark.getFile().getUrl());
|
||||
@@ -286,7 +288,8 @@ public class BookmarkManager extends AbstractProjectComponent implements Persist
|
||||
*
|
||||
* @return bookmark list after moving
|
||||
*/
|
||||
public List<Bookmark> moveBookmarkUp(Bookmark bookmark) {
|
||||
@NotNull
|
||||
public List<Bookmark> moveBookmarkUp(@NotNull Bookmark bookmark) {
|
||||
int index = myBookmarks.indexOf(bookmark);
|
||||
if (index > 0) {
|
||||
Collections.swap(myBookmarks, index, index - 1);
|
||||
@@ -301,7 +304,8 @@ public class BookmarkManager extends AbstractProjectComponent implements Persist
|
||||
*
|
||||
* @return bookmark list after moving
|
||||
*/
|
||||
public List<Bookmark> moveBookmarkDown(Bookmark bookmark) {
|
||||
@NotNull
|
||||
public List<Bookmark> moveBookmarkDown(@NotNull Bookmark bookmark) {
|
||||
int index = myBookmarks.indexOf(bookmark);
|
||||
if (index < myBookmarks.size() - 1) {
|
||||
Collections.swap(myBookmarks, index, index + 1);
|
||||
@@ -311,7 +315,7 @@ public class BookmarkManager extends AbstractProjectComponent implements Persist
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Bookmark getNextBookmark(Editor editor, boolean isWrapped) {
|
||||
public Bookmark getNextBookmark(@NotNull Editor editor, boolean isWrapped) {
|
||||
Bookmark[] bookmarksForDocument = getBookmarksForDocument(editor.getDocument());
|
||||
int lineNumber = editor.getCaretModel().getLogicalPosition().line;
|
||||
for (Bookmark bookmark : bookmarksForDocument) {
|
||||
@@ -324,7 +328,7 @@ public class BookmarkManager extends AbstractProjectComponent implements Persist
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Bookmark getPreviousBookmark(Editor editor, boolean isWrapped) {
|
||||
public Bookmark getPreviousBookmark(@NotNull Editor editor, boolean isWrapped) {
|
||||
Bookmark[] bookmarksForDocument = getBookmarksForDocument(editor.getDocument());
|
||||
int lineNumber = editor.getCaretModel().getLogicalPosition().line;
|
||||
for (int i = bookmarksForDocument.length - 1; i >= 0; i--) {
|
||||
@@ -337,7 +341,8 @@ public class BookmarkManager extends AbstractProjectComponent implements Persist
|
||||
return null;
|
||||
}
|
||||
|
||||
private Bookmark[] getBookmarksForDocument(Document document) {
|
||||
@NotNull
|
||||
private Bookmark[] getBookmarksForDocument(@NotNull Document document) {
|
||||
ArrayList<Bookmark> answer = new ArrayList<Bookmark>();
|
||||
for (Bookmark bookmark : getValidBookmarks()) {
|
||||
if (document.equals(bookmark.getDocument())) {
|
||||
|
||||
@@ -45,7 +45,7 @@ import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.pom.Navigatable;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
@@ -60,6 +60,7 @@ import javax.swing.border.BevelBorder;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -91,7 +92,7 @@ public class CommanderPanel extends JPanel {
|
||||
private boolean myActive = true;
|
||||
private final List<CommanderHistoryListener> myHistoryListeners = ContainerUtil.createEmptyCOWList();
|
||||
private boolean myMoveFocus = false;
|
||||
private boolean myEnableSearchHighlighting;
|
||||
private final boolean myEnableSearchHighlighting;
|
||||
|
||||
public CommanderPanel(final Project project, final boolean enablePopupMenu, final boolean enableSearchHighlighting) {
|
||||
super(new BorderLayout());
|
||||
@@ -103,6 +104,7 @@ public class CommanderPanel extends JPanel {
|
||||
|
||||
if (enablePopupMenu) {
|
||||
myCopyPasteDelegator = new CopyPasteDelegator(myProject, myList) {
|
||||
@Override
|
||||
@NotNull
|
||||
protected PsiElement[] getSelectedElements() {
|
||||
return CommanderPanel.this.getSelectedElements();
|
||||
@@ -116,16 +118,18 @@ public class CommanderPanel extends JPanel {
|
||||
ListScrollingUtil.installActions(myList);
|
||||
|
||||
myList.registerKeyboardAction(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
if (myBuilder == null) return;
|
||||
myBuilder.buildRoot();
|
||||
}
|
||||
}, KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SLASH, SystemInfo.isMac ? KeyEvent.META_MASK : KeyEvent.CTRL_MASK), JComponent.WHEN_FOCUSED);
|
||||
}, KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SLASH, SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.CTRL_MASK), JComponent.WHEN_FOCUSED);
|
||||
|
||||
myList.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), ACTION_DRILL_DOWN);
|
||||
myList.getInputMap(WHEN_FOCUSED)
|
||||
.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, SystemInfo.isMac ? KeyEvent.META_MASK : KeyEvent.CTRL_MASK), ACTION_DRILL_DOWN);
|
||||
.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.CTRL_MASK), ACTION_DRILL_DOWN);
|
||||
myList.getActionMap().put(ACTION_DRILL_DOWN, new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
drillDown();
|
||||
}
|
||||
@@ -139,15 +143,17 @@ public class CommanderPanel extends JPanel {
|
||||
}.installOn(myList);
|
||||
|
||||
myList.getInputMap(WHEN_FOCUSED)
|
||||
.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, SystemInfo.isMac ? KeyEvent.META_MASK : KeyEvent.CTRL_MASK), ACTION_GO_UP);
|
||||
.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.CTRL_MASK), ACTION_GO_UP);
|
||||
myList.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), ACTION_GO_UP);
|
||||
myList.getActionMap().put(ACTION_GO_UP, new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
goUp();
|
||||
}
|
||||
});
|
||||
|
||||
myList.getActionMap().put("selectAll", new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
}
|
||||
});
|
||||
@@ -155,6 +161,7 @@ public class CommanderPanel extends JPanel {
|
||||
|
||||
if (enablePopupMenu) {
|
||||
myList.addMouseListener(new PopupHandler() {
|
||||
@Override
|
||||
public void invokePopup(final Component comp, final int x, final int y) {
|
||||
CommanderPanel.this.invokePopup(comp, x, y);
|
||||
}
|
||||
@@ -162,10 +169,12 @@ public class CommanderPanel extends JPanel {
|
||||
}
|
||||
|
||||
myList.addFocusListener(new FocusAdapter() {
|
||||
@Override
|
||||
public void focusGained(final FocusEvent e) {
|
||||
setActive(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void focusLost(final FocusEvent e) {
|
||||
setActive(false);
|
||||
}
|
||||
@@ -177,15 +186,11 @@ public class CommanderPanel extends JPanel {
|
||||
return myEnableSearchHighlighting;
|
||||
}
|
||||
|
||||
public ListSpeedSearch getListSpeedSearch() {
|
||||
return myListSpeedSearch;
|
||||
}
|
||||
|
||||
public void addHistoryListener(CommanderHistoryListener listener) {
|
||||
void addHistoryListener(@NotNull CommanderHistoryListener listener) {
|
||||
myHistoryListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeHistoryListener(CommanderHistoryListener listener) {
|
||||
private void removeHistoryListener(CommanderHistoryListener listener) {
|
||||
myHistoryListeners.remove(listener);
|
||||
}
|
||||
|
||||
@@ -227,7 +232,7 @@ public class CommanderPanel extends JPanel {
|
||||
}
|
||||
|
||||
final AbstractTreeNode element = getSelectedNode();
|
||||
if (element.getChildren().size() == 0) {
|
||||
if (element.getChildren().isEmpty()) {
|
||||
if (!shouldDrillDownOnEmptyElement(element)) {
|
||||
navigateSelectedElement();
|
||||
return;
|
||||
@@ -292,10 +297,12 @@ public class CommanderPanel extends JPanel {
|
||||
|
||||
// TODO[vova,anton] it seems that the code below performs double focus request. Is it OK?
|
||||
myTitlePanel.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
myList.requestFocus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(final MouseEvent e) {
|
||||
myList.requestFocus();
|
||||
}
|
||||
@@ -327,8 +334,9 @@ public class CommanderPanel extends JPanel {
|
||||
return elementAtIndex instanceof AbstractTreeNode ? (AbstractTreeNode)elementAtIndex : null;
|
||||
}
|
||||
|
||||
private ArrayList<AbstractTreeNode> getSelectedNodes() {
|
||||
if (myBuilder == null) return null;
|
||||
@NotNull
|
||||
private List<AbstractTreeNode> getSelectedNodes() {
|
||||
if (myBuilder == null) return Collections.emptyList();
|
||||
final int[] indices = myList.getSelectedIndices();
|
||||
ArrayList<AbstractTreeNode> result = new ArrayList<AbstractTreeNode>();
|
||||
for (int index : indices) {
|
||||
@@ -359,7 +367,7 @@ public class CommanderPanel extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
return PsiUtilBase.toPsiElementArray(elements);
|
||||
return PsiUtilCore.toPsiElementArray(elements);
|
||||
}
|
||||
|
||||
private static Object getValueAtIndex(AbstractTreeNode node) {
|
||||
@@ -440,39 +448,39 @@ public class CommanderPanel extends JPanel {
|
||||
if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
|
||||
return filterInvalidElements(getSelectedElements());
|
||||
}
|
||||
else if (LangDataKeys.PASTE_TARGET_PSI_ELEMENT.is(dataId)) {
|
||||
if (LangDataKeys.PASTE_TARGET_PSI_ELEMENT.is(dataId)) {
|
||||
final AbstractTreeNode parentNode = myBuilder.getParentNode();
|
||||
final Object element = parentNode != null ? parentNode.getValue() : null;
|
||||
return element instanceof PsiElement && ((PsiElement)element).isValid() ? element : null;
|
||||
}
|
||||
else if (PlatformDataKeys.NAVIGATABLE_ARRAY.is(dataId)) {
|
||||
if (PlatformDataKeys.NAVIGATABLE_ARRAY.is(dataId)) {
|
||||
return getNavigatables();
|
||||
}
|
||||
else if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
|
||||
if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
|
||||
return myCopyPasteDelegator != null ? myCopyPasteDelegator.getCopyProvider() : null;
|
||||
}
|
||||
else if (PlatformDataKeys.CUT_PROVIDER.is(dataId)) {
|
||||
if (PlatformDataKeys.CUT_PROVIDER.is(dataId)) {
|
||||
return myCopyPasteDelegator != null ? myCopyPasteDelegator.getCutProvider() : null;
|
||||
}
|
||||
else if (PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
|
||||
if (PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
|
||||
return myCopyPasteDelegator != null ? myCopyPasteDelegator.getPasteProvider() : null;
|
||||
}
|
||||
else if (LangDataKeys.IDE_VIEW.is(dataId)) {
|
||||
if (LangDataKeys.IDE_VIEW.is(dataId)) {
|
||||
return myIdeView;
|
||||
}
|
||||
else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
|
||||
if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
|
||||
return myDeleteElementProvider;
|
||||
}
|
||||
else if (LangDataKeys.MODULE.is(dataId)) {
|
||||
if (LangDataKeys.MODULE.is(dataId)) {
|
||||
return selectedValue instanceof Module ? selectedValue : null;
|
||||
}
|
||||
else if (ModuleGroup.ARRAY_DATA_KEY.is(dataId)) {
|
||||
if (ModuleGroup.ARRAY_DATA_KEY.is(dataId)) {
|
||||
return selectedValue instanceof ModuleGroup ? new ModuleGroup[]{(ModuleGroup)selectedValue} : null;
|
||||
}
|
||||
else if (LibraryGroupElement.ARRAY_DATA_KEY.is(dataId)) {
|
||||
if (LibraryGroupElement.ARRAY_DATA_KEY.is(dataId)) {
|
||||
return selectedValue instanceof LibraryGroupElement ? new LibraryGroupElement[]{(LibraryGroupElement)selectedValue} : null;
|
||||
}
|
||||
else if (NamedLibraryElement.ARRAY_DATA_KEY.is(dataId)) {
|
||||
if (NamedLibraryElement.ARRAY_DATA_KEY.is(dataId)) {
|
||||
return selectedValue instanceof NamedLibraryElement ? new NamedLibraryElement[]{(NamedLibraryElement)selectedValue} : null;
|
||||
}
|
||||
|
||||
@@ -511,7 +519,7 @@ public class CommanderPanel extends JPanel {
|
||||
validElements.add(element);
|
||||
}
|
||||
}
|
||||
return validElements.size() == elements.length ? elements : PsiUtilBase.toPsiElementArray(validElements);
|
||||
return validElements.size() == elements.length ? elements : PsiUtilCore.toPsiElementArray(validElements);
|
||||
}
|
||||
|
||||
protected final Navigatable createEditSourceDescriptor() {
|
||||
@@ -529,18 +537,20 @@ public class CommanderPanel extends JPanel {
|
||||
myPanel = panel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(String text) {
|
||||
if (text == null || text.length() == 0) {
|
||||
if (text == null || text.isEmpty()) {
|
||||
text = " ";
|
||||
}
|
||||
super.setText(text);
|
||||
if (myPanel != null) {
|
||||
myPanel.setToolTipText(text.trim().length() == 0 ? null : text);
|
||||
myPanel.setToolTipText(text.trim().isEmpty() ? null : text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class MyDeleteElementProvider implements DeleteProvider {
|
||||
@Override
|
||||
public void deleteElement(@NotNull final DataContext dataContext) {
|
||||
LocalHistoryAction a = LocalHistory.getInstance().startAction(IdeBundle.message("progress.deleting"));
|
||||
try {
|
||||
@@ -552,6 +562,7 @@ public class CommanderPanel extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDeleteElement(@NotNull final DataContext dataContext) {
|
||||
final PsiElement[] elements = getSelectedElements();
|
||||
return DeleteHandler.shouldEnableDeleteAction(elements);
|
||||
@@ -559,16 +570,19 @@ public class CommanderPanel extends JPanel {
|
||||
}
|
||||
|
||||
private final class MyIdeView implements IdeView {
|
||||
@Override
|
||||
public void selectElement(final PsiElement element) {
|
||||
final boolean isDirectory = element instanceof PsiDirectory;
|
||||
if (!isDirectory) {
|
||||
EditorHelper.openInEditor(element);
|
||||
}
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
myBuilder.selectElement(element, PsiUtilBase.getVirtualFile(element));
|
||||
myBuilder.selectElement(element, PsiUtilCore.getVirtualFile(element));
|
||||
if (!isDirectory) {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (myMoveFocus) {
|
||||
ToolWindowManager.getInstance(myProject).activateEditorComponent();
|
||||
@@ -593,11 +607,13 @@ public class CommanderPanel extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiDirectory[] getDirectories() {
|
||||
PsiDirectory directory = getDirectory();
|
||||
return directory == null ? PsiDirectory.EMPTY_ARRAY : new PsiDirectory[]{directory};
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiDirectory getOrChooseDirectory() {
|
||||
return DirectoryChooserUtil.getOrChooseDirectory(this);
|
||||
}
|
||||
@@ -605,6 +621,7 @@ public class CommanderPanel extends JPanel {
|
||||
|
||||
public static final class MyModel extends AbstractListModel implements AbstractListBuilder.Model{
|
||||
final List myElements = new ArrayList();
|
||||
@Override
|
||||
public void removeAllElements() {
|
||||
int index1 = myElements.size()-1;
|
||||
myElements.clear();
|
||||
@@ -613,30 +630,36 @@ public class CommanderPanel extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addElement(final Object obj) {
|
||||
int index = myElements.size();
|
||||
myElements.add(obj);
|
||||
fireIntervalAdded(this, index, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceElements(final List newElements) {
|
||||
removeAllElements();
|
||||
myElements.addAll(newElements);
|
||||
fireIntervalAdded(this, 0, newElements.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
return ArrayUtil.toObjectArray(myElements);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(final Object o) {
|
||||
return myElements.indexOf(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return myElements.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getElementAt(final int index) {
|
||||
return myElements.get(index);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class TopLevelNode extends AbstractTreeNode {
|
||||
public TopLevelNode(Project project, Object value) {
|
||||
super(project, value);
|
||||
myName = "[ .. ]";
|
||||
myIcon = AllIcons.Nodes.UpLevel;
|
||||
setIcon(AllIcons.Nodes.UpLevel);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+1
@@ -38,6 +38,7 @@ public abstract class FavoritesToolbarButtonAction extends AnActionButton implem
|
||||
super(name, icon);
|
||||
myBuilder = builder;
|
||||
mySettings = FavoritesManager.getInstance(project).getViewSettings();
|
||||
setContextComponent(myBuilder.getTree());
|
||||
Disposer.register(project, new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
|
||||
@@ -81,14 +81,17 @@ public abstract class BaseProjectTreeBuilder extends AbstractTreeBuilder {
|
||||
final VirtualFile finalVFile = vFile;
|
||||
final FocusRequestor focusRequestor = IdeFocusManager.getInstance(myProject).getFurtherRequestor();
|
||||
batch(new Progressive() {
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
final Ref<Object> target = new Ref<Object>();
|
||||
_select(value, finalVFile, false, Conditions.<AbstractTreeNode>alwaysTrue(), cb, indicator, target, focusRequestor, false);
|
||||
cb.doWhenDone(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
result.setDone(target.get());
|
||||
}
|
||||
}).doWhenRejected(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
result.setRejected();
|
||||
}
|
||||
@@ -102,14 +105,17 @@ public abstract class BaseProjectTreeBuilder extends AbstractTreeBuilder {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean isAlwaysShowPlus(NodeDescriptor nodeDescriptor) {
|
||||
return ((AbstractTreeNode)nodeDescriptor).isAlwaysShowPlus();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAutoExpandNode(NodeDescriptor nodeDescriptor) {
|
||||
return nodeDescriptor.getParentDescriptor() == null || ((AbstractTreeNode)nodeDescriptor).isAlwaysExpand();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void expandNodeChildren(final DefaultMutableTreeNode node) {
|
||||
final NodeDescriptor userObject = (NodeDescriptor)node.getUserObject();
|
||||
if (userObject == null) return;
|
||||
@@ -185,8 +191,10 @@ public abstract class BaseProjectTreeBuilder extends AbstractTreeBuilder {
|
||||
|
||||
UiActivityMonitor.getInstance().addActivity(myProject, new UiActivity.AsyncBgOperation("projectViewSelect"), getUpdater().getModalityState());
|
||||
cancelUpdate().doWhenDone(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
batch(new Progressive() {
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
_select(element, file, requestFocus, nonStopCondition, result, indicator, null, requestor, false);
|
||||
UiActivityMonitor.getInstance().removeActivity(myProject, new UiActivity.AsyncBgOperation("projectViewSelect"));
|
||||
@@ -212,6 +220,7 @@ public abstract class BaseProjectTreeBuilder extends AbstractTreeBuilder {
|
||||
final AbstractTreeNode alreadySelected = alreadySelectedNode(element);
|
||||
|
||||
final Runnable onDone = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (requestFocus && virtualSelectTarget == null && getUi().isReady()) {
|
||||
focusRequestor.requestFocus(getTree(), true);
|
||||
@@ -222,6 +231,7 @@ public abstract class BaseProjectTreeBuilder extends AbstractTreeBuilder {
|
||||
};
|
||||
|
||||
final Condition<AbstractTreeNode> condition = new Condition<AbstractTreeNode>() {
|
||||
@Override
|
||||
public boolean value(AbstractTreeNode abstractTreeNode) {
|
||||
if (result.isProcessed()) return false;
|
||||
return nonStopCondition.value(abstractTreeNode);
|
||||
@@ -231,6 +241,7 @@ public abstract class BaseProjectTreeBuilder extends AbstractTreeBuilder {
|
||||
if (alreadySelected == null) {
|
||||
expandPathTo(file, (AbstractTreeNode)getTreeStructure().getRootElement(), element, condition, indicator, virtualSelectTarget)
|
||||
.doWhenDone(new AsyncResult.Handler<AbstractTreeNode>() {
|
||||
@Override
|
||||
public void run(AbstractTreeNode node) {
|
||||
if (virtualSelectTarget == null) {
|
||||
select(node, onDone);
|
||||
@@ -294,6 +305,7 @@ public abstract class BaseProjectTreeBuilder extends AbstractTreeBuilder {
|
||||
if (root.canRepresent(element)) {
|
||||
if (target == null) {
|
||||
expand(root, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
async.setDone(root);
|
||||
}
|
||||
@@ -313,6 +325,7 @@ public abstract class BaseProjectTreeBuilder extends AbstractTreeBuilder {
|
||||
|
||||
if (target == null) {
|
||||
expand(root, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
indicator.checkCanceled();
|
||||
|
||||
@@ -342,6 +355,7 @@ public abstract class BaseProjectTreeBuilder extends AbstractTreeBuilder {
|
||||
}
|
||||
|
||||
yield(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isDisposed()) return;
|
||||
expandChild(kids, 0, nonStopCondition, file, element, async, indicator, target);
|
||||
@@ -371,12 +385,14 @@ public abstract class BaseProjectTreeBuilder extends AbstractTreeBuilder {
|
||||
|
||||
if (nonStopCondition.value(eachKid)) {
|
||||
expandPathTo(file, eachKid, element, nonStopCondition, indicator, virtualSelectTarget).doWhenDone(new AsyncResult.Handler<AbstractTreeNode>() {
|
||||
@Override
|
||||
public void run(AbstractTreeNode abstractTreeNode) {
|
||||
indicator.checkCanceled();
|
||||
|
||||
async.setDone(abstractTreeNode);
|
||||
}
|
||||
}).doWhenRejected(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
indicator.checkCanceled();
|
||||
|
||||
@@ -391,6 +407,7 @@ public abstract class BaseProjectTreeBuilder extends AbstractTreeBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean validateNode(final Object child) {
|
||||
if (child == null) {
|
||||
return false;
|
||||
@@ -402,6 +419,7 @@ public abstract class BaseProjectTreeBuilder extends AbstractTreeBuilder {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected ProgressIndicator createProgressIndicator() {
|
||||
return new StatusBarProgress();
|
||||
|
||||
+6
@@ -44,18 +44,21 @@ public abstract class ProjectViewPsiTreeChangeListener extends PsiTreeChangeAdap
|
||||
|
||||
protected abstract DefaultMutableTreeNode getRootNode();
|
||||
|
||||
@Override
|
||||
public final void childRemoved(@NotNull PsiTreeChangeEvent event) {
|
||||
PsiElement child = event.getOldChild();
|
||||
if (child instanceof PsiWhiteSpace) return; //optimization
|
||||
childrenChanged(event.getParent(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void childAdded(@NotNull PsiTreeChangeEvent event) {
|
||||
PsiElement child = event.getNewChild();
|
||||
if (child instanceof PsiWhiteSpace) return; //optimization
|
||||
childrenChanged(event.getParent(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void childReplaced(@NotNull PsiTreeChangeEvent event) {
|
||||
PsiElement oldChild = event.getOldChild();
|
||||
PsiElement newChild = event.getNewChild();
|
||||
@@ -63,11 +66,13 @@ public abstract class ProjectViewPsiTreeChangeListener extends PsiTreeChangeAdap
|
||||
childrenChanged(event.getParent(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void childMoved(@NotNull PsiTreeChangeEvent event) {
|
||||
childrenChanged(event.getOldParent(), false);
|
||||
childrenChanged(event.getNewParent(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void childrenChanged(@NotNull PsiTreeChangeEvent event) {
|
||||
childrenChanged(event.getParent(), true);
|
||||
}
|
||||
@@ -105,6 +110,7 @@ public abstract class ProjectViewPsiTreeChangeListener extends PsiTreeChangeAdap
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void propertyChanged(@NotNull PsiTreeChangeEvent event) {
|
||||
String propertyName = event.getPropertyName();
|
||||
PsiElement element = event.getElement();
|
||||
|
||||
+2
@@ -26,6 +26,7 @@ import com.intellij.openapi.wm.ToolWindowId;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
|
||||
public final class ChangeProjectViewAction extends AnAction {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
|
||||
if (project == null) {
|
||||
@@ -35,6 +36,7 @@ public final class ChangeProjectViewAction extends AnAction {
|
||||
projectView.changeView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent event){
|
||||
Presentation presentation = event.getPresentation();
|
||||
Project project = PlatformDataKeys.PROJECT.getData(event.getDataContext());
|
||||
|
||||
+1
@@ -32,6 +32,7 @@ public class MoveModulesOutsideGroupAction extends AnAction {
|
||||
super(IdeBundle.message("action.move.module.outside.any.group"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final DataContext dataContext = e.getDataContext();
|
||||
final Module[] modules = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext);
|
||||
|
||||
+2
@@ -39,6 +39,7 @@ public class MoveModulesToGroupAction extends AnAction {
|
||||
myModuleGroup = moduleGroup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
Presentation presentation = getTemplatePresentation();
|
||||
final DataContext dataContext = e.getDataContext();
|
||||
@@ -52,6 +53,7 @@ public class MoveModulesToGroupAction extends AnAction {
|
||||
return modules.length == 1 ? IdeBundle.message("message.module", modules[0].getName()) : IdeBundle.message("message.modules");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final DataContext dataContext = e.getDataContext();
|
||||
final Module[] modules = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext);
|
||||
|
||||
+2
@@ -34,12 +34,14 @@ public class MoveModulesToSubGroupAction extends MoveModulesToGroupAction {
|
||||
super(moduleGroup, moduleGroup == null ? IdeBundle.message("action.move.module.new.top.level.group") : IdeBundle.message("action.move.module.to.new.sub.group"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
Presentation presentation = e.getPresentation();
|
||||
String description = IdeBundle.message("action.description.create.new.module.group");
|
||||
presentation.setDescription(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final DataContext dataContext = e.getDataContext();
|
||||
final Module[] modules = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext);
|
||||
|
||||
+9
-5
@@ -35,31 +35,35 @@ public abstract class AbstractProjectTreeStructure extends ProjectAbstractTreeSt
|
||||
return new ProjectViewProjectNode(myProject, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract boolean isShowMembers();
|
||||
|
||||
@Override
|
||||
public final Object getRootElement() {
|
||||
return myRoot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void commit() {
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean hasSomethingToCommit() {
|
||||
if (myProject.isDisposed()) return false;
|
||||
return PsiDocumentManager.getInstance(myProject).hasUncommitedDocuments();
|
||||
return !myProject.isDisposed()
|
||||
&& PsiDocumentManager.getInstance(myProject).hasUncommitedDocuments();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStructureView() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlwaysLeaf(Object element) {
|
||||
if (element instanceof ProjectViewNode) {
|
||||
return ((ProjectViewNode)element).isAlwaysLeaf();
|
||||
}
|
||||
else {
|
||||
return super.isAlwaysLeaf(element);
|
||||
}
|
||||
return super.isAlwaysLeaf(element);
|
||||
}
|
||||
}
|
||||
+14
@@ -62,6 +62,7 @@ public abstract class AbstractProjectViewPSIPane extends AbstractProjectViewPane
|
||||
super(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
if (myComponent != null) return myComponent;
|
||||
|
||||
@@ -78,6 +79,7 @@ public abstract class AbstractProjectViewPSIPane extends AbstractProjectViewPane
|
||||
return myComponent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void dispose() {
|
||||
myComponent = null;
|
||||
super.dispose();
|
||||
@@ -97,23 +99,28 @@ public abstract class AbstractProjectViewPSIPane extends AbstractProjectViewPane
|
||||
TreeUtil.installActions(myTree);
|
||||
|
||||
myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
|
||||
@Override
|
||||
public void valueChanged(TreeSelectionEvent e) {
|
||||
fireTreeChangeListener();
|
||||
}
|
||||
});
|
||||
myTree.getModel().addTreeModelListener(new TreeModelListener() {
|
||||
@Override
|
||||
public void treeNodesChanged(TreeModelEvent e) {
|
||||
fireTreeChangeListener();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void treeNodesInserted(TreeModelEvent e) {
|
||||
fireTreeChangeListener();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void treeNodesRemoved(TreeModelEvent e) {
|
||||
fireTreeChangeListener();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void treeStructureChanged(TreeModelEvent e) {
|
||||
fireTreeChangeListener();
|
||||
}
|
||||
@@ -122,6 +129,7 @@ public abstract class AbstractProjectViewPSIPane extends AbstractProjectViewPane
|
||||
new MySpeedSearch(myTree);
|
||||
|
||||
myTree.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (KeyEvent.VK_ENTER == e.getKeyCode()) {
|
||||
|
||||
@@ -147,6 +155,7 @@ public abstract class AbstractProjectViewPSIPane extends AbstractProjectViewPane
|
||||
CustomizationUtil.installPopupHandler(myTree, IdeActions.GROUP_PROJECT_VIEW_POPUP, ActionPlaces.PROJECT_VIEW_POPUP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ActionCallback updateFromRoot(boolean restoreExpandedPaths) {
|
||||
final ArrayList<Object> pathsToExpand = new ArrayList<Object>();
|
||||
final ArrayList<Object> selectionPaths = new ArrayList<Object>();
|
||||
@@ -155,6 +164,7 @@ public abstract class AbstractProjectViewPSIPane extends AbstractProjectViewPane
|
||||
if (restoreExpandedPaths) {
|
||||
TreeBuilderUtil.storePaths(getTreeBuilder(), (DefaultMutableTreeNode)myTree.getModel().getRoot(), pathsToExpand, selectionPaths, true);
|
||||
afterUpdate = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (myTree != null && getTreeBuilder() != null && !getTreeBuilder().isDisposed()) {
|
||||
myTree.setSelectionPaths(new TreePath[0]);
|
||||
@@ -166,6 +176,7 @@ public abstract class AbstractProjectViewPSIPane extends AbstractProjectViewPane
|
||||
}
|
||||
else {
|
||||
afterUpdate = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cb.setDone();
|
||||
}
|
||||
@@ -178,6 +189,7 @@ public abstract class AbstractProjectViewPSIPane extends AbstractProjectViewPane
|
||||
return cb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void select(Object element, VirtualFile file, boolean requestFocus) {
|
||||
selectCB(element, file, requestFocus);
|
||||
}
|
||||
@@ -192,6 +204,7 @@ public abstract class AbstractProjectViewPSIPane extends AbstractProjectViewPane
|
||||
@NotNull
|
||||
protected BaseProjectTreeBuilder createBuilder(DefaultTreeModel treeModel) {
|
||||
return new ProjectTreeBuilder(myProject, myTree, treeModel, null, (ProjectAbstractTreeStructureBase)myTreeStructure) {
|
||||
@Override
|
||||
protected AbstractTreeUpdater createUpdater() {
|
||||
return createTreeUpdater(this);
|
||||
}
|
||||
@@ -210,6 +223,7 @@ public abstract class AbstractProjectViewPSIPane extends AbstractProjectViewPane
|
||||
super(tree);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isMatchingElement(Object element, String pattern) {
|
||||
Object userObject = ((DefaultMutableTreeNode)((TreePath)element).getLastPathComponent()).getUserObject();
|
||||
if (userObject instanceof PsiDirectoryNode) {
|
||||
|
||||
@@ -184,6 +184,7 @@ public abstract class AbstractProjectViewPane implements DataProvider, Disposabl
|
||||
TreeUtil.selectPath(myTree, treePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (myDndManager != null) {
|
||||
if (myDropTarget != null) {
|
||||
@@ -211,12 +212,14 @@ public abstract class AbstractProjectViewPane implements DataProvider, Disposabl
|
||||
private void doSelectModuleOrGroup(final Object toSelect, final boolean requestFocus) {
|
||||
ToolWindowManager windowManager=ToolWindowManager.getInstance(myProject);
|
||||
final Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ProjectView projectView = ProjectView.getInstance(myProject);
|
||||
if (requestFocus) {
|
||||
projectView.changeView(getId(), getSubId());
|
||||
}
|
||||
((BaseProjectTreeBuilder)getTreeBuilder()).selectInWidth(toSelect, requestFocus, new Condition<AbstractTreeNode>(){
|
||||
@Override
|
||||
public boolean value(final AbstractTreeNode node) {
|
||||
return node instanceof AbstractModuleNode || node instanceof ModuleGroupNode || node instanceof AbstractProjectNode;
|
||||
}
|
||||
@@ -260,6 +263,7 @@ public abstract class AbstractProjectViewPane implements DataProvider, Disposabl
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getData(String dataId) {
|
||||
if (PlatformDataKeys.NAVIGATABLE_ARRAY.is(dataId)) {
|
||||
TreePath[] paths = getSelectionPaths();
|
||||
|
||||
@@ -45,6 +45,7 @@ public class DirectoryUrl extends AbstractUrl {
|
||||
return new DirectoryUrl(virtualFile.getUrl(), module != null ? module.getName() : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] createPath(final Project project) {
|
||||
if (moduleName != null) {
|
||||
final Module module = ApplicationManager.getApplication().runReadAction(new Computable<Module>() {
|
||||
@@ -70,10 +71,12 @@ public class DirectoryUrl extends AbstractUrl {
|
||||
return new Object[]{directory};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractUrl createUrl(String moduleName, String url) {
|
||||
return new DirectoryUrl(url, moduleName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractUrl createUrlByElement(Object element) {
|
||||
if (element instanceof PsiDirectory) {
|
||||
return create((PsiDirectory)element);
|
||||
|
||||
+1
@@ -29,6 +29,7 @@ import com.intellij.ui.content.ContentManager;
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class FavoritesViewToolWindowFactory implements ToolWindowFactory, DumbAware {
|
||||
@Override
|
||||
public void createToolWindowContent(Project project, ToolWindow toolWindow) {
|
||||
if (toolWindow != null) {
|
||||
final ContentManager contentManager = toolWindow.getContentManager();
|
||||
|
||||
@@ -42,6 +42,7 @@ public class GroupByTypeComparator implements Comparator<NodeDescriptor> {
|
||||
myForceSortByType = forceSortByType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(NodeDescriptor descriptor1, NodeDescriptor descriptor2) {
|
||||
if (!isSortByType() && descriptor1 instanceof ProjectViewNode && ((ProjectViewNode) descriptor1).isSortByFirstChild()) {
|
||||
final Collection<AbstractTreeNode> children = ((ProjectViewNode)descriptor1).getChildren();
|
||||
|
||||
@@ -31,16 +31,19 @@ public class LibraryModuleGroupUrl extends AbstractUrl {
|
||||
super(null, moduleName, ELEMENT_TYPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] createPath(Project project) {
|
||||
final Module module = moduleName != null ? ModuleManager.getInstance(project).findModuleByName(moduleName) : null;
|
||||
if (module == null) return null;
|
||||
return new Object[]{new LibraryGroupElement(module)};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractUrl createUrl(String moduleName, String url) {
|
||||
return new LibraryModuleGroupUrl(moduleName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractUrl createUrlByElement(Object element) {
|
||||
if (element instanceof LibraryGroupElement) {
|
||||
LibraryGroupElement libraryGroupElement = (LibraryGroupElement)element;
|
||||
|
||||
@@ -27,15 +27,18 @@ public class ModuleGroupUrl extends AbstractUrl {
|
||||
super(url, null, ELEMENT_TYPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] createPath(Project project) {
|
||||
final String[] groupPath = url.split(";");
|
||||
return new Object[]{new ModuleGroup(groupPath)};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractUrl createUrl(String moduleName, String url) {
|
||||
return new ModuleGroupUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractUrl createUrlByElement(Object element) {
|
||||
if (element instanceof ModuleGroup) {
|
||||
ModuleGroup group = (ModuleGroup)element;
|
||||
|
||||
@@ -31,16 +31,19 @@ public class ModuleUrl extends AbstractUrl {
|
||||
super(url, moduleName,ELEMENT_TYPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] createPath(Project project) {
|
||||
final Module module = moduleName != null ? ModuleManager.getInstance(project).findModuleByName(moduleName) : null;
|
||||
if (module == null) return null;
|
||||
return new Object[]{module};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractUrl createUrl(String moduleName, String url) {
|
||||
return new ModuleUrl(url, moduleName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractUrl createUrlByElement(Object element) {
|
||||
if (element instanceof Module) {
|
||||
Module module = (Module)element;
|
||||
|
||||
@@ -41,6 +41,7 @@ public class MoveModuleToGroup extends ActionGroup {
|
||||
setPopup(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e){
|
||||
final DataContext dataContext = e.getDataContext();
|
||||
final Project project = PlatformDataKeys.PROJECT.getData(dataContext);
|
||||
@@ -51,12 +52,14 @@ public class MoveModuleToGroup extends ActionGroup {
|
||||
presentation.setText(myModuleGroup.presentableText());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public AnAction[] getChildren(@Nullable AnActionEvent e) {
|
||||
if (e == null) return EMPTY_ARRAY;
|
||||
|
||||
List<ModuleGroup> children = new ArrayList<ModuleGroup>(myModuleGroup.childGroups(e.getDataContext()));
|
||||
Collections.sort ( children, new Comparator<ModuleGroup>() {
|
||||
@Override
|
||||
public int compare(final ModuleGroup moduleGroup1, final ModuleGroup moduleGroup2) {
|
||||
assert moduleGroup1.getGroupPath().length == moduleGroup2.getGroupPath().length;
|
||||
return moduleGroup1.toString().compareToIgnoreCase(moduleGroup2.toString());
|
||||
|
||||
+2
@@ -32,6 +32,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.*;
|
||||
|
||||
public class MoveModuleToGroupTopLevel extends ActionGroup {
|
||||
@Override
|
||||
public void update(AnActionEvent e){
|
||||
final DataContext dataContext = e.getDataContext();
|
||||
final Project project = PlatformDataKeys.PROJECT.getData(dataContext);
|
||||
@@ -40,6 +41,7 @@ public class MoveModuleToGroupTopLevel extends ActionGroup {
|
||||
e.getPresentation().setVisible(active);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public AnAction[] getChildren(@Nullable AnActionEvent e) {
|
||||
if (e == null) {
|
||||
|
||||
@@ -34,6 +34,7 @@ public class NamedLibraryUrl extends AbstractUrl {
|
||||
super(url, moduleName, ELEMENT_TYPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] createPath(Project project) {
|
||||
final Module module = moduleName != null ? ModuleManager.getInstance(project).findModuleByName(moduleName) : null;
|
||||
if (module == null) return null;
|
||||
@@ -45,10 +46,12 @@ public class NamedLibraryUrl extends AbstractUrl {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractUrl createUrl(String moduleName, String url) {
|
||||
return new NamedLibraryUrl(url, moduleName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractUrl createUrlByElement(Object element) {
|
||||
if (element instanceof NamedLibraryElement) {
|
||||
NamedLibraryElement libraryElement = (NamedLibraryElement)element;
|
||||
|
||||
+1
@@ -31,6 +31,7 @@ public abstract class ProjectAbstractTreeStructureBase extends AbstractTreeStruc
|
||||
super(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TreeStructureProvider> getProviders() {
|
||||
if (myProviders == null) {
|
||||
final TreeStructureProvider[] providers = Extensions.getExtensions(TreeStructureProvider.EP_NAME, myProject);
|
||||
|
||||
@@ -31,26 +31,32 @@ public abstract class ProjectTreeStructure extends AbstractProjectTreeStructure
|
||||
myId = ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFlattenPackages() {
|
||||
return ProjectView.getInstance(myProject).isFlattenPackages(myId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShowMembers() {
|
||||
return ProjectView.getInstance(myProject).isShowMembers(myId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHideEmptyMiddlePackages() {
|
||||
return ProjectView.getInstance(myProject).isHideEmptyMiddlePackages(myId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbbreviatePackageNames() {
|
||||
return ProjectView.getInstance(myProject).isAbbreviatePackageNames(myId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShowLibraryContents() {
|
||||
return ProjectView.getInstance(myProject).isShowLibraryContents(myId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShowModules() {
|
||||
return ProjectView.getInstance(myProject).isShowModules(myId);
|
||||
}
|
||||
|
||||
@@ -232,10 +232,12 @@ class ProjectViewDropTarget implements DnDNativeTarget {
|
||||
}
|
||||
|
||||
public abstract class MoveCopyDropHandler implements DropHandler {
|
||||
@Override
|
||||
public boolean isValidSource(@NotNull final TreeNode[] sourceNodes, TreeNode targetNode) {
|
||||
return canDrop(sourceNodes, targetNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidTarget(@NotNull final TreeNode[] sourceNodes, final @NotNull TreeNode targetNode) {
|
||||
return canDrop(sourceNodes, targetNode);
|
||||
}
|
||||
@@ -279,6 +281,7 @@ class ProjectViewDropTarget implements DnDNativeTarget {
|
||||
}
|
||||
|
||||
private class MoveDropHandler extends MoveCopyDropHandler {
|
||||
@Override
|
||||
protected boolean canDrop(@NotNull final TreeNode[] sourceNodes, @Nullable final TreeNode targetNode) {
|
||||
if (targetNode instanceof DefaultMutableTreeNode) {
|
||||
final Object userObject = ((DefaultMutableTreeNode)targetNode).getUserObject();
|
||||
@@ -293,6 +296,7 @@ class ProjectViewDropTarget implements DnDNativeTarget {
|
||||
MoveHandler.canMove(sourceElements, targetElement));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doDrop(@NotNull final TreeNode[] sourceNodes, @NotNull final TreeNode targetNode) {
|
||||
if (targetNode instanceof DefaultMutableTreeNode) {
|
||||
final Object userObject = ((DefaultMutableTreeNode)targetNode).getUserObject();
|
||||
@@ -311,6 +315,7 @@ class ProjectViewDropTarget implements DnDNativeTarget {
|
||||
final Module module = getModule(targetNode);
|
||||
final DataContext dataContext = DataManager.getInstance().getDataContext(myTree);
|
||||
getActionHandler().invoke(myProject, sourceElements, new DataContext() {
|
||||
@Override
|
||||
@Nullable
|
||||
public Object getData(@NonNls String dataId) {
|
||||
if (LangDataKeys.TARGET_MODULE.is(dataId)) {
|
||||
@@ -330,15 +335,18 @@ class ProjectViewDropTarget implements DnDNativeTarget {
|
||||
return RefactoringActionHandlerFactory.getInstance().createMoveHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDropRedundant(@NotNull TreeNode sourceNode, @NotNull TreeNode targetNode) {
|
||||
return sourceNode.getParent() == targetNode || MoveHandler.isMoveRedundant(getPsiElement(sourceNode), getPsiElement(targetNode));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldDelegateToParent(TreeNode[] sourceNodes, @NotNull final TreeNode targetNode) {
|
||||
final PsiElement psiElement = getPsiElement(targetNode);
|
||||
return !MoveHandler.isValidTarget(psiElement, getPsiElements(sourceNodes));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doDropFiles(List<File> fileList, TreeNode targetNode) {
|
||||
final PsiFileSystemItem[] sourceFileArray = getPsiFiles(fileList);
|
||||
|
||||
@@ -355,6 +363,7 @@ class ProjectViewDropTarget implements DnDNativeTarget {
|
||||
}
|
||||
|
||||
private class CopyDropHandler extends MoveCopyDropHandler {
|
||||
@Override
|
||||
protected boolean canDrop(@NotNull final TreeNode[] sourceNodes, @Nullable final TreeNode targetNode) {
|
||||
final PsiElement[] sourceElements = getPsiElements(sourceNodes);
|
||||
final PsiElement targetElement = getPsiElement(targetNode);
|
||||
@@ -365,6 +374,7 @@ class ProjectViewDropTarget implements DnDNativeTarget {
|
||||
return isTargetAcceptable && CopyHandler.canCopy(sourceElements);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doDrop(@NotNull final TreeNode[] sourceNodes, @NotNull final TreeNode targetNode) {
|
||||
final PsiElement[] sourceElements = getPsiElements(sourceNodes);
|
||||
doDrop(targetNode, sourceElements);
|
||||
@@ -389,15 +399,18 @@ class ProjectViewDropTarget implements DnDNativeTarget {
|
||||
CopyHandler.doCopy(sourceElements, psiDirectory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDropRedundant(@NotNull TreeNode sourceNode, @NotNull TreeNode targetNode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldDelegateToParent(TreeNode[] sourceNodes, @NotNull final TreeNode targetNode) {
|
||||
final PsiElement psiElement = getPsiElement(targetNode);
|
||||
return psiElement == null || (!(psiElement instanceof PsiDirectoryContainer) && !(psiElement instanceof PsiDirectory));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doDropFiles(List<File> fileList, TreeNode targetNode) {
|
||||
final PsiFileSystemItem[] sourceFileArray = getPsiFiles(fileList);
|
||||
doDrop(targetNode, sourceFileArray);
|
||||
|
||||
@@ -178,6 +178,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
private static final String ATTRIBUTE_ID = "id";
|
||||
private JPanel myViewContentPanel;
|
||||
private static final Comparator<AbstractProjectViewPane> PANE_WEIGHT_COMPARATOR = new Comparator<AbstractProjectViewPane>() {
|
||||
@Override
|
||||
public int compare(final AbstractProjectViewPane o1, final AbstractProjectViewPane o2) {
|
||||
return o1.getWeight() - o2.getWeight();
|
||||
}
|
||||
@@ -201,6 +202,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
|
||||
myConnection = project.getMessageBus().connect();
|
||||
myConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() {
|
||||
@Override
|
||||
public void rootsChanged(ModuleRootEvent event) {
|
||||
refresh();
|
||||
}
|
||||
@@ -211,6 +213,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
myDataProvider = new MyPanel();
|
||||
myDataProvider.add(myPanel, BorderLayout.CENTER);
|
||||
myCopyPasteDelegator = new CopyPasteDelegator(myProject, myPanel) {
|
||||
@Override
|
||||
@NotNull
|
||||
protected PsiElement[] getSelectedElements() {
|
||||
final AbstractProjectViewPane viewPane = getCurrentProjectViewPane();
|
||||
@@ -218,10 +221,12 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
}
|
||||
};
|
||||
myAutoScrollToSourceHandler = new AutoScrollToSourceHandler() {
|
||||
@Override
|
||||
protected boolean isAutoScrollMode() {
|
||||
return isAutoscrollToSource(myCurrentViewId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAutoScrollMode(boolean state) {
|
||||
setAutoscrollToSource(state, myCurrentViewId);
|
||||
}
|
||||
@@ -229,6 +234,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
toolWindowManager.addToolWindowManagerListener(new ToolWindowManagerAdapter(){
|
||||
private boolean toolWindowVisible;
|
||||
|
||||
@Override
|
||||
public void stateChanged() {
|
||||
ToolWindow window = toolWindowManager.getToolWindow(ToolWindowId.PROJECT_VIEW);
|
||||
if (window == null) return;
|
||||
@@ -252,10 +258,12 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
myPanel.setContent(myViewContentPanel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Project";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AnAction> getActions(boolean originalProvider) {
|
||||
ArrayList<AnAction> result = new ArrayList<AnAction>();
|
||||
|
||||
@@ -330,10 +338,12 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCycleRoot() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void addProjectPane(final AbstractProjectViewPane pane) {
|
||||
myUninitializedPanes.add(pane);
|
||||
SelectInTarget selectInTarget = pane.createSelectInTarget();
|
||||
@@ -345,6 +355,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void removeProjectPane(AbstractProjectViewPane pane) {
|
||||
myUninitializedPanes.remove(pane);
|
||||
//assume we are completely initialized here
|
||||
@@ -423,6 +434,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
content.setIcon(newPane.getIcon());
|
||||
content.setPopupIcon(subId != null ? AllIcons.General.Bullet : newPane.getIcon());
|
||||
content.setPreferredFocusedComponent(new Computable<JComponent>() {
|
||||
@Override
|
||||
public JComponent compute() {
|
||||
final AbstractProjectViewPane current = getCurrentProjectViewPane();
|
||||
return current != null ? current.getComponentToFocus() : null;
|
||||
@@ -470,20 +482,24 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
if (selectedPsiElement != null) {
|
||||
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(selectedPsiElement);
|
||||
if (virtualFile != null && ((ProjectViewSelectInTarget)newPane.createSelectInTarget()).isSubIdSelectable(newSubId, new SelectInContext() {
|
||||
@Override
|
||||
@NotNull
|
||||
public Project getProject() {
|
||||
return myProject;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public VirtualFile getVirtualFile() {
|
||||
return virtualFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getSelectorInFile() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileEditorProvider getFileEditorProvider() {
|
||||
return null;
|
||||
}
|
||||
@@ -539,6 +555,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
|
||||
GuiUtils.replaceJSplitPaneWithIDEASplitter(myPanel);
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
splitterProportions.restoreSplitterProportions(myPanel);
|
||||
}
|
||||
@@ -602,6 +619,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
myActionGroup.addAction(new PaneOptionAction(myFlattenPackages, IdeBundle.message("action.flatten.packages"),
|
||||
IdeBundle.message("action.flatten.packages"), PlatformIcons.FLATTEN_PACKAGES_ICON,
|
||||
ourFlattenPackagesDefaults) {
|
||||
@Override
|
||||
public void setSelected(AnActionEvent event, boolean flag) {
|
||||
final AbstractProjectViewPane viewPane = getCurrentProjectViewPane();
|
||||
final SelectionInfo selectionInfo = SelectionInfo.create(viewPane);
|
||||
@@ -622,6 +640,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
super(optionsMap, text, description, icon, optionDefaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
super.update(e);
|
||||
final Presentation presentation = e.getPresentation();
|
||||
@@ -637,11 +656,13 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
IdeBundle.message("action.abbreviate.qualified.package.names"),
|
||||
AllIcons.ObjectBrowser.AbbreviatePackageNames,
|
||||
ourAbbreviatePackagesDefaults) {
|
||||
@Override
|
||||
public boolean isSelected(AnActionEvent event) {
|
||||
return super.isSelected(event) && isAbbreviatePackageNames(myCurrentViewId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
super.update(e);
|
||||
if (ScopeViewPane.ID.equals(myCurrentViewId)) {
|
||||
@@ -665,14 +686,17 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
myActionGroup.addAction(new ScrollFromSourceAction());
|
||||
}
|
||||
AnAction collapseAllAction = CommonActionsManager.getInstance().createCollapseAllAction(new TreeExpander() {
|
||||
@Override
|
||||
public void expandAll() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExpand() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collapseAll() {
|
||||
AbstractProjectViewPane pane = getCurrentProjectViewPane();
|
||||
JTree tree = pane.myTree;
|
||||
@@ -681,6 +705,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCollapse() {
|
||||
return true;
|
||||
}
|
||||
@@ -689,6 +714,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
getCurrentProjectViewPane().addToolbarActions(myActionGroup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractProjectViewPane getProjectViewPaneById(String id) {
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode()) { // most tests don't need all panes to be loaded
|
||||
ensurePanesLoaded();
|
||||
@@ -706,10 +732,12 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractProjectViewPane getCurrentProjectViewPane() {
|
||||
return getProjectViewPaneById(myCurrentViewId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
AbstractProjectViewPane currentProjectViewPane = getCurrentProjectViewPane();
|
||||
if (currentProjectViewPane != null) {
|
||||
@@ -718,6 +746,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void select(final Object element, VirtualFile file, boolean requestFocus) {
|
||||
final AbstractProjectViewPane viewPane = getCurrentProjectViewPane();
|
||||
if (viewPane != null) {
|
||||
@@ -725,6 +754,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionCallback selectCB(Object element, VirtualFile file, boolean requestFocus) {
|
||||
final AbstractProjectViewPane viewPane = getCurrentProjectViewPane();
|
||||
if (viewPane != null && viewPane instanceof AbstractProjectViewPSIPane) {
|
||||
@@ -735,18 +765,22 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
myConnection.disconnect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent getComponent() {
|
||||
return myDataProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentViewId() {
|
||||
return myCurrentViewId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement getParentOfCurrentSelection() {
|
||||
final AbstractProjectViewPane viewPane = getCurrentProjectViewPane();
|
||||
if (viewPane == null) {
|
||||
@@ -792,15 +826,18 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
myOptionDefaultValue = optionDefaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected(AnActionEvent event) {
|
||||
return getPaneOptionValue(myOptionsMap, myCurrentViewId, myOptionDefaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent event, boolean flag) {
|
||||
setPaneOption(myOptionsMap, flag, myCurrentViewId, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeView() {
|
||||
final List<AbstractProjectViewPane> views = new ArrayList<AbstractProjectViewPane>(myId2Pane.values());
|
||||
views.remove(getCurrentProjectViewPane());
|
||||
@@ -808,6 +845,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
|
||||
final JList list = new JBList(ArrayUtil.toObjectArray(views));
|
||||
list.setCellRenderer(new DefaultListCellRenderer() {
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
AbstractProjectViewPane pane = (AbstractProjectViewPane)value;
|
||||
@@ -820,6 +858,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
list.setSelectedValue(views.get(0), true);
|
||||
}
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (list.getSelectedIndex() < 0) return;
|
||||
AbstractProjectViewPane pane = (AbstractProjectViewPane)list.getSelectedValue();
|
||||
@@ -833,10 +872,12 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
createPopup().showInCenterOf(getComponent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeView(@NotNull String viewId) {
|
||||
changeView(viewId, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeView(@NotNull String viewId, @Nullable String subId) {
|
||||
AbstractProjectViewPane pane = getProjectViewPaneById(viewId);
|
||||
LOG.assertTrue(pane != null, "Project view pane not found: " + viewId + "; subId:" + subId);
|
||||
@@ -853,11 +894,13 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
}
|
||||
|
||||
private final class MyDeletePSIElementProvider implements DeleteProvider {
|
||||
@Override
|
||||
public boolean canDeleteElement(@NotNull DataContext dataContext) {
|
||||
final PsiElement[] elements = getElementsToDelete();
|
||||
return DeleteHandler.shouldEnableDeleteAction(elements);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteElement(@NotNull DataContext dataContext) {
|
||||
List<PsiElement> allElements = Arrays.asList(getElementsToDelete());
|
||||
List<PsiElement> validElements = new ArrayList<PsiElement>();
|
||||
@@ -942,6 +985,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
return ((NodeDescriptor)userObject).getElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getData(String dataId) {
|
||||
final AbstractProjectViewPane currentProjectViewPane = getCurrentProjectViewPane();
|
||||
if (currentProjectViewPane != null) {
|
||||
@@ -1005,10 +1049,12 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
final LibraryOrderEntry orderEntry = getSelectedLibrary();
|
||||
if (orderEntry != null) {
|
||||
return new DeleteProvider() {
|
||||
@Override
|
||||
public void deleteElement(@NotNull DataContext dataContext) {
|
||||
detachLibrary(orderEntry, myProject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDeleteElement(@NotNull DataContext dataContext) {
|
||||
return true;
|
||||
}
|
||||
@@ -1102,8 +1148,10 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
int ret = Messages.showOkCancelDialog(project, message, title, Messages.getQuestionIcon());
|
||||
if (ret != 0) return;
|
||||
CommandProcessor.getInstance().executeCommand(module.getProject(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Runnable action = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
OrderEntry[] orderEntries = rootManager.getOrderEntries();
|
||||
@@ -1186,6 +1234,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
}
|
||||
|
||||
private final class MyIdeView implements IdeView {
|
||||
@Override
|
||||
public void selectElement(PsiElement element) {
|
||||
selectPsiElement(element, false);
|
||||
boolean requestFocus = true;
|
||||
@@ -1205,6 +1254,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiDirectory[] getDirectories() {
|
||||
final AbstractProjectViewPane viewPane = getCurrentProjectViewPane();
|
||||
if (viewPane != null) {
|
||||
@@ -1214,11 +1264,13 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
return PsiDirectory.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiDirectory getOrChooseDirectory() {
|
||||
return DirectoryChooserUtil.getOrChooseDirectory(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectPsiElement(PsiElement element, boolean requestFocus) {
|
||||
if (element == null) return;
|
||||
VirtualFile virtualFile = PsiUtilBase.getVirtualFile(element);
|
||||
@@ -1247,6 +1299,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
parentNode.addContent(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(Element parentNode) {
|
||||
Element navigatorElement = parentNode.getChild(ELEMENT_NAVIGATOR);
|
||||
if (navigatorElement != null) {
|
||||
@@ -1300,6 +1353,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element getState() {
|
||||
Element parentNode = new Element("projectView");
|
||||
Element navigatorElement = new Element(ELEMENT_NAVIGATOR);
|
||||
@@ -1357,6 +1411,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutoscrollToSource(String paneId) {
|
||||
return getPaneOptionValue(myAutoscrollToSource, paneId, ourAutoscrollToSourceDefaults);
|
||||
}
|
||||
@@ -1365,6 +1420,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
myAutoscrollToSource.put(paneId, autoscrollMode ? Boolean.TRUE : Boolean.FALSE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutoscrollFromSource(String paneId) {
|
||||
return getPaneOptionValue(myAutoscrollFromSource, paneId, ourAutoscrollFromSourceDefaults);
|
||||
}
|
||||
@@ -1373,6 +1429,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
setPaneOption(myAutoscrollFromSource, autoscrollMode, paneId, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFlattenPackages(String paneId) {
|
||||
return getPaneOptionValue(myFlattenPackages, paneId, ourFlattenPackagesDefaults);
|
||||
}
|
||||
@@ -1381,6 +1438,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
setPaneOption(myFlattenPackages, flattenPackages, paneId, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShowMembers(String paneId) {
|
||||
return getPaneOptionValue(myShowMembers, paneId, ourShowMembersDefaults);
|
||||
}
|
||||
@@ -1389,18 +1447,22 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
setPaneOption(myShowMembers, showMembers, paneId, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHideEmptyMiddlePackages(String paneId) {
|
||||
return getPaneOptionValue(myHideEmptyPackages, paneId, ourHideEmptyPackagesDefaults);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbbreviatePackageNames(String paneId) {
|
||||
return getPaneOptionValue(myAbbreviatePackageNames, paneId, ourAbbreviatePackagesDefaults);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShowLibraryContents(String paneId) {
|
||||
return getPaneOptionValue(myShowLibraryContents, paneId, ourShowLibraryContentsDefaults);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShowLibraryContents(boolean showLibraryContents, String paneId) {
|
||||
setPaneOption(myShowLibraryContents, showLibraryContents, paneId, true);
|
||||
}
|
||||
@@ -1409,18 +1471,22 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
return setPaneOption(myShowLibraryContents, showLibraryContents, paneId, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShowModules(String paneId) {
|
||||
return getPaneOptionValue(myShowModules, paneId, ourShowModulesDefaults);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShowModules(boolean showModules, String paneId) {
|
||||
setPaneOption(myShowModules, showModules, paneId, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHideEmptyPackages(boolean hideEmptyPackages, String paneId) {
|
||||
setPaneOption(myHideEmptyPackages, hideEmptyPackages, paneId, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAbbreviatePackageNames(boolean abbreviatePackageNames, String paneId) {
|
||||
setPaneOption(myAbbreviatePackageNames, abbreviatePackageNames, paneId, true);
|
||||
}
|
||||
@@ -1446,6 +1512,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
super(myHideEmptyPackages, "", "", null, ourHideEmptyPackagesDefaults);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent event, boolean flag) {
|
||||
final AbstractProjectViewPane viewPane = getCurrentProjectViewPane();
|
||||
final SelectionInfo selectionInfo = SelectionInfo.create(viewPane);
|
||||
@@ -1455,6 +1522,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
selectionInfo.apply(viewPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
super.update(e);
|
||||
final Presentation presentation = e.getPresentation();
|
||||
@@ -1599,10 +1667,12 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAutoScrollEnabled() {
|
||||
return isAutoscrollFromSource(myCurrentViewId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAutoScrollEnabled(boolean state) {
|
||||
setAutoscrollFromSource(state, myCurrentViewId);
|
||||
if (state) {
|
||||
@@ -1624,6 +1694,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
myEditor = editor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Project getProject() {
|
||||
return myProject;
|
||||
@@ -1633,9 +1704,11 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
return myPsiFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileEditorProvider getFileEditorProvider() {
|
||||
if (myPsiFile == null) return null;
|
||||
return new FileEditorProvider() {
|
||||
@Override
|
||||
public FileEditor openFileEditor() {
|
||||
return myFileEditorManager.openFile(myPsiFile.getContainingFile().getVirtualFile(), false)[0];
|
||||
}
|
||||
@@ -1655,21 +1728,25 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
return e;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public VirtualFile getVirtualFile() {
|
||||
return getPsiFile().getVirtualFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getSelectorInFile() {
|
||||
return getPsiElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSortByType(String paneId) {
|
||||
return getPaneOptionValue(mySortByType, paneId, ourSortByTypeDefaults);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSortByType(String paneId, final boolean sortByType) {
|
||||
setPaneOption(mySortByType, sortByType, paneId, false);
|
||||
final AbstractProjectViewPane pane = getProjectViewPaneById(paneId);
|
||||
@@ -1682,14 +1759,17 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
AllIcons.ObjectBrowser.SortByType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected(AnActionEvent event) {
|
||||
return isSortByType(getCurrentViewId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent event, boolean flag) {
|
||||
setSortByType(getCurrentViewId(), flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(final AnActionEvent e) {
|
||||
super.update(e);
|
||||
final Presentation presentation = e.getPresentation();
|
||||
@@ -1709,6 +1789,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getPaneIds() {
|
||||
return myId2Pane.keySet();
|
||||
}
|
||||
|
||||
@@ -45,42 +45,51 @@ public class ProjectViewPane extends AbstractProjectViewPSIPane {
|
||||
super(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return IdeBundle.message("title.project");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return AllIcons.General.ProjectTab;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SelectInTarget createSelectInTarget() {
|
||||
return new ProjectPaneSelectInTarget(myProject);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractTreeUpdater createTreeUpdater(AbstractTreeBuilder treeBuilder) {
|
||||
return new ProjectViewTreeUpdater(treeBuilder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ProjectAbstractTreeStructureBase createStructure() {
|
||||
return new ProjectTreeStructure(myProject, ID){
|
||||
@Override
|
||||
protected AbstractTreeNode createRoot(final Project project, ViewSettings settings) {
|
||||
return new ProjectViewProjectNode(project, settings);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ProjectViewTree createTree(DefaultTreeModel treeModel) {
|
||||
return new ProjectViewTree(myProject, treeModel) {
|
||||
public String toString() {
|
||||
return getTitle() + " " + super.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultMutableTreeNode getSelectedNode() {
|
||||
return ProjectViewPane.this.getSelectedNode();
|
||||
}
|
||||
@@ -94,6 +103,7 @@ public class ProjectViewPane extends AbstractProjectViewPSIPane {
|
||||
|
||||
|
||||
// should be first
|
||||
@Override
|
||||
public int getWeight() {
|
||||
return 0;
|
||||
}
|
||||
@@ -103,6 +113,7 @@ public class ProjectViewPane extends AbstractProjectViewPSIPane {
|
||||
super(treeBuilder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addSubtreeToUpdateByElement(Object element) {
|
||||
if (element instanceof PsiDirectory) {
|
||||
final PsiDirectory dir = (PsiDirectory)element;
|
||||
|
||||
+1
@@ -28,6 +28,7 @@ import com.intellij.openapi.wm.ToolWindowFactoryEx;
|
||||
* @author yole
|
||||
*/
|
||||
public class ProjectViewToolWindowFactory implements ToolWindowFactoryEx, DumbAware {
|
||||
@Override
|
||||
public void createToolWindowContent(Project project, ToolWindow toolWindow) {
|
||||
((ProjectViewImpl) ProjectView.getInstance(project)).setupImpl(toolWindow);
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ public abstract class ProjectViewTree extends JBTreeWithHintProvider {
|
||||
return myProject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getToggleClickCount() {
|
||||
final DefaultMutableTreeNode selectedNode = getSelectedNode();
|
||||
if (selectedNode != null) {
|
||||
|
||||
@@ -36,6 +36,7 @@ public class PsiFileUrl extends AbstractUrl {
|
||||
super(url, null, ELEMENT_TYPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] createPath(final Project project) {
|
||||
final VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url);
|
||||
if (file == null || !file.isValid()){
|
||||
@@ -44,10 +45,12 @@ public class PsiFileUrl extends AbstractUrl {
|
||||
return new Object[]{PsiManager.getInstance(project).findFile(file)};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractUrl createUrl(String moduleName, String url) {
|
||||
return new PsiFileUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractUrl createUrlByElement(Object element) {
|
||||
if (element instanceof PsiFile) {
|
||||
VirtualFile file = ((PsiFile)element).getVirtualFile();
|
||||
|
||||
@@ -50,19 +50,23 @@ import org.jetbrains.annotations.Nullable;
|
||||
public class RenameModuleHandler implements RenameHandler, TitledHandler {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.ide.projectView.actions.RenameModuleHandler");
|
||||
|
||||
@Override
|
||||
public boolean isAvailableOnDataContext(DataContext dataContext) {
|
||||
Module module = LangDataKeys.MODULE_CONTEXT.getData(dataContext);
|
||||
return module != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRenaming(DataContext dataContext) {
|
||||
return isAvailableOnDataContext(dataContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
|
||||
LOG.assertTrue(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull final Project project, @NotNull PsiElement[] elements, @NotNull DataContext dataContext) {
|
||||
final Module module = LangDataKeys.MODULE_CONTEXT.getData(dataContext);
|
||||
LOG.assertTrue(module != null);
|
||||
@@ -74,6 +78,7 @@ public class RenameModuleHandler implements RenameHandler, TitledHandler {
|
||||
new MyInputValidator(project, module));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActionTitle() {
|
||||
return RefactoringBundle.message("rename.module.title");
|
||||
}
|
||||
@@ -86,18 +91,22 @@ public class RenameModuleHandler implements RenameHandler, TitledHandler {
|
||||
myModule = module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkInput(String inputString) {
|
||||
return inputString != null && inputString.length() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canClose(final String inputString) {
|
||||
final String oldName = myModule.getName();
|
||||
final ModifiableModuleModel modifiableModel = renameModule(inputString);
|
||||
if (modifiableModel == null) return false;
|
||||
final Ref<Boolean> success = Ref.create(Boolean.TRUE);
|
||||
CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UndoableAction action = new BasicUndoableAction() {
|
||||
@Override
|
||||
public void undo() throws UnexpectedUndoException {
|
||||
final ModifiableModuleModel modifiableModel = renameModule(oldName);
|
||||
if (modifiableModel != null) {
|
||||
@@ -115,6 +124,7 @@ public class RenameModuleHandler implements RenameHandler, TitledHandler {
|
||||
};
|
||||
UndoManager.getInstance(myProject).undoableActionPerformed(action);
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
modifiableModel.commit();
|
||||
}
|
||||
|
||||
@@ -26,17 +26,20 @@ public abstract class ShowModulesAction extends ToggleAction {
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected(AnActionEvent event) {
|
||||
return ProjectView.getInstance(myProject).isShowModules(getId());
|
||||
}
|
||||
|
||||
protected abstract String getId();
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent event, boolean flag) {
|
||||
final ProjectViewImpl projectView = (ProjectViewImpl)ProjectView.getInstance(myProject);
|
||||
projectView.setShowModules(flag, getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
super.update(e);
|
||||
final Presentation presentation = e.getPresentation();
|
||||
|
||||
@@ -38,6 +38,7 @@ public abstract class AbstractModuleNode extends ProjectViewNode<Module> impleme
|
||||
super(project, module, viewSettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(PresentationData presentation) {
|
||||
if (getValue().isDisposed()) {
|
||||
setValue(null);
|
||||
@@ -56,6 +57,7 @@ public abstract class AbstractModuleNode extends ProjectViewNode<Module> impleme
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getTestPresentation() {
|
||||
return "Module";
|
||||
}
|
||||
@@ -84,11 +86,13 @@ public abstract class AbstractModuleNode extends ProjectViewNode<Module> impleme
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToolTip() {
|
||||
final Module module = getValue();
|
||||
return ModuleType.get(module).getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void navigate(final boolean requestFocus) {
|
||||
ProjectSettingsService.getInstance(myProject).openModuleSettings(getValue());
|
||||
}
|
||||
@@ -98,6 +102,7 @@ public abstract class AbstractModuleNode extends ProjectViewNode<Module> impleme
|
||||
return "Open Module Settings";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canNavigate() {
|
||||
return ProjectSettingsService.getInstance(myProject).canOpenModuleSettings();
|
||||
}
|
||||
|
||||
+3
@@ -77,15 +77,18 @@ public abstract class AbstractProjectNode extends ProjectViewNode<Project> {
|
||||
protected abstract AbstractTreeNode createModuleGroupNode(final ModuleGroup moduleGroup)
|
||||
throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException;
|
||||
|
||||
@Override
|
||||
public void update(PresentationData presentation) {
|
||||
presentation.setIcon(PlatformIcons.PROJECT_ICON);
|
||||
presentation.setPresentableText(getProject().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTestPresentation() {
|
||||
return "Project";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(@NotNull VirtualFile file) {
|
||||
ProjectFileIndex index = ProjectRootManager.getInstance(getProject()).getFileIndex();
|
||||
final VirtualFile baseDir = getProject().getBaseDir();
|
||||
|
||||
+8
@@ -68,6 +68,7 @@ public abstract class AbstractPsiBasedNode<Value> extends ProjectViewNode<Value>
|
||||
protected abstract Collection<AbstractTreeNode> getChildrenImpl();
|
||||
protected abstract void updateImpl(final PresentationData data);
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public final Collection<AbstractTreeNode> getChildren() {
|
||||
final PsiElement psiElement = extractPsiFromValue();
|
||||
@@ -83,6 +84,7 @@ public abstract class AbstractPsiBasedNode<Value> extends ProjectViewNode<Value>
|
||||
return children != null ? children : Collections.<AbstractTreeNode>emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
final PsiElement psiElement = extractPsiFromValue();
|
||||
return psiElement != null && psiElement.isValid();
|
||||
@@ -103,6 +105,7 @@ public abstract class AbstractPsiBasedNode<Value> extends ProjectViewNode<Value>
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FileStatus getFileStatus() {
|
||||
VirtualFile file = getVirtualFileForValue();
|
||||
if (file == null) {
|
||||
@@ -124,6 +127,7 @@ public abstract class AbstractPsiBasedNode<Value> extends ProjectViewNode<Value>
|
||||
|
||||
// Should be called in atomic action
|
||||
|
||||
@Override
|
||||
public void update(final PresentationData data) {
|
||||
AccessToken token = ReadAction.start();
|
||||
try {
|
||||
@@ -176,6 +180,7 @@ public abstract class AbstractPsiBasedNode<Value> extends ProjectViewNode<Value>
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(@NotNull final VirtualFile file) {
|
||||
final PsiElement psiElement = extractPsiFromValue();
|
||||
if (psiElement == null || !psiElement.isValid()) {
|
||||
@@ -196,6 +201,7 @@ public abstract class AbstractPsiBasedNode<Value> extends ProjectViewNode<Value>
|
||||
return (psiElement instanceof NavigationItem) ? (NavigationItem) psiElement : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void navigate(boolean requestFocus) {
|
||||
if (canNavigate()) {
|
||||
if (requestFocus) {
|
||||
@@ -207,11 +213,13 @@ public abstract class AbstractPsiBasedNode<Value> extends ProjectViewNode<Value>
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canNavigate() {
|
||||
final NavigationItem item = getNavigationItem();
|
||||
return item != null && item.canNavigate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canNavigateToSource() {
|
||||
final NavigationItem item = getNavigationItem();
|
||||
return item != null && item.canNavigateToSource();
|
||||
|
||||
@@ -27,6 +27,7 @@ public abstract class BasePsiNode <T extends PsiElement> extends AbstractPsiBase
|
||||
super(project, value, viewSettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected PsiElement extractPsiFromValue() {
|
||||
return getValue();
|
||||
|
||||
@@ -53,6 +53,7 @@ public class LibraryGroupNode extends ProjectViewNode<LibraryGroupElement> {
|
||||
this(project, (LibraryGroupElement)value, viewSettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<AbstractTreeNode> getChildren() {
|
||||
Module module = getValue().getModule();
|
||||
@@ -107,10 +108,12 @@ public class LibraryGroupNode extends ProjectViewNode<LibraryGroupElement> {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getTestPresentation() {
|
||||
return "Libraries";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(@NotNull VirtualFile file) {
|
||||
final ProjectFileIndex index = ProjectRootManager.getInstance(getProject()).getFileIndex();
|
||||
if (!index.isInLibrarySource(file) && !index.isInLibraryClasses(file)) {
|
||||
@@ -120,15 +123,18 @@ public class LibraryGroupNode extends ProjectViewNode<LibraryGroupElement> {
|
||||
return someChildContainsFile(file, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(PresentationData presentation) {
|
||||
presentation.setPresentableText(IdeBundle.message("node.projectview.libraries"));
|
||||
presentation.setIcon(PlatformIcons.LIBRARY_ICON);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canNavigate() {
|
||||
return ProjectSettingsService.getInstance(myProject).canOpenModuleLibrarySettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void navigate(final boolean requestFocus) {
|
||||
Module module = getValue().getModule();
|
||||
ProjectSettingsService.getInstance(myProject).openModuleLibrarySettings(module);
|
||||
|
||||
@@ -49,6 +49,7 @@ public abstract class ModuleGroupNode extends ProjectViewNode<ModuleGroup> imple
|
||||
InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException;
|
||||
protected abstract ModuleGroupNode createModuleGroupNode(ModuleGroup moduleGroup);
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<AbstractTreeNode> getChildren() {
|
||||
final Collection<ModuleGroup> childGroups = getValue().childGroups(getProject());
|
||||
@@ -82,37 +83,45 @@ public abstract class ModuleGroupNode extends ProjectViewNode<ModuleGroup> imple
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(@NotNull VirtualFile file) {
|
||||
return someChildContainsFile(file, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(PresentationData presentation) {
|
||||
final String[] groupPath = getValue().getGroupPath();
|
||||
presentation.setPresentableText(groupPath[groupPath.length-1]);
|
||||
presentation.setIcon(PlatformIcons.CLOSED_MODULE_GROUP_ICON);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTestPresentation() {
|
||||
return "Group: " + getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToolTip() {
|
||||
return IdeBundle.message("tooltip.module.group");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWeight() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTypeSortWeight(final boolean sortByType) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrop(TreeNode[] sourceNodes) {
|
||||
final List<Module> modules = extractModules(sourceNodes);
|
||||
return !modules.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drop(TreeNode[] sourceNodes, DataContext dataContext) {
|
||||
final List<Module> modules = extractModules(sourceNodes);
|
||||
MoveModulesToGroupAction.doMove(modules.toArray(new Module[modules.size()]), getValue(), null);
|
||||
|
||||
@@ -41,6 +41,7 @@ public class ModuleListNode extends ProjectViewNode<Module> {
|
||||
this(project, (Module)value, viewSettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<AbstractTreeNode> getChildren() {
|
||||
Module module = getValue();
|
||||
@@ -60,14 +61,17 @@ public class ModuleListNode extends ProjectViewNode<Module> {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getTestPresentation() {
|
||||
return "Modules";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(@NotNull VirtualFile file) {
|
||||
return someChildContainsFile(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(PresentationData presentation) {
|
||||
presentation.setPresentableText("Module Dependencies");
|
||||
presentation.setIcon(PlatformIcons.CLOSED_MODULE_GROUP_ICON);
|
||||
|
||||
+7
@@ -44,6 +44,7 @@ public class NamedLibraryElementNode extends ProjectViewNode<NamedLibraryElement
|
||||
super(project, value, viewSettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<AbstractTreeNode> getChildren() {
|
||||
final List<AbstractTreeNode> children = new ArrayList<AbstractTreeNode>();
|
||||
@@ -51,6 +52,7 @@ public class NamedLibraryElementNode extends ProjectViewNode<NamedLibraryElement
|
||||
return children;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTestPresentation() {
|
||||
return "Library: " + getValue().getName();
|
||||
}
|
||||
@@ -64,10 +66,12 @@ public class NamedLibraryElementNode extends ProjectViewNode<NamedLibraryElement
|
||||
return sdkType.getIcon();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getValue().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(@NotNull VirtualFile file) {
|
||||
return orderEntryContainsFile(getValue().getOrderEntry(), file);
|
||||
}
|
||||
@@ -89,6 +93,7 @@ public class NamedLibraryElementNode extends ProjectViewNode<NamedLibraryElement
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(PresentationData presentation) {
|
||||
presentation.setPresentableText(getValue().getName());
|
||||
final OrderEntry orderEntry = getValue().getOrderEntry();
|
||||
@@ -110,10 +115,12 @@ public class NamedLibraryElementNode extends ProjectViewNode<NamedLibraryElement
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void navigate(final boolean requestFocus) {
|
||||
ProjectSettingsService.getInstance(myProject).openLibraryOrSdkSettings(getValue().getOrderEntry());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canNavigate() {
|
||||
return ProjectSettingsService.getInstance(myProject).canOpenLibraryOrSdkSettings(getValue().getOrderEntry());
|
||||
}
|
||||
|
||||
+1
@@ -55,6 +55,7 @@ public class ProjectViewModuleGroupNode extends ModuleGroupNode {
|
||||
return createTreeNode(ProjectViewModuleNode.class, getProject(), module, getSettings());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModuleGroupNode createModuleGroupNode(ModuleGroup moduleGroup) {
|
||||
return new ProjectViewModuleGroupNode(getProject(), moduleGroup, getSettings());
|
||||
}
|
||||
|
||||
+3
@@ -44,6 +44,7 @@ public class ProjectViewModuleNode extends AbstractModuleNode {
|
||||
this(project, (Module)value, viewSettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<AbstractTreeNode> getChildren() {
|
||||
Module module = getValue();
|
||||
@@ -76,10 +77,12 @@ public class ProjectViewModuleNode extends AbstractModuleNode {
|
||||
return children;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWeight() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTypeSortWeight(final boolean sortByType) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
+4
@@ -43,6 +43,7 @@ public class ProjectViewProjectNode extends AbstractProjectNode {
|
||||
super(project, project, viewSettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<AbstractTreeNode> getChildren() {
|
||||
List<VirtualFile> topLevelContentRoots = ProjectViewDirectoryHelper.getInstance(myProject).getTopLevelRoots();
|
||||
@@ -98,6 +99,7 @@ public class ProjectViewProjectNode extends AbstractProjectNode {
|
||||
}
|
||||
|
||||
Collections.sort(roots, new java.util.Comparator<VirtualFile>() {
|
||||
@Override
|
||||
public int compare(VirtualFile o1, VirtualFile o2) {
|
||||
return o1.getPath().compareTo(o2.getPath());
|
||||
}
|
||||
@@ -124,6 +126,7 @@ public class ProjectViewProjectNode extends AbstractProjectNode {
|
||||
return reducedRoots;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractTreeNode createModuleGroup(final Module module)
|
||||
throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
||||
final VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
|
||||
@@ -137,6 +140,7 @@ public class ProjectViewProjectNode extends AbstractProjectNode {
|
||||
return createTreeNode(ProjectViewModuleNode.class, getProject(), module, getSettings());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractTreeNode createModuleGroupNode(final ModuleGroup moduleGroup)
|
||||
throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
||||
return createTreeNode(ProjectViewModuleGroupNode.class, getProject(), moduleGroup, getSettings());
|
||||
|
||||
@@ -62,6 +62,7 @@ public class PsiDirectoryNode extends BasePsiNode<PsiDirectory> implements Navig
|
||||
return !PlatformUtils.isCidr();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateImpl(PresentationData data) {
|
||||
final Project project = getProject();
|
||||
final PsiDirectory psiDirectory = getValue();
|
||||
@@ -151,10 +152,12 @@ public class PsiDirectoryNode extends BasePsiNode<PsiDirectory> implements Navig
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<AbstractTreeNode> getChildrenImpl() {
|
||||
return ProjectViewDirectoryHelper.getInstance(myProject).getDirectoryChildren(getValue(), getSettings(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public String getTestPresentation() {
|
||||
return "PsiDirectory: " + getValue().getName();
|
||||
@@ -164,6 +167,7 @@ public class PsiDirectoryNode extends BasePsiNode<PsiDirectory> implements Navig
|
||||
return ProjectViewDirectoryHelper.getInstance(getProject()).isShowFQName(getSettings(), getParentValue(), getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(@NotNull VirtualFile file) {
|
||||
final PsiDirectory value = getValue();
|
||||
if (value == null) {
|
||||
@@ -184,12 +188,14 @@ public class PsiDirectoryNode extends BasePsiNode<PsiDirectory> implements Navig
|
||||
return !fileIndex.isIgnored(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualFile getVirtualFile() {
|
||||
PsiDirectory directory = getValue();
|
||||
if (directory == null) return null;
|
||||
return directory.getVirtualFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRepresent(final Object element) {
|
||||
if (super.canRepresent(element)) return true;
|
||||
PsiDirectory directory = getValue();
|
||||
@@ -197,6 +203,7 @@ public class PsiDirectoryNode extends BasePsiNode<PsiDirectory> implements Navig
|
||||
return ProjectViewDirectoryHelper.getInstance(getProject()).canRepresent(element, directory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canNavigate() {
|
||||
VirtualFile file = getVirtualFile();
|
||||
Project project = getProject();
|
||||
@@ -207,10 +214,12 @@ public class PsiDirectoryNode extends BasePsiNode<PsiDirectory> implements Navig
|
||||
(ProjectRootsUtil.isLibraryRoot(file, project) && service.canOpenModuleLibrarySettings()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canNavigateToSource() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void navigate(final boolean requestFocus) {
|
||||
Module module = ModuleUtil.findModuleForPsiElement(getValue());
|
||||
if (module != null) {
|
||||
@@ -250,10 +259,12 @@ public class PsiDirectoryNode extends BasePsiNode<PsiDirectory> implements Navig
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWeight() {
|
||||
return isFQNameShown() ? 70 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
final PsiDirectory directory = getValue();
|
||||
if (directory != null) {
|
||||
@@ -297,11 +308,13 @@ public class PsiDirectoryNode extends BasePsiNode<PsiDirectory> implements Navig
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQualifiedNameSortKey() {
|
||||
final PsiDirectoryFactory factory = PsiDirectoryFactory.getInstance(getProject());
|
||||
return factory.getQualifiedName(getValue(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTypeSortWeight(final boolean sortByType) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user