Merge branch 'master' of git.labs.intellij.net:idea/community

This commit is contained in:
andrey zaytsev
2011-02-16 21:32:29 +03:00
71 changed files with 1305 additions and 972 deletions
@@ -15,9 +15,9 @@
*/
package com.intellij.compiler;
import com.intellij.compiler.impl.javaCompiler.FileObject;
import com.intellij.openapi.compiler.CompilerMessageCategory;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.compiler.impl.javaCompiler.FileObject;
import org.jetbrains.annotations.NonNls;
import java.util.ArrayList;
@@ -29,6 +29,7 @@ public abstract class OutputParser {
public interface Callback {
@NonNls String getNextLine();
@NonNls String getCurrentLine();
void pushBack(String line);
void setProgressText(String text);
void fileProcessed(@NonNls String path);
void fileGenerated(@NonNls FileObject path);
@@ -44,6 +44,7 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
private final boolean myIsUnitTestMode;
private FileObject myClassFileToProcess = null;
private String myLastReadLine = null;
private String myPushBackLine = null;
private volatile boolean myProcessExited = false;
private final CompileContext myContext;
@@ -104,6 +105,12 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
}
public final String getNextLine() {
final String pushBack = myPushBackLine;
if (pushBack != null) {
myPushBackLine = null;
myLastReadLine = pushBack;
return pushBack;
}
final String line = readLine(myCompilerOutStreamReader);
if (LOG.isDebugEnabled()) {
LOG.debug("LIne read: #" + line + "#");
@@ -120,6 +127,12 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
return myLastReadLine;
}
@Override
public void pushBack(String line) {
myLastReadLine = null;
myPushBackLine = line;
}
public final void fileGenerated(FileObject path) {
// javac first logs file generated, then starts to write the file to disk,
// so this thread sometimes can stumble on not yet existing file,
@@ -131,6 +144,9 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
processCompiledClass(previousPath);
}
catch (CacheCorruptedException e) {
if (CompileDriver.ourDebugMode) {
e.printStackTrace();
}
myError = e;
LOG.info(e);
killProcess();
@@ -164,6 +180,9 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
buffer = StringBuilderSpinAllocator.alloc();
}
catch (SpinAllocator.AllocatorExhaustedException e) {
if (CompileDriver.ourDebugMode) {
e.printStackTrace();
}
LOG.info(e);
buffer = new StringBuilder();
releaseBuffer = false;
@@ -207,6 +226,16 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
try {
while(!reader.ready()) {
if (isProcessTerminated()) {
if (CompileDriver.ourDebugMode) {
String text;
try {
text = reader.ready()? "ready" : "not ready";
}
catch (IOException e) {
text = "Exception " + e.getMessage();
}
System.out.println("COMPILER PARSING THREAD: reader not ready before isTerminatedCheck(), after the check: isReady= " + text);
}
return -1;
}
try {
@@ -218,7 +247,7 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
return reader.read();
}
catch (IOException e) {
return -1; // When process terminated Process.getInputStream()'s underlaying stream becomes closed on Linux.
return -1; // When process terminated Process.getInputStream()'s underlying stream becomes closed on Linux.
}
}
@@ -127,6 +127,14 @@ public class JavacOutputParser extends OutputParser {
final CharSequence chars = prevLine == null ? line : prevLine;
final int offset = Math.max(0, Math.min(chars.length(), nextLine.indexOf('^')));
colNum = EditorUtil.calcColumnNumber(null, chars,0, offset, myTabSize);
String messageEnd = callback.getNextLine();
while (isMessageEnd(messageEnd)) {
messages.add(messageEnd.trim());
messageEnd = callback.getNextLine();
}
if (messageEnd != null) {
callback.pushBack(messageEnd);
}
break;
}
if (prevLine != null) {
@@ -168,6 +176,10 @@ public class JavacOutputParser extends OutputParser {
return true;
}
private static boolean isMessageEnd(String line) {
return line != null && line.length() > 0 && Character.isWhitespace(line.charAt(0));
}
private static List<String> convertMessages(List<String> messages) {
if(messages.size() <= 1) {
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.roots.ui.configuration.libraries.impl;
import com.intellij.internal.statistic.AbstractApplicationUsagesCollector;
import com.intellij.internal.statistic.UsagesCollector;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.internal.statistic.beans.UsageDescriptor;
@@ -34,12 +35,13 @@ import java.util.*;
/**
* @author nik
*/
public class LibraryUsageCollector extends UsagesCollector {
public class LibraryUsageCollector extends AbstractApplicationUsagesCollector {
@NonNls private static final String GROUP_ID = "libraries";
@NotNull
@Override
public Set<UsageDescriptor> getUsages(@Nullable Project project) {
public Set<UsageDescriptor> getProjectUsages(@Nullable Project project) {
if (project == null) return Collections.emptySet();
final Set<LibraryKind<?>> usedKinds = new HashSet<LibraryKind<?>>();
@@ -56,15 +58,13 @@ public class LibraryUsageCollector extends UsagesCollector {
final HashSet<UsageDescriptor> usageDescriptors = new HashSet<UsageDescriptor>();
for (LibraryKind<?> kind : usedKinds) {
final GroupDescriptor group = GroupDescriptor.create(GROUP_ID);
usageDescriptors.add(new UsageDescriptor(group, kind.getKindId(), 1));
usageDescriptors.add(new UsageDescriptor(kind.getKindId(), 1));
}
return usageDescriptors;
}
@NotNull
@Override
public String getGroupId() {
return GROUP_ID;
}
public GroupDescriptor getGroupId() {
return GroupDescriptor.create(GROUP_ID); }
}
@@ -23,13 +23,11 @@ import com.intellij.psi.*;
import com.intellij.psi.statistics.JavaStatisticsManager;
import com.intellij.psi.statistics.StatisticsInfo;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NonNls;
/**
* @author peter
*/
public class JavaCompletionStatistician extends CompletionStatistician{
@NonNls public static final String CLASS_NAME_COMPLETION_PREFIX = "classNameCompletion#";
public StatisticsInfo serialize(final LookupElement element, final CompletionLocation location) {
final Object o = element.getObject();
@@ -76,6 +74,10 @@ public class JavaCompletionStatistician extends CompletionStatistician{
if (!isClass && type == CompletionType.BASIC) return JavaStatisticsManager.createInfo(qualifierType, (PsiMember)o);
return StatisticsInfo.EMPTY;
}
if (isClass) {
return JavaStatisticsManager.createInfo(qualifierType, (PsiMember)o);
}
}
if (qualifierType != null) return StatisticsInfo.EMPTY;
@@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull;
public class PreferLocalVariablesLiteralsAndAnnoMethodsWeigher extends CompletionWeigher {
enum MyResult {
className,
classLiteral,
normal,
superMethodParameters,
@@ -54,6 +55,10 @@ public class PreferLocalVariablesLiteralsAndAnnoMethodsWeigher extends Completio
if (object instanceof PsiAnnotationMethod && ((PsiAnnotationMethod)object).getContainingClass().isAnnotationType()) {
return MyResult.annoMethod;
}
if (object instanceof PsiClass) {
return MyResult.className;
}
}
return MyResult.normal;
@@ -0,0 +1,14 @@
abstract class Base {
public static @interface IfNotParsed {}
static class X {}
}
class Derived extends Base {
}
class B {
void foo(Derived b) {
b.<caret>
}
}
@@ -0,0 +1,4 @@
class Foo {
Baaa<caret>x
}
@@ -8,6 +8,7 @@ import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.impl.LookupImpl;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMethod;
import java.util.List;
@@ -182,4 +183,22 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems(0, "XcodeProjectTemplate", "XcodeConfigurable");
}
public void testFqnStats() {
myFixture.addClass("public interface Baaaaaaar {}");
myFixture.addClass("package zoo; public interface Baaaaaaar {}");
final LookupImpl lookup = invokeCompletion(getTestName(false) + ".java");
assertEquals("Baaaaaaar", ((JavaPsiClassReferenceElement) lookup.getItems().get(0)).getQualifiedName());
assertEquals("zoo.Baaaaaaar", ((JavaPsiClassReferenceElement) lookup.getItems().get(1)).getQualifiedName());
incUseCount(lookup, 1);
assertEquals("zoo.Baaaaaaar", ((JavaPsiClassReferenceElement) lookup.getItems().get(0)).getQualifiedName());
assertEquals("Baaaaaaar", ((JavaPsiClassReferenceElement)lookup.getItems().get(1)).getQualifiedName());
}
public void testDispreferInnerClasses() {
checkPreferredItems(0); //no chosen items
assertFalse(getLookup().getItems().get(0).getObject() instanceof PsiClass);
}
}
@@ -29,7 +29,7 @@ import java.io.IOException;
public interface JavaCodeInsightTestFixture extends CodeInsightTestFixture {
JavaPsiFacade getJavaFacade();
PsiClass addClass(@NotNull @NonNls final String classText) throws IOException;
PsiClass addClass(@NotNull @NonNls final String classText);
@NotNull
PsiClass findClass(@NotNull @NonNls String name);
@@ -27,8 +27,6 @@ import com.intellij.testFramework.fixtures.TempDirTestFixture;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
/**
* @author yole
*/
@@ -44,7 +42,7 @@ public class JavaCodeInsightTestFixtureImpl extends CodeInsightTestFixtureImpl i
}
@Override
public PsiClass addClass(@NotNull @NonNls final String classText) throws IOException {
public PsiClass addClass(@NotNull @NonNls final String classText) {
assertInitialized();
final PsiClass psiClass = addClass(getTempDirPath(), classText);
final VirtualFile file = psiClass.getContainingFile().getVirtualFile();
@@ -38,6 +38,7 @@ import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.patterns.ElementPattern;
import com.intellij.psi.PsiFile;
@@ -102,7 +103,6 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
}
};
private final Semaphore myDuringCompletionSemaphore = new Semaphore();
private static final boolean ourHintAutopopup = "true".equals(System.getProperty("hint.autopopup", "false"));
private volatile int myCount;
@@ -336,7 +336,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
}
}
if (isAutopopupCompletion() && ourHintAutopopup) {
if (isAutopopupCompletion() && showHintAutopopup()) {
myLookup.setHintMode(true);
}
else {
@@ -348,6 +348,10 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
updateFocus();
}
private static boolean showHintAutopopup() {
return "true".equals(Registry.stringValue("hint.autopopup"));
}
final boolean isInsideIdentifier() {
return getIdentifierEndOffset() != getSelectionEndOffset();
}
@@ -463,13 +467,14 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
}
private boolean hideAutopopupIfMeaningless() {
if (ourHintAutopopup) {
return false;
}
if (isAutopopupCompletion() && !myLookup.isSelectionTouched() && !myLookup.isCalculating()) {
myLookup.refreshUi();
for (LookupElement item : myLookup.getItems()) {
final List<LookupElement> items = myLookup.getItems();
if (!items.isEmpty() && showHintAutopopup()) {
return false;
}
for (LookupElement item : items) {
if (!(item.getPrefixMatcher().getPrefix() + myLookup.getAdditionalPrefix()).equals(item.getLookupString())) {
return false;
}
@@ -15,6 +15,7 @@
*/
package com.intellij.codeInsight.lookup;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
@@ -71,7 +72,7 @@ public abstract class ComparingClassifier<T> extends Classifier<T> {
@Override
public void describeItems(LinkedHashMap<T, StringBuilder> map) {
final TreeMap<Comparable, List<T>> treeMap = groupByWeights(new ArrayList<T>(map.keySet()));
if (treeMap.size() > 1) {
if (treeMap.size() > 1 || ApplicationManager.getApplication().isUnitTestMode()) {
for (Map.Entry<Comparable, List<T>> entry: treeMap.entrySet()){
for (T t : entry.getValue()) {
final StringBuilder builder = map.get(t);
@@ -566,9 +566,10 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
/**
* @return point in layered pane coordinate system.
* @param component
*/
public Point calculatePosition(){
Dimension dim = getComponent().getPreferredSize();
public Point calculatePosition(final JComponent component){
Dimension dim = component.getPreferredSize();
int lookupStart = getLookupStart();
if (lookupStart < 0) {
LOG.error(lookupStart + "; minprefix=" + myMinPrefixLength + "; offset=" + myEditor.getCaretModel().getOffset() + "; element=" +
@@ -587,7 +588,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
JLayeredPane layeredPane = rootPane.getLayeredPane();
Point layeredPanePoint=SwingUtilities.convertPoint(internalComponent,location, layeredPane);
layeredPanePoint.x -= myCellRenderer.getIconIndent();
layeredPanePoint.x -= getComponent().getInsets().left;
layeredPanePoint.x -= component.getInsets().left;
int shiftLow = layeredPane.getHeight() - (layeredPanePoint.y + dim.height);
int shiftHigh = layeredPanePoint.y - dim.height;
@@ -684,7 +685,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
getComponent().setBorder(null);
updateScrollbarVisibility();
Point p = calculatePosition();
Point p = calculatePosition(getComponent());
HintManagerImpl.getInstanceImpl().showEditorHint(this, myEditor, p, HintManagerImpl.HIDE_BY_ESCAPE | HintManagerImpl.UPDATE_BY_SCROLLING, 0, false);
final JLayeredPane layeredPane = getComponent().getRootPane().getLayeredPane();
@@ -1121,7 +1122,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
}
updateScrollbarVisibility();
HintManagerImpl.adjustEditorHintPosition(this, editor, calculatePosition());
HintManagerImpl.adjustEditorHintPosition(this, editor, calculatePosition(getComponent()));
layoutStatusIcons();
if (reused) {
@@ -1129,12 +1130,11 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
}
}
else if (myHintMode) {
hideAutopopupHint();
final int itemTextPadding = 2;
final int borderWidth = 1;
final int borderWidth = 0;
Point bestPoint = calculatePosition();
final JPanel hintComponent = createAutopopupHintComponent(itemTextPadding, borderWidth);
Point bestPoint = calculatePosition(hintComponent);
bestPoint.x += myCellRenderer.getIconIndent() - itemTextPadding - borderWidth;
Point editorPoint = SwingUtilities.convertPoint(
editor.getComponent().getRootPane().getLayeredPane(),
@@ -1145,13 +1145,24 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
final HintHint hintHint = new HintHint(editor, editorPoint).setHighlighterType(true).setContentActive(true);
final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
myAutopopupHint = new LightweightHint(createAutopopupHintComponent(itemTextPadding, borderWidth));
hintManager.showEditorHint(myAutopopupHint, editor, bestPoint, HintManagerImpl.HIDE_BY_ESCAPE | HintManagerImpl.UPDATE_BY_SCROLLING, 0, false, hintHint);
if (myAutopopupHint == null) {
final JPanel panel = new JPanel(new BorderLayout());
panel.add(hintComponent);
myAutopopupHint = new LightweightHint(panel);
myAutopopupHint.setForceShowAsPopup(true);
hintManager.showEditorHint(myAutopopupHint, editor, new Point(bestPoint),
HintManagerImpl.HIDE_BY_ESCAPE | HintManagerImpl.UPDATE_BY_SCROLLING, 0, false, hintHint);
} else {
final JComponent panel = myAutopopupHint.getComponent();
panel.remove(0);
panel.add(hintComponent);
HintManagerImpl.adjustEditorHintPosition(myAutopopupHint, editor, bestPoint);
}
}
}
private JPanel createAutopopupHintComponent(int itemTextPadding, int borderWidth) {
int maxAutopopupItems = 10;
int maxAutopopupItems = 7;
JPanel pane = new JPanel(new GridBagLayout());
pane.setBackground(HintUtil.INFORMATION_COLOR);
@@ -1189,11 +1200,10 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
final GridBagConstraints c = new GridBagConstraints();
c.gridx = 1;
c.gridy = i;
c.ipadx = 4;
c.fill = GridBagConstraints.HORIZONTAL;
final JLabel comp = new JLabel(" " + StringUtil.notNullize(presentation.getTypeText()));
final JLabel comp = new JLabel(" " + StringUtil.notNullize(presentation.getTypeText()) + " ");
comp.setFont(comp.getFont().deriveFont(Font.PLAIN, editorFont.getSize()));
comp.setAlignmentX(Component.RIGHT_ALIGNMENT);
comp.setHorizontalAlignment(SwingConstants.RIGHT);
pane.add(comp, c);
}
}
@@ -1211,17 +1221,20 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
KeymapUtil
.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION)) +
" for more suggestions)";
pane.add(new JLabel(moreText), c);
final JLabel label = new JLabel(moreText);
label.setFont(label.getFont().deriveFont(Font.PLAIN, editorFont.getSize()));
pane.add(label, c);
}
}
pane.setBorder(new LineBorder(Color.darkGray, borderWidth));
//pane.setBorder(new LineBorder(Color.darkGray, borderWidth));
return pane;
}
private void hideAutopopupHint() {
if (myAutopopupHint != null) {
myAutopopupHint.hide();
myPositionedAbove = null;
}
}
@@ -904,7 +904,6 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
}
public void printHyperlink(final String hyperlinkText, final HyperlinkInfo info) {
if (myEditor == null) return;
printHyperlink(hyperlinkText, ConsoleViewContentType.NORMAL_OUTPUT, info);
}
@@ -1,42 +0,0 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.facet.impl.statistics;
import com.intellij.openapi.project.Project;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.util.containers.HashMap;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.Set;
public abstract class FrameworkStatisticsPersistence {
private Map<String, Set<UsageDescriptor>> myFrameworks = new HashMap<String, Set<UsageDescriptor>>();
public FrameworkStatisticsPersistence() {
}
public void persistFrameworks(@NotNull Project project, @NotNull Set<UsageDescriptor> frameworks) {
myFrameworks.put(project.getName(), frameworks);
}
@NotNull
public Map<String, Set<UsageDescriptor>> getFrameworks() {
return myFrameworks;
}
}
@@ -1,146 +0,0 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.facet.impl.statistics;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.ProjectManagerListener;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.Function;
import com.intellij.util.containers.HashSet;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Set;
@State(
name = "FrameworkUsages",
storages = {
@Storage(
id = "frameworks",
file = "$APP_CONFIG$/framework.usages.xml"
)}
)
public class FrameworkStatisticsPersistenceComponent extends FrameworkStatisticsPersistence
implements ApplicationComponent, PersistentStateComponent<Element> {
private static final String TOKENIZER = ",";
@NonNls private static final String PROJECT_TAG = "project";
@NonNls private static final String PROJECT_ID_ATTR = "id";
@NonNls private static final String FRAMEWORKS_ATTR = "frameworks";
public FrameworkStatisticsPersistenceComponent() {
}
public static FrameworkStatisticsPersistenceComponent getInstance() {
return ApplicationManager.getApplication().getComponent(FrameworkStatisticsPersistenceComponent.class);
}
public void loadState(final Element element) {
List projectsList = element.getChildren(PROJECT_TAG);
for (Object project : projectsList) {
Element projectElement = (Element)project;
String projectId = projectElement.getAttributeValue(PROJECT_ID_ATTR);
String frameworks = projectElement.getAttributeValue(FRAMEWORKS_ATTR);
if (!StringUtil.isEmptyOrSpaces(projectId) && !StringUtil.isEmptyOrSpaces(frameworks)) {
Set<UsageDescriptor> frameworkDescriptors = new HashSet<UsageDescriptor>();
for (String key : StringUtil.split(frameworks, TOKENIZER)) {
frameworkDescriptors.add(new UsageDescriptor(FrameworkUsagesCollector.getGroupDescriptor(), key, 1));
}
getFrameworks().put(projectId, frameworkDescriptors);
}
}
}
public Element getState() {
Element element = new Element("state");
for (Map.Entry<String, Set<UsageDescriptor>> frameworks : getFrameworks().entrySet()) {
Element projectElement = new Element(PROJECT_TAG);
projectElement.setAttribute(PROJECT_ID_ATTR, frameworks.getKey());
projectElement.setAttribute(FRAMEWORKS_ATTR, joinUsages(frameworks.getValue()));
element.addContent(projectElement);
}
return element;
}
private static String joinUsages(@NotNull Set<UsageDescriptor> usages) {
return StringUtil.join(usages, new Function<UsageDescriptor, String>() {
@Override
public String fun(UsageDescriptor usageDescriptor) {
return usageDescriptor.getKey();
}
}, TOKENIZER);
}
@NotNull
@NonNls
public File[] getExportFiles() {
return new File[]{PathManager.getOptionsFile("framework.usages")};
}
@NotNull
public String getPresentableName() {
return "Framework Usages";
}
@NonNls
@NotNull
public String getComponentName() {
return "FrameworkStatisticsPersistenceComponent";
}
public void initComponent() {
ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerListener() {
@Override
public void projectOpened(Project project) {
}
@Override
public boolean canCloseProject(Project project) {
return true;
}
@Override
public void projectClosed(Project project) {
}
@Override
public void projectClosing(Project project) {
if (project != null) {
FrameworkUsagesCollector.persistProjectUsages(project);
}
}
});
}
public void disposeComponent() {
}
}
@@ -17,84 +17,31 @@ package com.intellij.facet.impl.statistics;
import com.intellij.facet.Facet;
import com.intellij.facet.FacetManager;
import com.intellij.internal.statistic.AbstractApplicationUsagesCollector;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import com.intellij.internal.statistic.UsagesCollector;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashSet;
import com.intellij.util.containers.hash.HashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.Set;
public class FrameworkUsagesCollector extends UsagesCollector {
public class FrameworkUsagesCollector extends AbstractApplicationUsagesCollector {
public static final String GROUP_ID = "frameworks";
public static void persistProjectUsages(@NotNull Project project) {
persistProjectUsages(project, getProjectUsages(project));
}
public static void persistProjectUsages(@NotNull Project project, @NotNull Set<UsageDescriptor> usages) {
persistProjectUsages(project, usages, FrameworkStatisticsPersistenceComponent.getInstance());
}
public static void persistProjectUsages(@NotNull Project project,
@NotNull Set<UsageDescriptor> usages,
@NotNull FrameworkStatisticsPersistence persistence) {
persistence.persistFrameworks(project, usages);
}
@NotNull
public Set<UsageDescriptor> getApplicationUsages() {
return getApplicationUsages(FrameworkStatisticsPersistenceComponent.getInstance());
}
@NotNull
public Set<UsageDescriptor> getApplicationUsages(@NotNull final FrameworkStatisticsPersistence persistence) {
final Map<String, Integer> facets = new HashMap<String, Integer>();
for (Set<UsageDescriptor> frameworks : persistence.getFrameworks().values()) {
for (UsageDescriptor framework : frameworks) {
final String key = framework.getKey();
final Integer count = facets.get(key);
facets.put(key, count == null ? 1 : count.intValue() + 1);
}
}
return ContainerUtil.map2Set(facets.entrySet(), new Function<Map.Entry<String, Integer>, UsageDescriptor>() {
@Override
public UsageDescriptor fun(Map.Entry<String, Integer> facet) {
return new UsageDescriptor(getGroupDescriptor(), facet.getKey(), facet.getValue());
}
});
}
@NotNull
@Override
public String getGroupId() {
return GROUP_ID;
}
public static GroupDescriptor getGroupDescriptor() {
public GroupDescriptor getGroupId() {
return GroupDescriptor.create(GROUP_ID, GroupDescriptor.HIGHER_PRIORITY);
}
@NotNull
public Set<UsageDescriptor> getUsages(@Nullable Project project) {
if (project != null) {
persistProjectUsages(project, getProjectUsages(project));
}
return getApplicationUsages();
}
public static Set<UsageDescriptor> getProjectUsages(@NotNull Project project) {
public Set<UsageDescriptor> getProjectUsages(@NotNull Project project) {
final Set<String> facets = new HashSet<String>();
for (Module module : ModuleManager.getInstance(project).getModules()) {
for (Facet facet : FacetManager.getInstance(module).getAllFacets()) {
@@ -105,7 +52,7 @@ public class FrameworkUsagesCollector extends UsagesCollector {
return ContainerUtil.map2Set(facets, new Function<String, UsageDescriptor>() {
@Override
public UsageDescriptor fun(String facet) {
return new UsageDescriptor(getGroupDescriptor(), facet, 1);
return new UsageDescriptor(facet, 1);
}
});
}
@@ -458,18 +458,18 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec
}
throw new AssertionError(msg);
}
} else if (document.getTextLength() - textBlock.getTextEndOffset() != file.getTextLength() - psiEndOffset) {
} else if (document.getTextLength() - textBlock.getTextEndOffset() != myTreeElementBeingReparsedSoItWontBeCollected.getTextLength() - psiEndOffset) {
throw new AssertionError("PSI/document inconsistency before reparse: file=" + file);
}
}
else {
startOffset = 0;
endOffset = document.getTextLength();
lengthShift = document.getTextLength() - file.getTextLength();
lengthShift = document.getTextLength() - myTreeElementBeingReparsedSoItWontBeCollected.getTextLength();
}
myBlockSupport.reparseRange(file, startOffset, endOffset, lengthShift, chars);
if (file.getTextLength() != document.getTextLength()) {
if (myTreeElementBeingReparsedSoItWontBeCollected.getTextLength() != document.getTextLength()) {
if (ApplicationManagerEx.getApplicationEx().isInternal()) {
boolean x = false;
if (x) {
@@ -477,7 +477,7 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec
}
String fileText = file.getText();
String documentText = document.getText();
throw new AssertionError("commitDocument left PSI inconsistent; file len=" + file.getTextLength() +
throw new AssertionError("commitDocument left PSI inconsistent; file len=" + myTreeElementBeingReparsedSoItWontBeCollected.getTextLength() +
"; doc len=" + document.getTextLength() +
"; doc.getText() == file.getText(): " + Comparing.equal(fileText, documentText) +
";\n file text=" + fileText +
@@ -87,11 +87,10 @@ public class BlockSupportImpl extends BlockSupport {
file.getViewProvider().beforeContentsSynchronized();
final PsiFileImpl fileImpl = (PsiFileImpl)file;
Project project = fileImpl.getProject();
final FileElement treeFileElement = fileImpl.getTreeElement();
final CharTable charTable = treeFileElement.getCharTable();
// hack
final int textLength = file.getTextLength() + lengthShift;
final CharTable charTable = fileImpl.getTreeElement().getCharTable();
final FileElement treeFileElement = fileImpl.getTreeElement();
final int textLength = treeFileElement.getTextLength() + lengthShift;
if (treeFileElement.getElementType() instanceof ITemplateDataElementType || isTooDeep(file)) {
// unable to perform incremental reparse for template data in JSP, or in exceptionally deep trees
@@ -369,7 +369,7 @@ public class HintManagerImpl extends HintManager implements Disposable {
p = rectangle.getLocation();
SwingUtilities.convertPointFromScreen(p, layeredPane);
}
else if ((layeredPane.getWidth() < p.x + size.width) && !hintInfo.isAwtTooltip()) {
else if ((layeredPane.getWidth() < p.x + size.width) && !hintInfo.isAwtTooltip() && !hint.isRealPopup()) {
p.x = Math.max(0, layeredPane.getWidth() - size.width);
}
@@ -29,8 +29,8 @@ public class FeaturesUsageCollector extends UsagesCollector {
@NotNull
@Override
public String getGroupId() {
return "productivity";
public GroupDescriptor getGroupId() {
return GroupDescriptor.create("productivity", GroupDescriptor.LOWER_PRIORITY);
}
@NotNull
@@ -44,8 +44,7 @@ public class FeaturesUsageCollector extends UsagesCollector {
for (String featureId : registry.getFeatureIds()) {
final FeatureDescriptor featureDescriptor = registry.getFeatureDescriptor(featureId);
if (featureDescriptor != null) {
usages.add(new UsageDescriptor(
GroupDescriptor.create(getGroupId(), GroupDescriptor.LOWER_PRIORITY), featureId, featureDescriptor.getUsageCount()));
usages.add(new UsageDescriptor(featureId, featureDescriptor.getUsageCount()));
}
}
@@ -30,8 +30,8 @@ public class PluginsUsagesCollector extends UsagesCollector {
private static final String GROUP_ID = "disabled-plugins";
@NotNull
public String getGroupId() {
return GROUP_ID;
public GroupDescriptor getGroupId() {
return GroupDescriptor.create(GROUP_ID, GroupDescriptor.HIGHER_PRIORITY);
}
@NotNull
@@ -39,7 +39,7 @@ public class PluginsUsagesCollector extends UsagesCollector {
return ContainerUtil.map2Set(PluginManager.getDisabledPlugins(), new Function<String, UsageDescriptor>() {
@Override
public UsageDescriptor fun(String descriptor) {
return new UsageDescriptor(GroupDescriptor.create(getGroupId(), GroupDescriptor.HIGHER_PRIORITY), descriptor, 1);
return new UsageDescriptor(descriptor, 1);
}
});
}
@@ -0,0 +1,67 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.internal.focus;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.openapi.wm.impl.FocusManagerImpl;
import com.intellij.openapi.wm.impl.FocusRequestInfo;
import java.util.ArrayList;
import java.util.List;
/**
* @author Konstantin Bulenkov
*/
public class FocusTracesAction extends AnAction implements DumbAware {
private static boolean myActive = false;
public static boolean isActive() {
return myActive;
}
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = e.getData(PlatformDataKeys.PROJECT);
final IdeFocusManager manager = IdeFocusManager.getGlobalInstance();
if (! (manager instanceof FocusManagerImpl)) return;
final FocusManagerImpl focusManager = (FocusManagerImpl)manager;
myActive = !myActive;
if (!myActive) {
final List<FocusRequestInfo> requests = focusManager.getRequests();
new FocusTracesDialog(project, new ArrayList<FocusRequestInfo>(requests)).show();
requests.clear();
}
}
@Override
public void update(AnActionEvent e) {
final Presentation presentation = e.getPresentation();
if (myActive) {
presentation.setText("Stop Focus Tracing");
} else {
presentation.setText("Start Focus Tracing");
}
presentation.setEnabled(e.getData(PlatformDataKeys.PROJECT) != null);
}
}
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.internal.focus.FocusTracesDialog">
<grid id="27dc6" binding="myRootPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties>
<preferredSize width="500" height="400"/>
</properties>
<border type="none"/>
<children>
<splitpane id="227bc">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="200" height="200"/>
</grid>
</constraints>
<properties>
<orientation value="0"/>
</properties>
<border type="none"/>
<children>
<component id="37ff7" class="javax.swing.JTextPane" binding="myStacktrace">
<constraints>
<splitpane position="right"/>
</constraints>
<properties/>
</component>
<scrollpane id="ef29" class="com.intellij.ui.components.JBScrollPane">
<constraints>
<splitpane position="left"/>
</constraints>
<properties>
<minimumSize width="23" height="250"/>
</properties>
<border type="none"/>
<children>
<component id="3cc44" class="com.intellij.ui.table.JBTable" binding="myRequestsTable">
<constraints/>
<properties>
<autoResizeMode value="3"/>
<autoscrolls value="false"/>
<minimumSize width="30" height="250"/>
<preferredSize width="150" height="150"/>
</properties>
</component>
</children>
</scrollpane>
</children>
</splitpane>
</children>
</grid>
</form>
@@ -0,0 +1,105 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.internal.focus;
import com.intellij.openapi.ide.CopyPasteManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.wm.impl.FocusRequestInfo;
import com.intellij.ui.table.JBTable;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;
/**
* @author Konstantin Bulenkov
*/
public class FocusTracesDialog extends DialogWrapper {
private JTextPane myStacktrace;
private JBTable myRequestsTable;
private JPanel myRootPanel;
private final List<FocusRequestInfo> myRequests;
private static final String[] COLUMNS = {"Time", "Forced", "Component"};
public FocusTracesDialog(Project project, ArrayList<FocusRequestInfo> requests) {
super(project);
myRequests = requests;
setTitle("Focus Traces");
init();
final String[][] data = new String[requests.size()][];
for (int i = 0; i < data.length; i++) {
final FocusRequestInfo r = requests.get(i);
data[i] = new String[]{r.getDate(), String.valueOf(r.isForced()), r.getComponent()};
}
myRequestsTable.setModel(new DefaultTableModel(data, COLUMNS));
final ListSelectionListener selectionListener = new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
final int index = myRequestsTable.getSelectedRow();
if (-1 < index && index < myRequests.size()) {
myStacktrace.setText(myRequests.get(index).getStackTrace());
}
else {
myStacktrace.setText("");
}
}
};
myRequestsTable.getSelectionModel().addListSelectionListener(selectionListener);
final TableColumnModel columnModel = myRequestsTable.getColumnModel();
columnModel.getColumn(0).setMaxWidth(120);
columnModel.getColumn(1).setMaxWidth(60);
columnModel.getSelectionModel().addListSelectionListener(selectionListener);
columnModel.setColumnSelectionAllowed(false);
myRequestsTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
myRequestsTable.changeSelection(0, 0, false, true);
}
@Override
protected String getDimensionServiceKey() {
return "ide.internal.focus.trace.dialog";
}
@Override
protected JComponent createCenterPanel() {
return myRootPanel;
}
@Override
public JComponent getPreferredFocusedComponent() {
return myRequestsTable;
}
@Override
protected Action[] createActions() {
return new Action[] {getOKAction(), getCopyStackTraceAction()};
}
private Action getCopyStackTraceAction() {
return new AbstractAction("&Copy stacktrace") {
@Override
public void actionPerformed(ActionEvent e) {
CopyPasteManager.getInstance().setContents(new StringSelection(myStacktrace.getText()));
}
};
}
}
@@ -0,0 +1,82 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.internal.statistic;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.internal.statistic.persistence.ApplicationStatisticsPersistence;
import com.intellij.internal.statistic.persistence.ApplicationStatisticsPersistenceComponent;
import com.intellij.openapi.project.Project;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.hash.HashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.Set;
public abstract class AbstractApplicationUsagesCollector extends UsagesCollector {
public void persistProjectUsages(@NotNull Project project) {
persistProjectUsages(project, getProjectUsages(project));
}
public void persistProjectUsages(@NotNull Project project, @NotNull Set<UsageDescriptor> usages) {
persistProjectUsages(project, usages, ApplicationStatisticsPersistenceComponent.getInstance());
}
public void persistProjectUsages(@NotNull Project project,
@NotNull Set<UsageDescriptor> usages,
@NotNull ApplicationStatisticsPersistence persistence) {
persistence.persistFrameworks(getGroupId(), project, usages);
}
@NotNull
public Set<UsageDescriptor> getApplicationUsages() {
return getApplicationUsages(ApplicationStatisticsPersistenceComponent.getInstance());
}
@NotNull
public Set<UsageDescriptor> getApplicationUsages(@NotNull final ApplicationStatisticsPersistence persistence) {
final Map<String, Integer> facets = new HashMap<String, Integer>();
for (Set<UsageDescriptor> frameworks : persistence.getApplicationData(getGroupId()).values()) {
for (UsageDescriptor framework : frameworks) {
final String key = framework.getKey();
final Integer count = facets.get(key);
facets.put(key, count == null ? 1 : count.intValue() + 1);
}
}
return ContainerUtil.map2Set(facets.entrySet(), new Function<Map.Entry<String, Integer>, UsageDescriptor>() {
@Override
public UsageDescriptor fun(Map.Entry<String, Integer> facet) {
return new UsageDescriptor(facet.getKey(), facet.getValue());
}
});
}
@NotNull
public Set<UsageDescriptor> getUsages(@Nullable Project project) {
if (project != null) {
persistProjectUsages(project, getProjectUsages(project));
}
return getApplicationUsages();
}
@NotNull
public abstract Set<UsageDescriptor> getProjectUsages(@NotNull Project project);
}
@@ -30,7 +30,7 @@ import com.intellij.openapi.util.Pair;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashSet;
import com.intellij.util.text.DateFormatUtil;
import com.intellij.util.containers.hash.HashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -38,173 +38,204 @@ import java.util.*;
public class StatisticsUploadAssistant {
public String getData() {
return getData(Collections.<String>emptySet());
}
public String getData() {
return getData(Collections.<String>emptySet());
}
public static boolean showNotification() {
return UsageStatisticsPersistenceComponent.getInstance().isShowNotification();
}
public static boolean showNotification() {
return UsageStatisticsPersistenceComponent.getInstance().isShowNotification();
}
public static boolean isTimeToSend() {
if (ApplicationManagerEx.getApplicationEx().isInternal()) return true; // todo remove
public static boolean isTimeToSend() {
if (ApplicationManagerEx.getApplicationEx().isInternal()) return true; // todo remove
return isTimeToSend(UsageStatisticsPersistenceComponent.getInstance());
}
return isTimeToSend(UsageStatisticsPersistenceComponent.getInstance());
}
public static boolean isTimeToSend(UsageStatisticsPersistenceComponent settings) {
final long timeDelta = System.currentTimeMillis() - settings.getLastTimeSent();
public static boolean isTimeToSend(UsageStatisticsPersistenceComponent settings) {
final long timeDelta = System.currentTimeMillis() - settings.getLastTimeSent();
return Math.abs(timeDelta) > settings.getPeriod().getMillis();
}
return Math.abs(timeDelta) > settings.getPeriod().getMillis();
}
public static boolean isSendAllowed() {
if (ApplicationManagerEx.getApplicationEx().isInternal()) return true; // todo remove
public static boolean isSendAllowed() {
if (ApplicationManagerEx.getApplicationEx().isInternal()) return true; // todo remove
return isSendAllowed(UsageStatisticsPersistenceComponent.getInstance());
}
return isSendAllowed(UsageStatisticsPersistenceComponent.getInstance());
}
public static boolean isSendAllowed(final SentUsagesPersistence settings) {
return settings != null && settings.isAllowed();
}
public static boolean isSendAllowed(final SentUsagesPersistence settings) {
return settings != null && settings.isAllowed();
}
public static String getData(@NotNull Set<String> disabledGroups) {
return getStringPatch(disabledGroups, ProjectManager.getInstance().getOpenProjects());
}
public static String getData(@NotNull Set<String> disabledGroups) {
return getStringPatch(disabledGroups, ProjectManager.getInstance().getOpenProjects());
}
public static void persistSentPatch(@NotNull String patchStr) {
persistSentPatch(patchStr, UsageStatisticsPersistenceComponent.getInstance());
}
public static void persistSentPatch(@NotNull String patchStr) {
persistSentPatch(patchStr, UsageStatisticsPersistenceComponent.getInstance());
}
public static void persistSentPatch(@NotNull String patchStr, @NotNull SentUsagesPersistence persistenceComponent) {
Set<PatchedUsage> patchedUsages =
ContainerUtil.map2Set(ConvertUsagesUtil.convertString(patchStr), new Function<UsageDescriptor, PatchedUsage>() {
@Override
public PatchedUsage fun(UsageDescriptor usageDescriptor) {
return new PatchedUsage(usageDescriptor);
public static void persistSentPatch(@NotNull String patchStr, @NotNull SentUsagesPersistence persistenceComponent) {
Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages = mapToPatchedUsagesMap(ConvertUsagesUtil.convertString(patchStr));
if (patchedUsages.size() > 0) persistenceComponent.persistPatch(patchedUsages);
}
@NotNull
public static String getStringPatch(@NotNull Set<String> disabledGroups, Project... project) {
return getStringPatch(disabledGroups, project, UsageStatisticsPersistenceComponent.getInstance(), 0);
}
@NotNull
public static String getStringPatch(@NotNull Set<String> disabledGroups,
@NotNull Project[] projects,
@NotNull SentUsagesPersistence usagesPersistence,
int maxSize) {
final Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages = getPatchedUsages(disabledGroups, projects, usagesPersistence);
return getStringPatch(patchedUsages, maxSize);
}
public static String getStringPatch(@NotNull Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages, int maxSize) {
if (patchedUsages.size() == 0) return "";
String patchStr = ConvertUsagesUtil.convertUsages(patchedUsages);
if (maxSize > 0 && patchStr.getBytes().length > maxSize) {
patchStr = ConvertUsagesUtil.cutPatchString(patchStr, maxSize);
}
});
if (patchedUsages.size() > 0) persistenceComponent.persistPatch(patchedUsages);
}
@NotNull
public static String getStringPatch(@NotNull Set<String> disabledGroups, Project... project) {
return getStringPatch(disabledGroups, project, UsageStatisticsPersistenceComponent.getInstance(), 0);
}
@NotNull
public static String getStringPatch(@NotNull Set<String> disabledGroups,
@NotNull Project[] projects,
@NotNull SentUsagesPersistence usagesPersistence,
int maxSize) {
final Set<PatchedUsage> patchedUsages = getPatchedUsages(disabledGroups, projects, usagesPersistence);
return getStringPatch(patchedUsages, maxSize);
}
public static String getStringPatch(@NotNull Set<PatchedUsage> patchedUsages, int maxSize) {
if (patchedUsages.size() == 0) return "";
String patchStr = ConvertUsagesUtil.convertUsages(patchedUsages);
if (maxSize > 0 && patchStr.getBytes().length > maxSize) {
patchStr = ConvertUsagesUtil.cutPatchString(patchStr, maxSize);
return patchStr;
}
return patchStr;
}
@NotNull
public static Map<GroupDescriptor, Set<PatchedUsage>> getPatchedUsages(@NotNull Set<String> disabledGroups,
@NotNull Project[] projects,
@NotNull SentUsagesPersistence usagesPersistence) {
Map<GroupDescriptor, Set<PatchedUsage>> usages = new HashMap<GroupDescriptor, Set<PatchedUsage>>();
@NotNull
public static Set<PatchedUsage> getPatchedUsages(@NotNull Set<String> disabledGroups,
@NotNull Project[] projects,
@NotNull SentUsagesPersistence usagesPersistence) {
Set<PatchedUsage> usages = new HashSet<PatchedUsage>();
for (Project project : projects) {
final Map<GroupDescriptor, Set<UsageDescriptor>> allUsages = getAllUsages(project, disabledGroups);
final Map<GroupDescriptor, Set<UsageDescriptor>> sentUsages = filterDisabled(disabledGroups, usagesPersistence.getSentUsages());
for (Project project : projects) {
final Set<UsageDescriptor> allUsages = getAllUsages(project, disabledGroups);
final Set<UsageDescriptor> sentUsages = filterDisabled(disabledGroups, usagesPersistence.getSentUsages());
usages.addAll(getPatchedUsages(allUsages, sentUsages));
}
return usages;
}
private static Set<UsageDescriptor> filterDisabled(@NotNull Set<String> disabledGroups, @NotNull Set<UsageDescriptor> usages) {
Set<UsageDescriptor> filtered = new HashSet<UsageDescriptor>();
for (UsageDescriptor usage : usages) {
if (!disabledGroups.contains(usage.getGroup().getId())) {
filtered.add(usage);
}
}
return filtered;
}
@NotNull
public static Set<PatchedUsage> getPatchedUsages(@NotNull final Set<UsageDescriptor> allUsages,
@NotNull SentUsagesPersistence usagesPersistence) {
return getPatchedUsages(allUsages, usagesPersistence.getSentUsages());
}
@NotNull
public static Set<PatchedUsage> getPatchedUsages(@NotNull final Set<UsageDescriptor> allUsages, final Set<UsageDescriptor> sentUsages) {
final Set<PatchedUsage> patchedUsages = ContainerUtil.map2Set(allUsages, new Function<UsageDescriptor, PatchedUsage>() {
@Override
public PatchedUsage fun(UsageDescriptor usageDescriptor) {
return new PatchedUsage(usageDescriptor);
}
});
for (UsageDescriptor sentUsage : sentUsages) {
final PatchedUsage descriptor = findDescriptor(patchedUsages, Pair.create(sentUsage.getGroup(), sentUsage.getKey()));
if (descriptor == null) {
patchedUsages.add(new PatchedUsage(sentUsage.getGroup(), sentUsage.getKey(), -sentUsage.getValue()));
}
else {
descriptor.subValue(sentUsage.getValue());
}
usages.putAll(getPatchedUsages(allUsages, sentUsages));
}
return usages;
}
return packCollection(patchedUsages, new Condition<PatchedUsage>() {
@Override
public boolean value(PatchedUsage patchedUsage) {
return patchedUsage.getDelta() != 0;
}
});
}
@NotNull
private static Map<GroupDescriptor, Set<UsageDescriptor>> filterDisabled(@NotNull Set<String> disabledGroups, @NotNull Map<GroupDescriptor, Set<UsageDescriptor>> usages) {
Map<GroupDescriptor, Set<UsageDescriptor>> filtered = new HashMap<GroupDescriptor, Set<UsageDescriptor>>();
@NotNull
private static <T> Set<T> packCollection(@NotNull Collection<T> set, @NotNull Condition<T> condition) {
final Set<T> result = new LinkedHashSet<T>();
for (T t : set) {
if (condition.value(t)) {
result.add(t);
}
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> usage : usages.entrySet()) {
if (!disabledGroups.contains(usage.getKey().getId())) {
filtered.put(usage.getKey(), usage.getValue());
}
}
return filtered;
}
return result;
}
@Nullable
public static <T extends UsageDescriptor> T findDescriptor(@NotNull Set<T> descriptors,
@NotNull final Pair<GroupDescriptor, String> id) {
return ContainerUtil.find(descriptors, new Condition<T>() {
@Override
public boolean value(T t) {
return id.getFirst().equals(t.getGroup()) && id.getSecond().equals(t.getKey());
}
});
}
@NotNull
public static Set<UsageDescriptor> getAllUsages(@Nullable Project project, @NotNull Set<String> disabledGroups) {
final Set<UsageDescriptor> usageDescriptors = new TreeSet<UsageDescriptor>();
for (UsagesCollector usagesCollector : Extensions.getExtensions(UsagesCollector.EP_NAME)) {
if (!disabledGroups.contains(usagesCollector.getGroupId())) {
usageDescriptors.addAll(usagesCollector.getUsages(project));
}
@NotNull
public static Map<GroupDescriptor, Set<PatchedUsage>> getPatchedUsages(@NotNull final Map<GroupDescriptor, Set<UsageDescriptor>> allUsages,
@NotNull SentUsagesPersistence usagesPersistence) {
return getPatchedUsages(allUsages, usagesPersistence.getSentUsages());
}
@NotNull
public static Map<GroupDescriptor, Set<PatchedUsage>> getPatchedUsages(@NotNull final Map<GroupDescriptor, Set<UsageDescriptor>> allUsages, final Map<GroupDescriptor, Set<UsageDescriptor>> sentUsageMap) {
Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages = mapToPatchedUsagesMap(allUsages);
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> sentUsageEntry : sentUsageMap.entrySet()) {
final GroupDescriptor sentUsageGroupDescriptor = sentUsageEntry.getKey();
final Set<UsageDescriptor> sentUsages = sentUsageEntry.getValue();
for (UsageDescriptor sentUsage : sentUsages) {
final PatchedUsage descriptor = findDescriptor(patchedUsages, Pair.create(sentUsageGroupDescriptor, sentUsage.getKey()));
if (descriptor == null) {
if (!patchedUsages.containsKey(sentUsageGroupDescriptor)) {
patchedUsages.put(sentUsageGroupDescriptor, new HashSet<PatchedUsage>());
}
patchedUsages.get(sentUsageGroupDescriptor).add(new PatchedUsage(sentUsage.getKey(), -sentUsage.getValue()));
} else {
descriptor.subValue(sentUsage.getValue());
}
}
}
return packCollection(patchedUsages, new Condition<PatchedUsage>() {
@Override
public boolean value(PatchedUsage patchedUsage) {
return patchedUsage.getDelta() != 0;
}
});
}
private static Map<GroupDescriptor, Set<PatchedUsage>> mapToPatchedUsagesMap(Map<GroupDescriptor, Set<UsageDescriptor>> allUsages) {
Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages = new HashMap<GroupDescriptor, Set<PatchedUsage>>();
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> entry : allUsages.entrySet()) {
patchedUsages.put(entry.getKey(), ContainerUtil.map2Set(entry.getValue(), new Function<UsageDescriptor, PatchedUsage>() {
@Override
public PatchedUsage fun(UsageDescriptor usageDescriptor) {
return new PatchedUsage(usageDescriptor);
}
}));
}
return patchedUsages;
}
@NotNull
private static Map<GroupDescriptor, Set<PatchedUsage>> packCollection(@NotNull Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages, Condition<PatchedUsage> condition) {
Map<GroupDescriptor, Set<PatchedUsage>> result = new HashMap<GroupDescriptor, Set<PatchedUsage>>();
for (GroupDescriptor descriptor : patchedUsages.keySet()) {
final Set<PatchedUsage> usages = packCollection(patchedUsages.get(descriptor), condition);
if (usages.size() > 0) {
result.put(descriptor, usages);
}
}
return result;
}
@NotNull
private static <T> Set<T> packCollection(@NotNull Collection<T> set, @NotNull Condition<T> condition) {
final Set<T> result = new LinkedHashSet<T>();
for (T t : set) {
if (condition.value(t)) {
result.add(t);
}
}
return result;
}
@Nullable
public static <T extends UsageDescriptor> T findDescriptor(@NotNull Map<GroupDescriptor, Set<T>> descriptors,
@NotNull final Pair<GroupDescriptor, String> id) {
final Set<T> usages = descriptors.get(id.getFirst());
if (usages == null) return null;
return ContainerUtil.find(usages, new Condition<T>() {
@Override
public boolean value(T t) {
return id.getSecond().equals(t.getKey());
}
});
}
@NotNull
public static Map<GroupDescriptor, Set<UsageDescriptor>> getAllUsages(@Nullable Project project, @NotNull Set<String> disabledGroups) {
Map<GroupDescriptor, Set<UsageDescriptor>> usageDescriptors = new HashMap<GroupDescriptor, Set<UsageDescriptor>>();
for (UsagesCollector usagesCollector : Extensions.getExtensions(UsagesCollector.EP_NAME)) {
final GroupDescriptor groupDescriptor = usagesCollector.getGroupId();
if (!disabledGroups.contains(groupDescriptor.getId())) {
usageDescriptors.put(groupDescriptor, usagesCollector.getUsages(project));
}
}
return usageDescriptors;
}
return usageDescriptors;
}
}
@@ -15,6 +15,7 @@
*/
package com.intellij.internal.statistic;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.project.Project;
import com.intellij.internal.statistic.beans.UsageDescriptor;
@@ -28,5 +29,5 @@ public abstract class UsagesCollector {
public abstract @NotNull Set<UsageDescriptor> getUsages(@Nullable Project project);
public abstract @NotNull String getGroupId();
public abstract @NotNull GroupDescriptor getGroupId();
}
@@ -16,6 +16,8 @@
package com.intellij.internal.statistic.beans;
import com.intellij.util.containers.hash.HashMap;
import java.util.*;
public class ConvertUsagesUtil {
@@ -26,19 +28,14 @@ public class ConvertUsagesUtil {
private ConvertUsagesUtil() {
}
// @NotNull
public static String convertUsages(Set<? extends UsageDescriptor> descriptors) {
assert descriptors != null;
final Map<GroupDescriptor, Set<UsageDescriptor>> descriptorGroups = groupDescriptors(descriptors);
return convertUsages(descriptorGroups);
}
// @NotNull
public static String convertUsages(Map<GroupDescriptor, Set<UsageDescriptor>> map) {
public static <T extends UsageDescriptor> String convertUsages(Map<GroupDescriptor, Set<T>> map) {
assert map != null;
final Map<GroupDescriptor, Set<T>> sortedMap = sortDescriptorsByPriority(map);
StringBuffer buffer = new StringBuffer();
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> entry : map.entrySet()) {
for (Map.Entry<GroupDescriptor, Set<T>> entry : sortedMap.entrySet()) {
buffer.append(entry.getKey().getId());
buffer.append(GROUP_SEPARATOR);
buffer.append(convertValueMap(entry.getValue()));
@@ -49,7 +46,7 @@ public class ConvertUsagesUtil {
}
//@NotNull
public static String convertValueMap(Set<UsageDescriptor> descriptors) {
public static String convertValueMap(Set<? extends UsageDescriptor> descriptors) {
assert descriptors != null;
final StringBuffer buffer = new StringBuffer();
for (UsageDescriptor usageDescriptor : descriptors) {
@@ -76,14 +73,14 @@ public class ConvertUsagesUtil {
}
//@NotNull
public static Set<UsageDescriptor> convertString(String usages) {
public static Map<GroupDescriptor, Set<UsageDescriptor>> convertString(String usages) {
assert usages != null;
Set<UsageDescriptor> descriptors = new LinkedHashSet<UsageDescriptor>();
Map<GroupDescriptor, Set<UsageDescriptor>> descriptors = new HashMap<GroupDescriptor, Set<UsageDescriptor>>();
for (String groupStr : usages.split(GROUPS_SEPARATOR.toString())) {
if (!isEmptyOrSpaces(groupStr)) {
final StringPair group = getPair(groupStr, GROUP_SEPARATOR.toString());
if (group != null) {
descriptors.addAll(convertValueString(GroupDescriptor.create(group.first), group.second));
descriptors.putAll(convertValueString(GroupDescriptor.create(group.first), group.second));
}
}
}
@@ -91,9 +88,9 @@ public class ConvertUsagesUtil {
}
//@NotNull
public static Set<UsageDescriptor> convertValueString(GroupDescriptor groupId, String valueData) {
public static Map<GroupDescriptor, Set<UsageDescriptor>> convertValueString(GroupDescriptor groupId, String valueData) {
assert groupId != null;
final Set<UsageDescriptor> descriptors = new LinkedHashSet<UsageDescriptor>();
final Map<GroupDescriptor, Set<UsageDescriptor>> descriptors = new HashMap<GroupDescriptor, Set<UsageDescriptor>>();
for (String value : valueData.split(GROUP_VALUE_SEPARATOR.toString())) {
if (!isEmptyOrSpaces(value)) {
final StringPair pair = getPair(value, "=");
@@ -102,7 +99,10 @@ public class ConvertUsagesUtil {
if (!isEmptyOrSpaces(count)) {
try {
final int i = Integer.parseInt(count);
descriptors.add(new UsageDescriptor(groupId, pair.first, i));
if (!descriptors.containsKey(groupId)) {
descriptors.put(groupId, new LinkedHashSet<UsageDescriptor>());
}
descriptors.get(groupId).add(new UsageDescriptor(pair.first, i));
} catch (NumberFormatException ignored) {
}
}
@@ -129,22 +129,17 @@ public class ConvertUsagesUtil {
}
//@NotNull
public static Map<GroupDescriptor, Set<UsageDescriptor>> groupDescriptors(Set<? extends UsageDescriptor> descriptors) {
public static <T extends UsageDescriptor> Map<GroupDescriptor, Set<T>> sortDescriptorsByPriority(Map<GroupDescriptor, Set<T>> descriptors) {
assert descriptors != null;
final SortedMap<GroupDescriptor, Set<UsageDescriptor>> map = new TreeMap<GroupDescriptor, Set<UsageDescriptor>>(new Comparator<GroupDescriptor>() {
final SortedMap<GroupDescriptor, Set<T>> map = new TreeMap<GroupDescriptor, Set<T>>(new Comparator<GroupDescriptor>() {
public int compare(GroupDescriptor g1, GroupDescriptor g2) {
final int priority = (int) (g2.getPriority() - g1.getPriority());
return priority == 0 ? g1.getId().compareTo(g2.getId()) : priority;
}
});
for (UsageDescriptor descriptor : descriptors) {
final GroupDescriptor group = descriptor.getGroup();
if (!map.containsKey(group)) {
map.put(group, new HashSet<UsageDescriptor>());
}
map.get(group).add(descriptor);
}
map.putAll(descriptors);
return map;
}
@@ -158,7 +153,7 @@ public class ConvertUsagesUtil {
}
}
public static boolean isEmptyOrSpaces(final String s) {
return s == null || s.trim().length() == 0;
}
public static boolean isEmptyOrSpaces(final String s) {
return s == null || s.trim().length() == 0;
}
}
@@ -18,11 +18,11 @@ package com.intellij.internal.statistic.beans;
public class PatchedUsage extends UsageDescriptor {
public PatchedUsage(UsageDescriptor descriptor) {
super(descriptor.getGroup(), descriptor.getKey(), descriptor.getValue());
super(descriptor.getKey(), descriptor.getValue());
}
public PatchedUsage(GroupDescriptor group, String key, int value) {
super(group, key, value);
public PatchedUsage(String key, int value) {
super(key, value);
}
public int getDelta() {
@@ -16,15 +16,12 @@
package com.intellij.internal.statistic.beans;
public class UsageDescriptor implements Comparable<UsageDescriptor> {
private final GroupDescriptor myGroup;
private final String myKey;
private int myValue;
public UsageDescriptor(GroupDescriptor group, String key, int value) {
assert group != null;
assert key != null;
public UsageDescriptor(String key, int value) {
assert key != null;
myGroup = group;
myKey = key;
myValue = value;
}
@@ -33,10 +30,6 @@ public class UsageDescriptor implements Comparable<UsageDescriptor> {
return myKey;
}
public GroupDescriptor getGroup() {
return myGroup;
}
public int getValue() {
return myValue;
}
@@ -45,29 +38,15 @@ public class UsageDescriptor implements Comparable<UsageDescriptor> {
myValue = i;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof UsageDescriptor)) return false;
UsageDescriptor that = (UsageDescriptor) o;
if (!myGroup.equals(that.myGroup)) return false;
if (!myKey.equals(that.myKey)) return false;
return true;
public int getMyValue() {
return myValue;
}
@Override
public int hashCode() {
int result = myGroup.hashCode();
result = 31 * result + myKey.hashCode();
return result;
public void setMyValue(int myValue) {
this.myValue = myValue;
}
public int compareTo(UsageDescriptor ud) {
final int byGroup = this.getGroup().compareTo(ud.getGroup());
return byGroup == 0 ? this.getKey().compareTo(ud.myKey) : byGroup;
return this.getKey().compareTo(ud.myKey);
}
}
@@ -29,7 +29,18 @@ import javax.swing.*;
public class StatisticsConfigurable implements SearchableConfigurable {
private StatisticsConfigurationComponent myConfig;
private boolean modifiedByDefault;
public StatisticsConfigurable() {
this(false);
}
public StatisticsConfigurable(boolean isModifiedByDefault) {
modifiedByDefault = isModifiedByDefault;
}
private StatisticsConfigurationComponent myConfig;
@Nls
public String getDisplayName() {
@@ -56,7 +67,7 @@ public class StatisticsConfigurable implements SearchableConfigurable {
final UsageStatisticsPersistenceComponent persistenceComponent = UsageStatisticsPersistenceComponent.getInstance();
return myConfig.isAllowed() != persistenceComponent.isAllowed() ||
myConfig.getPeriod() != persistenceComponent.getPeriod() ||
persistenceComponent.isShowNotification();
modifiedByDefault;
}
public void apply() throws ConfigurationException {
@@ -65,6 +76,7 @@ public class StatisticsConfigurable implements SearchableConfigurable {
persistenceComponent.setPeriod(myConfig.getPeriod());
persistenceComponent.setAllowed(myConfig.isAllowed());
persistenceComponent.setShowNotification(false);
modifiedByDefault = false;
}
public void reset() {
@@ -0,0 +1,37 @@
package com.intellij.internal.statistic.persistence;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.util.containers.HashMap;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.Set;
public abstract class ApplicationStatisticsPersistence {
private Map<GroupDescriptor, Map<String, Set<UsageDescriptor>>> myApplicationData = new HashMap<GroupDescriptor, Map<String, Set<UsageDescriptor>>>();
public ApplicationStatisticsPersistence() {
}
public void persistFrameworks(@NotNull GroupDescriptor groupDescriptor, @NotNull Project project, @NotNull Set<UsageDescriptor> frameworks) {
if (!myApplicationData.containsKey(groupDescriptor)) {
myApplicationData.put(groupDescriptor, new HashMap<String, Set<UsageDescriptor>>());
}
myApplicationData.get(groupDescriptor).put(project.getName(), frameworks);
}
@NotNull
public Map<String, Set<UsageDescriptor>> getApplicationData(@NotNull GroupDescriptor groupDescriptor) {
final Map<String, Set<UsageDescriptor>> map = myApplicationData.get(groupDescriptor);
return map == null ? new HashMap<String, Set<UsageDescriptor>>(): map;
}
@NotNull
public Map<GroupDescriptor, Map<String, Set<UsageDescriptor>>> getApplicationData() {
return myApplicationData;
}
}
@@ -0,0 +1,184 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.internal.statistic.persistence;
import com.intellij.internal.statistic.AbstractApplicationUsagesCollector;
import com.intellij.internal.statistic.UsagesCollector;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.ProjectManagerListener;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.Function;
import com.intellij.util.containers.HashSet;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Set;
@State(
name = "StatisticsApplicationUsages",
storages = {
@Storage(
id = "statistics.application.usages",
file = "$APP_CONFIG$/statistics.application.usages.xml"
)}
)
public class ApplicationStatisticsPersistenceComponent extends ApplicationStatisticsPersistence
implements ApplicationComponent, PersistentStateComponent<Element> {
private static final String TOKENIZER = ",";
@NonNls
private static final String GROUP_TAG = "group";
@NonNls
private static final String GROUP_NAME_ATTR = "name";
@NonNls
private static final String PROJECT_TAG = "project";
@NonNls
private static final String PROJECT_ID_ATTR = "id";
@NonNls
private static final String VALUES_ATTR = "values";
public ApplicationStatisticsPersistenceComponent() {
}
public static ApplicationStatisticsPersistenceComponent getInstance() {
return ApplicationManager.getApplication().getComponent(ApplicationStatisticsPersistenceComponent.class);
}
public void loadState(final Element element) {
List groups = element.getChildren(GROUP_TAG);
for (Object group : groups) {
Element groupElement = (Element) group;
String groupName = groupElement.getAttributeValue(GROUP_NAME_ATTR);
final GroupDescriptor groupDescriptor = GroupDescriptor.create(groupName);
List projectsList = groupElement.getChildren(PROJECT_TAG);
for (Object project : projectsList) {
Element projectElement = (Element) project;
String projectId = projectElement.getAttributeValue(PROJECT_ID_ATTR);
String frameworks = projectElement.getAttributeValue(VALUES_ATTR);
if (!StringUtil.isEmptyOrSpaces(projectId) && !StringUtil.isEmptyOrSpaces(frameworks)) {
Set<UsageDescriptor> frameworkDescriptors = new HashSet<UsageDescriptor>();
for (String key : StringUtil.split(frameworks, TOKENIZER)) {
frameworkDescriptors.add(new UsageDescriptor(key, 1));
}
getApplicationData(groupDescriptor).put(projectId, frameworkDescriptors);
}
}
}
}
public Element getState() {
Element element = new Element("state");
for (Map.Entry<GroupDescriptor, Map<String, Set<UsageDescriptor>>> appData : getApplicationData().entrySet()) {
Element groupElement = new Element(GROUP_TAG);
groupElement.setAttribute(GROUP_NAME_ATTR, appData.getKey().getId());
boolean isEmptyGroup = true;
for (Map.Entry<String, Set<UsageDescriptor>> projectData : appData.getValue().entrySet()) {
Element projectElement = new Element(PROJECT_TAG);
projectElement.setAttribute(PROJECT_ID_ATTR, projectData.getKey());
final Set<UsageDescriptor> projectDataValue = projectData.getValue();
if (!projectDataValue.isEmpty()) {
projectElement.setAttribute(VALUES_ATTR, joinUsages(projectDataValue));
groupElement.addContent(projectElement);
isEmptyGroup = false;
}
}
if (!isEmptyGroup) {
element.addContent(groupElement);
}
}
return element;
}
private static String joinUsages(@NotNull Set<UsageDescriptor> usages) {
return StringUtil.join(usages, new Function<UsageDescriptor, String>() {
@Override
public String fun(UsageDescriptor usageDescriptor) {
return usageDescriptor.getKey();
}
}, TOKENIZER);
}
@NotNull
@NonNls
public File[] getExportFiles() {
return new File[]{PathManager.getOptionsFile("framework.usages")};
}
@NotNull
public String getPresentableName() {
return "Application Usages Statistics";
}
@NonNls
@NotNull
public String getComponentName() {
return "ApplicationStatisticsPersistenceComponent";
}
public void initComponent() {
ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerListener() {
@Override
public void projectOpened(Project project) {
}
@Override
public boolean canCloseProject(Project project) {
return true;
}
@Override
public void projectClosed(Project project) {
}
@Override
public void projectClosing(Project project) {
if (project != null) {
for (UsagesCollector usagesCollector : Extensions.getExtensions(UsagesCollector.EP_NAME)) {
if (usagesCollector instanceof AbstractApplicationUsagesCollector) {
((AbstractApplicationUsagesCollector) usagesCollector).persistProjectUsages(project);
}
}
}
}
});
}
public void disposeComponent() {
}
}
@@ -17,58 +17,69 @@
package com.intellij.internal.statistic.persistence;
import com.intellij.internal.statistic.StatisticsUploadAssistant;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.internal.statistic.beans.PatchedUsage;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.openapi.util.Pair;
import com.intellij.util.containers.HashSet;
import com.intellij.util.containers.hash.HashMap;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.Set;
public class BasicSentUsagesPersistenceComponent extends SentUsagesPersistence {
public BasicSentUsagesPersistenceComponent() {
}
public BasicSentUsagesPersistenceComponent() {
}
protected Set<UsageDescriptor> mySentDescriptors = new HashSet<UsageDescriptor>();
@NonNls private long mySentTime = 0;
protected Map<GroupDescriptor, Set<UsageDescriptor>> mySentDescriptors = new HashMap<GroupDescriptor, Set<UsageDescriptor>>();
@NonNls
private long mySentTime = 0;
@Override
public boolean isAllowed() {
return true;
}
@Override
public boolean isAllowed() {
return true;
}
@Override
public boolean isShowNotification() {
return false;
}
@Override
public boolean isShowNotification() {
return false;
}
@Override
public long getLastTimeSent() {
return mySentTime;
}
@Override
public long getLastTimeSent() {
return mySentTime;
}
public void setSentTime(long time) {
mySentTime = time;
}
public void setSentTime(long time) {
mySentTime = time;
}
public void persistPatch(@NotNull Set<PatchedUsage> patchedDescriptors) {
for (PatchedUsage patchedUsage : patchedDescriptors) {
UsageDescriptor usageDescriptor = StatisticsUploadAssistant.findDescriptor(mySentDescriptors, Pair.create(patchedUsage.getGroup(), patchedUsage.getKey()));
if (usageDescriptor != null) {
usageDescriptor.setValue(usageDescriptor.getValue() + patchedUsage.getDelta());
}
else {
mySentDescriptors.add(new UsageDescriptor(patchedUsage.getGroup(), patchedUsage.getKey(), patchedUsage.getValue()));
}
public void persistPatch(@NotNull Map<GroupDescriptor, Set<PatchedUsage>> patchedDescriptorMap) {
for (Map.Entry<GroupDescriptor, Set<PatchedUsage>> entry : patchedDescriptorMap.entrySet()) {
final GroupDescriptor groupDescriptor = entry.getKey();
for (PatchedUsage patchedUsage : entry.getValue()) {
UsageDescriptor usageDescriptor = StatisticsUploadAssistant.findDescriptor(mySentDescriptors, Pair.create(groupDescriptor, patchedUsage.getKey()));
if (usageDescriptor != null) {
usageDescriptor.setValue(usageDescriptor.getValue() + patchedUsage.getDelta());
} else {
if (!mySentDescriptors.containsKey(groupDescriptor)) {
mySentDescriptors.put(groupDescriptor, new HashSet<UsageDescriptor>());
}
mySentDescriptors.get(groupDescriptor).add(new UsageDescriptor(patchedUsage.getKey(), patchedUsage.getValue()));
}
}
}
setSentTime(System.currentTimeMillis());
}
setSentTime(System.currentTimeMillis());
}
@NotNull
public Set<UsageDescriptor> getSentUsages() {
return mySentDescriptors;
}
@NotNull
public Map<GroupDescriptor, Set<UsageDescriptor>> getSentUsages
() {
return mySentDescriptors;
}
}
@@ -16,18 +16,20 @@
package com.intellij.internal.statistic.persistence;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.internal.statistic.beans.PatchedUsage;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.Set;
public abstract class SentUsagesPersistence {
public abstract void persistPatch(@NotNull Set<PatchedUsage> patchedDescriptors);
public abstract void persistPatch(@NotNull Map<GroupDescriptor, Set<PatchedUsage>> patchedDescriptors);
@NotNull
public abstract Set<UsageDescriptor> getSentUsages();
public abstract Map<GroupDescriptor, Set<UsageDescriptor>> getSentUsages();
public abstract boolean isAllowed();
@@ -76,7 +76,7 @@ public class UsageStatisticsPersistenceComponent extends BasicSentUsagesPersiste
String valueData = groupElement.getAttributeValue(DATA_ATTR);
if (!StringUtil.isEmptyOrSpaces(groupId) && !StringUtil.isEmptyOrSpaces(valueData)) {
getSentUsages().addAll(ConvertUsagesUtil.convertValueString(GroupDescriptor.create(groupId, groupPriority), valueData));
getSentUsages().putAll(ConvertUsagesUtil.convertValueString(GroupDescriptor.create(groupId, groupPriority), valueData));
}
}
@@ -99,7 +99,7 @@ public class UsageStatisticsPersistenceComponent extends BasicSentUsagesPersiste
public Element getState() {
Element element = new Element("state");
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> entry : ConvertUsagesUtil.groupDescriptors(getSentUsages())
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> entry : ConvertUsagesUtil.sortDescriptorsByPriority(getSentUsages())
.entrySet()) {
Element projectElement = new Element(GROUP_TAG);
projectElement.setAttribute(GROUP_ID_ATTR, entry.getKey().getId());
@@ -72,7 +72,7 @@ public class StatisticsNotificationManager {
else if ("settings".equals(description)) {
final ShowSettingsUtil util = ShowSettingsUtil.getInstance();
IdeFrame ideFrame = WindowManagerEx.getInstanceEx().findFrameFor(null);
util.editConfigurable((JFrame)ideFrame, new StatisticsConfigurable());
util.editConfigurable((JFrame)ideFrame, new StatisticsConfigurable(true));
notification.expire();
}
}
@@ -16,12 +16,14 @@
package com.intellij.openapi.wm.impl;
import com.intellij.ide.IdeEventQueue;
import com.intellij.internal.focus.FocusTracesAction;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationAdapter;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.EdtRunnable;
@@ -60,6 +62,8 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
private FocusCommand myFocusCommandOnAppActivation;
private ActionCallback myCallbackOnActivation;
private final boolean isInternalMode = ApplicationManagerEx.getApplicationEx().isInternal();
private List<FocusRequestInfo> myRequests = new ArrayList<FocusRequestInfo>();
private final IdeEventQueue myQueue;
private final KeyProcessorConext myKeyProcessorContext = new KeyProcessorConext();
@@ -156,6 +160,9 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
@NotNull
public ActionCallback requestFocus(@NotNull final FocusCommand command, final boolean forced) {
if (isInternalMode) {
recordCommand(command, new Throwable(), forced);
}
final ActionCallback result = new ActionCallback();
if (!forced) {
@@ -183,6 +190,16 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
return result;
}
public List<FocusRequestInfo> getRequests() {
return myRequests;
}
private void recordCommand(FocusCommand command, Throwable trace, boolean forced) {
if (FocusTracesAction.isActive()) {
myRequests.add(new FocusRequestInfo(command.getDominationComponent(), trace, forced));
}
}
private void _requestFocus(final FocusCommand command, final boolean forced, final ActionCallback result) {
if (checkForRejectOrByPass(command, forced, result)) return;
@@ -0,0 +1,56 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.wm.impl;
import com.intellij.util.ExceptionUtil;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author Konstantin Bulenkov
*/
public final class FocusRequestInfo {
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("HH:mm:ss.SSS");
private final String when;
private final Throwable trace;
private final String component;
private final boolean forced;
public FocusRequestInfo(Component component, Throwable trace, boolean forced) {
this.forced = forced;
this.component = component == null ? "null" : component.toString();
this.trace = trace;
when = DATE_FORMAT.format(new Date());
}
public String getStackTrace() {
return ExceptionUtil.getThrowableText(trace);
}
public String getComponent() {
return component;
}
public boolean isForced() {
return forced;
}
public String getDate() {
return when;
}
}
@@ -20,13 +20,11 @@ import com.intellij.ide.IdeTooltip;
import com.intellij.ide.IdeTooltipManager;
import com.intellij.ide.TooltipEvent;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.actionSystem.EditorAction;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.util.UserDataHolderBase;
import com.intellij.openapi.wm.ex.LayoutFocusTraversalPolicyExt;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.ui.popup.AbstractPopup;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -241,7 +239,7 @@ public class LightweightHint extends UserDataHolderBase implements Hint {
}
public final boolean isRealPopup() {
return myIsRealPopup;
return myIsRealPopup | myForceShowAsPopup;
}
public void hide() {
@@ -116,4 +116,6 @@ vcs.show.history.numbers=true
navbar.updateMergeTime=250
navbar.userActivityMergeTime=500
inspectionGadgets.telemetry.enabled=false
inspectionGadgets.telemetry.enabled=false
hint.autopopup=false
@@ -118,20 +118,16 @@
<implementation-class>com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent</implementation-class>
</component>
<component>
<interface-class>com.intellij.internal.statistic.persistence.ApplicationStatisticsPersistenceComponent</interface-class>
<implementation-class>com.intellij.internal.statistic.persistence.ApplicationStatisticsPersistenceComponent</implementation-class>
</component>
<component>
<implementation-class>com.intellij.openapi.util.FoundationLoader</implementation-class>
<headless-implementation-class/>
</component>
<component>
<interface-class>com.intellij.facet.impl.statistics.FrameworkStatisticsPersistenceComponent</interface-class>
<implementation-class>com.intellij.facet.impl.statistics.FrameworkStatisticsPersistenceComponent</implementation-class>
</component>
<component>
<interface-class>com.intellij.openapi.vcs.statistics.VcsStatisticsPersistenceComponent</interface-class>
<implementation-class>com.intellij.openapi.vcs.statistics.VcsStatisticsPersistenceComponent</implementation-class>
</component>
</application-components>
<project-components>
@@ -441,6 +441,10 @@
<action id="TestMessageBoxAction" internal="true" class="com.intellij.diagnostic.TestMessageBoxAction" text="Show Test Dialog"/>
<separator/>
<action id="FocusDebugger" internal="true" class="com.intellij.internal.focus.FocusDebuggerAction" text="Start Focus Debugger"/>
<action id="FocusTracer" internal="true" class="com.intellij.internal.focus.FocusTracesAction" text="Start Focus Trace">
<keyboard-shortcut first-keystroke="control shift F11" keymap="$default"/>
</action>
<action id="UiInspector" internal="true" class="com.intellij.internal.inspector.UiInspectorAction" text="UI Inspector"/>
<action id="ShowSplash" internal="true" class="com.intellij.ui.ShowSplashAction" text="Show Splash" />
<action id="ValidationTest" internal="true" class="com.intellij.internal.validation.TestDialogWithValidationAction" text="Validation Dialog Test" />
@@ -25,6 +25,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.vcs.actions.VcsContextFactory;
import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager;
import com.intellij.openapi.vfs.*;
import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
import com.intellij.vcsUtil.VcsUtil;
@@ -37,6 +38,8 @@ import java.util.*;
* @author yole
*/
public abstract class VcsVFSListener implements Disposable {
private VcsDirtyScopeManager myDirtyScopeManager;
protected static class MovedFileInfo {
public final String myOldPath;
public String myNewPath;
@@ -59,6 +62,7 @@ public abstract class VcsVFSListener implements Disposable {
protected final List<FilePath> myDeletedFiles = new ArrayList<FilePath>();
protected final List<FilePath> myDeletedWithoutConfirmFiles = new ArrayList<FilePath>();
protected final List<MovedFileInfo> myMovedFiles = new ArrayList<MovedFileInfo>();
protected final List<VirtualFile> myDirtyFiles = new ArrayList<VirtualFile>();
protected enum VcsDeleteType {SILENT, CONFIRM, IGNORE}
@@ -66,6 +70,7 @@ public abstract class VcsVFSListener implements Disposable {
myProject = project;
myVcs = vcs;
myChangeListManager = ChangeListManager.getInstance(project);
myDirtyScopeManager = VcsDirtyScopeManager.getInstance(myProject);
final MyVirtualFileAdapter myVFSListener = new MyVirtualFileAdapter();
final MyCommandAdapter myCommandListener = new MyCommandAdapter();
@@ -200,7 +205,14 @@ public abstract class VcsVFSListener implements Disposable {
protected void processMovedFile(VirtualFile file, String newParentPath, String newName) {
if (FileStatusManager.getInstance(myProject).getStatus(file) != FileStatus.UNKNOWN) {
final FileStatus status = FileStatusManager.getInstance(myProject).getStatus(file);
if (status == FileStatus.IGNORED) {
if (file.getParent() != null) {
myDirtyFiles.add(file.getParent());
myDirtyFiles.add(file); // will be at new path
}
}
if (status != FileStatus.UNKNOWN && status != FileStatus.IGNORED) {
final String newPath = newParentPath + "/" + newName;
boolean foundExistingInfo = false;
for (MovedFileInfo info : myMovedFiles) {
@@ -359,7 +371,8 @@ public abstract class VcsVFSListener implements Disposable {
if (myProject != event.getProject()) return;
myCommandLevel--;
if (myCommandLevel == 0) {
if (!myAddedFiles.isEmpty() || !myDeletedFiles.isEmpty() || !myDeletedWithoutConfirmFiles.isEmpty() || !myMovedFiles.isEmpty()) {
if (!myAddedFiles.isEmpty() || !myDeletedFiles.isEmpty() || !myDeletedWithoutConfirmFiles.isEmpty() || !myMovedFiles.isEmpty() ||
! myDirtyFiles.isEmpty()) {
// avoid reentering commandFinished handler - saving the documents may cause a "before file deletion" event firing,
// which will cause closing the text editor, which will itself run a command that will be caught by this listener
myCommandLevel++;
@@ -379,6 +392,20 @@ public abstract class VcsVFSListener implements Disposable {
if (!myMovedFiles.isEmpty()) {
executeMoveRename();
}
if (! myDirtyFiles.isEmpty()) {
final List<VirtualFile> files = new ArrayList<VirtualFile>();
final List<VirtualFile> dirs = new ArrayList<VirtualFile>();
for (VirtualFile dirtyFile : myDirtyFiles) {
if (dirtyFile != null) {
if (dirtyFile.isDirectory()) {
dirs.add(dirtyFile);
} else {
files.add(dirtyFile);
}
}
}
myDirtyScopeManager.filesDirty(files, dirs);
}
}
}
}
@@ -79,7 +79,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
private FileHolderComposite myComposite;
private final ChangeListWorker myWorker;
private ChangeListWorker myWorker;
private VcsException myUpdateException = null;
@SuppressWarnings({"FieldAccessedSynchronizedAndUnsynchronized"})
@@ -117,7 +117,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
myChangesViewManager = myProject.isDefault() ? new DummyChangesView(myProject) : ChangesViewManager.getInstance(myProject);
myFileStatusManager = FileStatusManager.getInstance(myProject);
myComposite = new FileHolderComposite(project);
myIgnoredIdeaLevel = new IgnoredFilesComponent(myProject);
myIgnoredIdeaLevel = new IgnoredFilesComponent(myProject, true);
myUpdater = new UpdateRequestsQueue(myProject, ourUpdateAlarm, new ActualUpdater());
myWorker = new ChangeListWorker(myProject, new MyChangesDeltaForwarder(myProject, ourUpdateAlarm));
@@ -421,10 +421,8 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
myModifier.clearQueue();
// update member from copy
if (takeChanges) {
myWorker.takeData(dataHolder.getChangeListWorker());
}
if (takeChanges) {
myWorker = dataHolder.getChangeListWorker();
myModifier.setWorker(myWorker);
if (LOG.isDebugEnabled()) {
LOG.debug("refresh procedure finished, size: " + dataHolder.getComposite().getVFHolder(FileHolder.HolderType.UNVERSIONED).getSize());
}
@@ -996,8 +994,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
final IgnoredFilesComponent ignoredFilesComponent;
final ChangeListWorker worker;
synchronized (myDataLock) {
ignoredFilesComponent = new IgnoredFilesComponent(myProject);
ignoredFilesComponent.add(myIgnoredIdeaLevel.getFilesToIgnore());
ignoredFilesComponent = new IgnoredFilesComponent(myIgnoredIdeaLevel);
worker = myWorker.copy();
}
new ChangeListManagerSerialization(ignoredFilesComponent, worker).writeExternal(element);
@@ -24,10 +24,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
public class ChangeListsIndexes {
private final Map<String, FileStatus> myFileToStatus;
@@ -107,6 +104,22 @@ public class ChangeListsIndexes {
}
}
public void getDelta(final ChangeListsIndexes newIndexes, final Set<Pair<String,VcsKey>> toRemove, Set<Pair<String,VcsKey>> toAdd) {
// this is old
final Set<String> oldKeySet = myFileToVcs.keySet();
final Set<String> toRemoveSet = new HashSet<String>(oldKeySet);
final Set<String> newKeySet = newIndexes.myFileToVcs.keySet();
final Set<String> toAddSet = new HashSet<String>(newKeySet);
toRemoveSet.removeAll(newKeySet);
toAddSet.removeAll(oldKeySet);
for (String s : toRemoveSet) {
toRemove.add(new Pair<String, VcsKey>(s, myFileToVcs.get(s)));
}
for (String s : toAddSet) {
toAdd.add(new Pair<String, VcsKey>(s, newIndexes.myFileToVcs.get(s)));
}
}
public List<Pair<String, VcsKey>> getAffectedFilesUnderVcs() {
final ArrayList<Pair<String, VcsKey>> result = new ArrayList<Pair<String, VcsKey>>();
for (Map.Entry<String, VcsKey> entry : myFileToVcs.entrySet()) {
@@ -23,6 +23,7 @@ import com.intellij.openapi.vcs.VcsKey;
import com.intellij.openapi.vcs.impl.CollectionsDelta;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -44,18 +45,16 @@ public class ChangesDelta {
myInitialized = true;
return true; //+-
}
final List<Pair<String, VcsKey>> becameAffected = became.getAffectedFilesUnderVcs();
final Set<Pair<String,VcsKey>> toRemove = CollectionsDelta.notInSecond(wasAffected, becameAffected);
final Set<Pair<String, VcsKey>> toAdd = CollectionsDelta.notInSecond(becameAffected, wasAffected);
final Set<Pair<String,VcsKey>> toRemove = new HashSet<Pair<String,VcsKey>>();
final Set<Pair<String, VcsKey>> toAdd = new HashSet<Pair<String,VcsKey>>();
was.getDelta(became, toRemove, toAdd);
if (toRemove != null) {
for (Pair<String, VcsKey> pair : toRemove) {
myDeltaListener.minus(convertPair(pair));
}
for (Pair<String, VcsKey> pair : toRemove) {
myDeltaListener.minus(convertPair(pair));
}
sendPlus(toAdd);
return toRemove != null || toAdd != null;
return ! toRemove.isEmpty() || ! toAdd.isEmpty();
}
private void sendPlus(final Collection<Pair<String, VcsKey>> toAdd) {
@@ -28,20 +28,24 @@ import java.util.List;
import java.util.Set;
public class IgnoredFilesComponent {
private final Project myProject;
private final Set<IgnoredFileBean> myFilesToIgnore;
public IgnoredFilesComponent(final Project project) {
myProject = project;
public IgnoredFilesComponent(final Project project, final boolean registerListener) {
myFilesToIgnore = new LinkedHashSet<IgnoredFileBean>();
project.getMessageBus().connect().subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
public void before(List<? extends VFileEvent> events) {}
if (registerListener) {
project.getMessageBus().connect(project).subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
public void before(List<? extends VFileEvent> events) {}
public void after(List<? extends VFileEvent> events) {
resetCaches();
}
});
public void after(List<? extends VFileEvent> events) {
resetCaches();
}
});
}
}
public IgnoredFilesComponent(final IgnoredFilesComponent other) {
myFilesToIgnore = new LinkedHashSet<IgnoredFileBean>(other.myFilesToIgnore);
}
public void add(final IgnoredFileBean... filesToIgnore) {
@@ -27,7 +27,7 @@ import java.util.List;
* (after update is done)
*/
public class Modifier implements ChangeListsWriteOperations {
private final ChangeListWorker myWorker;
private ChangeListWorker myWorker;
private boolean myInsideUpdate;
private final List<ChangeListCommand> myCommandQueue;
private final DelayedNotificator myNotificator;
@@ -113,4 +113,8 @@ public class Modifier implements ChangeListsWriteOperations {
myNotificator.callNotify(command);
}
}
public void setWorker(ChangeListWorker worker) {
myWorker = worker;
}
}
@@ -1,42 +0,0 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.statistics;
import com.intellij.openapi.project.Project;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.util.containers.HashMap;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.Set;
public abstract class VcsStatisticsPersistence {
private Map<String, Set<UsageDescriptor>> myVcsUsagesMap = new HashMap<String, Set<UsageDescriptor>>();
public VcsStatisticsPersistence() {
}
public void persist(@NotNull Project project, @NotNull Set<UsageDescriptor> vcs) {
myVcsUsagesMap.put(project.getName(), vcs);
}
@NotNull
public Map<String, Set<UsageDescriptor>> getVcsUsageMap() {
return myVcsUsagesMap;
}
}
@@ -1,146 +0,0 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.statistics;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.ProjectManagerListener;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.util.Function;
import com.intellij.util.containers.HashSet;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Set;
@State(
name = "VcsUsages",
storages = {
@Storage(
id = "vcs",
file = "$APP_CONFIG$/vcs.usages.xml"
)}
)
public class VcsStatisticsPersistenceComponent extends VcsStatisticsPersistence
implements ApplicationComponent, PersistentStateComponent<Element> {
private static final String TOKENIZER = ",";
@NonNls private static final String PROJECT_TAG = "project";
@NonNls private static final String PROJECT_ID_ATTR = "id";
@NonNls private static final String USAGES_ATTR = "usages";
public VcsStatisticsPersistenceComponent() {
}
public static VcsStatisticsPersistenceComponent getInstance() {
return ApplicationManager.getApplication().getComponent(VcsStatisticsPersistenceComponent.class);
}
public void loadState(final Element element) {
List projectsList = element.getChildren(PROJECT_TAG);
for (Object project : projectsList) {
Element projectElement = (Element)project;
String projectId = projectElement.getAttributeValue(PROJECT_ID_ATTR);
String vcs = projectElement.getAttributeValue(USAGES_ATTR);
if (!StringUtil.isEmptyOrSpaces(projectId) && !StringUtil.isEmptyOrSpaces(vcs)) {
Set<UsageDescriptor> vcsDescriptors = new HashSet<UsageDescriptor>();
for (String key : StringUtil.split(vcs, TOKENIZER)) {
vcsDescriptors.add(new UsageDescriptor(VcsUsagesCollector.createGroupDescriptor(), key, 1));
}
getVcsUsageMap().put(projectId, vcsDescriptors);
}
}
}
public Element getState() {
Element element = new Element("state");
for (Map.Entry<String, Set<UsageDescriptor>> vcsUsageEntry : getVcsUsageMap().entrySet()) {
Element projectElement = new Element(PROJECT_TAG);
projectElement.setAttribute(PROJECT_ID_ATTR, vcsUsageEntry.getKey());
projectElement.setAttribute(USAGES_ATTR, joinUsages(vcsUsageEntry.getValue()));
element.addContent(projectElement);
}
return element;
}
private static String joinUsages(@NotNull Set<UsageDescriptor> usages) {
return StringUtil.join(usages, new Function<UsageDescriptor, String>() {
@Override
public String fun(UsageDescriptor usageDescriptor) {
return usageDescriptor.getKey();
}
}, TOKENIZER);
}
@NotNull
@NonNls
public File[] getExportFiles() {
return new File[]{PathManager.getOptionsFile("vcs.usages")};
}
@NotNull
public String getPresentableName() {
return "Vcs Usages";
}
@NonNls
@NotNull
public String getComponentName() {
return "VcsStatisticsPersistenceComponent";
}
public void initComponent() {
ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerListener() {
@Override
public void projectOpened(Project project) {
}
@Override
public boolean canCloseProject(Project project) {
return true;
}
@Override
public void projectClosed(Project project) {
}
@Override
public void projectClosing(Project project) {
if (project != null) {
VcsUsagesCollector.persistProjectUsages(project);
}
}
});
}
public void disposeComponent() {
}
}
@@ -15,10 +15,10 @@
*/
package com.intellij.openapi.vcs.statistics;
import com.intellij.internal.statistic.AbstractApplicationUsagesCollector;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.AbstractVcs;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vcs.impl.VcsDescriptor;
import com.intellij.internal.statistic.UsagesCollector;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.internal.statistic.beans.UsageDescriptor;
@@ -28,77 +28,25 @@ import com.intellij.util.containers.hash.HashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;
public class VcsUsagesCollector extends UsagesCollector {
private static final String GROUP_ID = "vcs";
public class VcsUsagesCollector extends AbstractApplicationUsagesCollector {
private static final String GROUP_ID = "vcs";
public static void persistProjectUsages(@NotNull Project project) {
persistProjectUsages(project, getProjectUsages(project));
}
public static void persistProjectUsages(@NotNull Project project, @NotNull Set<UsageDescriptor> usages) {
persistProjectUsages(project, usages, VcsStatisticsPersistenceComponent.getInstance());
}
public static void persistProjectUsages(@NotNull Project project,
@NotNull Set<UsageDescriptor> usages,
@NotNull VcsStatisticsPersistenceComponent persistence) {
persistence.persist(project, usages);
}
@NotNull
public static Set<UsageDescriptor> getApplicationUsages() {
return getApplicationUsages(VcsStatisticsPersistenceComponent.getInstance());
}
@NotNull
public static Set<UsageDescriptor> getApplicationUsages(@NotNull final VcsStatisticsPersistenceComponent persistence) {
final Map<String, Integer> vcsUsagesMap = new HashMap<String, Integer>();
for (Set<UsageDescriptor> descriptors : persistence.getVcsUsageMap().values()) {
for (UsageDescriptor descriptor : descriptors) {
final String key = descriptor.getKey();
final Integer count = vcsUsagesMap.get(key);
vcsUsagesMap.put(key, count == null ? 1 : count.intValue() + 1);
}
@NotNull
public GroupDescriptor getGroupId() {
return GroupDescriptor.create(GROUP_ID, GroupDescriptor.HIGHER_PRIORITY);
}
return ContainerUtil.map2Set(vcsUsagesMap.entrySet(), new Function<Map.Entry<String, Integer>, UsageDescriptor>() {
@Override
public UsageDescriptor fun(Map.Entry<String, Integer> vcsUsage) {
return new UsageDescriptor(createGroupDescriptor(), vcsUsage.getKey(), vcsUsage.getValue());
}
});
}
@NotNull
public String getGroupId() {
return GROUP_ID;
}
@NotNull
public Set<UsageDescriptor> getUsages(@Nullable Project project) {
if (project != null) {
persistProjectUsages(project, getProjectUsages(project));
@NotNull
public Set<UsageDescriptor> getProjectUsages(@NotNull Project project) {
return ContainerUtil.map2Set(ProjectLevelVcsManager.getInstance(project).getAllActiveVcss(), new Function<AbstractVcs, UsageDescriptor>() {
@Override
public UsageDescriptor fun(AbstractVcs vcs) {
return new UsageDescriptor(vcs.getName(), 1);
}
});
}
return getApplicationUsages();
}
public static Set<UsageDescriptor> getProjectUsages(@NotNull Project project) {
return ContainerUtil.map2Set(ProjectLevelVcsManager.getInstance(project).getAllActiveVcss(), new Function<AbstractVcs, UsageDescriptor>() {
@Override
public UsageDescriptor fun(AbstractVcs vcs) {
return new UsageDescriptor(createGroupDescriptor(), vcs.getName(), 1);
}
});
}
public static GroupDescriptor createGroupDescriptor() {
return GroupDescriptor.create(GROUP_ID, GroupDescriptor.HIGHER_PRIORITY);
}
}
@@ -17,6 +17,7 @@
package com.intellij.xdebugger;
import com.intellij.execution.configurations.RunProfile;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.execution.ui.RunContentDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.xdebugger.breakpoints.XBreakpoint;
@@ -125,4 +126,6 @@ public interface XDebugSession extends AbstractDebuggerSession {
<V extends XSmartStepIntoVariant> void smartStepInto(XSmartStepIntoHandler<V> handler, V variant);
void updateExecutionPosition();
ConsoleView getConsoleView();
}
@@ -86,6 +86,7 @@ public class XDebugSessionImpl implements XDebugSession {
private boolean myStopped;
private boolean myPauseActionSupported;
private boolean myShowTabOnSuspend;
private ConsoleView myConsoleView;
public XDebugSessionImpl(final @NotNull ExecutionEnvironment env,
final @NotNull ProgramRunner runner,
@@ -197,6 +198,8 @@ public class XDebugSessionImpl implements XDebugSession {
stopImpl();
}
});
//todo[nik] make 'createConsole()' method return ConsoleView
myConsoleView = (ConsoleView)myDebugProcess.createConsole();
if (!myShowTabOnSuspend) {
initSessionTab();
}
@@ -204,6 +207,11 @@ public class XDebugSessionImpl implements XDebugSession {
return mySessionTab;
}
@Override
public ConsoleView getConsoleView() {
return myConsoleView;
}
public XDebugSessionTab getSessionTab() {
return mySessionTab;
}
@@ -214,7 +222,7 @@ public class XDebugSessionImpl implements XDebugSession {
mySessionTab.setEnvironment(myEnvironment);
}
Disposer.register(myProject, mySessionTab);
mySessionTab.attachToSession(this, myRunner, myEnvironment, mySessionData);
mySessionTab.attachToSession(this, myRunner, myEnvironment, mySessionData, myConsoleView);
myDebugProcess.sessionInitialized();
}
@@ -514,18 +522,16 @@ public class XDebugSessionImpl implements XDebugSession {
}
private void printMessage(final String message, final String hyperLinkText, @Nullable final HyperlinkInfo info) {
assertSessionTabInitialized();
DebuggerUIUtil.invokeOnEventDispatch(new Runnable() {
public void run() {
final ConsoleView consoleView = (ConsoleView)mySessionTab.getConsole();
consoleView.print(message, ConsoleViewContentType.SYSTEM_OUTPUT);
myConsoleView.print(message, ConsoleViewContentType.SYSTEM_OUTPUT);
if (info != null) {
consoleView.printHyperlink(hyperLinkText, info);
myConsoleView.printHyperlink(hyperLinkText, info);
}
else if (hyperLinkText != null) {
consoleView.print(hyperLinkText, ConsoleViewContentType.SYSTEM_OUTPUT);
myConsoleView.print(hyperLinkText, ConsoleViewContentType.SYSTEM_OUTPUT);
}
consoleView.print("\n", ConsoleViewContentType.SYSTEM_OUTPUT);
myConsoleView.print("\n", ConsoleViewContentType.SYSTEM_OUTPUT);
}
});
}
@@ -16,8 +16,6 @@
package com.intellij.xdebugger.impl.ui;
import com.intellij.debugger.ui.DebuggerContentInfo;
import com.intellij.execution.DefaultExecutionResult;
import com.intellij.execution.ExecutionResult;
import com.intellij.execution.Executor;
import com.intellij.execution.configurations.RunProfile;
import com.intellij.execution.executors.DefaultDebugExecutor;
@@ -26,6 +24,7 @@ import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.runners.ProgramRunner;
import com.intellij.execution.runners.RestartAction;
import com.intellij.execution.runners.RunContentBuilder;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.execution.ui.ExecutionConsole;
import com.intellij.execution.ui.RunContentDescriptor;
import com.intellij.execution.ui.RunnerLayoutUi;
@@ -136,16 +135,9 @@ public class XDebugSessionTab extends DebuggerSessionTabBase {
}
public RunContentDescriptor attachToSession(final @NotNull XDebugSession session, final @Nullable ProgramRunner runner,
final @Nullable ExecutionEnvironment env,
final @NotNull XDebugSessionData sessionData) {
return initUI(session, sessionData, env, runner);
}
@NotNull
private static ExecutionResult createExecutionResult(@NotNull final XDebugSession session) {
final XDebugProcess debugProcess = session.getDebugProcess();
ProcessHandler processHandler = debugProcess.getProcessHandler();
return new DefaultExecutionResult(debugProcess.createConsole(), processHandler);
final @Nullable ExecutionEnvironment env,
final @NotNull XDebugSessionData sessionData, ConsoleView consoleView) {
return initUI(session, sessionData, env, runner, consoleView);
}
public XWatchesView getWatchesView() {
@@ -153,10 +145,13 @@ public class XDebugSessionTab extends DebuggerSessionTabBase {
}
private RunContentDescriptor initUI(final @NotNull XDebugSession session, final @NotNull XDebugSessionData sessionData,
final @Nullable ExecutionEnvironment environment, final @Nullable ProgramRunner runner) {
ExecutionResult executionResult = createExecutionResult(session);
myConsole = executionResult.getExecutionConsole();
myRunContentDescriptor = new RunContentDescriptor(myConsole, executionResult.getProcessHandler(), myUi.getComponent(), getSessionName());
final @Nullable ExecutionEnvironment environment,
final @Nullable ProgramRunner runner,
ConsoleView consoleView) {
final XDebugProcess debugProcess = session.getDebugProcess();
ProcessHandler processHandler = debugProcess.getProcessHandler();
myConsole = consoleView;
myRunContentDescriptor = new RunContentDescriptor(myConsole, processHandler, myUi.getComponent(), getSessionName());
myUi.addContent(createFramesContent(session), 0, PlaceInGrid.left, false);
myUi.addContent(createVariablesContent(session), 0, PlaceInGrid.center, false);
@@ -268,7 +268,7 @@ instance.variable.may.not.be.initialized.display.name=Instance field may not be
instance.variable.may.not.be.initialized.problem.descriptor=Instance field <code>#ref</code> may not be initialized during object construction #loc
instance.Variable.may.not.be.initialized.problem.descriptor.junit=Instance field <code>#ref</code> may not be initialized during object construction or 'setUp()' call #loc
primitive.fields.ignore.option=Ignore primitive fields
instance.variable.used.before.initialized.display.name=Instance field used before initialized
instance.variable.used.before.initialized.display.name=Instance field used before initialization
instance.variable.used.before.initialized.problem.descriptor=Instance field <code>#ref</code> used before initialized #loc
non.final.static.variable.initialization.display.name=Non-final static field is used during class initialization
non.final.static.variable.initialization.problem.descriptor=Non-final static field <code>#ref</code> used during class initialization #loc
@@ -1841,4 +1841,6 @@ package.dot.html.may.be.package.info.problem.descriptor=<code>package.html</code
package.dot.html.may.be.package.info.delete.quickfix=Delete package.html
package.dot.html.delete.command=package.html deletion
package.dot.html.may.be.package.info.convert.quickfix=Convert to package-info.java
package.dot.html.convert.command=package.html to package-info.java conversion
package.dot.html.convert.command=package.html to package-info.java conversion
choose.super.class.to.ignore=Choose class
ignore.anonymous.inner.classes=Ignore anonymous inner classes
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 Dave Griffith, Bas Leijdekkers
* Copyright 2006-2011 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
*/
package com.siyeh.ig.serialization;
import com.intellij.psi.PsiAnonymousClass;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiModifier;
@@ -26,18 +27,21 @@ import org.jetbrains.annotations.NotNull;
public class NonSerializableFieldInSerializableClassInspection
extends SerializableInspection {
@Override
@NotNull
public String getDisplayName() {
return InspectionGadgetsBundle.message(
"non.serializable.field.in.serializable.class.display.name");
}
@Override
@NotNull
public String buildErrorString(Object... infos) {
return InspectionGadgetsBundle.message(
"non.serializable.field.in.serializable.class.problem.descriptor");
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new NonSerializableFieldInSerializableClassVisitor();
}
@@ -51,6 +55,13 @@ public class NonSerializableFieldInSerializableClassInspection
return;
}
final PsiClass aClass = field.getContainingClass();
if (aClass == null) {
return;
}
if (ignoreAnonymousInnerClasses &&
aClass instanceof PsiAnonymousClass) {
return;
}
if (!SerializationUtils.isSerializable(aClass)) {
return;
}
@@ -1,47 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.siyeh.ig.serialization.SerializableInspection.Form">
<grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="4" vgap="4">
<margin top="4" left="4" bottom="4" right="4"/>
<constraints>
<xy x="20" y="20" width="368" height="330"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane class="com.intellij.ui.components.JBScrollPane" id="4a009">
<constraints>
<grid row="0" column="0" row-span="3" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="ec407" class="com.intellij.codeInspection.ui.ListTable" binding="table" custom-create="true">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
<component id="d216b" class="javax.swing.JButton" binding="addButton">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Button"/>
</properties>
</component>
<component id="c54c6" class="javax.swing.JButton" binding="removeButton">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Button"/>
</properties>
</component>
<vspacer id="c7b68">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
</form>
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,11 +22,13 @@ import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.fixes.AddSerialVersionUIDFix;
import com.siyeh.ig.psiutils.SerializationUtils;
import org.intellij.lang.annotations.Pattern;
import org.jetbrains.annotations.NotNull;
public class SerializableHasSerialVersionUIDFieldInspection
extends SerializableInspection {
@Pattern("[a-zA-Z_0-9.-]+")
@Override
@NotNull
public String getID() {
@@ -70,6 +72,10 @@ public class SerializableHasSerialVersionUIDFieldInspection
aClass instanceof PsiEnumConstantInitializer) {
return;
}
if (ignoreAnonymousInnerClasses &&
aClass instanceof PsiAnonymousClass) {
return;
}
final PsiField serialVersionUIDField = aClass.findFieldByName(
HardcodedMethodConstants.SERIAL_VERSION_UID, false);
if (serialVersionUIDField != null) {
@@ -15,6 +15,7 @@
*/
package com.siyeh.ig.serialization;
import com.intellij.psi.PsiAnonymousClass;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiEnumConstantInitializer;
import com.intellij.psi.PsiTypeParameter;
@@ -26,12 +27,14 @@ import org.jetbrains.annotations.NotNull;
public class SerializableHasSerializationMethodsInspection
extends SerializableInspection {
@Override
@NotNull
public String getDisplayName() {
return InspectionGadgetsBundle.message(
"serializable.has.serialization.methods.display.name");
}
@Override
@NotNull
public String buildErrorString(Object... infos) {
final boolean hasReadObject = ((Boolean)infos[0]).booleanValue();
@@ -48,6 +51,7 @@ public class SerializableHasSerializationMethodsInspection
}
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new SerializableHasSerializationMethodsVisitor();
}
@@ -65,6 +69,10 @@ public class SerializableHasSerializationMethodsInspection
aClass instanceof PsiEnumConstantInitializer) {
return;
}
if (ignoreAnonymousInnerClasses &&
aClass instanceof PsiAnonymousClass) {
return;
}
if (!SerializationUtils.isSerializable(aClass)) {
return;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
*/
package com.siyeh.ig.serialization;
import com.intellij.psi.PsiAnonymousClass;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiModifier;
@@ -28,7 +29,8 @@ class SerializableInnerClassHasSerialVersionUIDFieldVisitor
private final SerializableInspection inspection;
public SerializableInnerClassHasSerialVersionUIDFieldVisitor(SerializableInspection inspection) {
public SerializableInnerClassHasSerialVersionUIDFieldVisitor(
SerializableInspection inspection) {
this.inspection = inspection;
}
@@ -38,6 +40,10 @@ class SerializableInnerClassHasSerialVersionUIDFieldVisitor
aClass.isEnum()) {
return;
}
if (inspection.ignoreAnonymousInnerClasses &&
aClass instanceof PsiAnonymousClass) {
return;
}
if (hasSerialVersionUIDField(aClass)) {
return;
}
@@ -57,7 +63,7 @@ class SerializableInnerClassHasSerialVersionUIDFieldVisitor
registerClassError(aClass);
}
private boolean hasSerialVersionUIDField(PsiClass aClass) {
private static boolean hasSerialVersionUIDField(PsiClass aClass) {
final PsiField[] fields = aClass.getFields();
boolean hasSerialVersionUID = false;
for (PsiField field : fields) {
@@ -15,6 +15,7 @@
*/
package com.siyeh.ig.serialization;
import com.intellij.psi.PsiAnonymousClass;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiModifier;
import com.siyeh.ig.BaseInspectionVisitor;
@@ -24,10 +25,10 @@ import org.jetbrains.annotations.NotNull;
class SerializableInnerClassWithNonSerializableOuterClassVisitor
extends BaseInspectionVisitor {
private final SerializableInnerClassWithNonSerializableOuterClassInspection inspection;
private final SerializableInspection inspection;
public SerializableInnerClassWithNonSerializableOuterClassVisitor(
SerializableInnerClassWithNonSerializableOuterClassInspection inspection) {
SerializableInspection inspection) {
this.inspection = inspection;
}
@@ -36,6 +37,10 @@ class SerializableInnerClassWithNonSerializableOuterClassVisitor
aClass.isEnum()) {
return;
}
if (inspection.ignoreAnonymousInnerClasses &&
aClass instanceof PsiAnonymousClass) {
return;
}
final PsiClass containingClass = aClass.getContainingClass();
if (containingClass == null) {
return;
@@ -19,22 +19,29 @@ import com.intellij.codeInspection.ui.AddAction;
import com.intellij.codeInspection.ui.ListTable;
import com.intellij.codeInspection.ui.ListWrappingTableModel;
import com.intellij.codeInspection.ui.RemoveAction;
import com.intellij.openapi.actionSystem.ActionToolbar;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.psi.PsiClass;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.ui.ScrollPaneFactory;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.psiutils.SerializationUtils;
import com.siyeh.ig.ui.CheckBox;
import com.siyeh.ig.ui.UiUtils;
import org.jdom.Element;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
public abstract class SerializableInspection extends BaseInspection {
/** @noinspection PublicField */
@SuppressWarnings({"PublicField"})
public boolean ignoreAnonymousInnerClasses = false;
@SuppressWarnings({"PublicField"})
public String superClassString = "java.awt.Component";
protected List<String> superClassList = new ArrayList();
@@ -44,8 +51,41 @@ public abstract class SerializableInspection extends BaseInspection {
@Override
public JComponent createOptionsPanel() {
final Form form = new Form();
return form.getContentPanel();
final JComponent panel = new JPanel(new GridBagLayout());
final ListTable table = new ListTable(new ListWrappingTableModel(
superClassList, InspectionGadgetsBundle.message(
"ignore.classes.in.hierarchy.column.name")));
final JScrollPane scrollPane =
ScrollPaneFactory.createScrollPane(table);
final ActionToolbar toolbar =
UiUtils.createAddRemoveTreeAnnotationChooserToolbar(table,
InspectionGadgetsBundle.message(
"choose.super.class.to.ignore"));
final CheckBox checkBox = new CheckBox(InspectionGadgetsBundle.message(
"ignore.anonymous.inner.classes"), this,
"ignoreAnonymousInnerClasses");
final GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 0;
constraints.insets.left = 4;
constraints.insets.right = 4;
constraints.fill = GridBagConstraints.HORIZONTAL;
panel.add(toolbar.getComponent(), constraints);
constraints.gridy = 1;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
constraints.fill = GridBagConstraints.BOTH;
panel.add(scrollPane, constraints);
constraints.gridy = 2;
constraints.weighty = 0.0;
constraints.fill = GridBagConstraints.HORIZONTAL;
panel.add(checkBox, constraints);
return panel;
}
@Override
@@ -71,27 +111,4 @@ public abstract class SerializableInspection extends BaseInspection {
}
return false;
}
private class Form {
private JPanel contentPanel;
private ListTable table;
private JButton addButton;
private JButton removeButton;
Form() {
addButton.setAction(new AddAction(table));
removeButton.setAction(new RemoveAction(table));
}
private void createUIComponents() {
table = new ListTable(new ListWrappingTableModel(superClassList,
InspectionGadgetsBundle.message(
"ignore.classes.in.hierarchy.column.name")));
}
public JPanel getContentPanel() {
return contentPanel;
}
}
}
@@ -15,9 +15,9 @@
*/
package com.intellij.lang.ant.config.execution;
import com.intellij.compiler.impl.javaCompiler.FileObject;
import com.intellij.compiler.impl.javaCompiler.javac.JavacOutputParser;
import com.intellij.compiler.impl.javaCompiler.jikes.JikesOutputParser;
import com.intellij.compiler.impl.javaCompiler.FileObject;
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.lang.ant.AntBundle;
import com.intellij.openapi.application.ApplicationManager;
@@ -240,7 +240,7 @@ public class OutputParser{
}
com.intellij.compiler.OutputParser.Callback callback = new com.intellij.compiler.OutputParser.Callback() {
private int myIndex = 0;
private int myIndex = -1;
@Nullable
public String getCurrentLine() {
@@ -251,7 +251,16 @@ public class OutputParser{
}
public String getNextLine() {
return javacMessages.get(myIndex++);
final int next = myIndex + 1;
if (next >= javacMessages.size()) {
return null;
}
return javacMessages.get(myIndex = next);
}
@Override
public void pushBack(String line) {
myIndex--;
}
public void message(final CompilerMessageCategory category,
+10 -3
View File
@@ -312,7 +312,14 @@ public class GitUtil {
* @return timestamp as {@link Date} object
*/
public static Date parseTimestamp(String value) {
return new Date(Long.parseLong(value.trim()) * 1000);
final long parsed;
try {
parsed = Long.parseLong(value.trim());
return new Date(parsed * 1000);
} catch (NumberFormatException e) {
LOG.error("Error parsing timestamp from " + value, e);
return new Date();
}
}
/**
@@ -743,7 +750,7 @@ public class GitUtil {
GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.LOG);
h.setSilent(true);
h.setNoSSH(true);
h.addParameters("--pretty=format:%x00%x01" + GitChangeUtils.COMMITTED_CHANGELIST_FORMAT, "--name-status");
h.addParameters("--pretty=format:%x04%x01" + GitChangeUtils.COMMITTED_CHANGELIST_FORMAT, "--name-status");
parametersSpecifier.consume(h);
String output = h.run();
@@ -753,7 +760,7 @@ public class GitUtil {
boolean firstStep = true;
while (s.hasMoreData()) {
final String line = s.line();
final boolean lineIsAStart = line.startsWith("\u0000\u0001");
final boolean lineIsAStart = line.startsWith("\u0004\u0001");
if ((!firstStep) && lineIsAStart) {
final StringScanner innerScanner = new StringScanner(sb.toString());
sb.setLength(0);
@@ -157,7 +157,7 @@ public class RepositoryAttachHandler implements LibraryTableAttachHandler {
FileUtil.copy(repoFile, toFile);
}
}
String url = VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(toFile.getPath()));
final String url = VfsUtil.getUrlForLibraryRoot(toFile);
manager.refreshAndFindFileByUrl(url);
if (MavenExtraArtifactType.DOCS.getDefaultClassifier().equals(each.getClassifier())) {
libraryEditor.addRoot(url, JavadocOrderRootType.getInstance());
@@ -40,10 +40,7 @@ import org.tmatesoft.svn.core.SVNErrorMessage;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNProperties;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationProvider;
import org.tmatesoft.svn.core.auth.ISVNProxyManager;
import org.tmatesoft.svn.core.auth.SVNAuthentication;
import org.tmatesoft.svn.core.auth.SVNSSLAuthentication;
import org.tmatesoft.svn.core.auth.*;
import org.tmatesoft.svn.core.internal.wc.*;
import org.tmatesoft.svn.core.io.SVNRepository;
@@ -568,8 +565,9 @@ public class SvnAuthenticationManager extends DefaultSVNAuthenticationManager im
}
@Override
public boolean promptForSSLPlaintextPassphraseSaving(SVNURL url, String realm, File certificateFile) {
final int answer = Messages.showYesNoDialog(myProject, String.format("Your passphrase for client certificate:\n%s\ncan only be stored to disk unencrypted. Would you like to store it in plaintext?",
public boolean promptForSSLPlaintextPassphraseSaving(SVNURL url, String realm, File certificateFile, String certificateName) {
final int answer = Messages.showYesNoDialog(myProject,
String.format("Your passphrase for " + certificateName + ":\n%s\ncan only be stored to disk unencrypted. Would you like to store it in plaintext?",
certificateFile.getPath()),
"Store the passphrase in plaintext?", Messages.getQuestionIcon());
return answer == 0;
@@ -655,8 +653,19 @@ public class SvnAuthenticationManager extends DefaultSVNAuthenticationManager im
promptAndSaveWhenWeLackEncryption(realm, auth, new Getter<Boolean>() {
@Override
public Boolean get() {
File file = null;
String certificateName = null;
if (auth instanceof SVNSSLAuthentication) {
file = ((SVNSSLAuthentication) auth).getCertificateFile();
certificateName = "client certificate";
} else if (auth instanceof SVNSSHAuthentication) {
file = ((SVNSSHAuthentication) auth).getPrivateKeyFile();
certificateName = "private key file";
} else {
assert false;
}
return myInteraction.promptForSSLPlaintextPassphraseSaving(myUrl, realm,
((SVNSSLAuthentication) auth).getCertificateFile());
file, certificateName);
}
});
}
@@ -23,7 +23,7 @@ public interface SvnAuthenticationInteraction {
void warnOnAuthStorageDisabled(final SVNURL url);
void warnOnPasswordStorageDisabled(final SVNURL url);
void warnOnSSLPassphraseStorageDisabled(final SVNURL url);
boolean promptForSSLPlaintextPassphraseSaving(final SVNURL url, String realm, File certificateFile);
boolean promptForSSLPlaintextPassphraseSaving(final SVNURL url, String realm, File certificateFile, String certificateName);
boolean promptForPlaintextPasswordSaving(final SVNURL url, String realm);
boolean promptInAwt();
}
@@ -1248,7 +1248,7 @@ public class SvnAuthenticationTest extends PlatformTestCase {
}
@Override
public boolean promptForSSLPlaintextPassphraseSaving(SVNURL url, String realm, File certificateFile) {
public boolean promptForSSLPlaintextPassphraseSaving(SVNURL url, String realm, File certificateFile, String certificateName) {
++ myNumSSLPlaintextPrompt;
return mySSLPlaintextAnswer;
}