Merge remote branch 'origin/master'

This commit is contained in:
irengrig
2011-12-15 13:09:32 +04:00
59 changed files with 722 additions and 391 deletions
+1 -1
View File
@@ -124,7 +124,7 @@ fi
# if VM options file exists - use it
if [ -r "$VM_OPTIONS_FILE" ]; then
JVM_ARGS=`tr '\n' ' ' < "$VM_OPTIONS_FILE"`
JVM_ARGS=`cat "$VM_OPTIONS_FILE" | grep -ve "^#.*" | tr '\n' ' '`
JVM_ARGS="$JVM_ARGS -Djb.vmOptionsFile=\"$VM_OPTIONS_FILE\""
# only extract properties (not VM options) from Info.plist
INFO_PLIST_PARSER_OPTIONS=""
@@ -68,7 +68,6 @@ public abstract class IntervalTreeImpl<T extends MutableInterval> extends RedBla
intervals = new SmartList<Getter<E>>(createGetter(key));
}
@Override
public IntervalNode<E> getLeft() {
return (IntervalNode<E>)left;
@@ -159,6 +158,12 @@ public abstract class IntervalTreeImpl<T extends MutableInterval> extends RedBla
public WeakReferencedGetter(T referent, ReferenceQueue<? super T> q) {
super(referent, q);
}
@NonNls
@Override
public String toString() {
return "Ref: " + get();
}
}
protected int computeDeltaUpToRoot() {
@@ -306,6 +311,12 @@ public abstract class IntervalTreeImpl<T extends MutableInterval> extends RedBla
t.modCount = (int)value;
t.allDeltasUpAreNull = ((value >> 32) & 1) != 0;
}
@NonNls
@Override
public String toString() {
return "Node: " + intervals;
}
}
static class NodeCachedOffsets {
@@ -575,7 +586,7 @@ public abstract class IntervalTreeImpl<T extends MutableInterval> extends RedBla
// next node in in-order traversal
private IntervalNode<T> nextNode(@NotNull IntervalNode<T> root) {
assert root.isValid();
assert root.isValid() : root;
int delta = deltaUpToRootExclusive + root.delta;
int myMaxEnd = maxEndOf(root, deltaUpToRootExclusive);
if (startOffset > myMaxEnd) return null; // tree changed
@@ -19,7 +19,6 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.event.DocumentEvent;
import com.intellij.openapi.editor.ex.DocumentEx;
import com.intellij.openapi.editor.ex.RangeMarkerEx;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.UserDataHolderBase;
import com.intellij.util.Processor;
import org.jetbrains.annotations.NonNls;
@@ -60,6 +59,7 @@ public class RangeMarkerImpl extends UserDataHolderBase implements RangeMarkerEx
}
protected boolean unregisterInTree() {
if (!isValid()) return false;
IntervalTreeImpl tree = myNode.getTree();
tree.checkMax(true);
boolean b = myDocument.removeRangeMarker(this);
@@ -74,9 +74,7 @@ public class RangeMarkerImpl extends UserDataHolderBase implements RangeMarkerEx
@Override
public void dispose() {
if(isValid()) {
unregisterInTree();
}
unregisterInTree();
}
@Override
@@ -258,8 +256,6 @@ public class RangeMarkerImpl extends UserDataHolderBase implements RangeMarkerEx
return node != null && node.isValid();
}
private static final Key<Boolean> TRACK_INVALIDATION_KEY = new Key<Boolean>("TRACK_INVALIDATION_KEY");
@Override
public boolean setValid(boolean value) {
RangeMarkerTree.RMNode node = myNode;
@@ -218,6 +218,7 @@ public class RangeMarkerTree<T extends RangeMarkerEx> extends IntervalTreeImpl<T
if (!marker.isValid()) {
// marker can become invalid on its own, e.g. FoldRegion
node.removeIntervalInternal(i);
marker = null;
continue;
}
break;
@@ -356,7 +356,8 @@ public class ExtensionsAreaImpl implements ExtensionsArea {
final List<Element> extensions) {
final String areaClass = getAreaClass();
if (extensionsPoints != null) {
for (Element element : extensionsPoints) {
for (int i = 0, size = extensionsPoints.size(); i < size; ++i) {
Element element = extensionsPoints.get(i);
if (equal(areaClass, element.getAttributeValue(ATTRIBUTE_AREA))) {
registerExtensionPoint(pluginDescriptor, element);
}
@@ -364,7 +365,8 @@ public class ExtensionsAreaImpl implements ExtensionsArea {
}
if (extensions != null) {
for (Element element : extensions) {
for (int i = 0, size = extensions.size(); i < size; ++i) {
Element element = extensions.get(i);
if (hasExtensionPoint(extractEPName(element))) {
registerExtension(pluginDescriptor, element);
}
@@ -97,7 +97,6 @@ public class InitialConfigurationDialog extends DialogWrapper {
setText(keymap.getPresentableName());
}
}
});
preselectKeyMap(keymaps);
@@ -136,9 +135,10 @@ public class InitialConfigurationDialog extends DialogWrapper {
}
private void preselectKeyMap(ArrayList<Keymap> keymaps) {
if (SystemInfo.isMac) {
final Keymap defaultKeymap = KeymapManager.getInstance().getActiveKeymap();
if (defaultKeymap != null) {
for (Keymap keymap : keymaps) {
if (keymap.getName().equals("Default for Mac OS X")) {
if (keymap.equals(defaultKeymap)) {
myKeymapComboBox.setSelectedItem(keymap);
break;
}
@@ -261,15 +261,15 @@ public class InitialConfigurationDialog extends DialogWrapper {
}
private static boolean matchesPlatform(Keymap keymap) {
if (keymap.getName().equals(KeymapManager.DEFAULT_IDEA_KEYMAP)) {
return !SystemInfo.isMac;
final String name = keymap.getName();
if (KeymapManager.DEFAULT_IDEA_KEYMAP.equals(name)) {
return !SystemInfo.isMac && !SystemInfo.isLinux;
}
else if (keymap.getName().equals(KeymapManager.MAC_OS_X_KEYMAP)) {
else if (KeymapManager.MAC_OS_X_KEYMAP.equals(name) || "Mac OS X 10.5+".equals(name)) {
return SystemInfo.isMac;
}
else if (keymap.getName().equals("Default for GNOME") || keymap.getName().equals("Default for KDE") ||
keymap.getName().equals("Default for XWin")) {
return SystemInfo.isLinux;
else if (KeymapManager.X_WINDOW_KEYMAP.equals(name) || "Default for GNOME".equals(name) || "Default for KDE".equals(name)) {
return SystemInfo.isUnix && !SystemInfo.isMac;
}
return true;
}
@@ -218,18 +218,18 @@ public class ShowIntentionsPass extends TextEditorHighlightingPass {
List<HighlightInfo.IntentionActionDescriptor> actions = QuickFixAction.getAvailableActions(hostEditor, hostFile, passIdToShowIntentionsFor);
final DaemonCodeAnalyzer codeAnalyzer = DaemonCodeAnalyzer.getInstance(project);
final Document document = hostEditor.getDocument();
HighlightInfo infoAtCursor = ((DaemonCodeAnalyzerImpl)codeAnalyzer).findHighlightByOffset(document, offset, true);
final Document hostDocument = hostEditor.getDocument();
HighlightInfo infoAtCursor = ((DaemonCodeAnalyzerImpl)codeAnalyzer).findHighlightByOffset(hostDocument, offset, true);
if (infoAtCursor == null || infoAtCursor.getSeverity() == HighlightSeverity.ERROR) {
intentions.errorFixesToShow.addAll(actions);
}
else {
intentions.inspectionFixesToShow.addAll(actions);
}
final int line = document.getLineNumber(offset);
DaemonCodeAnalyzerImpl.processHighlights(document, project, null,
document.getLineStartOffset(line),
document.getLineEndOffset(line), new Processor<HighlightInfo>() {
final int line = hostDocument.getLineNumber(offset);
DaemonCodeAnalyzerImpl.processHighlights(hostDocument, project, null,
hostDocument.getLineStartOffset(line),
hostDocument.getLineEndOffset(line), new Processor<HighlightInfo>() {
@Override
public boolean process(HighlightInfo info) {
final GutterIconRenderer renderer = info.getGutterIconRenderer();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
@@ -38,6 +38,7 @@ public abstract class CodeFoldingManager {
@Nullable
public abstract Runnable updateFoldRegionsAsync(@NotNull Editor editor, boolean firstTime);
@Nullable
public abstract FoldRegion findFoldRegion(@NotNull Editor editor, int startOffset, int endOffset);
public abstract FoldRegion[] getFoldRegionsAtOffset(@NotNull Editor editor, int offset);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
@@ -19,7 +19,6 @@ package com.intellij.codeInsight.folding.impl;
import com.intellij.codeInsight.folding.CodeFoldingManager;
import com.intellij.codeInsight.hint.EditorFragmentComponent;
import com.intellij.codeInsight.hint.HintManager;
import com.intellij.codeInsight.hint.HintManagerImpl;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.editor.*;
@@ -102,7 +101,7 @@ public class CodeFoldingManagerImpl extends CodeFoldingManager implements Projec
MouseEvent mouseEvent = e.getMouseEvent();
FoldRegion fold = ((EditorEx)editor).getGutterComponentEx().findFoldingAnchorAt(mouseEvent.getX(), mouseEvent.getY());
if (fold == null) return;
if (fold == null || !fold.isValid()) return;
if (fold == myCurrentFold && myCurrentHint != null) {
hint = myCurrentHint;
return;
@@ -231,7 +230,8 @@ public class CodeFoldingManagerImpl extends CodeFoldingManager implements Projec
public void projectClosed() {
}
@Nullable
public FoldRegion findFoldRegion(@NotNull Editor editor, int startOffset, int endOffset) {
return FoldingUtil.findFoldRegion(editor, startOffset, endOffset);
}
@@ -681,7 +681,7 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider {
// deal with width
final int width = Math.max(editorSize.width, historySize.width);
newEditorSize.width = width + editor.getScrollPane().getHorizontalScrollBar().getHeight();
editor.getSoftWrapModel().forceAdditionalColumnsUsage();
history.getSoftWrapModel().forceAdditionalColumnsUsage();
editor.getSettings().setAdditionalColumnsCount(2 + (width - editorSize.width) / EditorUtil.getSpaceWidth(Font.PLAIN, editor));
history.getSettings().setAdditionalColumnsCount(2 + (width - historySize.width) / EditorUtil.getSpaceWidth(Font.PLAIN, history));
@@ -20,6 +20,7 @@ import com.intellij.lang.Language;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -27,19 +28,21 @@ import javax.swing.*;
* @author Gregory.Shrago
*/
public class LanguageConsoleViewImpl extends ConsoleViewImpl {
@NotNull
protected LanguageConsoleImpl myConsole;
public LanguageConsoleViewImpl(final Project project, String title, final Language language) {
this(project, new LanguageConsoleImpl(project, title, language));
}
protected LanguageConsoleViewImpl(final Project project, final LanguageConsoleImpl console) {
protected LanguageConsoleViewImpl(final Project project, @NotNull final LanguageConsoleImpl console) {
super(project, true);
myConsole = console;
Disposer.register(this, myConsole);
Disposer.register(project, this);
}
@NotNull
public LanguageConsoleImpl getConsole() {
return myConsole;
}
@@ -37,7 +37,10 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class GotoActionModel implements ChooseByNameModel, CustomMatcherModel {
private final Project myProject;
@@ -51,11 +54,15 @@ public class GotoActionModel implements ChooseByNameModel, CustomMatcherModel {
private Pattern myCompiledPattern;
private final PatternMatcher myMatcher = new Perl5Matcher();
private Map<AnAction, String> myActionsMap = new HashMap<AnAction, String>();
public GotoActionModel(Project project, final Component component) {
myProject = project;
myContextComponent = component;
final ActionGroup mainMenu = (ActionGroup)myActionManager.getActionOrStub(IdeActions.GROUP_MAIN_MENU);
collectActions(myActionsMap, mainMenu, mainMenu.getTemplatePresentation().getText());
}
public String getPromptText() {
@@ -113,7 +120,7 @@ public class GotoActionModel implements ChooseByNameModel, CustomMatcherModel {
final DataContext dataContext = DataManager.getInstance().getDataContext(myContextComponent);
final AnActionEvent event = updateActionBeforShow(anAction, dataContext);
final AnActionEvent event = updateActionBeforeShow(anAction, dataContext);
final Presentation presentation = event.getPresentation();
final Color fg = defaultActionForeground(isSelected, presentation);
@@ -157,7 +164,7 @@ public class GotoActionModel implements ChooseByNameModel, CustomMatcherModel {
return actionLabel;
}
protected AnActionEvent updateActionBeforShow(AnAction anAction, DataContext dataContext) {
protected static AnActionEvent updateActionBeforeShow(AnAction anAction, DataContext dataContext) {
final AnActionEvent event = new AnActionEvent(null, dataContext,
ActionPlaces.UNKNOWN, new Presentation(), ActionManager.getInstance(),
0);
@@ -166,7 +173,7 @@ public class GotoActionModel implements ChooseByNameModel, CustomMatcherModel {
return event;
}
protected Color defaultActionForeground(boolean isSelected, Presentation presentation) {
protected static Color defaultActionForeground(boolean isSelected, Presentation presentation) {
return isSelected ? UIUtil.getListSelectionForeground()
: presentation.isEnabled() && presentation.isVisible()
? UIUtil.getListForeground()
@@ -175,7 +182,10 @@ public class GotoActionModel implements ChooseByNameModel, CustomMatcherModel {
public String[] getNames(boolean checkBoxState) {
final ArrayList<String> result = new ArrayList<String>();
collectActionIds(result, (ActionGroup)myActionManager.getActionOrStub(IdeActions.GROUP_MAIN_MENU));
for (AnAction action : myActionsMap.keySet()) {
if (action instanceof ActionGroup) continue;
result.add(getActionId(action));
}
if (checkBoxState) {
final Set<String> ids = ((ActionManagerImpl)myActionManager).getActionIds();
for (String id : ids) {
@@ -188,22 +198,10 @@ public class GotoActionModel implements ChooseByNameModel, CustomMatcherModel {
return ArrayUtil.toStringArray(result);
}
private void collectActionIds(Collection<String> result, ActionGroup group){
final AnAction[] actions = group.getChildren(null);
for (AnAction action : actions) {
if (action instanceof ActionGroup) {
collectActionIds(result, (ActionGroup)action);
}
else if (action != null) {
result.add(getActionId(action));
}
}
}
public Object[] getElementsByName(final String id, final boolean checkBoxState, final String pattern) {
final HashMap<AnAction, String> map = new HashMap<AnAction, String>();
final ActionGroup mainMenu = (ActionGroup)myActionManager.getActionOrStub(IdeActions.GROUP_MAIN_MENU);
collectActions(id, map, mainMenu, mainMenu.getTemplatePresentation().getText());
final AnAction act = myActionManager.getAction(id);
map.put(act, myActionsMap.get(act));
if (checkBoxState) {
final Set<String> ids = ((ActionManagerImpl)myActionManager).getActionIds();
for (AnAction action : map.keySet()) { //do not add already included actions
@@ -219,15 +217,15 @@ public class GotoActionModel implements ChooseByNameModel, CustomMatcherModel {
return map.entrySet().toArray(new Map.Entry[map.size()]);
}
private void collectActions(String id, Map<AnAction, String> result, ActionGroup group, final String containingGroupName){
private static void collectActions(Map<AnAction, String> result, ActionGroup group, final String containingGroupName){
final AnAction[] actions = group.getChildren(null);
for (AnAction action : actions) {
if (action != null) {
if (action instanceof ActionGroup) {
final ActionGroup actionGroup = (ActionGroup)action;
final String groupName = actionGroup.getTemplatePresentation().getText();
collectActions(id, result, actionGroup, groupName != null ? groupName : containingGroupName);
} else if (getActionId(action) == id) {
collectActions(result, actionGroup, groupName != null ? groupName : containingGroupName);
} else {
final String groupName = group.getTemplatePresentation().getText();
result.put(action, groupName != null && groupName.length() > 0 ? groupName : containingGroupName);
}
@@ -265,6 +263,10 @@ public class GotoActionModel implements ChooseByNameModel, CustomMatcherModel {
(description != null && myMatcher.matches(description, compiledPattern))) {
return true;
}
final String groupName = myActionsMap.get(anAction);
if (groupName != null && text != null && myMatcher.matches(groupName + " " + text, compiledPattern)) {
return true;
}
}
return false;
}
@@ -292,7 +294,7 @@ public class GotoActionModel implements ChooseByNameModel, CustomMatcherModel {
pattern = pattern.substring(0, 80);
}
final @NonNls StringBuffer buffer = new StringBuffer(".*");
final @NonNls StringBuilder buffer = new StringBuilder(".*");
pattern = pattern.toLowerCase();
for (int i = 0; i < pattern.length(); i++) {
final char c = pattern.charAt(i);
@@ -50,6 +50,7 @@ import com.intellij.openapi.editor.markup.*;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.fileTypes.*;
import com.intellij.openapi.fileTypes.impl.AbstractFileType;
import com.intellij.openapi.ide.CopyPasteManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
@@ -66,6 +67,7 @@ import com.intellij.psi.PsiFileFactory;
import com.intellij.psi.PsiReference;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.impl.DebugUtil;
import com.intellij.psi.impl.source.resolve.FileContextUtil;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
import com.intellij.psi.search.FilenameIndex;
@@ -91,6 +93,7 @@ import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.*;
import java.awt.*;
import java.awt.datatransfer.StringSelection;
import java.awt.event.*;
import java.util.*;
import java.util.List;
@@ -714,6 +717,29 @@ public class PsiViewerDialog extends DialogWrapper implements DataProvider, Disp
return null;
}
@Override
protected Action[] createActions() {
AbstractAction copyPsi = new AbstractAction("Co&py PSI") {
@Override
public void actionPerformed(ActionEvent e) {
PsiElement element = parseText(myEditor.getDocument().getText());
List<PsiElement> allToParse = new ArrayList<PsiElement>();
if (element instanceof PsiFile) {
allToParse.addAll(((PsiFile)element).getViewProvider().getAllFiles());
}
else if (element != null) {
allToParse.add(element);
}
String data = "";
for (PsiElement psiElement : allToParse) {
data += DebugUtil.psiToString(psiElement, !myShowWhiteSpacesBox.isSelected(), true);
}
CopyPasteManager.getInstance().setContents(new StringSelection(data));
}
};
return ArrayUtil.mergeArrays(new Action[]{copyPsi}, super.createActions());
}
@Override
protected void doOKAction() {
if (myBlockTreeBuilder != null) {
@@ -725,35 +751,8 @@ public class PsiViewerDialog extends DialogWrapper implements DataProvider, Disp
myLastParsedText = text;
myLastParsedTextHashCode = text.hashCode();
myNewDocumentHashCode = myLastParsedTextHashCode;
PsiElement rootElement = null;
final Object source = getSource();
try {
if (source instanceof PsiViewerExtension) {
final PsiViewerExtension ext = (PsiViewerExtension)source;
rootElement = ext.createElement(myProject, text);
}
else if (source instanceof FileType) {
final FileType type = (FileType)source;
String ext = type.getDefaultExtension();
if (myExtensionComboBox.isVisible()) {
ext = myExtensionComboBox.getSelectedItem().toString().toLowerCase();
}
if (type instanceof LanguageFileType) {
final Language language = ((LanguageFileType)type).getLanguage();
final Language dialect = (Language)myDialectComboBox.getSelectedItem();
rootElement = PsiFileFactory.getInstance(myProject).createFileFromText("Dummy." + ext, dialect == null ? language : dialect, text);
}
else {
rootElement = PsiFileFactory.getInstance(myProject).createFileFromText("Dummy." + ext, text);
}
}
focusTree();
}
catch (IncorrectOperationException e) {
rootElement = null;
Messages.showMessageDialog(myProject, e.getMessage(), "Error", Messages.getErrorIcon());
}
PsiElement rootElement = parseText(text);
focusTree();
ViewerTreeStructure structure = (ViewerTreeStructure)myPsiTreeBuilder.getTreeStructure();
structure.setRootPsiElement(rootElement);
@@ -796,6 +795,32 @@ public class PsiViewerDialog extends DialogWrapper implements DataProvider, Disp
myBlockTreeBuilder.queueUpdate();
}
private PsiElement parseText(String text) {
final Object source = getSource();
try {
if (source instanceof PsiViewerExtension) {
return ((PsiViewerExtension)source).createElement(myProject, text);
}
if (source instanceof FileType) {
final FileType type = (FileType)source;
String ext = type.getDefaultExtension();
if (myExtensionComboBox.isVisible()) {
ext = myExtensionComboBox.getSelectedItem().toString().toLowerCase();
}
if (type instanceof LanguageFileType) {
final Language language = ((LanguageFileType)type).getLanguage();
final Language dialect = (Language)myDialectComboBox.getSelectedItem();
return PsiFileFactory.getInstance(myProject).createFileFromText("Dummy." + ext, dialect == null ? language : dialect, text);
}
return PsiFileFactory.getInstance(myProject).createFileFromText("Dummy." + ext, text);
}
}
catch (IncorrectOperationException e) {
Messages.showMessageDialog(myProject, e.getMessage(), "Error", Messages.getErrorIcon());
}
return null;
}
@Nullable
private static Block buildBlocks(@NotNull PsiElement rootElement) {
FormattingModelBuilder formattingModelBuilder = LanguageFormatting.INSTANCE.forContext(rootElement);
@@ -43,7 +43,6 @@ import com.intellij.psi.util.PsiUtilCore;
import com.intellij.util.CommonProcessors;
import com.intellij.util.Processor;
import com.intellij.util.indexing.FileBasedIndex;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import java.util.*;
@@ -99,12 +98,12 @@ public class IndexCacheManagerImpl implements CacheManager{
public boolean process(final VirtualFile file, final Integer value) {
ProgressManager.checkCanceled();
final int mask = value.intValue();
if ((mask & occurrenceMask) != 0 && scope.contains(file) && shouldBeFound(scope, file, index)) {
if ((mask & occurrenceMask) != 0 && shouldBeFound(scope, file, index)) {
if (!fileProcessor.process(file)) return false;
}
return true;
}
}, GlobalSearchScope.allScope(myProject).union(scope));
}, scope);
}
});
}
@@ -363,7 +363,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper {
}
}
private boolean processFilesWithText(@NotNull final GlobalSearchScope scope,
public boolean processFilesWithText(@NotNull final GlobalSearchScope scope,
final short searchContext,
final boolean caseSensitively,
@NotNull String text,
@@ -28,6 +28,7 @@ import com.intellij.psi.*;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
/**
@@ -65,22 +66,39 @@ class InjectedSelfElementInfo extends SelfElementInfo {
final Ref<PsiElement> result = new Ref<PsiElement>();
final InjectedLanguageManager manager = InjectedLanguageManager.getInstance(getProject());
InjectedLanguageUtil.enumerate(hostContext, hostContext.getContainingFile(), true, new PsiLanguageInjectionHost.InjectedPsiVisitor() {
@Override
public void visit(@NotNull PsiFile injectedPsi, @NotNull List<PsiLanguageInjectionHost.Shred> places) {
if (result.get() != null) return;
TextRange hostRange = manager.injectedToHost(injectedPsi, new TextRange(0, injectedPsi.getTextLength()));
Document document = PsiDocumentManager.getInstance(getProject()).getDocument(injectedPsi);
if (hostRange.contains(rangeInHostFile) && document instanceof DocumentWindow) {
int start = ((DocumentWindow)document).hostToInjected(rangeInHostFile.getStartOffset());
int end = ((DocumentWindow)document).hostToInjected(rangeInHostFile.getEndOffset());
PsiElement element = findElementInside(injectedPsi, start, end, anchorClass, anchorLanguage);
result.set(element);
}
}
});
PsiFile hostFile = hostContext.getContainingFile();
return result.get();
PsiLanguageInjectionHost.InjectedPsiVisitor visitor = new PsiLanguageInjectionHost.InjectedPsiVisitor() {
@Override
public void visit(@NotNull PsiFile injectedPsi, @NotNull List<PsiLanguageInjectionHost.Shred> places) {
if (result.get() != null) return;
TextRange hostRange = manager.injectedToHost(injectedPsi, new TextRange(0, injectedPsi.getTextLength()));
Document document = PsiDocumentManager.getInstance(getProject()).getDocument(injectedPsi);
if (hostRange.contains(rangeInHostFile) && document instanceof DocumentWindow) {
int start = ((DocumentWindow)document).hostToInjected(rangeInHostFile.getStartOffset());
int end = ((DocumentWindow)document).hostToInjected(rangeInHostFile.getEndOffset());
PsiElement element = findElementInside(injectedPsi, start, end, anchorClass, anchorLanguage);
result.set(element);
}
}
};
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(hostFile.getProject());
Document document = documentManager.getDocument(hostFile);
if (document != null && documentManager.isUncommited(document)) {
List<DocumentWindow> documents = InjectedLanguageUtil.getCachedInjectedDocuments(hostFile);
for (DocumentWindow documentWindow : documents) {
PsiFile injected = documentManager.getPsiFile(documentWindow);
if (injected != null) {
visitor.visit(injected, Collections.<PsiLanguageInjectionHost.Shred>emptyList());
}
}
}
else {
InjectedLanguageUtil.enumerate(hostContext, hostFile, true, visitor);
}
return result.get();
}
@Override
@@ -40,7 +40,9 @@ import com.intellij.openapi.extensions.PluginDescriptor;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.ProperTextRange;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.impl.PsiDocumentManagerImpl;
@@ -117,15 +119,16 @@ public class InjectedLanguageManagerImpl extends InjectedLanguageManager impleme
public void dispose() {
}
public boolean startRunInjectors(@NotNull Document hostDocument, final boolean synchronously) {
if (myProject.isDisposed()) return true;
public void startRunInjectors(@NotNull final Document hostDocument, final boolean synchronously) {
if (myProject.isDisposed()) return;
assert synchronously || !ApplicationManager.getApplication().isWriteAccessAllowed();
// use cached to avoid recreate PSI in alien project
final PsiFile hostPsiFile = PsiDocumentManager.getInstance(myProject).getCachedPsiFile(hostDocument);
if (hostPsiFile == null) return true;
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
final PsiFile hostPsiFile = documentManager.getCachedPsiFile(hostDocument);
if (hostPsiFile == null) return;
final List<DocumentWindow> injected = InjectedLanguageUtil.getCachedInjectedDocuments(hostPsiFile);
if (injected.isEmpty()) return true;
if (injected.isEmpty()) return;
if (myProgress.isCanceled()) {
myProgress = new DaemonProgressIndicator();
@@ -135,6 +138,8 @@ public class InjectedLanguageManagerImpl extends InjectedLanguageManager impleme
@Override
public boolean process(DocumentWindow documentWindow) {
ProgressManager.checkCanceled();
if (documentManager.isUncommited(hostDocument)) return false; // will be committed later
RangeMarker rangeMarker = documentWindow.getHostRanges()[0];
PsiElement element = rangeMarker.isValid() ? hostPsiFile.findElementAt(rangeMarker.getStartOffset()) : null;
if (element == null) {
@@ -161,36 +166,30 @@ public class InjectedLanguageManagerImpl extends InjectedLanguageManager impleme
return true;
}
};
final Computable<Boolean> commitRunnable = new Computable<Boolean>() {
final Runnable commitInjectionsRunnable = new Runnable() {
@Override
public Boolean compute() {
return JobUtil.invokeConcurrentlyUnderProgress(new ArrayList<DocumentWindow>(injected), myProgress, !synchronously, commitProcessor);
public void run() {
JobUtil.invokeConcurrentlyUnderProgress(new ArrayList<DocumentWindow>(injected), myProgress, !synchronously, commitProcessor);
}
};
if (synchronously) {
if (Thread.holdsLock(PsiLock.LOCK)) {
// hack for the case when docCommit was called from within PSI modification, e.g. in formatter
// hack for the case when docCommit was called from within PSI modification, e.g. in formatter.
// we can't spawn threads to do injections there or deadlock is imminent
return ContainerUtil.process(injected, commitProcessor);
ContainerUtil.process(injected, commitProcessor);
}
else {
return commitRunnable.compute();
commitInjectionsRunnable.run();
}
}
else {
JobUtil.submitToJobThread(Job.DEFAULT_PRIORITY, new Runnable() {
@Override
public void run() {
ApplicationManagerEx.getApplicationEx().tryRunReadAction(new Runnable() {
@Override
public void run() {
commitRunnable.compute();
}
});
ApplicationManagerEx.getApplicationEx().tryRunReadAction(commitInjectionsRunnable);
}
});
return true;
}
}
@@ -85,6 +85,11 @@ public class InplaceVariableIntroducer<E extends PsiElement> extends VariableInp
return true;
}
@Override
protected int getOffsetForCaret(RangeMarker rangeMarker, int offset) {
return rangeMarker.isValid() ? rangeMarker.getStartOffset() : offset;
}
@Override
protected StartMarkAction startRename() throws StartMarkAction.AlreadyStartedException {
return null;
@@ -401,7 +401,7 @@ public class VariableInplaceRenamer {
//move to old offset
Runnable runnable = new Runnable() {
public void run() {
myEditor.getCaretModel().moveToOffset(rangeMarker.isValid() ? rangeMarker.getStartOffset() : offset);
myEditor.getCaretModel().moveToOffset(getOffsetForCaret(rangeMarker, offset));
if (selectedRange != null){
myEditor.getSelectionModel().setSelection(selectedRange.getStartOffset(), selectedRange.getEndOffset());
} else if (!shouldSelectAll()){
@@ -411,7 +411,7 @@ public class VariableInplaceRenamer {
};
final LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(myEditor);
if (lookup != null && lookup.getLookupStart() <= (rangeMarker.isValid() ? rangeMarker.getStartOffset() : offset)) {
if (lookup != null && lookup.getLookupStart() <= (getOffsetForCaret(rangeMarker, offset))) {
lookup.setFocused(false);
lookup.performGuardedChange(runnable);
} else {
@@ -446,6 +446,10 @@ public class VariableInplaceRenamer {
return true;
}
protected int getOffsetForCaret(RangeMarker rangeMarker, int offset) {
return offset;
}
protected boolean shouldSelectAll() {
return false;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
@@ -28,9 +28,8 @@ import com.intellij.refactoring.classMembers.MemberInfoChange;
import com.intellij.refactoring.classMembers.MemberInfoChangeListener;
import com.intellij.refactoring.classMembers.MemberInfoModel;
import com.intellij.ui.*;
import com.intellij.util.containers.Convertor;
import com.intellij.ui.table.JBTable;
import com.intellij.util.ui.EmptyIcon;
import com.intellij.util.ui.Table;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -45,22 +44,23 @@ import java.util.List;
/**
* @author Dennis.Ushakov
*/
public abstract class AbstractMemberSelectionTable<T extends PsiElement, M extends MemberInfoBase<T>> extends Table implements TypeSafeDataProvider {
public abstract class AbstractMemberSelectionTable<T extends PsiElement, M extends MemberInfoBase<T>> extends JBTable implements TypeSafeDataProvider {
protected static final int CHECKED_COLUMN = 0;
protected static final int DISPLAY_NAME_COLUMN = 1;
protected static final int ABSTRACT_COLUMN = 2;
protected static final Icon OVERRIDING_METHOD_ICON = IconLoader.getIcon("/general/overridingMethod.png");
protected static final Icon IMPLEMENTING_METHOD_ICON = IconLoader.getIcon("/general/implementingMethod.png");
protected static final Icon EMPTY_OVERRIDE_ICON = EmptyIcon.ICON_16;
protected final String myAbstractColumnHeader;
protected static final String DISPLAY_NAME_COLUMN_HEADER = RefactoringBundle.message("member.column");
protected static final int OVERRIDE_ICON_POSITION = 2;
protected static final int VISIBILITY_ICON_POSITION = 1;
protected static final int MEMBER_ICON_POSITION = 0;
protected final String myAbstractColumnHeader;
protected List<M> myMemberInfos;
protected final boolean myAbstractEnabled;
protected MemberInfoModel<T, M> myMemberInfoModel;
protected MyTableModel<T, M> myTableModel;
protected static final int OVERRIDE_ICON_POSITION = 2;
protected static final int VISIBILITY_ICON_POSITION = 1;
protected static final int MEMBER_ICON_POSITION = 0;
public AbstractMemberSelectionTable(Collection<M> memberInfos, MemberInfoModel<T, M> memberInfoModel, String abstractColumnHeader) {
myAbstractEnabled = abstractColumnHeader != null;
@@ -83,11 +83,8 @@ public abstract class AbstractMemberSelectionTable<T extends PsiElement, M exten
final int checkBoxWidth = new JCheckBox().getPreferredSize().width;
model.getColumn(CHECKED_COLUMN).setMaxWidth(checkBoxWidth);
model.getColumn(CHECKED_COLUMN).setMinWidth(checkBoxWidth);
if (myAbstractEnabled) {
int width =
(int)(1.3 * getFontMetrics(getFont()).charsWidth(myAbstractColumnHeader.toCharArray(), 0,
myAbstractColumnHeader.length()));
int width = (int)(1.3 * getFontMetrics(getFont()).charsWidth(myAbstractColumnHeader.toCharArray(), 0, myAbstractColumnHeader.length()));
model.getColumn(ABSTRACT_COLUMN).setMaxWidth(width);
model.getColumn(ABSTRACT_COLUMN).setPreferredWidth(width);
model.getColumn(ABSTRACT_COLUMN).setCellRenderer(new MyBooleanRenderer<T, M>(this));
@@ -143,10 +140,11 @@ public abstract class AbstractMemberSelectionTable<T extends PsiElement, M exten
protected void fireMemberInfoChange(Collection<M> changedMembers) {
Object[] list = listenerList.getListenerList();
MemberInfoChange event = new MemberInfoChange<T, M>(changedMembers);
MemberInfoChange<T, M> event = new MemberInfoChange<T, M>(changedMembers);
for (Object element : list) {
if (element instanceof MemberInfoChangeListener) {
((MemberInfoChangeListener<T, M>)element).memberInfoChanged(event);
@SuppressWarnings("unchecked") final MemberInfoChangeListener<T, M> changeListener = (MemberInfoChangeListener<T, M>)element;
changeListener.memberInfoChanged(event);
}
}
}
@@ -389,18 +387,14 @@ public abstract class AbstractMemberSelectionTable<T extends PsiElement, M exten
myTable = table;
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus,
int row, int column) {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (component instanceof JComponent) {
JComponent jComponent = (JComponent)component;
if (component instanceof JCheckBox) {
int modelColumn = myTable.convertColumnIndexToModel(column);
final M memberInfo = myTable.myMemberInfos.get(row);
jComponent.setEnabled(
(modelColumn == CHECKED_COLUMN && myTable.myMemberInfoModel.isMemberEnabled(memberInfo)
|| (modelColumn == ABSTRACT_COLUMN && memberInfo.isChecked() && myTable.isAbstractColumnEditable(row)))
M memberInfo = myTable.myMemberInfos.get(row);
component.setEnabled(
(modelColumn == CHECKED_COLUMN && myTable.myMemberInfoModel.isMemberEnabled(memberInfo)) ||
(modelColumn == ABSTRACT_COLUMN && memberInfo.isChecked() && myTable.isAbstractColumnEditable(row))
);
}
return component;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.Nullable;
public abstract class KeymapManager {
@NonNls public static final String DEFAULT_IDEA_KEYMAP = "$default";
@NonNls public static final String MAC_OS_X_KEYMAP = "Mac OS X";
@NonNls public static final String X_WINDOW_KEYMAP = "Default for XWin";
public abstract Keymap getActiveKeymap();
@@ -16,6 +16,8 @@
package com.intellij.ui;
import com.intellij.util.ui.UIUtil;
import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
@@ -32,17 +34,18 @@ public class BooleanTableCellRenderer extends JCheckBox implements TableCellRend
setHorizontalAlignment(CENTER);
setVerticalAlignment(CENTER);
setBorder(null);
setOpaque(true);
myPanel.setOpaque(true);
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSel, boolean hasFocus,
int row, int column) {
final Color bg = table.getBackground();
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSel, boolean hasFocus, int row, int column) {
final Color bg = UIUtil.isUnderNimbusLookAndFeel() && row % 2 == 1 ? UIUtil.TRANSPARENT_COLOR : table.getBackground();
final Color fg = table.getForeground();
final Color selBg = table.getSelectionBackground();
final Color selFg = table.getSelectionForeground();
if(value == null) {
if (value == null) {
myPanel.setBackground(isSel ? selBg : bg);
return myPanel;
}
@@ -52,7 +55,8 @@ public class BooleanTableCellRenderer extends JCheckBox implements TableCellRend
if (value instanceof String) {
setSelected(Boolean.parseBoolean((String)value));
} else {
}
else {
setSelected(((Boolean)value).booleanValue());
}
setEnabled(table.isCellEditable(row, column));
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ui;
import com.intellij.ui.treeStructure.Tree;
@@ -32,9 +31,7 @@ import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Enumeration;
public class CheckboxTreeBase extends Tree {
private final CheckPolicy myCheckPolicy;
private static final CheckPolicy DEFAULT_POLICY = new CheckPolicy(true, true, false, true);
@@ -297,14 +294,7 @@ public class CheckboxTreeBase extends Tree {
myUsePartialStatusForParentNodes = usePartialStatusForParentNodes;
myCheckbox = new JCheckBox();
myTextRenderer = new ColoredTreeCellRenderer() {
public void customizeCellRenderer(JTree tree,
Object value,
boolean selected,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
}
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { }
};
myTextRenderer.setOpaque(opaque);
add(myCheckbox, BorderLayout.WEST);
@@ -315,13 +305,7 @@ public class CheckboxTreeBase extends Tree {
this(true);
}
public final Component getTreeCellRendererComponent(JTree tree,
Object value,
boolean selected,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
public final Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
invalidate();
if (value instanceof CheckedTreeNode) {
CheckedTreeNode node = (CheckedTreeNode)value;
@@ -338,15 +322,17 @@ public class CheckboxTreeBase extends Tree {
myCheckbox.setVisible(false);
}
myTextRenderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
// Fix GTK background
if (UIUtil.isUnderGTKLookAndFeel()) {
final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
UIUtil.changeBackGround(this, background);
}
else if (UIUtil.isUnderNimbusLookAndFeel()) {
UIUtil.changeBackGround(this, UIUtil.TRANSPARENT_COLOR);
}
customizeRenderer(tree, value, selected, expanded, leaf, row, hasFocus);
revalidate();
return this;
}
@@ -78,13 +78,23 @@ public class TableView<Item> extends BaseTableView implements ItemsProvider, Sel
final JTableHeader header = getTableHeader();
final TableCellRenderer defaultRenderer = header == null? null : header.getDefaultRenderer();
final RowSorter<? extends TableModel> sorter = getRowSorter();
final List<? extends RowSorter.SortKey> current = sorter == null ? null : sorter.getSortKeys();
ColumnInfo[] columns = getListTableModel().getColumnInfos();
for (int i = 0; i < columns.length; i++) {
final ColumnInfo columnInfo = columns[i];
final TableColumn column = getColumnModel().getColumn(i);
// hack to get sort arrow included into the renderer component
if (sorter != null && columnInfo.isSortable()) {
sorter.setSortKeys(Collections.singletonList(new RowSorter.SortKey(0, SortOrder.ASCENDING)));
}
final Component headerComponent = defaultRenderer == null? null :
defaultRenderer.getTableCellRendererComponent(this, column.getHeaderValue(), false, false, 0, 0);
if (sorter != null && columnInfo.isSortable()) {
sorter.setSortKeys(current);
}
final Dimension headerSize = headerComponent == null? new Dimension(0, 0) : headerComponent.getPreferredSize();
final String maxStringValue;
final String preferredValue;
@@ -1,8 +1,25 @@
/*
* 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.diagnostic;
import com.intellij.diagnostic.errordialog.Attachment;
import com.intellij.openapi.diagnostic.IdeaLoggingEvent;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.PrintStream;
@@ -112,6 +129,17 @@ public class LogMessageEx extends LogMessage {
};
}
public static void error(@NotNull Logger logger, @NotNull String message, @NotNull String... details) {
StringBuilder detailsBuffer = new StringBuilder();
for (String detail : details) {
detailsBuffer.append(detail).append(",");
}
if (details.length > 0 && detailsBuffer.length() > 0) {
detailsBuffer.setLength(detailsBuffer.length() - 1);
}
logger.error(createEvent(message, detailsBuffer.toString(), null, null, (Attachment)null));
}
/**
* @param userMessage user-friendly message description (short, single line if possible)
* @param details technical details (exception stack trace etc.)
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
@@ -170,7 +170,7 @@ public class EditorActionUtil {
}
}
editor.getCaretModel().moveToOffset(newCaretOffset);
editor.getCaretModel().moveToOffset(Math.min(document.getTextLength(), newCaretOffset));
}
private static boolean shouldUseSmartTabs(Project project, Editor editor) {
@@ -24,6 +24,7 @@
*/
package com.intellij.openapi.editor.impl;
import com.intellij.diagnostic.LogMessageEx;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
@@ -69,6 +70,25 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener,
private RangeMarker savedBeforeBulkCaretMarker;
private boolean ignoreWrongMoves = false;
/**
* We check that caret is located at the target offset at the end of {@link #moveToOffset(int, boolean)} method. However,
* it's possible that the following situation occurs:
* <p/>
* <pre>
* <ol>
* <li>Some client subscribes to caret change events;</li>
* <li>{@link #moveToLogicalPosition(LogicalPosition)} is called;</li>
* <li>Caret position is changed during {@link #moveToLogicalPosition(LogicalPosition)} processing;</li>
* <li>The client receives caret position change event and adjusts the position;</li>
* <li>{@link #moveToLogicalPosition(LogicalPosition)} processing is finished;</li>
* <li>{@link #moveToLogicalPosition(LogicalPosition)} reports an error because the caret is not located at the target offset;</li>
* </ol>
* </pre>
* <p/>
* This field serves as a flag that reports unexpected caret position change requests nested from {@link #moveToOffset(int, boolean)}.
*/
private boolean myReportCaretMoves;
/**
* There is a possible case that user defined non-monospaced font for editor. That means that various symbols have different
* visual widths. That means that if we move caret vertically it may deviate to the left/right. However, we can try to preserve
@@ -116,6 +136,9 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener,
public void moveToVisualPosition(@NotNull VisualPosition pos) {
assertIsDispatchThread();
validateCallContext();
if (myReportCaretMoves) {
LogMessageEx.error(LOG, "Unexpected caret move request");
}
myDesiredX = -1;
int column = pos.column;
int line = pos.line;
@@ -218,6 +241,9 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener,
boolean scrollToCaret)
{
assertIsDispatchThread();
if (myReportCaretMoves) {
LogMessageEx.error(LOG, "Unexpected caret move request");
}
SelectionModel selectionModel = myEditor.getSelectionModel();
int selectionStart = selectionModel.getLeadSelectionOffset();
LogicalPosition blockSelectionStart = selectionModel.hasBlockSelection()
@@ -366,6 +392,19 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener,
}
private void moveToLogicalPosition(@NotNull LogicalPosition pos, boolean locateBeforeSoftWrap, @Nullable StringBuilder debugBuffer) {
if (myReportCaretMoves) {
LogMessageEx.error(LOG, "Unexpected caret move request");
}
myReportCaretMoves = true;
try {
doMoveToLogicalPosition(pos, locateBeforeSoftWrap, debugBuffer);
}
finally {
myReportCaretMoves = false;
}
}
private void doMoveToLogicalPosition(@NotNull LogicalPosition pos, boolean locateBeforeSoftWrap, @Nullable StringBuilder debugBuffer) {
assertIsDispatchThread();
if (debugBuffer != null) {
debugBuffer.append(String.format(
@@ -22,6 +22,7 @@ import com.intellij.codeInsight.hint.EditorFragmentComponent;
import com.intellij.codeInsight.hint.TooltipController;
import com.intellij.codeInsight.hint.TooltipGroup;
import com.intellij.concurrency.JobScheduler;
import com.intellij.diagnostic.LogMessageEx;
import com.intellij.ide.*;
import com.intellij.ide.dnd.DnDManager;
import com.intellij.openapi.actionSystem.ActionManager;
@@ -320,8 +321,8 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
public void attributesChanged(@NotNull RangeHighlighterEx highlighter) {
int textLength = myDocument.getTextLength();
int start = Math.min(Math.max(highlighter.getAffectedAreaStartOffset(), 0), textLength - 1);
int end = Math.min(Math.max(highlighter.getAffectedAreaEndOffset(), 0), textLength - 1);
int start = Math.min(Math.max(highlighter.getAffectedAreaStartOffset(), 0), textLength);
int end = Math.min(Math.max(highlighter.getAffectedAreaEndOffset(), 0), textLength);
int startLine = start == -1 ? 0 : myDocument.getLineNumber(start);
int endLine = end == -1 ? myDocument.getLineCount() : myDocument.getLineNumber(end);
@@ -3233,10 +3234,10 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
return logicalToVisualPosition(logicalPos, true);
}
// TODO den remove before v.11 is released.
// TODO den remove as soon as the problem is fixed.
private final ThreadLocal<Integer> stackDepth = new ThreadLocal<Integer>();
// TODO den remove before v.11 is released.
// TODO den remove as soon as the problem is fixed.
@Override
@NotNull
public VisualPosition logicalToVisualPosition(@NotNull LogicalPosition logicalPos, boolean softWrapAware) {
@@ -3257,7 +3258,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
if (offset < getDocument().getTextLength()) {
offset = outermostCollapsed.getStartOffset();
LogicalPosition foldStart = offsetToLogicalPosition(offset);
// TODO den remove before v.11 is released.
// TODO den remove as soon as the problem is fixed.
Integer depth = stackDepth.get();
if (depth >= 0) {
stackDepth.set(depth + 1);
@@ -3269,7 +3270,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
stackDepth.set(-1);
}
}
// TODO den unwrap before v.11 is released.
// TODO den remove as soon as the problem is fixed.
try {
return doLogicalToVisualPosition(foldStart, true);
}
@@ -3507,6 +3508,9 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
if (newY > 0 && newY == y) {
newY = visibleLineToY(getVisibleLogicalLinesCount());
}
if (newY >= y) {
LogMessageEx.error(LOG, "cycled moveCaretToScreenPos() detected", String.format("x=%d, y=%d%nstate=%s", x, y, dumpState()));
}
moveCaretToScreenPos(x, newY);
return;
}
@@ -854,14 +854,14 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark
}
int endY;
int endLineNumber = offsetToLine(end, document);
if (end == -1 || start == -1) {
endY = Math.min(myEditorSourceHeight, myEditorTargetHeight);
}
else if (start == end || document.getLineNumber(start) == document.getLineNumber(end)) {
else if (start == end || offsetToLine(start,document) == endLineNumber) {
endY = startY; // both offsets are on the same line, no need to recalc Y position
}
else {
int endLineNumber = offsetToLine(end, document);
if (myEditorSourceHeight < myEditorTargetHeight) {
endY = myEditorScrollbarTop + endLineNumber * myEditor.getLineHeight();
}
@@ -541,6 +541,7 @@ public final class IterationState {
}
public void pushBack(T element) {
assert myPushedBack == null : "Pushed already: " + myPushedBack;
myPushedBack = element;
}
}
@@ -211,7 +211,7 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentLi
@Override
public boolean isRespectAdditionalColumns() {
return myForceAdditionalColumns || myApplianceManager.hasLinesWithFailedWrap();
return myForceAdditionalColumns || !isSoftWrappingEnabled() || myApplianceManager.hasLinesWithFailedWrap();
}
@Override
@@ -665,6 +665,7 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentLi
myDataMapper.release();
myApplianceManager.reset();
myStorage.removeAll();
myApplianceManager.recalculateIfNecessary();
try {
task.run(true);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* 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.
@@ -15,10 +15,13 @@
*/
package com.intellij.openapi.editor.impl.softwrap.mapping;
import com.intellij.diagnostic.LogMessageEx;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.FoldRegion;
import com.intellij.openapi.editor.LogicalPosition;
import com.intellij.openapi.editor.impl.EditorImpl;
import com.intellij.openapi.editor.impl.EditorTextRepresentationHelper;
import com.intellij.openapi.editor.impl.softwrap.SoftWrapsStorage;
import org.jetbrains.annotations.NotNull;
@@ -37,7 +40,9 @@ import java.util.List;
* @param <T> resulting document dimension type
*/
abstract class AbstractMappingStrategy<T> implements MappingStrategy<T> {
private static final Logger LOG = Logger.getInstance("#" + AbstractMappingStrategy.class.getName());
protected static final CacheEntry SEARCH_KEY = new CacheEntry(0, null, null, null);
protected final Editor myEditor;
@@ -121,7 +126,7 @@ abstract class AbstractMappingStrategy<T> implements MappingStrategy<T> {
}
@Override
public T advance(EditorPosition position, int offset) {
public T advance(@NotNull EditorPosition position, int offset) {
Document document = myEditor.getDocument();
if (offset >= myLastEntryOffset || offset >= document.getTextLength()) {
return build(position);
@@ -155,7 +160,7 @@ abstract class AbstractMappingStrategy<T> implements MappingStrategy<T> {
protected abstract T buildIfExceeds(EditorPosition position, int offset);
@Override
public T processFoldRegion(EditorPosition position, @NotNull FoldRegion foldRegion) {
public T processFoldRegion(@NotNull EditorPosition position, @NotNull FoldRegion foldRegion) {
T result = buildIfExceeds(position, foldRegion);
if (result != null) {
return result;
@@ -171,7 +176,11 @@ abstract class AbstractMappingStrategy<T> implements MappingStrategy<T> {
collapsedSymbolsWidthInColumns = foldingData.getCollapsedSymbolsWidthInColumns();
}
else {
assert false : String.format("Problem fold region: %s. Soft wraps cache: %s", foldRegion, myCache);
String details = "";
if (myEditor instanceof EditorImpl) {
details = ((EditorImpl)myEditor).dumpState();
}
LogMessageEx.error(LOG, "Unexpected fold region is found: " + foldRegion, details);
}
}
else {
@@ -195,7 +204,7 @@ abstract class AbstractMappingStrategy<T> implements MappingStrategy<T> {
protected abstract T buildIfExceeds(@NotNull EditorPosition context, @NotNull FoldRegion foldRegion);
@Override
public T processTabulation(EditorPosition position, TabData tabData) {
public T processTabulation(@NotNull EditorPosition position, TabData tabData) {
T result = buildIfExceeds(position, tabData);
if (result != null) {
return result;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* 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.
@@ -158,7 +158,7 @@ class LogicalToVisualMappingStrategy extends AbstractMappingStrategy<VisualPosit
}
@Override
public VisualPosition processSoftWrap(EditorPosition position, SoftWrap softWrap) {
public VisualPosition processSoftWrap(@NotNull EditorPosition position, SoftWrap softWrap) {
position.visualColumn = softWrap.getIndentInColumns();
position.softWrapColumnDiff += softWrap.getIndentInColumns();
@@ -170,7 +170,7 @@ class LogicalToVisualMappingStrategy extends AbstractMappingStrategy<VisualPosit
@NotNull
@Override
public VisualPosition build(EditorPosition position) {
public VisualPosition build(@NotNull EditorPosition position) {
int diff = myTargetLogical.column - position.logicalColumn;
position.logicalColumn += diff;
position.visualColumn += diff;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* 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.
@@ -58,7 +58,7 @@ interface MappingStrategy<T> {
* and given offset if any; <code>null</code> otherwise
*/
@Nullable
T advance(EditorPosition position, int offset);
T advance(@NotNull EditorPosition position, int offset);
/**
* Notifies current strategy that soft wrap is encountered during the processing. There are two ways to continue the processing then:
@@ -74,7 +74,7 @@ interface MappingStrategy<T> {
* @return target document dimension if it's located within the bounds of the given soft wrap; <code>null</code> otherwise
*/
@Nullable
T processSoftWrap(EditorPosition position, SoftWrap softWrap);
T processSoftWrap(@NotNull EditorPosition position, SoftWrap softWrap);
/**
* Notifies current strategy that collapsed fold region is encountered during the processing. There are two ways to
@@ -92,7 +92,7 @@ interface MappingStrategy<T> {
* <code>null</code> otherwise
*/
@Nullable
T processFoldRegion(EditorPosition position, @NotNull FoldRegion foldRegion);
T processFoldRegion(@NotNull EditorPosition position, @NotNull FoldRegion foldRegion);
/**
* Notifies current strategy that tabulation symbols is encountered during the processing. Tabulation symbols
@@ -111,7 +111,7 @@ interface MappingStrategy<T> {
* <code>null</code> otherwise
*/
@Nullable
T processTabulation(EditorPosition position, TabData tabData);
T processTabulation(@NotNull EditorPosition position, TabData tabData);
/**
* This method is assumed to be called when there are no special symbols between the document position identified by the
@@ -122,5 +122,5 @@ interface MappingStrategy<T> {
* @return resulting dimension that is built on the basis of the given position and target anchor dimension
*/
@NotNull
T build(EditorPosition position);
T build(@NotNull EditorPosition position);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* 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.
@@ -195,7 +195,7 @@ class OffsetToLogicalCalculationStrategy extends AbstractMappingStrategy<Logical
@Nullable
@Override
public LogicalPosition processSoftWrap(EditorPosition position, SoftWrap softWrap) {
public LogicalPosition processSoftWrap(@NotNull EditorPosition position, SoftWrap softWrap) {
position.visualColumn = softWrap.getIndentInColumns();
position.softWrapColumnDiff += softWrap.getIndentInColumns();
if (softWrap.getStart() == myTargetOffset) {
@@ -208,7 +208,7 @@ class OffsetToLogicalCalculationStrategy extends AbstractMappingStrategy<Logical
@NotNull
@Override
public LogicalPosition build(EditorPosition position) {
public LogicalPosition build(@NotNull EditorPosition position) {
Document document = myEditor.getDocument();
int logicalLine = document.getLineNumber(myTargetOffset);
int linesDiff = logicalLine - position.logicalLine;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* 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.
@@ -139,7 +139,7 @@ class VisualToLogicalCalculationStrategy extends AbstractMappingStrategy<Logical
@Nullable
@Override
public LogicalPosition processSoftWrap(EditorPosition position, SoftWrap softWrap) {
public LogicalPosition processSoftWrap(@NotNull EditorPosition position, SoftWrap softWrap) {
// There is a possible case that current visual line starts with soft wrap and target visual position points to its
// virtual space.
CacheEntry targetEntry = getTargetEntry();
@@ -157,14 +157,7 @@ class VisualToLogicalCalculationStrategy extends AbstractMappingStrategy<Logical
}
}
//TODO den implement
return null;
//// We assume that target visual position points to soft wrap-introduced virtual space if this method is called (we expect
//// to iterate only a single visual line and also expect soft wrap to have line feed symbol at the first position).
//EditorPosition targetContext = getAnchorCacheEntry().buildEndLineContext();
//targetContext.softWrapColumnDiff += myTargetVisual.column - targetContext.visualColumn;
//targetContext.visualColumn = myTargetVisual.column;
//return targetContext.buildLogicalPosition();
}
@Override
@@ -193,7 +186,7 @@ class VisualToLogicalCalculationStrategy extends AbstractMappingStrategy<Logical
@NotNull
@Override
public LogicalPosition build(EditorPosition position) {
public LogicalPosition build(@NotNull EditorPosition position) {
int linesDiff = myTargetVisual.line - position.visualLine;
if (linesDiff <= 0) {
int columnsDiff = myTargetVisual.column - position.visualColumn;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
@@ -68,7 +68,8 @@ public class DefaultKeymap {
}
private void loadKeymapsFromElement(final Element element) throws InvalidDataException {
for (Element child : (List<Element>)element.getChildren()) {
@SuppressWarnings("unchecked") final List<Element> children = (List<Element>)element.getChildren();
for (Element child : children) {
if (KEY_MAP.equals(child.getName())) {
String keymapName = child.getAttributeValue(NAME_ATTRIBUTE);
DefaultKeymapImpl keymap = keymapName.startsWith(KeymapManager.MAC_OS_X_KEYMAP) ? new MacOSDefaultKeymap() : new DefaultKeymapImpl();
@@ -84,7 +85,15 @@ public class DefaultKeymap {
}
public String getDefaultKeymapName() {
return SystemInfo.isMac ? KeymapManager.MAC_OS_X_KEYMAP : KeymapManager.DEFAULT_IDEA_KEYMAP;
if (SystemInfo.isMac) {
return KeymapManager.MAC_OS_X_KEYMAP;
}
else if (SystemInfo.isLinux) {
return KeymapManager.X_WINDOW_KEYMAP;
}
else {
return KeymapManager.DEFAULT_IDEA_KEYMAP;
}
}
public String getKeymapPresentableName(KeymapImpl keymap) {
@@ -514,7 +514,7 @@ action.CloneElement.text=Clo_ne...
action.CloneElement.description=Create a copy of the selected class, file or directory in the same package/directory
action.SafeDelete.text=Safe _Delete...
action.SafeDelete.description=Delete the selected class, method or field, checking for usages
action.ExtractMethod.text=E_xtract Method...
action.ExtractMethod.text=_Method...
action.ExtractMethod.description=Turn the selected code fragment into a method
action.RemoveMiddleman.text=Remove _Middleman...
action.RemoveMiddleman.description=Get the client to call the delegate directly
@@ -522,25 +522,25 @@ action.MethodDuplicates.text=Replace Met_hod Code Duplicates...
action.MethodDuplicates.description=Finds code in current file that can be transformed into a call of selected method
action.InvertBoolean.text=Invert _Boolean...
action.InvertBoolean.description=Makes the method return or variable contain the opposite value and corrects the references
action.IntroduceParameterObject.text=Introduce Parameter Ob_ject...
action.IntroduceParameterObject.text=Parameter Ob_ject...
action.IntroduceParameterObject.description=Replaces method parameters list with object
action.ExtractClass.text=Extract Cla_ss...
action.ExtractClass.text=Cla_ss...
action.ExtractClass.description=Extract Delegate
action.IntroduceVariable.text=Introduce _Variable...
action.IntroduceVariable.text=_Variable...
action.IntroduceVariable.description=Put a result of the selected expression into a variable
action.IntroduceField.text=Introduce _Field...
action.IntroduceField.text=_Field...
action.IntroduceField.description=Put a result of the selected expression into a field
action.IntroduceConstant.text=Introduce _Constant...
action.IntroduceConstant.text=_Constant...
action.IntroduceConstant.description=Replace selected expression with a constant (static final field)
action.IntroduceParameter.text=Introduce _Parameter...
action.IntroduceParameter.text=_Parameter...
action.IntroduceParameter.description=Turn the selected expression into method parameter
action.ExtractInterface.text=Extract _Interface...
action.ExtractInterface.text=_Interface...
action.ExtractInterface.description=Extract interface from the selected class
action.ExtractModule.text=Extract _Module...
action.ExtractModule.text=_Module...
action.ExtractModule.description=Extract module from the selected class
action.ExtractSuperclass.text=Extract S_uperclass...
action.ExtractSuperclass.text=S_uperclass...
action.ExtractSuperclass.description=Extract superclass from the selected class
group.IntroduceActionsGroup.text=Introd_uce
group.IntroduceActionsGroup.text=E_xtract
action.TurnRefsToSuper.text=Use Interface _Where Possible...
action.TurnRefsToSuper.description=Change usages of a class to those of its superclass or interface
action.MembersPullUp.text=Pu_ll Members Up...
@@ -559,7 +559,7 @@ action.ReplaceTempWithQuery.text=Replace Temp with _Query...
action.ReplaceTempWithQuery.description=Turn the selected variable into a method
action.ReplaceConstructorWithFactory.text=Replace Constructor with F_actory Method...
action.ReplaceConstructorWithFactory.description=Create a static factory method and use it instead of a constructor
action.ReplaceMethodWithMethodObject.text=Extract Method Ob_ject...
action.ReplaceMethodWithMethodObject.text=Method Ob_ject...
action.ReplaceMethodWithMethodObject.description=Turn the method into its own object so that all the parameters become fields on that object
action.Generify.text=Ge_nerify...
action.Generify.description=Convert your code to use generic types
@@ -567,7 +567,7 @@ action.Migrate.text=_Migrate...
action.Migrate.description=Open migration dialog
action.Type\ Migration.text=Type Migration...
action.Type\ Migration.description=Migrate one type to another
action.ExtractInclude.text=E_xtract Include File...
action.ExtractInclude.text=_Include File...
action.ExtractInclude.description=Turn the selected code fragment into included file
group.BuildMenu.text=_Build
action.CompileProject.text=_Rebuild Project
@@ -297,4 +297,7 @@ android.logcat.new.logcat.dialog.label=<html>Filter logcat messages by different
android.logcat.new.filter.dialog.name.busy.error=Filter {0} already exists
android.compile.messages.processing.external.apklib.dependencies=Processing external apklib dependencies
android.maven.cannot.parse.android.sdk.error=Cannot parse Android SDK for module {0}. Try to force reimport from Maven model
android.facet.settings.custom.debug.keystore.label=C&ustom debug keystore\:
android.facet.settings.custom.debug.keystore.label=C&ustom debug keystore\:
android.export.package.run.proguard.label=Run &ProGuard
android.export.package.proguad.config.label=C&onfig file path\:
android.extract.package.specify.proguard.cfg.path.error=Please specify ProGuard config file path
@@ -17,8 +17,8 @@ package org.jetbrains.android.actions;
import com.intellij.facet.ProjectFacetManager;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataKeys;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.Project;
import org.jetbrains.android.facet.AndroidFacet;
@@ -28,7 +28,7 @@ import org.jetbrains.android.facet.AndroidFacet;
public class AndroidToolsActionGroup extends DefaultActionGroup {
@Override
public void update(AnActionEvent e) {
final Project project = e.getData(DataKeys.PROJECT);
e.getPresentation().setEnabled(project != null && ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID).size() > 0);
final Project project = e.getData(PlatformDataKeys.PROJECT);
e.getPresentation().setVisible(project != null && ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID).size() > 0);
}
}
@@ -12,7 +12,9 @@ import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.roots.CompilerModuleExtension;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ArrayUtil;
import com.intellij.util.containers.HashMap;
@@ -37,6 +39,7 @@ public class AndroidProguardCompiler implements ClassPostProcessingCompiler {
private static final Logger LOG = Logger.getInstance("#org.jetbrains.android.compiler.AndroidProguardCompiler");
@NonNls private static final String DIRECTORY_FOR_LOGS_NAME = "proguard_logs";
@NonNls static final String PROGUARD_OUTPUT_JAR_NAME = "obfuscated_sources.jar";
public static Key<String> PROGUARD_CFG_PATH_KEY = Key.create("ANDROID_PROGUARD_CFG_PATH");
@NotNull
@Override
@@ -58,11 +61,17 @@ public class AndroidProguardCompiler implements ClassPostProcessingCompiler {
continue;
}
final VirtualFile proguardConfigFile = AndroidCompileUtil.getProguardConfigFile(facet);
if (proguardConfigFile == null) {
final String proguardCfgPath = context.getCompileScope().getUserData(PROGUARD_CFG_PATH_KEY);
if (proguardCfgPath == null) {
continue;
}
final VirtualFile proguardConfigFile =
LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(proguardCfgPath));
if (proguardConfigFile == null) {
context.addMessage(CompilerMessageCategory.ERROR, "Cannot find file " + proguardCfgPath, null, -1, -1);
}
final CompilerModuleExtension extension = CompilerModuleExtension.getInstance(module);
if (extension == null) {
LOG.error("Cannot find compiler module extension for module " + module.getName());
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.android.exportSignedPackage.ApkStep">
<grid id="27dc6" binding="myContentPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="myContentPanel" layout-manager="GridLayoutManager" row-count="4" column-count="2" 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="423" height="157"/>
<xy x="20" y="20" width="486" height="157"/>
</constraints>
<properties/>
<border type="none"/>
@@ -18,7 +18,7 @@
</component>
<vspacer id="6d187">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="c25aa" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myApkPathField">
@@ -30,6 +30,28 @@
</constraints>
<properties/>
</component>
<component id="68d4a" class="javax.swing.JCheckBox" binding="myProguardCheckBox">
<constraints>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/AndroidBundle" key="android.export.package.run.proguard.label"/>
</properties>
</component>
<component id="f63a9" class="com.intellij.ui.components.JBLabel" binding="myProguardConfigFilePathLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/AndroidBundle" key="android.export.package.proguad.config.label"/>
</properties>
</component>
<component id="db68e" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myProguardConfigFilePathField">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
</form>
@@ -31,6 +31,8 @@ import com.intellij.openapi.compiler.CompileContext;
import com.intellij.openapi.compiler.CompileScope;
import com.intellij.openapi.compiler.CompileStatusNotification;
import com.intellij.openapi.compiler.CompilerManager;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
@@ -40,10 +42,14 @@ import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.components.JBLabel;
import org.jetbrains.android.compiler.AndroidCompileUtil;
import org.jetbrains.android.compiler.AndroidPackagingCompiler;
import org.jetbrains.android.compiler.AndroidProguardCompiler;
import org.jetbrains.android.facet.AndroidFacet;
import org.jetbrains.android.facet.AndroidRootUtil;
import org.jetbrains.android.sdk.AndroidPlatform;
import org.jetbrains.android.util.AndroidBundle;
import org.jetbrains.android.util.AndroidUtils;
@@ -52,6 +58,8 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -65,10 +73,15 @@ import java.security.cert.X509Certificate;
*/
class ApkStep extends ExportSignedPackageWizardStep {
public static final String APK_PATH_PROPERTY = "ExportedApkPath";
public static final String RUN_PROGUARD_PROPERTY = "AndroidRunProguardForReleaseBuild";
public static final String PROGUARD_CFG_PATH_PROPERTY = "AndroidProguardConfigPath";
private TextFieldWithBrowseButton myApkPathField;
private JPanel myContentPanel;
private JLabel myApkPathLabel;
private JCheckBox myProguardCheckBox;
private JBLabel myProguardConfigFilePathLabel;
private TextFieldWithBrowseButton myProguardConfigFilePathField;
private final ExportSignedPackageWizard myWizard;
private boolean myInited;
@@ -86,6 +99,8 @@ class ApkStep extends ExportSignedPackageWizardStep {
public ApkStep(ExportSignedPackageWizard wizard) {
myWizard = wizard;
myApkPathLabel.setLabelFor(myApkPathField);
myProguardConfigFilePathLabel.setLabelFor(myProguardConfigFilePathField);
myApkPathField.getButton().addActionListener(
new SaveFileListener(myContentPanel, myApkPathField, AndroidBundle.message("android.extract.package.choose.dest.apk")) {
@Override
@@ -94,6 +109,35 @@ class ApkStep extends ExportSignedPackageWizardStep {
return getContentRootPath(module);
}
});
myProguardConfigFilePathField.getButton().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final String path = myProguardConfigFilePathField.getText().trim();
VirtualFile defaultFile = path != null && path.length() > 0
? LocalFileSystem.getInstance().findFileByPath(path)
: null;
final AndroidFacet facet = myWizard.getFacet();
if (defaultFile == null && facet != null) {
defaultFile = AndroidRootUtil.getMainContentRoot(facet);
}
final VirtualFile file = FileChooser.chooseFile(myContentPanel, FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(),
defaultFile);
if (file != null) {
myProguardConfigFilePathField.setText(FileUtil.toSystemDependentName(file.getPath()));
}
}
});
myProguardCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final boolean enabled = myProguardCheckBox.isSelected();
myProguardConfigFilePathLabel.setEnabled(enabled);
myProguardConfigFilePathField.setEnabled(enabled);
}
});
}
@Override
@@ -114,6 +158,32 @@ class ApkStep extends ExportSignedPackageWizardStep {
myApkPathField.setText(defaultPath);
}
}
final String runProguardPropValue = properties.getValue(RUN_PROGUARD_PROPERTY);
boolean selected;
if (runProguardPropValue != null) {
selected = Boolean.parseBoolean(runProguardPropValue);
}
else {
selected = false;
}
myProguardCheckBox.setSelected(selected);
myProguardConfigFilePathLabel.setEnabled(selected);
myProguardConfigFilePathField.setEnabled(selected);
final String proguardCfgPath = properties.getValue(PROGUARD_CFG_PATH_PROPERTY);
if (proguardCfgPath != null &&
LocalFileSystem.getInstance().refreshAndFindFileByPath(proguardCfgPath) != null) {
myProguardConfigFilePathField.setText(FileUtil.toSystemDependentName(proguardCfgPath));
}
else {
final VirtualFile proguardConfigFile = AndroidCompileUtil.getProguardConfigFile(myWizard.getFacet());
if (proguardConfigFile != null) {
myProguardConfigFilePathField.setText(FileUtil.toSystemDependentName(proguardConfigFile.getPath()));
}
}
myInited = true;
}
@@ -266,6 +336,22 @@ class ApkStep extends ExportSignedPackageWizardStep {
final CompileScope compileScope = manager.createModuleCompileScope(facet.getModule(), true);
AndroidCompileUtil.setReleaseBuild(compileScope);
properties.setValue(RUN_PROGUARD_PROPERTY, Boolean.toString(myProguardCheckBox.isSelected()));
if (myProguardCheckBox.isSelected()) {
final String proguardCfgPath = myProguardConfigFilePathField.getText().trim();
if (proguardCfgPath.length() == 0) {
throw new CommitStepException(AndroidBundle.message("android.extract.package.specify.proguard.cfg.path.error"));
}
properties.setValue(PROGUARD_CFG_PATH_PROPERTY, proguardCfgPath);
if (!new File(proguardCfgPath).isFile()) {
throw new CommitStepException("Cannot find file " + proguardCfgPath);
}
compileScope.putUserData(AndroidProguardCompiler.PROGUARD_CFG_PATH_KEY, proguardCfgPath);
}
manager.make(compileScope, new CompileStatusNotification() {
public void finished(boolean aborted, int errors, int warnings, CompileContext compileContext) {
if (aborted || errors != 0) {
@@ -377,11 +377,11 @@ public class AndroidLayoutPreviewToolWindowManager implements ProjectComponent {
LOG.debug(e);
String message = e.getPresentableMessage();
message = message != null ? message : AndroidBundle.message("android.layout.preview.default.error.message");
final Throwable cause = e.getCause();
errorMessage = cause != null ? new RenderingErrorMessage(message + ' ', "Details", "", new Runnable() {
final Throwable[] causes = e.getCauses();
errorMessage = causes.length > 0 ? new RenderingErrorMessage(message + ' ', "Details", "", new Runnable() {
@Override
public void run() {
showStackStace(cause);
showStackStace(causes);
}
}) : new RenderingErrorMessage(message);
}
@@ -432,8 +432,16 @@ public class AndroidLayoutPreviewToolWindowManager implements ProjectComponent {
});
}
private void showStackStace(@NotNull Throwable t) {
final String stackTrace = getStackTrace(t);
private void showStackStace(@NotNull Throwable[] throwables) {
final StringBuilder messageBuilder = new StringBuilder();
for (Throwable t : throwables) {
if (messageBuilder.length() > 0) {
messageBuilder.append("\n\n");
}
messageBuilder.append(getStackTrace(t));
}
final DialogWrapper wrapper = new DialogWrapper(myProject, false) {
{
@@ -443,7 +451,7 @@ public class AndroidLayoutPreviewToolWindowManager implements ProjectComponent {
@Override
protected JComponent createCenterPanel() {
final JPanel panel = new JPanel(new BorderLayout());
final JTextArea textArea = new JTextArea(stackTrace);
final JTextArea textArea = new JTextArea(messageBuilder.toString());
textArea.setEditable(false);
textArea.setRows(40);
textArea.setColumns(70);
@@ -49,7 +49,7 @@ class ProjectCallback extends LegacyCallback implements IProjectCallback {
public static final String FRAGMENT_TAG_NAME = "fragment";
private final Set<String> myMissingClasses = new TreeSet<String>();
private final Set<String> myBrokenClasses = new TreeSet<String>();
private final Map<String, Throwable> myBrokenClasses = new HashMap<String, Throwable>();
private final Map<String, Class<?>> myLoadedClasses = new HashMap<String, Class<?>>();
@@ -103,6 +103,7 @@ class ProjectCallback extends LegacyCallback implements IProjectCallback {
return myProjectResources.getResourceId(type, name);
}
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Nullable
public Object loadView(String className, Class[] constructorSignature, Object[] constructorArgs)
throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, IllegalAccessException, InstantiationException {
@@ -123,23 +124,23 @@ class ProjectCallback extends LegacyCallback implements IProjectCallback {
}
catch (ClassNotFoundException e) {
LOG.info(e);
myBrokenClasses.add(className);
myBrokenClasses.put(className, e.getCause());
}
catch (InvocationTargetException e) {
LOG.info(e);
myBrokenClasses.add(className);
myBrokenClasses.put(className, e.getCause());
}
catch (IllegalAccessException e) {
LOG.info(e);
myBrokenClasses.add(className);
myBrokenClasses.put(className, e.getCause());
}
catch (InstantiationException e) {
LOG.info(e);
myBrokenClasses.add(className);
myBrokenClasses.put(className, e.getCause());
}
catch (NoSuchMethodException e) {
LOG.info(e);
myBrokenClasses.add(className);
myBrokenClasses.put(className, e.getCause());
}
try {
@@ -326,7 +327,7 @@ class ProjectCallback extends LegacyCallback implements IProjectCallback {
}
@NotNull
public Set<String> getBrokenClasses() {
public Map<String, Throwable> getBrokenClasses() {
return myBrokenClasses;
}
@@ -7,6 +7,7 @@ import com.android.ide.common.resources.configuration.FolderConfiguration;
import com.android.ide.common.resources.configuration.VersionQualifier;
import com.android.io.*;
import com.android.sdklib.IAndroidTarget;
import com.android.sdklib.SdkConstants;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
@@ -30,10 +31,7 @@ import org.xmlpull.v1.XmlPullParserException;
import javax.imageio.ImageIO;
import java.io.*;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.*;
/**
* @author Eugene.Kudelevsky
@@ -115,23 +113,6 @@ class RenderUtil {
return false;
}
final Result result = session.getResult();
if (!result.isSuccess()) {
final Throwable exception = result.getException();
if (exception != null) {
throw new RenderingException(exception);
}
final String message = result.getErrorMessage();
if (message != null) {
LOG.info(message);
throw new RenderingException();
}
return false;
}
final String format = FileUtil.getExtension(imgPath);
ImageIO.write(session.getImage(), format, new File(imgPath));
if (missingRClass && callback.hasLoadedClasses()) {
warningBuilder.append(missingRClassMessage != null && missingRClassMessage.length() > 0
? ("Class not found error: " + missingRClassMessage + ".")
@@ -152,16 +133,16 @@ class RenderUtil {
}
}
final Set<String> brokenClasses = callback.getBrokenClasses();
final Map<String, Throwable> brokenClasses = callback.getBrokenClasses();
if (brokenClasses.size() > 0) {
if (brokenClasses.size() > 1) {
warningBuilder.append("Unable to initialize:\n");
for (String brokenClass : brokenClasses) {
for (String brokenClass : brokenClasses.keySet()) {
warningBuilder.append(" ").append(brokenClass).append('\n');
}
}
else {
warningBuilder.append("Unable to initialize ").append(brokenClasses.iterator().next());
warningBuilder.append("Unable to initialize ").append(brokenClasses.keySet().iterator().next());
}
}
@@ -169,9 +150,48 @@ class RenderUtil {
warningBuilder.deleteCharAt(warningBuilder.length() - 1);
}
final Result result = session.getResult();
if (!result.isSuccess()) {
final Throwable exception = result.getException();
if (exception != null) {
final List<Throwable> exceptionsFromWarnings = getNonNullValues(brokenClasses);
if (exceptionsFromWarnings.size() > 0 &&
exception instanceof ClassCastException &&
(SdkConstants.CLASS_MOCK_VIEW + " cannot be cast to " + SdkConstants.CLASS_VIEWGROUP)
.equalsIgnoreCase(exception.getMessage())) {
throw new RenderingException(exceptionsFromWarnings.toArray(new Throwable[exceptionsFromWarnings.size()]));
}
throw new RenderingException(exception);
}
final String message = result.getErrorMessage();
if (message != null) {
LOG.info(message);
throw new RenderingException();
}
return false;
}
final String format = FileUtil.getExtension(imgPath);
ImageIO.write(session.getImage(), format, new File(imgPath));
return true;
}
@NotNull
private static <T> List<T> getNonNullValues(@NotNull Map<?, T> map) {
final List<T> result = new ArrayList<T>();
for (Map.Entry<?, T> entry : map.entrySet()) {
final T value = entry.getValue();
if (value != null) {
result.add(value);
}
}
return result;
}
private static String getAppLabelToShow(final AndroidFacet facet) {
return ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
@@ -1,29 +1,40 @@
package org.jetbrains.android.uipreview;
import org.jetbrains.annotations.NotNull;
/**
* @author Eugene.Kudelevsky
*/
public class RenderingException extends Exception {
private final String myPresentableMessage;
private final Throwable[] myCauses;
public RenderingException() {
super();
myPresentableMessage = null;
myCauses = new Throwable[0];
}
public RenderingException(String message) {
super(message);
myPresentableMessage = message;
myCauses = new Throwable[0];
}
public RenderingException(String message, Throwable cause) {
super(message, cause);
myPresentableMessage = message;
myCauses = new Throwable[]{cause};
}
public RenderingException(Throwable cause) {
super(cause);
public RenderingException(@NotNull Throwable... causes) {
myPresentableMessage = null;
myCauses = causes;
}
@NotNull
public Throwable[] getCauses() {
return myCauses;
}
public String getPresentableMessage() {
@@ -142,7 +142,7 @@ public class GradleLibraryManager {
}
final File home = getGradleHome(project);
return LocalFileSystem.getInstance().findFileByIoFile(home);
return home == null ? null : LocalFileSystem.getInstance().findFileByIoFile(home);
}
/**
@@ -388,9 +388,9 @@
</action>
<group id="Maven.RefactoringGroup" text="Refactoring">
<add-to-group group-id="RefactoringMenu" anchor="last"/>
<add-to-group group-id="IntroduceActionsGroup" anchor="after" relative-to-action="IntroduceParameter"/>
<separator/>
<action id="refactoring.introduce.property" text="Introduce Property"
<action id="refactoring.introduce.property" text="Property"
class="org.jetbrains.idea.maven.dom.refactorings.introduce.IntroducePropertyAction"
use-shortcut-of="IntroduceVariable"/>
@@ -25,6 +25,7 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.fileEditor.impl.text.TextEditorPsiDataProvider;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
@@ -106,6 +107,10 @@ public class RenameTo extends ShowSuggestions implements SpellCheckerQuickFix {
DataContext dataContext = SimpleDataContext.getSimpleContext(map, DataManager.getInstance().getDataContext(editor.getComponent()));
AnAction action = new RenameElementAction();
final TextRange range = psiElement.getTextRange();
if (range != null) {
editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset());
}
AnActionEvent event = new AnActionEvent(null, dataContext, "", action.getTemplatePresentation(), ActionManager.getInstance(), 0);
action.actionPerformed(event);
if (provider != null) {
@@ -13,28 +13,21 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.NullableComputable;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.impl.PsiManagerImpl;
import com.intellij.psi.impl.cache.CacheManager;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.LocalSearchScope;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.UsageSearchContext;
import com.intellij.psi.impl.search.PsiSearchHelperImpl;
import com.intellij.psi.search.*;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.util.CommonProcessors;
import com.intellij.util.Processor;
import com.intellij.util.QueryExecutor;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashSet;
import com.intellij.util.text.CharArrayUtil;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
/**
* @author max
@@ -246,31 +239,25 @@ public class FormReferencesSearcher implements QueryExecutor<PsiReference, Refer
manager.startBatchFilesProcessingMode();
try {
final List<String> words = StringUtil.getWordsIn(name);
if(words.isEmpty()) return true;
final Set<PsiFile> fileSet = new HashSet<PsiFile>();
ApplicationManager.getApplication().runReadAction(new Runnable() {
public void run() {
PsiFile[] filesWithWord = CacheManager.SERVICE.getInstance(project).getFilesWithWord(words.get(0),
UsageSearchContext.IN_PLAIN_TEXT, scope,
true);
ContainerUtil.addAll(fileSet, filesWithWord);
for (int i = 1; i < words.size(); i++) {
ProgressManager.checkCanceled();
String word = words.get(i);
PsiFile[] filesWithThisWord = CacheManager.SERVICE.getInstance(project).getFilesWithWord(word, UsageSearchContext.IN_PLAIN_TEXT, scope, true);
fileSet.retainAll(Arrays.asList(filesWithThisWord));
if (fileSet.isEmpty()) break;
}
CommonProcessors.CollectProcessor<VirtualFile> collector = new CommonProcessors.CollectProcessor<VirtualFile>() {
@Override
protected boolean accept(VirtualFile virtualFile) {
return virtualFile.getFileType() == StdFileTypes.GUI_DESIGNER_FORM;
}
});
PsiFile[] files = PsiUtilCore.toPsiFileArray(fileSet);
for (PsiFile file : files) {
};
((PsiSearchHelperImpl)PsiSearchHelper.SERVICE.getInstance(project)).processFilesWithText(
scope, UsageSearchContext.IN_PLAIN_TEXT, true, name, collector, null
);
for (final VirtualFile vfile:collector.getResults()) {
ProgressManager.checkCanceled();
if (file.getFileType() != StdFileTypes.GUI_DESIGNER_FORM) continue;
PsiFile file = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile>() {
@Override
public PsiFile compute() {
return PsiManager.getInstance(project).findFile(vfile);
}
});
if (!processReferences(processor, file, name, property, filterScope)) return false;
}
}
@@ -15,7 +15,6 @@
*/
package org.intellij.lang.xpath.psi.impl;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
@@ -25,25 +24,41 @@ import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlAttributeValue;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.CommonProcessors;
import com.intellij.util.Processor;
import org.jetbrains.annotations.Nullable;
import gnu.trove.THashSet;
import gnu.trove.TObjectHashingStrategy;
import org.intellij.lang.xpath.xslt.impl.XsltIncludeIndex;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class ResolveUtil {
public static final Key<List<PsiElement>> DEPENDENCIES = Key.create("XSLT_DEPENDENCIES");
@SuppressWarnings({"unchecked"})
@SuppressWarnings({"unchecked"})
private final THashSet<PsiElement> myHistory = new THashSet<PsiElement>(TObjectHashingStrategy.IDENTITY);
private ResolveUtil() {
}
@Nullable
public static Collection<XmlFile> getDependencies(XmlFile element) {
final CommonProcessors.CollectUniquesProcessor<XmlFile> processor = new CommonProcessors.CollectUniquesProcessor<XmlFile>() {
@Override
public boolean process(XmlFile file) {
if (!getResults().contains(file)) {
XsltIncludeIndex.processForwardDependencies(file, this);
}
return super.process(file);
}
};
XsltIncludeIndex.processForwardDependencies(element, processor);
return processor.getResults();
}
@Nullable
public static PsiFile resolveFile(String name, PsiFile baseFile) {
if (baseFile == null) return null;
@@ -18,7 +18,6 @@ package org.intellij.lang.xpath.xslt.context;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.UserDataCache;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.CachedValueProvider;
import com.intellij.psi.util.CachedValuesManager;
import com.intellij.psi.util.ParameterizedCachedValue;
@@ -27,7 +26,6 @@ import com.intellij.psi.xml.XmlElement;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.ArrayUtil;
import com.intellij.util.SmartList;
import org.apache.commons.collections.map.CompositeMap;
import org.intellij.lang.xpath.context.ContextType;
import org.intellij.lang.xpath.context.XPathVersion;
@@ -45,8 +43,8 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.xml.namespace.QName;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Xslt2ContextProvider extends XsltContextProviderBase {
@@ -170,14 +168,15 @@ public class Xslt2ContextProvider extends XsltContextProviderBase {
candidates.put(Pair.create(function.getQName(), function.getParameters().length), function);
}
List<PsiElement> data = param.getUserData(ResolveUtil.DEPENDENCIES);
if (data == null) {
data = new SmartList<PsiElement>(param);
final Collection<XmlFile> data = ResolveUtil.getDependencies(param);
final Object[] dependencies;
if (data == null || data.size() == 0) {
dependencies = new Object[]{ param };
} else {
data.add(param);
param.putUserData(ResolveUtil.DEPENDENCIES, null);
dependencies = ArrayUtil.toObjectArray(data);
}
return CachedValueProvider.Result.create(candidates, ArrayUtil.toObjectArray(data));
return CachedValueProvider.Result.create(candidates, dependencies);
}
}
}
@@ -40,41 +40,55 @@ public class XsltIncludeIndex {
public static boolean isReachableFrom(XmlFile which, XmlFile from) {
return from == which || _isReachableFrom(from.getVirtualFile(), FileIncludeManager.getManager(which.getProject()).getIncludingFiles(which.getVirtualFile(), true));
}
}
private static boolean _isReachableFrom(VirtualFile from, VirtualFile[] which) {
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < which.length; i++) {
final VirtualFile file = which[i];
if (file == from) {
return true;
}
}
return false;
}
public static boolean processBackwardDependencies(@NotNull XmlFile file, Processor<XmlFile> processor) {
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) {
private static boolean _isReachableFrom(VirtualFile from, VirtualFile[] which) {
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < which.length; i++) {
final VirtualFile file = which[i];
if (file == from) {
return true;
}
final Project project = file.getProject();
final PsiManager psiManager = PsiManager.getInstance(project);
}
return false;
}
final VirtualFile[] files = FileIncludeManager.getManager(project).getIncludingFiles(virtualFile, true);
final PsiFile[] psiFiles = ContainerUtil.map2Array(files, PsiFile.class, new NullableFunction<VirtualFile, PsiFile>() {
public PsiFile fun(VirtualFile file) {
return psiManager.findFile(file);
}
});
for (final PsiFile psiFile : psiFiles) {
if (XsltSupport.isXsltFile(psiFile)) {
if (!processor.process((XmlFile)psiFile)) {
return false;
}
}
}
public static boolean processForwardDependencies(@NotNull XmlFile file, Processor<XmlFile> processor) {
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) {
return true;
}
final Project project = file.getProject();
}
final VirtualFile[] files = FileIncludeManager.getManager(project).getIncludedFiles(virtualFile, true);
return _process(files, project, processor);
}
public static boolean processBackwardDependencies(@NotNull XmlFile file, Processor<XmlFile> processor) {
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) {
return true;
}
final Project project = file.getProject();
final VirtualFile[] files = FileIncludeManager.getManager(project).getIncludingFiles(virtualFile, true);
return _process(files, project, processor);
}
private static boolean _process(VirtualFile[] files, Project project, Processor<XmlFile> processor) {
final PsiManager psiManager = PsiManager.getInstance(project);
final PsiFile[] psiFiles = ContainerUtil.map2Array(files, PsiFile.class, new NullableFunction<VirtualFile, PsiFile>() {
public PsiFile fun(VirtualFile file) {
return psiManager.findFile(file);
}
});
for (final PsiFile psiFile : psiFiles) {
if (XsltSupport.isXsltFile(psiFile)) {
if (!processor.process((XmlFile)psiFile)) {
return false;
}
}
}
return true;
}
}
@@ -15,20 +15,15 @@
*/
package org.intellij.lang.xpath.xslt.util;
import com.intellij.psi.PsiElement;
import com.intellij.util.SmartList;
import com.intellij.psi.PsiFile;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlDocument;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
import org.intellij.lang.xpath.psi.impl.ResolveUtil;
import org.intellij.lang.xpath.xslt.XsltSupport;
import com.intellij.psi.xml.XmlTag;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlDocument;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public abstract class IncludeAwareMatcher extends BaseMatcher {
protected final XmlDocument myDocument;
@@ -53,14 +48,6 @@ public abstract class IncludeAwareMatcher extends BaseMatcher {
final PsiFile file = ResolveUtil.resolveFile(href, f);
if (file instanceof XmlFile) {
final List<PsiElement> data = myDocument.getContainingFile().getUserData(ResolveUtil.DEPENDENCIES);
if (data == null) {
myDocument.getContainingFile().putUserData(ResolveUtil.DEPENDENCIES, new SmartList<PsiElement>(file));
} else if (!data.contains(file)) {
data.add(file);
}
return Result.create(changeDocument(((XmlFile)file).getDocument()));
}
}
@@ -59,4 +59,14 @@ public abstract class AbstractFrame<F extends Frame> implements Frame<F> {
public boolean isValid() {
return myValid;
}
protected static void debug(Throwable e) {
assert _debug(e);
}
@SuppressWarnings("CallToPrintStackTrace")
private static boolean _debug(Throwable e) {
e.printStackTrace();
return true;
}
}
@@ -218,7 +218,7 @@ class SaxonFrameImpl extends AbstractSaxonFrame<Debugger.StyleFrame, StyleElemen
list.add(new Node(new URI(id.replaceAll(" ", "%20")).normalize().toASCIIString(), node.getLineNumber(), path,
node.getStringValue()));
} catch (URISyntaxException e) {
e.printStackTrace();
debug(e);
list.add(new Node(id, node.getLineNumber(), path, node.getStringValue()));
}
} else {
@@ -31,11 +31,13 @@ import net.sf.saxon.type.TypeHierarchy;
import net.sf.saxon.value.SequenceType;
import org.intellij.plugins.xsltDebugger.rt.engine.Debugger;
import org.intellij.plugins.xsltDebugger.rt.engine.Value;
import org.intellij.plugins.xsltDebugger.rt.engine.local.VariableComparator;
import org.intellij.plugins.xsltDebugger.rt.engine.local.VariableImpl;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -60,6 +62,8 @@ class Saxon9StyleFrame<N extends StyleElement> extends AbstractSaxon9Frame<Debug
}
public Value eval(String expr) throws Debugger.EvaluationException {
assert isValid();
Saxon9TraceListener.MUTED = true;
try {
Expression expression =
@@ -83,23 +87,19 @@ class Saxon9StyleFrame<N extends StyleElement> extends AbstractSaxon9Frame<Debug
}
return new SequenceValue(value, it, itemType);
} catch (AssertionError e) {
assert debug(e);
debug(e);
throw new Debugger.EvaluationException(e.getMessage() != null ? e.getMessage() : e.toString());
} catch (Exception e) {
assert debug(e);
debug(e);
throw new Debugger.EvaluationException(e.getMessage() != null ? e.getMessage() : e.toString());
} finally {
Saxon9TraceListener.MUTED = false;
}
}
@SuppressWarnings("CallToPrintStackTrace")
private static boolean debug(Throwable e) {
e.printStackTrace();
return true;
}
public List<Debugger.Variable> getVariables() {
assert isValid();
final ArrayList<Debugger.Variable> variables = new ArrayList<Debugger.Variable>();
final HashMap<StructuredQName,GlobalVariable> globalVariables =
@@ -177,6 +177,8 @@ class Saxon9StyleFrame<N extends StyleElement> extends AbstractSaxon9Frame<Debug
//System.out.println("context = " + context);
}
Collections.sort(variables, VariableComparator.INSTANCE);
return variables;
}
@@ -67,12 +67,15 @@ class XalanStyleFrame extends AbstractFrame<Debugger.StyleFrame> implements Debu
final String name = variable.getName().getLocalName();
try {
final Value value = new XObjectValue(variable.getValue(myTransformer, myCurrentNode));
final Value value = kind == Debugger.Variable.Kind.PARAMETER ?
eval("$" + variable.getName().toNamespacedString()) : // http://youtrack.jetbrains.net/issue/IDEA-78638
new XObjectValue(variable.getValue(myTransformer, myCurrentNode));
variables.add(new VariableImpl(name, value, global, kind, variable.getSystemId(), variable.getLineNumber()));
} catch (TransformerException e) {
// TODO
e.printStackTrace();
debug(e);
} catch (Debugger.EvaluationException e) {
debug(e);
}
}
@@ -85,13 +88,15 @@ class XalanStyleFrame extends AbstractFrame<Debugger.StyleFrame> implements Debu
}
public List<Debugger.Variable> getVariables() {
assert isValid();
return collectVariables();
}
private List<Debugger.Variable> collectVariables() {
List<Debugger.Variable> variables = new ArrayList<Debugger.Variable>();
@SuppressWarnings({ "unchecked" })
@SuppressWarnings({"unchecked", "UseOfObsoleteCollectionType"})
final Vector<ElemVariable> globals = myTransformer.getStylesheet().getVariablesAndParamsComposed();
for (ElemVariable variable : globals) {
addVariable(variable, true, variables);
@@ -127,6 +132,8 @@ class XalanStyleFrame extends AbstractFrame<Debugger.StyleFrame> implements Debu
}
public Value eval(String expr) throws Debugger.EvaluationException {
assert isValid();
try {
final DTMIterator context = myTransformer.getContextNodeList();
@@ -164,7 +171,7 @@ class XalanStyleFrame extends AbstractFrame<Debugger.StyleFrame> implements Debu
final XPath xPath = new XPath(expr, myCurrentElement, prefixResolver, XPath.SELECT, myTransformer.getErrorListener());
return new XObjectValue(xPath.execute(myContext, myCurrentNode, myCurrentElement));
} catch (Exception e) {
e.printStackTrace();
debug(e);
final String message = e.getMessage();
throw new Debugger.EvaluationException(message != null ? message : e.getClass().getSimpleName());
}