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

This commit is contained in:
kirillk
2011-10-05 09:58:29 +04:00
86 changed files with 451 additions and 165 deletions
@@ -79,7 +79,7 @@ public abstract class RunConfigurationExtension extends RunConfigurationExtensio
return listener;
}
public boolean isListenerDisabled(RunConfigurationBase configuration, Object listener) {
public boolean isListenerDisabled(RunConfigurationBase configuration, Object listener, RunnerSettings runnerSettings) {
return false;
}
}
@@ -994,7 +994,7 @@ public class ExpectedTypesProvider {
PsiType parameterType = getParameterType(parameter, substitutor);
TailType tailType = getMethodArgumentTailType(argument, index, method, substitutor, parameters);
PsiType defaultType = getDefaultType(method, substitutor, parameterType, argument, args);
PsiType defaultType = getDefaultType(method, substitutor, parameterType, argument, args, index);
ExpectedTypeInfoImpl info = createInfoImpl(parameterType, ExpectedTypeInfo.TYPE_OR_SUBTYPE, defaultType, tailType);
info.setInsertExplicitTypeParams(true);
@@ -1053,7 +1053,7 @@ public class ExpectedTypesProvider {
@Nullable
private static PsiType getDefaultType(final PsiMethod method, final PsiSubstitutor substitutor, final PsiType parameterType,
final PsiExpression argument, PsiExpression[] args) {
final PsiExpression argument, PsiExpression[] args, int index) {
final PsiClass containingClass = method.getContainingClass();
if (containingClass == null) return parameterType;
@@ -1094,10 +1094,17 @@ public class ExpectedTypesProvider {
});
if (type != null) return type;
}
if (("assertEquals".equals(name) || "assertSame".equals(name)) && method.getParameterList().getParametersCount() == 2 && args.length == 2) {
ExpectedTypeInfo info = getEqualsType(args[0] == argument ? args[1] : args[0]);
if (info != null && parameterType.isAssignableFrom(info.getDefaultType())) {
return info.getDefaultType();
int argCount = Math.max(index + 1, args.length);
if ("assertEquals".equals(name) || "assertSame".equals(name) && method.getParameterList().getParametersCount() == argCount) {
if (argCount == 2 ||
argCount == 3 && method.getParameterList().getParameters()[0].getType().equalsToText(CommonClassNames.JAVA_LANG_STRING)) {
int other = index == argCount - 1 ? index - 1 : index + 1;
if (args.length > other) {
ExpectedTypeInfo info = getEqualsType(args[other]);
if (info != null && parameterType.isAssignableFrom(info.getDefaultType())) {
return info.getDefaultType();
}
}
}
}
return parameterType;
@@ -22,10 +22,7 @@ import com.intellij.codeInsight.lookup.LookupActionProvider;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementAction;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMember;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiModifier;
import com.intellij.psi.*;
import com.intellij.util.Consumer;
import org.jetbrains.annotations.Nullable;
@@ -43,6 +40,11 @@ public class ExcludeFromCompletionLookupActionProvider implements LookupActionPr
if (method.hasModifierProperty(PsiModifier.STATIC)) {
addExcludes(consumer, method, StaticImportMethodFix.getMemberQualifiedName(method));
}
} else if (o instanceof PsiField) {
final PsiField field = (PsiField)o;
if (field.hasModifierProperty(PsiModifier.STATIC)) {
addExcludes(consumer, field, StaticImportMethodFix.getMemberQualifiedName(field));
}
}
}
@@ -70,9 +70,8 @@ public class JavaCompletionData extends JavaAwareCompletionData{
)));
public static final PsiJavaElementPattern.Capture<PsiElement> INSIDE_PARAMETER_LIST =
PsiJavaPatterns.psiElement().withParent(
psiElement(PsiJavaCodeReferenceElement.class).withParent(
psiElement(PsiTypeElement.class).withParent(or(psiElement(PsiParameter.class).withParent(PsiParameterList.class),
psiElement(PsiParameterList.class)))));
psiElement(PsiJavaCodeReferenceElement.class).insideStarting(
psiElement().withParent(PsiParameterList.class)));
private static final AndFilter START_OF_CODE_FRAGMENT = new AndFilter(
new ScopeFilter(new AndFilter(
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.completion.impl.CamelHumpMatcher;
import com.intellij.codeInsight.completion.scope.CompletionElement;
import com.intellij.codeInsight.completion.scope.JavaCompletionProcessor;
import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler;
import com.intellij.codeInsight.daemon.impl.quickfix.StaticImportMethodFix;
import com.intellij.codeInsight.guess.GuessManager;
import com.intellij.codeInsight.lookup.*;
import com.intellij.lang.ASTNode;
@@ -171,8 +172,8 @@ public class JavaCompletionUtil {
return type;
}
public static boolean isInExcludedPackage(@NotNull final PsiClass psiClass) {
final String name = psiClass.getQualifiedName();
public static boolean isInExcludedPackage(@NotNull final PsiMember member) {
final String name = StaticImportMethodFix.getMemberQualifiedName(member);
if (name == null) return false;
CodeInsightSettings cis = CodeInsightSettings.getInstance();
for (String excluded : cis.EXCLUDED_PACKAGES) {
@@ -437,12 +438,13 @@ public class JavaCompletionUtil {
LookupElement item = createLookupElement(completionElement, qualifierType);
if (item != null) {
final Object o = item.getObject();
if (o instanceof PsiClass) {
if (!isSourceLevelAccessible(element, (PsiClass)o, pkgContext) || isInExcludedPackage((PsiClass)o)) {
continue;
}
if (o instanceof PsiClass && !isSourceLevelAccessible(element, (PsiClass)o, pkgContext)) {
continue;
}
if (o instanceof PsiMember) {
if (isInExcludedPackage((PsiMember)o)) {
continue;
}
mentioned.add((PsiMember)o);
}
set.add(mayHighlight ? highlightIfNeeded(qualifierType, item, o) : item);
@@ -153,7 +153,7 @@ public class JavaInheritorsGetter extends CompletionProvider<CompletionParameter
return LookupElementDecorator.withInsertHandler(item, myConstructorInsertHandler);
}
private static boolean areInferredTypesApplicable(PsiType[] types, PsiElement originalPosition) {
private static boolean areInferredTypesApplicable(@NotNull PsiType[] types, PsiElement originalPosition) {
final PsiNewExpression newExpression = PsiTreeUtil.getParentOfType(originalPosition, PsiNewExpression.class);
if (newExpression != null) {
final PsiMethodCallExpression methodCallExpression = PsiTreeUtil.getParentOfType(originalPosition, PsiMethodCallExpression.class);
@@ -190,37 +190,42 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
extend(CompletionType.SMART, INSIDE_EXPRESSION, new ExpectedTypeBasedCompletionProvider() {
protected void addCompletions(final CompletionParameters params, final CompletionResultSet result, final Collection<ExpectedTypeInfo> _infos) {
for (final ExpectedTypeInfo info : new THashSet<ExpectedTypeInfo>(_infos, EXPECTED_TYPE_INFO_STRATEGY)) {
final JavaSmartCompletionParameters parameters = new JavaSmartCompletionParameters(params, info);
final PsiType type = info.getType();
Consumer<LookupElement> noTypeCheck = new Consumer<LookupElement>() {
public void consume(final LookupElement lookupElement) {
result.addElement(decorate(lookupElement, _infos));
}
};
BasicExpressionCompletionContributor.fillCompletionVariants(parameters, new Consumer<LookupElement>() {
THashSet<ExpectedTypeInfo> mergedInfos = new THashSet<ExpectedTypeInfo>(_infos, EXPECTED_TYPE_INFO_STRATEGY);
for (final ExpectedTypeInfo info : mergedInfos) {
ReferenceExpressionCompletionContributor.fillCompletionVariants(new JavaSmartCompletionParameters(params, info), noTypeCheck);
}
for (final ExpectedTypeInfo info : mergedInfos) {
BasicExpressionCompletionContributor.fillCompletionVariants(new JavaSmartCompletionParameters(params, info), new Consumer<LookupElement>() {
@Override
public void consume(LookupElement lookupElement) {
final TypedLookupItem typed = lookupElement.as(TypedLookupItem.CLASS_CONDITION_KEY);
if (typed != null) {
final PsiType psiType = typed.getType();
if (psiType != null && type.isAssignableFrom(psiType)) {
if (psiType != null && info.getType().isAssignableFrom(psiType)) {
result.addElement(decorate(lookupElement, _infos));
}
}
}
}, result.getPrefixMatcher());
Consumer<LookupElement> noTypeCheck = new Consumer<LookupElement>() {
public void consume(final LookupElement lookupElement) {
result.addElement(decorate(lookupElement, _infos));
}
};
ReferenceExpressionCompletionContributor.fillCompletionVariants(parameters, noTypeCheck);
PsiElement position = parameters.getPosition();
if (!BasicExpressionCompletionContributor.AFTER_DOT.accepts(position)) {
final PsiElement parent = position.getParent();
if (parent != null && !(parent.getParent() instanceof PsiSwitchLabelStatement)) {
new JavaMembersGetter(type).addMembers(position, true, noTypeCheck);
if (!parameters.getDefaultType().equals(type)) {
new JavaMembersGetter(parameters.getDefaultType()).addMembers(position, true, noTypeCheck);
}
}
PsiElement position = params.getPosition();
final PsiElement parent = position.getParent();
if (!BasicExpressionCompletionContributor.AFTER_DOT.accepts(position) &&
parent != null &&
!(parent.getParent() instanceof PsiSwitchLabelStatement)) {
for (ExpectedTypeInfo info : mergedInfos) {
new JavaMembersGetter(info.getType()).addMembers(position, true, noTypeCheck);
if (!info.getDefaultType().equals(info.getType())) {
new JavaMembersGetter(info.getDefaultType()).addMembers(position, true, noTypeCheck);
}
}
}
@@ -62,8 +62,8 @@ public class ChangeToAppendFix implements IntentionAction {
return JavaTokenType.PLUSEQ == myTokenType &&
myAssignmentExpression.isValid() &&
myAssignmentExpression.getManager().isInProject(myAssignmentExpression) &&
myRhsType.equalsToText("java.lang.String") &&
(myLhsType.equalsToText("java.lang.StringBuilder") || myLhsType.equalsToText("java.lang.StringBuffer"));
myRhsType.equalsToText(CommonClassNames.JAVA_LANG_STRING) &&
(myLhsType.equalsToText(CommonClassNames.JAVA_LANG_STRING_BUILDER) || myLhsType.equalsToText(CommonClassNames.JAVA_LANG_STRING_BUFFER));
}
@Override
@@ -103,14 +103,13 @@ public class StaticImportMethodFix implements IntentionAction {
List<PsiMethod> applicableList = new ArrayList<PsiMethod>();
for (PsiMethod method : methods) {
ProgressManager.checkCanceled();
PsiClass aClass = method.getContainingClass();
if (aClass != null && JavaCompletionUtil.isInExcludedPackage(aClass)) continue;
if (JavaCompletionUtil.isInExcludedPackage(method)) continue;
if (!method.hasModifierProperty(PsiModifier.STATIC)) continue;
PsiFile file = method.getContainingFile();
if (file instanceof PsiJavaFile
//do not show methods from default package
&& ((PsiJavaFile)file).getPackageName().length() != 0
&& PsiUtil.isAccessible(method, element, aClass)) {
&& PsiUtil.isAccessible(method, element, method.getContainingClass())) {
list.add(method);
if (PsiUtil.isApplicable(method, PsiSubstitutor.EMPTY, argumentList)) {
applicableList.add(method);
@@ -269,12 +268,16 @@ public class StaticImportMethodFix implements IntentionAction {
}
@Nullable
public static String getMemberQualifiedName(PsiMember method) {
PsiClass containingClass = method.getContainingClass();
public static String getMemberQualifiedName(PsiMember member) {
if (member instanceof PsiClass) {
return ((PsiClass)member).getQualifiedName();
}
PsiClass containingClass = member.getContainingClass();
if (containingClass == null) return null;
String className = containingClass.getQualifiedName();
if (className == null) return null;
return className + "." + method.getName();
return className + "." + member.getName();
}
public boolean startInWriteAction() {
@@ -125,7 +125,7 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
for (int i = 0; i < candidates.length; i++) {
CandidateInfo candidate = (CandidateInfo)candidates[i];
PsiMethod method = (PsiMethod)candidate.getElement();
PsiSubstitutor substitutor = candidate instanceof MethodCandidateInfo ? ((MethodCandidateInfo)candidate).inferTypeArguments(true) : candidate.getSubstitutor();
PsiSubstitutor substitutor = candidate instanceof MethodCandidateInfo && ((MethodCandidateInfo)candidate).isInferencePossible() ? ((MethodCandidateInfo)candidate).inferTypeArguments(true) : candidate.getSubstitutor();
assert substitutor != null;
if (!method.isValid() || !substitutor.isValid()) {
@@ -408,7 +408,7 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
public void updateUI(final Object p, final ParameterInfoUIContext context) {
if (p instanceof CandidateInfo) {
CandidateInfo info = (CandidateInfo)p;
updateMethodPresentation((PsiMethod)info.getElement(), info instanceof MethodCandidateInfo ? ((MethodCandidateInfo)info).inferTypeArguments(true) : info.getSubstitutor(), context);
updateMethodPresentation((PsiMethod)info.getElement(), info instanceof MethodCandidateInfo && ((MethodCandidateInfo)info).isInferencePossible() ? ((MethodCandidateInfo)info).inferTypeArguments(true) : info.getSubstitutor(), context);
}
else {
updateMethodPresentation((PsiMethod)p, null, context);
@@ -24,6 +24,7 @@ import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.util.ClassConditionKey;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
import com.intellij.psi.impl.source.PsiClassReferenceType;
import com.intellij.psi.util.PsiUtil;
import org.jetbrains.annotations.NonNls;
@@ -51,6 +52,7 @@ public class PsiTypeLookupItem extends LookupItem {
public void handleInsert(InsertionContext context) {
context.getDocument().insertString(context.getTailOffset(), calcGenerics());
DefaultInsertHandler.addImportForItem(context, this);
PostprocessReformattingAspect.getInstance(context.getProject()).doPostponedFormatting();
int tail = context.getTailOffset();
String braces = StringUtil.repeat("[]", getBracketsCount());
@@ -16,11 +16,14 @@
package com.intellij.psi.filters.getters;
import com.intellij.codeInsight.completion.InsertionContext;
import com.intellij.codeInsight.lookup.*;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementPresentation;
import com.intellij.codeInsight.lookup.TypedLookupItem;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -49,9 +52,9 @@ public class ClassLiteralLookupElement extends LookupElement implements TypedLoo
public void renderElement(LookupElementPresentation presentation) {
presentation.setItemText(getLookupString());
presentation.setIcon(myExpr.getIcon(0));
final PsiType type = myExpr.getType();
if (type != null) {
presentation.setTypeText(type.getPresentableText());
String pkg = StringUtil.getPackageName(myCanonicalText);
if (StringUtil.isNotEmpty(pkg)) {
presentation.setTailText(" (" + pkg + ")", true);
}
}
@@ -17,6 +17,7 @@ package com.intellij.psi.filters.getters;
import com.intellij.codeInsight.CodeInsightUtil;
import com.intellij.codeInsight.completion.CompletionUtil;
import com.intellij.codeInsight.completion.JavaCompletionUtil;
import com.intellij.codeInsight.lookup.AutoCompletionPolicy;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.openapi.util.Condition;
@@ -85,6 +86,7 @@ public abstract class MembersGetter {
for (final PsiElement result : processor.getResults()) {
if (result instanceof PsiMember && !(result instanceof PsiClass)) {
final PsiMember member = (PsiMember)result;
if (JavaCompletionUtil.isInExcludedPackage(member)) continue;
if (member.hasModifierProperty(PsiModifier.STATIC) && resolveHelper.isAccessible(member, context, null)) {
if (result instanceof PsiField && !member.hasModifierProperty(PsiModifier.FINAL)) continue;
if (result instanceof PsiMethod && acceptMethods) continue;
@@ -17,6 +17,7 @@ package com.intellij.refactoring.inline;
import com.intellij.codeInsight.PsiEquivalenceUtil;
import com.intellij.codeInspection.sameParameterValue.SameParameterValueInspection;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
@@ -48,7 +49,9 @@ public class InlineParameterHandler extends JavaInlineActionHandler {
public static final String REFACTORING_NAME = RefactoringBundle.message("inline.parameter.refactoring");
public boolean canInlineElement(PsiElement element) {
return element instanceof PsiParameter && element.getParent() instanceof PsiParameterList;
return element instanceof PsiParameter &&
element.getParent() instanceof PsiParameterList &&
element.getLanguage() == JavaLanguage.INSTANCE;
}
public void inlineElement(final Project project, final Editor editor, final PsiElement psiElement) {
@@ -27,6 +27,7 @@ import com.intellij.psi.util.PsiUtil;
import com.intellij.refactoring.JavaRefactoringSettings;
import com.intellij.refactoring.ui.TypeSelectorManagerImpl;
import com.intellij.refactoring.util.occurrences.OccurrenceManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -165,7 +166,7 @@ public class InplaceIntroduceConstantPopup extends AbstractInplaceIntroduceField
}
@Override
protected void saveSettings(PsiVariable psiVariable) {
protected void saveSettings(@NotNull PsiVariable psiVariable) {
super.saveSettings(psiVariable);
JavaRefactoringSettings.getInstance().INTRODUCE_CONSTANT_VISIBILITY = getSelectedVisibility();
}
@@ -27,6 +27,7 @@ import com.intellij.psi.util.PsiUtil;
import com.intellij.refactoring.JavaRefactoringSettings;
import com.intellij.refactoring.ui.TypeSelectorManagerImpl;
import com.intellij.refactoring.util.occurrences.OccurrenceManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -141,7 +142,7 @@ public class InplaceIntroduceFieldPopup extends AbstractInplaceIntroduceFieldPop
}
@Override
protected void saveSettings(PsiVariable psiVariable) {
protected void saveSettings(@NotNull PsiVariable psiVariable) {
super.saveSettings(psiVariable);
JavaRefactoringSettings.getInstance().INTRODUCE_FIELD_VISIBILITY = myIntroduceFieldPanel.getFieldVisibility();
myIntroduceFieldPanel.saveFinalState();
@@ -19,6 +19,7 @@ import com.intellij.psi.codeStyle.VariableKind;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.refactoring.introduce.inplace.AbstractInplaceIntroducer;
import com.intellij.refactoring.ui.TypeSelectorManagerImpl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
@@ -91,7 +92,7 @@ public abstract class AbstractJavaInplaceIntroducer extends AbstractInplaceIntro
}
@Override
protected void saveSettings(PsiVariable psiVariable) {
protected void saveSettings(@NotNull PsiVariable psiVariable) {
TypeSelectorManagerImpl.typeSelected(psiVariable.getType(), getType());//myDefaultType.getType());
}
@@ -34,6 +34,7 @@ import com.intellij.refactoring.ui.TypeSelectorManagerImpl;
import com.intellij.usageView.UsageInfo;
import gnu.trove.TIntArrayList;
import gnu.trove.TIntProcedure;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -151,7 +152,7 @@ public class InplaceIntroduceParameterPopup extends AbstractJavaInplaceIntroduce
@Override
protected void saveSettings(PsiVariable psiVariable) {
protected void saveSettings(@NotNull PsiVariable psiVariable) {
myPanel.saveSettings(JavaRefactoringSettings.getInstance());
}
@@ -74,6 +74,7 @@ public interface CommonClassNames {
@NonNls String JAVA_LANG_CHARACTER = "java.lang.Character";
@NonNls String JAVA_LANG_STRING_BUFFER = "java.lang.StringBuffer";
@NonNls String JAVA_LANG_STRING_BUILDER = "java.lang.StringBuilder";
@NonNls String JAVA_LANG_ABSTRACT_STRING_BUILDER = "java.lang.AbstractStringBuilder";
@NonNls String JAVA_LANG_CLONEABLE = "java.lang.Cloneable";
@@ -16,6 +16,7 @@
package com.intellij.psi;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
@@ -29,6 +30,7 @@ public abstract class PsiDiamondType extends PsiType {
public static class DiamondInferenceResult {
public static final DiamondInferenceResult EXPLICIT_CONSTRUCTOR_TYPE_ARGS = new DiamondInferenceResult() {
@NotNull
@Override
public PsiType[] getTypes() {
return PsiType.EMPTY_ARRAY;
@@ -41,6 +43,7 @@ public abstract class PsiDiamondType extends PsiType {
};
public static final DiamondInferenceResult NULL_RESULT = new DiamondInferenceResult() {
@NotNull
@Override
public PsiType[] getTypes() {
return PsiType.EMPTY_ARRAY;
@@ -53,6 +56,7 @@ public abstract class PsiDiamondType extends PsiType {
};
public static final DiamondInferenceResult ANONYMOUS_INNER_RESULT = new DiamondInferenceResult() {
@NotNull
@Override
public PsiType[] getTypes() {
return PsiType.EMPTY_ARRAY;
@@ -78,6 +82,7 @@ public abstract class PsiDiamondType extends PsiType {
myProject = project;
}
@NotNull
public PsiType[] getTypes() {
if (myErrorMessage != null) {
return PsiType.EMPTY_ARRAY;
@@ -136,6 +136,10 @@ public class MethodCandidateInfo extends CandidateInfo{
myArgumentList.getParent(), forCompletion);
}
public boolean isInferencePossible() {
return myArgumentList.isValid();
}
public static class ApplicabilityLevel {
public static final int NOT_APPLICABLE = 1;
public static final int VARARGS = 2;
@@ -437,7 +437,7 @@ public final class PsiUtil extends PsiUtilCore {
return getApplicabilityLevel(method, substitutorForMethod, argList.getExpressionTypes(), getLanguageLevel(argList));
}
public static int getApplicabilityLevel(final PsiMethod method, final PsiSubstitutor substitutorForMethod, final PsiType[] args,
public static int getApplicabilityLevel(final PsiMethod method, final PsiSubstitutor substitutorForMethod, @NotNull final PsiType[] args,
final LanguageLevel languageLevel) {
final PsiParameter[] parms = method.getParameterList().getParameters();
if (args.length < parms.length - 1) return ApplicabilityLevel.NOT_APPLICABLE;
+1
View File
@@ -9,6 +9,7 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="java-psi-api" exported="" />
<orderEntry type="module" module-name="core-impl" exported="" />
<orderEntry type="module" module-name="resources-en" />
<orderEntry type="library" name="Guava" level="project" />
</component>
</module>
@@ -4,6 +4,7 @@ import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.lookup.Lookup;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementPresentation;
import com.intellij.codeInsight.lookup.PsiTypeLookupItem;
import com.intellij.codeInsight.template.SmartCompletionContextType;
import com.intellij.codeInsight.template.Template;
@@ -783,6 +784,12 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testClassLiteral() throws Exception {
doActionTest();
assertStringItems("String.class");
LookupElementPresentation p = new LookupElementPresentation();
myFixture.getLookupElements()[0].renderElement(p);
assertEquals("String.class", p.getItemText());
assertEquals(" (java.lang)", p.getTailText());
assertNull(p.getTypeText());
}
public void testNoClassLiteral() throws Exception {
doActionTest();
@@ -292,6 +292,22 @@ public abstract class PsiElementPattern<T extends PsiElement,Self extends PsiEle
}
});
}
public Self insideStarting(final ElementPattern<PsiElement> ancestor) {
return with(new PatternCondition<PsiElement>("insideStarting") {
@Override
public boolean accepts(@NotNull PsiElement start, ProcessingContext context) {
PsiElement element = getParent(start);
while (element != null && element.getTextRange().getStartOffset() == start.getTextRange().getStartOffset()) {
if (ancestor.accepts(element, context)) {
return true;
}
element = getParent(element);
}
return false;
}
});
}
public static class Capture<T extends PsiElement> extends PsiElementPattern<T,Capture<T>> {
@@ -64,6 +64,7 @@ public class LocalInspectionsPassFactory extends AbstractProjectComponent implem
@Override
public TextEditorHighlightingPass createMainHighlightingPass(@NotNull PsiFile file, @NotNull Document document) {
final TextRange textRange = file.getTextRange();
assert textRange != null : "null range " + file.getClass();
return new MyLocalInspectionsPass(file, document, textRange, LocalInspectionsPass.EMPTY_PRIORITY_RANGE);
}
@@ -72,7 +73,7 @@ public class LocalInspectionsPassFactory extends AbstractProjectComponent implem
}
private static class MyLocalInspectionsPass extends LocalInspectionsPass {
public MyLocalInspectionsPass(PsiFile file, Document document, TextRange textRange, TextRange visibleRange) {
public MyLocalInspectionsPass(PsiFile file, Document document, @NotNull TextRange textRange, TextRange visibleRange) {
super(file, document, textRange.getStartOffset(), textRange.getEndOffset(), visibleRange, true);
}
@@ -19,6 +19,7 @@ package com.intellij.ide.util.gotoByName;
import com.intellij.Patches;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl;
import com.intellij.find.findUsages.PsiElement2UsageTargetAdapter;
import com.intellij.ide.IdeBundle;
import com.intellij.ide.actions.CopyReferenceAction;
import com.intellij.ide.ui.UISettings;
@@ -1623,16 +1624,22 @@ public abstract class ChooseByNameBase {
presentation.setCodeUsagesString(pattern);
presentation.setTabName(pattern);
presentation.setTabText(pattern);
presentation.setTargetsNodeText("Unsorted " + StringUtil.toLowerCase(pattern.toLowerCase()));
final PsiElement[] elements = getElements();
final UsageInfo[] usages = new UsageInfo[elements.length];
for (int i = 0; i < elements.length; i++) {
usages[i] = new UsageInfo(elements[i]);
final List<UsageInfo> usageInfos = new ArrayList<UsageInfo>();
final List<PsiElement> targets = new ArrayList<PsiElement>();
for (PsiElement element : elements) {
if (element.getTextRange() != null) {
usageInfos.add(new UsageInfo(element));
} else {
targets.add(element);
}
}
final UsageInfoToUsageConverter.TargetElementsDescriptor descriptor =
new UsageInfoToUsageConverter.TargetElementsDescriptor(elements);
final UsageViewImpl usageView =
(UsageViewImpl)UsageViewManager.getInstance(myProject).showUsages(UsageTarget.EMPTY_ARRAY, UsageInfoToUsageConverter.convert(
descriptor, usages), presentation);
(UsageViewImpl)UsageViewManager.getInstance(myProject).showUsages(targets.isEmpty() ? UsageTarget.EMPTY_ARRAY : PsiElement2UsageTargetAdapter.convert(targets.toArray(new PsiElement[targets.size()])),
UsageInfoToUsageConverter.convert(descriptor, usageInfos.toArray(new UsageInfo[usageInfos.size()])), presentation);
if (myListModel.contains(EXTRA_ELEM)) { //start searching for the rest
final String text = myTextField.getText();
final boolean checkboxState = myCheckBox.isSelected();
@@ -18,6 +18,7 @@ package com.intellij.openapi.fileTypes;
import com.intellij.internal.statistic.AbstractApplicationUsagesCollector;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.FileTypeIndex;
@@ -45,23 +46,30 @@ public class FileTypeUsagesCollector extends AbstractApplicationUsagesCollector
@NotNull
@Override
public Set<UsageDescriptor> getProjectUsages(@NotNull Project project) {
public Set<UsageDescriptor> getProjectUsages(@NotNull final Project project) {
final Set<FileType> usedFileTypes = new HashSet<FileType>();
final FileType[] registeredFileTypes = FileTypeManager.getInstance().getRegisteredFileTypes();
for (final FileType fileType : registeredFileTypes) {
FileBasedIndex.getInstance().processValues(
FileTypeIndex.NAME,
fileType,
null,
new FileBasedIndex.ValueProcessor<Void>() {
@Override
public boolean process(VirtualFile file, Void value) {
usedFileTypes.add(fileType);
return false;
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
if (!project.isDisposed()) {
final FileType[] registeredFileTypes = FileTypeManager.getInstance().getRegisteredFileTypes();
for (final FileType fileType : registeredFileTypes) {
FileBasedIndex.getInstance().processValues(
FileTypeIndex.NAME,
fileType,
null,
new FileBasedIndex.ValueProcessor<Void>() {
@Override
public boolean process(VirtualFile file, Void value) {
usedFileTypes.add(fileType);
return false;
}
}, GlobalSearchScope.projectScope(project));
}
}, GlobalSearchScope.projectScope(project));
}
usedFileTypes.add(UnknownFileType.INSTANCE);
usedFileTypes.add(UnknownFileType.INSTANCE);
}
}
});
return ContainerUtil.map2Set(usedFileTypes, new NotNullFunction<FileType, UsageDescriptor>() {
@NotNull
@Override
@@ -193,7 +193,7 @@ public abstract class AbstractInplaceIntroducer<V extends PsiNameIdentifierOwner
public abstract void setReplaceAllOccurrences(boolean allOccurrences);
protected abstract JComponent getComponent();
protected abstract void saveSettings(V variable);
protected abstract void saveSettings(@NotNull V variable);
protected abstract V getVariable();
public abstract E restoreExpression(PsiFile containingFile, V variable, RangeMarker marker, String exprText);
@@ -483,7 +483,10 @@ public abstract class AbstractInplaceIntroducer<V extends PsiNameIdentifierOwner
}.execute();
}
performIntroduce();
saveSettings(getVariable());
V variable = getVariable();
if (variable != null) {
saveSettings(variable);
}
}
if (getLocalVariable() != null && getLocalVariable().isValid()) {
myEditor.getCaretModel().moveToOffset(getLocalVariable().getTextOffset());
@@ -98,7 +98,7 @@ public final class ScriptRunnerUtil {
return outputBuilder.toString();
}
public static OSProcessHandler execute(String exePath,
public static OSProcessHandler execute(@NotNull String exePath,
@Nullable String workingDirectory,
@Nullable VirtualFile scriptFile,
String[] parameters) throws ExecutionException {
@@ -22,6 +22,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.wm.IdeFrame;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.util.Alarm;
import com.intellij.util.text.DateFormatUtil;
@@ -90,9 +91,12 @@ class StatusPanel extends JPanel {
private Project getActiveProject() {
// a better way of finding a project would be great
for (Project project : ProjectManager.getInstance().getOpenProjects()) {
final JComponent frame = WindowManager.getInstance().getIdeFrame(project).getComponent();
if (SwingUtilities.isDescendingFrom(myTextPanel, frame)) {
return project;
IdeFrame ideFrame = WindowManager.getInstance().getIdeFrame(project);
if (ideFrame != null) {
final JComponent frame = ideFrame.getComponent();
if (SwingUtilities.isDescendingFrom(myTextPanel, frame)) {
return project;
}
}
}
return null;
@@ -193,7 +193,7 @@ public class MismatchedStringBuilderQueryUpdateInspection
}
final PsiClass aClass = (PsiClass)target;
final String qualifiedName = aClass.getQualifiedName();
if (!"java.lang.StringBuilder".equals(qualifiedName) &&
if (!CommonClassNames.JAVA_LANG_STRING_BUILDER.equals(qualifiedName) &&
!"java.lang.StringBuffer".equals(qualifiedName)) {
return false;
}
@@ -54,7 +54,7 @@ public class StringBufferFieldInspection extends BaseInspection {
super.visitField(field);
final PsiType type = field.getType();
if (!type.equalsToText(CommonClassNames.JAVA_LANG_STRING_BUFFER) &&
!type.equalsToText("java.lang.StringBuilder")) {
!type.equalsToText(CommonClassNames.JAVA_LANG_STRING_BUILDER)) {
return;
}
registerFieldError(field, type);
@@ -102,7 +102,7 @@ public class StringBufferReplaceableByStringBuilderInspection
extends BaseInspectionVisitor {
private static final Set<String> excludes = new HashSet(Arrays.asList(
"java.lang.StringBuilder",
CommonClassNames.JAVA_LANG_STRING_BUILDER,
CommonClassNames.JAVA_LANG_STRING_BUFFER));
@Override
@@ -148,7 +148,7 @@ public class LengthOneStringsInConcatenationInspection
}
final String className = methodClass.getQualifiedName();
return CommonClassNames.JAVA_LANG_STRING_BUFFER.equals(className) ||
"java.lang.StringBuilder".equals(className);
CommonClassNames.JAVA_LANG_STRING_BUILDER.equals(className);
}
}
}
@@ -61,7 +61,7 @@ public class StringBufferMustHaveInitialCapacityInspection
if (!TypeUtils.typeEquals(CommonClassNames.JAVA_LANG_STRING_BUFFER,
type) &&
!TypeUtils.typeEquals("java.lang.StringBuilder", type)) {
!TypeUtils.typeEquals(CommonClassNames.JAVA_LANG_STRING_BUILDER, type)) {
return;
}
final PsiExpressionList argumentList = expression.getArgumentList();
@@ -61,7 +61,7 @@ public class StringBufferReplaceableByStringInspection
final PsiType type = variable.getType();
if (!TypeUtils.typeEquals(CommonClassNames.JAVA_LANG_STRING_BUFFER,
type) &&
!TypeUtils.typeEquals("java.lang.StringBuilder", type)) {
!TypeUtils.typeEquals(CommonClassNames.JAVA_LANG_STRING_BUILDER, type)) {
return;
}
final PsiExpression initializer = variable.getInitializer();
@@ -118,7 +118,7 @@ public class StringBufferToStringInConcatenationInspection
}
final String className = aClass.getQualifiedName();
return CommonClassNames.JAVA_LANG_STRING_BUFFER.equals(className) ||
"java.lang.StringBuilder".equals(className);
CommonClassNames.JAVA_LANG_STRING_BUILDER.equals(className);
}
}
}
@@ -111,7 +111,7 @@ public class StringConcatenationInsideStringBufferAppendInspection
else {
useStringValueOf = !qualifiedName.equals(
CommonClassNames.JAVA_LANG_STRING_BUFFER) &&
!qualifiedName.equals("java.lang.StringBuilder");
!qualifiedName.equals(CommonClassNames.JAVA_LANG_STRING_BUILDER);
}
}
}
@@ -245,7 +245,7 @@ public class StringConcatenationInsideStringBufferAppendInspection
}
final String className = containingClass.getQualifiedName();
if (CommonClassNames.JAVA_LANG_STRING_BUFFER.equals(className) ||
"java.lang.StringBuilder".equals(className)) {
CommonClassNames.JAVA_LANG_STRING_BUILDER.equals(className)) {
registerMethodCallError(expression, containingClass);
return;
}
@@ -154,7 +154,7 @@ public class StringEqualsEmptyStringInspection extends BaseInspection {
if (HardcodedMethodConstants.TO_STRING.equals(referenceName) &&
type != null && (type.equalsToText(
CommonClassNames.JAVA_LANG_STRING_BUFFER) ||
type.equalsToText("java.lang.StringBuilder"))) {
type.equalsToText(CommonClassNames.JAVA_LANG_STRING_BUILDER))) {
return qualifierExpression.getText();
}
else {
@@ -95,8 +95,8 @@ class CharToStringPredicate implements PsiElementPredicate {
return false;
}
final String className = type.getCanonicalText();
if ("java.lang.StringBuffer".equals(className) ||
"java.lang.StringBuilder".equals(className)) {
if (CommonClassNames.JAVA_LANG_STRING_BUFFER.equals(className) ||
CommonClassNames.JAVA_LANG_STRING_BUILDER.equals(className)) {
@NonNls final String methodName =
methodExpression.getReferenceName();
if (!"append".equals(methodName) &&
@@ -114,8 +114,8 @@ class StringToCharPredicate implements PsiElementPredicate {
return false;
}
final String className = type.getCanonicalText();
if ("java.lang.StringBuffer".equals(className) ||
"java.lang.StringBuilder".equals(className)) {
if (CommonClassNames.JAVA_LANG_STRING_BUFFER.equals(className) ||
CommonClassNames.JAVA_LANG_STRING_BUILDER.equals(className)) {
@NonNls final String methodName =
methodExpression.getReferenceName();
if (!"append".equals(methodName) &&
@@ -62,8 +62,8 @@ class AppendUtil {
return false;
}
final String name = containingClass.getQualifiedName();
if ("java.lang.StringBuffer".equals(name) ||
"java.lang.StringBuilder".equals(name)) {
if (CommonClassNames.JAVA_LANG_STRING_BUFFER.equals(name) ||
CommonClassNames.JAVA_LANG_STRING_BUILDER.equals(name)) {
return true;
}
final Project project = containingClass.getProject();
@@ -110,8 +110,8 @@ public class ReplaceConcatenationWithStringBufferIntention extends MutablyNamedI
return false;
}
final String className = type.getCanonicalText();
if (!"java.lang.StringBuffer".equals(className) &&
!"java.lang.StringBuilder".equals(className)) {
if (!CommonClassNames.JAVA_LANG_STRING_BUFFER.equals(className) &&
!CommonClassNames.JAVA_LANG_STRING_BUILDER.equals(className)) {
return false;
}
@NonNls final String methodName = methodExpression.getReferenceName();
@@ -115,6 +115,12 @@ public abstract class AndroidSdk {
@Nullable
public static AndroidSdk parse(@NotNull String path, @NotNull ISdkLog log) {
path = FileUtil.toSystemDependentName(path);
final File f = new File(path);
if (!f.exists() && !f.isDirectory()) {
return null;
}
SdkManager manager = SdkManager.createManager(path + File.separatorChar, log);
if (manager != null) {
return new AndroidSdkImpl(manager);
@@ -191,6 +191,10 @@ public class AndroidUtils {
return ApplicationManager.getApplication().runReadAction(new Computable<T>() {
@Nullable
public T compute() {
if (module.isDisposed()) {
return null;
}
Project project = module.getProject();
if (project.isDisposed()) return null;
PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
@@ -84,8 +84,10 @@ public class GitAdd extends BasicAction {
protected boolean isEnabled(@NotNull Project project, @NotNull GitVcs vcs, @NotNull VirtualFile... vFiles) {
for (VirtualFile file : vFiles) {
FileStatus fileStatus = FileStatusManager.getInstance(project).getStatus(file);
if (fileStatus == FileStatus.NOT_CHANGED || fileStatus == FileStatus.DELETED) return false;
if (file.isDirectory() || (fileStatus != FileStatus.NOT_CHANGED && fileStatus != FileStatus.DELETED)) {
return true;
}
}
return true;
return false;
}
}
@@ -24,19 +24,30 @@ import org.jetbrains.annotations.NotNull;
enum GitChangeType {
MODIFIED('M'),
ADDED('A'),
COPIED('C'),
COPIED('C', true),
DELETED('D'),
RENAMED('R'),
RENAMED('R', true),
UNRESOLVED('U'),
TYPE_CHANGED('T')
;
private char myChar;
private final char myChar;
private final boolean myRequiresSecondPath;
GitChangeType(char c) {
this(c, false);
}
GitChangeType(char c, boolean requiresSecondPath) {
myChar = c;
myRequiresSecondPath = requiresSecondPath;
}
/**
* Finds the GitChangeType by the given string returned by Git.
* @throws GitFormatException if such status can't be found: it means either a developer mistake missing a possible valid status,
* or a Git invalid output.
*/
@NotNull
static GitChangeType fromString(@NotNull String statusString) {
assert statusString.length() > 0;
@@ -48,5 +59,12 @@ enum GitChangeType {
}
throw new GitFormatException("Unexpected status [" + statusString + "]");
}
/**
* @return true if this change type has 2 paths: old and new. This is true for renames and copies.
*/
boolean requiresSecondPath() {
return myRequiresSecondPath;
}
}
@@ -15,6 +15,7 @@
*/
package git4idea.history;
import com.intellij.openapi.diagnostic.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -24,6 +25,9 @@ import org.jetbrains.annotations.Nullable;
* @author Kirill Likhodedov
*/
class GitLogStatusInfo {
private static final Logger LOG = Logger.getInstance(GitLogStatusInfo.class);
private final GitChangeType myType;
private final String myPath;
private final String mySecondPath;
@@ -39,10 +43,10 @@ class GitLogStatusInfo {
* SecondPath == null iff it the type is rename
*/
private static void verifyParameters(@NotNull GitChangeType type, @NotNull String path, @Nullable String secondPath) {
if (type == GitChangeType.RENAMED) {
assert secondPath != null;
if (type.requiresSecondPath()) {
LOG.assertTrue(secondPath != null, "Rename change should have the second path");
} else {
assert secondPath == null;
LOG.assertTrue(secondPath == null, "Second path should be null in case of change type [" + type + "]");
}
}
@@ -113,8 +113,7 @@ public class GroovyStaticImportMethodFix implements IntentionAction {
List<PsiMethod> applicableList = new ArrayList<PsiMethod>();
for (PsiMethod method : methods) {
ProgressManager.checkCanceled();
PsiClass aClass = method.getContainingClass();
if (aClass != null && JavaCompletionUtil.isInExcludedPackage(aClass)) continue;
if (JavaCompletionUtil.isInExcludedPackage(method)) continue;
if (!method.hasModifierProperty(PsiModifier.STATIC)) continue;
PsiFile file = method.getContainingFile();
if (file instanceof PsiClassOwner
@@ -422,7 +422,7 @@ public class GroovyCompletionContributor extends CompletionContributor {
object = ((GroovyResolveResult)object).getElement();
}
if (object instanceof PsiClass && JavaCompletionUtil.isInExcludedPackage((PsiClass)object)) {
if (object instanceof PsiMember && JavaCompletionUtil.isInExcludedPackage((PsiMember)object)) {
return;
}
@@ -140,19 +140,19 @@ public class GroovyParameterInfoHandler implements ParameterInfoHandlerWithTabAc
final PsiElement parent = place.getParent();
if (parent instanceof GrMethodCall) {
final GrExpression invoked = ((GrMethodCall)parent).getInvokedExpression();
if (isSimpleMethodInvoked(invoked)) {
elementToShow.addAll(ContainerUtil.findAll(variants, condition));
}
else {
if (isPropertyInvoked(invoked)) {
final PsiType type = invoked.getType();
if (type instanceof GrClosureType) {
elementToShow.add(type);
}
else if (type != null) {
elementToShow.addAll(
ContainerUtil.findAll(ResolveUtil.getMethodCandidates(type, "call", place, PsiUtil.getArgumentTypes(place, true)), condition));
final GroovyResolveResult[] calls = ResolveUtil.getMethodCandidates(type, "call", place, PsiUtil.getArgumentTypes(place, true));
elementToShow.addAll(ContainerUtil.findAll(calls, condition));
}
}
else {
elementToShow.addAll(ContainerUtil.findAll(variants, condition));
}
}
else {
elementToShow.addAll(Arrays.asList(variants));
@@ -161,14 +161,20 @@ public class GroovyParameterInfoHandler implements ParameterInfoHandlerWithTabAc
context.showHint(place, place.getTextRange().getStartOffset(), this);
}
private static boolean isSimpleMethodInvoked(GrExpression invoked) {
private static boolean isPropertyInvoked(GrExpression invoked) {
if (!(invoked instanceof GrReferenceExpression)) return false;
final GroovyResolveResult resolveResult = ((GrReferenceExpression)invoked).advancedResolve();
return resolveResult.getElement() instanceof PsiMethod && !resolveResult.isInvokedOnProperty();
return resolveResult.isInvokedOnProperty();
}
public void updateParameterInfo(@NotNull GroovyPsiElement place, UpdateParameterInfoContext context) {
final PsiElement parameterOwner = context.getParameterOwner();
if (parameterOwner != place) {
context.removeHint();
return;
}
int offset = context.getEditor().getCaretModel().getOffset();
offset = CharArrayUtil.shiftForward(context.getEditor().getDocument().getText(), offset, " \t\n");
final int currIndex = getCurrentParameterIndex(place, offset);
@@ -13,6 +13,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpres
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.arithmetic.GrRangeExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrStringInjection;
import org.jetbrains.plugins.groovy.lang.psi.impl.GrRangeType;
import org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleType;
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
@@ -85,6 +86,10 @@ public class ClosureParameterEnhancer extends AbstractClosureParameterEnhancer {
@Nullable
protected PsiType getClosureParameterType(GrClosableBlock closure, int index) {
PsiElement parent = closure.getParent();
if (parent instanceof GrStringInjection && index == 0) {
return TypesUtil.createTypeByFQClassName(CommonClassNames.JAVA_LANG_STRING_BUILDER, closure);
}
if (parent instanceof GrArgumentList) parent = parent.getParent();
if (!(parent instanceof GrMethodCall)) {
return null;
@@ -35,6 +35,7 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrStringInjection;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
@@ -85,7 +86,7 @@ public class GrClosableBlockImpl extends GrBlockImpl implements GrClosableBlock
PsiElement current = place;
boolean it_already_processed = false;
while (current != this && current != null) {
if (current instanceof GrClosableBlock && !((GrClosableBlock)current).hasParametersSection()) {
if (current instanceof GrClosableBlock && !((GrClosableBlock)current).hasParametersSection() && !(current.getParent() instanceof GrStringInjection)) {
it_already_processed = true;
break;
}
@@ -184,6 +185,10 @@ public class GrClosableBlockImpl extends GrBlockImpl implements GrClosableBlock
}
public GrParameter[] getSyntheticItParameter() {
if (getParent() instanceof GrStringInjection) {
return GrParameter.EMPTY_ARRAY;
}
GrParameter[] res = mySyntheticItParameter;
if (res == null) {
res = new GrParameter[]{new ClosureSyntheticParameter(this)};
@@ -165,6 +165,9 @@ public class GrReferenceResolveUtil {
GroovyPsiElement resolveContext,
GroovyPsiElement place) {
final ResolveState state;
if (qualifierType instanceof PsiDisjunctionType) {
qualifierType = ((PsiDisjunctionType)qualifierType).getLeastUpperBound();
}
if (qualifierType instanceof PsiClassType) {
PsiClassType.ClassResolveResult qualifierResult = ((PsiClassType)qualifierType).resolveGenerics();
PsiClass qualifierClass = qualifierResult.getElement();
@@ -17,6 +17,7 @@
package org.jetbrains.plugins.groovy.mvc.projectView;
import com.intellij.ide.util.EditorHelper;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileEditor.*;
@@ -97,13 +98,27 @@ public class MvcProjectViewPane extends AbstractProjectViewPSIPane implements Id
}
};
project.getMessageBus().connect(this).subscribe(PsiModificationTracker.TOPIC, new PsiModificationTracker.Listener() {
public void modificationCountChanged() {
class TreeUpdater implements Runnable, PsiModificationTracker.Listener {
private volatile boolean myInQueue;
@Override
public void run() {
if (getTree() != null && getTreeBuilder() != null) {
updateFromRoot(true);
}
myInQueue = false;
}
});
@Override
public void modificationCountChanged() {
if (!myInQueue) {
myInQueue = true;
ApplicationManager.getApplication().invokeLater(this);
}
}
}
project.getMessageBus().connect(this).subscribe(PsiModificationTracker.TOPIC, new TreeUpdater());
myComponent = new JPanel(new BorderLayout());
myComponent.add(createComponent(), BorderLayout.CENTER);
@@ -181,6 +181,7 @@ public abstract class GroovyRefactoringUtil {
// todo add type hierarchy
public static Map<String, PsiType> getCompatibleTypeNames(@NotNull PsiType type) {
if (type instanceof PsiDisjunctionType) type = ((PsiDisjunctionType)type).getLeastUpperBound();
Map<String, PsiType> map = new LinkedHashMap<String, PsiType>();
final PsiPrimitiveType unboxed = PsiPrimitiveType.getUnboxedType(type);
if (unboxed != null) type = unboxed;
@@ -103,8 +103,7 @@ public class GrParameterInfo implements JavaParameterInfo {
}
public PsiExpression getValue(PsiCallExpression callExpression) {
return JavaPsiFacade.getInstance(callExpression.getProject()).getElementFactory()
.createExpressionFromText(myDefaultValue, callExpression);
return JavaPsiFacade.getElementFactory(callExpression.getProject()).createExpressionFromText(getDefaultValue(), callExpression);
}
public boolean isVarargType() {
@@ -231,13 +231,18 @@ public class GrIntroduceConstantDialog extends DialogWrapper
private void initializeTypeCombo() {
final PsiType expressionType;
PsiType expressionType;
if (myContext.expression != null) {
expressionType = myContext.expression.getType();
}
else {
expressionType = myContext.var.getDeclaredType();
}
if (expressionType instanceof PsiDisjunctionType) {
expressionType = ((PsiDisjunctionType)expressionType).getLeastUpperBound();
}
if (expressionType != null) {
myTypes = GroovyRefactoringUtil.getCompatibleTypeNames(expressionType);
for (String typeName : myTypes.keySet()) {
@@ -485,8 +485,10 @@ public class GrIntroduceClosureParameterProcessor extends BaseRefactoringProcess
call.append(newName).append('(');
final GrParameter[] parameters = result.getParameters();
for (GrParameter parameter : parameters) {
call.append(parameter.getName()).append(", ");
for (int i = 0; i < parameters.length; i++) {
if (!mySettings.parametersToRemove().contains(i)) {
call.append(parameters[i].getName()).append(", ");
}
}
call.append(myParameterInitializer.getText());
call.append(")");
@@ -86,7 +86,7 @@
<gridbag weightx="1.0" weighty="1.0"/>
</constraints>
<properties>
<text value="Remove local variable"/>
<text value="Remove local &amp;variable"/>
</properties>
</component>
<component id="d4b2" class="javax.swing.JCheckBox" binding="myChangeVarUsages">
@@ -95,7 +95,7 @@
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<text value="Change usages of variable"/>
<text value="&amp;Change usages of closure"/>
</properties>
</component>
</children>
@@ -33,6 +33,8 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.GroovyFileType;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrParametersOwner;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
import org.jetbrains.plugins.groovy.refactoring.GroovyNameSuggestionUtil;
@@ -95,6 +97,9 @@ public class GrIntroduceParameterDialog extends RefactoringDialog implements GrI
initReplaceFieldsWithGetters(settings);
myDeclareFinalCheckBox.setSelected(hasFinalModifier());
myChangeVarUsages.setVisible(context.toReplaceIn instanceof GrClosableBlock && context.toSearchFor instanceof GrVariable);
myChangeVarUsages.setSelected(true);
setTitle(RefactoringBundle.message("introduce.parameter.title"));
init();
@@ -151,6 +156,9 @@ public class GrIntroduceParameterDialog extends RefactoringDialog implements GrI
processor = new GrIntroduceParameterProcessor(settings, myContext);
}
else {
if (!myChangeVarUsages.isSelected() && myContext.toSearchFor != null) {
myContext = new GrIntroduceParameterContext(myContext, myContext.toReplaceIn, null);
}
processor = new GrIntroduceClosureParameterProcessor(settings, myContext);
}
invokeRefactoring(processor);
@@ -169,7 +177,7 @@ public class GrIntroduceParameterDialog extends RefactoringDialog implements GrI
@Override
protected JComponent createCenterPanel() {
final GridBag c = new GridBag().setDefaultAnchor(GridBagConstraints.WEST).setLine(3);
final GridBag c = new GridBag().setDefaultAnchor(GridBagConstraints.WEST).setLine(4);
for (Object o : toRemoveCBs.keys()) {
c.nextLine();
myCheckBoxContainer.add(((JCheckBox)o), c);
@@ -91,8 +91,8 @@ import static org.jetbrains.plugins.groovy.refactoring.HelpID.GROOVY_INTRODUCE_P
public class GrIntroduceParameterHandler implements RefactoringActionHandler {
private static final Logger LOG = Logger.getInstance(GrIntroduceParameterHandler.class);
@NonNls public static final String USE_SUPER_METHOD_OF = "Use super method of";
@NonNls public static final String CHANGE_USAGES_OF = "Change usages of";
@NonNls public static final String USE_SUPER_METHOD_OF = "Change base method";
@NonNls public static final String CHANGE_USAGES_OF = "Change usages";
private JBPopup myEnclosingMethodsPopup;
public void invoke(final @NotNull Project project, final Editor editor, final PsiFile file, final @Nullable DataContext dataContext) {
@@ -177,6 +177,7 @@ public class GrIntroduceParameterHandler implements RefactoringActionHandler {
final GrParametersOwner owner = scopes.get(0);
if (owner instanceof GrMethod) {
PsiMethod newMethod = SuperMethodWarningUtil.checkSuperMethod((PsiMethod)owner, RefactoringBundle.message("to.refactor"));
if (newMethod == null) return;
getContext(project, editor, expression, variable, owner, newMethod);
return;
}
@@ -312,8 +312,8 @@ public class GrIntroduceParameterProcessor extends BaseRefactoringProcessor impl
final GrOpenBlock block = factory.createMethodFromText(call.toString()).getBlock();
result.getBlock().replace(block);
final PsiElement parent = myContext.toReplaceIn.getParent();
return (GrMethod)parent.addBefore(result, myContext.toReplaceIn);
final PsiElement parent = prototype.getParent();
return (GrMethod)parent.addBefore(result, prototype);
}
private void processChangedMethodCall(PsiElement element) {
@@ -15,6 +15,7 @@
*/
package org.jetbrains.plugins.groovy.refactoring.ui;
import com.intellij.psi.PsiDisjunctionType;
import com.intellij.psi.PsiType;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.refactoring.GroovyRefactoringUtil;
@@ -34,6 +35,7 @@ public class GrTypeComboBox extends JComboBox {
public GrTypeComboBox(PsiType type, boolean selectType) {
super();
if (type instanceof PsiDisjunctionType) type = ((PsiDisjunctionType)type).getLeastUpperBound();
myType = type;
initialize();
if (selectType && getItemCount() > 1) {
@@ -1,5 +1,7 @@
package org.jetbrains.plugins.groovy.util;
import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.util.containers.ConcurrentHashMap;
import org.jetbrains.annotations.NotNull;
@@ -13,24 +15,42 @@ public class ClassInstanceCache {
private ClassInstanceCache() {
}
@SuppressWarnings("unchecked")
public static <T> T getInstance(@NotNull String className) {
Object res = CACHE.get(className);
if (res != null) return (T)res;
private static Object createInstance(@NotNull String className) {
try {
Object instance = Class.forName(className).newInstance();
Object oldValue = CACHE.putIfAbsent(className, instance);
if (oldValue != null) {
instance = oldValue;
try {
return Class.forName(className).newInstance();
}
catch (ClassNotFoundException e) {
for (IdeaPluginDescriptor descriptor : PluginManager.getPlugins()) {
try {
return descriptor.getPluginClassLoader().loadClass(className).newInstance();
}
catch (ClassNotFoundException ignored) {
return (T)instance;
}
}
throw new RuntimeException("Class not found: " + className);
}
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
@SuppressWarnings("unchecked")
public static <T> T getInstance(@NotNull String className) {
Object res = CACHE.get(className);
if (res == null) {
res = createInstance(className);
Object oldValue = CACHE.putIfAbsent(className, res);
if (oldValue != null) {
res = oldValue;
}
}
return (T)res;
}
}
@@ -796,4 +796,23 @@ print new B().f<caret>oo()
assertInstanceOf(resolved, GrMethod)
assertTrue(resolved.isPhysical())
}
void testDisjunctionType() {
def ref = configureByText ("""
import java.sql.SQLException
def test() {
try {}
catch (IOException | SQLException ex) {
ex.prin<caret>tStackTrace();
}
}""")
assertNotNull(ref.resolve())
}
void testStringInjectionDontOverrideItParameter() {
def ref = configureByText("""
[2, 3, 4].collect {"\${it.toBigDeci<caret>mal()}"}
""")
assertNotNull(ref.resolve())
}
}
@@ -229,11 +229,11 @@ public class TypeInferenceTest extends GroovyResolveTestCase {
public void testIncMethod() {
assertTypeEquals(JAVA_LANG_INTEGER, "A.groovy");
}
public void testDGMFind() {
assertTypeEquals("java.io.File", "a.groovy");
}
public void testMultiTypeParameter() {
assertTypeEquals("X | Y", "a.groovy");
}
@@ -241,4 +241,8 @@ public class TypeInferenceTest extends GroovyResolveTestCase {
public void testTypeArgsInAccessor() {
assertTypeEquals("Foo<java.lang.String>", "a.groovy");
}
public void testSingleParameterInStringInjection() {
assertTypeEquals("java.lang.StringBuilder", "a.groovy");
}
}
@@ -240,6 +240,10 @@ public class ChangeSignatureTest extends ChangeSignatureTestCase {
doTest(new SimpleInfo("newName", 0), new SimpleInfo(1));
}
public void testDefaultInitializerInJava() {
doTest(new SimpleInfo("p", -1, "", "1", ""));
}
private PsiType createType(String typeText) {
return JavaPsiFacade.getElementFactory(getProject()).createTypeByFQClassName(typeText, GlobalSearchScope.allScope(getProject()));
}
@@ -92,4 +92,8 @@ public class GrIntroduceParameterInClosureTest extends LightCodeInsightFixtureTe
public void testCorrectOccurrencesForLocalVar() {
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, null, false);
}
public void testDelegateRemoveUnusedParam() {
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, true, false, null, true);
}
}
@@ -323,6 +323,8 @@ public class GrIntroduceParameterTest extends LightCodeInsightFixtureTestCase {
public void testDelegate1() {doDelegateTest();}
public void testDelegate2() {doDelegateTest();}
public void testDelegaterInSuper() {doDelegateTest();}
private void doDelegateTest() {
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, null, true);
@@ -0,0 +1,3 @@
class GClass {
public void tes<caret>t() {}
}
@@ -0,0 +1,5 @@
public class JClass {
void doTest() {
new GClass().test();
}
}
@@ -0,0 +1,3 @@
class GClass {
public test(def p = 1) {}
}
@@ -0,0 +1,5 @@
public class JClass {
void doTest() {
new GClass().test(1);
}
}
@@ -0,0 +1,7 @@
class Base {
def foo(){}
}
class Inh extends Base {
def foo() {print <selection>123</selection>}
}
@@ -0,0 +1,15 @@
class Base {
def foo() {
foo(123);
}
def foo(int anObject){}
}
class Inh extends Base {
def foo() {
foo(123);
}
def foo(int anObject) {print anObject}
}
@@ -0,0 +1,3 @@
def clos = { int i ->
println <selection>"test"</selection>
}
@@ -0,0 +1,6 @@
def closDelegate = { String anObject ->
println anObject
}
def clos = {int i ->
closDelegate("test")
}
@@ -0,0 +1 @@
[2, 3, 4].collect {"${builder -> bui<ref>lder.append(it)}"}
@@ -215,7 +215,7 @@ public abstract class TestObject implements JavaCommandLine {
for (final Object listener : listeners) {
boolean enabled = true;
for (RunConfigurationExtension ext : Extensions.getExtensions(RunConfigurationExtension.EP_NAME)) {
if (ext.isListenerDisabled(myConfiguration, listener)) {
if (ext.isListenerDisabled(myConfiguration, listener, myRunnerSettings)) {
enabled = false;
break;
}
@@ -307,7 +307,7 @@ public class TestNGRunnableState extends JavaCommandLineState {
for (Object o : Extensions.getExtensions(IDEATestNGListener.EP_NAME)) {
boolean enabled = true;
for (RunConfigurationExtension extension : Extensions.getExtensions(RunConfigurationExtension.EP_NAME)) {
if (extension.isListenerDisabled(config, o)) {
if (extension.isListenerDisabled(config, o, getRunnerSettings())) {
enabled = false;
break;
}
@@ -49,8 +49,8 @@ public abstract class DomElementsInspection<T extends DomElement> extends XmlSup
private final Set<Class<? extends T>> myDomClasses;
public DomElementsInspection(Class<? extends T> domClass, @NotNull Class<? extends T>... additonalClasses) {
myDomClasses = new THashSet<Class<? extends T>>(Arrays.asList(additonalClasses));
public DomElementsInspection(Class<? extends T> domClass, @NotNull Class<? extends T>... additionalClasses) {
myDomClasses = new THashSet<Class<? extends T>>(Arrays.asList(additionalClasses));
myDomClasses.add(domClass);
}
@@ -22,6 +22,7 @@ import com.intellij.xml.breadcrumbs.BreadcrumbsPresentationProvider;
import com.intellij.xml.breadcrumbs.CrumbPresentation;
import com.intellij.xml.breadcrumbs.DefaultCrumbsPresentation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
@@ -53,7 +54,8 @@ public class XmlTagTreeBreadcrumbsPresentationProvider extends BreadcrumbsPresen
for (int i = result.length - 1; i >= 0; i--) {
if (elements[i] instanceof XmlTag) {
result[i] = new MyCrumbPresentation(baseColors[index % baseColors.length]);
final Color color = baseColors[index % baseColors.length];
result[i] = new MyCrumbPresentation(color);
index++;
}
}
@@ -63,14 +65,16 @@ public class XmlTagTreeBreadcrumbsPresentationProvider extends BreadcrumbsPresen
private static class MyCrumbPresentation extends DefaultCrumbsPresentation {
private final Color myColor;
private MyCrumbPresentation(Color color) {
private MyCrumbPresentation(@Nullable Color color) {
myColor = color;
}
@Override
public Color getBackgroundColor(boolean selected, boolean hovered, boolean light) {
final Color baseColor = super.getBackgroundColor(selected, hovered, light);
return XmlTagTreeHighlightingUtil.makeTransparent(myColor, baseColor, 0.1);
return myColor != null
? XmlTagTreeHighlightingUtil.makeTransparent(myColor, baseColor, 0.1)
: baseColor;
}
}
}
@@ -176,6 +176,10 @@ public class XmlTagTreeHighlightingPass extends TextEditorHighlightingPass {
Color color = colorsForEditor[i];
if (color == null) {
continue;
}
if (pair.first != null) {
highlightInfos.add(createHighlightInfo(color, pair.first));
}
@@ -270,7 +274,9 @@ public class XmlTagTreeHighlightingPass extends TextEditorHighlightingPass {
for (int i = 0; i < resultColors.length; i++) {
final Color color = baseColors[i];
final Color color1 = XmlTagTreeHighlightingUtil.makeTransparent(color, tagBackground, transparency);
final Color color1 = color != null
? XmlTagTreeHighlightingUtil.makeTransparent(color, tagBackground, transparency)
: null;
resultColors[i] = color1;
}
@@ -25,6 +25,7 @@ import com.intellij.psi.PsiFile;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.containers.HashSet;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
import java.util.Set;
@@ -66,7 +67,7 @@ class XmlTagTreeHighlightingUtil {
return true;
}
static Color makeTransparent(Color color, Color backgroundColor, double transparency) {
static Color makeTransparent(@NotNull Color color, @NotNull Color backgroundColor, double transparency) {
int r = makeTransparent(transparency, color.getRed(), backgroundColor.getRed());
int g = makeTransparent(transparency, color.getGreen(), backgroundColor.getGreen());
int b = makeTransparent(transparency, color.getBlue(), backgroundColor.getBlue());