mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Merge remote-tracking branch 'origin/upsource-master' into upsource-master
This commit is contained in:
@@ -16,14 +16,14 @@
|
||||
package com.intellij.framework.library;
|
||||
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public interface FrameworkSupportWithLibrary {
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
CustomLibraryDescription createLibraryDescription();
|
||||
|
||||
boolean isLibraryOnly();
|
||||
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.psi.impl.source.codeStyle;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import com.intellij.psi.impl.source.tree.ElementType;
|
||||
import com.intellij.psi.impl.source.tree.JavaJspElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* There is a possible case that the project is configured to keep fields in columns:
|
||||
* <pre>
|
||||
* class Test {
|
||||
* int i = 1;
|
||||
* int fieldWithLongName = 2;
|
||||
* }
|
||||
* </pre>
|
||||
* Suppose that one of the fields is renamed. We want to reformat the whole fields group then in order to keep that 'field columns'.
|
||||
* <p/>
|
||||
* Current extension checks if given range intersects with a field from a field group and expands its boundaries to contain
|
||||
* the whole group.
|
||||
* <p/>
|
||||
* Thread-safe.
|
||||
*
|
||||
* @author Denis Zhdanov
|
||||
* @since 5/9/12 4:54 PM
|
||||
*/
|
||||
public class FieldInColumnsPreFormatProcessor implements PreFormatProcessor {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TextRange process(@NotNull ASTNode element, @NotNull TextRange range) {
|
||||
//region Checking that everything is ready to expand the range for the 'fields in columns'.
|
||||
final PsiElement psi = element.getPsi();
|
||||
if (psi == null) {
|
||||
return range;
|
||||
}
|
||||
|
||||
final PsiFile file = psi.getContainingFile();
|
||||
if (file == null) {
|
||||
return range;
|
||||
}
|
||||
|
||||
final Project project = psi.getProject();
|
||||
final CommonCodeStyleSettings settings
|
||||
= CodeStyleSettingsManager.getInstance(project).getCurrentSettings().getCommonSettings(JavaLanguage.INSTANCE);
|
||||
if (!settings.ALIGN_GROUP_FIELD_DECLARATIONS) {
|
||||
return range;
|
||||
}
|
||||
|
||||
final PsiElement startElement = file.findElementAt(range.getStartOffset());
|
||||
if (startElement == null) {
|
||||
return range;
|
||||
}
|
||||
|
||||
final PsiField parent = PsiTreeUtil.getParentOfType(startElement, PsiField.class);
|
||||
if (parent == null) {
|
||||
return range;
|
||||
}
|
||||
//endregion
|
||||
|
||||
//region Calculating start offset to use by the start offset of the first sibling white space or field to the left of the current field.
|
||||
int startToUse = range.getStartOffset();
|
||||
for (PsiElement f = parent; f != null; f = f.getPrevSibling()) {
|
||||
final ASTNode node = f.getNode();
|
||||
if (node == null) {
|
||||
break;
|
||||
}
|
||||
if (JavaJspElementType.WHITE_SPACE_BIT_SET.contains(node.getElementType()) || f instanceof PsiField) {
|
||||
startToUse = f.getTextRange().getStartOffset();
|
||||
}
|
||||
else if (!ElementType.JAVA_COMMENT_BIT_SET.contains(node.getElementType())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
//endregion
|
||||
|
||||
//region Calculating end offset to use by the end offset of the last field in a group located to the right of the current field.
|
||||
int endToUse = range.getEndOffset();
|
||||
for (PsiElement f = parent; f != null; f = f.getPrevSibling()) {
|
||||
final ASTNode node = f.getNode();
|
||||
if (node == null) {
|
||||
break;
|
||||
}
|
||||
if (f instanceof PsiField) {
|
||||
endToUse = f.getTextRange().getEndOffset();
|
||||
}
|
||||
else if (!JavaJspElementType.WHITE_SPACE_BIT_SET.contains(node.getElementType()) &&
|
||||
!ElementType.JAVA_COMMENT_BIT_SET.contains(node.getElementType()))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
//endregion
|
||||
|
||||
return TextRange.from(startToUse, endToUse);
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,10 +25,12 @@ import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.impl.source.SourceTreeToPsiMap;
|
||||
import com.intellij.psi.impl.source.codeStyle.javadoc.CommentFormatter;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FormatCommentsProcessor implements PreFormatProcessor {
|
||||
@NotNull
|
||||
@Override
|
||||
public TextRange process(final ASTNode element, final TextRange range) {
|
||||
public TextRange process(@NotNull final ASTNode element, @NotNull final TextRange range) {
|
||||
final Project project = SourceTreeToPsiMap.treeElementToPsi(element).getProject();
|
||||
if (!CodeStyleSettingsManager.getSettings(project).ENABLE_JAVADOC_FORMATTING ||
|
||||
element.getPsi().getContainingFile().getLanguage() != StdLanguages.JAVA) {
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
class Test {
|
||||
int jj = 1;
|
||||
int fieldWithLongName = 2;
|
||||
|
||||
void test() {
|
||||
jj = 3;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
class Test {
|
||||
int i = 1;
|
||||
int fieldWithLongName = 2;
|
||||
|
||||
void test() {
|
||||
<caret>i = 3;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: dsl
|
||||
@@ -10,7 +26,9 @@ package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.TargetElementUtilBase;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.refactoring.rename.RenameProcessor;
|
||||
import com.intellij.refactoring.rename.RenameWrongRefHandler;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -66,6 +84,13 @@ public class RenameFieldTest extends LightRefactoringTestCase {
|
||||
assertFalse(RenameWrongRefHandler.isAvailable(getProject(), getEditor(), getFile()));
|
||||
}
|
||||
|
||||
public void testFieldInColumns() throws Exception {
|
||||
// Assuming that test infrastructure setups temp settings (CodeStyleSettingsManager.setTemporarySettings()) and we don't
|
||||
// need to perform explicit clean-up at the test level.
|
||||
CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE).ALIGN_GROUP_FIELD_DECLARATIONS = true;
|
||||
doTest("jj", "java");
|
||||
}
|
||||
|
||||
protected static void perform(String newName) {
|
||||
PsiElement element = TargetElementUtilBase.findTargetElement(myEditor, TargetElementUtilBase
|
||||
.ELEMENT_NAME_ACCEPTED | TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,22 +27,26 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class GotoRelatedItem {
|
||||
private final String myGroup;
|
||||
private final int myMnemonic;
|
||||
private final PsiElement myElement;
|
||||
public static final String DEFAULT_GROUP_NAME = "";
|
||||
|
||||
protected GotoRelatedItem(@Nullable PsiElement element, final int mnemonic) {
|
||||
protected GotoRelatedItem(@Nullable PsiElement element, String group, final int mnemonic) {
|
||||
myElement = element;
|
||||
myGroup = group;
|
||||
myMnemonic = mnemonic;
|
||||
}
|
||||
|
||||
public GotoRelatedItem(@NotNull PsiElement element) {
|
||||
this(element, -1);
|
||||
public GotoRelatedItem(@NotNull PsiElement element, String group) {
|
||||
this(element, group, -1);
|
||||
}
|
||||
|
||||
protected GotoRelatedItem() {
|
||||
this(null, -1);
|
||||
public GotoRelatedItem(@NotNull PsiElement element) {
|
||||
this(element, DEFAULT_GROUP_NAME);
|
||||
}
|
||||
|
||||
public void navigate() {
|
||||
@@ -67,11 +71,14 @@ public class GotoRelatedItem {
|
||||
public int getMnemonic() {
|
||||
return myMnemonic;
|
||||
}
|
||||
|
||||
public static List<GotoRelatedItem> createItems(@NotNull Collection<? extends PsiElement> elements) {
|
||||
return createItems(elements, DEFAULT_GROUP_NAME);
|
||||
}
|
||||
|
||||
public static List<GotoRelatedItem> createItems(@NotNull Collection<? extends PsiElement> elements, String group) {
|
||||
List<GotoRelatedItem> items = new ArrayList<GotoRelatedItem>(elements.size());
|
||||
for (PsiElement element : elements) {
|
||||
items.add(new GotoRelatedItem(element));
|
||||
items.add(new GotoRelatedItem(element, group));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
@@ -88,6 +95,10 @@ public class GotoRelatedItem {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return myGroup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return myElement != null ? myElement.hashCode() : 0;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -236,14 +236,15 @@ public abstract class AbstractBlockWrapper {
|
||||
else {
|
||||
return childIndent.add(myParent.getChildOffset(this, options, targetBlockStartOffset));
|
||||
}
|
||||
} else if (!getWhiteSpace().containsLineFeeds()) {
|
||||
if (isIndentAffectedAlignment(child)) {
|
||||
return createAlignmentIndent(childIndent, child);
|
||||
}
|
||||
else {
|
||||
return childIndent.add(myParent.getChildOffset(this, options, targetBlockStartOffset));
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else if (!getWhiteSpace().containsLineFeeds()) {
|
||||
final IndentData indent = createAlignmentIndent(childIndent, child);
|
||||
if (indent != null) {
|
||||
return indent;
|
||||
}
|
||||
return childIndent.add(myParent.getChildOffset(this, options, targetBlockStartOffset));
|
||||
}
|
||||
else {
|
||||
if (myParent == null) return childIndent.add(getWhiteSpace());
|
||||
if (getIndent().isAbsolute()) {
|
||||
if (myParent.myParent != null) {
|
||||
@@ -254,12 +255,11 @@ public abstract class AbstractBlockWrapper {
|
||||
}
|
||||
}
|
||||
if ((myFlags & CAN_USE_FIRST_CHILD_INDENT_AS_BLOCK_INDENT) != 0) {
|
||||
if (isIndentAffectedAlignment(child)) {
|
||||
return createAlignmentIndent(childIndent, child);
|
||||
}
|
||||
else {
|
||||
return childIndent.add(getWhiteSpace());
|
||||
final IndentData indent = createAlignmentIndent(childIndent, child);
|
||||
if (indent != null) {
|
||||
return indent;
|
||||
}
|
||||
return childIndent.add(getWhiteSpace());
|
||||
}
|
||||
else {
|
||||
return childIndent.add(myParent.getChildOffset(this, options, targetBlockStartOffset));
|
||||
@@ -343,29 +343,8 @@ public abstract class AbstractBlockWrapper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to answer if indent for the given child block should be calculated taking into consideration alignment
|
||||
* of the text at current block start.
|
||||
*
|
||||
* @param child child block to check
|
||||
* @return <code>true</code> if indent should be calculated taking into consideration alignment of the text at current
|
||||
* block start; <code>false</code> otherwise
|
||||
*/
|
||||
private boolean isIndentAffectedAlignment(AbstractBlockWrapper child) {
|
||||
if (!child.getWhiteSpace().containsLineFeeds()) {
|
||||
return false;
|
||||
}
|
||||
AlignmentImpl alignment = getAlignmentAtStartOffset();
|
||||
if (alignment == null || alignment == child.getAlignment()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LeafBlockWrapper anchorOffsetBlock = alignment.getOffsetRespBlockBefore(child);
|
||||
return anchorOffsetBlock == null || anchorOffsetBlock.getStartOffset() >= getStartOffset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to construct indent for the block that is affected by aligning rules. E.g. there is a possible case that the user
|
||||
* configures method call arguments to be aligned and single parameter expression spans more than one line:
|
||||
* Check if it's possible to construct indent for the block that is affected by aligning rules. E.g. there is a possible case
|
||||
* that the user configures method call arguments to be aligned and single parameter expression spans more than one line:
|
||||
* <p/>
|
||||
* <pre>
|
||||
* public void test(String s1, String s2) {}
|
||||
@@ -383,15 +362,41 @@ public abstract class AbstractBlockWrapper {
|
||||
* sub-blocks that are located on new lines should also be indented to the point of composite block start.
|
||||
* <p/>
|
||||
* This method takes care about constructing target absolute indent of the given child block assuming that it's parent
|
||||
* (referenced by <code>'this'</code>) or it's ancestor that starts at the same offset is aligned. I.e. it assumes
|
||||
* that {@link #isIndentAffectedAlignment(AbstractBlockWrapper)} returns <code>true</code> for the given child block.
|
||||
* (referenced by <code>'this'</code>) or it's ancestor that starts at the same offset is aligned.
|
||||
*
|
||||
* @param indentFromParent basic indent of given child from the current parent block
|
||||
* @param child child block of the current aligned composite block
|
||||
* @return absolute indent to use for the given child block of the current composite block
|
||||
* @return absolute indent to use for the given child block of the current composite block if alignment-affected
|
||||
* indent should be used for it;
|
||||
* <code>null</code> otherwise
|
||||
*/
|
||||
@Nullable
|
||||
private IndentData createAlignmentIndent(IndentData indentFromParent, AbstractBlockWrapper child) {
|
||||
if (!child.getWhiteSpace().containsLineFeeds()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
AlignmentImpl alignment = getAlignmentAtStartOffset();
|
||||
if (alignment == null || alignment == child.getAlignment()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
AbstractBlockWrapper previous = child.getPreviousBlock();
|
||||
LeafBlockWrapper anchorOffsetBlock = alignment.getOffsetRespBlockBefore(child);
|
||||
if (anchorOffsetBlock != null && anchorOffsetBlock.getStartOffset() != getStartOffset()) {
|
||||
// Located on different lines.
|
||||
boolean onDifferentLines = false;
|
||||
for (LeafBlockWrapper b = anchorOffsetBlock.getNextBlock(); b != null && b.getStartOffset() < getStartOffset(); b = b.getNextBlock()) {
|
||||
if (b.getWhiteSpace().containsLineFeeds()) {
|
||||
onDifferentLines = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!onDifferentLines) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// There is no point in continuing processing if given child is the first block, i.e. there is no alignment-implied
|
||||
// offset to add to the given 'indent from parent'.
|
||||
@@ -399,7 +404,13 @@ public abstract class AbstractBlockWrapper {
|
||||
return indentFromParent;
|
||||
}
|
||||
|
||||
IndentData symbolsBeforeCurrent = getNumberOfSymbolsBeforeBlock();
|
||||
IndentData symbolsBeforeCurrent;
|
||||
if (anchorOffsetBlock == null) {
|
||||
symbolsBeforeCurrent = getNumberOfSymbolsBeforeBlock();
|
||||
}
|
||||
else {
|
||||
symbolsBeforeCurrent = anchorOffsetBlock.getNumberOfSymbolsBeforeBlock();
|
||||
}
|
||||
|
||||
// Result is calculated as a number of symbols between the current composite parent block plus given 'indent from parent'.
|
||||
int indentSpaces = symbolsBeforeCurrent.getIndentSpaces() + indentFromParent.getSpaces() + indentFromParent.getIndentSpaces();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,11 +26,14 @@ import com.intellij.openapi.ui.popup.JBPopup;
|
||||
import com.intellij.openapi.ui.popup.PopupStep;
|
||||
import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.ui.ColoredListCellRenderer;
|
||||
import com.intellij.ui.SeparatorWithText;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.intellij.ui.popup.list.ListPopupImpl;
|
||||
import com.intellij.ui.popup.list.PopupListElementRenderer;
|
||||
import com.intellij.util.Processor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -97,6 +100,8 @@ public class GotoRelatedFileAction extends AnAction {
|
||||
final String title, final Processor<Object> processor) {
|
||||
|
||||
final Ref<Boolean> hasMnemonic = Ref.create(false);
|
||||
final Ref<ListCellRenderer> rendererRef = Ref.create(null);
|
||||
|
||||
final DefaultPsiElementCellRenderer renderer = new DefaultPsiElementCellRenderer() {
|
||||
{
|
||||
setFocusBorderEnabled(false);
|
||||
@@ -190,12 +195,55 @@ public class GotoRelatedFileAction extends AnAction {
|
||||
return super.onChosen(selectedValue, finalChoice);
|
||||
}
|
||||
}) {
|
||||
@Override
|
||||
protected ListCellRenderer getListElementRenderer() {
|
||||
return renderer;
|
||||
}
|
||||
};
|
||||
popup.getList().setCellRenderer(new PopupListElementRenderer(popup) {
|
||||
Map<Object, String> separators = new HashMap<Object, String>();
|
||||
{
|
||||
final ListModel model = popup.getList().getModel();
|
||||
String current = null;
|
||||
boolean hasTitle = false;
|
||||
for (int i = 0; i < model.getSize(); i++) {
|
||||
final Object element = model.getElementAt(i);
|
||||
final GotoRelatedItem item = itemsMap.get(element);
|
||||
if (!StringUtil.equals(current, item.getGroup())) {
|
||||
current = item.getGroup();
|
||||
separators.put(element, current);
|
||||
if (!hasTitle && !StringUtil.isEmpty(current)) {
|
||||
hasTitle = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasTitle) {
|
||||
separators.remove(model.getElementAt(0));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
final Component component = renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
final String separator = separators.get(value);
|
||||
|
||||
if (separator != null) {
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
panel.add(component, BorderLayout.CENTER);
|
||||
final SeparatorWithText sep = new SeparatorWithText() {
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
g.setColor(Color.WHITE);
|
||||
g.fillRect(0,0,getWidth(), getHeight());
|
||||
super.paintComponent(g);
|
||||
}
|
||||
};
|
||||
sep.setCaption(separator);
|
||||
panel.add(sep, BorderLayout.NORTH);
|
||||
return panel;
|
||||
}
|
||||
return component;
|
||||
}
|
||||
});
|
||||
|
||||
popup.setMinimumSize(new Dimension(200, -1));
|
||||
|
||||
for (Object item : elements) {
|
||||
final int mnemonic = getMnemonic(item, itemsMap);
|
||||
if (mnemonic != -1) {
|
||||
@@ -226,9 +274,32 @@ public class GotoRelatedFileAction extends AnAction {
|
||||
items.addAll(provider.getItems(dataContext));
|
||||
}
|
||||
}
|
||||
sortByGroupNames(items);
|
||||
return new ArrayList<GotoRelatedItem>(items);
|
||||
}
|
||||
|
||||
private static void sortByGroupNames(Set<GotoRelatedItem> items) {
|
||||
Map<String, List<GotoRelatedItem>> map = new HashMap<String, List<GotoRelatedItem>>();
|
||||
for (GotoRelatedItem item : items) {
|
||||
final String key = item.getGroup();
|
||||
if (!map.containsKey(key)) {
|
||||
map.put(key, new ArrayList<GotoRelatedItem>());
|
||||
}
|
||||
map.get(key).add(item);
|
||||
}
|
||||
final List<String> keys = new ArrayList<String>(map.keySet());
|
||||
Collections.sort(keys, new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
return StringUtil.isEmpty(o1) ? 1 : StringUtil.isEmpty(o2) ? -1 : o1.compareTo(o2);
|
||||
}
|
||||
});
|
||||
items.clear();
|
||||
for (String key : keys) {
|
||||
items.addAll(map.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
e.getPresentation().setEnabled(LangDataKeys.PSI_FILE.getData(e.getDataContext()) != null);
|
||||
|
||||
+4
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,6 +19,7 @@ package com.intellij.psi.impl.source.codeStyle;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
@@ -26,5 +27,6 @@ import com.intellij.openapi.util.TextRange;
|
||||
public interface PreFormatProcessor {
|
||||
ExtensionPointName<PreFormatProcessor> EP_NAME = ExtensionPointName.create("com.intellij.preFormatProcessor");
|
||||
|
||||
TextRange process(ASTNode element, TextRange range);
|
||||
@NotNull
|
||||
TextRange process(@NotNull ASTNode element, @NotNull TextRange range);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,15 +35,17 @@ public class GotoTestRelatedProvider extends GotoRelatedProvider {
|
||||
public List<? extends GotoRelatedItem> getItems(@NotNull DataContext context) {
|
||||
final PsiFile file = LangDataKeys.PSI_FILE.getData(context);
|
||||
List<PsiElement> result;
|
||||
if (TestFinderHelper.isTest(file)) {
|
||||
final boolean isTest = TestFinderHelper.isTest(file);
|
||||
if (isTest) {
|
||||
result = TestFinderHelper.findClassesForTest(file);
|
||||
} else {
|
||||
result = TestFinderHelper.findTestsForClass(file);
|
||||
}
|
||||
|
||||
if (!result.isEmpty()) {
|
||||
final List<GotoRelatedItem> items = new ArrayList<GotoRelatedItem>();
|
||||
for (PsiElement element : result) {
|
||||
items.add(new GotoRelatedItem(element));
|
||||
items.add(new GotoRelatedItem(element, isTest ? "Tests" : "Testee classes"));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -89,7 +89,6 @@ public class JarFileSystemImpl extends JarFileSystem implements ApplicationCompo
|
||||
SystemInfo.isFileSystemCaseSensitive)) {
|
||||
VirtualFile jarRootToRefresh = markDirty(jarPath);
|
||||
if (jarRootToRefresh != null) {
|
||||
LOG.info(jarPath + " will be refreshed due to " + event);
|
||||
rootsToRefresh.add(jarRootToRefresh);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -183,6 +183,10 @@ public class ListPopupImpl extends WizardPopup implements ListPopup {
|
||||
return count;
|
||||
}
|
||||
|
||||
public JList getList() {
|
||||
return myList;
|
||||
}
|
||||
|
||||
protected JComponent createContent() {
|
||||
myMouseMotionListener = new MyMouseMotionListener();
|
||||
myMouseListener = new MyMouseListener();
|
||||
|
||||
@@ -340,7 +340,7 @@ checkbox.collapse.xml.tags=XML tags
|
||||
checkbox.collapse.anonymous.classes=<html>Anonymous classes</html>
|
||||
checkbox.collapse.closures=<html>"Closures" (anonymous classes implementing one method)</html>
|
||||
checkbox.collapse.generic.constructor.parameters=<html>Generic constructor and method parameters</html>
|
||||
checkbox.collapse.i18n.messages=<html>I18n Strings</html>
|
||||
checkbox.collapse.i18n.messages=<html>I18n strings</html>
|
||||
checkbox.collapse.annotations=<html>Annotations</html>
|
||||
checkbox.collapse.inner.classes=Inner classes
|
||||
checkbox.collapse.simple.property.accessors=<html>Simple property accessors<html>
|
||||
|
||||
@@ -287,7 +287,7 @@ logs.tab.title=Logs
|
||||
before.launch.panel.title=Before Launch
|
||||
before.launch.panel.empty=There are no tasks to run before launch
|
||||
before.launch.panel.cyclic_dependency_warning=''{0}'' has already configured to be launched before {1}.\nSuch cyclic dependencies are not allowed.
|
||||
before.launch.run.another.configuration=Run another Configuration
|
||||
before.launch.run.another.configuration=Run Another Configuration
|
||||
before.launch.run.certain.configuration=Run ''{0}''
|
||||
before.launch.run.unknown.task=Unknown task
|
||||
action.name.save.as.configuration=Save As
|
||||
|
||||
@@ -36,6 +36,7 @@ import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings({"HardCodedStringLiteral", "UseOfSystemOutOrSystemErr", "CallToPrintStackTrace", "TestOnlyProblems"})
|
||||
public class TestCaseLoader {
|
||||
@@ -98,7 +99,9 @@ public class TestCaseLoader {
|
||||
* <code>shouldLoadTestCase ()</code> to determine that.
|
||||
*/
|
||||
void addClassIfTestCase(final Class testCaseClass) {
|
||||
if (shouldAddTestCase(testCaseClass, true) && testCaseClass != myFirstTestClass && testCaseClass != myLastTestClass) {
|
||||
if (shouldAddTestCase(testCaseClass, true) && testCaseClass != myFirstTestClass && testCaseClass != myLastTestClass
|
||||
&& PlatformTestUtil.canRunTest(testCaseClass))
|
||||
{
|
||||
myClassList.add(testCaseClass);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -448,6 +448,18 @@ public class PlatformTestUtil {
|
||||
return total/(n / part);
|
||||
}
|
||||
|
||||
public static boolean canRunTest(@NotNull Class testCaseClass) {
|
||||
if (GraphicsEnvironment.isHeadless()) {
|
||||
for (Class<?> clazz = testCaseClass; clazz != null; clazz = clazz.getSuperclass()) {
|
||||
if (clazz.getAnnotation(SkipInHeadlessEnvironment.class) != null) {
|
||||
System.out.println("Class '" + testCaseClass.getName() + "' is skipped because it requires working UI environment");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class TestInfo {
|
||||
private final ThrowableRunnable test; // runnable to measure
|
||||
private final int expected; // millis the test is expected to run
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -258,17 +258,7 @@ public abstract class UsefulTestCase extends TestCase {
|
||||
}
|
||||
|
||||
protected boolean shouldRunTest() {
|
||||
if (isInHeadlessEnvironment()) {
|
||||
Class<?> aClass = getClass();
|
||||
while (aClass != null) {
|
||||
if (aClass.getAnnotation(SkipInHeadlessEnvironment.class) != null) {
|
||||
System.out.println("Test '" + getClass().getName() + "." + getName() + "' is skipped because it requires working UI environment");
|
||||
return false;
|
||||
}
|
||||
aClass = aClass.getSuperclass();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return PlatformTestUtil.canRunTest(getClass());
|
||||
}
|
||||
|
||||
public static void edt(Runnable r) {
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.testAssistant;
|
||||
|
||||
import com.intellij.navigation.GotoRelatedItem;
|
||||
@@ -22,7 +37,7 @@ public class TestDataRelatedItem extends GotoRelatedItem{
|
||||
private final PsiMethod myMethod;
|
||||
|
||||
public TestDataRelatedItem(@NotNull PsiMethod method, @NotNull Editor editor, @NotNull Collection<String> testDataFiles) {
|
||||
super(method);
|
||||
super(method, "Test Data");
|
||||
myMethod = method;
|
||||
myEditor = editor;
|
||||
myTestDataFiles.addAll(testDataFiles);
|
||||
|
||||
@@ -180,7 +180,7 @@
|
||||
<grid row="4" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="A&dd Blank Line After"/>
|
||||
<text value="A&dd blank line after"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="81563" class="javax.swing.JLabel" binding="mySeparatorCharLabel">
|
||||
|
||||
@@ -265,6 +265,12 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
GrExpression qualifier = referenceExpression.getQualifierExpression();
|
||||
if (qualifier == null && isDeclarationAssignment(referenceExpression)) return;
|
||||
|
||||
if (qualifier != null && referenceExpression.getDotTokenType() == GroovyTokenTypes.mMEMBER_POINTER) {
|
||||
if (results.length > 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If it is reference to map.key we shouldn't highlight key unresolved
|
||||
if (!(parent instanceof GrCall) && ResolveUtil.isKeyOfMap(referenceExpression)) {
|
||||
PsiElement refNameElement = referenceExpression.getReferenceNameElement();
|
||||
|
||||
+11
@@ -46,6 +46,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArg
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrReturnStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrThrowStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrIndexProperty;
|
||||
@@ -349,6 +350,16 @@ public class GroovyAssignabilityCheckInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitThrowStatement(GrThrowStatement throwStatement) {
|
||||
super.visitThrowStatement(throwStatement);
|
||||
|
||||
final GrExpression exception = throwStatement.getException();
|
||||
if (exception != null) {
|
||||
checkAssignability(PsiType.getJavaLangThrowable(throwStatement.getManager(), throwStatement.getResolveScope()), exception, exception);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkLiteralConstructorApplicability(GroovyResolveResult result, GrListOrMap listOrMap, boolean checkUnknownArgs) {
|
||||
final PsiElement element = result.getElement();
|
||||
LOG.assertTrue(element instanceof PsiMethod && ((PsiMethod)element).isConstructor());
|
||||
|
||||
+18
-23
@@ -89,19 +89,6 @@ public class MvcProjectViewPane extends AbstractProjectViewPSIPane implements Id
|
||||
myDescriptor = descriptor;
|
||||
myId = descriptor.getToolWindowId();
|
||||
|
||||
myAutoScrollFromSourceHandler = new MyAutoScrollFromSourceHandler();
|
||||
myAutoScrollToSourceHandler = new AutoScrollToSourceHandler() {
|
||||
@Override
|
||||
protected boolean isAutoScrollMode() {
|
||||
return myAutoScrollToSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAutoScrollMode(boolean state) {
|
||||
myAutoScrollToSource = state;
|
||||
}
|
||||
};
|
||||
|
||||
class TreeUpdater implements Runnable, PsiModificationTracker.Listener {
|
||||
private volatile boolean myInQueue;
|
||||
|
||||
@@ -127,6 +114,23 @@ public class MvcProjectViewPane extends AbstractProjectViewPSIPane implements Id
|
||||
myComponent = createComponent();
|
||||
DataManager.registerDataProvider(myComponent, this);
|
||||
|
||||
myAutoScrollFromSourceHandler = new MyAutoScrollFromSourceHandler();
|
||||
myAutoScrollToSourceHandler = new AutoScrollToSourceHandler() {
|
||||
@Override
|
||||
protected boolean isAutoScrollMode() {
|
||||
return myAutoScrollToSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAutoScrollMode(boolean state) {
|
||||
myAutoScrollToSource = state;
|
||||
}
|
||||
};
|
||||
|
||||
myAutoScrollFromSourceHandler.install();
|
||||
myAutoScrollToSourceHandler.install(getTree());
|
||||
myAutoScrollToSourceHandler.onMouseClicked(getTree());
|
||||
|
||||
myCopyPasteDelegator = new CopyPasteDelegator(project, myComponent) {
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -166,15 +170,6 @@ public class MvcProjectViewPane extends AbstractProjectViewPSIPane implements Id
|
||||
toolWindow.setTitleActions(new AnAction[]{new ScrollFromSourceAction(), collapseAction});
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
JComponent component = super.createComponent();
|
||||
myAutoScrollFromSourceHandler.install();
|
||||
myAutoScrollToSourceHandler.install(getTree());
|
||||
myAutoScrollToSourceHandler.onMouseClicked(getTree());
|
||||
return component;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@@ -462,7 +457,7 @@ public class MvcProjectViewPane extends AbstractProjectViewPSIPane implements Id
|
||||
|
||||
private class MyAutoScrollFromSourceHandler extends AutoScrollFromSourceHandler {
|
||||
protected MyAutoScrollFromSourceHandler() {
|
||||
super(MvcProjectViewPane.this.myProject, getTree(), MvcProjectViewPane.this);
|
||||
super(MvcProjectViewPane.this.myProject, myComponent, MvcProjectViewPane.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+22
-10
@@ -867,7 +867,7 @@ C<error descr="Wrong number of type arguments: 2; required: 1"><String, Double><
|
||||
}
|
||||
|
||||
public void testRawClosureReturnType() {
|
||||
myFixture.configureByText('_.groovy', '''\
|
||||
testHighlighting('''\
|
||||
class A<T> {
|
||||
A(T t) {this.t = t}
|
||||
|
||||
@@ -880,17 +880,17 @@ class A<T> {
|
||||
|
||||
def a = new A(new Date())
|
||||
Date d = <warning descr="Cannot assign 'Object' to 'Date'">a.cl()</warning>
|
||||
''')
|
||||
testHighlighting(GroovyUncheckedAssignmentOfMemberOfRawTypeInspection)
|
||||
''', GroovyUncheckedAssignmentOfMemberOfRawTypeInspection)
|
||||
}
|
||||
|
||||
private void testHighlighting(Class<? extends LocalInspectionTool>... inspections) {
|
||||
private void testHighlighting(String text, Class<? extends LocalInspectionTool>... inspections) {
|
||||
myFixture.configureByText('_.groovy', text)
|
||||
myFixture.enableInspections(inspections)
|
||||
myFixture.testHighlighting(true, false, true)
|
||||
}
|
||||
|
||||
void testMethodRefs1() {
|
||||
myFixture.configureByText('_.groovy', '''\
|
||||
testHighlighting('''\
|
||||
class A {
|
||||
int foo(){2}
|
||||
|
||||
@@ -903,12 +903,11 @@ int i = foo()
|
||||
int i2 = <warning descr="Cannot assign 'Date' to 'int'">foo(2)</warning>
|
||||
Date d = foo(2)
|
||||
Date d2 = <warning descr="Cannot assign 'Integer' to 'Date'">foo()</warning>
|
||||
''')
|
||||
testHighlighting(GroovyAssignabilityCheckInspection)
|
||||
''', GroovyAssignabilityCheckInspection)
|
||||
}
|
||||
|
||||
void testMethodRefs2() {
|
||||
myFixture.configureByText('_.groovy', '''\
|
||||
testHighlighting('''\
|
||||
class Bar {
|
||||
def foo(int i, String s2) {s2}
|
||||
def foo(int i, int i2) {i2}
|
||||
@@ -920,8 +919,21 @@ String s = cl("2")
|
||||
int s2 = <warning descr="Cannot assign 'String' to 'int'">cl("2")</warning>
|
||||
int i = cl(3)
|
||||
String i2 = cl(3)
|
||||
''')
|
||||
testHighlighting(GroovyAssignabilityCheckInspection)
|
||||
''', GroovyAssignabilityCheckInspection)
|
||||
}
|
||||
|
||||
void testThrowObject() {
|
||||
testHighlighting('''\
|
||||
def foo() {
|
||||
throw new RuntimeException()
|
||||
}
|
||||
def bar () {
|
||||
throw <warning descr="Cannot assign 'Object' to 'Throwable'">new Object()</warning>
|
||||
}
|
||||
|
||||
def test() {
|
||||
throw new Throwable()
|
||||
}
|
||||
''', GroovyAssignabilityCheckInspection)
|
||||
}
|
||||
}
|
||||
@@ -236,7 +236,7 @@ public class FormatterTest extends GroovyFormatterTestCase {
|
||||
public void testGeese8() {doGeeseTest();}
|
||||
|
||||
public void testMapInArgumentList() {doTest();}
|
||||
public void testMapInArgumentList2() {
|
||||
public void testMapInArgList2() {
|
||||
myTempSettings.getCustomSettings(GroovyCodeStyleSettings.class).ALIGN_NAMED_ARGS_IN_MAP = true;
|
||||
doTest();
|
||||
}
|
||||
|
||||
@@ -18,11 +18,15 @@ package com.intellij.codeInspection.i18n;
|
||||
import com.intellij.lang.properties.psi.PropertiesFile;
|
||||
import com.intellij.lang.properties.references.CreatePropertyFix;
|
||||
import com.intellij.lang.properties.references.I18nizeQuickFixDialog;
|
||||
import com.intellij.lang.properties.references.I18nizeQuickFixModel;
|
||||
import com.intellij.openapi.application.AccessToken;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiLiteralExpression;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -32,19 +36,47 @@ import java.util.List;
|
||||
* @author Maxim.Mossienko
|
||||
*/
|
||||
public class JavaCreatePropertyFix extends CreatePropertyFix {
|
||||
private static final Logger LOG = Logger.getInstance(JavaCreatePropertyFix.class);
|
||||
|
||||
public JavaCreatePropertyFix() {}
|
||||
|
||||
public JavaCreatePropertyFix(PsiElement element, String key, final List<PropertiesFile> propertiesFiles) {
|
||||
super(element, key, propertiesFiles);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<String, String> doAction(Project project, PsiElement psiElement, I18nizeQuickFixModel model) {
|
||||
final Pair<String, String> result = super.doAction(project, psiElement, model);
|
||||
if (result != null && psiElement instanceof PsiLiteralExpression) {
|
||||
final String key = result.first;
|
||||
|
||||
final StringBuilder buffer = new StringBuilder();
|
||||
buffer.append('"');
|
||||
StringUtil.escapeStringCharacters(key.length(), key, buffer);
|
||||
buffer.append('"');
|
||||
|
||||
final AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(JavaCreatePropertyFix.class);
|
||||
try {
|
||||
final PsiExpression newKeyLiteral = JavaPsiFacade.getElementFactory(project).createExpressionFromText(buffer.toString(), null);
|
||||
psiElement.replace(newKeyLiteral);
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
finally {
|
||||
token.finish();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected static Pair<String, String> invokeAction(@NotNull final Project project,
|
||||
@NotNull PsiFile file,
|
||||
@NotNull PsiElement psiElement,
|
||||
@Nullable final String suggestedKey,
|
||||
@Nullable String suggestedValue,
|
||||
@Nullable final List<PropertiesFile> propertiesFiles) {
|
||||
protected Pair<String, String> invokeAction(@NotNull final Project project,
|
||||
@NotNull PsiFile file,
|
||||
@NotNull PsiElement psiElement,
|
||||
@Nullable final String suggestedKey,
|
||||
@Nullable String suggestedValue,
|
||||
@Nullable final List<PropertiesFile> propertiesFiles) {
|
||||
final PsiLiteralExpression literalExpression = psiElement instanceof PsiLiteralExpression ? (PsiLiteralExpression)psiElement : null;
|
||||
final String propertyValue = suggestedValue == null ? "" : suggestedValue;
|
||||
|
||||
@@ -59,5 +91,4 @@ public class JavaCreatePropertyFix extends CreatePropertyFix {
|
||||
);
|
||||
return doAction(project, psiElement, dialog);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-2
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.jetbrains.idea.maven.utils;
|
||||
|
||||
import com.intellij.openapi.application.AccessToken;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -30,7 +32,13 @@ public class MavenProblemFileHighlighter implements Condition<VirtualFile> {
|
||||
}
|
||||
|
||||
public boolean value(final VirtualFile file) {
|
||||
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
|
||||
return psiFile != null && MavenDomUtil.isMavenFile(psiFile);
|
||||
AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
|
||||
try {
|
||||
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
|
||||
return psiFile != null && MavenDomUtil.isMavenFile(psiFile);
|
||||
}
|
||||
finally {
|
||||
accessToken.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-7
@@ -88,11 +88,11 @@ public class CreatePropertyFix implements IntentionAction, LocalQuickFix {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Pair<String, String> invokeAction(@NotNull final Project project,
|
||||
@NotNull PsiFile file,
|
||||
@NotNull PsiElement psiElement,
|
||||
@Nullable final String suggestedKey,
|
||||
@Nullable final List<PropertiesFile> propertiesFiles) {
|
||||
private Pair<String, String> invokeAction(@NotNull final Project project,
|
||||
@NotNull PsiFile file,
|
||||
@NotNull PsiElement psiElement,
|
||||
@Nullable final String suggestedKey,
|
||||
@Nullable final List<PropertiesFile> propertiesFiles) {
|
||||
final I18nizeQuickFixModel model;
|
||||
final I18nizeQuickFixDialog.DialogCustomization dialogCustomization = createDefaultCustomization(suggestedKey, propertiesFiles);
|
||||
|
||||
@@ -128,8 +128,7 @@ public class CreatePropertyFix implements IntentionAction, LocalQuickFix {
|
||||
return new I18nizeQuickFixDialog.DialogCustomization(NAME, false, true, propertiesFiles, suggestedKey == null ? "" : suggestedKey);
|
||||
}
|
||||
|
||||
protected static Pair<String, String> doAction(Project project, PsiElement psiElement,
|
||||
I18nizeQuickFixModel model) {
|
||||
protected Pair<String, String> doAction(Project project, PsiElement psiElement, I18nizeQuickFixModel model) {
|
||||
if (!model.hasValidData()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -84,7 +84,7 @@ public class TestNGRelatedFilesProvider extends GotoRelatedProvider {
|
||||
}
|
||||
|
||||
if (!tags.isEmpty()) {
|
||||
return GotoRelatedItem.createItems(tags);
|
||||
return GotoRelatedItem.createItems(tags, "TestNG");
|
||||
}
|
||||
}
|
||||
psiClass = PsiTreeUtil.getParentOfType(psiClass, PsiClass.class);
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,7 +44,7 @@ public class FormRelatedFilesProvider extends GotoRelatedProvider {
|
||||
while (psiClass != null) {
|
||||
List<PsiFile> forms = FormClassIndex.findFormsBoundToClass(psiClass);
|
||||
if (!forms.isEmpty()) {
|
||||
return GotoRelatedItem.createItems(forms);
|
||||
return GotoRelatedItem.createItems(forms, "UI Forms");
|
||||
}
|
||||
psiClass = PsiTreeUtil.getParentOfType(psiClass, PsiClass.class);
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public class FormRelatedFilesProvider extends GotoRelatedProvider {
|
||||
Project project = file.getProject();
|
||||
PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.allScope(project));
|
||||
if (aClass != null) {
|
||||
return Collections.singletonList(new GotoRelatedItem(aClass));
|
||||
return Collections.singletonList(new GotoRelatedItem(aClass, "Java"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -888,6 +888,7 @@
|
||||
<elementSignatureProvider implementation="com.intellij.codeInsight.folding.impl.JavaElementSignatureProvider"/>
|
||||
|
||||
<preFormatProcessor implementation="com.intellij.psi.impl.source.codeStyle.FormatCommentsProcessor"/>
|
||||
<preFormatProcessor implementation="com.intellij.psi.impl.source.codeStyle.FieldInColumnsPreFormatProcessor"/>
|
||||
<postFormatProcessor implementation="com.intellij.psi.impl.source.codeStyle.BracePostFormatProcessor"/>
|
||||
<postFormatProcessor implementation="com.intellij.psi.impl.source.codeStyle.ImportPostFormatProcessor"/>
|
||||
<codeInspection.InspectionExtension implementation="com.intellij.codeInspection.ex.JavaInspectionExtensionsFactory"/>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,7 +17,6 @@ package com.intellij.codeInsight.navigation;
|
||||
|
||||
import com.intellij.navigation.GotoRelatedItem;
|
||||
import com.intellij.util.xml.DomElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
@@ -28,7 +27,15 @@ public class DomGotoRelatedItem extends GotoRelatedItem {
|
||||
private final DomElement myElement;
|
||||
|
||||
public DomGotoRelatedItem(DomElement element) {
|
||||
super(element.getXmlElement());
|
||||
this(element, "XML");
|
||||
}
|
||||
|
||||
public DomGotoRelatedItem(DomElement element, String group) {
|
||||
this(element, group, -1);
|
||||
}
|
||||
|
||||
public DomGotoRelatedItem(DomElement element, String group, int mnemonic) {
|
||||
super(element.getXmlElement(), group, mnemonic);
|
||||
myElement = element;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -93,7 +93,7 @@ public class NavigationGutterIconBuilder<T> {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<? extends GotoRelatedItem> fun(PsiElement dom) {
|
||||
return Collections.singletonList(new GotoRelatedItem(dom));
|
||||
return Collections.singletonList(new GotoRelatedItem(dom, "XML"));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,9 +24,9 @@ import com.intellij.psi.xml.XmlFile;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
@@ -44,10 +44,7 @@ public class HtmlGotoRelatedProvider extends GotoRelatedProvider {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
HashSet<PsiFile> resultSet = new HashSet<PsiFile>();
|
||||
fillRelatedFiles(file, resultSet);
|
||||
|
||||
return GotoRelatedItem.createItems(resultSet);
|
||||
return getRelatedFiles(file);
|
||||
}
|
||||
|
||||
private static boolean isAvailable(@NotNull PsiFile psiFile) {
|
||||
@@ -60,15 +57,22 @@ public class HtmlGotoRelatedProvider extends GotoRelatedProvider {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void fillRelatedFiles(@NotNull PsiFile file, @NotNull Set<PsiFile> resultSet) {
|
||||
private static List<? extends GotoRelatedItem> getRelatedFiles(@NotNull PsiFile file) {
|
||||
List<GotoRelatedItem> items = new ArrayList<GotoRelatedItem>();
|
||||
|
||||
for (PsiFile psiFile : file.getViewProvider().getAllFiles()) {
|
||||
if (psiFile instanceof XmlFile) {
|
||||
final XmlFile xmlFile = (XmlFile)psiFile;
|
||||
|
||||
for (RelatedToHtmlFilesContributor contributor : RelatedToHtmlFilesContributor.EP_NAME.getExtensions()) {
|
||||
HashSet<PsiFile> resultSet = new HashSet<PsiFile>();
|
||||
contributor.fillRelatedFiles(xmlFile, resultSet);
|
||||
for (PsiFile f: resultSet) {
|
||||
items.add(new GotoRelatedItem(f, contributor.getGroupName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -67,4 +67,9 @@ public class LinkedToHtmlFilesContributor extends RelatedToHtmlFilesContributor
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroupName() {
|
||||
return "Linked files";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,4 +30,5 @@ public abstract class RelatedToHtmlFilesContributor {
|
||||
ExtensionPointName.create("com.intellij.xml.relatedToHtmlFilesContributor");
|
||||
|
||||
public abstract void fillRelatedFiles(@NotNull XmlFile xmlFile, @NotNull Set<PsiFile> resultSet);
|
||||
public abstract String getGroupName();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user