Merge remote-tracking branch 'origin/master'

This commit is contained in:
Roman Shevchenko
2015-11-05 15:32:30 +01:00
37 changed files with 372 additions and 166 deletions
@@ -685,6 +685,11 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements
break;
}
}
if (myState.BUILD_PROCESS_HEAP_SIZE == DEFAULT_BUILD_PROCESS_HEAP_SIZE) {
final CompilerWorkspaceConfiguration workspace = CompilerWorkspaceConfiguration.getInstance(myProject);
// older version compatibility: as a fallback load this setting from workspace
myState.BUILD_PROCESS_HEAP_SIZE = workspace.COMPILER_PROCESS_HEAP_SIZE;
}
}
final Element notNullAssertions = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.ADD_NOTNULL_ASSERTIONS);
@@ -45,6 +45,11 @@ public class CompilerWorkspaceConfiguration implements PersistentStateComponent<
public boolean CLEAR_OUTPUT_DIRECTORY = true;
public boolean MAKE_PROJECT_ON_SAVE = false; // until we fix problems with several open projects (IDEA-104064), daemon slowness (IDEA-104666)
public boolean PARALLEL_COMPILATION = false;
/**
* @Deprecated. Use corresponding value from CompilerConfiguration
* This field is left here for compatibility with older projects
*/
public int COMPILER_PROCESS_HEAP_SIZE = 700;
public String COMPILER_PROCESS_ADDITIONAL_VM_OPTIONS = "";
public boolean REBUILD_ON_DEPENDENCY_CHANGE = true;
@@ -455,11 +455,11 @@ public class JavaCompletionSorting {
ContainerUtil.addIfNotNull(myExpectedClasses, PsiUtil.substituteTypeParameter(info.getDefaultType(), CommonClassNames.JAVA_LANG_CLASS, 0, false));
}
myExpectedMemberName = calcExpectedMemberName(position);
myExpectedMemberName = calcExpectedMemberNameByParentCall(position);
}
@Nullable
private static String calcExpectedMemberName(PsiElement position) {
private static String calcExpectedMemberNameByParentCall(PsiElement position) {
if (position.getParent() instanceof PsiJavaCodeReferenceElement) {
PsiElement grand = position.getParent().getParent();
if (grand instanceof PsiJavaCodeReferenceElement && ((PsiJavaCodeReferenceElement)grand).getQualifier() == position.getParent()) {
@@ -117,7 +117,7 @@ public class JavaTestFinder implements TestFinder {
for (String eachName : names) {
if (pattern.matcher(eachName).matches()) {
for (PsiClass eachClass : cache.getClassesByName(eachName, scope)) {
if (isTestClass(eachClass)) {
if (isTestClass(eachClass, klass)) {
if (!processor.process(Pair.create(eachClass, TestFinderHelper.calcTestNameProximity(klassName, eachName)))) {
return true;
}
@@ -128,9 +128,9 @@ public class JavaTestFinder implements TestFinder {
return false;
}
protected boolean isTestClass(PsiClass eachClass) {
protected boolean isTestClass(PsiClass eachClass, PsiClass klass) {
final TestFrameworks frameworks = TestFrameworks.getInstance();
return eachClass.isPhysical() && (frameworks.isTestClass(eachClass) || frameworks.isPotentialTestClass(eachClass));
return eachClass.isPhysical() && (frameworks.isTestClass(eachClass) || eachClass != klass && frameworks.isPotentialTestClass(eachClass));
}
@Nullable
@@ -301,7 +301,7 @@ public class InferenceIncorporationPhase {
if (!(sType instanceof PsiWildcardType) && !(tType instanceof PsiWildcardType) && sType != null && tType != null) {
addConstraint(new TypeEqualityConstraint(sType, tType));
}
return true;
return false;
}
}) != null;
}
@@ -0,0 +1,13 @@
interface I<T>{}
abstract class A<T> implements I<A<T>>{}
class Factory {
static <T extends A<?>> T get(Class<T> c){
return null;
}
}
class Impl extends A<Impl> {
static Impl get() {
return Factory.get(Impl.class);
}
}
@@ -311,6 +311,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
doTest();
}
public void testAcceptFirstPairOfCommonSupertypesDuringUpUpIncorporation() throws Exception {
doTest();
}
private void doTest() throws Exception {
doTest(false);
}
@@ -29,7 +29,6 @@ import com.intellij.refactoring.typeMigration.TypeConversionDescriptor;
import com.intellij.refactoring.typeMigration.TypeConversionDescriptorBase;
import com.intellij.refactoring.typeMigration.TypeMigrationLabeler;
import com.intellij.refactoring.typeMigration.rules.TypeConversionRule;
import com.intellij.util.Function;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
@@ -91,8 +90,6 @@ public class GuavaFluentIterableConversionRule extends BaseGuavaTypeConversionRu
}
static {
DESCRIPTORS_MAP.put("of", new TypeConversionDescriptorFactory("FluentIterable.of($arr$)", "java.util.Arrays.stream($arr$)", false, true, true));
DESCRIPTORS_MAP.put("isEmpty", new TypeConversionDescriptorFactory("$q$.isEmpty()", "$q$.findAny().isPresent()", false));
DESCRIPTORS_MAP.put("skip", new TypeConversionDescriptorFactory("$q$.skip($p$)", "$q$.skip($p$)", false, true, true));
DESCRIPTORS_MAP.put("limit", new TypeConversionDescriptorFactory("$q$.limit($p$)", "$q$.limit($p$)", false, true, true));
@@ -137,15 +134,26 @@ public class GuavaFluentIterableConversionRule extends BaseGuavaTypeConversionRu
TypeConversionDescriptor descriptorBase = null;
PsiType conversionType = null;
boolean needSpecifyType = true;
if (methodName.equals("from")) {
descriptorBase = new TypeConversionDescriptor("FluentIterable.from($it$)", null) {
if (methodName.equals("of")) {
descriptorBase = new TypeConversionDescriptor(null, "java.util.Arrays.stream($arr$)") {
@Override
public PsiExpression replace(PsiExpression expression) {
setStringToReplace((((PsiMethodCallExpression)expression).getMethodExpression().getQualifierExpression() != null
? "FluentIterable." : "") + "of($arr$)");
return super.replace(expression);
}
};
} else if (methodName.equals("from")) {
descriptorBase = new TypeConversionDescriptor(null, null) {
@Override
public PsiExpression replace(PsiExpression expression) {
final PsiMethodCallExpression methodCall = (PsiMethodCallExpression)expression;
PsiExpression argument =
PseudoLambdaReplaceTemplate.replaceTypeParameters(((PsiMethodCallExpression)expression).getArgumentList().getExpressions()[0]);
PseudoLambdaReplaceTemplate.replaceTypeParameters(methodCall.getArgumentList().getExpressions()[0]);
if (argument == null) {
return expression;
}
setStringToReplace((methodCall.getMethodExpression().getQualifierExpression() != null ? "FluentIterable." : "") + "from($it$)");
boolean isCollection =
InheritanceUtil.isInheritor(PsiTypesUtil.getPsiClass(argument.getType()), CommonClassNames.JAVA_UTIL_COLLECTION);
setReplaceByString(isCollection ? "$it$.stream()" : "java.util.stream.StreamSupport.stream($it$.spliterator(), false)");
@@ -212,7 +220,7 @@ public class GuavaFluentIterableConversionRule extends BaseGuavaTypeConversionRu
final TypeConversionDescriptor descriptor = base.create();
needSpecifyType = base.isChainedMethod();
if (needSpecifyType && !base.isFluentIterableReturnType()) {
conversionType = getTypeParametersAsText(GuavaOptionalConversionRule.JAVA_OPTIONAL, context.getType(), context);
conversionType = addTypeParameters(GuavaOptionalConversionRule.JAVA_OPTIONAL, context.getType(), context);
}
descriptorBase = descriptor;
}
@@ -220,7 +228,7 @@ public class GuavaFluentIterableConversionRule extends BaseGuavaTypeConversionRu
if (descriptorBase != null) {
if (needSpecifyType) {
if (conversionType == null) {
conversionType = getTypeParametersAsText(StreamApiConstants.JAVA_UTIL_STREAM_STREAM, context.getType(), context);
conversionType = addTypeParameters(StreamApiConstants.JAVA_UTIL_STREAM_STREAM, context.getType(), context);
}
descriptorBase.withConversionType(conversionType);
}
@@ -230,7 +238,7 @@ public class GuavaFluentIterableConversionRule extends BaseGuavaTypeConversionRu
}
@NotNull
private static PsiType getTypeParametersAsText(String baseClassQualifiedName, PsiType type, PsiElement context) {
private static PsiType addTypeParameters(String baseClassQualifiedName, PsiType type, PsiElement context) {
String parameterText = "";
if (type != null) {
final String canonicalText = type.getCanonicalText(false);
@@ -297,6 +305,10 @@ public class GuavaFluentIterableConversionRule extends BaseGuavaTypeConversionRu
}
break;
}
else if (qualifier instanceof PsiReferenceExpression && ((PsiReferenceExpression)qualifier).resolve() instanceof PsiVariable) {
labeler.migrateExpressionType(qualifier, addTypeParameters(StreamApiConstants.JAVA_UTIL_STREAM_STREAM, to, qualifier), qualifier.getParent(), false, false);
break;
}
else {
return null;
}
@@ -178,6 +178,14 @@ public class GuavaInspectionTest extends JavaCodeInsightFixtureTestCase {
doTest();
}
public void testFluentIterableWithStaticallyImportedFrom() {
doTest();
}
public void testTypeMigrationRootBackTraverse() {
doTest();
}
private void doTestNoQuickFixes(final Class<? extends IntentionAction>... quickFixesClasses) {
myFixture.configureByFile(getTestName(true) + ".java");
myFixture.enableInspections(new GuavaInspection());
@@ -0,0 +1,33 @@
import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import static com.google.common.collect.FluentIterable.from
import java.util.ArrayList;
import java.util.List;
class A {
Function<String, String> myFunction = new Function<String, String>() {
@Override
public String apply(String input) {
return input.trim();
}
};
List<String> main(String[] args) {
ArrayList<String> strings = new ArrayList<String>();
FluentIterable<String> i<caret>t = from(strings);
it = it.transform(input -> input.intern());
it = it.transform(String::trim);
it = it.transform(new Function<String, String>() {
@Override
public String apply(String input) {
System.out.println("do some action on " + input);
return input.substring(0, 10);
}
});
it = it.transform(myFunction);
return it.toList();
}
}
@@ -0,0 +1,32 @@
import com.google.common.base.Function;
import static com.google.common.collect.FluentIterable.from
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class A {
Function<String, String> myFunction = new Function<String, String>() {
@Override
public String apply(String input) {
return input.trim();
}
};
List<String> main(String[] args) {
ArrayList<String> strings = new ArrayList<String>();
Stream<String> it = strings.stream();
it = it.map(input -> input.intern());
it = it.map(String::trim);
it = it.map(input -> {
System.out.println("do some action on " + input);
return input.substring(0, 10);
});
it = it.map(myFunction::apply);
return it.collect(Collectors.toList());
}
}
@@ -1,4 +1,5 @@
import com.google.common.base.Optional;
import java.util.Collections;
class A {
@@ -1,3 +1,4 @@
import java.util.Collections;
import java.util.Optional;
class A {
@@ -0,0 +1,17 @@
import com.google.common.collect.FluentIterable;
import java.util.ArrayList;
public class MainFluentIterable {
FluentIter<caret>able<String> m2() {
FluentIterable<String> it = FluentIterable.from(new ArrayList<String>());
return it.transform(s -> s + s);
}
void m3() {
System.out.println((int) m2().size());
}
}
@@ -0,0 +1,16 @@
import java.util.ArrayList;
import java.util.stream.Stream;
public class MainFluentIterable {
Stream<String> m2() {
Stream<String> it = new ArrayList<String>().stream();
return it.map(s -> s + s);
}
void m3() {
System.out.println((int) (int) m2().count());
}
}
@@ -251,6 +251,8 @@ public class PerformanceWatcher implements ApplicationComponent {
return null;
}
checkMemoryUsage(file);
try {
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file));
try {
@@ -272,6 +274,17 @@ public class PerformanceWatcher implements ApplicationComponent {
return file;
}
private static void checkMemoryUsage(File file) {
final Runtime rt = Runtime.getRuntime();
final long allocatedMem = rt.totalMemory();
final long unusedMem = rt.freeMemory();
if (unusedMem < allocatedMem / 5) {
LOG.info("High memory usage (free " + (unusedMem / 1024 / 1024) +
" of " + (allocatedMem / 1024 / 1024) +
" MB) while dumping threads to " + file);
}
}
@SuppressWarnings("UseOfSystemOutOrSystemErr")
public static void dumpThreadsToConsole(String message) {
System.err.println(message);
@@ -100,8 +100,10 @@ class ResourceVersions implements PersistentStateComponent<ResourceVersions.Stat
return null;
}
@NotNull
private static String getId(@NotNull IdeaPluginDescriptor plugin) {
return plugin.isBundled() ? PluginManagerCore.CORE_PLUGIN_ID : plugin.getPluginId().getIdString();
PluginId pluginId = plugin.getPluginId();
return pluginId != null ? pluginId.getIdString() : PluginManagerCore.CORE_PLUGIN_ID;
}
@NotNull
@@ -5,9 +5,7 @@
<constraints>
<xy x="49" y="40" width="451" height="540"/>
</constraints>
<properties>
<preferredSize width="900" height="700"/>
</properties>
<properties/>
<border type="none"/>
<children>
<grid id="64782" binding="myFilter" custom-create="true" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
@@ -31,6 +31,7 @@ import com.intellij.ui.components.JBList;
import com.intellij.util.CatchingConsumer;
import com.intellij.util.Function;
import com.intellij.util.ObjectUtils;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.PlatformColors;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.update.UiNotifyConnector;
@@ -136,10 +137,10 @@ public class ManagePackagesDialog extends DialogWrapper {
.disableRemoveAction()
.addExtraAction(reloadButton)
.createPanel();
packagesPanel.setPreferredSize(new Dimension(400, -1));
packagesPanel.setMinimumSize(new Dimension(100, -1));
packagesPanel.setPreferredSize(new Dimension(JBUI.scale(400), -1));
packagesPanel.setMinimumSize(new Dimension(JBUI.scale(100), -1));
myPackages.setFixedCellWidth(0);
myPackages.setFixedCellHeight(22);
myPackages.setFixedCellHeight(JBUI.scale(22));
myPackages.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
mySplitPane.setLeftComponent(packagesPanel);
@@ -187,6 +188,7 @@ public class ManagePackagesDialog extends DialogWrapper {
else {
myInstallToUser.setVisible(false);
}
myMainPanel.setPreferredSize(new Dimension(JBUI.scale(900), JBUI.scale(700)));
}
public void selectPackage(@NotNull InstalledPackage pkg) {
@@ -60,7 +60,7 @@ public class KeyboardInternationalizationNotificationManager {
KeyboardSettingsExternalizable.getDisplayLanguageNameForComponent(recentFocusedWindow) + " language." +
"You can change this option in the settings of " + productName + " <a href='settings'>more...</a></html>";
String title = "Enable smart keyboard internalization for " + productName + ".";
String title = "Enable smart keyboard internationalization for " + productName + ".";
return new Notification(groupDisplayId, title,
text,
@@ -193,7 +193,7 @@ public class GeneralIdBasedToSMTRunnerEventsConvertor extends GeneralTestEventsP
if (node != null) {
SMTestProxy testProxy = node.getProxy();
testProxy.setDuration(testFinishedEvent.getDuration());
testProxy.setInputFilePath(testFinishedEvent.getOutputFile());
testProxy.setFrameworkOutputFile(testFinishedEvent.getOutputFile());
testProxy.setFinished();
fireOnTestFinished(testProxy);
terminateNode(node, State.FINISHED);
@@ -312,7 +312,7 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso
}
testProxy.setDuration(duration);
testProxy.setInputFilePath(testFinishedEvent.getOutputFile());
testProxy.setFrameworkOutputFile(testFinishedEvent.getOutputFile());
testProxy.setFinished();
myRunningTestsFullNameToProxy.remove(fullTestName);
myCurrentChildren.remove(testProxy);
@@ -410,8 +410,8 @@ public class OutputToGeneralTestEventsConverter implements ProcessOutputConsumer
duration = convertToLong(durationStr, testFinished);
}
TestFinishedEvent testFinishedEvent = new TestFinishedEvent(testFinished, duration);
testFinishedEvent.setOutputFile(testFinished.getAttributes().get(ATTR_KEY_TEST_OUTPUT_FILE));
TestFinishedEvent testFinishedEvent = new TestFinishedEvent(testFinished, duration,
testFinished.getAttributes().get(ATTR_KEY_TEST_OUTPUT_FILE));
fireOnTestFinished(testFinishedEvent);
}
@@ -22,15 +22,24 @@ import org.jetbrains.annotations.Nullable;
public class TestFinishedEvent extends TreeNodeEvent {
private final long myDuration;
private String myOutputFile;
private final String myOutputFile;
public TestFinishedEvent(@NotNull TestFinished testFinished, long duration) {
this(testFinished.getTestName(), TreeNodeEvent.getNodeId(testFinished), duration);
this(testFinished, duration, null);
}
public TestFinishedEvent(@NotNull TestFinished testFinished, long duration, String outputFile) {
this(testFinished.getTestName(), TreeNodeEvent.getNodeId(testFinished), duration, outputFile);
}
public TestFinishedEvent(@Nullable String name, int id, long duration) {
this(name, id, duration, null);
}
public TestFinishedEvent(@Nullable String name, int id, long duration, String outputFile) {
super(name, id);
myDuration = duration;
myOutputFile = outputFile;
}
public TestFinishedEvent(@NotNull String name, long duration) {
@@ -52,10 +61,6 @@ public class TestFinishedEvent extends TreeNodeEvent {
append(buf, "duration", myDuration);
}
public void setOutputFile(String outputFile) {
myOutputFile = outputFile;
}
public String getOutputFile() {
return myOutputFile;
}
@@ -40,7 +40,7 @@ public class CompositePrintable implements Printable, Disposable {
protected int myExceptionMark;
private int myCurrentSize = 0;
private String myOutputFile = null;
private String myInputFile;
private String myFrameworkOutputFile;
private static final Alarm myAlarm = new Alarm(Alarm.ThreadToUse.SHARED_THREAD);
public void flush() {
@@ -135,15 +135,15 @@ public class CompositePrintable implements Printable, Disposable {
myOutputFile = outputFile;
}
public void setInputFilePath(String inputFilePath) {
myInputFile = inputFilePath;
public void setFrameworkOutputFile(String frameworkOutputFile) {
myFrameworkOutputFile = frameworkOutputFile;
}
public void printFromInputFile(final Printer console) {
if (myInputFile != null) {
public void printFromFrameworkOutputFile(final Printer console) {
if (myFrameworkOutputFile != null) {
final Runnable runnable = new Runnable() {
public void run() {
final File inputFile = new File(myInputFile);
final File inputFile = new File(myFrameworkOutputFile);
if (inputFile.exists()) {
try {
final String fileText = FileUtil.loadFile(inputFile);
@@ -110,7 +110,7 @@ public class TestsOutputConsolePrinter implements Printer, Disposable {
final AbstractTestProxy currentProxyOrRoot = getCurrentProxyOrRoot();
CompositePrintable.invokeInAlarm(clearRunnable);
currentProxyOrRoot.printOn(this);
currentProxyOrRoot.printFromInputFile(this);
currentProxyOrRoot.printFromFrameworkOutputFile(this);
CompositePrintable.invokeInAlarm(scrollRunnable);
}
@@ -41,38 +41,38 @@ public class VcsBalloonProblemNotifier implements Runnable {
private final Project myProject;
private final String myMessage;
private final MessageType myMessageType;
private final boolean myShowOverChangesView;
@Nullable private final NamedRunnable[] myNotificationListener;
public VcsBalloonProblemNotifier(@NotNull final Project project, @NotNull final String message, final MessageType messageType) {
this(project, message, messageType, true, null);
this(project, message, messageType, null);
}
public VcsBalloonProblemNotifier(@NotNull final Project project, @NotNull final String message, final MessageType messageType, boolean showOverChangesView,
public VcsBalloonProblemNotifier(@NotNull final Project project,
@NotNull final String message,
final MessageType messageType,
@Nullable final NamedRunnable[] notificationListener) {
myProject = project;
myMessage = message;
myMessageType = messageType;
myShowOverChangesView = showOverChangesView;
myNotificationListener = notificationListener;
}
public static void showOverChangesView(@NotNull final Project project, @NotNull final String message, final MessageType type,
final NamedRunnable... notificationListener) {
show(project, message, type, true, notificationListener);
show(project, message, type, notificationListener);
}
public static void showOverVersionControlView(@NotNull final Project project, @NotNull final String message, final MessageType type) {
show(project, message, type, false, null);
show(project, message, type, null);
}
private static void show(final Project project, final String message, final MessageType type, final boolean showOverChangesView,
private static void show(final Project project, final String message, final MessageType type,
@Nullable final NamedRunnable[] notificationListener) {
final Application application = ApplicationManager.getApplication();
if (application.isHeadlessEnvironment()) return;
final Runnable showErrorAction = new Runnable() {
public void run() {
new VcsBalloonProblemNotifier(project, message, type, showOverChangesView, notificationListener).run();
new VcsBalloonProblemNotifier(project, message, type, notificationListener).run();
}
};
if (application.isDispatchThread()) {
+12 -13
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@ import com.intellij.openapi.keymap.KeymapUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiNameHelper;
import com.intellij.ui.ColoredListCellRenderer;
@@ -78,7 +77,7 @@ public class NewActionDialog extends DialogWrapper implements ActionData {
private Project myProject;
private ButtonGroup myAnchorButtonGroup;
public NewActionDialog(PsiClass actionClass) {
public NewActionDialog(@NotNull PsiClass actionClass) {
this(actionClass.getProject());
myActionNameEdit.setText(actionClass.getQualifiedName());
@@ -89,18 +88,18 @@ public class NewActionDialog extends DialogWrapper implements ActionData {
}
}
protected NewActionDialog(final Project project) {
protected NewActionDialog(Project project) {
super(project, false);
myProject = project;
init();
setTitle(DevKitBundle.message("new.action.dialog.title"));
final ActionManager actionManager = ActionManager.getInstance();
final String[] actionIds = actionManager.getActionIds("");
String[] actionIds = actionManager.getActionIds("");
Arrays.sort(actionIds);
final List<ActionGroup> actionGroups = new ArrayList<ActionGroup>();
List<ActionGroup> actionGroups = new ArrayList<ActionGroup>();
for(String actionId: actionIds) {
if (actionManager.isGroup(actionId)) {
final AnAction anAction = actionManager.getAction(actionId);
AnAction anAction = actionManager.getAction(actionId);
if (anAction instanceof DefaultActionGroup) {
actionGroups.add((ActionGroup) anAction);
}
@@ -115,7 +114,7 @@ public class NewActionDialog extends DialogWrapper implements ActionData {
myActionList.setListData(ArrayUtil.EMPTY_OBJECT_ARRAY);
}
else {
final AnAction[] actions = group.getChildren(null);
AnAction[] actions = group.getChildren(null);
// filter out actions that don't have IDs - they can't be used for anchoring in plugin.xml
List<AnAction> realActions = new ArrayList<AnAction>();
for(AnAction action: actions) {
@@ -128,7 +127,7 @@ public class NewActionDialog extends DialogWrapper implements ActionData {
}
});
new ListSpeedSearch(myGroupList, new Function<Object, String>() {
public String fun(final Object o) {
public String fun(Object o) {
return ActionManager.getInstance().getId((AnAction) o);
}
});
@@ -140,7 +139,7 @@ public class NewActionDialog extends DialogWrapper implements ActionData {
}
});
final MyDocumentListener listener = new MyDocumentListener();
MyDocumentListener listener = new MyDocumentListener();
myActionIdEdit.getDocument().addDocumentListener(listener);
myActionNameEdit.getDocument().addDocumentListener(listener);
myActionTextEdit.getDocument().addDocumentListener(listener);
@@ -158,8 +157,8 @@ public class NewActionDialog extends DialogWrapper implements ActionData {
myFirstKeystrokeEdit.getDocument().addDocumentListener(listener);
myClearFirstKeystroke.setText(null);
final Icon icon = AllIcons.Actions.Cancel;
final Dimension size = new Dimension(icon.getIconWidth(), icon.getIconHeight());
Icon icon = AllIcons.Actions.Cancel;
Dimension size = new Dimension(icon.getIconWidth(), icon.getIconHeight());
myClearFirstKeystroke.setIcon(icon);
myClearFirstKeystroke.setPreferredSize(size);
myClearFirstKeystroke.setMaximumSize(size);
@@ -266,7 +265,7 @@ public class NewActionDialog extends DialogWrapper implements ActionData {
protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
AnAction group = (AnAction) value;
append(ActionManager.getInstance().getId(group), SimpleTextAttributes.REGULAR_ATTRIBUTES);
final String text = group.getTemplatePresentation().getText();
String text = group.getTemplatePresentation().getText();
if (text != null) {
append(" (" + text + ")", SimpleTextAttributes.REGULAR_ATTRIBUTES);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -40,9 +40,6 @@ import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
/**
* @author swr
*/
public class ComponentNotRegisteredInspection extends DevKitInspectionBase {
public boolean CHECK_ACTIONS = true;
public boolean IGNORE_NON_PUBLIC = true;
@@ -65,7 +62,7 @@ public class ComponentNotRegisteredInspection extends DevKitInspectionBase {
@Nullable
public JComponent createOptionsPanel() {
final JPanel jPanel = new JPanel();
JPanel jPanel = new JPanel();
jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
final JCheckBox ignoreNonPublic = new JCheckBox(
@@ -82,7 +79,7 @@ public class ComponentNotRegisteredInspection extends DevKitInspectionBase {
CHECK_ACTIONS);
checkJavaActions.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
final boolean selected = checkJavaActions.isSelected();
boolean selected = checkJavaActions.isSelected();
CHECK_ACTIONS = selected;
ignoreNonPublic.setEnabled(selected);
}
@@ -95,8 +92,8 @@ public class ComponentNotRegisteredInspection extends DevKitInspectionBase {
@Nullable
public ProblemDescriptor[] checkClass(@NotNull PsiClass checkedClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
final PsiFile psiFile = checkedClass.getContainingFile();
final PsiIdentifier classIdentifier = checkedClass.getNameIdentifier();
PsiFile psiFile = checkedClass.getContainingFile();
PsiIdentifier classIdentifier = checkedClass.getNameIdentifier();
if (checkedClass.getQualifiedName() != null &&
classIdentifier != null &&
psiFile != null &&
@@ -108,11 +105,11 @@ public class ComponentNotRegisteredInspection extends DevKitInspectionBase {
return null;
}
final PsiManager psiManager = checkedClass.getManager();
final GlobalSearchScope scope = checkedClass.getResolveScope();
PsiManager psiManager = checkedClass.getManager();
GlobalSearchScope scope = checkedClass.getResolveScope();
if (CHECK_ACTIONS) {
final PsiClass actionClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(AnAction.class.getName(), scope);
PsiClass actionClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(AnAction.class.getName(), scope);
if (actionClass == null) {
// stop if action class cannot be found (non-devkit module/project)
return null;
@@ -122,8 +119,8 @@ public class ComponentNotRegisteredInspection extends DevKitInspectionBase {
return null;
}
if (!isActionRegistered(checkedClass) && canFix(checkedClass)) {
final LocalQuickFix fix = new RegisterActionFix(checkedClass);
final ProblemDescriptor problem = manager.createProblemDescriptor(
LocalQuickFix fix = new RegisterActionFix(org.jetbrains.idea.devkit.util.PsiUtil.createPointer(checkedClass));
ProblemDescriptor problem = manager.createProblemDescriptor(
classIdentifier,
DevKitBundle.message("inspections.component.not.registered.message",
DevKitBundle.message("new.menu.action.text")),
@@ -136,17 +133,17 @@ public class ComponentNotRegisteredInspection extends DevKitInspectionBase {
}
}
final ComponentType[] types = ComponentType.values();
ComponentType[] types = ComponentType.values();
for (ComponentType type : types) {
final PsiClass compClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(type.myClassName, scope);
PsiClass compClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(type.myClassName, scope);
if (compClass == null) {
// stop if component classes cannot be found (non-devkit module/project)
return null;
}
if (checkedClass.isInheritor(compClass, true)) {
if (getRegistrationTypes(checkedClass, false) == null && canFix(checkedClass)) {
final LocalQuickFix fix = new RegisterComponentFix(type, checkedClass);
final ProblemDescriptor problem = manager.createProblemDescriptor(classIdentifier,
LocalQuickFix fix = new RegisterComponentFix(type, org.jetbrains.idea.devkit.util.PsiUtil.createPointer(checkedClass));
ProblemDescriptor problem = manager.createProblemDescriptor(classIdentifier,
DevKitBundle.message("inspections.component.not.registered.message",
DevKitBundle.message(type.myPropertyKey)),
fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly);
@@ -162,10 +159,10 @@ public class ComponentNotRegisteredInspection extends DevKitInspectionBase {
}
private static boolean canFix(PsiClass psiClass) {
final Project project = psiClass.getProject();
final PsiFile psiFile = psiClass.getContainingFile();
Project project = psiClass.getProject();
PsiFile psiFile = psiClass.getContainingFile();
LOG.assertTrue(psiFile != null);
final Module module = ModuleUtilCore.findModuleForFile(psiFile.getVirtualFile(), project);
Module module = ModuleUtilCore.findModuleForFile(psiFile.getVirtualFile(), project);
return PluginModuleType.isPluginModuleOrDependency(module);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiFile;
import com.intellij.psi.SmartPsiElementPointer;
import com.intellij.psi.xml.XmlFile;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NonNls;
@@ -38,11 +39,11 @@ import org.jetbrains.idea.devkit.util.DescriptorUtil;
import java.util.List;
abstract class AbstractRegisterFix implements LocalQuickFix, DescriptorUtil.Patcher {
protected final PsiClass myClass;
private static final Logger LOG = Logger.getInstance("org.jetbrains.idea.devkit.inspections.quickfix.AbstractRegisterFix");
protected final SmartPsiElementPointer<PsiClass> myPointer;
protected static final Logger LOG = Logger.getInstance(AbstractRegisterFix.class);
public AbstractRegisterFix(PsiClass klass) {
myClass = klass;
public AbstractRegisterFix(@NotNull SmartPsiElementPointer<PsiClass> klass) {
myPointer = klass;
}
@NotNull
@@ -60,7 +61,7 @@ abstract class AbstractRegisterFix implements LocalQuickFix, DescriptorUtil.Patc
// copy of com.intellij.ide.actions.CreateElementActionBase.filterMessage()
protected static String filterMessage(String message) {
if (message == null) return null;
@NonNls final String ioExceptionPrefix = "java.io.IOException:";
@NonNls String ioExceptionPrefix = "java.io.IOException:";
if (message.startsWith(ioExceptionPrefix)) {
message = message.substring(ioExceptionPrefix.length());
}
@@ -69,7 +70,12 @@ abstract class AbstractRegisterFix implements LocalQuickFix, DescriptorUtil.Patc
public void applyFix(@NotNull final Project project, @NotNull ProblemDescriptor descriptor) {
if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.getPsiElement())) return;
final PsiFile psiFile = myClass.getContainingFile();
PsiFile psiFile = myPointer.getContainingFile();
final PsiClass element = myPointer.getElement();
if (element == null) {
LOG.info("Element is null for PsiPointer: " + myPointer);
return;
}
LOG.assertTrue(psiFile != null);
final Module module = ModuleUtil.findModuleForFile(psiFile.getVirtualFile(), project);
assert module != null;
@@ -78,26 +84,26 @@ abstract class AbstractRegisterFix implements LocalQuickFix, DescriptorUtil.Patc
public void run() {
try {
if (PluginModuleType.isOfType(module)) {
final XmlFile pluginXml = PluginModuleType.getPluginXml(module);
XmlFile pluginXml = PluginModuleType.getPluginXml(module);
if (pluginXml != null) {
DescriptorUtil.patchPluginXml(AbstractRegisterFix.this, myClass, pluginXml);
DescriptorUtil.patchPluginXml(AbstractRegisterFix.this, element, pluginXml);
}
}
else {
List<Module> modules = PluginModuleType.getCandidateModules(module);
if (modules.size() > 1) {
final ChooseModulesDialog dialog = new ChooseModulesDialog(project, modules, getName());
ChooseModulesDialog dialog = new ChooseModulesDialog(project, modules, getName());
if (!dialog.showAndGet()) {
return;
}
modules = dialog.getSelectedModules();
}
final XmlFile[] pluginXmls = new XmlFile[modules.size()];
XmlFile[] pluginXmls = new XmlFile[modules.size()];
for (int i = 0; i < pluginXmls.length; i++) {
pluginXmls[i] = PluginModuleType.getPluginXml(modules.get(i));
}
DescriptorUtil.patchPluginXml(AbstractRegisterFix.this, myClass, pluginXmls);
DescriptorUtil.patchPluginXml(AbstractRegisterFix.this, element, pluginXmls);
}
CommandProcessor.getInstance().markCurrentCommandAsGlobal(project);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,43 +24,42 @@ import com.intellij.openapi.vfs.ReadonlyStatusHandler;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.SmartPsiElementPointer;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.idea.devkit.DevKitBundle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.devkit.DevKitBundle;
/**
* @author swr
*/
abstract class BaseFix implements LocalQuickFix {
protected final PsiElement myElement;
protected final SmartPsiElementPointer<? extends PsiElement> myPointer;
protected final boolean myOnTheFly;
protected BaseFix(PsiElement element, boolean onTheFly) {
myElement = element;
protected BaseFix(@NotNull SmartPsiElementPointer<? extends PsiElement> pointer, boolean onTheFly) {
myPointer = pointer;
myOnTheFly = onTheFly;
}
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
// can happen during batch-inspection if resolution has already been applied
// to plugin.xml or java class
if (!myElement.isValid()) return;
PsiElement element = myPointer.getElement();
if (element == null || !element.isValid()) return;
final boolean external = descriptor.getPsiElement().getContainingFile() != myElement.getContainingFile();
boolean external = descriptor.getPsiElement().getContainingFile() != element.getContainingFile();
if (external) {
final PsiClass clazz = PsiTreeUtil.getParentOfType(myElement, PsiClass.class, false);
final ReadonlyStatusHandler readonlyStatusHandler = ReadonlyStatusHandler.getInstance(project);
final VirtualFile[] files = new VirtualFile[]{myElement.getContainingFile().getVirtualFile()};
final ReadonlyStatusHandler.OperationStatus status = readonlyStatusHandler.ensureFilesWritable(files);
PsiClass clazz = PsiTreeUtil.getParentOfType(element, PsiClass.class, false);
ReadonlyStatusHandler readonlyStatusHandler = ReadonlyStatusHandler.getInstance(project);
VirtualFile[] files = new VirtualFile[]{element.getContainingFile().getVirtualFile()};
ReadonlyStatusHandler.OperationStatus status = readonlyStatusHandler.ensureFilesWritable(files);
if (status.hasReadonlyFiles()) {
final String className = clazz != null ? clazz.getQualifiedName() : myElement.getContainingFile().getName();
String className = clazz != null ? clazz.getQualifiedName() : element.getContainingFile().getName();
Messages.showMessageDialog(project,
DevKitBundle.message("inspections.registration.problems.quickfix.read-only",
className),
getName(),
Messages.getErrorIcon());
DevKitBundle.message("inspections.registration.problems.quickfix.read-only",
className),
getName(),
Messages.getErrorIcon());
return;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,22 +17,17 @@ package org.jetbrains.idea.devkit.inspections.quickfix;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiModifier;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.devkit.DevKitBundle;
/**
* @author swr
*/
public class CreateConstructorFix extends BaseFix {
import static org.jetbrains.idea.devkit.util.PsiUtil.createPointer;
public CreateConstructorFix(PsiClass checkedClass, boolean onTheFly) {
super(checkedClass, onTheFly);
public class CreateConstructorFix extends BaseFix {
public CreateConstructorFix(@NotNull PsiClass aClass, boolean isOnTheFly) {
super(createPointer(aClass), isOnTheFly);
}
@NotNull
@@ -46,12 +41,14 @@ public class CreateConstructorFix extends BaseFix {
}
protected void doFix(Project project, ProblemDescriptor descriptor, boolean external) throws IncorrectOperationException {
final PsiClass clazz = (PsiClass)myElement;
PsiElement element = myPointer.getElement();
if (!(element instanceof PsiClass)) return;
PsiClass clazz = (PsiClass)element;
PsiMethod ctor = JavaPsiFacade.getInstance(clazz.getProject()).getElementFactory().createConstructor();
PsiUtil.setModifierProperty(ctor, PsiModifier.PUBLIC, true);
final PsiMethod[] constructors = clazz.getConstructors();
PsiMethod[] constructors = clazz.getConstructors();
if (constructors.length > 0) {
ctor = (PsiMethod)clazz.addBefore(ctor, constructors[0]);
} else {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,32 +25,35 @@ import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.devkit.DevKitBundle;
/**
* @author swr
*/
import static org.jetbrains.idea.devkit.util.PsiUtil.createPointer;
public class ImplementOrExtendFix extends BaseFix {
private final SmartPsiElementPointer<PsiClass> myCompClassPointer;
private final PsiClass myCompClass;
private ImplementOrExtendFix(PsiClass compClass, PsiClass checkedClass, boolean onTheFly) {
super(checkedClass, onTheFly);
myCompClass = compClass;
private ImplementOrExtendFix(@NotNull PsiClass compClass,
@NotNull PsiClass checkedClass,
boolean onTheFly) {
super(createPointer(checkedClass), onTheFly);
myCompClassPointer = createPointer(compClass);
}
@NotNull
public static LocalQuickFix[] createFix(PsiClass compClass, PsiClass checkedClass, boolean onTheFly) {
ImplementOrExtendFix fix = null;
if (compClass.isInterface() && compClass.getImplementsList() != null) {
fix = new ImplementOrExtendFix(compClass, checkedClass, onTheFly);
} else if (!compClass.isInterface()) {
final PsiReferenceList extendsList = checkedClass.getExtendsList();
}
else if (!compClass.isInterface()) {
PsiReferenceList extendsList = checkedClass.getExtendsList();
if (extendsList != null) {
if (extendsList.getReferenceElements().length == 0) {
fix = new ImplementOrExtendFix(compClass, checkedClass, onTheFly);
} else if (extendsList.getReferenceElements().length == 1) {
}
else if (extendsList.getReferenceElements().length == 1) {
// check for explicit "extends Object" case
final PsiClassType javaLangObject = PsiType.getJavaLangObject(checkedClass.getManager(),
checkedClass.getResolveScope());
PsiClassType javaLangObject = PsiType.getJavaLangObject(checkedClass.getManager(),
checkedClass.getResolveScope());
if (extendsList.getReferencedTypes()[0].equals(javaLangObject)) {
fix = new ImplementOrExtendFix(compClass, checkedClass, onTheFly);
}
@@ -62,10 +65,12 @@ public class ImplementOrExtendFix extends BaseFix {
@NotNull
public String getName() {
return (myCompClass.isInterface()
PsiClass clazz = myCompClassPointer.getElement();
if (clazz == null) return "Invalid";
return (clazz.isInterface()
? StringUtil.capitalize(DevKitBundle.message("keyword.implement"))
: StringUtil.capitalize(DevKitBundle.message("keyword.extend")))
+ " '" + myCompClass.getQualifiedName() + "'";
+ " '" + clazz.getQualifiedName() + "'";
}
@NotNull
@@ -74,16 +79,21 @@ public class ImplementOrExtendFix extends BaseFix {
}
protected void doFix(Project project, ProblemDescriptor descriptor, boolean external) throws IncorrectOperationException {
final PsiClass clazz = (PsiClass)myElement;
final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(clazz.getProject()).getElementFactory();
final PsiClassType compType = elementFactory.createType(myCompClass);
PsiElement element = myPointer.getElement();
PsiClass compClass = myCompClassPointer.getElement();
if (!(element instanceof PsiClass)) return;
if (compClass == null) return;
PsiClass clazz = (PsiClass)element;
PsiElementFactory elementFactory = JavaPsiFacade.getInstance(clazz.getProject()).getElementFactory();
PsiClassType compType = elementFactory.createType(compClass);
final PsiReferenceList list;
if (myCompClass.isInterface()) {
PsiReferenceList list;
if (compClass.isInterface()) {
list = clazz.getImplementsList();
assert list != null;
} else {
final PsiReferenceList extendsList = clazz.getExtendsList();
}
else {
PsiReferenceList extendsList = clazz.getExtendsList();
assert extendsList != null;
if (extendsList.getReferencedTypes().length > 0) {
extendsList.getReferenceElements()[0].delete();
@@ -91,7 +101,7 @@ public class ImplementOrExtendFix extends BaseFix {
list = extendsList;
}
final PsiElement e = list.add(elementFactory.createReferenceElementByType(compType));
PsiElement e = list.add(elementFactory.createReferenceElementByType(compType));
if (myOnTheFly && external && e instanceof Navigatable) ((Navigatable)e).navigate(true);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@ import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiClass;
import com.intellij.psi.SmartPsiElementPointer;
import com.intellij.psi.xml.XmlFile;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
@@ -31,8 +32,8 @@ import org.jetbrains.idea.devkit.util.ActionType;
public class RegisterActionFix extends AbstractRegisterFix {
private NewActionDialog myDialog;
public RegisterActionFix(PsiClass klass) {
super(klass);
public RegisterActionFix(@NotNull SmartPsiElementPointer<PsiClass> pointer) {
super(pointer);
}
protected String getType() {
@@ -46,7 +47,12 @@ public class RegisterActionFix extends AbstractRegisterFix {
}
try {
myDialog = new NewActionDialog(myClass);
PsiClass element = myPointer.getElement();
if (element == null) {
LOG.info("Element is null for PsiPointer: " + myPointer);
return;
}
myDialog = new NewActionDialog(element);
if (myDialog.showAndGet()) {
super.applyFix(project, descriptor);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -16,16 +16,18 @@
package org.jetbrains.idea.devkit.inspections.quickfix;
import com.intellij.psi.PsiClass;
import com.intellij.psi.SmartPsiElementPointer;
import com.intellij.psi.xml.XmlFile;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.devkit.DevKitBundle;
import org.jetbrains.idea.devkit.util.ComponentType;
public class RegisterComponentFix extends AbstractRegisterFix {
private final ComponentType myType;
public RegisterComponentFix(ComponentType type, PsiClass klass) {
super(klass);
public RegisterComponentFix(ComponentType type, @NotNull SmartPsiElementPointer<PsiClass> pointer) {
super(pointer);
myType = type;
}
+14 -9
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -39,12 +39,12 @@ public class PsiUtil {
private PsiUtil() { }
public static boolean isInstantiable(@NotNull PsiClass cls) {
final PsiModifierList modList = cls.getModifierList();
PsiModifierList modList = cls.getModifierList();
if (modList == null || cls.isInterface() || modList.hasModifierProperty(PsiModifier.ABSTRACT) || !isPublicOrStaticInnerClass(cls)) {
return false;
}
final PsiMethod[] constructors = cls.getConstructors();
PsiMethod[] constructors = cls.getConstructors();
if (constructors.length == 0) return true;
for (PsiMethod constructor : constructors) {
@@ -57,7 +57,7 @@ public class PsiUtil {
}
public static boolean isPublicOrStaticInnerClass(@NotNull PsiClass cls) {
final PsiModifierList modifiers = cls.getModifierList();
PsiModifierList modifiers = cls.getModifierList();
if (modifiers == null) return false;
return modifiers.hasModifierProperty(PsiModifier.PUBLIC) &&
@@ -66,9 +66,9 @@ public class PsiUtil {
@Nullable
public static String getReturnedLiteral(PsiMethod method, PsiClass cls) {
final PsiExpression value = getReturnedExpression(method);
PsiExpression value = getReturnedExpression(method);
if (value instanceof PsiLiteralExpression) {
final Object str = ((PsiLiteralExpression)value).getValue();
Object str = ((PsiLiteralExpression)value).getValue();
return str == null ? null : str.toString();
}
else if (value instanceof PsiMethodCallExpression) {
@@ -95,11 +95,11 @@ public class PsiUtil {
if (body != null) {
PsiStatement[] statements = body.getStatements();
if (statements.length == 1 && statements[0] instanceof PsiReturnStatement) {
final PsiExpression value = ((PsiReturnStatement)statements[0]).getReturnValue();
PsiExpression value = ((PsiReturnStatement)statements[0]).getReturnValue();
if (value instanceof PsiReferenceExpression) {
final PsiElement element = ((PsiReferenceExpression)value).resolve();
PsiElement element = ((PsiReferenceExpression)value).resolve();
if (element instanceof PsiField) {
final PsiField field = (PsiField)element;
PsiField field = (PsiField)element;
if (field.hasModifierProperty(PsiModifier.FINAL)) {
return field.getInitializer();
}
@@ -183,4 +183,9 @@ public class PsiUtil {
return true;
}
@NotNull
public static <E extends PsiElement> SmartPsiElementPointer<E> createPointer(@NotNull E e) {
return SmartPointerManager.getInstance(e.getProject()).createSmartPsiElementPointer(e);
}
}
@@ -39,6 +39,7 @@ import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
@@ -569,13 +570,30 @@ public class MavenProjectsManager extends MavenSimpleProjectComponent
myWatcher.resetManagedFilesAndProfilesInTests(files, profiles);
}
public void addManagedFilesWithProfiles(List<VirtualFile> files, MavenExplicitProfiles profiles) {
public void addManagedFilesWithProfiles(final List<VirtualFile> files, MavenExplicitProfiles profiles) {
if (!isInitialized()) {
initNew(files, profiles);
}
else {
myWatcher.addManagedFilesWithProfiles(files, profiles);
}
MavenUtil.invokeLater(myProject, new Runnable() {
@Override
public void run() {
if (myProject == null || !myProject.isDefault() && !myProject.isDisposed()) {
for (Notification notification : EventLog.getLogModel(myProject).getNotifications()) {
if (NON_MANAGED_POM_NOTIFICATION_GROUP_ID.equals(notification.getGroupId())) {
for (VirtualFile file : files) {
if (StringUtil.startsWith(notification.getContent(), file.getPresentableUrl())) {
notification.expire();
}
}
}
}
}
}
});
}
public void addManagedFiles(@NotNull List<VirtualFile> files) {