diff --git a/.idea/inspectionProfiles/idea_default.xml b/.idea/inspectionProfiles/idea_default.xml index 926c4b8e2b99..af758032d20b 100644 --- a/.idea/inspectionProfiles/idea_default.xml +++ b/.idea/inspectionProfiles/idea_default.xml @@ -258,7 +258,7 @@ - diff --git a/bin/scripts/unix/idea.sh b/bin/scripts/unix/idea.sh index b8f92069856c..934b38612f70 100755 --- a/bin/scripts/unix/idea.sh +++ b/bin/scripts/unix/idea.sh @@ -194,7 +194,7 @@ LD_LIBRARY_PATH="$IDE_BIN_HOME:$LD_LIBRARY_PATH" "$JAVA_BIN" \ EC=$? test $EC -ne 88 && exit $EC if [ -x "$HOME/.@@system_selector@@/restart/restarter.sh" ]; then - $HOME/.@@system_selector@@/restart/restarter.sh + "$HOME/.@@system_selector@@/restart/restarter.sh" "$RM" -f "$HOME/.@@system_selector@@/restart/restarter.sh" fi exec "$0" "$@" diff --git a/build.xml b/build.xml index ab62c1eb1932..dd8c90d39069 100644 --- a/build.xml +++ b/build.xml @@ -16,8 +16,7 @@ - + @@ -42,15 +41,15 @@ - - - - - + + + + + - - - + + + diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java index 6e861e88b7ae..d78a9a07cf1b 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java @@ -158,7 +158,8 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb myDebugProcessDispatcher.addListener(new DebugProcessAdapter() { @Override public void paused(SuspendContext suspendContext) { - myThreadBlockedMonitor.stopWatching(suspendContext.getThread()); + myThreadBlockedMonitor.stopWatching( + suspendContext.getSuspendPolicy() != EventRequest.SUSPEND_ALL ? suspendContext.getThread() : null); } }); } @@ -2143,6 +2144,7 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb // } //} + @NotNull public DebuggerContextImpl getDebuggerContext() { return mySession.getContextManager().getContext(); } diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/ThreadBlockedMonitor.java b/java/debugger/impl/src/com/intellij/debugger/engine/ThreadBlockedMonitor.java index 7475e3bbd6da..43b0dd2cfc20 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/ThreadBlockedMonitor.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/ThreadBlockedMonitor.java @@ -24,6 +24,7 @@ import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; import com.intellij.notification.NotificationType; import com.intellij.openapi.Disposable; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.registry.Registry; import com.intellij.util.Alarm; import com.intellij.util.SingleAlarm; @@ -42,6 +43,8 @@ import java.util.HashSet; * @author egor */ public class ThreadBlockedMonitor { + private static final Logger LOG = Logger.getInstance(ThreadBlockedMonitor.class); + private final Collection myWatchedThreads = new HashSet(); private final SingleAlarm myAlarm; @@ -71,14 +74,17 @@ public class ThreadBlockedMonitor { if (thread != null) { myWatchedThreads.remove(thread); } + else { + myWatchedThreads.clear(); + } if (myWatchedThreads.isEmpty()) { myAlarm.cancel(); } } - private void onThreadBlocked(@NotNull final ThreadReference blockedThread, - @NotNull final ThreadReference blockingThread, - final DebugProcessImpl process) { + private static void onThreadBlocked(@NotNull final ThreadReference blockedThread, + @NotNull final ThreadReference blockingThread, + final DebugProcessImpl process) { XDebugSessionImpl.NOTIFICATION_GROUP.createNotification( DebuggerBundle.message("status.thread.blocked.by", blockedThread.name(), blockingThread.name()), DebuggerBundle.message("status.thread.blocked.by.resume", blockingThread.name()), @@ -101,6 +107,11 @@ public class ThreadBlockedMonitor { }).notify(process.getProject()); } + private ThreadReference getCurrentThread() { + ThreadReferenceProxyImpl threadProxy = myProcess.getDebuggerContext().getThreadProxy(); + return threadProxy != null ? threadProxy.getThreadReference() : null; + } + private void checkBlockingThread() { myProcess.getManagerThread().schedule(new DebuggerCommandImpl() { @Override @@ -115,14 +126,16 @@ public class ThreadBlockedMonitor { vmProxy.canGetCurrentContendedMonitor() ? thread.getThreadReference().currentContendedMonitor() : null; if (waitedMonitor != null && vmProxy.canGetMonitorInfo()) { ThreadReference blockingThread = waitedMonitor.owningThread(); - if (blockingThread != null) { + if (blockingThread != null + && blockingThread.suspendCount() > 1 + && getCurrentThread() != blockingThread) { onThreadBlocked(thread.getThreadReference(), blockingThread, myProcess); } } } } catch (IncompatibleThreadStateException e) { - e.printStackTrace(); + LOG.info(e); } finally { vmProxy.getVirtualMachine().resume(); diff --git a/java/debugger/impl/src/com/intellij/debugger/jdi/StackFrameProxyImpl.java b/java/debugger/impl/src/com/intellij/debugger/jdi/StackFrameProxyImpl.java index c75a41f1f613..81000f4b7eb8 100644 --- a/java/debugger/impl/src/com/intellij/debugger/jdi/StackFrameProxyImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/jdi/StackFrameProxyImpl.java @@ -306,7 +306,14 @@ public class StackFrameProxyImpl extends JdiProxy implements StackFrameProxy { InvalidStackFrameException error = null; for (int attempt = 0; attempt < 2; attempt++) { try { - return getAllValues().get(localVariable.getVariable()); + Map values = getAllValues(); + LocalVariable variable = localVariable.getVariable(); + if (values.containsKey(variable)) { + return values.get(variable); + } + else { // try direct get + return getStackFrame().getValue(variable); + } } catch (InvalidStackFrameException e) { error = e; @@ -359,6 +366,14 @@ public class StackFrameProxyImpl extends JdiProxy implements StackFrameProxy { catch (AbsentInformationException e) { throw EvaluateExceptionUtil.createEvaluateException(e); } + catch (InternalException e) { + // extra logging for IDEA-141270 + if (e.errorCode() == 35 || e.errorCode() == 101) { + LOG.info(e); + myAllValues = Collections.emptyMap(); + } + else throw e; + } } return myAllValues; } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/StepIntoBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/StepIntoBreakpoint.java index 20f61dd9b9ee..9d1933d9b424 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/StepIntoBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/StepIntoBreakpoint.java @@ -25,15 +25,14 @@ import com.intellij.debugger.engine.requests.RequestManagerImpl; import com.intellij.debugger.impl.DebuggerUtilsEx; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; +import com.intellij.util.containers.MultiMap; import com.sun.jdi.*; import com.sun.jdi.request.BreakpointRequest; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Arrays; -import java.util.HashSet; import java.util.List; -import java.util.Set; /** * @author Eugene Zhuravlev @@ -67,29 +66,29 @@ public class StepIntoBreakpoint extends RunToCursorBreakpoint { } if (!locations.isEmpty()) { - final Set methods = new HashSet(); + MultiMap methods = new MultiMap(); for (Location loc : locations) { if (acceptLocation(debugProcess, classType, loc)) { - methods.add(loc.method()); + methods.putValue(loc.method(), loc); } } Location location = null; final int methodsFound = methods.size(); if (methodsFound == 1) { - location = methods.iterator().next().location(); + location = methods.values().iterator().next(); } else { if (myFilter instanceof LambdaMethodFilter) { final LambdaMethodFilter lambdaFilter = (LambdaMethodFilter)myFilter; if (lambdaFilter.getLambdaOrdinal() < methodsFound) { - final Method[] candidates = methods.toArray(new Method[methodsFound]); + Method[] candidates = methods.keySet().toArray(new Method[methodsFound]); Arrays.sort(candidates, DebuggerUtilsEx.LAMBDA_ORDINAL_COMPARATOR); - location = candidates[lambdaFilter.getLambdaOrdinal()].location(); + location = methods.get(candidates[lambdaFilter.getLambdaOrdinal()]).iterator().next(); } } else { if (methodsFound > 0) { - location = methods.iterator().next().location(); + location = methods.values().iterator().next(); } } } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/GraphicsObjectRenderer.java b/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/GraphicsObjectRenderer.java index 1676cf2736c3..b3b257a5824f 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/GraphicsObjectRenderer.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/GraphicsObjectRenderer.java @@ -45,9 +45,15 @@ public class GraphicsObjectRenderer extends ToStringBasedRenderer implements Ful Field surfaceField = ((ClassType)value.type()).fieldByName("surfaceData"); if (surfaceField == null) return null; ObjectReference surfaceDataValue = (ObjectReference)value.getValue(surfaceField); - final Field bufImgField = ((ClassType)surfaceDataValue.type()).fieldByName("bufImg"); - if (bufImgField == null) return null; - final Value bufImgValue = surfaceDataValue.getValue(bufImgField); + if (surfaceDataValue == null) return null; + + Field imgField = ((ReferenceType)surfaceDataValue.type()).fieldByName("bufImg"); // BufImgSurfaceData + if (imgField == null) { + imgField = ((ReferenceType)surfaceDataValue.type()).fieldByName("offscreenImage"); // CGLSurfaceData + } + if (imgField == null) return null; + + final Value bufImgValue = surfaceDataValue.getValue(imgField); Type type = bufImgValue.type(); if (!(type instanceof ReferenceType) || !DebuggerUtils.instanceOf(type, "java.awt.Image")) { return null; diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/IconObjectRenderer.java b/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/IconObjectRenderer.java index 51cb8b3c0fe7..c5be60cf00a2 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/IconObjectRenderer.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/IconObjectRenderer.java @@ -16,10 +16,12 @@ package com.intellij.debugger.ui.tree.render; import com.intellij.debugger.DebuggerBundle; +import com.intellij.debugger.engine.DebugProcessImpl; import com.intellij.debugger.engine.FullValueEvaluatorProvider; import com.intellij.debugger.engine.evaluation.EvaluateException; import com.intellij.debugger.engine.evaluation.EvaluationContext; import com.intellij.debugger.engine.evaluation.EvaluationContextImpl; +import com.intellij.debugger.engine.events.SuspendContextCommandImpl; import com.intellij.debugger.impl.DebuggerUtilsImpl; import com.intellij.debugger.settings.NodeRendererSettings; import com.intellij.debugger.ui.impl.watch.ValueDescriptorImpl; @@ -42,15 +44,27 @@ class IconObjectRenderer extends ToStringBasedRenderer implements FullValueEvalu } @Override - public Icon calcValueIcon(ValueDescriptor descriptor, EvaluationContext evaluationContext, DescriptorLabelListener listener) + public Icon calcValueIcon(final ValueDescriptor descriptor, final EvaluationContext evaluationContext, final DescriptorLabelListener listener) throws EvaluateException { - String getterName = AllIcons.Debugger.Value.getIconHeight() <= 16 ? "iconToBytesPreviewNormal" : "iconToBytesPreviewRetina"; - if (!Registry.is("debugger.auto.fetch.icons") || DebuggerUtilsImpl.isRemote(evaluationContext.getDebugProcess())) { - return null; // do not auto load icon for remote - } - else { - return ImageObjectRenderer.getIcon(evaluationContext, descriptor.getValue(), getterName); - } + EvaluationContextImpl evalContext = ((EvaluationContextImpl)evaluationContext); + DebugProcessImpl debugProcess = evalContext.getDebugProcess(); + + if (!Registry.is("debugger.auto.fetch.icons") || DebuggerUtilsImpl.isRemote(debugProcess)) return null; + + debugProcess.getManagerThread().schedule(new SuspendContextCommandImpl(evalContext.getSuspendContext()) { + @Override + public Priority getPriority() { + return Priority.LOW; + } + + @Override + public void contextAction() throws Exception { + String getterName = AllIcons.Debugger.Value.getIconHeight() <= 16 ? "iconToBytesPreviewNormal" : "iconToBytesPreviewRetina"; + descriptor.setValueIcon(ImageObjectRenderer.getIcon(evaluationContext, descriptor.getValue(), getterName)); + listener.labelChanged(); + } + }); + return null; } @Nullable diff --git a/java/execution/impl/src/com/intellij/execution/impl/JavaScratchCompilationSupport.java b/java/execution/impl/src/com/intellij/execution/impl/JavaScratchCompilationSupport.java index 00327b870eca..1f8d401b6693 100644 --- a/java/execution/impl/src/com/intellij/execution/impl/JavaScratchCompilationSupport.java +++ b/java/execution/impl/src/com/intellij/execution/impl/JavaScratchCompilationSupport.java @@ -28,6 +28,8 @@ import com.intellij.openapi.projectRoots.JavaSdkType; import com.intellij.openapi.projectRoots.JavaSdkVersion; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.ModuleRootManager; +import com.intellij.openapi.roots.OrderEnumerator; +import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; @@ -35,6 +37,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.psi.*; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; @@ -62,19 +65,21 @@ public class JavaScratchCompilationSupport implements ProjectComponent, CompileT if (scratchUrl == null) { return true; } - final Module configModule = ((ModuleBasedConfiguration)configuration).getConfigurationModule().getModule(); - if (configModule == null) { - context.addMessage(CompilerMessageCategory.ERROR, "A module must be specified for the run configuration", scratchUrl, -1, -1); - return true; - } - final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(configModule); - final Sdk targetSdk = moduleRootManager.getSdk(); + @Nullable + final Module module = ((ModuleBasedConfiguration)configuration).getConfigurationModule().getModule(); + final Sdk targetSdk = module != null? ModuleRootManager.getInstance(module).getSdk() : ProjectRootManager.getInstance(project).getProjectSdk(); if (targetSdk == null) { - context.addMessage(CompilerMessageCategory.ERROR, "Cannot find associated SDK for run configuration module \"" + configModule.getName() + "\".\nPlease check project settings.", scratchUrl, -1, -1); + final String message = module != null? + "Cannot find associated SDK for run configuration module \"" + module.getName() + "\".\nPlease check project settings." : + "Cannot find associated project SDK for the run configuration.\nPlease check project settings."; + context.addMessage(CompilerMessageCategory.ERROR, message, scratchUrl, -1, -1); return true; } if (!(targetSdk.getSdkType() instanceof JavaSdkType)) { - context.addMessage(CompilerMessageCategory.ERROR, "Expected Java SDK for run configuration module \"" + configModule.getName() + "\".\nPlease check project settings.", scratchUrl, -1, -1); + final String message = module != null? + "Expected Java SDK for run configuration module \"" + module.getName() + "\".\nPlease check project settings." : + "Expected Java SDK for project \"" + project.getName() + "\".\nPlease check project settings."; + context.addMessage(CompilerMessageCategory.ERROR, message, scratchUrl, -1, -1); return true; } @@ -131,11 +136,24 @@ public class JavaScratchCompilationSupport implements ProjectComponent, CompileT final Collection files = Collections.singleton(srcFile); final Set cp = new LinkedHashSet(); - for (String s : moduleRootManager.orderEntries().compileOnly().recursively().exportedOnly().withoutSdk().getPathsList().getPathList()) { + final List platformCp = new ArrayList(); + + final Computable orderEnumerator = module != null ? new Computable() { + @Override + public OrderEnumerator compute() { + return ModuleRootManager.getInstance(module).orderEntries(); + } + } : new Computable() { + @Override + public OrderEnumerator compute() { + return ProjectRootManager.getInstance(project).orderEntries(); + } + }; + + for (String s : orderEnumerator.compute().compileOnly().recursively().exportedOnly().withoutSdk().getPathsList().getPathList()) { cp.add(new File(s)); } - final List platformCp = new ArrayList(); - for (String s : moduleRootManager.orderEntries().compileOnly().sdkOnly().getPathsList().getPathList()) { + for (String s : orderEnumerator.compute().compileOnly().sdkOnly().getPathsList().getPathList()) { platformCp.add(new File(s)); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java index 158330edb020..76f33318392c 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java @@ -641,6 +641,10 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel { for (int row = 0; row < myModel.getRowCount(); row++) { final OrderEntry orderEntry = getItemAt(row).getEntry(); if (orderEntry != null && entry.getPresentableName().equals(orderEntry.getPresentableName())) { + if (orderEntry instanceof ExportableOrderEntry && entry instanceof ExportableOrderEntry && + ((ExportableOrderEntry)entry).getScope() != ((ExportableOrderEntry)orderEntry).getScope()) { + continue; + } myEntryTable.getSelectionModel().setSelectionInterval(row, row); TableUtil.scrollSelectionToVisible(myEntryTable); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ChangeLibraryLevelAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ChangeLibraryLevelAction.java index 9cd1fa67c5b4..979b9db7ded1 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ChangeLibraryLevelAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ChangeLibraryLevelAction.java @@ -17,6 +17,8 @@ package com.intellij.openapi.roots.ui.configuration.projectRoot; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.project.DumbModePermission; +import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.impl.libraries.LibraryEx; import com.intellij.openapi.roots.libraries.Library; @@ -56,18 +58,24 @@ public class ChangeLibraryLevelAction extends ChangeLibraryLevelActionBase { final LibraryProjectStructureElement libraryElement = (LibraryProjectStructureElement)selectedElement; final LibraryEx oldLibrary = (LibraryEx)context.getLibrary(libraryElement.getLibrary().getName(), mySourceConfigurable.getLevel()); LOG.assertTrue(oldLibrary != null); - final Library newLibrary = doCopy(oldLibrary); - if (newLibrary == null) return; - final Collection usages = context.getDaemonAnalyzer().getUsages(libraryElement); - for (ProjectStructureElementUsage usage : usages) { - usage.replaceElement(new LibraryProjectStructureElement(context, newLibrary)); - } + DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, new Runnable() { + @Override + public void run() { + final Library newLibrary = doCopy(oldLibrary); + if (newLibrary == null) return; - if (!myCopy) { - mySourceConfigurable.removeLibrary(libraryElement); - } - ProjectStructureConfigurable.getInstance(myProject).selectProjectOrGlobalLibrary(newLibrary, true); + final Collection usages = context.getDaemonAnalyzer().getUsages(libraryElement); + for (ProjectStructureElementUsage usage : usages) { + usage.replaceElement(new LibraryProjectStructureElement(context, newLibrary)); + } + + if (!myCopy) { + mySourceConfigurable.removeLibrary(libraryElement); + } + ProjectStructureConfigurable.getInstance(myProject).selectProjectOrGlobalLibrary(newLibrary, true); + } + }); } @Override diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/LambdaCanBeMethodReferenceInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/LambdaCanBeMethodReferenceInspection.java index ff96f4025ca5..140f672f1a30 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/LambdaCanBeMethodReferenceInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/LambdaCanBeMethodReferenceInspection.java @@ -26,6 +26,7 @@ import com.intellij.psi.*; import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.psi.util.*; import com.intellij.util.ArrayUtil; +import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -413,8 +414,15 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp } final PsiType qualifierExpressionType = qualifierExpression.getType(); - return qualifierExpressionType != null && !TypeConversionUtil.containsWildcards(qualifierExpressionType) - ? qualifierExpressionType.getCanonicalText() : getClassReferenceName(containingClass); + if (qualifierExpressionType != null && !TypeConversionUtil.containsWildcards(qualifierExpressionType)) { + try { + final String canonicalText = qualifierExpressionType.getCanonicalText(); + JavaPsiFacade.getElementFactory(containingClass.getProject()).createExpressionFromText(canonicalText + "::foo", qualifierExpression); + return canonicalText; + } + catch (IncorrectOperationException ignore){} + } + return getClassReferenceName(containingClass); } private static String getClassReferenceName(PsiClass containingClass) { diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java index 2559f4e9f3a5..439d23ccaf1b 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java @@ -1513,12 +1513,12 @@ public class ControlFlowAnalyzer extends JavaElementVisitor { } static List getMethodContracts(@NotNull final PsiMethod method) { - final PsiAnnotation contractAnno = findContractAnnotation(method); - if (contractAnno != null) { - return CachedValuesManager.getCachedValue(contractAnno, new CachedValueProvider>() { - @Nullable - @Override - public Result> compute() { + return CachedValuesManager.getCachedValue(method, new CachedValueProvider>() { + @Nullable + @Override + public Result> compute() { + final PsiAnnotation contractAnno = findContractAnnotation(method); + if (contractAnno != null) { String text = AnnotationUtil.getStringAttributeValue(contractAnno, null); if (text != null) { try { @@ -1534,12 +1534,10 @@ public class ControlFlowAnalyzer extends JavaElementVisitor { catch (Exception ignored) { } } - return Result.create(Collections.emptyList(), contractAnno, method, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT); } - }); - } - - return Collections.emptyList(); + return Result.create(Collections.emptyList(), method, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT); + } + }); } @Nullable diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java index 1939ef31d060..a196cf93eec4 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java @@ -768,7 +768,8 @@ public class JavaCompletionContributor extends CompletionContributor { iterator.advance(); } - if (!iterator.atEnd() && (iterator.getTokenType() == JavaTokenType.LPARENTH)) { + if (!iterator.atEnd() && iterator.getTokenType() == JavaTokenType.LPARENTH && PsiTreeUtil.getParentOfType(ref, PsiExpression.class, PsiClass.class) == null) { + // looks like a method declaration, e.g. StringBuimethodName() inside a class return true; } diff --git a/java/java-impl/src/com/intellij/ide/JavaFileIconPatcher.java b/java/java-impl/src/com/intellij/ide/JavaFileIconPatcher.java index b7d9d56006cd..db7b27e59bd5 100644 --- a/java/java-impl/src/com/intellij/ide/JavaFileIconPatcher.java +++ b/java/java-impl/src/com/intellij/ide/JavaFileIconPatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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,7 +15,7 @@ */ package com.intellij.ide; -import com.intellij.lang.StdLanguages; +import com.intellij.lang.java.JavaLanguage; import com.intellij.openapi.compiler.CompilerManager; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.StdFileTypes; @@ -36,6 +36,7 @@ import javax.swing.*; * @author yole */ public class JavaFileIconPatcher implements FileIconPatcher { + @Override public Icon patchIcon(final Icon baseIcon, final VirtualFile file, final int flags, final Project project) { if (project == null) { return baseIcon; @@ -58,7 +59,7 @@ public class JavaFileIconPatcher implements FileIconPatcher { } PsiFile psiFile = PsiManager.getInstance(project).findFile(file); - if (psiFile instanceof PsiClassOwner && psiFile.getViewProvider().getBaseLanguage() == StdLanguages.JAVA) { + if (psiFile instanceof PsiClassOwner && psiFile.getViewProvider().getBaseLanguage() == JavaLanguage.INSTANCE) { PsiClass[] classes = ((PsiClassOwner)psiFile).getClasses(); if (classes.length > 0) { // prefer icon of the class named after file diff --git a/java/java-psi-impl/src/com/intellij/ide/highlighter/JavaClassFileType.java b/java/java-psi-impl/src/com/intellij/ide/highlighter/JavaClassFileType.java index e203f41c1626..8040151b2ceb 100644 --- a/java/java-psi-impl/src/com/intellij/ide/highlighter/JavaClassFileType.java +++ b/java/java-psi-impl/src/com/intellij/ide/highlighter/JavaClassFileType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -18,7 +18,6 @@ package com.intellij.ide.highlighter; import com.intellij.icons.AllIcons; import com.intellij.ide.IdeBundle; import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.util.NotNullLazyValue; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; @@ -28,14 +27,6 @@ public class JavaClassFileType implements FileType { public static final JavaClassFileType INSTANCE = new JavaClassFileType(); - private static final NotNullLazyValue ICON = new NotNullLazyValue() { - @NotNull - @Override - protected Icon compute() { - return AllIcons.FileTypes.JavaClass; - } - }; - private JavaClassFileType() { } @@ -59,7 +50,7 @@ public class JavaClassFileType implements FileType { @Override public Icon getIcon() { - return ICON.getValue(); + return AllIcons.FileTypes.JavaClass; } @Override diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/ClassInnerStuffCache.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/ClassInnerStuffCache.java index 544925856a52..b770f5839835 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/ClassInnerStuffCache.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/ClassInnerStuffCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -139,11 +139,8 @@ public class ClassInnerStuffCache { @Nullable @Override public Result compute() { - PsiElementFactory factory = JavaPsiFacade.getInstance(myClass.getProject()).getElementFactory(); String text = "public static " + myClass.getName() + "[] values() { }"; - PsiMethod physicalMethod = factory.createMethodFromText(text, myClass); - PsiMethod method = new LightMethod(myClass.getManager(), physicalMethod, myClass); - return new Result(method, OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker); + return new Result(getSyntheticMethod(text), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker); } }); } @@ -154,11 +151,8 @@ public class ClassInnerStuffCache { @Nullable @Override public Result compute() { - PsiElementFactory factory = JavaPsiFacade.getInstance(myClass.getProject()).getElementFactory(); String text = "public static " + myClass.getName() + " valueOf(java.lang.String name) throws java.lang.IllegalArgumentException { }"; - PsiMethod physicalMethod = factory.createMethodFromText(text, myClass); - PsiMethod method = new LightMethod(myClass.getManager(), physicalMethod, myClass); - return new Result(method, OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker); + return new Result(getSyntheticMethod(text), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker); } }); } @@ -236,6 +230,12 @@ public class ClassInnerStuffCache { return cachedInners; } + private PsiMethod getSyntheticMethod(String text) { + PsiElementFactory factory = JavaPsiFacade.getInstance(myClass.getProject()).getElementFactory(); + PsiMethod method = factory.createMethodFromText(text, myClass); + return new LightMethod(myClass.getManager(), method, myClass); + } + public void dropCaches() { myTracker.incModificationCount(); } diff --git a/java/java-tests/testData/codeInsight/completion/normal/IfConditionLt.java b/java/java-tests/testData/codeInsight/completion/normal/IfConditionLt.java new file mode 100644 index 000000000000..580a2eedb323 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/IfConditionLt.java @@ -0,0 +1,9 @@ +class Zoo { + + void foo(int x) { + if (x < getAnnotationsAreaOffset()); + + } + + int getAnnotationsAreaOffset() {} +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/lambda2methodReference/afterLambdaWithFormalParametersWithParameterizedContainerClassToReceiverMethodRef.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/lambda2methodReference/afterLambdaWithFormalParametersWithParameterizedContainerClassToReceiverMethodRef.java new file mode 100644 index 000000000000..d4db9714b032 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/lambda2methodReference/afterLambdaWithFormalParametersWithParameterizedContainerClassToReceiverMethodRef.java @@ -0,0 +1,15 @@ +// "Replace lambda with method reference" "true" + +import java.util.function.Function; + +class Test { + + + class Bar { + void f( ){ + Function.Bar, String> r = Bar::foo; + } + + private String foo() {} + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/lambda2methodReference/beforeLambdaWithFormalParametersWithParameterizedContainerClassToReceiverMethodRef.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/lambda2methodReference/beforeLambdaWithFormalParametersWithParameterizedContainerClassToReceiverMethodRef.java new file mode 100644 index 000000000000..04df9584ad1a --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/lambda2methodReference/beforeLambdaWithFormalParametersWithParameterizedContainerClassToReceiverMethodRef.java @@ -0,0 +1,15 @@ +// "Replace lambda with method reference" "true" + +import java.util.function.Function; + +class Test { + + + class Bar { + void f( ){ + Function.Bar, String> r = (Test.Bar t) -> t.foo(); + } + + private String foo() {} + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/HeavyNormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/HeavyNormalCompletionTest.groovy index 2117c9e877f2..3852327e36e9 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/HeavyNormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/HeavyNormalCompletionTest.groovy @@ -117,7 +117,7 @@ public class HeavyNormalCompletionTest extends JavaCodeInsightFixtureTestCase { myFixture.completeBasic(); assertOrderedEquals(myFixture.getLookupElementStrings(), "getAaa", "getBbb"); myFixture.getEditor().getCaretModel().moveToOffset(myFixture.getEditor().getCaretModel().getOffset() + 2); - assertNull(myFixture.completeBasic()); + assert myFixture.completeBasic() == null } public void testQualifyInaccessibleClassName() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy index df9087e84238..22a692ec25b4 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy @@ -512,6 +512,11 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase { public void testBreakInIfCondition() throws Throwable { doTest(); } public void testAccessStaticViaInstance() throws Throwable { doTest(); } + public void testIfConditionLt() { + configure() + myFixture.assertPreferredCompletionItems 0, 'getAnnotationsAreaOffset' + } + public void testAccessStaticViaInstanceSecond() throws Throwable { configure() myFixture.complete(CompletionType.BASIC, 2) diff --git a/java/java-tests/testSrc/com/intellij/find/FindInEditorMultiCaretTest.java b/java/java-tests/testSrc/com/intellij/find/FindInEditorMultiCaretTest.java index 65d04a22dfb1..a8c4f255248b 100644 --- a/java/java-tests/testSrc/com/intellij/find/FindInEditorMultiCaretTest.java +++ b/java/java-tests/testSrc/com/intellij/find/FindInEditorMultiCaretTest.java @@ -148,11 +148,11 @@ public class FindInEditorMultiCaretTest extends LightPlatformCodeInsightFixtureT } private void nextOccurrence() { - executeHeaderAction(EditorSearchSession.createNextOccurrenceAction()); + executeHeaderAction(new NextOccurrenceAction()); } private void prevOccurrence() { - executeHeaderAction(EditorSearchSession.createPrevOccurrenceAction()); + executeHeaderAction(new PrevOccurrenceAction()); } private void addOccurrence() { diff --git a/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/handlers/DeclarationStatementHandler.java b/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/handlers/DeclarationStatementHandler.java index 6ebf9d238c95..acd6e91bfa96 100644 --- a/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/handlers/DeclarationStatementHandler.java +++ b/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/handlers/DeclarationStatementHandler.java @@ -22,6 +22,7 @@ import java.util.List; public class DeclarationStatementHandler extends MatchingHandler { private MatchingHandler myCommentHandler; + @Override public boolean match(PsiElement patternNode, PsiElement matchedNode, MatchContext context) { if (patternNode instanceof PsiComment) { return myCommentHandler.match(patternNode, matchedNode, context); @@ -59,7 +60,7 @@ public class DeclarationStatementHandler extends MatchingHandler { node = PsiTreeUtil.skipSiblingsForward(node, PsiWhiteSpace.class); while (PsiUtil.isJavaToken(node, JavaTokenType.COMMA)) { node = PsiTreeUtil.skipSiblingsForward(node, PsiWhiteSpace.class); - if (node != null) { + if (node instanceof PsiField) { matchNodes.add(node); } node = PsiTreeUtil.skipSiblingsForward(node, PsiWhiteSpace.class); @@ -89,6 +90,7 @@ public class DeclarationStatementHandler extends MatchingHandler { return false; } + @Override public boolean shouldAdvanceTheMatchFor(PsiElement patternElement, PsiElement matchedElement) { if (patternElement instanceof PsiComment && ( matchedElement instanceof PsiField || diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java b/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java index e8a6823e86ee..3c8218430e49 100644 --- a/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java @@ -93,7 +93,7 @@ import java.util.Collections; import java.util.List; public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase { - private final FileTreeAccessFilter myFileTreeAccessFilter = new FileTreeAccessFilter(); + private VirtualFileFilter myVirtualFileFilter = new FileTreeAccessFilter(); @Override protected boolean isRunInWriteAction() { @@ -282,7 +282,7 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase { } final JavaPsiFacadeEx facade = getJavaFacade(); if (facade != null) { - facade.setAssertOnFileLoadingFilter(myFileTreeAccessFilter, myTestRootDisposable); // check repository work + facade.setAssertOnFileLoadingFilter(myVirtualFileFilter, myTestRootDisposable); // check repository work } try { @@ -302,16 +302,24 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase { @Override protected Editor createEditor(@NotNull VirtualFile file) { - allowTreeAccessForFile(file); + if (myVirtualFileFilter instanceof FileTreeAccessFilter) { + allowTreeAccessForFile(file); + } return super.createEditor(file); } + protected void setVirtualFileFilter(@NotNull VirtualFileFilter filter) { + myVirtualFileFilter = filter; + } + protected void allowTreeAccessForFile(@NotNull VirtualFile file) { - myFileTreeAccessFilter.allowTreeAccessForFile(file); + assert myVirtualFileFilter instanceof FileTreeAccessFilter : "configured filter does not support this method"; + ((FileTreeAccessFilter)myVirtualFileFilter).allowTreeAccessForFile(file); } protected void allowTreeAccessForAllFiles() { - myFileTreeAccessFilter.allowTreeAccessForAllFiles(); + assert myVirtualFileFilter instanceof FileTreeAccessFilter : "configured filter does not support this method"; + ((FileTreeAccessFilter)myVirtualFileFilter).allowTreeAccessForAllFiles(); } @NotNull diff --git a/platform/analysis-api/src/com/intellij/profile/DefaultProjectProfileManager.java b/platform/analysis-api/src/com/intellij/profile/DefaultProjectProfileManager.java index 65b49bcd2aac..cfcf716c13e0 100644 --- a/platform/analysis-api/src/com/intellij/profile/DefaultProjectProfileManager.java +++ b/platform/analysis-api/src/com/intellij/profile/DefaultProjectProfileManager.java @@ -22,8 +22,6 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.InvalidDataException; -import com.intellij.openapi.util.WriteExternalException; import com.intellij.packageDependencies.DependencyValidationManager; import com.intellij.psi.search.scope.packageSet.NamedScopesHolder; import com.intellij.util.ArrayUtil; @@ -104,12 +102,7 @@ public abstract class DefaultProjectProfileManager extends ProjectProfileManager final Profile projectProfile = myProfiles.get(profile); if (projectProfile != null) { Element profileElement = new Element(PROFILE); - try { - projectProfile.writeExternal(profileElement); - } - catch (WriteExternalException e) { - LOG.error(e); - } + projectProfile.writeExternal(profileElement); boolean hasSmthToSave = sortedProfiles.length > 1 || isCustomProfileUsed(); if (!hasSmthToSave) { for (Element child : profileElement.getChildren()) { @@ -141,16 +134,12 @@ public abstract class DefaultProjectProfileManager extends ProjectProfileManager for (Element o : state.getChildren(PROFILE)) { Profile profile = myApplicationProfileManager.createProfile(); profile.setProfileManager(this); - try { - profile.readExternal(o); - } - catch (InvalidDataException e) { - LOG.error(e); - } + profile.readExternal(o); profile.setProjectLevel(true); if (profileKeys.contains(profile.getName())) { updateProfile(profile); - } else { + } + else { myProfiles.put(profile.getName(), profile); } } @@ -252,10 +241,6 @@ public abstract class DefaultProjectProfileManager extends ProjectProfileManager }); } - public void removeProfilesListener(@NotNull ProfileChangeAdapter profilesListener) { - myProfilesListener.remove(profilesListener); - } - public static class ProfileStateSplitter extends MainConfigurationStateSplitter { @NotNull @Override diff --git a/platform/analysis-api/src/com/intellij/profile/Profile.java b/platform/analysis-api/src/com/intellij/profile/Profile.java index 64150f91fbad..7aa2370836b5 100644 --- a/platform/analysis-api/src/com/intellij/profile/Profile.java +++ b/platform/analysis-api/src/com/intellij/profile/Profile.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -16,14 +16,14 @@ package com.intellij.profile; import com.intellij.openapi.options.Scheme; -import com.intellij.openapi.util.JDOMExternalizable; +import org.jdom.Element; import org.jetbrains.annotations.NotNull; /** * User: anna * Date: 20-Nov-2005 */ -public interface Profile extends JDOMExternalizable, Comparable, Scheme { +public interface Profile extends Comparable, Scheme { void copyFrom(@NotNull Profile profile); void setLocal(boolean isLocal); @@ -48,4 +48,8 @@ public interface Profile extends JDOMExternalizable, Comparable, Scheme { @NotNull ProfileManager getProfileManager(); + + void readExternal(Element element); + + void writeExternal(Element element); } diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java index 263ba488e5e0..f3295fcd50e6 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.codeInspection.ex; import com.intellij.codeHighlighting.HighlightDisplayLevel; @@ -27,7 +26,6 @@ import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.Extensions; -import com.intellij.openapi.options.ExternalInfo; import com.intellij.openapi.options.ExternalizableScheme; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.Project; @@ -253,7 +251,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel, } @Override - public void readExternal(@NotNull Element element) throws InvalidDataException { + public void readExternal(@NotNull Element element) { super.readExternal(element); final String version = element.getAttributeValue(VERSION_TAG); @@ -868,12 +866,6 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel, } } - @Override - @Nullable - public ExternalInfo getExternalInfo() { - return null; - } - @NotNull public List getAllTools(Project project) { initInspectionTools(project); diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java index d5b60c4b88a4..5f7e9014cf99 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java @@ -142,7 +142,7 @@ public class ToolsImpl implements Tools { return result; } - public void writeExternal(Element inspectionElement) throws WriteExternalException { + public void writeExternal(@NotNull Element inspectionElement) throws WriteExternalException { if (myTools != null) { for (ScopeToolState state : myTools) { final Element scopeElement = new Element("scope"); diff --git a/platform/analysis-impl/src/com/intellij/profile/ProfileEx.java b/platform/analysis-impl/src/com/intellij/profile/ProfileEx.java index dc7040e868c3..388a3c8eac12 100644 --- a/platform/analysis-impl/src/com/intellij/profile/ProfileEx.java +++ b/platform/analysis-impl/src/com/intellij/profile/ProfileEx.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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,10 +15,7 @@ */ package com.intellij.profile; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.InvalidDataException; -import com.intellij.openapi.util.WriteExternalException; import com.intellij.util.xmlb.SmartSerializer; import com.intellij.util.xmlb.annotations.OptionTag; import com.intellij.util.xmlb.annotations.Transient; @@ -30,8 +27,6 @@ import org.jetbrains.annotations.NotNull; * Date: 01-Dec-2005 */ public abstract class ProfileEx implements Profile { - private static final Logger LOG = Logger.getInstance(ProfileEx.class); - public static final String SCOPE = "scope"; public static final String NAME = "name"; @@ -68,17 +63,9 @@ public abstract class ProfileEx implements Profile { @Override public void copyFrom(@NotNull Profile profile) { - try { - Element config = new Element("config"); - profile.writeExternal(config); - readExternal(config); - } - catch (WriteExternalException e) { - LOG.error(e); - } - catch (InvalidDataException e) { - LOG.error(e); - } + Element config = new Element("config"); + profile.writeExternal(config); + readExternal(config); } @Override @@ -121,7 +108,7 @@ public abstract class ProfileEx implements Profile { } @Override - public void readExternal(Element element) throws InvalidDataException { + public void readExternal(Element element) { mySerializer.readExternal(this, element); } @@ -130,7 +117,7 @@ public abstract class ProfileEx implements Profile { } @Override - public void writeExternal(Element element) throws WriteExternalException { + public void writeExternal(Element element) { serializeInto(element, true); } diff --git a/platform/configuration-store-impl/testSrc/ApplicationStoreTest.kt b/platform/configuration-store-impl/testSrc/ApplicationStoreTest.kt index 27ac1dbc5e2e..3e8a1fc3e03f 100644 --- a/platform/configuration-store-impl/testSrc/ApplicationStoreTest.kt +++ b/platform/configuration-store-impl/testSrc/ApplicationStoreTest.kt @@ -15,6 +15,8 @@ */ package com.intellij.configurationStore +import com.intellij.ide.actions.ExportableItem +import com.intellij.ide.actions.getExportableComponentsMap import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.components.* import com.intellij.openapi.vfs.CharsetToolkit @@ -33,6 +35,7 @@ import org.junit.ClassRule import org.junit.Rule import org.junit.Test import java.io.ByteArrayInputStream +import java.io.File import java.io.InputStream import java.nio.file.Path import java.nio.file.Paths @@ -109,6 +112,17 @@ internal class ApplicationStoreTest { assertThat(oldFile).doesNotExist() } + @Test fun `export settings`() { + val storageManager = ApplicationManager.getApplication().stateStore.stateStorageManager + val optionsPath = storageManager.expandMacros(StoragePathMacros.APP_CONFIG) + val rootConfigPath = storageManager.expandMacros(ROOT_CONFIG) + val map = getExportableComponentsMap(false, true, storageManager) + assertThat(map.size()).isNotEqualTo(0) + + val key = File(optionsPath, "filetypes.xml") + assertThat(map.get(key)).containsExactly(ExportableItem(listOf(key, File(rootConfigPath, "filetypes")), "File types", RoamingType.DEFAULT)) + } + private fun createComponentData(foo: String) = """""" @Test fun `remove data from deprecated storage if another component data exists`() { diff --git a/platform/configuration-store-impl/testSrc/DirectoryBasedStorageTest.kt b/platform/configuration-store-impl/testSrc/DirectoryBasedStorageTest.kt index 27663ecbc040..75d15662fe08 100644 --- a/platform/configuration-store-impl/testSrc/DirectoryBasedStorageTest.kt +++ b/platform/configuration-store-impl/testSrc/DirectoryBasedStorageTest.kt @@ -40,7 +40,7 @@ private fun StateStorage.ExternalizationSession.save() { private fun StateStorageBase<*>.setStateAndSave(componentName: String, state: String?) { var externalizationSession = startExternalization()!! - externalizationSession.setState(null, componentName, if (state == null) Element("state") else JDOMUtil.load(state.reader)) + externalizationSession.setState(null, componentName, if (state == null) Element("state") else JDOMUtil.load(state.reader())) externalizationSession.save() } diff --git a/platform/configuration-store-impl/testSrc/ModuleStoreTest.kt b/platform/configuration-store-impl/testSrc/ModuleStoreTest.kt index 2082a7ceea56..d48f33c9210f 100644 --- a/platform/configuration-store-impl/testSrc/ModuleStoreTest.kt +++ b/platform/configuration-store-impl/testSrc/ModuleStoreTest.kt @@ -39,7 +39,7 @@ class ModuleStoreTest { } } - private fun VirtualFile.loadModule() = runWriteAction { ModuleManager.getInstance(projectRule.project).loadModule(getPath()) } + private fun VirtualFile.loadModule() = runWriteAction { ModuleManager.getInstance(projectRule.project).loadModule(path) } fun Path.createModule() = projectRule.createModule(this) } @@ -51,8 +51,7 @@ class ModuleStoreTest { @Test fun `set option`() { val moduleFile = runWriteAction { - VfsTestUtil.createFile(tempDirManager.newVirtualDirectory("module"), "test.iml", "\n" + - "") + VfsTestUtil.createFile(tempDirManager.newVirtualDirectory("module"), "test.iml", "\n") } moduleFile.loadModule().useAndDispose { @@ -117,7 +116,7 @@ class ModuleStoreTest { assertThat(moduleFile).isRegularFile() val virtualFile = LocalFileSystem.getInstance().findFileByPath(modulePath)!! - val newData = moduleFile.readText().replace("\n", "").toByteArray() + val newData = moduleFile.readText().replace("\n", "").toByteArray() runWriteAction { virtualFile.setBinaryContent(newData) } diff --git a/platform/configuration-store-impl/testSrc/ProjectStoreTest.kt b/platform/configuration-store-impl/testSrc/ProjectStoreTest.kt index 1e66ba93b924..8eab00a7b829 100644 --- a/platform/configuration-store-impl/testSrc/ProjectStoreTest.kt +++ b/platform/configuration-store-impl/testSrc/ProjectStoreTest.kt @@ -25,6 +25,7 @@ import com.intellij.openapi.project.impl.ProjectManagerImpl import com.intellij.openapi.util.io.systemIndependentPath import com.intellij.openapi.vfs.VirtualFile import com.intellij.testFramework.* +import com.intellij.util.PathUtil import org.assertj.core.api.Assertions.assertThat import org.intellij.lang.annotations.Language import org.junit.ClassRule @@ -64,7 +65,7 @@ private fun createOrLoadProject(tempDirManager: TemporaryDirectory, task: (Proje } } -class ProjectStoreTest { +internal class ProjectStoreTest { companion object { @ClassRule val projectRule = ProjectRule() } @@ -76,12 +77,7 @@ class ProjectStoreTest { @Language("XML") private val iprFileContent = - "\n" + - "\n" + - " \n" + - " \n" + - "" + "\n\n \n \n" @State(name = "AATestComponent", storages = arrayOf(Storage(file = StoragePathMacros.PROJECT_FILE))) private class TestComponent : PersistentStateComponent { @@ -103,6 +99,8 @@ class ProjectStoreTest { }) { project -> val testComponent = test(project) + assertThat(project.basePath).isEqualTo(PathUtil.getParentPath((PathUtil.getParentPath(project.projectFilePath!!)))) + // test reload on external change val file = File(project.stateStore.stateStorageManager.expandMacros(StoragePathMacros.PROJECT_FILE)) file.writeText(file.readText().replace(""" - - + \ No newline at end of file diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classlayout/UtilityClassCanBeEnumInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classlayout/UtilityClassCanBeEnumInspection.java index 89ce1411ea1f..7b5416fa6975 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classlayout/UtilityClassCanBeEnumInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classlayout/UtilityClassCanBeEnumInspection.java @@ -19,6 +19,7 @@ import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.psi.util.PsiUtil; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; @@ -97,6 +98,11 @@ public class UtilityClassCanBeEnumInspection extends BaseInspection { return new UtilityClassCanBeEnumVisitor(); } + @Override + public boolean shouldInspect(PsiFile file) { + return PsiUtil.isLanguageLevel5OrHigher(file); + } + private static class UtilityClassCanBeEnumVisitor extends BaseInspectionVisitor { @Override diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/MethodUtils.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/MethodUtils.java index 3be99a959f1f..ded6d27e6ce2 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/MethodUtils.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/MethodUtils.java @@ -235,6 +235,10 @@ public class MethodUtils { return statements.length == 0; } + /** + * Returns true if the method or constructor is trivial, i.e. does nothing of consequence. This is true when the method is empty, but + * also when it is a constructor which only calls super, contains empty statements or "if (false)" statements. + */ public static boolean isTrivial(PsiMethod method, boolean throwIsTrivial) { return isTrivial(method.getBody(), throwIsTrivial); } diff --git a/plugins/gradle/src/META-INF/plugin.xml b/plugins/gradle/src/META-INF/plugin.xml index 0b9157afa8f2..2a5f1a245638 100644 --- a/plugins/gradle/src/META-INF/plugin.xml +++ b/plugins/gradle/src/META-INF/plugin.xml @@ -78,6 +78,7 @@ + diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/GradleConsoleFilter.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/GradleConsoleFilter.java new file mode 100644 index 000000000000..c87aab841f0e --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/GradleConsoleFilter.java @@ -0,0 +1,124 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.plugins.gradle.execution; + +import com.intellij.execution.filters.Filter; +import com.intellij.execution.filters.OpenFileHyperlinkInfo; +import com.intellij.openapi.editor.colors.CodeInsightColors; +import com.intellij.openapi.editor.colors.EditorColorsManager; +import com.intellij.openapi.editor.markup.TextAttributes; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ProjectRootManager; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.Nullable; + +import java.awt.*; +import java.io.File; + +/** + * @author Vladislav.Soroka + * @since 9/29/2015 + */ +public class GradleConsoleFilter implements Filter { + private final Project myProject; + private static final TextAttributes HYPERLINK_ATTRIBUTES = + EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.HYPERLINK_ATTRIBUTES); + private String myFilteredFileName; + private int myFilteredLineNumber; + + public GradleConsoleFilter(Project project) { + myProject = project; + } + + @Nullable + @Override + public Result applyFilter(final String line, final int entireLength) { + String[] filePrefixes = new String[]{"Build file '", "build file '"}; + String[] linePrefixes = new String[]{"' line: ", "': "}; + String filePrefix = null; + String linePrefix = null; + for (int i = 0; i < filePrefixes.length; i++) { + int filePrefixIndex = StringUtil.indexOf(line, filePrefixes[i]); + if (filePrefixIndex != -1) { + filePrefix = filePrefixes[i]; + linePrefix = linePrefixes[i]; + break; + } + } + + if (filePrefix == null || linePrefix == null) { + return null; + } + + int filePrefixIndex = StringUtil.indexOf(line, filePrefix); + + final String fileAndLineNumber = line.substring(filePrefix.length() + filePrefixIndex); + int linePrefixIndex = StringUtil.indexOf(fileAndLineNumber, linePrefix); + + if (linePrefixIndex == -1) { + return null; + } + + final String fileName = fileAndLineNumber.substring(0, linePrefixIndex); + myFilteredFileName = fileName; + String lineNumberStr = fileAndLineNumber.substring(linePrefixIndex + linePrefix.length(), fileAndLineNumber.length()).trim(); + int lineNumberEndIndex = 0; + for (int i = 0; i < lineNumberStr.length(); i++) { + if (Character.isDigit(lineNumberStr.charAt(i))) { + lineNumberEndIndex = i; + } + else { + break; + } + } + lineNumberStr = lineNumberStr.substring(0, lineNumberEndIndex + 1); + int lineNumber; + try { + lineNumber = Integer.parseInt(lineNumberStr); + myFilteredLineNumber = lineNumber; + } + catch (NumberFormatException e) { + return null; + } + + final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(fileName.replace(File.separatorChar, '/')); + if (file == null) { + return null; + } + + int textStartOffset = entireLength - line.trim().length() + filePrefix.length() - 1; + int highlightEndOffset = textStartOffset + fileName.length(); + OpenFileHyperlinkInfo info = new OpenFileHyperlinkInfo(myProject, file, Math.max(lineNumber - 1, 0)); + TextAttributes attributes = HYPERLINK_ATTRIBUTES.clone(); + if (!ProjectRootManager.getInstance(myProject).getFileIndex().isInContent(file)) { + Color color = UIUtil.getInactiveTextColor(); + attributes.setForegroundColor(color); + attributes.setEffectColor(color); + } + return new Result(textStartOffset, highlightEndOffset, info, attributes); + } + + public String getFilteredFileName() { + return myFilteredFileName; + } + + public int getFilteredLineNumber() { + return myFilteredLineNumber; + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/GradleConsoleFilterProvider.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/GradleConsoleFilterProvider.java new file mode 100644 index 000000000000..357999acf715 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/GradleConsoleFilterProvider.java @@ -0,0 +1,33 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.plugins.gradle.execution; + +import com.intellij.execution.filters.ConsoleFilterProvider; +import com.intellij.execution.filters.Filter; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; + +/** + * @author Vladislav.Soroka + * @since 9/29/2015 + */ +public class GradleConsoleFilterProvider implements ConsoleFilterProvider { + @NotNull + @Override + public Filter[] getDefaultFilters(@NotNull final Project project) { + return new Filter[]{new GradleConsoleFilter(project)}; + } +} diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/execution/GradleConsoleFilterTest.java b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/execution/GradleConsoleFilterTest.java new file mode 100644 index 000000000000..2a7ece0f2744 --- /dev/null +++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/execution/GradleConsoleFilterTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.plugins.gradle.execution; + +import com.intellij.testFramework.fixtures.CodeInsightFixtureTestCase; + +/** + * @author Vladislav.Soroka + * @since 9/29/2015 + */ +public class GradleConsoleFilterTest extends CodeInsightFixtureTestCase { + + public void testApplyFilter() throws Exception { + doTest("Build file 'C:\\project\\build.gradle' line: 7", "C:\\project\\build.gradle", 7); + doTest("Build file '/project/build.gradle' line: 7", "/project/build.gradle", 7); + doTest(" build file 'C:\\project\\build.gradle': 49: unexpected token: 5 @ line 49, column 28.", "C:\\project\\build.gradle", 49); + doTest("build file 'C:\\project\\build.gradle': 49: unexpected token: 5 @ line 49, column 28.", "C:\\project\\build.gradle", 49); + } + + private void doTest(String line, String expectedFileName, int expectedLineNumber) { + GradleConsoleFilter filter = new GradleConsoleFilter(myFixture.getProject()); + filter.applyFilter(line, 0); + assertEquals(expectedFileName, filter.getFilteredFileName()); + assertEquals(expectedLineNumber, filter.getFilteredLineNumber()); + } +} \ No newline at end of file diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GroovyScriptClass.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GroovyScriptClass.java index f7708d4b7a99..e654a83a65ab 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GroovyScriptClass.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GroovyScriptClass.java @@ -194,7 +194,7 @@ public class GroovyScriptClass extends LightElement implements PsiClass, Synthet return RecursionManager.doPreventingRecursion(this, false, new Computable() { @Override public PsiClassType compute() { - return CachedValuesManager.getCachedValue(myFile, new CachedValueProvider() { + return CachedValuesManager.getCachedValue(GroovyScriptClass.this, new CachedValueProvider() { @Nullable @Override public Result compute() { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcModuleStructureSynchronizer.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcModuleStructureSynchronizer.java index c094dbd512ff..8bd5e1723fd6 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcModuleStructureSynchronizer.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcModuleStructureSynchronizer.java @@ -276,7 +276,7 @@ public class MvcModuleStructureSynchronizer extends AbstractProjectComponent { @Override public void computeInReadAction(@NotNull ProgressIndicator indicator) { if (!isUpToDate()) { - indicator.cancel(); + scheduleRunActions(); return; } diff --git a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.java b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.java index 1f9d266de19c..a38359dfe9d3 100644 --- a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.java +++ b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.java @@ -32,6 +32,8 @@ import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.DefaultProjectFactory; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; +import com.intellij.openapi.util.AtomicNotNullLazyValue; +import com.intellij.openapi.util.NotNullLazyValue; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; @@ -75,27 +77,24 @@ public class IdeaDecompiler extends ClassFileDecompilers.Light { private static final String LEGAL_NOTICE_KEY = "decompiler.legal.notice.accepted"; - private final IFernflowerLogger myLogger = new IdeaLogger(); - private final Map myOptions; + private final NotNullLazyValue myLogger = new AtomicNotNullLazyValue() { + @NotNull + @Override + protected IFernflowerLogger compute() { + return new IdeaLogger(); + } + }; + private final NotNullLazyValue> myOptions = new AtomicNotNullLazyValue>() { + @NotNull + @Override + protected Map compute() { + return getOptions(); + } + }; private final Map myProgress = ContainerUtil.newConcurrentMap(); private boolean myLegalNoticeAccepted; public IdeaDecompiler() { - Map options = ContainerUtil.newHashMap(); - options.put(IFernflowerPreferences.HIDE_DEFAULT_CONSTRUCTOR, "0"); - options.put(IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES, "1"); - options.put(IFernflowerPreferences.REMOVE_SYNTHETIC, "1"); - options.put(IFernflowerPreferences.REMOVE_BRIDGE, "1"); - options.put(IFernflowerPreferences.LITERALS_AS_IS, "1"); - options.put(IFernflowerPreferences.NEW_LINE_SEPARATOR, "1"); - options.put(IFernflowerPreferences.BANNER, BANNER); - options.put(IFernflowerPreferences.MAX_PROCESSING_METHOD, 60); - - Project project = DefaultProjectFactory.getInstance().getDefaultProject(); - CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(project).getCurrentSettings(); - CommonCodeStyleSettings.IndentOptions indentOptions = settings.getIndentOptions(JavaFileType.INSTANCE); - options.put(IFernflowerPreferences.INDENT_STRING, StringUtil.repeat(" ", indentOptions.INDENT_SIZE)); - Application app = ApplicationManager.getApplication(); myLegalNoticeAccepted = app.isUnitTestMode() || PropertiesComponent.getInstance().isValueSet(LEGAL_NOTICE_KEY); if (!myLegalNoticeAccepted) { @@ -115,12 +114,30 @@ public class IdeaDecompiler extends ClassFileDecompilers.Light { } }); } + } - if (app.isUnitTestMode()) { + private static Map getOptions() { + Map options = ContainerUtil.newHashMap(); + + options.put(IFernflowerPreferences.HIDE_DEFAULT_CONSTRUCTOR, "0"); + options.put(IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES, "1"); + options.put(IFernflowerPreferences.REMOVE_SYNTHETIC, "1"); + options.put(IFernflowerPreferences.REMOVE_BRIDGE, "1"); + options.put(IFernflowerPreferences.LITERALS_AS_IS, "1"); + options.put(IFernflowerPreferences.NEW_LINE_SEPARATOR, "1"); + options.put(IFernflowerPreferences.BANNER, BANNER); + options.put(IFernflowerPreferences.MAX_PROCESSING_METHOD, 60); + + Project project = DefaultProjectFactory.getInstance().getDefaultProject(); + CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(project).getCurrentSettings(); + CommonCodeStyleSettings.IndentOptions indentOptions = settings.getIndentOptions(JavaFileType.INSTANCE); + options.put(IFernflowerPreferences.INDENT_STRING, StringUtil.repeat(" ", indentOptions.INDENT_SIZE)); + + if (ApplicationManager.getApplication().isUnitTestMode()) { options.put(IFernflowerPreferences.UNIT_TEST_MODE, "1"); } - myOptions = Collections.unmodifiableMap(options); + return Collections.unmodifiableMap(options); } private void showLegalNotice(final Project project, final VirtualFile file) { @@ -164,7 +181,7 @@ public class IdeaDecompiler extends ClassFileDecompilers.Light { MyBytecodeProvider provider = new MyBytecodeProvider(files); MyResultSaver saver = new MyResultSaver(); - Map options = ContainerUtil.newHashMap(myOptions); + Map options = ContainerUtil.newHashMap(myOptions.getValue()); if (Registry.is("decompiler.use.line.mapping")) { options.put(IFernflowerPreferences.BYTECODE_SOURCE_MAPPING, "1"); options.put(IFernflowerPreferences.USE_DEBUG_LINE_NUMBERS, "0"); @@ -181,7 +198,7 @@ public class IdeaDecompiler extends ClassFileDecompilers.Light { options.put(IFernflowerPreferences.DUMP_ORIGINAL_LINES, "1"); } - BaseDecompiler decompiler = new BaseDecompiler(provider, saver, options, myLogger); + BaseDecompiler decompiler = new BaseDecompiler(provider, saver, options, myLogger.getValue()); for (String path : files.keySet()) { decompiler.addSpace(new File(path), true); } diff --git a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompilerBundle.java b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompilerBundle.java index 7bb0ed4cc028..6530ff8db6cd 100644 --- a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompilerBundle.java +++ b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompilerBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -16,17 +16,19 @@ package org.jetbrains.java.decompiler; import com.intellij.AbstractBundle; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.PropertyKey; public class IdeaDecompilerBundle extends AbstractBundle { - public static String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, @NotNull Object... params) { - return INSTANCE.getMessage(key, params); + private static final String BUNDLE = "messages.Decompiler"; + + private static class Holder { + private static final AbstractBundle INSTANCE = new IdeaDecompilerBundle(); } - public static final AbstractBundle INSTANCE = new IdeaDecompilerBundle(); - @NonNls private static final String BUNDLE = "messages.Decompiler"; + public static String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, @NotNull Object... params) { + return Holder.INSTANCE.getMessage(key, params); + } private IdeaDecompilerBundle() { super(BUNDLE); diff --git a/plugins/junit/src/com/intellij/execution/junit/TestMethod.java b/plugins/junit/src/com/intellij/execution/junit/TestMethod.java index 013c0e908bf2..3b68c8fb60f8 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestMethod.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestMethod.java @@ -51,8 +51,7 @@ class TestMethod extends TestObject { protected void addJUnit3Parameter(JavaParameters javaParameters, final JUnitConfiguration.Data data, Project project) throws ExecutionException { final PsiClass psiClass = JavaExecutionUtil.findMainClass(project, data.getMainClassName(), GlobalSearchScope.allScope(project)); - LOG.assertTrue(psiClass != null); - if (JUnitUtil.isJUnit4TestClass(psiClass)) { + if (psiClass == null || JUnitUtil.isJUnit4TestClass(psiClass)) { return; } final String methodName = data.getMethodName(); diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/RepositoryLibrarySynchronizer.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/RepositoryLibrarySynchronizer.java index 35db1d640ae4..5f331bae62f8 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/RepositoryLibrarySynchronizer.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/RepositoryLibrarySynchronizer.java @@ -41,6 +41,9 @@ import java.util.Collection; public class RepositoryLibrarySynchronizer implements StartupActivity, DumbAware{ private static boolean isLibraryNeedToBeReloaded(LibraryEx library, RepositoryLibraryProperties properties) { String version = properties.getVersion(); + if (version == null) { + return false; + } if (version.equals(RepositoryUtils.LatestVersionId) || version.equals(RepositoryUtils.ReleaseVersionId) || version.endsWith(RepositoryUtils.SnapshotVersionSuffix)) { @@ -95,8 +98,9 @@ public class RepositoryLibrarySynchronizer implements StartupActivity, DumbAware return false; } LibraryEx libraryEx = (LibraryEx)library; - return libraryEx.getKind() == RepositoryLibraryType.REPOSITORY_LIBRARY_KIND && - libraryEx.getProperties() instanceof RepositoryLibraryProperties; + return libraryEx.getKind() == RepositoryLibraryType.REPOSITORY_LIBRARY_KIND + && libraryEx.getProperties() instanceof RepositoryLibraryProperties + && isLibraryNeedToBeReloaded(libraryEx, (RepositoryLibraryProperties)libraryEx.getProperties()); } }); for (Library library : libraries) { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/remote/MavenRemoteManager.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/remote/MavenRemoteManager.java index 186a125a5063..08ff9604efe2 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/remote/MavenRemoteManager.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/remote/MavenRemoteManager.java @@ -124,7 +124,14 @@ public abstract class MavenRemoteManager resultProcessor = item.getResultProcessor(); if (resultProcessor != null) { resultProcessor.process(result); diff --git a/plugins/settings-repository/src/copyAppSettingsToRepository.kt b/plugins/settings-repository/src/copyAppSettingsToRepository.kt index d638b61f4303..435a9116a2dc 100644 --- a/plugins/settings-repository/src/copyAppSettingsToRepository.kt +++ b/plugins/settings-repository/src/copyAppSettingsToRepository.kt @@ -17,9 +17,11 @@ package org.jetbrains.settingsRepository import com.intellij.configurationStore.ROOT_CONFIG import com.intellij.configurationStore.StateStorageManagerImpl -import com.intellij.ide.actions.ExportSettingsAction +import com.intellij.ide.actions.ExportableItem +import com.intellij.ide.actions.getExportableComponentsMap import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.components.* +import com.intellij.openapi.components.RoamingType +import com.intellij.openapi.components.stateStore import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.io.FileUtilRt import java.io.File @@ -27,7 +29,7 @@ import java.io.File fun copyLocalConfig(storageManager: StateStorageManagerImpl = ApplicationManager.getApplication()!!.stateStore.stateStorageManager as StateStorageManagerImpl) { val streamProvider = storageManager.streamProvider!! as IcsManager.IcsStreamProvider - val fileToComponents = ExportSettingsAction.getExportableComponentsMap(true, false, storageManager) + val fileToComponents = getExportableComponentsMap(true, false, storageManager) for (file in fileToComponents.keySet()) { val absolutePath = FileUtilRt.toSystemIndependentName(file.absolutePath) var fileSpec = storageManager.collapseMacros(absolutePath) @@ -67,20 +69,20 @@ private fun saveDirectory(parent: File, parentFileSpec: String, roamingType: Roa } } -private fun getRoamingType(components: Collection): RoamingType { +private fun getRoamingType(components: Collection): RoamingType { for (component in components) { - if (component is ExportSettingsAction.ExportableComponentItem) { + if (component is ExportableItem) { return component.roamingType } - else if (component is PersistentStateComponent<*>) { - val stateAnnotation = component.javaClass.getAnnotation(State::class.java) - if (stateAnnotation != null) { - val storages = stateAnnotation.storages - if (!storages.isEmpty()) { - return storages[0].roamingType - } - } - } +// else if (component is PersistentStateComponent<*>) { +// val stateAnnotation = component.javaClass.getAnnotation(State::class.java) +// if (stateAnnotation != null) { +// val storages = stateAnnotation.storages +// if (!storages.isEmpty()) { +// return storages[0].roamingType +// } +// } +// } } return RoamingType.DEFAULT } \ No newline at end of file diff --git a/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfigurationProducer.java b/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfigurationProducer.java index 8b07de478261..2f6d390163ac 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfigurationProducer.java +++ b/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfigurationProducer.java @@ -42,6 +42,11 @@ public abstract class TestNGConfigurationProducer extends JavaRunConfigurationPr super(configurationType); } + @SuppressWarnings("unused") //used in kotlin + public TestNGConfigurationProducer() { + super(TestNGConfigurationType.getInstance()); + } + @Override public boolean isConfigurationFromContext(TestNGConfiguration testNGConfiguration, ConfigurationContext context) { if (RunConfigurationProducer.getInstance(AbstractTestNGPatternConfigurationProducer.class).isMultipleElementsSelected(context)) { diff --git a/plugins/testng_rt/src/org/testng/IDEATestNGRemoteListener.java b/plugins/testng_rt/src/org/testng/IDEATestNGRemoteListener.java index 5664908788bf..6232db10a13a 100644 --- a/plugins/testng_rt/src/org/testng/IDEATestNGRemoteListener.java +++ b/plugins/testng_rt/src/org/testng/IDEATestNGRemoteListener.java @@ -31,39 +31,45 @@ public class IDEATestNGRemoteListener implements ISuiteListener, IResultListener public synchronized void onStart(final ISuite suite) { if (suite != null) { - final List allMethods = suite.getAllMethods(); - if (allMethods != null) { - int count = 0; - for (ITestNGMethod method : allMethods) { - if (method.isTest()) count += method.getInvocationCount(); + try { + final List allMethods = suite.getAllMethods(); + if (allMethods != null) { + int count = 0; + for (ITestNGMethod method : allMethods) { + if (method.isTest()) count += method.getInvocationCount(); + } + myPrintStream.println("##teamcity[testCount count = \'" + count + "\']"); } - myPrintStream.println("##teamcity[testCount count = \'" + count + "\']"); } + catch (NoSuchMethodError ignore) {} myPrintStream.println("##teamcity[rootName name = '" + suite.getName() + "' location = 'file://" + suite.getXmlSuite().getFileName() + "']"); } } public synchronized void onFinish(ISuite suite) { - if (suite != null && suite.getAllInvokedMethods().size() < suite.getAllMethods().size()) { - for (ITestNGMethod method : suite.getAllMethods()) { - if (method.isTest()) { - boolean found = false; - for (IInvokedMethod invokedMethod : suite.getAllInvokedMethods()) { - if (invokedMethod.getTestMethod() == method) { - found = true; + try { + if (suite != null && suite.getAllInvokedMethods().size() < suite.getAllMethods().size()) { + for (ITestNGMethod method : suite.getAllMethods()) { + if (method.isTest()) { + boolean found = false; + for (IInvokedMethod invokedMethod : suite.getAllInvokedMethods()) { + if (invokedMethod.getTestMethod() == method) { + found = true; + break; + } + } + if (!found) { + final String fullEscapedMethodName = escapeName(getShortName(method.getTestClass().getName()) + "." + method.getMethodName()); + myPrintStream.println("##teamcity[testStarted name=\'" + fullEscapedMethodName + "\']"); + myPrintStream.println("##teamcity[testIgnored name=\'" + fullEscapedMethodName + "\']"); + myPrintStream.println("##teamcity[testFinished name=\'" + fullEscapedMethodName + "\']"); break; } } - if (!found) { - final String fullEscapedMethodName = escapeName(getShortName(method.getTestClass().getName()) + "." + method.getMethodName()); - myPrintStream.println("##teamcity[testStarted name=\'" + fullEscapedMethodName + "\']"); - myPrintStream.println("##teamcity[testIgnored name=\'" + fullEscapedMethodName + "\']"); - myPrintStream.println("##teamcity[testFinished name=\'" + fullEscapedMethodName + "\']"); - break; - } } } } + catch (NoSuchMethodError ignored) {} for (int i = myCurrentSuites.size() - 1; i >= 0; i--) { onSuiteFinish(myCurrentSuites.remove(i)); } diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/binding/BoundIconRenderer.java b/plugins/ui-designer/src/com/intellij/uiDesigner/binding/BoundIconRenderer.java index 60f12b2489b6..dfdd6db8fa13 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/binding/BoundIconRenderer.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/binding/BoundIconRenderer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -68,6 +68,7 @@ public class BoundIconRenderer extends GutterIconRenderer { } } + @Override @NotNull public Icon getIcon() { if (myIcon != null) { @@ -76,13 +77,16 @@ public class BoundIconRenderer extends GutterIconRenderer { return PlatformIcons.UI_FORM_ICON; } + @Override public boolean isNavigateAction() { return true; } + @Override @Nullable public AnAction getClickAction() { return new AnAction() { + @Override public void actionPerformed(AnActionEvent e) { List formFiles = getBoundFormFiles(); if (formFiles.size() > 0) { @@ -104,6 +108,7 @@ public class BoundIconRenderer extends GutterIconRenderer { }; } + @Override @Nullable public String getTooltipText() { List formFiles = getBoundFormFiles(); diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/binding/FormClassAnnotator.java b/plugins/ui-designer/src/com/intellij/uiDesigner/binding/FormClassAnnotator.java index 05c1bcb1b912..da243250d8ec 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/binding/FormClassAnnotator.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/binding/FormClassAnnotator.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -37,6 +37,7 @@ import java.util.List; public class FormClassAnnotator implements Annotator { private static final Logger LOG = Logger.getInstance("#com.intellij.uiDesigner.binding.FormClassAnnotator"); + @Override public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder holder) { if (psiElement instanceof PsiField) { PsiField field = (PsiField) psiElement; @@ -76,20 +77,24 @@ public class FormClassAnnotator implements Annotator { final String message = UIDesignerBundle.message("field.is.overwritten.by.generated.code", field.getName()); Annotation annotation = holder.createWarningAnnotation(field.getInitializer(), message); annotation.registerFix(new IntentionAction() { + @Override @NotNull public String getText() { return message; } + @Override @NotNull public String getFamilyName() { return UIBundle.message("remove.field.initializer.quick.fix"); } + @Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { return field.getInitializer() != null; } + @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { if (!FileModificationService.getInstance().preparePsiElementForWrite(field)) return; final PsiExpression initializer = field.getInitializer(); @@ -97,6 +102,7 @@ public class FormClassAnnotator implements Annotator { initializer.delete(); } + @Override public boolean startInWriteAction() { return true; } diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/palette/AddGroupAction.java b/plugins/ui-designer/src/com/intellij/uiDesigner/palette/AddGroupAction.java index 2d388652188f..4047d7e58b74 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/palette/AddGroupAction.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/palette/AddGroupAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -20,17 +20,18 @@ import com.intellij.CommonBundle; 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.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.uiDesigner.UIDesignerBundle; import java.util.ArrayList; +import java.util.List; /** * @author yole */ public class AddGroupAction extends AnAction { + @Override public void actionPerformed(AnActionEvent e) { Project project = e.getData(CommonDataKeys.PROJECT); if (project == null) return; @@ -41,15 +42,15 @@ public class AddGroupAction extends AnAction { UIDesignerBundle.message("title.add.group"), Messages.getQuestionIcon() ); - if(groupName == null){ + if (groupName == null) { return; } Palette palette = Palette.getInstance(project); // Check that name of the group is unique - final ArrayList groups = palette.getGroups(); - for(int i = groups.size() - 1; i >= 0; i--){ - if(groupName.equals(groups.get(i).getName())){ + List groups = palette.getGroups(); + for (int i = groups.size() - 1; i >= 0; i--) { + if (groupName.equals(groups.get(i).getName())) { Messages.showErrorDialog(project, UIDesignerBundle.message("error.group.name.unique"), CommonBundle.getErrorTitle()); diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/palette/ComponentItemDialog.java b/plugins/ui-designer/src/com/intellij/uiDesigner/palette/ComponentItemDialog.java index a3d66a914304..cbf5cccf19b1 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/palette/ComponentItemDialog.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/palette/ComponentItemDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,7 +53,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; -import java.util.ArrayList; +import java.util.List; /** * @author Vladimir Kondratyev @@ -114,6 +114,7 @@ public final class ComponentItemDialog extends DialogWrapper { updateEnabledTextField(); myTfClassName.getChildComponent().addDocumentListener(new com.intellij.openapi.editor.event.DocumentAdapter() { + @Override public void documentChanged(com.intellij.openapi.editor.event.DocumentEvent e) { updateOKAction(); } @@ -128,12 +129,14 @@ public final class ComponentItemDialog extends DialogWrapper { UIDesignerBundle.message("add.component.choose.icon"))); myTfNestedForm.addActionListener(new MyChooseFileActionListener(project, new TreeFileChooser.PsiFileFilter() { + @Override public boolean accept(PsiFile file) { return file.getFileType().equals(StdFileTypes.GUI_DESIGNER_FORM); } }, myTfNestedForm, UIDesignerBundle.message("add.component.choose.form"))); myTfNestedForm.getTextField().getDocument().addDocumentListener(new DocumentAdapter() { + @Override protected void textChanged(DocumentEvent e) { updateOKAction(); } @@ -181,10 +184,11 @@ public final class ComponentItemDialog extends DialogWrapper { void showGroupChooser(GroupItem defaultGroup) { myGroupLabel.setVisible(true); myGroupComboBox.setVisible(true); - final ArrayList groups = Palette.getInstance(myProject).getGroups(); + List groups = Palette.getInstance(myProject).getGroups(); myGroupComboBox.setModel(new DefaultComboBoxModel(groups.toArray())); myGroupComboBox.setSelectedItem(defaultGroup); myGroupComboBox.addItemListener(new ItemListener() { + @Override public void itemStateChanged(ItemEvent e) { updateOKAction(); } @@ -205,15 +209,18 @@ public final class ComponentItemDialog extends DialogWrapper { updateOKAction(); } + @Override @NotNull protected Action[] createActions() { return new Action[]{getOKAction(), getCancelAction(), getHelpAction()}; } + @Override protected void doHelpAction() { HelpManager.getInstance().invokeHelp("reference.dialogs.addEditPaletteComponent"); } + @Override protected void doOKAction() { // TODO[vova] implement validation if (myClassRadioButton.isSelected()) { @@ -294,6 +301,7 @@ public final class ComponentItemDialog extends DialogWrapper { return true; } + @Override protected String getDimensionServiceKey() { if (myOneOff) { return "#com.intellij.uiDesigner.palette.ComponentItemDialog.OneOff"; @@ -301,10 +309,12 @@ public final class ComponentItemDialog extends DialogWrapper { return "#com.intellij.uiDesigner.palette.ComponentItemDialog"; } + @Override public JComponent getPreferredFocusedComponent() { return myTfClassName.getChildComponent(); } + @Override protected JComponent createCenterPanel() { return myPanel; } @@ -365,6 +375,7 @@ public final class ComponentItemDialog extends DialogWrapper { myProject = project; } + @Override public void actionPerformed(final ActionEvent e) { final TreeClassChooserFactory factory = TreeClassChooserFactory.getInstance(myProject); final TreeClassChooser chooser = factory.createInheritanceClassChooser(UIDesignerBundle.message("title.choose.component.class"), @@ -394,6 +405,7 @@ public final class ComponentItemDialog extends DialogWrapper { myTitle = title; } + @Override public void actionPerformed(ActionEvent e) { final TreeClassChooserFactory factory = TreeClassChooserFactory.getInstance(myProject); PsiFile formFile = null; @@ -413,6 +425,7 @@ public final class ComponentItemDialog extends DialogWrapper { } private class MyRadioChangeListener implements ChangeListener { + @Override public void stateChanged(ChangeEvent e) { updateEnabledTextField(); } diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/palette/EditGroupAction.java b/plugins/ui-designer/src/com/intellij/uiDesigner/palette/EditGroupAction.java index 3bedd33a745a..d69437c7b204 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/palette/EditGroupAction.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/palette/EditGroupAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -20,17 +20,17 @@ import com.intellij.CommonBundle; 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.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.uiDesigner.UIDesignerBundle; -import java.util.ArrayList; +import java.util.List; /** * @author yole */ public class EditGroupAction extends AnAction { + @Override public void actionPerformed(AnActionEvent e) { Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); GroupItem groupToBeEdited = GroupItem.DATA_KEY.getData(e.getDataContext()); @@ -45,14 +45,14 @@ public class EditGroupAction extends AnAction { groupToBeEdited.getName(), null ); - if(groupName == null || groupName.equals(groupToBeEdited.getName())){ + if (groupName == null || groupName.equals(groupToBeEdited.getName())) { return; } Palette palette = Palette.getInstance(project); - final ArrayList groups = palette.getGroups(); - for(int i = groups.size() - 1; i >= 0; i--){ - if(groupName.equals(groups.get(i).getName())){ + List groups = palette.getGroups(); + for (int i = groups.size() - 1; i >= 0; i--) { + if (groupName.equals(groups.get(i).getName())) { Messages.showErrorDialog(project, UIDesignerBundle.message("error.group.name.unique"), CommonBundle.getErrorTitle()); return; @@ -63,7 +63,8 @@ public class EditGroupAction extends AnAction { palette.fireGroupsChanged(); } - @Override public void update(AnActionEvent e) { + @Override + public void update(AnActionEvent e) { Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); GroupItem groupItem = GroupItem.DATA_KEY.getData(e.getDataContext()); e.getPresentation().setEnabled(project != null && groupItem != null && !groupItem.isReadOnly()); diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/palette/Palette.java b/plugins/ui-designer/src/com/intellij/uiDesigner/palette/Palette.java index 4627efd195f0..2fe60e396578 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/palette/Palette.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/palette/Palette.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -18,7 +18,6 @@ package com.intellij.uiDesigner.palette; import com.intellij.ide.ui.LafManager; import com.intellij.ide.ui.LafManagerListener; import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ApplicationNamesInfo; import com.intellij.openapi.components.*; import com.intellij.openapi.diagnostic.Logger; @@ -78,7 +77,7 @@ public final class Palette implements Disposable, PersistentStateComponent myClass2Properties; private final Map myClassName2Item; /*All groups in the palette*/ - private final ArrayList myGroups; + private final List myGroups; /*Listeners, etc*/ private final List myListeners = ContainerUtil.createLockFreeCopyOnWriteList(); private final Project myProject; @@ -118,7 +117,9 @@ public final class Palette implements Disposable, PersistentStateComponentDO NOT MODIFY OR CACHE THIS LIST. */ - public ArrayList getGroups(){ + public List getGroups() { return myGroups; } public GroupItem[] getToolWindowGroups() { - GroupItem[] groups = new GroupItem[myGroups.size()+1]; - for(int i=0; i groups){ + public void setGroups(@NotNull final ArrayList groups) { myGroups.clear(); myGroups.addAll(groups); @@ -288,9 +274,10 @@ public final class Palette implements Disposable, PersistentStateComponentitem to the palette. + * * @param item item to be added - * @exception java.lang.IllegalArgumentException if an item for the same class - * is already exists in the palette + * @throws IllegalArgumentException if an item for the same class + * is already exists in the palette */ public void addItem(@NotNull final GroupItem group, @NotNull final ComponentItem item) { // class -> item @@ -309,7 +296,7 @@ public final class Palette implements Disposable, PersistentStateComponent propertyName2initialValue = new HashMap(); { final Element initialValues = itemElement.getChild(ELEMENT_INITIAL_VALUES); - if (initialValues != null){ - for(final Object o : initialValues.getChildren(ELEMENT_PROPERTY)) { + if (initialValues != null) { + for (final Object o : initialValues.getChildren(ELEMENT_PROPERTY)) { final Element e = (Element)o; final String name = LwXmlReader.getRequiredString(e, ATTRIBUTE_NAME); // TODO[all] currently all initial values are strings @@ -430,14 +417,11 @@ public final class Palette implements Disposable, PersistentStateComponent groupElements) { + for (Element groupElement : groupElements) { + GroupItem group = new GroupItem(LwXmlReader.getRequiredString(groupElement, ATTRIBUTE_NAME)); myGroups.add(group); - for (final Object o : groupElement.getChildren(ELEMENT_ITEM)) { - final Element itemElement = (Element)o; + for (Element itemElement : groupElement.getChildren(ELEMENT_ITEM)) { try { processItemElement(itemElement, group, false); } @@ -448,8 +432,10 @@ public final class Palette implements Disposable, PersistentStateComponent name2value - ){ + ) { LOG.assertTrue(ELEMENT_ITEM.equals(itemElement.getName())); - if(name2value.size() == 0){ // do not append 'initial-values' subtag + if (name2value.size() == 0) { // do not append 'initial-values' subtag return; } @@ -516,8 +504,10 @@ public final class Palette implements Disposable, PersistentStateComponent filter = null; if (name.equals(SwingProperties.LABEL_FOR)) { filter = new Condition() { + @Override public boolean value(final RadComponent t) { ComponentItem item = getItem(t.getComponentClassName()); return item != null && item.isCanAttachLabel(); @@ -756,9 +744,9 @@ public final class Palette implements Disposable, PersistentStateComponentDO NOT USE THIS METHOD DIRECTLY. Use {@link com.intellij.uiDesigner.radComponents.RadComponent#getInplaceProperty(int, int) } + * DO NOT USE THIS METHOD DIRECTLY. Use {@link RadComponent#getInplaceProperty(int, int) } * instead. */ @Nullable @@ -777,17 +765,17 @@ public final class Palette implements Disposable, PersistentStateComponent= 0; i--) { final IntrospectedProperty property = properties[i]; - if(property.getName().equals(inplaceProperty)){ + if (property.getName().equals(inplaceProperty)) { return property; } } return null; } - public static boolean isRemovable(@NotNull final GroupItem group){ + public static boolean isRemovable(@NotNull final GroupItem group) { final ComponentItem[] items = group.getItems(); - for(int i = items.length - 1; i >=0; i--){ - if(!items [i].isRemovable()){ + for (int i = items.length - 1; i >= 0; i--) { + if (!items[i].isRemovable()) { return false; } } @@ -797,12 +785,12 @@ public final class Palette implements Disposable, PersistentStateComponent myProcessListeners = new LinkedList(); public StudyRunAction() { super("Run File With Tests", "Run your code with tests", AllIcons.General.Run); @@ -75,6 +78,11 @@ public class StudyRunAction extends DumbAwareAction { return; } myHandler = new OSProcessHandler(process); + + for (ProcessListener processListener : myProcessListeners) { + myHandler.addProcessListener(processListener); + } + final RunContentExecutor executor = StudyUtils.getExecutor(project, currentTask, myHandler); if (executor != null) { Disposer.register(project, executor); @@ -84,6 +92,14 @@ public class StudyRunAction extends DumbAwareAction { } } + public void addProcessListener(@NotNull final ProcessListener processListener) { + myProcessListeners.add(processListener); + } + + public void removeProcessListener(@NotNull final ProcessListener processListener) { + myProcessListeners.remove(processListener); + } + public void actionPerformed(@NotNull AnActionEvent e) { final Project project = e.getProject(); if (project != null) { diff --git a/python/src/com/jetbrains/python/packaging/PyCondaPackageManagerImpl.java b/python/src/com/jetbrains/python/packaging/PyCondaPackageManagerImpl.java index ee9a62cd868d..f597917178f2 100644 --- a/python/src/com/jetbrains/python/packaging/PyCondaPackageManagerImpl.java +++ b/python/src/com/jetbrains/python/packaging/PyCondaPackageManagerImpl.java @@ -50,7 +50,7 @@ public class PyCondaPackageManagerImpl extends PyPackageManagerImpl { @Override public boolean hasManagement(boolean cachedOnly) throws ExecutionException { - return findCondaExecutable(mySdk) != null; + return isCondaVEnv(mySdk); } @Override @@ -74,7 +74,7 @@ public class PyCondaPackageManagerImpl extends PyPackageManagerImpl { } private ProcessOutput getCondaOutput(@NotNull final String command, List arguments) throws ExecutionException { - final String condaExecutable = findCondaExecutable(mySdk); + final String condaExecutable = PyCondaPackageService.getCondaExecutable(); final String path = getCondaDirectory(); if (path == null) throw new PyExecutionException("Empty conda name for " + mySdk, command, arguments); @@ -109,6 +109,7 @@ public class PyCondaPackageManagerImpl extends PyPackageManagerImpl { private String getCondaDirectory() { final VirtualFile homeDirectory = mySdk.getHomeDirectory(); if (homeDirectory == null) return null; + if (SystemInfo.isWindows) return homeDirectory.getParent().getPath(); return homeDirectory.getParent().getParent().getPath(); } @@ -147,7 +148,6 @@ public class PyCondaPackageManagerImpl extends PyPackageManagerImpl { } final String name = fields.get(0); final String version = fields.get(1); - final String location = fields.get(2); final List requirements = new ArrayList(); if (fields.size() >= 4) { final String requiresLine = fields.get(3); @@ -155,25 +155,24 @@ public class PyCondaPackageManagerImpl extends PyPackageManagerImpl { requirements.addAll(PyRequirement.parse(requiresSpec)); } if (!"Python".equals(name)) { - packages.add(new PyPackage(name, version, location, requirements)); + packages.add(new PyPackage(name, version, "", requirements)); } } return packages; } - @Nullable - public static String findCondaExecutable(Sdk sdk) { - final String condaName = SystemInfo.isWindows ? "conda.exe" : "conda"; + public static boolean isCondaVEnv(Sdk sdk) { + final String condaName = "conda-meta"; final VirtualFile homeDirectory = sdk.getHomeDirectory(); - if (homeDirectory == null) return null; - final VirtualFile condaExecutable = homeDirectory.getParent().findChild(condaName); - return condaExecutable != null ? condaExecutable.getPath() : null; + if (homeDirectory == null) return false; + final VirtualFile condaExecutable = SystemInfo.isWindows ? homeDirectory.getParent().findChild(condaName) : + homeDirectory.getParent().getParent().findChild(condaName); + return condaExecutable != null; } @NotNull public static String createVirtualEnv(@NotNull String destinationDir, String version) throws ExecutionException { - final String condaName = SystemInfo.isWindows ? "conda.exe" : "conda"; - final String condaExecutable = PyCondaPackageService.getCondaExecutable(condaName); + final String condaExecutable = PyCondaPackageService.getCondaExecutable(); if (condaExecutable == null) throw new PyExecutionException("Cannot find conda", "Conda", Collections.emptyList(), new ProcessOutput()); final ArrayList parameters = Lists.newArrayList(condaExecutable, "create", "-p", destinationDir, diff --git a/python/src/com/jetbrains/python/packaging/PyCondaPackageService.java b/python/src/com/jetbrains/python/packaging/PyCondaPackageService.java index ae79f64e5e5c..c3355fa4c0d0 100644 --- a/python/src/com/jetbrains/python/packaging/PyCondaPackageService.java +++ b/python/src/com/jetbrains/python/packaging/PyCondaPackageService.java @@ -79,12 +79,28 @@ public class PyCondaPackageService implements PersistentStateComponent parameters = Lists.newArrayList(conda, "config", "--add", "channels", repositoryUrl, "--force"); + final GeneralCommandLine commandLine = new GeneralCommandLine(parameters); + + try { + final Process process = commandLine.createProcess(); + final CapturingProcessHandler handler = new CapturingProcessHandler(process); + final ProcessOutput result = handler.runProcess(); + final int exitCode = result.getExitCode(); + if (exitCode != 0) { + final String message = StringUtil.isEmptyOrSpaces(result.getStdout()) && StringUtil.isEmptyOrSpaces(result.getStderr()) ? + "Permission denied" : "Non-zero exit code"; + LOG.warn("Failed to add repository " + message); + } + PyCondaPackageService.getInstance().addChannel(repositoryUrl); + } + catch (ExecutionException e) { + LOG.warn("Failed to add repository"); + } + + } + + @Override + public void removeRepository(String repositoryUrl) { + final String conda = PyCondaPackageService.getCondaExecutable(); + final ArrayList parameters = Lists.newArrayList(conda, "config", "--remove", "channels", repositoryUrl, "--force"); + final GeneralCommandLine commandLine = new GeneralCommandLine(parameters); + + try { + final Process process = commandLine.createProcess(); + final CapturingProcessHandler handler = new CapturingProcessHandler(process); + final ProcessOutput result = handler.runProcess(); + final int exitCode = result.getExitCode(); + if (exitCode != 0) { + final String message = StringUtil.isEmptyOrSpaces(result.getStdout()) && StringUtil.isEmptyOrSpaces(result.getStderr()) ? + "Permission denied" : "Non-zero exit code"; + LOG.warn("Failed to remove repository " + message); + } + PyCondaPackageService.getInstance().removeChannel(repositoryUrl); + } + catch (ExecutionException e) { + LOG.warn("Failed to remove repository"); + } + } + @Override public boolean canInstallToUser() { return false; @@ -71,8 +124,4 @@ public class PyCondaManagementService extends PyPackageManagementService { consumer.consume(versions); } - @Override - public void uninstallPackages(List installedPackages, Listener listener) { - super.uninstallPackages(installedPackages, listener); - } } diff --git a/python/src/com/jetbrains/python/sdk/AbstractCreateVirtualEnvDialog.java b/python/src/com/jetbrains/python/sdk/AbstractCreateVirtualEnvDialog.java index ec069ff17c47..fe0d9e50fc71 100644 --- a/python/src/com/jetbrains/python/sdk/AbstractCreateVirtualEnvDialog.java +++ b/python/src/com/jetbrains/python/sdk/AbstractCreateVirtualEnvDialog.java @@ -128,7 +128,7 @@ public abstract class AbstractCreateVirtualEnvDialog extends IdeaDialog { new LocationNameFieldsBinding(project, myDestination, myName, myInitialPath, "Select Location for Virtual Environment"); } - private void setInitialDestination() { + protected void setInitialDestination() { myInitialPath = ""; final VirtualFile file = VirtualEnvSdkFlavor.getDefaultLocation(); diff --git a/python/src/com/jetbrains/python/sdk/CreateCondaEnvDialog.java b/python/src/com/jetbrains/python/sdk/CreateCondaEnvDialog.java index e1f74649d843..37c9620424ab 100644 --- a/python/src/com/jetbrains/python/sdk/CreateCondaEnvDialog.java +++ b/python/src/com/jetbrains/python/sdk/CreateCondaEnvDialog.java @@ -20,9 +20,11 @@ import com.intellij.facet.ui.FacetValidatorsManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.ui.ComboBox; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.CollectionComboBoxModel; import com.intellij.ui.components.JBLabel; import com.jetbrains.python.packaging.PyCondaPackageManagerImpl; +import com.jetbrains.python.sdk.flavors.VirtualEnvSdkFlavor; import com.jetbrains.python.validation.UnsupportedFeaturesUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -55,6 +57,14 @@ public class CreateCondaEnvDialog extends AbstractCreateVirtualEnvDialog { checkValid(); } + @Override + protected void setInitialDestination() { + final List locations = VirtualEnvSdkFlavor.getCondaDefaultLocations(); + if (!locations.isEmpty()) { + myInitialPath = locations.get(0).getPath(); + } + } + protected void layoutPanel(final List allSdks) { final GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; diff --git a/python/src/com/jetbrains/python/sdk/PythonSdkDetailsStep.java b/python/src/com/jetbrains/python/sdk/PythonSdkDetailsStep.java index bf16c4ee37bb..c66d491f6a7f 100644 --- a/python/src/com/jetbrains/python/sdk/PythonSdkDetailsStep.java +++ b/python/src/com/jetbrains/python/sdk/PythonSdkDetailsStep.java @@ -37,7 +37,6 @@ import com.intellij.openapi.ui.popup.ListSeparator; import com.intellij.openapi.ui.popup.PopupStep; import com.intellij.openapi.ui.popup.util.BaseListPopupStep; import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.SystemInfo; import com.intellij.util.NullableConsumer; import com.jetbrains.python.PyBundle; import com.jetbrains.python.packaging.PyCondaPackageService; @@ -110,8 +109,7 @@ public class PythonSdkDetailsStep extends BaseListPopupStep { options.add(REMOTE); } options.add(VIRTUALENV); - final String condaName = SystemInfo.isWindows ? "conda.exe" : "conda"; - if (PyCondaPackageService.getCondaExecutable(condaName) != null) { + if (PyCondaPackageService.getCondaExecutable() != null) { options.add(CONDA); } diff --git a/python/src/com/jetbrains/python/sdk/PythonSdkType.java b/python/src/com/jetbrains/python/sdk/PythonSdkType.java index 5e9fc647fe06..c08e908d8cb0 100644 --- a/python/src/com/jetbrains/python/sdk/PythonSdkType.java +++ b/python/src/com/jetbrains/python/sdk/PythonSdkType.java @@ -316,7 +316,7 @@ public class PythonSdkType extends SdkType { public static boolean isCondaVirtualEnv(Sdk sdk) { final String path = sdk.getHomePath(); - return path != null && PyCondaPackageManagerImpl.findCondaExecutable(sdk) != null; + return path != null && PyCondaPackageManagerImpl.isCondaVEnv(sdk); } @Nullable