Merge remote-tracking branch 'origin/master'

This commit is contained in:
Roman Shevchenko
2014-09-09 20:05:04 +04:00
46 changed files with 552 additions and 420 deletions
@@ -285,13 +285,20 @@ public class JVMNameUtil {
return DebuggerManager.getInstance(aClass.getProject()).getVMClassQualifiedName(aClass);
}
public static JVMName getJVMConstructorSignature(@Nullable PsiMethod method, @Nullable PsiClass declaringClass) {
return getJVMSignature(method, true, declaringClass);
}
public static JVMName getJVMSignature(@NotNull PsiMethod method) {
return getJVMSignature(method, method.isConstructor(), method.getContainingClass());
}
@SuppressWarnings({"HardCodedStringLiteral"})
public static JVMName getJVMSignature(PsiMethod method) {
private static JVMName getJVMSignature(@Nullable PsiMethod method, boolean constructor, @Nullable PsiClass declaringClass) {
JVMNameBuffer signature = new JVMNameBuffer();
signature.append("(");
if (method.isConstructor()) {
final PsiClass declaringClass = method.getContainingClass();
if (constructor) {
if (declaringClass != null) {
final PsiClass outerClass = declaringClass.getContainingClass();
if (outerClass != null) {
@@ -302,11 +309,13 @@ public class JVMNameUtil {
}
}
}
for (PsiParameter psiParameter : method.getParameterList().getParameters()) {
appendJVMSignature(signature, psiParameter.getType());
if (method != null) {
for (PsiParameter psiParameter : method.getParameterList().getParameters()) {
appendJVMSignature(signature, psiParameter.getType());
}
}
signature.append(")");
if (!method.isConstructor()) {
if (!constructor && method != null) {
appendJVMSignature(signature, method.getReturnType());
}
else {
@@ -74,7 +74,7 @@ public class JavaDebuggerEvaluator extends XDebuggerEvaluator {
PsiFile psiFile = element.getContainingFile();
PsiCodeFragment fragment = descriptor.createCodeFragment(element);
ExtractLightMethodObjectHandler.ExtractedData data =
ExtractLightMethodObjectHandler.extractLightMethodObject(project, psiFile, fragment, "test");
ExtractLightMethodObjectHandler.extractLightMethodObject(project, psiFile, fragment, CompilingEvaluator.getGeneratedClassName());
descriptor.putUserData(CompilingEvaluator.COMPILING_EVALUATOR_DATA, data);
}
catch (Exception e) {
@@ -184,6 +184,11 @@ public class EvaluatorBuilderImpl implements EvaluatorBuilder {
return rEvaluator;
}
@Override
public void visitTryStatement(PsiTryStatement statement) {
throw new EvaluateRuntimeException(new UnsupportedExpressionException(statement.getText()));
}
@Override
public void visitStatement(PsiStatement statement) {
throwEvaluateException(DebuggerBundle.message("evaluation.error.statement.not.supported", statement.getText()));
@@ -741,24 +746,28 @@ public class EvaluatorBuilderImpl implements EvaluatorBuilder {
}
private int calcIterationCount(final PsiJavaCodeReferenceElement qualifier) {
int iterationCount = 0;
if (qualifier != null) {
PsiElement targetClass = qualifier.resolve();
if (targetClass == null || getContextPsiClass() == null) {
throwEvaluateException(DebuggerBundle.message("evaluation.error.invalid.expression", qualifier.getText()));
}
try {
PsiClass aClass = getContextPsiClass();
while (aClass != null && !aClass.equals(targetClass)) {
iterationCount++;
aClass = getOuterClass(aClass);
}
}
catch (Exception e) {
//noinspection ThrowableResultOfMethodCallIgnored
throw new EvaluateRuntimeException(EvaluateExceptionUtil.createEvaluateException(e));
return calcIterationCount(qualifier.resolve(), qualifier.getText());
}
return 0;
}
private int calcIterationCount(PsiElement targetClass, String name) {
int iterationCount = 0;
if (targetClass == null || getContextPsiClass() == null) {
throwEvaluateException(DebuggerBundle.message("evaluation.error.invalid.expression", name));
}
try {
PsiClass aClass = getContextPsiClass();
while (aClass != null && !aClass.equals(targetClass)) {
iterationCount++;
aClass = getOuterClass(aClass);
}
}
catch (Exception e) {
//noinspection ThrowableResultOfMethodCallIgnored
throw new EvaluateRuntimeException(EvaluateExceptionUtil.createEvaluateException(e));
}
return iterationCount;
}
@@ -1187,8 +1196,11 @@ public class EvaluatorBuilderImpl implements EvaluatorBuilder {
argumentEvaluators = wrapVarargs(constructor.getParameterList().getParameters(), argExpressions, constructorResolveResult.getSubstitutor(), argumentEvaluators);
}
//noinspection HardCodedStringLiteral
JVMName signature = constructor != null ? JVMNameUtil.getJVMSignature(constructor) : JVMNameUtil.getJVMRawText("()V");
if (aClass != null && aClass.getContainingClass() != null && !aClass.hasModifierProperty(PsiModifier.STATIC)) {
argumentEvaluators = addThisEvaluator(argumentEvaluators, aClass.getContainingClass());
}
JVMName signature = JVMNameUtil.getJVMConstructorSignature(constructor, aClass);
myResult = new NewClassInstanceEvaluator(
new TypeEvaluator(JVMNameUtil.getJVMQualifiedName(expressionPsiType)),
signature,
@@ -1205,6 +1217,14 @@ public class EvaluatorBuilderImpl implements EvaluatorBuilder {
}
}
private Evaluator[] addThisEvaluator(Evaluator[] argumentEvaluators, PsiClass cls) {
Evaluator[] res = new Evaluator[argumentEvaluators.length+1];
int depth = calcIterationCount(cls, "this");
res[0] = new ThisEvaluator(depth);
System.arraycopy(argumentEvaluators, 0, res, 1, argumentEvaluators.length);
return res;
}
@Override
public void visitArrayInitializerExpression(PsiArrayInitializerExpression expression) {
PsiExpression[] initializers = expression.getInitializers();
@@ -21,13 +21,13 @@
*/
package com.intellij.debugger.engine.evaluation.expression;
import com.intellij.debugger.DebuggerBundle;
import com.intellij.debugger.engine.DebugProcessImpl;
import com.intellij.debugger.engine.DebuggerUtils;
import com.intellij.debugger.engine.JVMName;
import com.intellij.debugger.engine.evaluation.EvaluateException;
import com.intellij.debugger.engine.evaluation.EvaluateExceptionUtil;
import com.intellij.debugger.engine.evaluation.EvaluationContextImpl;
import com.intellij.debugger.impl.DebuggerUtilsEx;
import com.intellij.debugger.DebuggerBundle;
import com.sun.jdi.ClassType;
import com.sun.jdi.Method;
import com.sun.jdi.ObjectReference;
@@ -55,7 +55,7 @@ class NewClassInstanceEvaluator implements Evaluator {
}
ClassType classType = (ClassType)obj;
// find constructor
Method method = DebuggerUtilsEx.findMethod(classType, "<init>", myConstructorSignature.getName(debugProcess));
Method method = DebuggerUtils.findMethod(classType, "<init>", myConstructorSignature.getName(debugProcess));
if (method == null) {
throw EvaluateExceptionUtil.createEvaluateException(
DebuggerBundle.message("evaluation.error.cannot.resolve.constructor", myConstructorSignature.getDisplayName(debugProcess)));
@@ -51,9 +51,9 @@ public class CompilingEvaluator implements ExpressionEvaluator {
private final PsiCodeFragment myCodeFragment;
private final PsiElement myPsiContext;
private final ExtractLightMethodObjectHandler.ExtractedData myData;
private final EvaluationDescriptor myDescriptor;
public static Key<ExtractLightMethodObjectHandler.ExtractedData> COMPILING_EVALUATOR_DATA = new Key<ExtractLightMethodObjectHandler.ExtractedData>("COMPILING_EVALUATOR_DATA");
private final EvaluationDescriptor myDescriptor;
public CompilingEvaluator(TextWithImports text,
PsiCodeFragment codeFragment,
@@ -138,14 +138,17 @@ public class CompilingEvaluator implements ExpressionEvaluator {
VirtualMachineProxyImpl proxy = (VirtualMachineProxyImpl)process.getVirtualMachineProxy();
for (OutputFileObject cls : classes) {
Method defineMethod = ((ClassType)classLoader.referenceType()).concreteMethodByName("defineClass", "(Ljava/lang/String;[BII)Ljava/lang/Class;");
byte[] bytes = cls.toByteArray();
ArrayList<Value> args = new ArrayList<Value>();
args.add(proxy.mirrorOf(cls.myOrigName));
args.add(mirrorOf(bytes, context, process));
args.add(proxy.mirrorOf(0));
args.add(proxy.mirrorOf(bytes.length));
classLoader.invokeMethod(threadReference, defineMethod, args, ClassType.INVOKE_SINGLE_THREADED);
if (cls.getName().contains(getGenClassName())) {
Method defineMethod =
((ClassType)classLoader.referenceType()).concreteMethodByName("defineClass", "(Ljava/lang/String;[BII)Ljava/lang/Class;");
byte[] bytes = cls.toByteArray();
ArrayList<Value> args = new ArrayList<Value>();
args.add(proxy.mirrorOf(cls.myOrigName));
args.add(mirrorOf(bytes, context, process));
args.add(proxy.mirrorOf(0));
args.add(proxy.mirrorOf(bytes.length));
classLoader.invokeMethod(threadReference, defineMethod, args, ClassType.INVOKE_SINGLE_THREADED);
}
}
return (ClassType)process.findClass(context, getGenPackageName() + '.' + getGenClassName(), classLoader);
}
@@ -161,7 +164,11 @@ public class CompilingEvaluator implements ExpressionEvaluator {
return reference;
}
private static final String GEN_CLASS_NAME = "Test";
public static String getGeneratedClassName() {
return GEN_CLASS_NAME;
}
private static final String GEN_CLASS_NAME = "GeneratedEvaluationClass";
private static final String GEN_CLASS_PACKAGE = "dummy";
private static final String GEN_CLASS_FULL_NAME = GEN_CLASS_PACKAGE + '.' + GEN_CLASS_NAME;
private static final String GEN_METHOD_NAME = "invoke";
@@ -17,6 +17,7 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor;
import com.intellij.codeInsight.ExternalAnnotationsManager;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.fileChooser.FileElement;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.progress.ProgressIndicator;
@@ -29,7 +30,9 @@ import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.ui.*;
import com.intellij.openapi.roots.ui.OrderRootTypeUIFactory;
import com.intellij.openapi.roots.ui.configuration.PathUIUtils;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileVisitor;
@@ -45,6 +48,14 @@ import java.util.*;
* @author nik
*/
public class DefaultLibraryRootsComponentDescriptor extends LibraryRootsComponentDescriptor {
private static final Set<String> NATIVE_LIBRARY_EXTENSIONS = ContainerUtil.newTroveSet(FileUtil.PATH_HASHING_STRATEGY, "dll", "so", "dylib");
public static final Condition<VirtualFile> LIBRARY_ROOT_CONDITION = new Condition<VirtualFile>() {
@Override
public boolean value(VirtualFile file) {
return FileElement.isArchive(file) || isNativeLibrary(file);
}
};
@Override
public OrderRootTypePresentation getRootTypePresentation(@NotNull OrderRootType type) {
return getDefaultPresentation(type);
@@ -67,10 +78,17 @@ public class DefaultLibraryRootsComponentDescriptor extends LibraryRootsComponen
new AnnotationsRootFilter(), new NativeLibraryRootFilter());
}
private static boolean isNativeLibrary(VirtualFile file) {
String extension = file.getExtension();
return extension != null && NATIVE_LIBRARY_EXTENSIONS.contains(extension);
}
@NotNull
@Override
public FileChooserDescriptor createAttachFilesChooserDescriptor(@Nullable String libraryName) {
FileChooserDescriptor descriptor = super.createAttachFilesChooserDescriptor(libraryName);
final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, true, false, true, true).withFileFilter(LIBRARY_ROOT_CONDITION);
descriptor.setTitle(StringUtil.isEmpty(libraryName) ? ProjectBundle.message("library.attach.files.action")
: ProjectBundle.message("library.attach.files.to.library.action", libraryName));
descriptor.setDescription(ProjectBundle.message("library.java.attach.files.description"));
return descriptor;
}
@@ -119,24 +137,25 @@ public class DefaultLibraryRootsComponentDescriptor extends LibraryRootsComponen
}
}
private static class NativeLibraryRootFilter extends RootFilter {
private static final Set<String> NATIVE_LIBRARY_EXTENSIONS = ContainerUtil.newTroveSet(FileUtil.PATH_HASHING_STRATEGY, "dll", "so", "dylib");
private static class NativeLibraryRootFilter extends RootDetector {
private NativeLibraryRootFilter() {
super(NativeLibraryOrderRootType.getInstance(), false, "external annotations");
super(NativeLibraryOrderRootType.getInstance(), false, "native library location");
}
@NotNull
@Override
public boolean isAccepted(@NotNull VirtualFile rootCandidate, @NotNull ProgressIndicator progressIndicator) {
public Collection<VirtualFile> detectRoots(@NotNull VirtualFile rootCandidate, @NotNull ProgressIndicator progressIndicator) {
if (rootCandidate.isDirectory()) {
for (VirtualFile file : rootCandidate.getChildren()) {
String extension = file.getExtension();
if (extension != null && NATIVE_LIBRARY_EXTENSIONS.contains(extension)) {
return true;
if (isNativeLibrary(file)) {
return Collections.singleton(rootCandidate);
}
}
}
return false;
else if (isNativeLibrary(rootCandidate)) {
return Collections.singleton(rootCandidate.getParent());
}
return Collections.emptyList();
}
}
@@ -625,7 +625,7 @@ public class ExtractMethodProcessor implements MatchProvider {
}
}
private void doExtract() throws IncorrectOperationException {
public void doExtract() throws IncorrectOperationException {
PsiMethod newMethod = generateEmptyMethod(getThrownExceptions(), isStatic());
@@ -17,23 +17,31 @@ package com.intellij.refactoring.extractMethodObject;
import com.intellij.codeInsight.CodeInsightUtil;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.RangeMarker;
import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.controlFlow.*;
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.refactoring.extractMethod.AbstractExtractDialog;
import com.intellij.refactoring.extractMethod.InputVariables;
import com.intellij.refactoring.extractMethod.PrepareFailedException;
import com.intellij.refactoring.util.CommonRefactoringUtil;
import com.intellij.refactoring.util.RefactoringUtil;
import com.intellij.refactoring.util.VariableData;
import com.intellij.refactoring.util.duplicates.DuplicatesImpl;
import com.intellij.usageView.UsageInfo;
import com.intellij.util.Function;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -105,9 +113,19 @@ public class ExtractLightMethodObjectHandler {
return null;
}
final List<PsiVariable> variables = ControlFlowUtil.getUsedVariables(controlFlow,
controlFlow.getStartOffset(elementsCopy[0]),
controlFlow.getEndOffset(elementsCopy[elementsCopy.length - 1]));
List<PsiVariable> variables = ControlFlowUtil.getUsedVariables(controlFlow,
controlFlow.getStartOffset(elementsCopy[0]),
controlFlow.getEndOffset(elementsCopy[elementsCopy.length - 1]));
variables = ContainerUtil.filter(variables, new Condition<PsiVariable>() {
@Override
public boolean value(PsiVariable variable) {
final PsiElement variableScope = variable instanceof PsiParameter ? ((PsiParameter)variable).getDeclarationScope()
: PsiTreeUtil.getParentOfType(variable, PsiCodeBlock.class, PsiForStatement.class);
return variableScope != null && PsiTreeUtil.isAncestor(variableScope, elementsCopy[elementsCopy.length - 1], false);
}
});
final String outputVariables = StringUtil.join(variables, new Function<PsiVariable, String>() {
@Override
@@ -126,7 +144,32 @@ public class ExtractLightMethodObjectHandler {
};
extractMethodObjectProcessor.getExtractProcessor().setShowErrorDialogs(false);
ExtractMethodObjectHandler.extractMethodObject(project, null, extractMethodObjectProcessor);
final ExtractMethodObjectProcessor.MyExtractMethodProcessor extractProcessor = extractMethodObjectProcessor.getExtractProcessor();
if (extractProcessor.prepare() && CommonRefactoringUtil
.checkReadOnlyStatus(project, extractProcessor.getTargetClass().getContainingFile())) {
if (extractProcessor.showDialog()) {
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
public void run() {
try {
extractProcessor.doExtract();
final UsageInfo[] usages = extractMethodObjectProcessor.findUsages();
extractMethodObjectProcessor.performRefactoring(usages);
extractMethodObjectProcessor.runChangeSignature();
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
if (extractMethodObjectProcessor.isCreateInnerClass()) {
extractMethodObjectProcessor.changeInstanceAccess(project);
}
final PsiElement method = extractMethodObjectProcessor.getMethod();
LOG.assertTrue(method != null);
method.delete();
}
}, ExtractMethodObjectProcessor.REFACTORING_NAME, ExtractMethodObjectProcessor.REFACTORING_NAME);
}
}
PsiDocumentManager.getInstance(project).commitAllDocuments();
@@ -105,7 +105,11 @@ public class ExtractMethodObjectHandler implements RefactoringActionHandler {
}
});
processor.run();
processor.runChangeSignature();
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
processor.runChangeSignature();
}
});
}
catch (IncorrectOperationException e) {
LOG.error(e);
@@ -149,7 +149,7 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
return UsageViewUtil.removeDuplicatedUsages(usageInfos);
}
protected void performRefactoring(final UsageInfo[] usages) {
public void performRefactoring(final UsageInfo[] usages) {
try {
if (isCreateInnerClass()) {
myInnerClass = (PsiClass)getMethod().getContainingClass().add(myElementFactory.createClass(getInnerClassName()));
@@ -392,19 +392,14 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
void runChangeSignature() {
if (myCopyMethodToInner != null) {
ApplicationManager.getApplication().runWriteAction(myCopyMethodToInner);
myCopyMethodToInner.run();
}
if (myChangeReturnType) {
final Runnable runnable = new Runnable() {
public void run() {
final PsiTypeElement typeElement = ((PsiLocalVariable)((PsiDeclarationStatement)JavaPsiFacade.getElementFactory(myProject)
.createStatementFromText(myInnerClassName + " l =null;", myInnerClass)).getDeclaredElements()[0]).getTypeElement();
final PsiTypeElement innerMethodReturnTypeElement = myInnerMethod.getReturnTypeElement();
LOG.assertTrue(innerMethodReturnTypeElement != null);
innerMethodReturnTypeElement.replace(typeElement);
}
};
ApplicationManager.getApplication().runWriteAction(runnable);
final PsiTypeElement typeElement = ((PsiLocalVariable)((PsiDeclarationStatement)JavaPsiFacade.getElementFactory(myProject)
.createStatementFromText(myInnerClassName + " l =null;", myInnerClass)).getDeclaredElements()[0]).getTypeElement();
final PsiTypeElement innerMethodReturnTypeElement = myInnerMethod.getReturnTypeElement();
LOG.assertTrue(innerMethodReturnTypeElement != null);
innerMethodReturnTypeElement.replace(typeElement);
}
}
@@ -0,0 +1,8 @@
interface I {
void foo(int i) {}
}
class Sample {
void foo() {
System.out.println("hello <caret>world");
}
}
@@ -98,6 +98,20 @@ public class ExtractMethodObject4DebuggerTest extends LightRefactoringTestCase {
" }");
}
public void testAnonymousClassParams() throws Exception {
doTest("new I() {public void foo(int i) {i++;}};", "new Test().invoke();",
"public class Test {\n" +
" public void invoke() {\n" +
" new I() {\n" +
" public void foo(int i) {\n" +
" i++;\n" +
" }\n" +
" };\n" +
" }\n" +
" }");
}
@Override
protected Sdk getProjectJDK() {
return IdeaTestUtil.getMockJdk18();
@@ -20,7 +20,7 @@ import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Consumer;
import com.intellij.util.Processor;
@@ -101,15 +101,10 @@ public class RepositoryUtil {
}
public static void visitAllChildrenRecursively(@Nullable VirtualFile dir) {
if (dir == null) {
return;
if (dir != null) {
//noinspection unchecked
VfsUtilCore.processFilesRecursively(dir, Processor.TRUE);
}
VfsUtil.processFilesRecursively(dir, new Processor<VirtualFile>() {
@Override
public boolean process(VirtualFile virtualFile) {
return true;
}
});
}
public static class Updater implements Consumer<Object> {
@@ -109,7 +109,7 @@
<properties/>
<border type="none"/>
<children>
<component id="2479d" class="javax.swing.JLabel">
<component id="2479d" class="javax.swing.JLabel" binding="myTabTitleLimitLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
@@ -46,6 +46,7 @@ public class EditorTabsConfigurable implements EditorOptionsProvider {
private JCheckBox myShowDirectoryInTabCheckBox;
private JRadioButton myActivateRightNeighbouringTabRadioButton;
private JTextField myTabTitleLimitField;
private JLabel myTabTitleLimitLabel;
public EditorTabsConfigurable() {
myEditorTabPlacement.setModel(new DefaultComboBoxModel(new Object[]{
@@ -69,21 +70,15 @@ public class EditorTabsConfigurable implements EditorOptionsProvider {
private void revalidateSingleRowCheckbox() {
final int i = ((Integer)myEditorTabPlacement.getSelectedItem()).intValue();
if (i == UISettings.TABS_NONE) {
myHideKnownExtensions.setEnabled(false);
myScrollTabLayoutInEditorCheckBox.setEnabled(false);
myCbModifiedTabsMarkedWithAsterisk.setEnabled(false);
myShowTabsTooltipsCheckBox.setEnabled(false);
myShowCloseButtonOnCheckBox.setEnabled(false);
myShowDirectoryInTabCheckBox.setEnabled(false);
} else {
myHideKnownExtensions.setEnabled(true);
myScrollTabLayoutInEditorCheckBox.setEnabled(true);
myCbModifiedTabsMarkedWithAsterisk.setEnabled(true);
myShowTabsTooltipsCheckBox.setEnabled(true);
myShowCloseButtonOnCheckBox.setEnabled(true);
myShowDirectoryInTabCheckBox.setEnabled(true);
}
boolean none = i == UISettings.TABS_NONE;
myHideKnownExtensions.setEnabled(!none);
myScrollTabLayoutInEditorCheckBox.setEnabled(!none);
myCbModifiedTabsMarkedWithAsterisk.setEnabled(!none);
myShowTabsTooltipsCheckBox.setEnabled(!none);
myShowCloseButtonOnCheckBox.setEnabled(!none);
myShowDirectoryInTabCheckBox.setEnabled(!none);
myTabTitleLimitField.setEnabled(!none);
myTabTitleLimitLabel.setEnabled(!none);
if (SwingConstants.TOP == i) {
myScrollTabLayoutInEditorCheckBox.setEnabled(true);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -26,6 +26,7 @@ import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.help.HelpManager;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.ui.ToolbarDecorator;
import com.intellij.ui.table.JBTable;
@@ -107,11 +108,11 @@ class EditVariableDialog extends DialogWrapper {
myTable.getSelectionModel().setSelectionInterval(0, 0);
}
JComboBox comboField = new JComboBox();
ComboBox comboField = new ComboBox();
Macro[] macros = MacroFactory.getMacros();
Arrays.sort(macros, new Comparator<Macro> () {
@Override
public int compare(Macro m1, Macro m2) {
public int compare(@NotNull Macro m1, @NotNull Macro m2) {
return m1.getPresentableName().compareTo(m2.getPresentableName());
}
});
@@ -231,11 +232,13 @@ class EditVariableDialog extends DialogWrapper {
}
}
@NotNull
@Override
public String getColumnName(int column) {
return myNames[column];
}
@NotNull
@Override
public Class getColumnClass(int c) {
if (c <= 2) {
@@ -70,7 +70,7 @@ public class RootDetectionUtil {
try {
for (VirtualFile rootCandidate : rootCandidates) {
final Collection<DetectedLibraryRoot> roots = detector.detectRoots(rootCandidate, indicator);
if (!roots.isEmpty() && allRootsHaveOneTypeAndEqualTo(roots, rootCandidate)) {
if (!roots.isEmpty() && allRootsHaveOneTypeAndEqualToOrAreDirectParentOf(roots, rootCandidate)) {
for (DetectedLibraryRoot root : roots) {
final LibraryRootType libraryRootType = root.getTypes().get(0);
result.add(new OrderRoot(root.getFile(), libraryRootType.getType(), libraryRootType.isJarDirectory()));
@@ -141,9 +141,9 @@ public class RootDetectionUtil {
return result;
}
private static boolean allRootsHaveOneTypeAndEqualTo(Collection<DetectedLibraryRoot> roots, VirtualFile candidate) {
private static boolean allRootsHaveOneTypeAndEqualToOrAreDirectParentOf(Collection<DetectedLibraryRoot> roots, VirtualFile candidate) {
for (DetectedLibraryRoot root : roots) {
if (root.getTypes().size() > 1 || !root.getFile().equals(candidate)) {
if (root.getTypes().size() > 1 || !root.getFile().equals(candidate) && !root.getFile().equals(candidate.getParent())) {
return false;
}
}
@@ -15,6 +15,8 @@
*/
package com.intellij.openapi.application;
import org.jetbrains.annotations.Nullable;
/**
* Implementers of the interface declared via {@link com.intellij.ExtensionPoints#APPLICATION_STARTER}
* may be capable of processing an external command line within a running IntelliJ Platform instance.
@@ -28,5 +30,10 @@ public abstract class ApplicationStarterEx implements ApplicationStarter {
return false;
}
@Deprecated
public void processExternalCommandLine(String[] args) { }
public void processExternalCommandLine(String[] args, @Nullable String currentDirectory) {
processExternalCommandLine(args);
}
}
@@ -141,7 +141,7 @@ public class CommandLineProcessor {
starter instanceof ApplicationStarterEx &&
((ApplicationStarterEx)starter).canProcessExternalCommandLine()) {
LOG.info("Processing command with " + starter);
((ApplicationStarterEx) starter).processExternalCommandLine(ArrayUtil.toStringArray(args));
((ApplicationStarterEx) starter).processExternalCommandLine(ArrayUtil.toStringArray(args), currentDirectory);
return null;
}
}
@@ -26,6 +26,7 @@ import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.FileInputStream;
@@ -57,13 +58,13 @@ public abstract class ApplicationStarterBase extends ApplicationStarterEx {
}
@Override
public void processExternalCommandLine(String[] args) {
public void processExternalCommandLine(String[] args, @Nullable String currentDirectory) {
if (!checkArguments(args)) {
Messages.showMessageDialog(getUsageMessage(), StringUtil.toTitleCase(getCommandName()), Messages.getInformationIcon());
return;
}
try {
processCommand(args);
processCommand(args, currentDirectory);
}
catch (Exception e) {
Messages.showMessageDialog(String.format("Error showing %s: %s", getCommandName(), e.getMessage()),
@@ -86,7 +87,7 @@ public abstract class ApplicationStarterBase extends ApplicationStarterEx {
public abstract String getUsageMessage();
protected abstract void processCommand(String[] args) throws Exception;
protected abstract void processCommand(String[] args, @Nullable String currentDirectory) throws Exception;
@Override
public void premain(String[] args) {
@@ -99,7 +100,7 @@ public abstract class ApplicationStarterBase extends ApplicationStarterEx {
@Override
public void main(String[] args) {
try {
processCommand(args);
processCommand(args, null);
}
catch (Exception e) {
e.printStackTrace();
@@ -116,12 +117,12 @@ public abstract class ApplicationStarterBase extends ApplicationStarterEx {
System.exit(0);
}
public static VirtualFile findOrCreateFile(String path) throws IOException {
public static VirtualFile findOrCreateFile(String path, @Nullable String currentDirectory) throws IOException {
final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(path));
if (file == null) {
boolean result = new File(path).createNewFile();
if (result) {
return findFile(path);
return findFile(path, currentDirectory);
}
else {
throw new FileNotFoundException("Can't create file " + path);
@@ -167,11 +168,10 @@ public abstract class ApplicationStarterBase extends ApplicationStarterEx {
}
@NotNull
public static VirtualFile findFile(final String path) throws OperationFailedException {
public static VirtualFile findFile(final String path, @Nullable String currentDirectory) throws OperationFailedException {
File ioFile = new File(path);
if (!ioFile.exists()) {
final String dir = PathManager.getOriginalWorkingDir();
ioFile = new File(dir + File.separator + path);
if (!ioFile.isAbsolute() && currentDirectory != null) {
ioFile = new File(currentDirectory, path);
}
final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ioFile);
if (file == null) {
@@ -21,6 +21,7 @@ import com.intellij.openapi.application.ApplicationNamesInfo;
import com.intellij.openapi.fileTypes.UnknownFileType;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.Nullable;
/**
* @author max
@@ -37,11 +38,11 @@ public class DiffApplication extends ApplicationStarterBase {
return DiffBundle.message("diff.application.usage.parameters.and.description", scriptName);
}
public void processCommand(String[] args) throws OperationFailedException {
public void processCommand(String[] args, @Nullable String currentDirectory) throws OperationFailedException {
final String path1 = args[1];
final String path2 = args[2];
final VirtualFile file1 = findFile(path1);
final VirtualFile file2 = findFile(path2);
final VirtualFile file1 = findFile(path1, currentDirectory);
final VirtualFile file2 = findFile(path2, currentDirectory);
final boolean areDirs = areDirs(file1, file2);
final boolean areJars = areJars(file1, file2);
if (areDirs || areJars) {
@@ -18,6 +18,7 @@ package com.intellij.openapi.diff;
import com.intellij.openapi.application.ApplicationNamesInfo;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.Nullable;
/**
* @author Konstantin Bulenkov
@@ -34,11 +35,11 @@ public class MergeApplication extends ApplicationStarterBase {
}
@Override
protected void processCommand(String[] args) throws Exception {
final VirtualFile left = findFile(args[1]);
final VirtualFile right = findFile(args[2]);
final VirtualFile middle = findFile(args[3]);
final VirtualFile result = findOrCreateFile(args.length == 4 ? args[3] : args[4]);
protected void processCommand(String[] args, @Nullable String currentDirectory) throws Exception {
final VirtualFile left = findFile(args[1], currentDirectory);
final VirtualFile right = findFile(args[2], currentDirectory);
final VirtualFile middle = findFile(args[3], currentDirectory);
final VirtualFile result = findOrCreateFile(args.length == 4 ? args[3] : args[4], currentDirectory);
MergeRequest request = DiffRequestFactory.getInstance()
.createMergeRequest(getText(left), getText(right), getText(middle), result,
@@ -47,6 +47,9 @@ import java.util.ArrayList;
import java.util.EnumSet;
class PreviewPanel extends JPanel {
private CardLayout myLayout;
enum ContentType {Files, Usages, Diagrams, Documentation}
private static final Key<VirtualFile> FILE_KEY = Key.create("v_file");
@@ -162,8 +165,12 @@ class PreviewPanel extends JPanel {
myEditorsSplitters.createCurrentWindow();
myWindow = myEditorsSplitters.getCurrentWindow();
myWindow.setTabsPlacement(UISettings.TABS_NONE);
setLayout(new GridLayout(1, 1));
add(myEditorsSplitters);
myLayout = new CardLayout();
setLayout(myLayout);
add(ContentType.Files.toString(), myEditorsSplitters);
//add(ContentType.Usages.toString(), myUsagesPreview);??? tree or editor ???
//add(ContentType.Diagrams.toString(), myDiagramPanel);
//add(ContentType.Documentation.toString(), myDocumentationPanel);//todo
myToolWindow.setTitleActions(new MoveToEditorTabsAction(), new CloseFileAction());
ArrayList<AnAction> myGearActions = new ArrayList<AnAction>();
for (ContentType contentType : ContentType.values()) {
@@ -17,7 +17,6 @@ package com.intellij.openapi.options.newEditor;
import com.intellij.AbstractBundle;
import com.intellij.CommonBundle;
import com.intellij.icons.AllIcons;
import com.intellij.ide.ui.laf.darcula.ui.DarculaTextBorder;
import com.intellij.ide.ui.laf.darcula.ui.DarculaTextFieldUI;
import com.intellij.ide.ui.search.SearchUtil;
@@ -1219,16 +1218,18 @@ public class OptionsEditor extends JPanel implements DataProvider, Place.Navigat
* @return default view for the specified configurable
*/
private JComponent createDefaultComponent(SearchableConfigurable searchable) {
JPanel box = new JPanel();
box.setLayout(new BoxLayout(box, BoxLayout.Y_AXIS));
JPanel panel = new JPanel(new BorderLayout(0, 9));
try {
box.add(new JLabel(getDefaultDescription(searchable)));
panel.add(BorderLayout.NORTH, new JLabel(getDefaultDescription(searchable)));
}
catch (AssertionError error) {
return null; // description is not set
}
if (searchable instanceof Configurable.Composite) {
box.add(Box.createVerticalStrut(9));
JPanel box = new JPanel();
box.setLayout(new BoxLayout(box, BoxLayout.Y_AXIS));
panel.add(BorderLayout.CENTER, box);
Configurable.Composite composite = (Configurable.Composite)searchable;
for (final Configurable configurable : composite.getConfigurables()) {
LinkLabel label = new LinkLabel(configurable.getDisplayName(), null) {
@@ -1241,7 +1242,7 @@ public class OptionsEditor extends JPanel implements DataProvider, Place.Navigat
box.add(label);
}
}
return box;
return panel;
}
@NotNull
@@ -17,6 +17,7 @@ package com.intellij.openapi.wm.impl;
import com.intellij.ide.actions.ResizeToolWindowAction;
import com.intellij.idea.ActionsBundle;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.keymap.Keymap;
import com.intellij.openapi.keymap.KeymapManagerListener;
@@ -55,8 +56,6 @@ import java.util.Map;
*/
public final class InternalDecorator extends JPanel implements Queryable, TypeSafeDataProvider {
private static final int DIVIDER_WIDTH = UIUtil.isUnderDarcula() ? 2 : 5;
private Project myProject;
private WindowInfoImpl myInfo;
private final ToolWindowImpl myToolWindow;
@@ -170,7 +169,7 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa
else if (ToolWindowAnchor.RIGHT == anchor) {
add(myDivider, BorderLayout.WEST);
}
myDivider.setPreferredSize(new Dimension(DIVIDER_WIDTH, DIVIDER_WIDTH));
myDivider.setPreferredSize(new Dimension(0, 0));
}
else { // docked and floating windows don't have divider
remove(myDivider);
@@ -304,10 +303,16 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa
@Override
public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
g.setColor(UIUtil.getPanelBackground());
doPaintBorder(c, g, x, y, width, height);
g.setColor(new Color(0, 0, 0, 90));
doPaintBorder(c, g, x, y, width, height);
if (UIUtil.isUnderDarcula()) {
g.setColor(Gray._40);
doPaintBorder(c, g, x, y, width, height);
}
else {
g.setColor(UIUtil.getPanelBackground());
doPaintBorder(c, g, x, y, width, height);
g.setColor(Gray._155);
doPaintBorder(c, g, x, y, width, height);
}
}
private void doPaintBorder(Component c, Graphics g, int x, int y, int width, int height) {
@@ -315,18 +320,22 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa
if (insets.top > 0) {
UIUtil.drawLine(g, x, y + insets.top - 1, x + width - 1, y + insets.top - 1);
UIUtil.drawLine(g, x, y + insets.top, x + width - 1, y + insets.top);
}
if (insets.left > 0) {
UIUtil.drawLine(g, x, y + insets.top, x, y + height - 1);
UIUtil.drawLine(g, x, y, x, y + height);
UIUtil.drawLine(g, x + 1, y, x + 1, y + height);
}
if (insets.right > 0) {
UIUtil.drawLine(g, x + width - 1, y + insets.top, x + width - 1, y + height - 1);
UIUtil.drawLine(g, x + width - 1, y + insets.top, x + width - 1, y + height);
UIUtil.drawLine(g, x + width, y + insets.top, x + width, y + height);
}
if (insets.bottom > 0) {
UIUtil.drawLine(g, x, y + height - 1, x + width - 1, y + height - 1);
UIUtil.drawLine(g, x, y + height - 1, x + width, y + height - 1);
UIUtil.drawLine(g, x, y + height, x + width, y + height);
}
}
@@ -355,7 +364,7 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa
component = parent;
parent = component.getParent();
}
return new Insets(0, anchor == ToolWindowAnchor.RIGHT ? 1 : 0, 0, anchor == ToolWindowAnchor.LEFT ? 1 : 0);
return new Insets(0, anchor == ToolWindowAnchor.RIGHT ? 1 : 0, anchor == ToolWindowAnchor.TOP ? 1 : 0, anchor == ToolWindowAnchor.LEFT ? 1 : 0);
}
@Override
@@ -614,135 +623,98 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa
private final class MyDivider extends JPanel {
private boolean myDragging;
private Point myLastPoint;
private Disposable myDisposable;
private IdeGlassPane myGlassPane;
private MyDivider() {
myDragging = false;
enableEvents(MouseEvent.MOUSE_EVENT_MASK | MouseEvent.MOUSE_MOTION_EVENT_MASK);
setBorder(new DividerBorder());
private final MouseAdapter myListener = new MyMouseAdapter();
@Override
public void addNotify() {
super.addNotify();
myGlassPane = IdeGlassPaneUtil.find(this);
myDisposable = Disposer.newDisposable();
myGlassPane.addMouseMotionPreprocessor(myListener, myDisposable);
myGlassPane.addMousePreprocessor(myListener, myDisposable);
}
@Override
protected final void processMouseMotionEvent(final MouseEvent e) {
super.processMouseMotionEvent(e);
if (MouseEvent.MOUSE_DRAGGED == e.getID()) {
myDragging = true;
final ToolWindowAnchor anchor = myInfo.getAnchor();
final boolean isVerticalCursor = myInfo.isDocked() ? anchor.isSplitVertically() : anchor.isHorizontal();
setCursor(isVerticalCursor ? Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR) : Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
final Point point = e.getPoint();
public void removeNotify() {
super.removeNotify();
if (myDisposable != null && !Disposer.isDisposed(myDisposable)) {
Disposer.dispose(myDisposable);
}
}
boolean isInDragZone(MouseEvent e) {
final Point p = SwingUtilities.convertMouseEvent(e.getComponent(), e, this).getPoint();
return Math.abs(myInfo.getAnchor().isHorizontal() ? p.y : p.x) < 6;
}
private class MyMouseAdapter extends MouseAdapter {
private void updateCursor(MouseEvent e) {
if (isInDragZone(e)) {
myGlassPane.setCursor(MyDivider.this.getCursor(), MyDivider.this);
e.consume();
}
}
@Override
public void mousePressed(MouseEvent e) {
myDragging = isInDragZone(e);
updateCursor(e);
}
@Override
public void mouseClicked(MouseEvent e) {
updateCursor(e);
}
@Override
public void mouseReleased(MouseEvent e) {
updateCursor(e);
myDragging = false;
}
@Override
public void mouseMoved(MouseEvent e) {
updateCursor(e);
}
@Override
public void mouseDragged(MouseEvent e) {
if (!myDragging) return;
MouseEvent event = SwingUtilities.convertMouseEvent(e.getComponent(), e, MyDivider.this);
final ToolWindowAnchor anchor = myInfo.getAnchor();
final Point point = event.getPoint();
final Container windowPane = InternalDecorator.this.getParent();
myLastPoint = SwingUtilities.convertPoint(this, point, windowPane);
myLastPoint = SwingUtilities.convertPoint(MyDivider.this, point, windowPane);
myLastPoint.x = Math.min(Math.max(myLastPoint.x, 0), windowPane.getWidth());
myLastPoint.y = Math.min(Math.max(myLastPoint.y, 0), windowPane.getHeight());
final Rectangle bounds = InternalDecorator.this.getBounds();
if (anchor == ToolWindowAnchor.TOP) {
if (myLastPoint.y < DIVIDER_WIDTH) {
myLastPoint.y = DIVIDER_WIDTH;
}
InternalDecorator.this.setBounds(0, 0, bounds.width, myLastPoint.y);
}
else if (anchor == ToolWindowAnchor.LEFT) {
if (myLastPoint.x < DIVIDER_WIDTH) {
myLastPoint.x = DIVIDER_WIDTH;
}
InternalDecorator.this.setBounds(0, 0, myLastPoint.x, bounds.height);
}
else if (anchor == ToolWindowAnchor.BOTTOM) {
if (myLastPoint.y > windowPane.getHeight() - DIVIDER_WIDTH) {
myLastPoint.y = windowPane.getHeight() - DIVIDER_WIDTH;
}
InternalDecorator.this.setBounds(0, myLastPoint.y, bounds.width, windowPane.getHeight() - myLastPoint.y);
}
else if (anchor == ToolWindowAnchor.RIGHT) {
if (myLastPoint.x > windowPane.getWidth() - DIVIDER_WIDTH) {
myLastPoint.x = windowPane.getWidth() - DIVIDER_WIDTH;
}
InternalDecorator.this.setBounds(myLastPoint.x, 0, windowPane.getWidth() - myLastPoint.x, bounds.height);
}
InternalDecorator.this.validate();
e.consume();
}
}
@Override
protected final void processMouseEvent(final MouseEvent e) {
super.processMouseEvent(e);
public Cursor getCursor() {
final boolean isVerticalCursor = myInfo.isDocked() ? myInfo.getAnchor().isSplitVertically() : myInfo.getAnchor().isHorizontal();
switch (e.getID()) {
case MouseEvent.MOUSE_MOVED:
default:
break;
case MouseEvent.MOUSE_ENTERED:
setCursor(
isVerticalCursor ? Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR) : Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
break;
case MouseEvent.MOUSE_EXITED:
if (!myDragging) {
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
break;
case MouseEvent.MOUSE_PRESSED:
setCursor(
isVerticalCursor ? Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR) : Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
break;
case MouseEvent.MOUSE_RELEASED:
myDragging = false;
myLastPoint = null;
break;
case MouseEvent.MOUSE_CLICKED:
break;
}
}
private final class DividerBorder implements Border {
@Override
public final void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
final ToolWindowAnchor anchor = myInfo.getAnchor();
final boolean isVertical = !anchor.isSplitVertically();
final JBColor outer = new JBColor(Color.white, Color.darkGray);
if (isVertical) {
if (anchor == ToolWindowAnchor.TOP) {
g.setColor(outer);
UIUtil.drawLine(g, x, y, x + width - 1, y);
g.setColor(Color.darkGray);
UIUtil.drawLine(g, x, y + height - 1, x + width - 1, y + height - 1);
}
else {
g.setColor(Color.darkGray);
UIUtil.drawLine(g, x, y, x + width - 1, y);
g.setColor(outer);
UIUtil.drawLine(g, x, y + height - 1, x + width - 1, y + height - 1);
}
}
else {
if (anchor == ToolWindowAnchor.LEFT) {
g.setColor(outer);
UIUtil.drawLine(g, x, y, x, y + height - 1);
g.setColor(Color.darkGray);
UIUtil.drawLine(g, x + width - 1, y, x + width - 1, y + height - 1);
}
else {
g.setColor(Color.darkGray);
UIUtil.drawLine(g, x, y, x, y + height - 1);
g.setColor(outer);
UIUtil.drawLine(g, x + width - 1, y, x + width - 1, y + height - 1);
}
}
}
@Override
public final Insets getBorderInsets(final Component c) {
if (c instanceof MyDivider) {
return new Insets(1, 1, 1, 1);
}
return new Insets(0, 0, 0, 0);
}
@Override
public final boolean isBorderOpaque() {
return true;
}
return isVerticalCursor ? Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR) : Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
}
}
@@ -17,6 +17,7 @@ package com.intellij.ui.win;
import com.intellij.ide.impl.ProjectUtil;
import com.intellij.openapi.diff.ApplicationStarterBase;
import org.jetbrains.annotations.Nullable;
/**
@@ -33,7 +34,7 @@ public class RecentProjectApplication extends ApplicationStarterBase {
}
@Override
protected void processCommand(String[] args) throws Exception {
protected void processCommand(String[] args, @Nullable String currentDirectory) throws Exception {
ProjectUtil.openProject(args[1], null, false);
}
}
@@ -132,7 +132,12 @@ public final class SourceMapDecoder {
if (reader.peek() != JsonToken.END_ARRAY) {
sourcesContent = new SmartList<String>();
do {
sourcesContent.add(StringUtilRt.convertLineSeparators(reader.nextString()));
if (reader.peek() == JsonToken.STRING) {
sourcesContent.add(StringUtilRt.convertLineSeparators(reader.nextString()));
}
else {
reader.skipValue();
}
}
while (reader.hasNext());
}
@@ -430,4 +435,4 @@ public final class SourceMapDecoder {
return MAPPING_COMPARATOR_BY_GENERATED_POSITION;
}
}
}
}
@@ -27,10 +27,7 @@ import com.intellij.execution.testframework.Printable;
import com.intellij.execution.testframework.Printer;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.diff.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.LocalFileSystem;
@@ -93,12 +90,20 @@ public class DiffHyperlink implements Printable {
@Override
public void customize(DiffToolbar toolbar) {
toolbar.addAction(new NextPrevAction("Compare Previous Failure", AllIcons.Actions.Prevfile, chain) {
{
registerCustomShortcutSet(ActionManager.getInstance().getAction("PreviousTab").getShortcutSet(), null);
}
@Override
protected AbstractTestProxy.AssertEqualsMultiDiffViewProvider getNextId() {
return chain.getPrevious();
}
});
toolbar.addAction(new NextPrevAction("Compare Next Failure", AllIcons.Actions.Nextfile, chain) {
{
registerCustomShortcutSet(ActionManager.getInstance().getAction("NextTab").getShortcutSet(), null);
}
@Override
protected AbstractTestProxy.AssertEqualsMultiDiffViewProvider getNextId() {
return chain.getNext();
@@ -45,7 +45,6 @@ public class PathManager {
@NonNls public static final String PROPERTY_HOME_PATH = "idea.home.path";
@NonNls public static final String PROPERTY_LOG_PATH = "idea.log.path";
@NonNls public static final String PROPERTY_PATHS_SELECTOR = "idea.paths.selector";
@NonNls public static final String PROPERTY_ORIGINAL_WORKING_DIR = "original.working.dir";
@NonNls public static final String DEFAULT_OPTIONS_FILE_NAME = "other";
@NonNls private static final String LIB_FOLDER = "lib";
@@ -253,11 +252,6 @@ public class PathManager {
// misc stuff
@Nullable
public static String getOriginalWorkingDir() {
return System.getProperty(PROPERTY_ORIGINAL_WORKING_DIR);
}
/**
* Attempts to detect classpath entry which contains given resource.
*/
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
*/
package com.intellij.xdebugger.impl.frame;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
@@ -27,7 +29,9 @@ import com.intellij.util.ui.UIUtil;
import com.intellij.xdebugger.XDebuggerBundle;
import com.intellij.xdebugger.XSourcePosition;
import com.intellij.xdebugger.frame.XStackFrame;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
@@ -78,7 +82,7 @@ public class XDebuggerFramesList extends DebuggerFramesList {
}
@Override
public int getSourceActions(JComponent c) {
public int getSourceActions(@NotNull JComponent c) {
return COPY;
}
};
@@ -90,6 +94,17 @@ public class XDebuggerFramesList extends DebuggerFramesList {
doInit();
setTransferHandler(DEFAULT_TRANSFER_HANDLER);
setDataProvider(new DataProvider() {
@Nullable
@Override
public Object getData(@NonNls String dataId) {
if (CommonDataKeys.VIRTUAL_FILE.is(dataId) && mySelectedFrame != null) {
XSourcePosition position = mySelectedFrame.getSourcePosition();
return position != null ? position.getFile() : null;
}
return null;
}
});
}
@Override
@@ -22,6 +22,7 @@ import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Couple;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vfs.VfsUtil;
import git4idea.GitCommit;
import git4idea.GitExecutionException;
import git4idea.GitPlatformFacade;
@@ -67,9 +68,9 @@ public final class GitBranchWorker {
}
public void createNewTag(@NotNull final String name, @NotNull final String reference, @NotNull final List<GitRepository> repositories) {
updateInfo(repositories);
for (GitRepository repository : repositories) {
myGit.createNewTag(repository, name, null, reference);
VfsUtil.markDirtyAndRefresh(true, true, false, repository.getGitDir());
}
}
@@ -15,12 +15,14 @@
*/
package git4idea.checkin;
import com.intellij.CommonBundle;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Couple;
@@ -281,7 +283,7 @@ public class GitCheckinHandlerFactory extends VcsCheckinHandlerFactory {
private ReturnResult warnAboutDetachedHeadIfNeeded() {
// Warning: commit on a detached HEAD
DetachedRoot detachedRoot = getDetachedRoot();
if (detachedRoot == null) {
if (detachedRoot == null || !GitVcsSettings.getInstance(myProject).warnAboutDetachedHead()) {
return ReturnResult.COMMIT;
}
@@ -303,10 +305,38 @@ public class GitCheckinHandlerFactory extends VcsCheckinHandlerFactory {
readMore("http://gitolite.com/detached-head.html", "Read more about detached HEAD");
}
final int choice = Messages.showOkCancelDialog(myPanel.getComponent(), XmlStringUtil.wrapInHtml(message), title,
"Cancel", "Commit",
Messages.getWarningIcon());
if (choice != Messages.OK) {
DialogWrapper.DoNotAskOption dontAskAgain = new DialogWrapper.DoNotAskOption() {
@Override
public boolean isToBeShown() {
return true;
}
@Override
public void setToBeShown(boolean toBeShown, int exitCode) {
if (exitCode == Messages.OK) {
GitVcsSettings.getInstance(myProject).setWarnAboutDetachedHead(toBeShown);
}
}
@Override
public boolean canBeHidden() {
return true;
}
@Override
public boolean shouldSaveOptionsOnCancel() {
return false;
}
@NotNull
@Override
public String getDoNotShowMessage() {
return "Don't warn again";
}
};
int choice = Messages.showOkCancelDialog(myProject, XmlStringUtil.wrapInHtml(message), title, "Commit",
CommonBundle.getCancelButtonText(), Messages.getWarningIcon(), dontAskAgain);
if (choice == Messages.OK) {
return ReturnResult.COMMIT;
} else {
return ReturnResult.CLOSE_WINDOW;
@@ -91,7 +91,7 @@
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="4d15a" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="4d15a" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -134,6 +134,15 @@
<text value="Warn if &amp;CRLF line separators are about to be committed"/>
</properties>
</component>
<component id="29d5c" class="javax.swing.JCheckBox" binding="myWarnAboutDetachedHead">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="true"/>
<text value="Warn when committing in detached HEAD or during rebase"/>
</properties>
</component>
</children>
</grid>
</children>
@@ -51,6 +51,7 @@ public class GitVcsPanel {
private JBCheckBox mySyncBranchControl;
private JCheckBox myAutoCommitOnCherryPick;
private JBCheckBox myWarnAboutCrlf;
private JCheckBox myWarnAboutDetachedHead;
public GitVcsPanel(@NotNull Project project) {
myVcs = GitVcs.getInstance(project);
@@ -121,6 +122,7 @@ public class GitVcsPanel {
mySyncBranchControl.setSelected(settings.getSyncSetting() == DvcsBranchSync.SYNC);
myAutoCommitOnCherryPick.setSelected(settings.isAutoCommitOnCherryPick());
myWarnAboutCrlf.setSelected(settings.warnAboutCrlf());
myWarnAboutDetachedHead.setSelected(settings.warnAboutDetachedHead());
}
/**
@@ -134,7 +136,8 @@ public class GitVcsPanel {
!settings.autoUpdateIfPushRejected() == myAutoUpdateIfPushRejected.isSelected() ||
((settings.getSyncSetting() == DvcsBranchSync.SYNC) != mySyncBranchControl.isSelected() ||
settings.isAutoCommitOnCherryPick() != myAutoCommitOnCherryPick.isSelected() ||
settings.warnAboutCrlf() != myWarnAboutCrlf.isSelected());
settings.warnAboutCrlf() != myWarnAboutCrlf.isSelected() ||
settings.warnAboutDetachedHead() != myWarnAboutDetachedHead.isSelected());
}
/**
@@ -153,6 +156,7 @@ public class GitVcsPanel {
settings.setSyncSetting(mySyncBranchControl.isSelected() ? DvcsBranchSync.SYNC : DvcsBranchSync.DONT);
settings.setAutoCommitOnCherryPick(myAutoCommitOnCherryPick.isSelected());
settings.setWarnAboutCrlf(myWarnAboutCrlf.isSelected());
settings.setWarnAboutDetachedHead(myWarnAboutDetachedHead.isSelected());
}
}
@@ -66,6 +66,7 @@ public class GitVcsSettings implements PersistentStateComponent<GitVcsSettings.S
public String RECENT_COMMON_BRANCH = null;
public boolean AUTO_COMMIT_ON_CHERRY_PICK = false;
public boolean WARN_ABOUT_CRLF = true;
public boolean WARN_ABOUT_DETACHED_HEAD = true;
public GitResetMode RESET_MODE = null;
}
@@ -183,6 +184,14 @@ public class GitVcsSettings implements PersistentStateComponent<GitVcsSettings.S
myState.WARN_ABOUT_CRLF = warn;
}
public boolean warnAboutDetachedHead() {
return myState.WARN_ABOUT_DETACHED_HEAD;
}
public void setWarnAboutDetachedHead(boolean warn) {
myState.WARN_ABOUT_DETACHED_HEAD = warn;
}
@Nullable
public GitResetMode getResetMode() {
return myState.RESET_MODE;
@@ -45,6 +45,7 @@ public class GitRepositoryFiles {
public static final String PACKED_REFS = "packed-refs";
public static final String REFS_HEADS = "refs/heads";
public static final String REFS_REMOTES = "refs/remotes";
public static final String REFS_TAGS = "refs/tags";
public static final String SQUASH_MSG = "SQUASH_MSG";
public static final String GIT_HEAD = DOT_GIT + slash(HEAD);
@@ -64,6 +65,7 @@ public class GitRepositoryFiles {
private final String myPackedRefsPath;
private final String myRefsHeadsDirPath;
private final String myRefsRemotesDirPath;
private final String myRefsTagsPath;
private final String myCommitMessagePath;
private final String myExcludePath;
@@ -85,6 +87,7 @@ public class GitRepositoryFiles {
myRebaseMergePath = gitDirPath + slash(REBASE_MERGE);
myPackedRefsPath = gitDirPath + slash(PACKED_REFS);
myRefsHeadsDirPath = gitDirPath + slash(REFS_HEADS);
myRefsTagsPath = gitDirPath + slash(REFS_TAGS);
myRefsRemotesDirPath = gitDirPath + slash(REFS_REMOTES);
myExcludePath = gitDirPath + slash(INFO_EXCLUDE);
}
@@ -99,19 +102,24 @@ public class GitRepositoryFiles {
*/
@NotNull
static Collection<String> getSubDirRelativePaths() {
return Arrays.asList(slash(REFS_HEADS), slash(REFS_REMOTES), slash(INFO));
return Arrays.asList(slash(REFS_HEADS), slash(REFS_REMOTES), slash(REFS_TAGS), slash(INFO));
}
@NotNull
String getRefsHeadsPath() {
return myRefsHeadsDirPath;
}
@NotNull
String getRefsRemotesPath() {
return myRefsRemotesDirPath;
}
@NotNull
String getRefsTagsPath() {
return myRefsTagsPath;
}
/**
* {@code .git/config}
*/
@@ -147,6 +155,13 @@ public class GitRepositoryFiles {
return filePath.startsWith(myRefsRemotesDirPath);
}
/**
* .git/refs/tags/*
*/
public boolean isTagFile(@NotNull String path) {
return path.startsWith(myRefsTagsPath);
}
/**
* .git/rebase-merge or .git/rebase-apply
*/
@@ -34,19 +34,21 @@ import java.util.List;
/**
* Listens to .git service files changes and updates {@link GitRepository} when needed.
* @author Kirill Likhodedov
*/
final class GitRepositoryUpdater implements Disposable, BulkFileListener {
@NotNull private final GitRepository myRepository;
@NotNull private final GitRepositoryFiles myRepositoryFiles;
@Nullable private final MessageBusConnection myMessageBusConnection;
@NotNull private final QueueProcessor<Object> myUpdateQueue;
@NotNull private final Object DUMMY_UPDATE_OBJECT = new Object();
@Nullable private final VirtualFile myRemotesDir;
@Nullable private final VirtualFile myHeadsDir;
@Nullable private final VirtualFile myTagsDir;
@Nullable private final LocalFileSystem.WatchRequest myWatchRequest;
GitRepositoryUpdater(@NotNull GitRepository repository) {
myRepository = repository;
VirtualFile gitDir = repository.getGitDir();
myWatchRequest = LocalFileSystem.getInstance().addRootToWatch(gitDir.getPath(), true);
@@ -54,6 +56,7 @@ final class GitRepositoryUpdater implements Disposable, BulkFileListener {
RepositoryUtil.visitVcsDirVfs(gitDir, GitRepositoryFiles.getSubDirRelativePaths());
myHeadsDir = VcsUtil.getVirtualFile(myRepositoryFiles.getRefsHeadsPath());
myRemotesDir = VcsUtil.getVirtualFile(myRepositoryFiles.getRefsRemotesPath());
myTagsDir = VcsUtil.getVirtualFile(myRepositoryFiles.getRefsTagsPath());
Project project = repository.getProject();
myUpdateQueue = new QueueProcessor<Object>(new RepositoryUtil.Updater(repository), project.getDisposed());
@@ -66,8 +69,6 @@ final class GitRepositoryUpdater implements Disposable, BulkFileListener {
}
}
@Override
public void dispose() {
if (myWatchRequest != null) {
@@ -92,19 +93,16 @@ final class GitRepositoryUpdater implements Disposable, BulkFileListener {
boolean packedRefsChanged = false;
boolean rebaseFileChanged = false;
boolean mergeFileChanged = false;
boolean tagChanged = false;
for (VFileEvent event : events) {
String filePath = event.getPath();
if (filePath == null) {
continue;
}
filePath = GitFileUtils.stripFileProtocolPrefix(filePath);
String filePath = GitFileUtils.stripFileProtocolPrefix(event.getPath());
if (myRepositoryFiles.isConfigFile(filePath)) {
configChanged = true;
} else if (myRepositoryFiles.isHeadFile(filePath)) {
headChanged = true;
} else if (myRepositoryFiles.isBranchFile(filePath)) {
// it is also possible, that a local branch with complex name ("folder/branch") was created => the folder also to be watched.
branchFileChanged = true;
branchFileChanged = true;
RepositoryUtil.visitAllChildrenRecursively(myHeadsDir);
} else if (myRepositoryFiles.isRemoteBranchFile(filePath)) {
// it is possible, that a branch from a new remote was fetch => we need to add new remote folder to the VFS
@@ -116,12 +114,18 @@ final class GitRepositoryUpdater implements Disposable, BulkFileListener {
rebaseFileChanged = true;
} else if (myRepositoryFiles.isMergeFile(filePath)) {
mergeFileChanged = true;
} else if (myRepositoryFiles.isTagFile(filePath)) {
RepositoryUtil.visitAllChildrenRecursively(myTagsDir);
tagChanged = true;
}
}
if (headChanged || configChanged || branchFileChanged || packedRefsChanged || rebaseFileChanged || mergeFileChanged) {
myUpdateQueue.add(DUMMY_UPDATE_OBJECT);
}
else if (tagChanged) {
myRepository.getProject().getMessageBus().syncPublisher(GitRepository.GIT_REPO_CHANGE).repositoryChanged(myRepository);
}
}
}
@@ -1,125 +0,0 @@
package git4idea.log;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.newvfs.impl.NullVirtualFile;
import com.intellij.vcs.log.*;
import com.intellij.vcs.log.impl.VcsRefImpl;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import java.util.Collection;
import java.util.List;
import static junit.framework.Assert.assertEquals;
/**
* @author erokhins
*/
public class RefParserTest {
public String toStr(VcsRef ref) {
return String.format("%s TAG %s", ref.getCommitHash().asString(), ref.getName());
}
public void runTest(String inputStr, String outStr) {
List<VcsRef> refs = new RefParser(new TestLogObjectsFactory()).parseCommitRefs(inputStr, NullVirtualFile.INSTANCE);
StringBuilder s = new StringBuilder();
for (VcsRef ref : refs) {
if (s.length() > 0) {
s.append("\n");
}
s.append(toStr(ref));
}
assertEquals(outStr, s.toString());
}
@Test
public void tagTest() {
runTest("22762ebf7203f6a2888425a3207d2ddc63085dd7 (tag: refs/tags/v3.6-rc1, refs/heads/br)",
"22762ebf7203f6a2888425a3207d2ddc63085dd7 TAG v3.6-rc1");
}
@Test
public void severalRefsTest() {
runTest("f85125c (refs/tags/v3.6-rc1, HEAD)", "f85125c TAG v3.6-rc1");
}
@Test
public void severalRefsTest2() {
runTest("ed7a0d14da090ea256d68a06c6f8dd7311de192e (refs/tags/category/v3.6-rc1, HEAD, refs/remotes/origin/graph_fix)",
"ed7a0d14da090ea256d68a06c6f8dd7311de192e TAG category/v3.6-rc1");
}
@Test
public void severalRefsTest3() {
runTest("ed7a0d14da090ea256d68a06c6f8dd7311de192e (tag: refs/tags/web/130.1599, tag: refs/tags/ruby/130.1597, " +
"tag: refs/tags/py/130.1598, " +
"tag: refs/tags/php/130.1596, tag: refs/tags/idea/130.1601, tag: refs/tags/app/130.1600)",
"ed7a0d14da090ea256d68a06c6f8dd7311de192e TAG web/130.1599\n" +
"ed7a0d14da090ea256d68a06c6f8dd7311de192e TAG ruby/130.1597\n" +
"ed7a0d14da090ea256d68a06c6f8dd7311de192e TAG py/130.1598\n" +
"ed7a0d14da090ea256d68a06c6f8dd7311de192e TAG php/130.1596\n" +
"ed7a0d14da090ea256d68a06c6f8dd7311de192e TAG idea/130.1601\n" +
"ed7a0d14da090ea256d68a06c6f8dd7311de192e TAG app/130.1600"
);
}
@Test
public void noTagName() {
runTest("787ec72f340d740433ba068d4d58a6e58f6226bf", "");
}
private static class TestLogObjectsFactory implements VcsLogObjectsFactory {
@NotNull
@Override
public Hash createHash(@NotNull String stringHash) {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public TimedVcsCommit createTimedCommit(@NotNull Hash hash, @NotNull List<Hash> parents, long timeStamp) {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public VcsShortCommitDetails createShortDetails(@NotNull Hash hash, @NotNull List<Hash> parents, long timeStamp, VirtualFile root,
@NotNull String subject, @NotNull String authorName, String authorEmail) {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public VcsFullCommitDetails createCommitMetadata(@NotNull Hash hash, @NotNull List<Hash> parents, long time, VirtualFile root,
@NotNull String subject, @NotNull String authorName, @NotNull String authorEmail,
@NotNull String message, @NotNull String committerName, @NotNull String committerEmail,
long authorTime) {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public VcsFullCommitDetails createFullDetails(@NotNull Hash hash, @NotNull List<Hash> parents, long time, VirtualFile root,
@NotNull String subject, @NotNull String authorName, @NotNull String authorEmail,
@NotNull String message, @NotNull String committerName, @NotNull String committerEmail,
long authorTime,
@NotNull ThrowableComputable<Collection<Change>, ? extends Exception> changesGetter) {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public VcsUser createUser(@NotNull String name, @NotNull String email) {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public VcsRef createRef(@NotNull Hash commitHash, @NotNull String name, @NotNull VcsRefType type, @NotNull VirtualFile root) {
return new VcsRefImpl(commitHash, name, type, root);
}
}
}
@@ -1,5 +1,6 @@
package com.jetbrains.python.edu.actions;
import com.intellij.ide.projectView.ProjectView;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.DumbAwareAction;
@@ -12,6 +13,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowId;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.util.ui.tree.TreeUtil;
import com.jetbrains.python.edu.StudyState;
import com.jetbrains.python.edu.course.Lesson;
import com.jetbrains.python.edu.course.Task;
@@ -20,6 +22,7 @@ import com.jetbrains.python.edu.editor.StudyEditor;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.tree.TreePath;
import java.util.Map;
@@ -74,7 +77,11 @@ abstract public class StudyTaskNavigationAction extends DumbAwareAction {
}
}
}
JTree tree = ProjectView.getInstance(project).getCurrentProjectViewPane().getTree();
TreePath path = TreeUtil.getFirstNodePath(tree);
tree.collapsePath(path);
if (shouldBeActive != null) {
ProjectView.getInstance(project).select(shouldBeActive, shouldBeActive, false);
FileEditorManager.getInstance(project).openFile(shouldBeActive, true);
}
ToolWindow runToolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.RUN);
@@ -1,8 +1,10 @@
package com.jetbrains.python.edu.projectView;
import com.intellij.ide.projectView.PresentationData;
import com.intellij.ide.projectView.ProjectView;
import com.intellij.ide.projectView.ViewSettings;
import com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDirectory;
@@ -17,6 +19,7 @@ import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
import java.util.Set;
public class StudyDirectoryNode extends PsiDirectoryNode {
private final PsiDirectory myValue;
@@ -110,4 +113,56 @@ public class StudyDirectoryNode extends PsiDirectoryNode {
data.addText(additionalName, new SimpleTextAttributes(Font.PLAIN, color));
data.setIcon(icon);
}
@Override
public boolean canNavigate() {
return true;
}
@Override
public boolean canNavigateToSource() {
return true;
}
@Override
public void navigate(boolean requestFocus) {
if (myValue.getName().contains(Task.TASK_DIR)) {
TaskFile taskFile = null;
VirtualFile virtualFile = null;
for (PsiElement child : myValue.getChildren()) {
VirtualFile childFile = child.getContainingFile().getVirtualFile();
taskFile = StudyTaskManager.getInstance(myProject).getTaskFile(childFile);
if (taskFile != null) {
virtualFile = childFile;
break;
}
}
if (taskFile != null) {
VirtualFile taskDir = virtualFile.getParent();
Task task = taskFile.getTask();
for (VirtualFile openFile : FileEditorManager.getInstance(myProject).getOpenFiles()) {
FileEditorManager.getInstance(myProject).closeFile(openFile);
}
VirtualFile child = null;
Set<String> fileNames = task.getTaskFiles().keySet();
for (String name : fileNames) {
child = taskDir.findChild(name);
if (child != null) {
FileEditorManager.getInstance(myProject).openFile(child, true);
}
}
if (child != null) {
ProjectView.getInstance(myProject).select(child, child, false);
}
}
}
}
@Override
public boolean expandOnDoubleClick() {
if (myValue.getName().contains(Task.TASK_DIR)) {
return false;
}
return super.expandOnDoubleClick();
}
}
@@ -44,7 +44,7 @@ public class IndexedElementInvocationHandler extends DomInvocationHandler<FixedC
final DomParentStrategy strategy,
final DomManagerImpl manager,
@Nullable ElementStub stub) {
super(description.getType(), strategy, tagName, description, manager, strategy.getXmlElement() != null, stub);
super(description.getType(), strategy, tagName, description, manager, strategy.isPhysical(), stub);
myIndex = index;
}
@@ -80,6 +80,10 @@ public abstract class EmmetParser {
ZenCodingNode mul = parseMul();
ZenCodingToken operationToken = getToken();
if (operationToken == ZenCodingTokens.OPENING_R_BRACKET) {
mul = new MoreOperationNode(notNullNode(mul), parseExpression());
operationToken = getToken();
}
if (!(operationToken instanceof OperationToken)) {
return mul;
}
@@ -132,7 +136,7 @@ public abstract class EmmetParser {
@Nullable
private ZenCodingNode parseMul() {
ZenCodingNode exp = parseExpressionInBraces();
ZenCodingNode exp = parseExpression();
if (exp == null) {
return null;
}
@@ -153,7 +157,7 @@ public abstract class EmmetParser {
}
@Nullable
private ZenCodingNode parseExpressionInBraces() {
private ZenCodingNode parseExpression() {
ZenCodingToken token = getToken();
if (token == ZenCodingTokens.OPENING_R_BRACKET) {
advance();
@@ -202,7 +202,7 @@ public class XmlEmmetParser extends EmmetParser {
int loremWordsCount = DEFAULT_LOREM_LENGTH;
if (matcher.groupCount() > 1) {
String group = matcher.group(2);
loremWordsCount = group.isEmpty() ? DEFAULT_LOREM_LENGTH : Integer.parseInt(group);
loremWordsCount = group == null || group.isEmpty() ? DEFAULT_LOREM_LENGTH : Integer.parseInt(group);
}
final List<Couple<String>> attrList = parseSelectors();
@@ -89,8 +89,12 @@ public class MoreOperationNode extends ZenCodingNode {
}
return result;
}
List<GenerationNode> leftGenNodes = myLeftOperand.expand(numberInIteration, totalIterations, surroundedText, callback, insertSurroundedTextAtTheEnd,
parent);
List<GenerationNode> leftGenNodes = myLeftOperand.expand(numberInIteration, totalIterations, surroundedText, callback, insertSurroundedTextAtTheEnd, parent);
if (leftGenNodes.isEmpty()) {
return myRightOperand.expand(numberInIteration, totalIterations, surroundedText, callback, insertSurroundedTextAtTheEnd, parent);
}
for (GenerationNode leftGenNode : leftGenNodes) {
myRightOperand.expand(numberInIteration,totalIterations , surroundedText, callback, insertSurroundedTextAtTheEnd, leftGenNode);
}
@@ -15,7 +15,6 @@
*/
package com.intellij.xml.refactoring;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
@@ -35,12 +34,6 @@ import java.util.Collection;
*/
public class SchemaPrefixRenameHandler extends VariableInplaceRenameHandler {
@Override
protected boolean isAvailable(PsiElement element, Editor editor, PsiFile file) {
PossiblePrefixReference ref = getReference(file, editor);
return ref != null && ref.resolve() instanceof SchemaPrefix;
}
@Nullable
private static PossiblePrefixReference getReference(PsiFile file, Editor editor) {
if (file != null && editor != null) {
@@ -54,6 +47,12 @@ public class SchemaPrefixRenameHandler extends VariableInplaceRenameHandler {
}
@Override
protected boolean isAvailable(PsiElement element, Editor editor, PsiFile file) {
PossiblePrefixReference ref = getReference(file, editor);
return ref != null && ref.resolve() instanceof SchemaPrefix;
}
@Override
protected VariableInplaceRenamer createRenamer(@NotNull PsiElement elementToRename, Editor editor) {
PossiblePrefixReference reference = getReference(elementToRename.getContainingFile(), editor);
@@ -71,12 +70,6 @@ public class SchemaPrefixRenameHandler extends VariableInplaceRenameHandler {
};
}
}
if (ApplicationManager.getApplication().isUnitTestMode()) {
System.out.println("Reference: " + reference);
if (reference != null) {
System.out.println("Resolved: " + reference.resolve());
}
}
return null;
}
}
@@ -3,22 +3,23 @@ package com.intellij.xml.refactoring;
import com.intellij.lang.refactoring.InlineHandler;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
/**
* @author Eugene.Kudelevsky
*/
public class XmlInlineHandler implements InlineHandler {
@Override
public Settings prepareInlineElement(PsiElement element, Editor editor, boolean invokedOnReference) {
public Settings prepareInlineElement(@NotNull PsiElement element, Editor editor, boolean invokedOnReference) {
return null;
}
@Override
public void removeDefinition(PsiElement element, Settings settings) {
public void removeDefinition(@NotNull PsiElement element, @NotNull Settings settings) {
}
@Override
public Inliner createInliner(PsiElement element, Settings settings) {
public Inliner createInliner(@NotNull PsiElement element, @NotNull Settings settings) {
return null;
}
}