();
+ final LibraryKind kind = ((LibraryEx)library).getKind();
+ if (kind != null) {
+ result.add(kind);
+ }
+ final VirtualFile[] files = getLibraryFiles(library, context);
+ LibraryDetectionManager.getInstance().processProperties(Arrays.asList(files), new LibraryDetectionManager.LibraryPropertiesProcessor() {
+ @Override
+ public boolean processProperties(@NotNull LibraryKind kind, @NotNull P properties) {
+ result.add(kind);
+ return true;
+ }
+ });
+ return result;
+ }
+
+ @NotNull
+ private static VirtualFile[] getLibraryFiles(@NotNull Library library, @Nullable StructureConfigurableContext context) {
+ if (((LibraryEx)library).isDisposed()) {
+ return VirtualFile.EMPTY_ARRAY;
+ }
+ return context != null ? context.getLibraryFiles(library, OrderRootType.CLASSES) : library.getFiles(OrderRootType.CLASSES);
+ }
+
private
LibraryPresentationProvider
getPresentationProvider(LibraryKind kind) {
if (myPresentationProviders == null) {
final Map> providers = new HashMap>();
@@ -62,9 +87,10 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
@Override
public Icon getCustomIcon(@NotNull Library library, StructureConfigurableContext context) {
- final LibraryKind kind = ((LibraryEx)library).getKind();
+ LibraryEx libraryEx = (LibraryEx)library;
+ final LibraryKind kind = libraryEx.getKind();
if (kind != null) {
- return LibraryType.findByKind(kind).getIcon();
+ return LibraryType.findByKind(kind).getIcon(libraryEx.getProperties());
}
final List icons = getCustomIcons(library, context);
if (icons.size() == 1) {
@@ -83,7 +109,7 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
public boolean processProperties(@NotNull LibraryKind kind, @NotNull P properties) {
final LibraryPresentationProvider
provider = getPresentationProvider(kind);
if (provider != null) {
- ContainerUtil.addIfNotNull(icons, provider.getIcon());
+ ContainerUtil.addIfNotNull(icons, provider.getIcon(properties));
}
return true;
}
@@ -117,23 +143,6 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
});
}
- public static List getLibraryKinds(@NotNull Library library, @Nullable StructureConfigurableContext context) {
- final List result = new SmartList();
- final LibraryKind kind = ((LibraryEx)library).getKind();
- if (kind != null) {
- result.add(kind);
- }
- final VirtualFile[] files = getLibraryFiles(library, context);
- LibraryDetectionManager.getInstance().processProperties(Arrays.asList(files), new LibraryDetectionManager.LibraryPropertiesProcessor() {
- @Override
- public boolean processProperties(@NotNull LibraryKind kind, @NotNull P properties) {
- result.add(kind);
- return true;
- }
- });
- return result;
- }
-
@NotNull
@Override
public List getDescriptions(@NotNull Library library, StructureConfigurableContext context) {
@@ -141,14 +150,6 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
return getDescriptions(files, Collections.emptySet());
}
- @NotNull
- private static VirtualFile[] getLibraryFiles(@NotNull Library library, @Nullable StructureConfigurableContext context) {
- if (((LibraryEx)library).isDisposed()) {
- return VirtualFile.EMPTY_ARRAY;
- }
- return context != null ? context.getLibraryFiles(library, OrderRootType.CLASSES) : library.getFiles(OrderRootType.CLASSES);
- }
-
@NotNull
@Override
public List getDescriptions(@NotNull VirtualFile[] classRoots, final Set excludedKinds) {
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryAction.java
index 42861a4e84e4..6da7c1c6a004 100644
--- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryAction.java
+++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryAction.java
@@ -61,20 +61,6 @@ public class CreateNewLibraryAction extends DumbAwareAction {
myProject = project;
}
- @Override
- public void actionPerformed(AnActionEvent e) {
- Library library =
- createLibrary(myType, myLibrariesConfigurable.getTree(), myProject, myLibrariesConfigurable.getModelProvider().getModifiableModel());
- if (library == null) return;
-
- final BaseLibrariesConfigurable rootConfigurable = ProjectStructureConfigurable.getInstance(myProject).getConfigurableFor(library);
- final DefaultMutableTreeNode
- libraryNode = MasterDetailsComponent.findNodeByObject((TreeNode)rootConfigurable.getTree().getModel().getRoot(), library);
- rootConfigurable.selectNodeInTree(libraryNode);
- LibraryEditingUtil.showDialogAndAddLibraryToDependencies(library, myProject, true);
- }
-
-
@Nullable
public static Library createLibrary(@Nullable final LibraryType type, @NotNull final JComponent parentComponent,
@NotNull final Project project, @NotNull final LibrariesModifiableModel modifiableModel) {
@@ -82,7 +68,8 @@ public class CreateNewLibraryAction extends DumbAwareAction {
if (configuration == null) return null;
final LibraryType> libraryType = configuration.getLibraryType();
final Library library = modifiableModel.createLibrary(
- LibraryEditingUtil.suggestNewLibraryName(modifiableModel, configuration.getDefaultLibraryName()), libraryType != null ? libraryType.getKind() : null);
+ LibraryEditingUtil.suggestNewLibraryName(modifiableModel, configuration.getDefaultLibraryName()),
+ libraryType != null ? libraryType.getKind() : null);
final NewLibraryEditor editor = new NewLibraryEditor(libraryType, configuration.getProperties());
configuration.addRoots(editor);
@@ -136,9 +123,22 @@ public class CreateNewLibraryAction extends DumbAwareAction {
for (LibraryType> type : suitableTypes) {
final String actionName = type.getCreateActionName();
if (actionName != null) {
- actions.add(new CreateNewLibraryAction(actionName, type.getIcon(), type, librariesConfigurable, project));
+ actions.add(new CreateNewLibraryAction(actionName, type.getIcon(null), type, librariesConfigurable, project));
}
}
return actions.toArray(new AnAction[actions.size()]);
}
+
+ @Override
+ public void actionPerformed(AnActionEvent e) {
+ Library library =
+ createLibrary(myType, myLibrariesConfigurable.getTree(), myProject, myLibrariesConfigurable.getModelProvider().getModifiableModel());
+ if (library == null) return;
+
+ final BaseLibrariesConfigurable rootConfigurable = ProjectStructureConfigurable.getInstance(myProject).getConfigurableFor(library);
+ final DefaultMutableTreeNode
+ libraryNode = MasterDetailsComponent.findNodeByObject((TreeNode)rootConfigurable.getTree().getModel().getRoot(), library);
+ rootConfigurable.selectNodeInTree(libraryNode);
+ LibraryEditingUtil.showDialogAndAddLibraryToDependencies(library, myProject, true);
+ }
}
diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java
index af88115801c4..0f44a9171846 100644
--- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java
+++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java
@@ -182,7 +182,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
highlight.run();
progress.checkCanceled();
HighlightingSession highlightingSession = HighlightingSessionImpl.getHighlightingSession(file, progress);
- PostHighlightingVisitor highlightingVisitor = new PostHighlightingVisitor(file, document, refCountHolder, highlightingSession);
+ PostHighlightingVisitor highlightingVisitor = new PostHighlightingVisitor(file, document, refCountHolder);
highlightingVisitor.collectHighlights(file, holder, progress);
}
});
diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/PostHighlightingVisitor.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/PostHighlightingVisitor.java
index 3f89ae26ff55..1d1644d7dfd5 100644
--- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/PostHighlightingVisitor.java
+++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/PostHighlightingVisitor.java
@@ -73,7 +73,6 @@ class PostHighlightingVisitor {
@NotNull private final Project myProject;
private final PsiFile myFile;
@NotNull private final Document myDocument;
- @NotNull private final HighlightingSession myHighlightingSession;
private boolean myHasRedundantImports;
private int myCurrentEntryIndex;
@@ -94,19 +93,19 @@ class PostHighlightingVisitor {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
- if (myProject.isDisposed() || !myFile.isValid()) return;
+ if (myProject.isDisposed() || !myFile.isValid() || !myFile.isWritable()) return;
IntentionAction optimizeImportsFix = QuickFixFactory.getInstance().createOptimizeImportsFix(true);
- if (optimizeImportsFix.isAvailable(myProject, null, myFile) && myFile.isWritable()) {
+ if (optimizeImportsFix.isAvailable(myProject, null, myFile)) {
optimizeImportsFix.invoke(myProject, null, myFile);
}
}
});
}
};
- Disposer.register(myHighlightingSession, invokeFixLater);
+ Disposer.register((DaemonProgressIndicator)progress, invokeFixLater);
if (progress.isCanceled()) {
Disposer.dispose(invokeFixLater);
- Disposer.dispose(myHighlightingSession);
+ Disposer.dispose((DaemonProgressIndicator)progress);
progress.checkCanceled();
}
}
@@ -114,9 +113,7 @@ class PostHighlightingVisitor {
PostHighlightingVisitor(@NotNull PsiFile file,
@NotNull Document document,
- @NotNull RefCountHolder refCountHolder,
- @NotNull HighlightingSession highlightingSession) throws ProcessCanceledException {
- myHighlightingSession = highlightingSession;
+ @NotNull RefCountHolder refCountHolder) throws ProcessCanceledException {
myProject = file.getProject();
myFile = file;
myDocument = document;
diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java
index 0ae52adb5325..ade25c7b1d5d 100644
--- a/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java
+++ b/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java
@@ -206,16 +206,15 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection
return false;
}
- public static PsiLambdaExpression replacePsiElementWithLambda(@NotNull PsiElement element, final boolean ignoreEqualsMethod) {
+ public static PsiExpression replacePsiElementWithLambda(@NotNull PsiElement element, final boolean ignoreEqualsMethod) {
if (element instanceof PsiNewExpression) {
if (!FileModificationService.getInstance().preparePsiElementForWrite(element)) return null;
final PsiAnonymousClass anonymousClass = ((PsiNewExpression)element).getAnonymousClass();
- LOG.assertTrue(anonymousClass != null);
+ if (anonymousClass == null) return null;
ChangeContextUtil.encodeContextInfo(anonymousClass, true);
final PsiElement lambdaContext = anonymousClass.getParent().getParent();
- boolean validContext = LambdaUtil.isValidLambdaContext(lambdaContext);
final String canonicalText = anonymousClass.getBaseClassType().getCanonicalText();
final PsiMethod method;
@@ -230,10 +229,10 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection
} else {
method = anonymousClass.getMethods()[0];
}
- LOG.assertTrue(method != null);
+ if (method == null) return null;
final PsiCodeBlock body = method.getBody();
- LOG.assertTrue(body != null);
+ if (body == null) return null;
final ForbiddenRefsChecker checker = new ForbiddenRefsChecker(method, anonymousClass);
body.accept(checker);
@@ -254,8 +253,7 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection
ReplaceWithLambdaFix
.giveUniqueNames(project, anonymousClass, elementFactory, body, conflictingLocals.toArray(new PsiVariable[conflictingLocals.size()]));
- final String lambdaWithTypesDeclared = ReplaceWithLambdaFix.composeLambdaText(method, true);
- final String withoutTypesDeclared = ReplaceWithLambdaFix.composeLambdaText(method, false);
+ final String withoutTypesDeclared = ReplaceWithLambdaFix.composeLambdaText(method);
PsiLambdaExpression lambdaExpression =
(PsiLambdaExpression)elementFactory.createExpressionFromText(withoutTypesDeclared, anonymousClass);
@@ -275,47 +273,24 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection
lambdaExpression.getBody().replace(singleExpr);
}
ChangeContextUtil.decodeContextInfo(lambdaExpression, null, null);
- if (!validContext) {
- final PsiParenthesizedExpression typeCast =
- (PsiParenthesizedExpression)elementFactory.createExpressionFromText("((" + canonicalText + ")" + withoutTypesDeclared + ")", lambdaExpression);
- final PsiExpression typeCastExpr = typeCast.getExpression();
- LOG.assertTrue(typeCastExpr != null);
- final PsiExpression typeCastOperand = ((PsiTypeCastExpression)typeCastExpr).getOperand();
- LOG.assertTrue(typeCastOperand != null);
- final PsiElement fromText = ((PsiLambdaExpression)typeCastOperand).getBody();
- LOG.assertTrue(fromText != null);
- lambdaBody = lambdaExpression.getBody();
- LOG.assertTrue(lambdaBody != null);
- fromText.replace(lambdaBody);
- lambdaExpression.replace(typeCast);
- return lambdaExpression;
- }
- PsiType interfaceType = lambdaExpression.getFunctionalInterfaceType();
- if (ReplaceWithLambdaFix.isInferred(lambdaExpression, interfaceType)) {
- final PsiLambdaExpression withTypes =
- (PsiLambdaExpression)elementFactory.createExpressionFromText(lambdaWithTypesDeclared, lambdaExpression);
- final PsiElement withTypesBody = withTypes.getBody();
- LOG.assertTrue(withTypesBody != null);
- lambdaBody = lambdaExpression.getBody();
- LOG.assertTrue(lambdaBody != null);
- withTypesBody.replace(lambdaBody);
- lambdaExpression = (PsiLambdaExpression)lambdaExpression.replace(withTypes);
-
- interfaceType = lambdaExpression.getFunctionalInterfaceType();
- if (ReplaceWithLambdaFix.isInferred(lambdaExpression, interfaceType)) {
- final PsiTypeCastExpression typeCast = (PsiTypeCastExpression)elementFactory.createExpressionFromText("(" + canonicalText + ")" + withoutTypesDeclared, lambdaExpression);
- final PsiExpression typeCastOperand = typeCast.getOperand();
- LOG.assertTrue(typeCastOperand instanceof PsiLambdaExpression);
- final PsiElement fromText = ((PsiLambdaExpression)typeCastOperand).getBody();
- LOG.assertTrue(fromText != null);
- lambdaBody = lambdaExpression.getBody();
- LOG.assertTrue(lambdaBody != null);
- fromText.replace(lambdaBody);
- lambdaExpression.replace(typeCast);
- }
+ PsiTypeCastExpression typeCast = (PsiTypeCastExpression)elementFactory
+ .createExpressionFromText("(" + canonicalText + ")" + withoutTypesDeclared, lambdaExpression);
+ final PsiExpression typeCastOperand = typeCast.getOperand();
+ LOG.assertTrue(typeCastOperand instanceof PsiLambdaExpression);
+ final PsiElement fromText = ((PsiLambdaExpression)typeCastOperand).getBody();
+ LOG.assertTrue(fromText != null);
+ lambdaBody = lambdaExpression.getBody();
+ LOG.assertTrue(lambdaBody != null);
+ fromText.replace(lambdaBody);
+ ((PsiLambdaExpression)typeCastOperand).getParameterList().replace(lambdaExpression.getParameterList());
+ typeCast = (PsiTypeCastExpression)lambdaExpression.replace(typeCast);
+ if (RedundantCastUtil.isCastRedundant(typeCast)) {
+ final PsiExpression operand = typeCast.getOperand();
+ LOG.assertTrue(operand != null);
+ return (PsiExpression)typeCast.replace(operand);
}
- return lambdaExpression;
+ return (PsiExpression)JavaCodeStyleManager.getInstance(project).shortenClassReferences(typeCast);
}
return null;
}
@@ -385,45 +360,32 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection
}
}
- private static boolean isInferred(PsiLambdaExpression lambdaExpression, PsiType interfaceType) {
- return interfaceType == null || !LambdaUtil.isLambdaFullyInferred(lambdaExpression, interfaceType) || !LambdaUtil.isFunctionalType(interfaceType);
- }
-
- private static String composeLambdaText(PsiMethod method, final boolean appendType) {
+ private static String composeLambdaText(PsiMethod method) {
final StringBuilder buf = new StringBuilder();
final PsiParameter[] parameters = method.getParameterList().getParameters();
- if (parameters.length != 1 || appendType) {
+ if (parameters.length != 1) {
buf.append("(");
}
buf.append(StringUtil.join(parameters,
new Function() {
@Override
public String fun(PsiParameter parameter) {
- return composeParameter(parameter, appendType);
+ return composeParameter(parameter);
}
}, ","));
- if (parameters.length != 1 || appendType) {
+ if (parameters.length != 1) {
buf.append(")");
}
buf.append("-> {}");
return buf.toString();
}
- private static String composeParameter(PsiParameter parameter,
- boolean appendType) {
- final String parameterType;
- if (appendType) {
- final PsiTypeElement typeElement = parameter.getTypeElement();
- parameterType = typeElement != null ? (typeElement.getText() + " ") : "";
- }
- else {
- parameterType = "";
- }
+ private static String composeParameter(PsiParameter parameter) {
String parameterName = parameter.getName();
if (parameterName == null) {
parameterName = "";
}
- return parameterType + parameterName;
+ return parameterName;
}
}
diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/LambdaCanBeMethodReferenceInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/LambdaCanBeMethodReferenceInspection.java
index 6b0b3b12928c..ff96f4025ca5 100644
--- a/java/java-analysis-impl/src/com/intellij/codeInspection/LambdaCanBeMethodReferenceInspection.java
+++ b/java/java-analysis-impl/src/com/intellij/codeInspection/LambdaCanBeMethodReferenceInspection.java
@@ -19,6 +19,8 @@ import com.intellij.codeInsight.FileModificationService;
import com.intellij.codeInsight.daemon.GroupNames;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Condition;
+import com.intellij.openapi.util.Conditions;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
@@ -217,7 +219,26 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp
}
private static boolean checkQualifier(PsiElement qualifier) {
- return !(qualifier instanceof PsiCallExpression);
+ if (qualifier == null) {
+ return true;
+ }
+ final Condition callExpressionCondition = Conditions.instanceOf(PsiCallExpression.class);
+ final Condition nonFinalFieldRefCondition = new Condition() {
+ @Override
+ public boolean value(PsiElement expression) {
+ if (expression instanceof PsiReferenceExpression) {
+ PsiElement element = ((PsiReferenceExpression)expression).resolve();
+ if (element instanceof PsiField && !((PsiField)element).hasModifierProperty(PsiModifier.FINAL)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ };
+ return SyntaxTraverser
+ .psiTraverser()
+ .withRoot(qualifier)
+ .filter(Conditions.or(callExpressionCondition, nonFinalFieldRefCondition)).toList().isEmpty();
}
@Nullable
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java b/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java
index 64a16addf3c3..4c81a4e2a87a 100644
--- a/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java
@@ -178,7 +178,7 @@ public class ConstructorInsertHandler implements InsertHandler implements Type
presentation.setIcon(DefaultLookupItemRenderer.getRawIcon(this, presentation.isReal()));
presentation.setStrikeout(JavaElementLookupRenderer.isToStrikeout(this));
- presentation.setItemTextBold(getAttribute(HIGHLIGHTED_ATTR) != null);
MemberLookupHelper helper = myHelper != null ? myHelper : new MemberLookupHelper(myMethod, myContainingClass, false, false);
final Boolean qualify = getAttribute(FORCE_QUALIFY) != null ? Boolean.TRUE : myHelper == null ? Boolean.FALSE : null;
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaPsiClassReferenceElement.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaPsiClassReferenceElement.java
index a5fcdadeaf06..6a4f29ec6020 100644
--- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaPsiClassReferenceElement.java
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaPsiClassReferenceElement.java
@@ -16,10 +16,7 @@
package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.TailType;
-import com.intellij.codeInsight.lookup.DefaultLookupItemRenderer;
-import com.intellij.codeInsight.lookup.LookupElementPresentation;
-import com.intellij.codeInsight.lookup.LookupItem;
-import com.intellij.codeInsight.lookup.PsiTypeLookupItem;
+import com.intellij.codeInsight.lookup.*;
import com.intellij.codeInsight.lookup.impl.JavaElementLookupRenderer;
import com.intellij.openapi.util.ClassConditionKey;
import com.intellij.openapi.util.Comparing;
@@ -41,7 +38,7 @@ import java.util.Set;
/**
* @author peter
*/
-public class JavaPsiClassReferenceElement extends LookupItem