mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Merge branch 'master' of git.labs.intellij.net:idea/community
This commit is contained in:
@@ -73,7 +73,7 @@ public class AllClassesGetter {
|
||||
LOG.error(endOffset + " became invalid: " + context.getOffsetMap() + "; inserting " + qname);
|
||||
}
|
||||
|
||||
final RangeMarker toDelete = JavaCompletionUtil.insertSpace(endOffset, document);
|
||||
final RangeMarker toDelete = JavaCompletionUtil.insertTemporary(endOffset, document, " ");
|
||||
psiDocumentManager.commitAllDocuments();
|
||||
PsiReference psiReference = file.findReferenceAt(endOffset - 1);
|
||||
|
||||
@@ -85,6 +85,7 @@ public class AllClassesGetter {
|
||||
}
|
||||
else if (psiClass.isValid()) {
|
||||
try {
|
||||
context.setTailOffset(psiReference.getRangeInElement().getEndOffset() + psiReference.getElement().getTextRange().getStartOffset());
|
||||
final PsiElement newUnderlying = psiReference.bindToElement(psiClass);
|
||||
if (newUnderlying != null) {
|
||||
final PsiElement psiElement = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(newUnderlying);
|
||||
|
||||
@@ -27,6 +27,8 @@ package com.intellij.codeInsight.completion;
|
||||
import com.intellij.codeInsight.lookup.CharFilter;
|
||||
import com.intellij.codeInsight.lookup.Lookup;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||
import com.intellij.patterns.PsiJavaPatterns;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -48,8 +50,8 @@ public class JavaCharFilter extends CharFilter {
|
||||
LookupElement item = lookup.getCurrentItem();
|
||||
if (item == null) return null;
|
||||
|
||||
final Object o = item.getObject();
|
||||
if (c == '!') {
|
||||
final Object o = item.getObject();
|
||||
if (o instanceof PsiVariable) {
|
||||
if (PsiType.BOOLEAN.isAssignableFrom(((PsiVariable)o).getType())) return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
|
||||
}
|
||||
@@ -62,10 +64,25 @@ public class JavaCharFilter extends CharFilter {
|
||||
}
|
||||
if (c == '.' && isWithinLiteral(lookup)) return Result.ADD_TO_PREFIX;
|
||||
if (c == '[') return CharFilter.Result.SELECT_ITEM_AND_FINISH_LOOKUP;
|
||||
if (c == '<' && item.getObject() instanceof PsiClass) return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
|
||||
if (c == '<' && o instanceof PsiClass) return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
|
||||
if (c == '(' && o instanceof PsiClass) {
|
||||
if (PsiJavaPatterns.psiElement().afterLeaf(PsiKeyword.NEW).accepts(lookup.getPsiElement())) {
|
||||
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
|
||||
}
|
||||
return Result.HIDE_LOOKUP;
|
||||
}
|
||||
if (c == ',' && o instanceof PsiVariable) {
|
||||
int lookupStart = ((LookupImpl)lookup).getLookupStart();
|
||||
String name = ((PsiVariable)o).getName();
|
||||
if (lookupStart >= 0 &&
|
||||
name != null &&
|
||||
name.equals(item.getPrefixMatcher().getPrefix() + ((LookupImpl)lookup).getAdditionalPrefix())) {
|
||||
return Result.HIDE_LOOKUP;
|
||||
}
|
||||
}
|
||||
|
||||
if (c == '#' && PsiTreeUtil.getParentOfType(lookup.getPsiElement(), PsiDocComment.class) != null) {
|
||||
if (item.getObject() instanceof PsiClass) {
|
||||
if (o instanceof PsiClass) {
|
||||
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -763,7 +763,7 @@ public class JavaCompletionUtil {
|
||||
String name = psiClass.getName();
|
||||
document.replaceString(startOffset, endOffset, name);
|
||||
|
||||
final RangeMarker toDelete = insertSpace(startOffset + name.length(), document);
|
||||
final RangeMarker toDelete = insertTemporary(startOffset + name.length(), document, ";");
|
||||
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
|
||||
@@ -812,12 +812,12 @@ public class JavaCompletionUtil {
|
||||
return psiReference.resolve();
|
||||
}
|
||||
|
||||
public static RangeMarker insertSpace(final int endOffset, final Document document) {
|
||||
public static RangeMarker insertTemporary(final int endOffset, final Document document, final String temporary) {
|
||||
final CharSequence chars = document.getCharsSequence();
|
||||
final int length = chars.length();
|
||||
final RangeMarker toDelete;
|
||||
if (endOffset < length && Character.isJavaIdentifierPart(chars.charAt(endOffset))){
|
||||
document.insertString(endOffset, " ");
|
||||
document.insertString(endOffset, temporary);
|
||||
toDelete = document.createRangeMarker(endOffset, endOffset + 1);
|
||||
} else if (endOffset >= length) {
|
||||
toDelete = document.createRangeMarker(length, length);
|
||||
|
||||
+6
-1
@@ -48,6 +48,7 @@ public class JavaCompletionProcessor extends BaseScopeProcessor implements Eleme
|
||||
public static final Key<Boolean> JAVA_COMPLETION = Key.create("JAVA_COMPLETION");
|
||||
|
||||
private boolean myStatic = false;
|
||||
private PsiElement myDeclarationHolder = null;
|
||||
private final Set<Object> myResultNames = new THashSet<Object>();
|
||||
private final List<CompletionElement> myResults;
|
||||
private final PsiElement myElement;
|
||||
@@ -182,6 +183,9 @@ public class JavaCompletionProcessor extends BaseScopeProcessor implements Eleme
|
||||
if(event == JavaScopeProcessorEvent.CHANGE_LEVEL){
|
||||
myMembersFlag = true;
|
||||
}
|
||||
if (event == JavaScopeProcessorEvent.SET_CURRENT_FILE_CONTEXT) {
|
||||
myDeclarationHolder = (PsiElement)associated;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean execute(PsiElement element, ResolveState state) {
|
||||
@@ -242,7 +246,8 @@ public class JavaCompletionProcessor extends BaseScopeProcessor implements Eleme
|
||||
if (!myCheckAccess) return true;
|
||||
if (!(element instanceof PsiMember)) return true;
|
||||
|
||||
return JavaPsiFacade.getInstance(element.getProject()).getResolveHelper().isAccessible((PsiMember)element, myElement, myQualifierClass);
|
||||
PsiMember member = (PsiMember)element;
|
||||
return JavaPsiFacade.getInstance(element.getProject()).getResolveHelper().isAccessible(member, member.getModifierList(), myElement, myQualifierClass, myDeclarationHolder);
|
||||
}
|
||||
|
||||
public void setCompletionElements(@NotNull Object[] elements) {
|
||||
|
||||
@@ -20,7 +20,10 @@ import com.intellij.codeInsight.CodeInsightUtilBase;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.intention.AddAnnotationFix;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.SuppressIntentionAction;
|
||||
import com.intellij.codeInspection.SuppressManager;
|
||||
import com.intellij.codeInspection.SuppressionUtil;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -33,7 +36,6 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.jsp.jspJava.JspHolderMethod;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.javadoc.PsiDocTag;
|
||||
import com.intellij.psi.javadoc.PsiDocTagValue;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -133,14 +135,14 @@ public class SuppressFix extends SuppressIntentionAction {
|
||||
final PsiElement container,
|
||||
final PsiModifierListOwner modifierOwner,
|
||||
final String id) throws IncorrectOperationException {
|
||||
PsiAnnotation annotation = AnnotationUtil.findAnnotation(modifierOwner, SuppressManagerImpl.SUPPRESS_INSPECTIONS_ANNOTATION_NAME);
|
||||
PsiAnnotation annotation = AnnotationUtil.findAnnotation(modifierOwner, SuppressManager.SUPPRESS_INSPECTIONS_ANNOTATION_NAME);
|
||||
final PsiAnnotation newAnnotation = createNewAnnotation(project, editor, container, annotation, id);
|
||||
if (newAnnotation != null) {
|
||||
if (annotation != null && annotation.isPhysical()) {
|
||||
annotation.replace(newAnnotation);
|
||||
} else {
|
||||
final PsiNameValuePair[] attributes = newAnnotation.getParameterList().getAttributes();
|
||||
new AddAnnotationFix(SuppressManagerImpl.SUPPRESS_INSPECTIONS_ANNOTATION_NAME, modifierOwner, attributes).invoke(project, editor, container.getContainingFile());
|
||||
new AddAnnotationFix(SuppressManager.SUPPRESS_INSPECTIONS_ANNOTATION_NAME, modifierOwner, attributes).invoke(project, editor, container.getContainingFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,8 +158,8 @@ public class SuppressFix extends SuppressIntentionAction {
|
||||
final PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
|
||||
if (attributes.length == 1) {
|
||||
final String suppressedWarnings = attributes[0].getText();
|
||||
return JavaPsiFacade.getInstance(project).getElementFactory().createAnnotationFromText("@" + SuppressManagerImpl
|
||||
.SUPPRESS_INSPECTIONS_ANNOTATION_NAME + "({" + suppressedWarnings + ", \"" + id + "\"})", container);
|
||||
return JavaPsiFacade.getInstance(project).getElementFactory().createAnnotationFromText("@" +
|
||||
SuppressManager.SUPPRESS_INSPECTIONS_ANNOTATION_NAME + "({" + suppressedWarnings + ", \"" + id + "\"})", container);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -174,7 +176,7 @@ public class SuppressFix extends SuppressIntentionAction {
|
||||
}
|
||||
else {
|
||||
return JavaPsiFacade.getInstance(project).getElementFactory()
|
||||
.createAnnotationFromText("@" + SuppressManagerImpl.SUPPRESS_INSPECTIONS_ANNOTATION_NAME + "({\"" + id + "\"})", container);
|
||||
.createAnnotationFromText("@" + SuppressManager.SUPPRESS_INSPECTIONS_ANNOTATION_NAME + "({\"" + id + "\"})", container);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
+1
@@ -493,6 +493,7 @@ public class GenericsHighlightUtil {
|
||||
if (!checkEqualsSuper && MethodSignatureUtil.isSubsignature(superSignature, signatureToCheck)) {
|
||||
return null;
|
||||
}
|
||||
if (superContainingClass != null && !superContainingClass.isInterface() && checkContainingClass.isInterface() && !aClass.equals(superContainingClass)) return null;
|
||||
if (aClass.equals(checkContainingClass)) {
|
||||
boolean sameClass = aClass.equals(superContainingClass);
|
||||
return getSameErasureMessage(sameClass, checkMethod, superMethod, HighlightNamesUtil.getMethodDeclarationTextRange(checkMethod));
|
||||
|
||||
+4
@@ -247,6 +247,10 @@ public class HighlightMethodUtil {
|
||||
PsiMethod superMethod = superMethodSignature.getMethod();
|
||||
int index = getExtraExceptionNum(methodSignature, superMethodSignature, checkedExceptions, superSubstitutor);
|
||||
if (index != -1) {
|
||||
if (aClass.isInterface()) {
|
||||
final PsiClass superContainingClass = superMethod.getContainingClass();
|
||||
if (superContainingClass != null && !superContainingClass.isInterface()) continue;
|
||||
}
|
||||
PsiClassType exception = checkedExceptions.get(index);
|
||||
String message = JavaErrorMessages.message("overridden.method.does.not.throw",
|
||||
createClashMethodMessage(method, superMethod, true),
|
||||
|
||||
@@ -327,7 +327,7 @@ public class OverrideImplementUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void annotate(PsiMethod result, String fqn, String... annosToRemove) throws IncorrectOperationException {
|
||||
public static void annotate(@NotNull PsiMethod result, String fqn, String... annosToRemove) throws IncorrectOperationException {
|
||||
Project project = result.getProject();
|
||||
AddAnnotationFix fix = new AddAnnotationFix(fqn, result, annosToRemove);
|
||||
if (fix.isAvailable(project, null, result.getContainingFile())) {
|
||||
|
||||
@@ -175,7 +175,7 @@ public class AddAnnotationFix extends PsiElementBaseIntentionAction implements L
|
||||
}
|
||||
}
|
||||
|
||||
PsiAnnotation inserted = modifierList.addAnnotation(myAnnotation);
|
||||
final @NotNull PsiAnnotation inserted = modifierList.addAnnotation(myAnnotation);
|
||||
if (myPairs != null) {
|
||||
for (PsiNameValuePair pair : myPairs) {
|
||||
inserted.setDeclaredAttributeValue(pair.getName(), pair.getValue());
|
||||
|
||||
+3
-1
@@ -122,7 +122,9 @@ public class UnusedParametersInspection extends GlobalJavaInspectionTool {
|
||||
final boolean[] found = {false};
|
||||
for (int i = 0; i < derived.length && !found[0]; i++) {
|
||||
if (!scope.contains(derived[i])) {
|
||||
PsiParameter psiParameter = derived[i].getParameterList().getParameters()[idx];
|
||||
final PsiParameter[] parameters = derived[i].getParameterList().getParameters();
|
||||
if (parameters.length >= idx) continue;
|
||||
PsiParameter psiParameter = parameters[idx];
|
||||
ReferencesSearch.search(psiParameter, helper.getUseScope(psiParameter), false).forEach(new PsiReferenceProcessorAdapter(
|
||||
new PsiReferenceProcessor() {
|
||||
public boolean execute(PsiReference element) {
|
||||
|
||||
@@ -117,13 +117,16 @@ public class JavaFindUsagesHandler extends FindUsagesHandler{
|
||||
for (int i = 0; i < overrides.length; i++) {
|
||||
overrides[i] = (PsiMethod)overrides[i].getNavigationElement();
|
||||
}
|
||||
PsiElement[] elementsToSearch = new PsiElement[overrides.length + 1];
|
||||
elementsToSearch[0] = parameter;
|
||||
List<PsiElement> elementsToSearch = new ArrayList<PsiElement>(overrides.length + 1);
|
||||
elementsToSearch.add(parameter);
|
||||
int idx = method.getParameterList().getParameterIndex(parameter);
|
||||
for (int i = 0; i < overrides.length; i++) {
|
||||
elementsToSearch[i + 1] = overrides[i].getParameterList().getParameters()[idx];
|
||||
for (PsiMethod override : overrides) {
|
||||
final PsiParameter[] parameters = override.getParameterList().getParameters();
|
||||
if (idx < parameters.length) {
|
||||
elementsToSearch.add(parameters[idx]);
|
||||
}
|
||||
}
|
||||
return elementsToSearch;
|
||||
return elementsToSearch.toArray(new PsiElement[elementsToSearch.size()]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,17 +17,13 @@ package com.intellij.lang.java;
|
||||
|
||||
import com.intellij.codeInsight.javadoc.JavaDocExternalFilter;
|
||||
import com.intellij.codeInsight.javadoc.JavaDocInfoGenerator;
|
||||
import com.intellij.lang.documentation.QuickDocumentationProvider;
|
||||
import com.intellij.lang.documentation.AbstractDocumentationProvider;
|
||||
import com.intellij.psi.PsiElement;
|
||||
|
||||
/**
|
||||
* @author spleaner
|
||||
*/
|
||||
public class FileDocumentationProvider extends QuickDocumentationProvider {
|
||||
|
||||
public String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) {
|
||||
return null;
|
||||
}
|
||||
public class FileDocumentationProvider extends AbstractDocumentationProvider {
|
||||
|
||||
@Override
|
||||
public String generateDoc(PsiElement element, PsiElement originalElement) {
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import com.intellij.psi.formatter.FormatterUtil;
|
||||
import com.intellij.psi.formatter.common.AbstractBlock;
|
||||
import com.intellij.psi.formatter.java.wrap.JavaWrapManager;
|
||||
@@ -44,6 +45,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.intellij.psi.formatter.java.JavaFormatterUtil.isFirstAmongOthersAnonymousClassMethodCallArguments;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlock, ReservedWrapsProvider {
|
||||
@@ -258,7 +260,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
if (parentType == JavaElementType.MODIFIER_LIST) return Indent.getNoneIndent();
|
||||
if (parentType == JspElementType.JSP_CODE_BLOCK) return Indent.getNormalIndent();
|
||||
if (parentType == JspElementType.JSP_CLASS_LEVEL_DECLARATION_STATEMENT) return Indent.getNormalIndent();
|
||||
if (parentType == ElementType.DUMMY_HOLDER) return Indent.getNoneIndent();
|
||||
if (parentType == TokenType.DUMMY_HOLDER) return Indent.getNoneIndent();
|
||||
if (parentType == JavaElementType.CLASS) return Indent.getNoneIndent();
|
||||
if (parentType == JavaElementType.IF_STATEMENT) return Indent.getNoneIndent();
|
||||
if (parentType == JavaElementType.TRY_STATEMENT) return Indent.getNoneIndent();
|
||||
@@ -285,7 +287,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
}
|
||||
|
||||
protected static boolean isRBrace(final ASTNode child) {
|
||||
return child.getElementType() == ElementType.RBRACE;
|
||||
return child.getElementType() == JavaTokenType.RBRACE;
|
||||
}
|
||||
|
||||
public Spacing getSpacing(Block child1, Block child2) {
|
||||
@@ -363,7 +365,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
else if (nodeType == JavaElementType.CLASS || nodeType == JavaElementType.METHOD) {
|
||||
return Alignment.createAlignment();
|
||||
}
|
||||
else if (nodeType == JavaElementType.MODIFIER_LIST) {
|
||||
else if (nodeType == JavaElementType.MODIFIER_LIST || nodeType == JavaElementType.NEW_EXPRESSION) {
|
||||
return myAlignment;
|
||||
}
|
||||
|
||||
@@ -838,7 +840,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
// Here '@NotNull' has a 'class' node as a parent but we want to use field annotation setting value. Hence, we check if subsequent
|
||||
// parsed info is valid.
|
||||
for (ASTNode node = child.getTreeNext(); node != null; node = node.getTreeNext()) {
|
||||
if (JavaTokenType.WHITE_SPACE == node.getElementType() || node instanceof PsiTypeElement) {
|
||||
if (TokenType.WHITE_SPACE == node.getElementType() || node instanceof PsiTypeElement) {
|
||||
continue;
|
||||
}
|
||||
if (node instanceof PsiErrorElement) {
|
||||
@@ -856,7 +858,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
if (nodeType == JavaElementType.LOCAL_VARIABLE) {
|
||||
return mySettings.VARIABLE_ANNOTATION_WRAP;
|
||||
}
|
||||
return CodeStyleSettings.DO_NOT_WRAP;
|
||||
return CommonCodeStyleSettings.DO_NOT_WRAP;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -922,7 +924,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
// There is a special case - comment block that is located at the very start of the line. We don't reformat such a blocks,
|
||||
// hence, no alignment should be applied to them in order to avoid subsequent blocks aligned with the same alignment to
|
||||
// be located at the left editor edge as well.
|
||||
if (previous != null && previous.getElementType() == JavaTokenType.WHITE_SPACE && previous.getChars().length() > 0
|
||||
if (previous != null && previous.getElementType() == TokenType.WHITE_SPACE && previous.getChars().length() > 0
|
||||
&& previous.getChars().charAt(previous.getChars().length() - 1) == '\n') {
|
||||
return null;
|
||||
} else {
|
||||
@@ -940,6 +942,12 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
return null;
|
||||
}
|
||||
|
||||
else if (nodeType == JavaElementType.ANONYMOUS_CLASS && role == ChildRole.RBRACE
|
||||
&& isFirstAmongOthersAnonymousClassMethodCallArguments(myNode))
|
||||
{
|
||||
return myAlignment;
|
||||
}
|
||||
|
||||
else {
|
||||
return defaultAlignment;
|
||||
}
|
||||
@@ -1015,11 +1023,11 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
|
||||
private static WrapType getWrapType(final int wrap) {
|
||||
switch (wrap) {
|
||||
case CodeStyleSettings.WRAP_ALWAYS:
|
||||
case CommonCodeStyleSettings.WRAP_ALWAYS:
|
||||
return WrapType.ALWAYS;
|
||||
case CodeStyleSettings.WRAP_AS_NEEDED:
|
||||
case CommonCodeStyleSettings.WRAP_AS_NEEDED:
|
||||
return WrapType.NORMAL;
|
||||
case CodeStyleSettings.DO_NOT_WRAP:
|
||||
case CommonCodeStyleSettings.DO_NOT_WRAP:
|
||||
return WrapType.NONE;
|
||||
default:
|
||||
return WrapType.CHOP_DOWN_IF_LONG;
|
||||
@@ -1040,12 +1048,12 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
|
||||
private ASTNode processParenthesisBlock(final IElementType from,
|
||||
final IElementType to, final List<Block> result, ASTNode child,
|
||||
final WrappingStrategy wrappingStrategy, final boolean doAlign
|
||||
) {
|
||||
final WrappingStrategy wrappingStrategy, final boolean doAlign)
|
||||
{
|
||||
final Indent externalIndent = Indent.getNoneIndent();
|
||||
final Indent internalIndent = Indent.getContinuationIndent(myIndentSettings.USE_RELATIVE_INDENTS);
|
||||
final Indent internalIndentEnforcedToParent = Indent.getIndent(Indent.Type.CONTINUATION, myIndentSettings.USE_RELATIVE_INDENTS, true);
|
||||
AlignmentStrategy alignmentStrategy = AlignmentStrategy.wrap(createAlignment(doAlign, null), ElementType.COMMA);
|
||||
final Indent internalIndent = Indent.getContinuationWithoutFirstIndent(myIndentSettings.USE_RELATIVE_INDENTS);
|
||||
final Indent internalIndentEnforcedToChildren = Indent.getIndent(Indent.Type.CONTINUATION, myIndentSettings.USE_RELATIVE_INDENTS, true);
|
||||
AlignmentStrategy alignmentStrategy = AlignmentStrategy.wrap(createAlignment(doAlign, null), JavaTokenType.COMMA);
|
||||
setChildIndent(internalIndent);
|
||||
setChildAlignment(alignmentStrategy.getAlignment(null));
|
||||
boolean methodParametersBlock = true;
|
||||
@@ -1076,7 +1084,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
}
|
||||
else {
|
||||
final IElementType elementType = child.getElementType();
|
||||
Indent indentToUse = shouldEnforceParentIndent(child) ? internalIndentEnforcedToParent : internalIndent;
|
||||
Indent indentToUse = shouldEnforceIndentToChildren(child) ? internalIndentEnforcedToChildren : internalIndent;
|
||||
processChild(result, child, alignmentStrategy.getAlignment(elementType), wrappingStrategy.getWrap(elementType), indentToUse);
|
||||
if (to == null) {//process only one statement
|
||||
return child;
|
||||
@@ -1091,7 +1099,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
return prev;
|
||||
}
|
||||
|
||||
private boolean shouldEnforceParentIndent(@NotNull ASTNode node) {
|
||||
private boolean shouldEnforceIndentToChildren(@NotNull ASTNode node) {
|
||||
// Don't enforce indent if given node is the last argument, i.e. prefer the code below
|
||||
// void test() {
|
||||
// foo("test", new Runnable() {
|
||||
@@ -1129,7 +1137,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
|
||||
// Enforce indent only if anonymous class instance expression doesn't start new line.
|
||||
ASTNode prev = node.getTreePrev();
|
||||
return prev == null || prev.getElementType() != JavaTokenType.WHITE_SPACE || !StringUtil.containsLineBreak(prev.getChars());
|
||||
return prev == null || prev.getElementType() != TokenType.WHITE_SPACE || !StringUtil.containsLineBreak(prev.getChars());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -1193,7 +1201,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
}
|
||||
|
||||
final int braceStyle = getBraceStyle();
|
||||
return braceStyle == CodeStyleSettings.NEXT_LINE_SHIFTED ?
|
||||
return braceStyle == CommonCodeStyleSettings.NEXT_LINE_SHIFTED ?
|
||||
createNormalIndent(baseChildrenIndent - 1, enforceParentIndent)
|
||||
: createNormalIndent(baseChildrenIndent, enforceParentIndent);
|
||||
}
|
||||
@@ -1202,16 +1210,16 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
return createNormalIndent(baseChildrenIndent, false);
|
||||
}
|
||||
|
||||
protected static Indent createNormalIndent(final int baseChildrenIndent, boolean enforceParentIndent) {
|
||||
protected static Indent createNormalIndent(final int baseChildrenIndent, boolean enforceIndentToChildren) {
|
||||
if (baseChildrenIndent == 1) {
|
||||
return Indent.getIndent(Indent.Type.NORMAL, false, enforceParentIndent);
|
||||
return Indent.getIndent(Indent.Type.NORMAL, false, enforceIndentToChildren);
|
||||
}
|
||||
else if (baseChildrenIndent <= 0) {
|
||||
return Indent.getNoneIndent();
|
||||
}
|
||||
else {
|
||||
LOG.assertTrue(false);
|
||||
return Indent.getIndent(Indent.Type.NORMAL, false, enforceParentIndent);
|
||||
return Indent.getIndent(Indent.Type.NORMAL, false, enforceIndentToChildren);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1222,8 +1230,8 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
|
||||
protected Indent getCodeBlockExternalIndent() {
|
||||
final int braceStyle = getBraceStyle();
|
||||
if (braceStyle == CodeStyleSettings.END_OF_LINE || braceStyle == CodeStyleSettings.NEXT_LINE ||
|
||||
braceStyle == CodeStyleSettings.NEXT_LINE_IF_WRAPPED) {
|
||||
if (braceStyle == CommonCodeStyleSettings.END_OF_LINE || braceStyle == CommonCodeStyleSettings.NEXT_LINE ||
|
||||
braceStyle == CommonCodeStyleSettings.NEXT_LINE_IF_WRAPPED) {
|
||||
return Indent.getNoneIndent();
|
||||
}
|
||||
else {
|
||||
@@ -1236,9 +1244,9 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
if (!isAfterCodeBlock(newChildIndex)) {
|
||||
return Indent.getNormalIndent();
|
||||
}
|
||||
else if (braceStyle == CodeStyleSettings.NEXT_LINE ||
|
||||
braceStyle == CodeStyleSettings.NEXT_LINE_IF_WRAPPED ||
|
||||
braceStyle == CodeStyleSettings.END_OF_LINE) {
|
||||
else if (braceStyle == CommonCodeStyleSettings.NEXT_LINE ||
|
||||
braceStyle == CommonCodeStyleSettings.NEXT_LINE_IF_WRAPPED ||
|
||||
braceStyle == CommonCodeStyleSettings.END_OF_LINE) {
|
||||
return Indent.getNoneIndent();
|
||||
}
|
||||
else {
|
||||
@@ -1364,9 +1372,10 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
);
|
||||
}
|
||||
final boolean rBrace = isRBrace(child);
|
||||
Indent childIndent = rBrace ? Indent.getNoneIndent() : getCodeBlockInternalIndent(childrenIndent);
|
||||
Indent childIndent = rBrace ? Indent.getNoneIndent() : getCodeBlockInternalIndent(childrenIndent, false);
|
||||
if (!rBrace && child.getElementType() == JavaElementType.CODE_BLOCK
|
||||
&& (getBraceStyle() == CodeStyleSettings.NEXT_LINE_SHIFTED || getBraceStyle() == CodeStyleSettings.NEXT_LINE_SHIFTED2))
|
||||
&& (getBraceStyle() == CommonCodeStyleSettings.NEXT_LINE_SHIFTED
|
||||
|| getBraceStyle() == CommonCodeStyleSettings.NEXT_LINE_SHIFTED2))
|
||||
{
|
||||
childIndent = Indent.getNormalIndent();
|
||||
}
|
||||
|
||||
@@ -18,12 +18,12 @@ package com.intellij.psi.formatter.java;
|
||||
import com.intellij.formatting.*;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.JavaTokenType;
|
||||
import com.intellij.psi.TokenType;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.formatter.FormatterUtil;
|
||||
import com.intellij.psi.formatter.common.AbstractBlock;
|
||||
import com.intellij.formatting.alignment.AlignmentStrategy;
|
||||
import com.intellij.psi.impl.source.jsp.jspJava.JspClass;
|
||||
import com.intellij.psi.impl.source.tree.ElementType;
|
||||
import com.intellij.psi.impl.source.tree.JavaDocElementType;
|
||||
import com.intellij.psi.impl.source.tree.JavaElementType;
|
||||
import com.intellij.psi.impl.source.tree.StdTokenSets;
|
||||
@@ -72,7 +72,7 @@ public class CodeBlockBlock extends AbstractJavaBlock {
|
||||
continue;
|
||||
}
|
||||
ASTNode lastChildNode = node.getLastChildNode();
|
||||
if (lastChildNode != null && lastChildNode.getElementType() == JavaTokenType.ERROR_ELEMENT) {
|
||||
if (lastChildNode != null && lastChildNode.getElementType() == TokenType.ERROR_ELEMENT) {
|
||||
Alignment alignmentToUse = alignment;
|
||||
if (alignment == null) {
|
||||
alignmentToUse = Alignment.createAlignment();
|
||||
@@ -87,7 +87,7 @@ public class CodeBlockBlock extends AbstractJavaBlock {
|
||||
}
|
||||
|
||||
private boolean isSwitchCodeBlock() {
|
||||
return myNode.getTreeParent().getElementType() == ElementType.SWITCH_STATEMENT;
|
||||
return myNode.getTreeParent().getElementType() == JavaElementType.SWITCH_STATEMENT;
|
||||
}
|
||||
|
||||
protected List<Block> buildChildren() {
|
||||
@@ -115,13 +115,13 @@ public class CodeBlockBlock extends AbstractJavaBlock {
|
||||
final Indent indent = calcCurrentIndent(child, state);
|
||||
state = calcNewState(child, state);
|
||||
|
||||
if (child.getElementType() == ElementType.SWITCH_LABEL_STATEMENT) {
|
||||
if (child.getElementType() == JavaElementType.SWITCH_LABEL_STATEMENT) {
|
||||
child = processCaseAndStatementAfter(result, child, childAlignment, childWrap, indent);
|
||||
}
|
||||
else if (myNode.getElementType() == ElementType.CLASS && child.getElementType() == ElementType.LBRACE) {
|
||||
else if (myNode.getElementType() == JavaElementType.CLASS && child.getElementType() == JavaTokenType.LBRACE) {
|
||||
child = composeCodeBlock(result, child, getCodeBlockExternalIndent(), myChildrenIndent, null);
|
||||
}
|
||||
else if (myNode.getElementType() == ElementType.CODE_BLOCK && child.getElementType() == ElementType.LBRACE
|
||||
else if (myNode.getElementType() == JavaElementType.CODE_BLOCK && child.getElementType() == JavaTokenType.LBRACE
|
||||
&& myNode.getTreeParent().getElementType() == JavaElementType.METHOD)
|
||||
{
|
||||
child = composeCodeBlock(result, child, indent, myChildrenIndent, childWrap);
|
||||
@@ -146,14 +146,14 @@ public class CodeBlockBlock extends AbstractJavaBlock {
|
||||
child = child.getTreeNext();
|
||||
Indent childIndent = Indent.getNormalIndent();
|
||||
while (child != null) {
|
||||
if (child.getElementType() == ElementType.SWITCH_LABEL_STATEMENT || isRBrace(child)) {
|
||||
if (child.getElementType() == JavaElementType.SWITCH_LABEL_STATEMENT || isRBrace(child)) {
|
||||
result.add(createCaseSectionBlock(localResult, childAlignment, indent, childWrap));
|
||||
return child.getTreePrev();
|
||||
}
|
||||
|
||||
if (!FormatterUtil.containsWhiteSpacesOnly(child)) {
|
||||
|
||||
if (child.getElementType() == ElementType.BLOCK_STATEMENT) {
|
||||
if (child.getElementType() == JavaElementType.BLOCK_STATEMENT) {
|
||||
childIndent = Indent.getNoneIndent();
|
||||
}
|
||||
|
||||
@@ -189,9 +189,9 @@ public class CodeBlockBlock extends AbstractJavaBlock {
|
||||
}
|
||||
}
|
||||
|
||||
if (prevElementType == ElementType.BLOCK_STATEMENT
|
||||
|| prevElementType == ElementType.BREAK_STATEMENT
|
||||
|| prevElementType == ElementType.RETURN_STATEMENT) {
|
||||
if (prevElementType == JavaElementType.BLOCK_STATEMENT
|
||||
|| prevElementType == JavaElementType.BREAK_STATEMENT
|
||||
|| prevElementType == JavaElementType.RETURN_STATEMENT) {
|
||||
return new ChildAttributes(Indent.getNoneIndent(), null);
|
||||
}
|
||||
else {
|
||||
@@ -231,7 +231,7 @@ public class CodeBlockBlock extends AbstractJavaBlock {
|
||||
}
|
||||
|
||||
private static boolean isLBrace(final ASTNode child) {
|
||||
return child.getElementType() == ElementType.LBRACE;
|
||||
return child.getElementType() == JavaTokenType.LBRACE;
|
||||
}
|
||||
|
||||
private Indent calcCurrentIndent(final ASTNode child, final int state) {
|
||||
@@ -241,7 +241,7 @@ public class CodeBlockBlock extends AbstractJavaBlock {
|
||||
|
||||
if (state == BEFORE_FIRST) return Indent.getNoneIndent();
|
||||
|
||||
if (child.getElementType() == ElementType.SWITCH_LABEL_STATEMENT) {
|
||||
if (child.getElementType() == JavaElementType.SWITCH_LABEL_STATEMENT) {
|
||||
return getCodeBlockInternalIndent(myChildrenIndent);
|
||||
}
|
||||
if (state == BEFORE_LBRACE) {
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* 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.psi.formatter.java;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiExpressionList;
|
||||
import com.intellij.psi.impl.source.tree.ElementType;
|
||||
import com.intellij.psi.impl.source.tree.JavaElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Denis Zhdanov
|
||||
* @since 4/12/11 3:26 PM
|
||||
*/
|
||||
public class JavaFormatterUtil {
|
||||
|
||||
private JavaFormatterUtil() {
|
||||
}
|
||||
|
||||
public static boolean isFirstMethodCallArgument(@NotNull ASTNode node) {
|
||||
ASTNode firstArgCandidate = node;
|
||||
ASTNode expressionList = node.getTreeParent();
|
||||
if (expressionList == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (expressionList.getElementType() != JavaElementType.EXPRESSION_LIST
|
||||
&& expressionList.getElementType() == JavaElementType.NEW_EXPRESSION)
|
||||
{
|
||||
firstArgCandidate = expressionList;
|
||||
expressionList = expressionList.getTreeParent();
|
||||
}
|
||||
|
||||
if (expressionList == null || expressionList.getElementType() != JavaElementType.EXPRESSION_LIST) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ASTNode methodCallExpression = expressionList.getTreeParent();
|
||||
if (methodCallExpression == null || methodCallExpression.getElementType() != JavaElementType.METHOD_CALL_EXPRESSION) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ASTNode lbrace = expressionList.getFirstChildNode();
|
||||
ASTNode firstArg = lbrace.getTreeNext();
|
||||
if (firstArg != null && ElementType.WHITE_SPACE_BIT_SET.contains(firstArg.getElementType())) {
|
||||
firstArg = firstArg.getTreeNext();
|
||||
}
|
||||
|
||||
return firstArg == firstArgCandidate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to check if given node references anonymous class instance used as a method call argument. The most important thing
|
||||
* is that that method call expression should have other anonymous classes as well.
|
||||
* <p/>
|
||||
* <b>Examples</b>
|
||||
* <pre>
|
||||
* test(new Runnable() { <-- true is returned for this node
|
||||
* public void run() {
|
||||
* }
|
||||
* },
|
||||
* new Runnable() { <-- false is returned for this node
|
||||
* public void run() {
|
||||
* }
|
||||
* }
|
||||
* );
|
||||
*
|
||||
* test(1234, "text", new Runnable() { <-- true is returned for this node because there are no other anonymous
|
||||
* public void run() { class objects at method call expression before it
|
||||
* }
|
||||
* },
|
||||
* new Runnable() { <-- false is returned for this node
|
||||
* public void run() {
|
||||
* }
|
||||
* }
|
||||
* );
|
||||
*
|
||||
* test(1234, "text", new Runnable() { <-- false is returned for this node because there are no other anonymous
|
||||
* public void run() { class objects at method call expression after it
|
||||
* }
|
||||
* });
|
||||
* </pre>
|
||||
*
|
||||
* @param node node to process
|
||||
* @return
|
||||
*/
|
||||
public static boolean isFirstAmongOthersAnonymousClassMethodCallArguments(@NotNull ASTNode node) {
|
||||
ASTNode expressionList = node.getTreeParent();
|
||||
ASTNode firstAnonymousClassCandidate = node;
|
||||
if (expressionList == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (expressionList.getElementType() != JavaElementType.EXPRESSION_LIST
|
||||
&& expressionList.getElementType() == JavaElementType.NEW_EXPRESSION)
|
||||
{
|
||||
firstAnonymousClassCandidate = expressionList;
|
||||
expressionList = expressionList.getTreeParent();
|
||||
}
|
||||
|
||||
if (expressionList == null || expressionList.getElementType() != JavaElementType.EXPRESSION_LIST) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ASTNode methodCallExpression = expressionList.getTreeParent();
|
||||
if (methodCallExpression == null || methodCallExpression.getElementType() != JavaElementType.METHOD_CALL_EXPRESSION) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ASTNode lbrace = expressionList.getFirstChildNode();
|
||||
boolean firstAnonymousClass = false;
|
||||
for (ASTNode arg = lbrace.getTreeNext(); arg != null; arg = FormattingAstUtil.getNextNonWhiteSpaceNode(arg)) {
|
||||
if (!isAnonymousClass(arg)) {
|
||||
continue;
|
||||
}
|
||||
if (firstAnonymousClass) {
|
||||
// Other anonymous class is found at the method call expression after the target one.
|
||||
return true;
|
||||
}
|
||||
else if (arg != firstAnonymousClassCandidate) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
firstAnonymousClass = true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to check if given expression list has given number of anonymous classes.
|
||||
*
|
||||
* @param count interested number of anonymous classes used at the given expression list
|
||||
* @return <code>true</code> if given expression list contains given number of anonymous classes;
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
public static boolean hasAnonymousClassesArguments(@NotNull PsiExpressionList expressionList, int count) {
|
||||
int found = 0;
|
||||
for (PsiExpression expression : expressionList.getExpressions()) {
|
||||
ASTNode node = expression.getNode();
|
||||
if (isAnonymousClass(node)) {
|
||||
found++;
|
||||
}
|
||||
if (found >= count) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isAnonymousClass(@Nullable final ASTNode node) {
|
||||
if (node == null) {
|
||||
return false;
|
||||
}
|
||||
ASTNode nodeToCheck = node;
|
||||
if (node.getElementType() == JavaElementType.NEW_EXPRESSION) {
|
||||
nodeToCheck = node.getLastChildNode();
|
||||
}
|
||||
return nodeToCheck != null && nodeToCheck.getElementType() == JavaElementType.ANONYMOUS_CLASS;
|
||||
}
|
||||
}
|
||||
@@ -1100,8 +1100,13 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor {
|
||||
createParenthSpace(mySettings.CALL_PARAMETERS_LPAREN_ON_NEXT_LINE, false);
|
||||
}
|
||||
else if (myRole2 == ChildRole.RPARENTH) {
|
||||
createParenthSpace(mySettings.CALL_PARAMETERS_RPAREN_ON_NEXT_LINE,
|
||||
myRole1 == ChildRole.COMMA || mySettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES);
|
||||
if (JavaFormatterUtil.hasAnonymousClassesArguments(list, 2)) {
|
||||
myResult = Spacing.createSpacing(0, 0, 1, mySettings.KEEP_LINE_BREAKS, 0);
|
||||
}
|
||||
else {
|
||||
createParenthSpace(mySettings.CALL_PARAMETERS_RPAREN_ON_NEXT_LINE,
|
||||
myRole1 == ChildRole.COMMA || mySettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES);
|
||||
}
|
||||
}
|
||||
else if (myRole1 == ChildRole.LPARENTH) {
|
||||
createParenthSpace(mySettings.CALL_PARAMETERS_LPAREN_ON_NEXT_LINE, mySettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES);
|
||||
|
||||
@@ -170,7 +170,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiAnnotation createAnnotationFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
|
||||
public PsiAnnotation createAnnotationFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
|
||||
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, ANNOTATION, level(context)), context);
|
||||
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
|
||||
if (!(element instanceof PsiAnnotation)) {
|
||||
@@ -187,7 +187,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiDocTag createDocTagFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
|
||||
public PsiDocTag createDocTagFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
|
||||
return createDocTagFromText(text);
|
||||
}
|
||||
|
||||
@@ -202,14 +202,14 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiDocComment createDocCommentFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
|
||||
public PsiDocComment createDocCommentFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
|
||||
return createDocCommentFromText(text);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiClass createClassFromText(@NotNull final String body, final PsiElement context) throws IncorrectOperationException {
|
||||
final PsiJavaFile aFile = createDummyJavaFile(StringUtil.join("class _Dummy_ { ", body, " }"));
|
||||
public PsiClass createClassFromText(@NotNull final String body, @Nullable final PsiElement context) throws IncorrectOperationException {
|
||||
final PsiJavaFile aFile = createDummyJavaFile(StringUtil.join("class _Dummy_ {\n", body, "\n}"));
|
||||
final PsiClass[] classes = aFile.getClasses();
|
||||
if (classes.length != 1) {
|
||||
throw new IncorrectOperationException("Incorrect class \"" + body + "\".");
|
||||
@@ -219,7 +219,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiField createFieldFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
|
||||
public PsiField createFieldFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
|
||||
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, DECLARATION, level(context)), context);
|
||||
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
|
||||
if (!(element instanceof PsiField)) {
|
||||
@@ -230,7 +230,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiMethod createMethodFromText(@NotNull final String text, final PsiElement context, final LanguageLevel level) throws IncorrectOperationException {
|
||||
public PsiMethod createMethodFromText(@NotNull final String text, @Nullable final PsiElement context, final LanguageLevel level) throws IncorrectOperationException {
|
||||
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, DECLARATION, level), context);
|
||||
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
|
||||
if (!(element instanceof PsiMethod)) {
|
||||
@@ -241,14 +241,14 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public final PsiMethod createMethodFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
|
||||
public final PsiMethod createMethodFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
|
||||
final LanguageLevel level = LanguageLevelProjectExtension.getInstance(myManager.getProject()).getLanguageLevel();
|
||||
return createMethodFromText(text, context, level);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiParameter createParameterFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
|
||||
public PsiParameter createParameterFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
|
||||
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, PARAMETER, level(context)), context);
|
||||
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
|
||||
if (!(element instanceof PsiParameter)) {
|
||||
@@ -259,7 +259,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiResourceVariable createResourceFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
|
||||
public PsiResourceVariable createResourceFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
|
||||
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, RESOURCE, level(context)), context);
|
||||
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
|
||||
if (!(element instanceof PsiResourceVariable)) {
|
||||
@@ -270,13 +270,13 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiType createTypeFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
|
||||
public PsiType createTypeFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
|
||||
return createTypeInner(text, context, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiTypeElement createTypeElementFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
|
||||
public PsiTypeElement createTypeElementFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
|
||||
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, TYPE, level(context)), context);
|
||||
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
|
||||
if (!(element instanceof PsiTypeElement)) {
|
||||
@@ -285,7 +285,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
return (PsiTypeElement)element;
|
||||
}
|
||||
|
||||
protected PsiType createTypeInner(final String text, final PsiElement context, final boolean markAsCopy) throws IncorrectOperationException {
|
||||
protected PsiType createTypeInner(final String text, @Nullable final PsiElement context, final boolean markAsCopy) throws IncorrectOperationException {
|
||||
final PsiPrimitiveType primitiveType = PRIMITIVE_TYPES.get(text);
|
||||
if (primitiveType != null) return primitiveType;
|
||||
|
||||
@@ -298,7 +298,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiJavaCodeReferenceElement createReferenceFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
|
||||
public PsiJavaCodeReferenceElement createReferenceFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
|
||||
final boolean isStaticImport = context instanceof PsiImportStaticStatement &&
|
||||
!((PsiImportStaticStatement)context).isOnDemand();
|
||||
final boolean mayHaveDiamonds = context instanceof PsiNewExpression &&
|
||||
@@ -314,7 +314,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiCodeBlock createCodeBlockFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
|
||||
public PsiCodeBlock createCodeBlockFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
|
||||
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, CODE_BLOCK, level(context), true), context);
|
||||
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
|
||||
if (!(element instanceof PsiCodeBlock)) {
|
||||
@@ -325,7 +325,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiStatement createStatementFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
|
||||
public PsiStatement createStatementFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
|
||||
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, STATEMENT, level(context)), context);
|
||||
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
|
||||
if (!(element instanceof PsiStatement)) {
|
||||
@@ -336,7 +336,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiExpression createExpressionFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
|
||||
public PsiExpression createExpressionFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
|
||||
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, EXPRESSION, level(context)), context);
|
||||
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
|
||||
if (!(element instanceof PsiExpression)) {
|
||||
@@ -353,7 +353,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiTypeParameter createTypeParameterFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
|
||||
public PsiTypeParameter createTypeParameterFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
|
||||
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, TYPE_PARAMETER, level(context)), context);
|
||||
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
|
||||
if (!(element instanceof PsiTypeParameter)) {
|
||||
@@ -364,7 +364,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiComment createCommentFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
|
||||
public PsiComment createCommentFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
|
||||
final PsiJavaFile aFile = createDummyJavaFile(text);
|
||||
for (PsiElement aChildren : aFile.getChildren()) {
|
||||
if (aChildren instanceof PsiComment) {
|
||||
@@ -382,7 +382,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiEnumConstant createEnumConstantFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
|
||||
public PsiEnumConstant createEnumConstantFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
|
||||
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, ENUM_CONSTANT, level(context)), context);
|
||||
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
|
||||
if (!(element instanceof PsiEnumConstant)) {
|
||||
@@ -393,8 +393,9 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiCatchSection createCatchSection(@NotNull final PsiClassType exceptionType, @NotNull final String exceptionName,
|
||||
final PsiElement context) throws IncorrectOperationException {
|
||||
public PsiCatchSection createCatchSection(@NotNull final PsiClassType exceptionType,
|
||||
@NotNull final String exceptionName,
|
||||
@Nullable final PsiElement context) throws IncorrectOperationException {
|
||||
final String text = StringUtil
|
||||
.join("catch (", exceptionType.getCanonicalText(), " ", exceptionName, ") {}");
|
||||
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, CATCH_SECTION, level(context)), context);
|
||||
@@ -406,7 +407,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
return (PsiCatchSection)myManager.getCodeStyleManager().reformat(element);
|
||||
}
|
||||
|
||||
private void setupCatchBlock(final String exceptionName, final PsiElement context, final PsiCatchSection psiCatchSection)
|
||||
private void setupCatchBlock(final String exceptionName, @Nullable final PsiElement context, final PsiCatchSection psiCatchSection)
|
||||
throws IncorrectOperationException {
|
||||
final FileTemplate catchBodyTemplate = FileTemplateManager.getInstance().getCodeTemplate(JavaTemplateUtil.TEMPLATE_CATCH_BODY);
|
||||
LOG.assertTrue(catchBodyTemplate != null);
|
||||
@@ -433,6 +434,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
psiCatchSection.getCatchBlock().replace(codeBlockFromText);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiType createPrimitiveType(@NotNull final String text, @NotNull final PsiAnnotation[] annotations) throws IncorrectOperationException {
|
||||
final PsiPrimitiveType primitiveType = getPrimitiveType(text);
|
||||
|
||||
@@ -207,11 +207,14 @@ public class PsiSuperMethodImplUtil {
|
||||
if (!PsiUtil.isAccessible(hierarchicalMethodSignature.getMethod(), aClass, aClass)) return;
|
||||
HierarchicalMethodSignatureImpl existing = map.get(signature);
|
||||
if (existing == null) {
|
||||
map.put(signature, copy(hierarchicalMethodSignature));
|
||||
HierarchicalMethodSignatureImpl copy = copy(hierarchicalMethodSignature);
|
||||
LOG.assertTrue(copy.getMethod().isValid());
|
||||
map.put(signature, copy);
|
||||
}
|
||||
else if (isReturnTypeIsMoreSpecificThan(hierarchicalMethodSignature, existing) && isSuperMethod(aClass, hierarchicalMethodSignature, existing)) {
|
||||
HierarchicalMethodSignatureImpl newSuper = copy(hierarchicalMethodSignature);
|
||||
mergeSupers(newSuper, existing);
|
||||
LOG.assertTrue(newSuper.getMethod().isValid());
|
||||
map.put(signature, newSuper);
|
||||
}
|
||||
else if (isSuperMethod(aClass, existing, hierarchicalMethodSignature)) {
|
||||
|
||||
@@ -62,7 +62,8 @@ public class JavaDirectoryServiceImpl extends JavaDirectoryService {
|
||||
|
||||
List<PsiClass> classes = null;
|
||||
for (PsiFile file : dir.getFiles()) {
|
||||
if (file instanceof PsiClassOwner) {
|
||||
FileViewProvider viewProvider = file.getViewProvider();
|
||||
if (file instanceof PsiClassOwner && file == viewProvider.getPsi(viewProvider.getBaseLanguage())) {
|
||||
PsiClass[] psiClasses = ((PsiClassOwner)file).getClasses();
|
||||
if (psiClasses.length == 0) continue;
|
||||
if (classes == null) classes = new ArrayList<PsiClass>();
|
||||
|
||||
@@ -304,11 +304,11 @@ public abstract class PsiJavaFileBaseImpl extends PsiFileImpl implements PsiJava
|
||||
}
|
||||
}
|
||||
|
||||
if(classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.PACKAGE)){
|
||||
final PsiPackage rootPackage = JavaPsiFacade.getInstance(getProject()).findPackage("");
|
||||
processor.handleEvent(JavaScopeProcessorEvent.SET_CURRENT_FILE_CONTEXT, rootPackage);
|
||||
if(rootPackage != null) rootPackage.processDeclarations(processor, state, null, place);
|
||||
}
|
||||
//if(classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.PACKAGE)){
|
||||
// final PsiPackage rootPackage = JavaPsiFacade.getInstance(getProject()).findPackage("");
|
||||
// processor.handleEvent(JavaScopeProcessorEvent.SET_CURRENT_FILE_CONTEXT, rootPackage);
|
||||
// if(rootPackage != null) rootPackage.processDeclarations(processor, state, null, place);
|
||||
//}
|
||||
|
||||
final PsiImportList importList = getImportList();
|
||||
final PsiImportStaticStatement[] importStaticStatements = importList.getImportStaticStatements();
|
||||
|
||||
+9
-4
@@ -52,6 +52,7 @@ import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -194,13 +195,17 @@ public class JavaClassReference extends GenericReference implements PsiJavaRefer
|
||||
}
|
||||
assert newName != null;
|
||||
|
||||
TextRange range =
|
||||
new TextRange(myJavaClassReferenceSet.getReference(0).getRangeInElement().getStartOffset(), getRangeInElement().getEndOffset());
|
||||
int end = getRangeInElement().getEndOffset();
|
||||
String text = getElement().getText();
|
||||
int lt = text.indexOf('<', getRangeInElement().getStartOffset());
|
||||
if (lt >= 0) {
|
||||
end = CharArrayUtil.shiftBackward(text, lt - 1, "\n\t ") + 1;
|
||||
}
|
||||
TextRange range = new TextRange(myJavaClassReferenceSet.getReference(0).getRangeInElement().getStartOffset(), end);
|
||||
final ElementManipulator<PsiElement> manipulator = getManipulator(getElement());
|
||||
if (manipulator != null) {
|
||||
final PsiElement finalElement = manipulator.handleContentChange(getElement(), range, newName);
|
||||
range = new TextRange(range.getStartOffset(), range.getStartOffset() + newName.length());
|
||||
myJavaClassReferenceSet.reparse(finalElement, range);
|
||||
myJavaClassReferenceSet.reparse(finalElement, TextRange.from(range.getStartOffset(), newName.length()));
|
||||
return finalElement;
|
||||
}
|
||||
return element;
|
||||
|
||||
+9
-11
@@ -32,10 +32,10 @@ import java.util.Map;
|
||||
* @author peter
|
||||
*/
|
||||
public class JavaClassReferenceSet {
|
||||
public static final char SEPARATOR = '.';
|
||||
public static final char SEPARATOR2 = '$';
|
||||
private static final char SEPARATOR3 = '<';
|
||||
private static final char SEPARATOR4 = ',';
|
||||
public static final char DOT = '.';
|
||||
public static final char DOLLAR = '$';
|
||||
private static final char LT = '<';
|
||||
private static final char COMMA = ',';
|
||||
|
||||
private JavaClassReference[] myReferences;
|
||||
private List<JavaClassReferenceSet> myNestedGenericParameterReferences;
|
||||
@@ -75,14 +75,12 @@ public class JavaClassReferenceSet {
|
||||
for(int curIndex = currentDot + 1; curIndex < str.length(); ++curIndex) {
|
||||
final char ch = str.charAt(curIndex);
|
||||
|
||||
if (ch == SEPARATOR ||
|
||||
(ch == SEPARATOR2 && allowDollarInNames)
|
||||
) {
|
||||
if (ch == DOT || ch == DOLLAR && allowDollarInNames) {
|
||||
nextDotOrDollar = curIndex;
|
||||
break;
|
||||
}
|
||||
|
||||
if (((ch == SEPARATOR3 || ch == SEPARATOR4))) {
|
||||
if (ch == LT || ch == COMMA) {
|
||||
if (!allowGenericsCalculated) {
|
||||
allowGenerics = !isStaticImport && PsiUtil.getLanguageLevel(element).hasEnumKeywordAndAutoboxing();
|
||||
allowGenericsCalculated = true;
|
||||
@@ -131,7 +129,7 @@ public class JavaClassReferenceSet {
|
||||
|
||||
if (nextDotOrDollar != -1 && nextDotOrDollar < str.length()) {
|
||||
final char c = str.charAt(nextDotOrDollar);
|
||||
if (c == SEPARATOR3) {
|
||||
if (c == LT) {
|
||||
int end = str.lastIndexOf('>');
|
||||
if (end != -1 && end > nextDotOrDollar) {
|
||||
if (myNestedGenericParameterReferences == null) myNestedGenericParameterReferences = new ArrayList<JavaClassReferenceSet>(1);
|
||||
@@ -149,7 +147,7 @@ public class JavaClassReferenceSet {
|
||||
} else {
|
||||
nextDotOrDollar = -1; // nonsensible characters anyway, don't do resolve
|
||||
}
|
||||
} else if (SEPARATOR4 == c && myContext != null) {
|
||||
} else if (COMMA == c && myContext != null) {
|
||||
if (myContext.myNestedGenericParameterReferences == null) myContext.myNestedGenericParameterReferences = new ArrayList<JavaClassReferenceSet>(1);
|
||||
myContext.myNestedGenericParameterReferences.add(
|
||||
new JavaClassReferenceSet(
|
||||
@@ -194,7 +192,7 @@ public class JavaClassReferenceSet {
|
||||
}
|
||||
|
||||
protected boolean isStaticSeparator(char c, boolean strict) {
|
||||
return isAllowDollarInNames() ? c == SEPARATOR2 : c == SEPARATOR;
|
||||
return isAllowDollarInNames() ? c == DOLLAR : c == DOT;
|
||||
}
|
||||
|
||||
public void reparse(PsiElement element, final TextRange range) {
|
||||
|
||||
@@ -32,6 +32,8 @@ public class KnownElementWeigher extends ProximityWeigher {
|
||||
if (element instanceof PsiClass) {
|
||||
@NonNls final String qname = ((PsiClass)element).getQualifiedName();
|
||||
if (qname != null) {
|
||||
if (qname.startsWith("java.lang")) return 4;
|
||||
if (qname.startsWith("java.util")) return 3;
|
||||
if (qname.startsWith("java.")) return 2;
|
||||
if (qname.startsWith("javax.")) return 1;
|
||||
if (qname.startsWith("com.")) return -1;
|
||||
|
||||
+1
-1
@@ -149,7 +149,7 @@ public class IntroduceConstantHandler extends BaseExpressionToFieldHandler {
|
||||
if (editor != null && editor.getSettings().isVariableInplaceRenameEnabled()) {
|
||||
new InplaceIntroduceConstantPopup(project, editor, parentClass, expr, localVariable, occurences, typeSelectorManager,
|
||||
anchorElement, anchorElementIfAll,
|
||||
createOccurenceManager(expr, parentClass)).performInplaceIntroduce();
|
||||
expr != null ? createOccurenceManager(expr, parentClass) : null).performInplaceIntroduce();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -108,7 +108,7 @@ public class IntroduceFieldHandler extends BaseExpressionToFieldHandler {
|
||||
if (editor != null && editor.getSettings().isVariableInplaceRenameEnabled()) {
|
||||
myInplaceIntroduceFieldPopup =
|
||||
new InplaceIntroduceFieldPopup(localVariable, parentClass, declareStatic, currentMethodConstructor, occurences, expr, typeSelectorManager, editor,
|
||||
allowInitInMethod, allowInitInMethodIfAll, anchorElement, anchorElementIfAll, createOccurenceManager(expr, parentClass));
|
||||
allowInitInMethod, allowInitInMethodIfAll, anchorElement, anchorElementIfAll, expr != null ? createOccurenceManager(expr, parentClass) : null);
|
||||
myInplaceIntroduceFieldPopup.startTemplate();
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.intellij.slicer;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import gnu.trove.THashMap;
|
||||
import gnu.trove.TObjectHashingStrategy;
|
||||
@@ -37,13 +39,17 @@ public class DuplicateMap {
|
||||
};
|
||||
private final Map<SliceUsage, SliceNode> myDuplicates = new THashMap<SliceUsage, SliceNode>(USAGEINFO_EQUALITY);
|
||||
|
||||
public SliceNode putNodeCheckDupe(SliceNode node) {
|
||||
SliceUsage usage = node.getValue();
|
||||
SliceNode eq = myDuplicates.get(usage);
|
||||
if (eq == null) {
|
||||
myDuplicates.put(usage, node);
|
||||
}
|
||||
return eq;
|
||||
public SliceNode putNodeCheckDupe(final SliceNode node) {
|
||||
return ApplicationManager.getApplication().runReadAction(new Computable<SliceNode>() {
|
||||
public SliceNode compute() {
|
||||
SliceUsage usage = node.getValue();
|
||||
SliceNode eq = myDuplicates.get(usage);
|
||||
if (eq == null) {
|
||||
myDuplicates.put(usage, node);
|
||||
}
|
||||
return eq;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
|
||||
Reference in New Issue
Block a user