mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
Generated
+3
@@ -5,6 +5,7 @@
|
||||
</component>
|
||||
<component name="CompilerConfiguration">
|
||||
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||
<option name="BUILD_PROCESS_HEAP_SIZE" value="1100" />
|
||||
<excludeFromCompile>
|
||||
<file url="file://$PROJECT_DIR$/jps/jps-builders/src/org/jetbrains/jps/incremental/java/OptimizedFileManager.java" />
|
||||
<file url="file://$PROJECT_DIR$/jps/jps-builders/src/org/jetbrains/jps/javac/OptimizedFileManager.java" />
|
||||
@@ -34,6 +35,7 @@
|
||||
<module name="annotations-common" target="1.5" />
|
||||
<module name="annotations-java8" target="1.8" />
|
||||
<module name="community-tests" target="1.8" />
|
||||
<module name="configuration-store-tests" target="1.8" />
|
||||
<module name="gradle-jps-plugin" target="1.6" />
|
||||
<module name="groovy-rt-constants" target="1.5" />
|
||||
<module name="groovy_rt" target="1.5" />
|
||||
@@ -53,6 +55,7 @@
|
||||
<module name="junit_rt" target="1.3" />
|
||||
<module name="maven-jps-plugin" target="1.6" />
|
||||
<module name="remote-servers-agent-rt" target="1.5" />
|
||||
<module name="settings-repository-tests" target="1.8" />
|
||||
<module name="svn4idea-tests" target="1.8" />
|
||||
<module name="tasks-tests" target="1.8" />
|
||||
<module name="testng_rt" target="1.5" />
|
||||
|
||||
Generated
-3
@@ -2,15 +2,12 @@
|
||||
<library name="assertJ">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/dev/assertj-core-2.1.0.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/lib/dev/assertj-guava-2.0.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$PROJECT_DIR$/lib/dev/assertj-core-2.1.0-javadoc.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/lib/dev/assertj-guava-2.0.0-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/dev/assertj-core-2.1.0-sources.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/lib/dev/assertj-guava-2.0.0-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
Generated
+11
@@ -0,0 +1,11 @@
|
||||
<component name="libraryTable">
|
||||
<library name="hamcrest">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/hamcrest-library-1.3.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/src/hamcrest-1.3-src.zip!/hamcrest-library/src/main/java" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
@@ -136,7 +136,10 @@ if [ -n "$@@product_uc@@_PROPERTIES" ]; then
|
||||
IDE_PROPERTIES_PROPERTY="-Didea.properties.file=$@@product_uc@@_PROPERTIES"
|
||||
fi
|
||||
|
||||
vm_options_file="$OS_SPECIFIC_BIN_DIR/@@vm_options@@$BITS.vmoptions"
|
||||
vm_options_file="$IDE_BIN_HOME/@@vm_options@@$BITS.vmoptions"
|
||||
if [ ! -r "$vm_options_file" ]; then
|
||||
vm_options_file="$OS_SPECIFIC_BIN_DIR/@@vm_options@@$BITS.vmoptions"
|
||||
fi
|
||||
user_vm_options_file="$HOME/.@@system_selector@@/@@vm_options@@$BITS.vmoptions"
|
||||
if [ -r "$user_vm_options_file" ]; then
|
||||
vm_options_file="$user_vm_options_file"
|
||||
@@ -184,6 +187,5 @@ LD_LIBRARY_PATH="$IDE_BIN_HOME:$LD_LIBRARY_PATH" "$JDK/jre/bin/java" \
|
||||
com.intellij.idea.Main \
|
||||
"$@"
|
||||
EC=$?
|
||||
exit $EC
|
||||
# test $EC -ne 88 && exit $EC
|
||||
# exec "$0" "$@"
|
||||
test $EC -ne 88 && exit $EC
|
||||
exec "$0" "$@"
|
||||
|
||||
@@ -852,10 +852,15 @@ skip_properties:
|
||||
; set the current time for installation files under $INSTDIR\bin
|
||||
ExecCmd::exec 'copy "$INSTDIR\bin\*.*s" +,,'
|
||||
call winVersion
|
||||
${If} $0 == "1"
|
||||
${If} $0 == "1"
|
||||
;ExecCmd::exec 'icacls "$INSTDIR" /grant %username%:F /T >"$INSTDIR"\installation_log.txt 2>"$INSTDIR"\installation_error.txt'
|
||||
AccessControl::GrantOnFile \
|
||||
"$INSTDIR" "(S-1-5-32-545)" "GenericRead + GenericExecute"
|
||||
AccessControl::GrantOnFile \
|
||||
"$INSTDIR\bin\${PRODUCT_EXE_FILE}.vmoptions" "(S-1-5-32-545)" "GenericRead + GenericWrite"
|
||||
${StrRep} $0 ${PRODUCT_EXE_FILE} ".exe" "64.exe.vmoptions"
|
||||
AccessControl::GrantOnFile \
|
||||
"$INSTDIR\bin\$0" "(S-1-5-32-545)" "GenericRead + GenericWrite"
|
||||
${EndIf}
|
||||
SectionEnd
|
||||
|
||||
|
||||
@@ -666,6 +666,15 @@ public def layoutCommunityPlugins(String home, boolean maySkipAndroidPlugin = fa
|
||||
}
|
||||
}
|
||||
|
||||
def setPluginVersionAndSince(String moduleName, String version) {
|
||||
def file = new File(projectBuilder.moduleOutput(findModule(moduleName)) + "/META-INF/plugin.xml")
|
||||
if (file.isFile()) {
|
||||
def text = file.text
|
||||
if (!text.contains("<version>")) {
|
||||
file.text = text.replace("</id>", "</id>\n <version>${version}</version>\n <idea-version since-build=\"${version}\" until-build=\"${version}\"/>\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def layoutPlugin(String moduleName) {
|
||||
layoutPlugin(moduleName, moduleName, {})
|
||||
@@ -697,6 +706,8 @@ def layoutPlugin(String pluginName, String moduleName, String jarName, Closure c
|
||||
return
|
||||
}
|
||||
|
||||
setPluginVersionAndSince(moduleName, requireProperty("buildNumber", requireProperty("build.number", snapshot)))
|
||||
|
||||
dir(pluginName) {
|
||||
dir("lib") {
|
||||
jar("${jarName}.jar") {
|
||||
|
||||
@@ -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.
|
||||
@@ -27,6 +27,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.MultiLineLabelUI;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.ScrollPaneFactory;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
@@ -129,19 +130,13 @@ public class GenerateAntBuildDialog extends DialogWrapper {
|
||||
|
||||
private void saveSettings() {
|
||||
final PropertiesComponent properties = PropertiesComponent.getInstance(myProject);
|
||||
properties.setValue(SINGLE_FILE_PROPERTY, Boolean.toString(myRbGenerateSingleFileBuild.isSelected()));
|
||||
properties.setValue(UI_FORM_PROPERTY, Boolean.toString(myCbEnableUIFormsCompilation.isSelected()));
|
||||
properties.setValue(FORCE_TARGET_JDK_PROPERTY, Boolean.toString(myCbForceTargetJdk.isSelected()));
|
||||
properties.setValue(BACKUP_FILES_PROPERTY, Boolean.toString(myRbBackupFiles.isSelected()));
|
||||
properties.setValue(INLINE_RUNTIME_CLASSPATH_PROPERTY, Boolean.toString(myCbInlineRuntimeClasspath.isSelected()));
|
||||
properties.setValue(GENERATE_IDEA_HOME_PROPERTY, Boolean.toString(myGenerateIdeaHomeProperty.isSelected()));
|
||||
final String outputFileName = getOutputFileName();
|
||||
if (outputFileName.length() > 0) {
|
||||
properties.setValue(OUTPUT_FILE_NAME_PROPERTY, outputFileName);
|
||||
}
|
||||
else {
|
||||
properties.unsetValue(OUTPUT_FILE_NAME_PROPERTY);
|
||||
}
|
||||
properties.setValue(SINGLE_FILE_PROPERTY, myRbGenerateSingleFileBuild.isSelected());
|
||||
properties.setValue(UI_FORM_PROPERTY, myCbEnableUIFormsCompilation.isSelected());
|
||||
properties.setValue(FORCE_TARGET_JDK_PROPERTY, myCbForceTargetJdk.isSelected());
|
||||
properties.setValue(BACKUP_FILES_PROPERTY, myRbBackupFiles.isSelected());
|
||||
properties.setValue(INLINE_RUNTIME_CLASSPATH_PROPERTY, myCbInlineRuntimeClasspath.isSelected());
|
||||
properties.setValue(GENERATE_IDEA_HOME_PROPERTY, myGenerateIdeaHomeProperty.isSelected());
|
||||
properties.setValue(OUTPUT_FILE_NAME_PROPERTY, StringUtil.nullize(getOutputFileName()));
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -18,8 +18,8 @@ package com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup;
|
||||
import com.intellij.codeInsight.completion.InsertionContext;
|
||||
import com.intellij.codeInsight.completion.JavaMethodCallElement;
|
||||
import com.intellij.codeInsight.completion.StaticallyImportable;
|
||||
import com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.sub.SubLookupElement;
|
||||
import com.intellij.codeInsight.lookup.AutoCompletionPolicy;
|
||||
import com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.sub.SubLookupElement;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.psi.PsiClass;
|
||||
@@ -64,7 +64,7 @@ public class ChainCompletionMethodCallLookupElement extends JavaMethodCallElemen
|
||||
|
||||
private void configureAutoCompletionPolicy() {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
if (PropertiesComponent.getInstance(myMethod.getProject()).getBoolean(PROP_METHODS_CHAIN_COMPLETION_AUTO_COMPLETION, false)) {
|
||||
if (PropertiesComponent.getInstance(myMethod.getProject()).getBoolean(PROP_METHODS_CHAIN_COMPLETION_AUTO_COMPLETION)) {
|
||||
setAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,6 +126,24 @@ public class JavaSmartStepIntoHandler extends JvmSmartStepIntoHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitField(PsiField field) {
|
||||
TextRange range = field.getTextRange();
|
||||
if (lineRange.intersects(range)) {
|
||||
//textRange.set(textRange.get().union(range));
|
||||
super.visitField(field);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethod(PsiMethod method) {
|
||||
TextRange range = method.getTextRange();
|
||||
if (lineRange.intersects(range)) {
|
||||
//textRange.set(textRange.get().union(range));
|
||||
super.visitMethod(method);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitStatement(PsiStatement statement) {
|
||||
TextRange range = statement.getTextRange();
|
||||
|
||||
+4
-3
@@ -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.
|
||||
@@ -31,6 +31,7 @@ import java.awt.*;
|
||||
*/
|
||||
public class ObjectMarkupPropertiesDialog extends ValueMarkerPresentationDialogBase {
|
||||
@NonNls private static final String MARK_ALL_REFERENCED_VALUES_KEY = "debugger.mark.all.referenced.values";
|
||||
private static final boolean MARK_ALL_REFERENCED_VALUES_DEFAULT_VALUE = true;
|
||||
private JCheckBox myCbMarkAdditionalFields;
|
||||
private final boolean mySuggestAdditionalMarkup;
|
||||
private JPanel myAdditionalPropertiesPanel;
|
||||
@@ -41,14 +42,14 @@ public class ObjectMarkupPropertiesDialog extends ValueMarkerPresentationDialogB
|
||||
mySuggestAdditionalMarkup = suggestAdditionalMarkup;
|
||||
myDescriptionLabel.setText("If the value is referenced by a constant field of an abstract class,\n" +
|
||||
"IDEA could additionally mark all values referenced from this class with the names of referencing fields.");
|
||||
myCbMarkAdditionalFields.setSelected(PropertiesComponent.getInstance().getBoolean(MARK_ALL_REFERENCED_VALUES_KEY, true));
|
||||
myCbMarkAdditionalFields.setSelected(PropertiesComponent.getInstance().getBoolean(MARK_ALL_REFERENCED_VALUES_KEY, MARK_ALL_REFERENCED_VALUES_DEFAULT_VALUE));
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doOKAction() {
|
||||
if (mySuggestAdditionalMarkup) {
|
||||
PropertiesComponent.getInstance().setValue(MARK_ALL_REFERENCED_VALUES_KEY, Boolean.toString(myCbMarkAdditionalFields.isSelected()));
|
||||
PropertiesComponent.getInstance().setValue(MARK_ALL_REFERENCED_VALUES_KEY, myCbMarkAdditionalFields.isSelected(), MARK_ALL_REFERENCED_VALUES_DEFAULT_VALUE);
|
||||
}
|
||||
super.doOKAction();
|
||||
}
|
||||
|
||||
+12
-6
@@ -26,7 +26,6 @@ import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.util.text.StringUtilRt;
|
||||
import com.intellij.ui.PortField;
|
||||
import com.intellij.xdebugger.impl.settings.DebuggerConfigurable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -40,7 +39,7 @@ public class GenericDebuggerParametersRunnerConfigurable extends SettingsEditor<
|
||||
private JTextField myAddressField;
|
||||
private JPanel myShMemPanel;
|
||||
private JPanel myPortPanel;
|
||||
private PortField myPortField;
|
||||
private JTextField myPortField;
|
||||
private boolean myIsLocal = false;
|
||||
private JButton myDebuggerSettings;
|
||||
private JRadioButton mySocketTransport;
|
||||
@@ -94,7 +93,6 @@ public class GenericDebuggerParametersRunnerConfigurable extends SettingsEditor<
|
||||
myPortPanel.setVisible(isSocket());
|
||||
myShMemPanel.setVisible(!isSocket());
|
||||
myAddressField.setEditable(!myIsLocal);
|
||||
myPortField.setEditable(!myIsLocal);
|
||||
mySocketTransport.setEnabled(!myIsLocal);
|
||||
myShmemTransport.setEnabled(!myIsLocal);
|
||||
}
|
||||
@@ -142,7 +140,7 @@ public class GenericDebuggerParametersRunnerConfigurable extends SettingsEditor<
|
||||
|
||||
private String getPort() {
|
||||
if (isSocket()) {
|
||||
return String.valueOf(myPortField.getNumber());
|
||||
return String.valueOf(myPortField.getText());
|
||||
}
|
||||
else {
|
||||
return myAddressField.getText();
|
||||
@@ -150,10 +148,18 @@ public class GenericDebuggerParametersRunnerConfigurable extends SettingsEditor<
|
||||
}
|
||||
|
||||
private void checkPort() throws ConfigurationException {
|
||||
if (isSocket() && !myPortField.isSpecified()) {
|
||||
if (isSocket() && parsePort() == 0) {
|
||||
throw new ConfigurationException(DebuggerBundle.message("error.text.invalid.port"));
|
||||
}
|
||||
}
|
||||
private int parsePort() {
|
||||
try {
|
||||
return Math.max(0, Integer.parseInt(myPortField.getText()));
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void setTransport(int transport) {
|
||||
mySocketTransport.setSelected(transport == DebuggerSettings.SOCKET_TRANSPORT);
|
||||
@@ -168,7 +174,7 @@ public class GenericDebuggerParametersRunnerConfigurable extends SettingsEditor<
|
||||
|
||||
private void setPort(String port) {
|
||||
if (isSocket()) {
|
||||
myPortField.setNumber(StringUtilRt.parseInt(port, 0));
|
||||
myPortField.setText(String.valueOf(StringUtilRt.parseInt(port, 0)));
|
||||
}
|
||||
else {
|
||||
myAddressField.setText(port);
|
||||
|
||||
+4
-2
@@ -52,11 +52,13 @@
|
||||
<text resource-bundle="messages/DebuggerBundle" key="label.generic.debugger.parameters.patcher.configurable.port"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="5ffe7" class="com.intellij.ui.PortField" binding="myPortField">
|
||||
<component id="3f860" class="javax.swing.JTextField" binding="myPortField">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<properties>
|
||||
<columns value="5"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
|
||||
+7
-3
@@ -32,13 +32,17 @@ public class ApplicationRunLineMarkerProvider extends RunLineMarkerContributor {
|
||||
@Nullable
|
||||
@Override
|
||||
public Info getInfo(PsiElement e) {
|
||||
if (e instanceof PsiIdentifier) {
|
||||
if (isIdentifier(e)) {
|
||||
PsiElement element = e.getParent();
|
||||
if (element instanceof PsiClass && PsiMethodUtil.findMainInClass((PsiClass)element) != null)
|
||||
return new Info(ApplicationConfigurationType.getInstance().getIcon(), null, ExecutorAction.ACTIONS);
|
||||
return new Info(ApplicationConfigurationType.getInstance().getIcon(), null, ExecutorAction.getActions(0));
|
||||
if (element instanceof PsiMethod && "main".equals(((PsiMethod)element).getName()) && PsiMethodUtil.isMainMethod((PsiMethod)element))
|
||||
return new Info(ApplicationConfigurationType.getInstance().getIcon(), null, ExecutorAction.ACTIONS);
|
||||
return new Info(ApplicationConfigurationType.getInstance().getIcon(), null, ExecutorAction.getActions(0));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected boolean isIdentifier(PsiElement e) {
|
||||
return e instanceof PsiIdentifier;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -182,7 +182,7 @@ public class LibraryEditingUtil {
|
||||
|
||||
@Override
|
||||
public Icon getIconFor(LibraryType aValue) {
|
||||
return aValue != null ? aValue.getIcon() : PlatformIcons.LIBRARY_ICON;
|
||||
return aValue != null ? aValue.getIcon(null) : PlatformIcons.LIBRARY_ICON;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+29
-28
@@ -38,6 +38,31 @@ import java.util.*;
|
||||
public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
|
||||
private Map<LibraryKind, LibraryPresentationProvider<?>> myPresentationProviders;
|
||||
|
||||
public static List<LibraryKind> getLibraryKinds(@NotNull Library library, @Nullable StructureConfigurableContext context) {
|
||||
final List<LibraryKind> result = new SmartList<LibraryKind>();
|
||||
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 <P extends LibraryProperties> 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 <P extends LibraryProperties> LibraryPresentationProvider<P> getPresentationProvider(LibraryKind kind) {
|
||||
if (myPresentationProviders == null) {
|
||||
final Map<LibraryKind, LibraryPresentationProvider<?>> providers = new HashMap<LibraryKind, LibraryPresentationProvider<?>>();
|
||||
@@ -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<Icon> icons = getCustomIcons(library, context);
|
||||
if (icons.size() == 1) {
|
||||
@@ -83,7 +109,7 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
|
||||
public <P extends LibraryProperties> boolean processProperties(@NotNull LibraryKind kind, @NotNull P properties) {
|
||||
final LibraryPresentationProvider<P> 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<LibraryKind> getLibraryKinds(@NotNull Library library, @Nullable StructureConfigurableContext context) {
|
||||
final List<LibraryKind> result = new SmartList<LibraryKind>();
|
||||
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 <P extends LibraryProperties> boolean processProperties(@NotNull LibraryKind kind, @NotNull P properties) {
|
||||
result.add(kind);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> getDescriptions(@NotNull Library library, StructureConfigurableContext context) {
|
||||
@@ -141,14 +150,6 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
|
||||
return getDescriptions(files, Collections.<LibraryKind>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<String> getDescriptions(@NotNull VirtualFile[] classRoots, final Set<LibraryKind> excludedKinds) {
|
||||
|
||||
+16
-16
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
+5
-8
@@ -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;
|
||||
|
||||
+27
-65
@@ -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<PsiParameter, String>() {
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+22
-1
@@ -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<PsiElement> callExpressionCondition = Conditions.instanceOf(PsiCallExpression.class);
|
||||
final Condition<PsiElement> nonFinalFieldRefCondition = new Condition<PsiElement>() {
|
||||
@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
|
||||
|
||||
+1
-1
@@ -178,7 +178,7 @@ public class ConstructorInsertHandler implements InsertHandler<LookupElementDeco
|
||||
if (newExpr != null) {
|
||||
for (ExpectedTypeInfo info : ExpectedTypesProvider.getExpectedTypes(newExpr, true)) {
|
||||
PsiType expected = info.getDefaultType();
|
||||
if (expected.isAssignableFrom(delegate.getPsiType())) {
|
||||
if (expected.isAssignableFrom(delegate.getType())) {
|
||||
if (expected instanceof PsiClassType && ((PsiClassType)expected).isRaw()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -26,11 +26,9 @@ import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DefaultInsertHandler extends TemplateInsertHandler implements Cloneable {
|
||||
public class DefaultInsertHandler implements InsertHandler {
|
||||
|
||||
public static final DefaultInsertHandler NO_TAIL_HANDLER = new DefaultInsertHandler(){
|
||||
@Override
|
||||
@@ -40,13 +38,9 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
|
||||
};
|
||||
|
||||
@Override
|
||||
public void handleInsert(final InsertionContext context, LookupElement item) {
|
||||
super.handleInsert(context, item);
|
||||
|
||||
handleInsertInner(context, (LookupItem)item, context.getCompletionChar());
|
||||
}
|
||||
|
||||
private void handleInsertInner(InsertionContext context, LookupItem item, final char completionChar) {
|
||||
public void handleInsert(final InsertionContext context, LookupElement lookupElement) {
|
||||
LookupItem item = (LookupItem)lookupElement;
|
||||
char completionChar = context.getCompletionChar();
|
||||
final Project project = context.getProject();
|
||||
final Editor editor = context.getEditor();
|
||||
final Document document = editor.getDocument();
|
||||
@@ -170,11 +164,6 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
|
||||
return editor.getCaretModel().getOffset();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void populateInsertMap(@NotNull final PsiFile file, @NotNull final OffsetMap offsetMap) {
|
||||
JavaCompletionUtil.initOffsets(file, offsetMap);
|
||||
}
|
||||
|
||||
public static class InsertHandlerState{
|
||||
int tailOffset;
|
||||
int caretOffset;
|
||||
|
||||
+1
-1
@@ -293,7 +293,7 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
|
||||
private static void registerClassFromTypeElement(LookupElement element, InheritorsHolder inheritors) {
|
||||
PsiType type = assertNotNull(element.as(PsiTypeLookupItem.CLASS_CONDITION_KEY)).getPsiType();
|
||||
PsiType type = assertNotNull(element.as(PsiTypeLookupItem.CLASS_CONDITION_KEY)).getType();
|
||||
PsiClass aClass =
|
||||
type instanceof PsiClassType && ((PsiClassType)type).getParameterCount() == 0 ? ((PsiClassType)type).resolve() : null;
|
||||
if (aClass != null) {
|
||||
|
||||
@@ -245,48 +245,10 @@ public class JavaCompletionUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiType getPsiType(final Object o) {
|
||||
if (o instanceof ResolveResult) {
|
||||
return getPsiType(((ResolveResult)o).getElement());
|
||||
}
|
||||
if (o instanceof PsiVariable) {
|
||||
return ((PsiVariable)o).getType();
|
||||
}
|
||||
else if (o instanceof PsiMethod) {
|
||||
return ((PsiMethod)o).getReturnType();
|
||||
}
|
||||
else if (o instanceof PsiClass) {
|
||||
final PsiClass psiClass = (PsiClass)o;
|
||||
return JavaPsiFacade.getInstance(psiClass.getProject()).getElementFactory().createType(psiClass);
|
||||
}
|
||||
else if (o instanceof PsiExpression) {
|
||||
return ((PsiExpression)o).getType();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiType getLookupElementType(final LookupElement element) {
|
||||
TypedLookupItem typed = element.as(TypedLookupItem.CLASS_CONDITION_KEY);
|
||||
if (typed != null) {
|
||||
return typed.getType();
|
||||
}
|
||||
|
||||
final PsiType qualifierType = getPsiType(element.getObject());
|
||||
final LookupItem lookupItem = element.as(LookupItem.CLASS_CONDITION_KEY);
|
||||
if (lookupItem != null) {
|
||||
final Object o = lookupItem.getAttribute(LookupItem.TYPE);
|
||||
if (o instanceof PsiType) {
|
||||
return (PsiType)o;
|
||||
}
|
||||
|
||||
final PsiSubstitutor substitutor = (PsiSubstitutor)lookupItem.getAttribute(LookupItem.SUBSTITUTOR);
|
||||
if (substitutor != null) {
|
||||
return substitutor.substitute(qualifierType);
|
||||
}
|
||||
}
|
||||
return qualifierType;
|
||||
return typed != null ? typed.getType() : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -424,7 +386,7 @@ public class JavaCompletionUtil {
|
||||
if (plainQualifier != null) {
|
||||
Object o = item.getObject();
|
||||
if (o instanceof PsiMethod) {
|
||||
PsiType castType = castTypeItem.getPsiType();
|
||||
PsiType castType = castTypeItem.getType();
|
||||
if (plainQualifier instanceof PsiClassType && castType instanceof PsiClassType) {
|
||||
PsiMethod method = (PsiMethod)o;
|
||||
PsiClassType.ClassResolveResult plainResult = ((PsiClassType)plainQualifier).resolveGenerics();
|
||||
|
||||
@@ -250,7 +250,6 @@ public class JavaMethodCallElement extends LookupItem<PsiMethod> 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;
|
||||
|
||||
+10
-7
@@ -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<Object> {
|
||||
public class JavaPsiClassReferenceElement extends LookupItem<Object> implements TypedLookupItem {
|
||||
public static final Key<String> PACKAGE_NAME = Key.create("PACKAGE_NAME");
|
||||
public static final ClassConditionKey<JavaPsiClassReferenceElement> CLASS_CONDITION_KEY = ClassConditionKey.create(JavaPsiClassReferenceElement.class);
|
||||
private final Object myClass;
|
||||
@@ -63,6 +60,14 @@ public class JavaPsiClassReferenceElement extends LookupItem<Object> {
|
||||
return myForcedPresentableName;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiType getType() {
|
||||
PsiClass psiClass = getObject();
|
||||
final PsiSubstitutor substitutor = (PsiSubstitutor)getAttribute(LookupItem.SUBSTITUTOR);
|
||||
return JavaPsiFacade.getElementFactory(psiClass.getProject()).createType(psiClass, substitutor == null ? PsiSubstitutor.EMPTY : substitutor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getLookupString() {
|
||||
@@ -147,11 +152,9 @@ public class JavaPsiClassReferenceElement extends LookupItem<Object> {
|
||||
presentation.setIcon(DefaultLookupItemRenderer.getRawIcon(item, presentation.isReal()));
|
||||
}
|
||||
|
||||
final boolean bold = item.getAttribute(LookupItem.HIGHLIGHTED_ATTR) != null;
|
||||
boolean strikeout = JavaElementLookupRenderer.isToStrikeout(item);
|
||||
presentation.setItemText(getName(psiClass, item, diamond));
|
||||
presentation.setStrikeout(strikeout);
|
||||
presentation.setItemTextBold(bold);
|
||||
|
||||
String tailText = getLocationString(item);
|
||||
PsiSubstitutor substitutor = (PsiSubstitutor)item.getAttribute(LookupItem.SUBSTITUTOR);
|
||||
|
||||
-2
@@ -20,7 +20,6 @@ import com.intellij.codeInsight.lookup.LookupItem;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiKeyword;
|
||||
import com.intellij.psi.PsiPrimitiveType;
|
||||
import com.intellij.psi.PsiType;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
@@ -53,7 +52,6 @@ public class NullSmartCompletionContributor extends CompletionContributor{
|
||||
for (final ExpectedTypeInfo info : infos) {
|
||||
if (!(info.getType() instanceof PsiPrimitiveType)) {
|
||||
final LookupItem item = (LookupItem)BasicExpressionCompletionContributor.createKeywordLookupItem(parameters.getPosition(), PsiKeyword.NULL);
|
||||
item.setAttribute(LookupItem.TYPE, PsiType.NULL);
|
||||
result.addElement(JavaSmartCompletionContributor.decorate(item, infos));
|
||||
return;
|
||||
}
|
||||
|
||||
+6
-11
@@ -1,32 +1,29 @@
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.lookup.LookupItem;
|
||||
import com.intellij.codeInsight.lookup.TypedLookupItem;
|
||||
import com.intellij.codeInsight.template.Template;
|
||||
import com.intellij.codeInsight.template.impl.LiveTemplateLookupElementImpl;
|
||||
import com.intellij.codeInsight.template.impl.TemplateImpl;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class SmartCompletionTemplateItem extends LookupItem<Template> implements TypedLookupItem {
|
||||
@NonNls private static final String PLACEHOLDER = "xxx";
|
||||
public class SmartCompletionTemplateItem extends LiveTemplateLookupElementImpl implements TypedLookupItem {
|
||||
private final PsiElement myContext;
|
||||
|
||||
public SmartCompletionTemplateItem(Template o, PsiElement context) {
|
||||
super(o, o.getKey());
|
||||
public SmartCompletionTemplateItem(TemplateImpl template, PsiElement context) {
|
||||
super(template, false);
|
||||
myContext = context;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PsiType getType() {
|
||||
final Template template = getObject();
|
||||
final Template template = getTemplate();
|
||||
String text = template.getTemplateText();
|
||||
StringBuilder resultingText = new StringBuilder(text);
|
||||
|
||||
@@ -37,9 +34,7 @@ public class SmartCompletionTemplateItem extends LookupItem<Template> implements
|
||||
continue;
|
||||
}
|
||||
|
||||
int segmentOffset = template.getSegmentOffset(j);
|
||||
|
||||
resultingText.insert(segmentOffset, PLACEHOLDER);
|
||||
resultingText.insert(template.getSegmentOffset(j), "xxx");
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
+1
-1
@@ -217,7 +217,7 @@ class TypeArgumentCompletionProvider extends CompletionProvider<CompletionParame
|
||||
|
||||
public void registerSingleClass(@Nullable InheritorsHolder inheritors) {
|
||||
if (inheritors != null && myTypeItems.size() == 1) {
|
||||
PsiType type = myTypeItems.get(0).getPsiType();
|
||||
PsiType type = myTypeItems.get(0).getType();
|
||||
PsiClass aClass = PsiUtil.resolveClassInClassTypeOnly(type);
|
||||
if (aClass != null && !aClass.hasTypeParameters()) {
|
||||
JavaCompletionUtil.setShowFQN(myTypeItems.get(0));
|
||||
|
||||
+15
-3
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.roots.ExternalLibraryDescriptor;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.module.Module;
|
||||
@@ -23,6 +25,7 @@ import com.intellij.openapi.roots.DependencyScope;
|
||||
import com.intellij.openapi.roots.ProjectModelModificationService;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -66,9 +69,18 @@ class AddExternalLibraryToDependenciesQuickFix extends OrderEntryFix {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
public void invoke(@NotNull Project project, final Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
DependencyScope scope = suggestScopeByLocation(myCurrentModule, myReference.getElement());
|
||||
ProjectModelModificationService.getInstance(project).addDependency(myCurrentModule, myLibraryDescriptor, scope);
|
||||
importClass(myCurrentModule, editor, myReference, myQualifiedClassName);
|
||||
ProjectModelModificationService.getInstance(project).addDependency(myCurrentModule, myLibraryDescriptor, scope).done(
|
||||
new Consumer<Void>() {
|
||||
@Override
|
||||
public void consume(Void aVoid) {
|
||||
new WriteAction() {
|
||||
protected void run(@NotNull final Result result) {
|
||||
importClass(myCurrentModule, editor, myReference, myQualifiedClassName);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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.
|
||||
@@ -27,7 +27,7 @@ public class AnonymousTargetClassPreselectionUtil {
|
||||
|
||||
public static void rememberSelection(PsiClass aClass, PsiClass firstClass) {
|
||||
if (firstClass instanceof PsiAnonymousClass) {
|
||||
PropertiesComponent.getInstance().setValue(PRESELECT_ANONYMOUS, String.valueOf(aClass == firstClass));
|
||||
PropertiesComponent.getInstance().setValue(PRESELECT_ANONYMOUS, aClass == firstClass);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -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.
|
||||
@@ -25,6 +25,7 @@ import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -117,7 +118,9 @@ public class ConvertSwitchToIfIntention implements IntentionAction {
|
||||
else {
|
||||
hadSideEffects = false;
|
||||
declarationString = null;
|
||||
expressionText = switchExpression.getText();
|
||||
expressionText = ParenthesesUtils.getPrecedence(switchExpression) > ParenthesesUtils.EQUALITY_PRECEDENCE
|
||||
? '(' + switchExpression.getText() + ')'
|
||||
: switchExpression.getText();
|
||||
}
|
||||
final PsiCodeBlock body = switchStatement.getBody();
|
||||
if (body == null) {
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ public class JetBrainsAnnotationsExternalLibraryResolver extends ExternalLibrary
|
||||
|
||||
private static abstract class JetBrainsAnnotationsLibraryDescriptor extends ExternalLibraryDescriptor {
|
||||
public JetBrainsAnnotationsLibraryDescriptor() {
|
||||
super("com.intellij", "annotations", null);
|
||||
super("com.intellij", "annotations");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -86,7 +86,7 @@ public class JavaOverrideImplementMemberChooser extends MemberChooser<PsiMethodM
|
||||
final JavaOverrideImplementMemberChooser javaOverrideImplementMemberChooser =
|
||||
new JavaOverrideImplementMemberChooser(all, onlyPrimary, lazyElementsWithPercent, project, PsiUtil.isLanguageLevel5OrHigher(aClass),
|
||||
merge, toImplement, PropertiesComponent.getInstance(project)
|
||||
.getBoolean(PROP_OVERRIDING_SORTED_OVERRIDE_IMPLEMENT, false));
|
||||
.getBoolean(PROP_OVERRIDING_SORTED_OVERRIDE_IMPLEMENT));
|
||||
javaOverrideImplementMemberChooser.setTitle(getChooserTitle(toImplement, merge));
|
||||
|
||||
javaOverrideImplementMemberChooser.setCopyJavadocVisible(true);
|
||||
@@ -151,8 +151,8 @@ public class JavaOverrideImplementMemberChooser extends MemberChooser<PsiMethodM
|
||||
@Override
|
||||
protected void doOKAction() {
|
||||
super.doOKAction();
|
||||
PropertiesComponent.getInstance(myProject).setValue(PROP_COMBINED_OVERRIDE_IMPLEMENT, String.valueOf(myMerge));
|
||||
PropertiesComponent.getInstance(myProject).setValue(PROP_OVERRIDING_SORTED_OVERRIDE_IMPLEMENT, String.valueOf(mySortedByOverriding));
|
||||
PropertiesComponent.getInstance(myProject).setValue(PROP_COMBINED_OVERRIDE_IMPLEMENT, myMerge, true);
|
||||
PropertiesComponent.getInstance(myProject).setValue(PROP_OVERRIDING_SORTED_OVERRIDE_IMPLEMENT, mySortedByOverriding);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.intention.impl;
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInsight.intention.BaseElementAtCaretIntentionAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Dmitry Batkovich
|
||||
*/
|
||||
public class ConvertEqualsMethodToStaticIntention extends BaseElementAtCaretIntentionAction {
|
||||
private static final Logger LOG = Logger.getInstance(ConvertEqualsMethodToStaticIntention.class);
|
||||
private static final String REPLACE_TEMPLATE = "java.util.Objects.equals(%s, %s)";
|
||||
public static final String TEXT = "Convert '.equals()' to 'java.util.Objects.equals()'";
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
|
||||
if (!(element instanceof PsiIdentifier)) {
|
||||
return false;
|
||||
}
|
||||
if (!PsiUtil.isLanguageLevel7OrHigher(element)) {
|
||||
return false;
|
||||
}
|
||||
final PsiElement referenceExpression = element.getParent();
|
||||
if (!(referenceExpression instanceof PsiReferenceExpression)) {
|
||||
return false;
|
||||
}
|
||||
if (!"equals".equals(((PsiReferenceExpression)referenceExpression).getReferenceName())) {
|
||||
return false;
|
||||
}
|
||||
final PsiElement methodCallExpression = referenceExpression.getParent();
|
||||
if (!(methodCallExpression instanceof PsiMethodCallExpression)) {
|
||||
return false;
|
||||
}
|
||||
final int argumentsCount = ((PsiMethodCallExpression)methodCallExpression).getArgumentList().getExpressions().length;
|
||||
if (argumentsCount != 1) {
|
||||
return false;
|
||||
}
|
||||
final PsiMethod method = ((PsiMethodCallExpression)methodCallExpression).resolveMethod();
|
||||
if (method == null) {
|
||||
return false;
|
||||
}
|
||||
PsiClass javaLangObject = JavaPsiFacade.getInstance(project).findClass(CommonClassNames.JAVA_LANG_OBJECT, element.getResolveScope());
|
||||
if (javaLangObject == null) {
|
||||
return false;
|
||||
}
|
||||
if (javaLangObject.isEquivalentTo(method.getContainingClass())) {
|
||||
return true;
|
||||
}
|
||||
final PsiMethod[] superMethods = method.findSuperMethods(javaLangObject);
|
||||
return superMethods.length == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
|
||||
if (!FileModificationService.getInstance().preparePsiElementsForWrite(element)) {
|
||||
return;
|
||||
}
|
||||
final PsiElement parent = element.getParent().getParent();
|
||||
LOG.assertTrue(parent instanceof PsiMethodCallExpression);
|
||||
PsiMethodCallExpression methodCall = (PsiMethodCallExpression) parent;
|
||||
final PsiExpression qualifier = methodCall.getMethodExpression().getQualifierExpression();
|
||||
final String qualifierText = qualifier == null ? PsiKeyword.THIS : qualifier.getText();
|
||||
final PsiExpression parameter = methodCall.getArgumentList().getExpressions()[0];
|
||||
final String expressionText = String.format(REPLACE_TEMPLATE, qualifierText, parameter.getText());
|
||||
methodCall.replace(JavaPsiFacade.getElementFactory(project).createExpressionFromText(expressionText, null));
|
||||
}
|
||||
|
||||
@Nls
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return TEXT;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return getFamilyName();
|
||||
}
|
||||
}
|
||||
+6
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -21,7 +21,10 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.ComboBox;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiNameHelper;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.refactoring.ui.TypeSelector;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -64,7 +67,7 @@ public class CreateFieldFromParameterDialog extends DialogWrapper {
|
||||
@Override
|
||||
protected void doOKAction() {
|
||||
if (myCbFinal.isEnabled()) {
|
||||
PropertiesComponent.getInstance().setValue(PROPERTY_NAME, String.valueOf(myCbFinal.isSelected()));
|
||||
PropertiesComponent.getInstance().setValue(PROPERTY_NAME, myCbFinal.isSelected());
|
||||
}
|
||||
|
||||
final PsiField[] fields = myTargetClass.getFields();
|
||||
|
||||
@@ -29,6 +29,8 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||
import com.intellij.openapi.projectRoots.JavaSdkVersion;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.PackageIndex;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
@@ -383,23 +385,52 @@ public class JavaDocInfoGenerator {
|
||||
return null;
|
||||
|
||||
if (docURLs != null) {
|
||||
if (buffer.length() == 0) {
|
||||
buffer.append("<html><body></body></html>");
|
||||
if (elementHasSourceCode()) {
|
||||
LOG.debug("Documentation for " + myElement + " was generated from source code, it wasn't found at following URLs: ", docURLs);
|
||||
}
|
||||
else {
|
||||
if (buffer.length() == 0) {
|
||||
buffer.append("<html><body></body></html>");
|
||||
}
|
||||
String errorSection = "<p id=\"error\">Following external urls were checked:<br> <i>" +
|
||||
StringUtil.join(docURLs, new Function<String, String>() {
|
||||
@Override
|
||||
public String fun(String url) {
|
||||
return XmlStringUtil.escapeString(url);
|
||||
}
|
||||
}, "</i><br> <i>") +
|
||||
"</i><br>The documentation for this element is not found. Please add all the needed paths to API docs in " +
|
||||
"<a href=\"open://Project Settings\">Project Settings.</a></p>";
|
||||
buffer.insert(buffer.indexOf("<body>"), errorSection);
|
||||
}
|
||||
String errorSection = "<p id=\"error\">Following external urls were checked:<br> <i>" +
|
||||
StringUtil.join(docURLs, new Function<String, String>() {
|
||||
@Override
|
||||
public String fun(String url) {
|
||||
return XmlStringUtil.escapeString(url);
|
||||
}
|
||||
}, "</i><br> <i>") +
|
||||
"</i><br>The documentation for this element is not found. Please add all the needed paths to API docs in " +
|
||||
"<a href=\"open://Project Settings\">Project Settings.</a></p>";
|
||||
buffer.insert(buffer.indexOf("<body>"), errorSection);
|
||||
}
|
||||
return fixupDoc(buffer);
|
||||
}
|
||||
|
||||
private boolean elementHasSourceCode() {
|
||||
VirtualFile[] files;
|
||||
if (myElement instanceof PsiDirectory) {
|
||||
final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory)myElement);
|
||||
if (aPackage == null) return false;
|
||||
files = PackageIndex.getInstance(myProject).getDirectoriesByPackageName(aPackage.getQualifiedName(), true);
|
||||
}
|
||||
else if (myElement instanceof PsiPackage) {
|
||||
files = PackageIndex.getInstance(myProject).getDirectoriesByPackageName(((PsiPackage)myElement).getQualifiedName(), true);
|
||||
}
|
||||
else {
|
||||
PsiFile containingFile = myElement.getNavigationElement().getContainingFile();
|
||||
if (containingFile == null) return false;
|
||||
VirtualFile virtualFile = containingFile.getVirtualFile();
|
||||
if (virtualFile == null) return false;
|
||||
files = new VirtualFile[] {virtualFile};
|
||||
}
|
||||
ProjectFileIndex projectFileIndex = ProjectFileIndex.SERVICE.getInstance(myProject);
|
||||
for (VirtualFile file : files) {
|
||||
if (projectFileIndex.isInSource(file)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void generateClassJavaDoc(@NonNls StringBuilder buffer, PsiClass aClass, boolean generatePrologueAndEpilogue) {
|
||||
if (aClass instanceof PsiAnonymousClass) return;
|
||||
if (generatePrologueAndEpilogue)
|
||||
@@ -652,7 +683,10 @@ public class JavaDocInfoGenerator {
|
||||
}
|
||||
|
||||
private void generatePackageJavaDoc(final StringBuilder buffer, final PsiPackage psiPackage, boolean generatePrologueAndEpilogue) {
|
||||
for(PsiDirectory directory: psiPackage.getDirectories()) {
|
||||
VirtualFile[] dirs = PackageIndex.getInstance(myProject).getDirectoriesByPackageName(psiPackage.getQualifiedName(), true);
|
||||
for (VirtualFile dir : dirs) {
|
||||
PsiDirectory directory = PsiManager.getInstance(myProject).findDirectory(dir);
|
||||
if (directory == null) continue;
|
||||
final PsiFile packageInfoFile = directory.findFile(PsiPackage.PACKAGE_INFO_FILE);
|
||||
if (packageInfoFile != null) {
|
||||
final ASTNode node = packageInfoFile.getNode();
|
||||
|
||||
@@ -40,9 +40,6 @@ import java.util.Collection;
|
||||
public class LookupItemUtil{
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.lookup.LookupItemUtil");
|
||||
|
||||
private LookupItemUtil() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static LookupElement addLookupItem(Collection<LookupElement> set, @NotNull Object object) {
|
||||
return addLookupItem(set, object, new CamelHumpMatcher(""));
|
||||
@@ -124,9 +121,6 @@ public class LookupItemUtil{
|
||||
if (s == null) {
|
||||
LOG.error("Null string for object: " + object + " of class " + (object != null ? object.getClass() : null));
|
||||
}
|
||||
if (object instanceof LookupValueWithTail) {
|
||||
item.setAttribute(LookupItem.TAIL_TEXT_ATTR, " " + ((LookupValueWithTail)object).getTailText());
|
||||
}
|
||||
item.setLookupString(s);
|
||||
|
||||
item.setTailType(tailType);
|
||||
|
||||
@@ -39,7 +39,7 @@ import java.util.Set;
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class PsiTypeLookupItem extends LookupItem {
|
||||
public class PsiTypeLookupItem extends LookupItem implements TypedLookupItem {
|
||||
private static final InsertHandler<PsiTypeLookupItem> DEFAULT_IMPORT_FIXER = new InsertHandler<PsiTypeLookupItem>() {
|
||||
@Override
|
||||
public void handleInsert(InsertionContext context, PsiTypeLookupItem item) {
|
||||
@@ -65,13 +65,14 @@ public class PsiTypeLookupItem extends LookupItem {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PsiType getPsiType() {
|
||||
@Override
|
||||
public PsiType getType() {
|
||||
Object object = getObject();
|
||||
PsiType type = object instanceof PsiType ? (PsiType)object : JavaPsiFacade.getElementFactory(((PsiClass) object).getProject()).createType((PsiClass)object);
|
||||
for (int i = 0; i < getBracketsCount(); i++) {
|
||||
type = new PsiArrayType(type);
|
||||
}
|
||||
return type;
|
||||
return getSubstitutor().substitute(type);
|
||||
}
|
||||
|
||||
|
||||
@@ -191,18 +192,14 @@ public class PsiTypeLookupItem extends LookupItem {
|
||||
}
|
||||
|
||||
|
||||
public static PsiTypeLookupItem createLookupItem(@NotNull PsiType type, @Nullable PsiElement context, boolean isDiamond, InsertHandler<PsiTypeLookupItem> importFixer) {
|
||||
final PsiType original = type;
|
||||
public static PsiTypeLookupItem createLookupItem(@NotNull PsiType type, @Nullable PsiElement context, boolean isDiamond, InsertHandler<PsiTypeLookupItem> importFixer) {
|
||||
int dim = 0;
|
||||
while (type instanceof PsiArrayType) {
|
||||
type = ((PsiArrayType)type).getComponentType();
|
||||
dim++;
|
||||
}
|
||||
|
||||
PsiTypeLookupItem item = doCreateItem(type, context, dim, isDiamond, importFixer);
|
||||
|
||||
item.setAttribute(TYPE, original);
|
||||
return item;
|
||||
return doCreateItem(type, context, dim, isDiamond, importFixer);
|
||||
}
|
||||
|
||||
private static PsiTypeLookupItem doCreateItem(final PsiType type,
|
||||
@@ -275,7 +272,7 @@ public class PsiTypeLookupItem extends LookupItem {
|
||||
}
|
||||
|
||||
presentation.setItemText(((PsiType)object).getCanonicalText());
|
||||
presentation.setItemTextBold(getAttribute(LookupItem.HIGHLIGHTED_ATTR) != null || object instanceof PsiPrimitiveType);
|
||||
presentation.setItemTextBold(object instanceof PsiPrimitiveType);
|
||||
if (isAddArrayInitializer()) {
|
||||
presentation.setTailText("{...}");
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.TailType;
|
||||
import com.intellij.codeInsight.completion.*;
|
||||
import com.intellij.codeInsight.daemon.impl.JavaColorProvider;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightControlFlowUtil;
|
||||
import com.intellij.codeInsight.lookup.impl.JavaElementLookupRenderer;
|
||||
import com.intellij.featureStatistics.FeatureUsageTracker;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
@@ -92,6 +93,7 @@ public class VariableLookupItem extends LookupItem<PsiVariable> implements Typed
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiType getType() {
|
||||
return getSubstitutor().substitute(getObject().getType());
|
||||
}
|
||||
@@ -124,12 +126,25 @@ public class VariableLookupItem extends LookupItem<PsiVariable> implements Typed
|
||||
|
||||
@Override
|
||||
public void renderElement(LookupElementPresentation presentation) {
|
||||
super.renderElement(presentation);
|
||||
boolean qualify = getAttribute(FORCE_QUALIFY) != null;
|
||||
|
||||
PsiVariable variable = getObject();
|
||||
String name = variable.getName();
|
||||
if (qualify && variable instanceof PsiField && ((PsiField)variable).getContainingClass() != null) {
|
||||
name = ((PsiField)variable).getContainingClass().getName() + "." + name;
|
||||
}
|
||||
presentation.setItemText(name);
|
||||
|
||||
presentation.setIcon(DefaultLookupItemRenderer.getRawIcon(this, presentation.isReal()));
|
||||
presentation.setStrikeout(JavaElementLookupRenderer.isToStrikeout(this));
|
||||
|
||||
if (myHelper != null) {
|
||||
myHelper.renderElement(presentation, getAttribute(FORCE_QUALIFY) != null ? Boolean.TRUE : null, getSubstitutor());
|
||||
myHelper.renderElement(presentation, qualify ? Boolean.TRUE : null, getSubstitutor());
|
||||
}
|
||||
if (myColor != null) {
|
||||
presentation.setTypeText("", new ColorIcon(12, myColor));
|
||||
} else {
|
||||
presentation.setTypeText(getType().getPresentableText());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-25
@@ -19,7 +19,6 @@ import com.intellij.codeInsight.completion.JavaCompletionUtil;
|
||||
import com.intellij.codeInsight.lookup.DefaultLookupItemRenderer;
|
||||
import com.intellij.codeInsight.lookup.LookupElementPresentation;
|
||||
import com.intellij.codeInsight.lookup.LookupItem;
|
||||
import com.intellij.codeInsight.lookup.VariableLookupItem;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.beanProperties.BeanPropertyElement;
|
||||
@@ -34,8 +33,7 @@ import java.util.List;
|
||||
public class JavaElementLookupRenderer implements ElementLookupRenderer {
|
||||
@Override
|
||||
public boolean handlesItem(final Object element) {
|
||||
return element instanceof PsiVariable ||
|
||||
element instanceof PsiKeyword || element instanceof PsiExpression ||
|
||||
return element instanceof PsiKeyword || element instanceof PsiExpression ||
|
||||
element instanceof PsiTypeElement || element instanceof BeanPropertyElement;
|
||||
}
|
||||
|
||||
@@ -45,7 +43,6 @@ public class JavaElementLookupRenderer implements ElementLookupRenderer {
|
||||
|
||||
presentation.setItemText(getName(element, item));
|
||||
presentation.setStrikeout(isToStrikeout(item));
|
||||
presentation.setItemTextBold(item.getAttribute(LookupItem.HIGHLIGHTED_ATTR) != null);
|
||||
|
||||
presentation.setTailText((String)item.getAttribute(LookupItem.TAIL_TEXT_ATTR), item.getAttribute(LookupItem.TAIL_TEXT_SMALL_ATTR) != null);
|
||||
|
||||
@@ -69,18 +66,6 @@ public class JavaElementLookupRenderer implements ElementLookupRenderer {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (o instanceof PsiArrayType) {
|
||||
name = ((PsiArrayType)o).getDeepComponentType().getPresentableText();
|
||||
}
|
||||
else if (o instanceof PsiType) {
|
||||
name = ((PsiType)o).getPresentableText();
|
||||
}
|
||||
|
||||
if (item.getAttribute(LookupItem.FORCE_QUALIFY) != null) {
|
||||
if (o instanceof PsiMember && ((PsiMember)o).getContainingClass() != null) {
|
||||
name = ((PsiMember)o).getContainingClass().getName() + "." + name;
|
||||
}
|
||||
}
|
||||
|
||||
return StringUtil.notNullize(name);
|
||||
}
|
||||
@@ -91,15 +76,7 @@ public class JavaElementLookupRenderer implements ElementLookupRenderer {
|
||||
if (o instanceof PsiElement) {
|
||||
final PsiElement element = (PsiElement)o;
|
||||
if (element.isValid()) {
|
||||
if (element instanceof PsiVariable){
|
||||
PsiVariable variable = (PsiVariable)element;
|
||||
PsiType type = variable.getType();
|
||||
if (item instanceof VariableLookupItem) {
|
||||
type = ((VariableLookupItem)item).getSubstitutor().substitute(type);
|
||||
}
|
||||
text = type.getPresentableText();
|
||||
}
|
||||
else if (element instanceof PsiExpression){
|
||||
if (element instanceof PsiExpression){
|
||||
PsiExpression expression = (PsiExpression)element;
|
||||
PsiType type = expression.getType();
|
||||
if (type != null){
|
||||
|
||||
+2
-3
@@ -20,7 +20,6 @@ import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.PsiTypeLookupItem;
|
||||
import com.intellij.codeInsight.template.*;
|
||||
import com.intellij.psi.PsiArrayType;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -49,7 +48,7 @@ public class ComponentTypeOfMacro extends Macro {
|
||||
for (LookupElement element : lookupItems) {
|
||||
PsiTypeLookupItem lookupItem = element.as(PsiTypeLookupItem.CLASS_CONDITION_KEY);
|
||||
if (lookupItem != null) {
|
||||
PsiType psiType = lookupItem.getPsiType();
|
||||
PsiType psiType = lookupItem.getType();
|
||||
if (psiType instanceof PsiArrayType) {
|
||||
result.add(PsiTypeLookupItem.createLookupItem(((PsiArrayType)psiType).getComponentType(), null));
|
||||
}
|
||||
@@ -83,7 +82,7 @@ public class ComponentTypeOfMacro extends Macro {
|
||||
for (LookupElement element : elements) {
|
||||
PsiTypeLookupItem typeLookupItem = element.as(PsiTypeLookupItem.CLASS_CONDITION_KEY);
|
||||
if (typeLookupItem != null) {
|
||||
PsiType psiType = typeLookupItem.getPsiType();
|
||||
PsiType psiType = typeLookupItem.getType();
|
||||
if (psiType instanceof PsiArrayType) {
|
||||
return new PsiTypeResult(((PsiArrayType)psiType).getComponentType(), context.getProject());
|
||||
}
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ import java.util.List;
|
||||
*/
|
||||
public class JCiPExternalLibraryResolver extends ExternalLibraryResolver {
|
||||
private static final ExternalLibraryDescriptor JDCIP_LIBRARY_DESCRIPTOR =
|
||||
new ExternalLibraryDescriptor("net.jcip", "jcip-annotations", null) {
|
||||
new ExternalLibraryDescriptor("net.jcip", "jcip-annotations") {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> getLibraryClassesRoots() {
|
||||
|
||||
+3
-3
@@ -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.
|
||||
@@ -78,7 +78,7 @@ public class InferNullityAnnotationsAction extends BaseAnalysisAction {
|
||||
|
||||
@Override
|
||||
protected void analyze(@NotNull final Project project, @NotNull final AnalysisScope scope) {
|
||||
PropertiesComponent.getInstance().setValue(ANNOTATE_LOCAL_VARIABLES, String.valueOf(myAnnotateLocalVariablesCb.isSelected()));
|
||||
PropertiesComponent.getInstance().setValue(ANNOTATE_LOCAL_VARIABLES, myAnnotateLocalVariablesCb.isSelected());
|
||||
|
||||
final ProgressManager progressManager = ProgressManager.getInstance();
|
||||
final Set<Module> modulesWithoutAnnotations = new HashSet<Module>();
|
||||
@@ -344,7 +344,7 @@ public class InferNullityAnnotationsAction extends BaseAnalysisAction {
|
||||
protected JComponent getAdditionalActionSettings(Project project, BaseAnalysisActionDialog dialog) {
|
||||
final JPanel panel = new JPanel(new VerticalFlowLayout());
|
||||
panel.add(new TitledSeparator());
|
||||
myAnnotateLocalVariablesCb = new JCheckBox("Annotate local variables", PropertiesComponent.getInstance().getBoolean(ANNOTATE_LOCAL_VARIABLES, false));
|
||||
myAnnotateLocalVariablesCb = new JCheckBox("Annotate local variables", PropertiesComponent.getInstance().getBoolean(ANNOTATE_LOCAL_VARIABLES));
|
||||
panel.add(myAnnotateLocalVariablesCb);
|
||||
return panel;
|
||||
}
|
||||
|
||||
+8
-5
@@ -56,8 +56,7 @@ public class GuavaFluentIterableInspection extends BaseJavaBatchLocalInspectionT
|
||||
return null;
|
||||
}
|
||||
final Project project = manager.getProject();
|
||||
final PsiClass fluentIterable = JavaPsiFacade.getInstance(project)
|
||||
.findClass(GUAVA_FLUENT_ITERABLE, GlobalSearchScope.allScope(project));
|
||||
final PsiClass fluentIterable = JavaPsiFacade.getInstance(project).findClass(GUAVA_FLUENT_ITERABLE, file.getResolveScope());
|
||||
if (fluentIterable == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -394,7 +393,7 @@ public class GuavaFluentIterableInspection extends BaseJavaBatchLocalInspectionT
|
||||
if (parameterType instanceof PsiClassType) {
|
||||
final PsiClass resolvedParameterClass = ((PsiClassType)parameterType).resolve();
|
||||
final JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(methodCallExpression.getProject());
|
||||
final GlobalSearchScope scope = GlobalSearchScope.allScope(methodCallExpression.getProject());
|
||||
final GlobalSearchScope scope = methodCallExpression.getResolveScope();
|
||||
final PsiClass optional = javaPsiFacade.findClass(GUAVA_OPTIONAL, scope);
|
||||
final PsiClass immutableMap = javaPsiFacade.findClass(GUAVA_IMMUTABLE_MAP, scope);
|
||||
if (resolvedParameterClass != null &&
|
||||
@@ -474,16 +473,20 @@ public class GuavaFluentIterableInspection extends BaseJavaBatchLocalInspectionT
|
||||
final JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
|
||||
final PsiElementFactory elementFactory = javaPsiFacade.getElementFactory();
|
||||
final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
|
||||
final GuavaFluentIterableMethodConverters converters = new GuavaFluentIterableMethodConverters(elementFactory);
|
||||
for (SmartPsiElementPointer<PsiExpression> usage : myFoundUsages) {
|
||||
final PsiExpression element = usage.getElement();
|
||||
if (element != null) {
|
||||
GuavaFluentIterableMethodConverters.convert(element, elementFactory, codeStyleManager);
|
||||
PsiElement converted = converters.convert(element);
|
||||
if (converted != null) {
|
||||
codeStyleManager.shortenClassReferences(converted);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (myVariable != null) {
|
||||
final PsiLocalVariable element = myVariable.getElement();
|
||||
if (element != null) {
|
||||
GuavaFluentIterableMethodConverters.convert(element, elementFactory, codeStyleManager);
|
||||
codeStyleManager.shortenClassReferences(converters.convert(element));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+62
-70
@@ -18,9 +18,7 @@ package com.intellij.codeInspection.java18StreamApi;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -42,6 +40,11 @@ public class GuavaFluentIterableMethodConverters {
|
||||
private static final Map<String, FluentIterableMethodTransformer> METHOD_INDEX = new HashMap<String, FluentIterableMethodTransformer>();
|
||||
private static final Map<String, String> TO_OTHER_COLLECTION_METHODS = new HashMap<String, String>();
|
||||
private static final Set<String> STOP_METHODS = new HashSet<String>();
|
||||
private final PsiElementFactory myElementFactory;
|
||||
|
||||
public GuavaFluentIterableMethodConverters(PsiElementFactory elementFactory) {
|
||||
myElementFactory = elementFactory;
|
||||
}
|
||||
|
||||
static {
|
||||
METHOD_INDEX.put("allMatch", new FluentIterableMethodTransformer.OneParameterMethodTransformer(StreamApiConstants.ALL_MATCH + "(%s)", true));
|
||||
@@ -86,52 +89,44 @@ public class GuavaFluentIterableMethodConverters {
|
||||
return STOP_METHODS.contains(methodName);
|
||||
}
|
||||
|
||||
public static void convert(final PsiLocalVariable localVariable,
|
||||
final PsiElementFactory elementFactory,
|
||||
final JavaCodeStyleManager codeStyleManager) {
|
||||
public PsiLocalVariable convert(final PsiLocalVariable localVariable) {
|
||||
final PsiTypeElement typeElement = localVariable.getTypeElement();
|
||||
final PsiReferenceParameterList generics = PsiTreeUtil.findChildOfType(typeElement, PsiReferenceParameterList.class);
|
||||
typeElement.replace(elementFactory.createTypeElementFromText(
|
||||
typeElement.replace(myElementFactory.createTypeElementFromText(
|
||||
StreamApiConstants.JAVA_UTIL_STREAM_STREAM + (generics == null ? "" : generics.getText()), null));
|
||||
|
||||
final PsiExpression initializer = localVariable.getInitializer();
|
||||
if (initializer != null) {
|
||||
PsiMethodCallExpression initializerMethodCall = (PsiMethodCallExpression)initializer;
|
||||
convertMethodCallDeep(elementFactory, initializerMethodCall);
|
||||
convertMethodCallDeep((PsiMethodCallExpression)initializer);
|
||||
}
|
||||
codeStyleManager.shortenClassReferences(localVariable);
|
||||
return localVariable;
|
||||
}
|
||||
|
||||
public static void convert(PsiExpression expression,
|
||||
final PsiElementFactory elementFactory,
|
||||
final JavaCodeStyleManager codeStyleManager) {
|
||||
public PsiElement convert(PsiExpression expression) {
|
||||
if (expression instanceof PsiReferenceExpression) {
|
||||
final PsiElement expressionParent = expression.getParent();
|
||||
if (expressionParent instanceof PsiReturnStatement || isIterableMethodParameter(expressionParent, expression)) {
|
||||
expression = (PsiExpression)expression.replace(
|
||||
elementFactory.createExpressionFromText(expression.getText() + ".collect(java.util.stream.Collectors.toList())", null));
|
||||
codeStyleManager.shortenClassReferences(expression);
|
||||
return addCollectionToList(expression);
|
||||
}
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
final PsiMethodCallExpression parentMethodCall = PsiTreeUtil.getParentOfType(expression, PsiMethodCallExpression.class);
|
||||
if (parentMethodCall != null && parentMethodCall.getMethodExpression().getQualifierExpression() == expression) {
|
||||
final PsiMethod seqTailMethod = parentMethodCall.resolveMethod();
|
||||
if (seqTailMethod == null) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
final PsiClass seqTailMethodClass = seqTailMethod.getContainingClass();
|
||||
if (seqTailMethodClass != null && GuavaFluentIterableInspection.GUAVA_OPTIONAL.equals(seqTailMethodClass.getQualifiedName())) {
|
||||
final PsiMethodCallExpression newParentMethodCall =
|
||||
GuavaOptionalConverter.convertGuavaOptionalToJava(parentMethodCall, elementFactory);
|
||||
final PsiMethodCallExpression newParentMethodCall = GuavaOptionalConverter.convertGuavaOptionalToJava(parentMethodCall, myElementFactory);
|
||||
expression = newParentMethodCall.getMethodExpression().getQualifierExpression();
|
||||
}
|
||||
}
|
||||
if (expression instanceof PsiMethodCallExpression) {
|
||||
expression = convertMethodCallDeep(elementFactory, (PsiMethodCallExpression)expression);
|
||||
expression = convertMethodCallDeep((PsiMethodCallExpression)expression);
|
||||
}
|
||||
if (expression == null) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
final PsiElement parent = expression.getParent();
|
||||
if (parent instanceof PsiExpressionList) {
|
||||
@@ -142,28 +137,28 @@ public class GuavaFluentIterableMethodConverters {
|
||||
final PsiMethod method = methodCall.resolveMethod();
|
||||
LOG.assertTrue(method != null);
|
||||
final PsiType parameterType = method.getParameterList().getParameters()[index].getType();
|
||||
expression = addCollectToListIfNeed(expression, parameterType, elementFactory);
|
||||
} else if (parent instanceof PsiReturnStatement) {
|
||||
return addCollectToListIfNeed(expression, parameterType);
|
||||
}
|
||||
else if (parent instanceof PsiReturnStatement) {
|
||||
final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(parent, PsiMethod.class);
|
||||
LOG.assertTrue(containingMethod != null);
|
||||
final PsiType returnType = containingMethod.getReturnType();
|
||||
expression = addCollectToListIfNeed(expression, returnType, elementFactory);
|
||||
}
|
||||
codeStyleManager.shortenClassReferences(expression);
|
||||
}
|
||||
|
||||
private static PsiExpression addCollectToListIfNeed(PsiExpression expression, PsiType type, PsiElementFactory elementFactory) {
|
||||
if (type instanceof PsiClassType) {
|
||||
PsiClass resolvedParamClass = ((PsiClassType)type).resolve();
|
||||
if (resolvedParamClass != null && CommonClassNames.JAVA_LANG_ITERABLE.equals(resolvedParamClass.getQualifiedName())) {
|
||||
final PsiExpression newExpression =
|
||||
elementFactory.createExpressionFromText(expression.getText() + ".collect(java.util.stream.Collectors.toList())", null);
|
||||
return (PsiExpression) expression.replace(newExpression);
|
||||
}
|
||||
return addCollectToListIfNeed(expression, returnType);
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
private PsiExpression addCollectToListIfNeed(PsiExpression expression, PsiType type) {
|
||||
if (type instanceof PsiClassType && ((PsiClassType)type).rawType().equalsToText(CommonClassNames.JAVA_LANG_ITERABLE)) {
|
||||
return (PsiExpression)addCollectionToList(expression);
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
private PsiElement addCollectionToList(PsiElement expression) {
|
||||
return expression.replace(myElementFactory.createExpressionFromText(expression.getText() + ".collect(java.util.stream.Collectors.toList())", null));
|
||||
}
|
||||
|
||||
private static boolean isIterableMethodParameter(PsiElement listExpression, PsiExpression parameterExpression) {
|
||||
if (!(listExpression instanceof PsiExpressionList)) {
|
||||
return false;
|
||||
@@ -172,28 +167,38 @@ public class GuavaFluentIterableMethodConverters {
|
||||
return false;
|
||||
}
|
||||
final Project project = parameterExpression.getProject();
|
||||
final PsiClass fluentIterable = JavaPsiFacade.getInstance(project)
|
||||
.findClass(GuavaFluentIterableInspection.GUAVA_FLUENT_ITERABLE, GlobalSearchScope.allScope(project));
|
||||
final PsiClass fluentIterable = JavaPsiFacade.getInstance(project).findClass(GuavaFluentIterableInspection.GUAVA_FLUENT_ITERABLE,
|
||||
listExpression.getResolveScope());
|
||||
return GuavaFluentIterableInspection.isMethodWithParamAcceptsConversion((PsiMethodCallExpression)listExpression.getParent(), parameterExpression, fluentIterable);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiMethodCallExpression convertMethodCallDeep(PsiElementFactory elementFactory,
|
||||
@NotNull PsiMethodCallExpression methodCall) {
|
||||
private PsiMethodCallExpression convertMethodCallDeep(@NotNull PsiMethodCallExpression methodCall) {
|
||||
PsiMethodCallExpression newMethodCall = methodCall;
|
||||
PsiMethodCallExpression returnCall = null;
|
||||
while (true) {
|
||||
final Pair<PsiMethodCallExpression, Boolean> converted = convertMethodCall(elementFactory, newMethodCall);
|
||||
if (converted.getSecond()) {
|
||||
final PsiReferenceExpression methodExpression = newMethodCall.getMethodExpression();
|
||||
final String name = methodExpression.getReferenceName();
|
||||
PsiMethodCallExpression converted = convertFromMethodCall(newMethodCall);
|
||||
if (converted != null) {
|
||||
return returnCall;
|
||||
}
|
||||
if (TO_OTHER_COLLECTION_METHODS.containsKey(name)) {
|
||||
converted = convertToCollection(newMethodCall, name);
|
||||
}
|
||||
else {
|
||||
final FluentIterableMethodTransformer transformer = METHOD_INDEX.get(name);
|
||||
LOG.assertTrue(transformer != null, name);
|
||||
converted = transformer.transform(newMethodCall, myElementFactory);
|
||||
}
|
||||
if (converted == null) {
|
||||
return returnCall;
|
||||
}
|
||||
|
||||
if (returnCall == null) {
|
||||
returnCall = converted.getFirst();
|
||||
returnCall = converted;
|
||||
}
|
||||
if (converted.getFirst() == null) {
|
||||
return returnCall;
|
||||
}
|
||||
newMethodCall = converted.getFirst();
|
||||
newMethodCall = converted;
|
||||
final PsiExpression expression = newMethodCall.getMethodExpression().getQualifierExpression();
|
||||
if (expression instanceof PsiMethodCallExpression) {
|
||||
newMethodCall = (PsiMethodCallExpression)expression;
|
||||
@@ -203,42 +208,30 @@ public class GuavaFluentIterableMethodConverters {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Pair<PsiMethodCallExpression, Boolean> convertMethodCall(PsiElementFactory elementFactory, PsiMethodCallExpression methodCall) {
|
||||
final PsiReferenceExpression methodExpression = methodCall.getMethodExpression();
|
||||
final String name = methodExpression.getReferenceName();
|
||||
if (TO_OTHER_COLLECTION_METHODS.containsKey(name)) {
|
||||
return Pair.create(convertToCollection(methodCall, name, elementFactory), false);
|
||||
}
|
||||
else if (GuavaFluentIterableInspection.FLUENT_ITERABLE_FROM.equals(name)) {
|
||||
|
||||
private PsiMethodCallExpression convertFromMethodCall(PsiMethodCallExpression methodCall) {
|
||||
if (GuavaFluentIterableInspection.FLUENT_ITERABLE_FROM.equals(methodCall.getMethodExpression().getReferenceName())) {
|
||||
final PsiExpression[] argumentList = methodCall.getArgumentList().getExpressions();
|
||||
LOG.assertTrue(argumentList.length == 1);
|
||||
final PsiExpression expression = argumentList[0];
|
||||
|
||||
final PsiType type = expression.getType();
|
||||
LOG.assertTrue(type instanceof PsiClassType);
|
||||
final PsiClass resolvedClass = ((PsiClassType)type).resolve();
|
||||
final String newExpressionText;
|
||||
if (InheritanceUtil.isInheritor(resolvedClass, CommonClassNames.JAVA_UTIL_COLLECTION)) {
|
||||
if (InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_COLLECTION)) {
|
||||
newExpressionText = expression.getText() + ".stream()";
|
||||
} else {
|
||||
newExpressionText = "java.util.stream.StreamSupport.stream(" + expression.getText() + ".spliterator(), false)";
|
||||
}
|
||||
return Pair.create((PsiMethodCallExpression)methodCall.replace(elementFactory.createExpressionFromText(newExpressionText, null)), true);
|
||||
}
|
||||
else {
|
||||
final FluentIterableMethodTransformer transformer = METHOD_INDEX.get(name);
|
||||
LOG.assertTrue(transformer != null, name);
|
||||
final PsiMethodCallExpression transformedExpression = transformer.transform(methodCall, elementFactory);
|
||||
return Pair.create(transformedExpression, false);
|
||||
return (PsiMethodCallExpression)methodCall.replace(myElementFactory.createExpressionFromText(newExpressionText, null));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static PsiMethodCallExpression convertToCollection(final PsiMethodCallExpression methodCall,
|
||||
final String methodName,
|
||||
final PsiElementFactory elementFactory) {
|
||||
private PsiMethodCallExpression convertToCollection(final PsiMethodCallExpression methodCall,
|
||||
final String methodName) {
|
||||
final PsiExpression[] expressions = methodCall.getArgumentList().getExpressions();
|
||||
assert expressions.length < 2;
|
||||
LOG.assertTrue(expressions.length < 2);
|
||||
String template = TO_OTHER_COLLECTION_METHODS.get(methodName);
|
||||
if (expressions.length == 1) {
|
||||
template = String.format(template, expressions[0].getText());
|
||||
@@ -247,8 +240,7 @@ public class GuavaFluentIterableMethodConverters {
|
||||
if (qualifier == null) {
|
||||
return null;
|
||||
}
|
||||
final String text = qualifier.getText() + "." + template;
|
||||
final PsiExpression expression = elementFactory.createExpressionFromText(text, null);
|
||||
final PsiExpression expression = myElementFactory.createExpressionFromText(qualifier.getText() + "." + template, null);
|
||||
return (PsiMethodCallExpression)methodCall.replace(expression);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ public class GuavaFunctionAndPredicateConverter {
|
||||
if (expression instanceof PsiNewExpression) {
|
||||
final PsiAnonymousClass anonymousClass = ((PsiNewExpression)expression).getAnonymousClass();
|
||||
if (anonymousClass != null && AnonymousCanBeLambdaInspection.canBeConvertedToLambda(anonymousClass, true)) {
|
||||
final PsiLambdaExpression lambdaExpression = AnonymousCanBeLambdaInspection.replacePsiElementWithLambda(expression, true);
|
||||
final PsiExpression lambdaExpression = AnonymousCanBeLambdaInspection.replacePsiElementWithLambda(expression, true);
|
||||
LOG.assertTrue(lambdaExpression != null);
|
||||
return lambdaExpression.getText();
|
||||
}
|
||||
|
||||
+10
-1
@@ -489,7 +489,16 @@ class PseudoLambdaReplaceTemplate {
|
||||
LOG.assertTrue(method != null);
|
||||
return JavaPsiFacade.getElementFactory(expression.getProject()).createExpressionFromText(expression.getText() + "::" + method.getName(), null);
|
||||
}
|
||||
return AnonymousCanBeLambdaInspection.replacePsiElementWithLambda(expression, true);
|
||||
|
||||
final PsiType psiType = expression.getType();
|
||||
if (psiType != null) {
|
||||
PsiNewExpression newArrayExpression = (PsiNewExpression)JavaPsiFacade.getElementFactory(expression.getProject())
|
||||
.createExpressionFromText("new " + psiType.getCanonicalText() + "[]{" + expression.getText() + "}", expression);
|
||||
PsiArrayInitializerExpression initializer = newArrayExpression.getArrayInitializer();
|
||||
LOG.assertTrue(initializer != null);
|
||||
return AnonymousCanBeLambdaInspection.replacePsiElementWithLambda(initializer.getInitializers()[0], true);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -202,7 +202,7 @@ public class PackageChooserDialog extends PackageChooser {
|
||||
|
||||
private void toggleShowPathComponent(JPanel northPanel, TextFieldAction fieldAction) {
|
||||
boolean toShowTextField = !isPathShowing();
|
||||
PropertiesComponent.getInstance().setValue(FileChooserDialogImpl.FILE_CHOOSER_SHOW_PATH_PROPERTY, Boolean.toString(toShowTextField));
|
||||
PropertiesComponent.getInstance().setValue(FileChooserDialogImpl.FILE_CHOOSER_SHOW_PATH_PROPERTY, toShowTextField, true);
|
||||
myPathEditor.setVisible(toShowTextField);
|
||||
fieldAction.update();
|
||||
northPanel.revalidate();
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.javadoc.JavadocGenerationPanel">
|
||||
<grid id="a2c87" binding="myPanel" layout-manager="GridLayoutManager" row-count="8" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="7">
|
||||
<grid id="a2c87" binding="myPanel" layout-manager="GridLayoutManager" row-count="9" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="7">
|
||||
<margin top="2" left="5" bottom="0" right="5"/>
|
||||
<constraints>
|
||||
<xy x="47" y="80" width="511" height="440"/>
|
||||
<xy x="47" y="80" width="511" height="455"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="34b10" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value="eefb8"/>
|
||||
@@ -19,7 +19,7 @@
|
||||
</component>
|
||||
<component id="eefb8" class="javax.swing.JTextField" binding="myOtherOptionsField">
|
||||
<constraints>
|
||||
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
@@ -28,7 +28,7 @@
|
||||
<grid id="35953" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
@@ -172,7 +172,7 @@
|
||||
</grid>
|
||||
<component id="7c67a" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value="61630"/>
|
||||
@@ -181,7 +181,7 @@
|
||||
</component>
|
||||
<component id="61630" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myTfOutputDir">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
@@ -189,7 +189,7 @@
|
||||
</component>
|
||||
<component id="d6470" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value="c592b"/>
|
||||
@@ -198,7 +198,7 @@
|
||||
</component>
|
||||
<component id="c592b" class="javax.swing.JTextField" binding="myHeapSizeField">
|
||||
<constraints>
|
||||
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
@@ -208,7 +208,7 @@
|
||||
</component>
|
||||
<component id="61bae" class="javax.swing.JCheckBox" binding="myOpenInBrowserCheckBox">
|
||||
<constraints>
|
||||
<grid row="6" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<grid row="7" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<borderPaintedFlat value="false"/>
|
||||
@@ -221,12 +221,12 @@
|
||||
</component>
|
||||
<vspacer id="b3b4c">
|
||||
<constraints>
|
||||
<grid row="7" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
<grid row="8" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="b7872" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value="3b6ec"/>
|
||||
@@ -235,7 +235,7 @@
|
||||
</component>
|
||||
<component id="3b6ec" class="javax.swing.JTextField" binding="myLocaleTextField">
|
||||
<constraints>
|
||||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
@@ -250,6 +250,15 @@
|
||||
<text value="Include jdk and library sources in -sourcepath"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="44709" class="javax.swing.JCheckBox" binding="myLinkToJdkDocs">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<margin top="0" left="8" bottom="10" right="3"/>
|
||||
<text value="Link to JDK documentation (use -link option)"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
||||
@@ -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.
|
||||
@@ -31,6 +31,7 @@ public final class JavadocConfigurable implements Configurable {
|
||||
|
||||
public JComponent createComponent() {
|
||||
myPanel = new JavadocGenerationPanel();
|
||||
myPanel.myLinkToJdkDocs.setEnabled(myConfiguration.sdkHasJavadocUrls());
|
||||
return myPanel.myPanel;
|
||||
}
|
||||
|
||||
@@ -51,6 +52,7 @@ public final class JavadocConfigurable implements Configurable {
|
||||
configuration.OPTION_DOCUMENT_TAG_DEPRECATED = myPanel.myTagDeprecated.isSelected();
|
||||
configuration.OPTION_DEPRECATED_LIST = myPanel.myDeprecatedList.isSelected();
|
||||
configuration.OPTION_INCLUDE_LIBS = myPanel.myIncludeLibraryCb.isSelected();
|
||||
configuration.OPTION_LINK_TO_JDK_DOCS = myPanel.myLinkToJdkDocs.isSelected();
|
||||
}
|
||||
|
||||
public void loadFrom(JavadocConfiguration configuration) {
|
||||
@@ -74,6 +76,7 @@ public final class JavadocConfigurable implements Configurable {
|
||||
myPanel.myDeprecatedList.setEnabled(myPanel.myTagDeprecated.isSelected());
|
||||
|
||||
myPanel.myIncludeLibraryCb.setSelected(configuration.OPTION_INCLUDE_LIBS);
|
||||
myPanel.myLinkToJdkDocs.setSelected(configuration.OPTION_LINK_TO_JDK_DOCS);
|
||||
}
|
||||
|
||||
public boolean isModified() {
|
||||
@@ -95,6 +98,7 @@ public final class JavadocConfigurable implements Configurable {
|
||||
isModified |= myPanel.myTagDeprecated.isSelected() != configuration.OPTION_DOCUMENT_TAG_DEPRECATED;
|
||||
isModified |= myPanel.myDeprecatedList.isSelected() != configuration.OPTION_DEPRECATED_LIST;
|
||||
isModified |= myPanel.myIncludeLibraryCb.isSelected() != configuration.OPTION_INCLUDE_LIBS;
|
||||
isModified |= myPanel.myLinkToJdkDocs.isSelected() != configuration.OPTION_LINK_TO_JDK_DOCS;
|
||||
|
||||
return isModified;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ import com.intellij.openapi.roots.*;
|
||||
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.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.PathsList;
|
||||
@@ -85,6 +86,7 @@ public class JavadocConfiguration implements ModuleRunProfile, JDOMExternalizabl
|
||||
private AnalysisScope myGenerationScope;
|
||||
private static final Logger LOGGER = Logger.getInstance("#" + JavadocConfiguration.class.getName());
|
||||
public boolean OPTION_INCLUDE_LIBS = false;
|
||||
public boolean OPTION_LINK_TO_JDK_DOCS = false;
|
||||
|
||||
public void setGenerationScope(AnalysisScope generationScope) {
|
||||
myGenerationScope = generationScope;
|
||||
@@ -128,6 +130,10 @@ public class JavadocConfiguration implements ModuleRunProfile, JDOMExternalizabl
|
||||
public void writeExternal(Element element) throws WriteExternalException {
|
||||
DefaultJDOMExternalizer.writeExternal(this, element);
|
||||
}
|
||||
|
||||
public boolean sdkHasJavadocUrls() {
|
||||
return getSdk(myProject).getRootProvider().getFiles(JavadocOrderRootType.getInstance()).length > 0;
|
||||
}
|
||||
|
||||
public static Sdk getSdk(@NotNull Project project) {
|
||||
return PathUtilEx.getAnyJdk(project);
|
||||
@@ -295,6 +301,14 @@ public class JavadocConfiguration implements ModuleRunProfile, JDOMExternalizabl
|
||||
LOGGER.error(e);
|
||||
}
|
||||
|
||||
if (OPTION_LINK_TO_JDK_DOCS) {
|
||||
VirtualFile[] docUrls = jdk.getRootProvider().getFiles(JavadocOrderRootType.getInstance());
|
||||
for (VirtualFile docUrl : docUrls) {
|
||||
parameters.add("-link");
|
||||
parameters.add(VfsUtil.toUri(docUrl).toString());
|
||||
}
|
||||
}
|
||||
|
||||
final PathsList classPath;
|
||||
final OrderEnumerator orderEnumerator = ProjectRootManager.getInstance(myProject).orderEntries(modules);
|
||||
if (jdk.getSdkType() instanceof JavaSdk) {
|
||||
|
||||
@@ -48,6 +48,7 @@ final class JavadocGenerationPanel extends JPanel {
|
||||
JCheckBox myOpenInBrowserCheckBox;
|
||||
JTextField myLocaleTextField;
|
||||
JCheckBox myIncludeLibraryCb;
|
||||
JCheckBox myLinkToJdkDocs;
|
||||
|
||||
JavadocGenerationPanel() {
|
||||
myTfOutputDir.addBrowseFolderListener(JavadocBundle.message("javadoc.generate.output.directory.browse"), null, null, FileChooserDescriptorFactory.createSingleFolderDescriptor());
|
||||
|
||||
@@ -27,8 +27,10 @@ import com.intellij.lang.LangBundle;
|
||||
import com.intellij.lang.LanguageCommenters;
|
||||
import com.intellij.lang.documentation.CodeDocumentationProvider;
|
||||
import com.intellij.lang.documentation.CompositeDocumentationProvider;
|
||||
import com.intellij.lang.documentation.DocumentationProviderEx;
|
||||
import com.intellij.lang.documentation.ExternalDocumentationProvider;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.project.IndexNotReadyException;
|
||||
@@ -66,7 +68,7 @@ import java.util.Set;
|
||||
/**
|
||||
* @author Maxim.Mossienko
|
||||
*/
|
||||
public class JavaDocumentationProvider implements CodeDocumentationProvider, ExternalDocumentationProvider {
|
||||
public class JavaDocumentationProvider extends DocumentationProviderEx implements CodeDocumentationProvider, ExternalDocumentationProvider {
|
||||
private static final Logger LOG = Logger.getInstance("#" + JavaDocumentationProvider.class.getName());
|
||||
|
||||
private static final String LINE_SEPARATOR = "\n";
|
||||
@@ -793,6 +795,19 @@ public class JavaDocumentationProvider implements CodeDocumentationProvider, Ext
|
||||
public void promptToConfigureDocumentation(PsiElement element) {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement getCustomDocumentationElement(@NotNull Editor editor, @NotNull PsiFile file, @Nullable PsiElement contextElement) {
|
||||
PsiDocComment docComment = PsiTreeUtil.getParentOfType(contextElement, PsiDocComment.class, false);
|
||||
if (docComment != null && JavaDocUtil.isInsidePackageInfo(docComment)) {
|
||||
PsiDirectory directory = file.getContainingDirectory();
|
||||
if (directory != null) {
|
||||
return JavaDirectoryService.getInstance().getPackage(directory);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String fetchExternalJavadoc(PsiElement element, final Project project, final List<String> docURLs) {
|
||||
return fetchExternalJavadoc(element, docURLs, new JavaDocExternalFilter(project));
|
||||
}
|
||||
|
||||
@@ -27,11 +27,17 @@ public abstract class ExternalLibraryDescriptor {
|
||||
private final String myLibraryGroupId;
|
||||
private final String myLibraryArtifactId;
|
||||
private final String myMinVersion;
|
||||
private final String myMaxVersion;
|
||||
|
||||
public ExternalLibraryDescriptor(@NotNull String libraryGroupId, @NotNull String libraryArtifactId, @Nullable String minVersion) {
|
||||
public ExternalLibraryDescriptor(String libraryGroupId, String libraryArtifactId) {
|
||||
this(libraryGroupId, libraryArtifactId, null, null);
|
||||
}
|
||||
|
||||
public ExternalLibraryDescriptor(@NotNull String libraryGroupId, @NotNull String libraryArtifactId, @Nullable String minVersion, @Nullable String maxVersion) {
|
||||
myLibraryGroupId = libraryGroupId;
|
||||
myLibraryArtifactId = libraryArtifactId;
|
||||
myMinVersion = minVersion;
|
||||
myMaxVersion = maxVersion;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -49,6 +55,11 @@ public abstract class ExternalLibraryDescriptor {
|
||||
return myMinVersion;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getMaxVersion() {
|
||||
return myMaxVersion;
|
||||
}
|
||||
|
||||
public String getPresentableName() {
|
||||
return myLibraryArtifactId;
|
||||
}
|
||||
|
||||
+16
-10
@@ -20,11 +20,17 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Provides methods to perform high-level modifications of project configuration accordingly with dependency management system used in the
|
||||
* project. E.g. if the project is imported from Maven the methods will modify pom.xml files and invoke reimporting to update IDEA's
|
||||
* project model. Since importing the changes to IDEA's project model may take a while the method work asynchronously and returns
|
||||
* {@link Promise} objects which may be used to be notified when the project configuration is finally updated.
|
||||
*
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class ProjectModelModificationService {
|
||||
@@ -32,22 +38,22 @@ public abstract class ProjectModelModificationService {
|
||||
return ServiceManager.getService(project, ProjectModelModificationService.class);
|
||||
}
|
||||
|
||||
public void addDependency(@NotNull Module from, @NotNull Module to) {
|
||||
addDependency(from, to, DependencyScope.COMPILE);
|
||||
public Promise<Void> addDependency(@NotNull Module from, @NotNull Module to) {
|
||||
return addDependency(from, to, DependencyScope.COMPILE);
|
||||
}
|
||||
|
||||
public abstract void addDependency(@NotNull Module from, @NotNull Module to, @NotNull DependencyScope scope);
|
||||
public abstract Promise<Void> addDependency(@NotNull Module from, @NotNull Module to, @NotNull DependencyScope scope);
|
||||
|
||||
public void addDependency(@NotNull Module from, @NotNull ExternalLibraryDescriptor libraryDescriptor) {
|
||||
addDependency(from, libraryDescriptor, DependencyScope.COMPILE);
|
||||
public Promise<Void> addDependency(@NotNull Module from, @NotNull ExternalLibraryDescriptor libraryDescriptor) {
|
||||
return addDependency(from, libraryDescriptor, DependencyScope.COMPILE);
|
||||
}
|
||||
|
||||
public void addDependency(Module from, ExternalLibraryDescriptor descriptor, DependencyScope scope) {
|
||||
addDependency(Collections.singletonList(from), descriptor, scope);
|
||||
public Promise<Void> addDependency(@NotNull Module from, @NotNull ExternalLibraryDescriptor descriptor, @NotNull DependencyScope scope) {
|
||||
return addDependency(Collections.singletonList(from), descriptor, scope);
|
||||
}
|
||||
|
||||
public abstract void addDependency(@NotNull Collection<Module> from, @NotNull ExternalLibraryDescriptor libraryDescriptor,
|
||||
@NotNull DependencyScope scope);
|
||||
public abstract Promise<Void> addDependency(@NotNull Collection<Module> from, @NotNull ExternalLibraryDescriptor libraryDescriptor,
|
||||
@NotNull DependencyScope scope);
|
||||
|
||||
public abstract void addDependency(@NotNull Module from, @NotNull Library library, @NotNull DependencyScope scope);
|
||||
public abstract Promise<Void> addDependency(@NotNull Module from, @NotNull Library library, @NotNull DependencyScope scope);
|
||||
}
|
||||
|
||||
@@ -19,20 +19,53 @@ import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Register implementation of this extension to support custom dependency management system for {@link ProjectModelModificationService}.
|
||||
*
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class ProjectModelModifier {
|
||||
public static final ExtensionPointName<ProjectModelModifier> EP_NAME = ExtensionPointName.create("com.intellij.projectModelModifier");
|
||||
|
||||
public abstract boolean addModuleDependency(@NotNull Module from, @NotNull Module to, @NotNull DependencyScope scope);
|
||||
/**
|
||||
* Implementation of this method should add dependency from module {@code from} to module {@code to} with scope {@code scope} accordingly
|
||||
* to this dependencies management system. If it takes some time to propagate changes in the external project configuration to IDEA's
|
||||
* project model the method may schedule this work for asynchronous execution and return {@link Promise} instance which will be fulfilled
|
||||
* when the work is done.
|
||||
* @return {@link Promise} instance if dependencies between these modules can be handled by this dependencies management system or
|
||||
* {@code null} otherwise
|
||||
*/
|
||||
@Nullable
|
||||
public abstract Promise<Void> addModuleDependency(@NotNull Module from, @NotNull Module to, @NotNull DependencyScope scope);
|
||||
|
||||
public abstract boolean addExternalLibraryDependency(@NotNull Collection<Module> modules,
|
||||
@NotNull ExternalLibraryDescriptor descriptor,
|
||||
@NotNull DependencyScope scope);
|
||||
/**
|
||||
* Implementation of this method should add dependency from modules {@code modules} to an external library with scope {@code scope} accordingly
|
||||
* to this dependencies management system. If it takes some time to propagate changes in the external project configuration to IDEA's
|
||||
* project model the method may schedule this work for asynchronous execution and return {@link Promise} instance which will be fulfilled
|
||||
* when the work is done.
|
||||
*
|
||||
* @return {@link Promise} instance if dependencies of these modules can be handled by this dependencies management system or
|
||||
* {@code null} otherwise
|
||||
*/
|
||||
@Nullable
|
||||
public abstract Promise<Void> addExternalLibraryDependency(@NotNull Collection<Module> modules,
|
||||
@NotNull ExternalLibraryDescriptor descriptor,
|
||||
@NotNull DependencyScope scope);
|
||||
|
||||
public abstract boolean addLibraryDependency(@NotNull Module from, @NotNull Library library, @NotNull DependencyScope scope);
|
||||
/**
|
||||
* Implementation of this method should add dependency from module {@code from} to {@code library} with scope {@code scope} accordingly
|
||||
* to this dependencies management system. If it takes some time to propagate changes in the external project configuration to IDEA's
|
||||
* project model the method may schedule this work for asynchronous execution and return {@link Promise} instance which will be fulfilled
|
||||
* when the work is done.
|
||||
*
|
||||
* @return {@link Promise} instance if dependencies between these modules can be handled by this dependencies management system or
|
||||
* {@code null} otherwise
|
||||
*/
|
||||
@Nullable
|
||||
public abstract Promise<Void> addLibraryDependency(@NotNull Module from, @NotNull Library library, @NotNull DependencyScope scope);
|
||||
}
|
||||
|
||||
+12
-10
@@ -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.
|
||||
@@ -104,15 +104,17 @@ public class CompilerModuleExtensionImpl extends CompilerModuleExtension {
|
||||
@Override
|
||||
public void writeExternal(final Element element) throws WriteExternalException {
|
||||
assert !myDisposed;
|
||||
if (myCompilerOutput != null) {
|
||||
final Element pathElement = new Element(OUTPUT_TAG);
|
||||
pathElement.setAttribute(ATTRIBUTE_URL, myCompilerOutput);
|
||||
element.addContent(pathElement);
|
||||
}
|
||||
if (myCompilerOutputForTests != null) {
|
||||
final Element pathElement = new Element(TEST_OUTPUT_TAG);
|
||||
pathElement.setAttribute(ATTRIBUTE_URL, myCompilerOutputForTests);
|
||||
element.addContent(pathElement);
|
||||
if (!myInheritedCompilerOutput) {
|
||||
if (myCompilerOutput != null) {
|
||||
final Element pathElement = new Element(OUTPUT_TAG);
|
||||
pathElement.setAttribute(ATTRIBUTE_URL, myCompilerOutput);
|
||||
element.addContent(pathElement);
|
||||
}
|
||||
if (myCompilerOutputForTests != null) {
|
||||
final Element pathElement = new Element(TEST_OUTPUT_TAG);
|
||||
pathElement.setAttribute(ATTRIBUTE_URL, myCompilerOutputForTests);
|
||||
element.addContent(pathElement);
|
||||
}
|
||||
}
|
||||
element.setAttribute(INHERIT_COMPILER_OUTPUT, String.valueOf(myInheritedCompilerOutput));
|
||||
if (myExcludeOutput) {
|
||||
|
||||
@@ -55,7 +55,6 @@ public class CompilerProjectExtensionImpl extends CompilerProjectExtension {
|
||||
final Element outputPathChild = element.getChild(OUTPUT_TAG);
|
||||
if (outputPathChild != null) {
|
||||
String outputPath = outputPathChild.getAttributeValue(URL);
|
||||
assert myCompilerOutput == null;
|
||||
myCompilerOutput = VirtualFilePointerManager.getInstance().create(outputPath, myProject, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
|
||||
import com.intellij.openapi.roots.libraries.LibraryUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -45,15 +46,15 @@ public class IdeaProjectModelModifier extends ProjectModelModifier {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addModuleDependency(@NotNull Module from, @NotNull Module to, @NotNull DependencyScope scope) {
|
||||
public Promise<Void> addModuleDependency(@NotNull Module from, @NotNull Module to, @NotNull DependencyScope scope) {
|
||||
ModuleRootModificationUtil.addDependency(from, to, scope, false);
|
||||
return true;
|
||||
return Promise.DONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addExternalLibraryDependency(@NotNull final Collection<Module> modules,
|
||||
@NotNull final ExternalLibraryDescriptor descriptor,
|
||||
@NotNull final DependencyScope scope) {
|
||||
public Promise<Void> addExternalLibraryDependency(@NotNull final Collection<Module> modules,
|
||||
@NotNull final ExternalLibraryDescriptor descriptor,
|
||||
@NotNull final DependencyScope scope) {
|
||||
List<String> defaultRoots = descriptor.getLibraryClassesRoots();
|
||||
Module firstModule = ContainerUtil.getFirstItem(modules);
|
||||
LOG.assertTrue(firstModule != null);
|
||||
@@ -82,12 +83,12 @@ public class IdeaProjectModelModifier extends ProjectModelModifier {
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return Promise.DONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addLibraryDependency(@NotNull Module from, @NotNull Library library, @NotNull DependencyScope scope) {
|
||||
public Promise<Void> addLibraryDependency(@NotNull Module from, @NotNull Library library, @NotNull DependencyScope scope) {
|
||||
OrderEntryUtil.addLibraryToRoots(from, library);
|
||||
return true;
|
||||
return Promise.DONE;
|
||||
}
|
||||
}
|
||||
|
||||
+16
-9
@@ -23,6 +23,7 @@ import com.intellij.openapi.roots.ProjectModelModificationService;
|
||||
import com.intellij.openapi.roots.ProjectModelModifier;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -37,30 +38,36 @@ public class ProjectModelModificationServiceImpl extends ProjectModelModificatio
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDependency(@NotNull Module from, @NotNull Module to, @NotNull DependencyScope scope) {
|
||||
public Promise<Void> addDependency(@NotNull Module from, @NotNull Module to, @NotNull DependencyScope scope) {
|
||||
for (ProjectModelModifier modifier : getModelModifiers()) {
|
||||
if (modifier.addModuleDependency(from, to, scope)) {
|
||||
return;
|
||||
Promise<Void> promise = modifier.addModuleDependency(from, to, scope);
|
||||
if (promise != null) {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
return Promise.REJECTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDependency(@NotNull Collection<Module> from, @NotNull ExternalLibraryDescriptor libraryDescriptor, @NotNull DependencyScope scope) {
|
||||
public Promise<Void> addDependency(@NotNull Collection<Module> from, @NotNull ExternalLibraryDescriptor libraryDescriptor, @NotNull DependencyScope scope) {
|
||||
for (ProjectModelModifier modifier : getModelModifiers()) {
|
||||
if (modifier.addExternalLibraryDependency(from, libraryDescriptor, scope)) {
|
||||
return;
|
||||
Promise<Void> promise = modifier.addExternalLibraryDependency(from, libraryDescriptor, scope);
|
||||
if (promise != null) {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
return Promise.REJECTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDependency(@NotNull Module from, @NotNull Library library, @NotNull DependencyScope scope) {
|
||||
public Promise<Void> addDependency(@NotNull Module from, @NotNull Library library, @NotNull DependencyScope scope) {
|
||||
for (ProjectModelModifier modifier : getModelModifiers()) {
|
||||
if (modifier.addLibraryDependency(from, library, scope)) {
|
||||
return;
|
||||
Promise<Void> promise = modifier.addLibraryDependency(from, library, scope);
|
||||
if (promise != null) {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
return Promise.REJECTED;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -69,6 +69,23 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
private Map<IElementType, Wrap> myPreferredWraps;
|
||||
private AbstractJavaBlock myParentBlock;
|
||||
|
||||
private BlockFactory myBlockFactory = new BlockFactory() {
|
||||
@Override
|
||||
public Block createBlock(ASTNode node, Indent indent, Alignment alignment, Wrap wrap) {
|
||||
return new SimpleJavaBlock(node, wrap, AlignmentStrategy.wrap(alignment), indent, mySettings, myJavaSettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonCodeStyleSettings getSettings() {
|
||||
return mySettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaCodeStyleSettings getJavaSettings() {
|
||||
return myJavaSettings;
|
||||
}
|
||||
};
|
||||
|
||||
protected AbstractJavaBlock(@NotNull final ASTNode node,
|
||||
final Wrap wrap,
|
||||
final Alignment alignment,
|
||||
@@ -476,12 +493,11 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
if (nodeType == JavaElementType.POLYADIC_EXPRESSION) nodeType = JavaElementType.BINARY_EXPRESSION;
|
||||
|
||||
if (childType == JavaTokenType.LBRACE && nodeType == JavaElementType.ARRAY_INITIALIZER_EXPRESSION) {
|
||||
final Wrap wrap = Wrap.createWrap(getWrapType(mySettings.ARRAY_INITIALIZER_WRAP), false);
|
||||
child = processParenthesisBlock(JavaTokenType.LBRACE, JavaTokenType.RBRACE,
|
||||
result,
|
||||
child,
|
||||
WrappingStrategy.createDoNotWrapCommaStrategy(wrap),
|
||||
mySettings.ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION);
|
||||
ArrayInitializerBlocksBuilder builder = new ArrayInitializerBlocksBuilder(myNode, myBlockFactory);
|
||||
List<Block> newlyCreated = builder.buildBlocks();
|
||||
|
||||
child = myNode.getLastChildNode();
|
||||
result.addAll(newlyCreated);
|
||||
}
|
||||
else if (childType == JavaTokenType.LBRACE && nodeType == JavaElementType.ANNOTATION_ARRAY_INITIALIZER) {
|
||||
final Wrap wrap = Wrap.createWrap(getWrapType(mySettings.ARRAY_INITIALIZER_WRAP), false);
|
||||
@@ -1213,14 +1229,15 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
|
||||
return null;
|
||||
}
|
||||
|
||||
private ChildAlignmentStrategyProvider getStrategyProvider() {
|
||||
protected ChildAlignmentStrategyProvider getStrategyProvider() {
|
||||
if (mySettings.ALIGN_GROUP_FIELD_DECLARATIONS && myNode.getElementType() == JavaElementType.CLASS) {
|
||||
return new SubsequentFieldAligner(mySettings);
|
||||
}
|
||||
|
||||
ASTNode parent = myNode.getTreeParent();
|
||||
IElementType parentType = parent != null ? parent.getElementType() : null;
|
||||
if (mySettings.ALIGN_CONSECUTIVE_VARIABLE_DECLARATIONS && parentType == JavaElementType.METHOD) {
|
||||
if (mySettings.ALIGN_CONSECUTIVE_VARIABLE_DECLARATIONS
|
||||
&& (parentType == JavaElementType.METHOD || myNode instanceof PsiCodeBlock)) {
|
||||
return new SubsequentVariablesAligner();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.psi.formatter.java;
|
||||
|
||||
import com.intellij.formatting.Alignment;
|
||||
import com.intellij.formatting.Block;
|
||||
import com.intellij.formatting.Indent;
|
||||
import com.intellij.formatting.Wrap;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.psi.JavaTokenType;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiWhiteSpace;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.psi.formatter.java.JavaFormatterUtil.getWrapType;
|
||||
|
||||
public class ArrayInitializerBlocksBuilder {
|
||||
private final ASTNode myNode;
|
||||
private final BlockFactory myBlockFactory;
|
||||
private final CommonCodeStyleSettings mySettings;
|
||||
|
||||
public ArrayInitializerBlocksBuilder(ASTNode node, BlockFactory blockFactory) {
|
||||
myNode = node;
|
||||
myBlockFactory = blockFactory;
|
||||
mySettings = myBlockFactory.getSettings();
|
||||
}
|
||||
|
||||
public List<Block> buildBlocks() {
|
||||
Wrap wrap = Wrap.createWrap(getWrapType(mySettings.ARRAY_INITIALIZER_WRAP), false);
|
||||
Alignment alignment = mySettings.ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION ? Alignment.createAlignment() : null;
|
||||
|
||||
ChildrenBlocksBuilder.Config config = new ChildrenBlocksBuilder.Config()
|
||||
.setDefaultIndent(Indent.getContinuationWithoutFirstIndent())
|
||||
.setIndent(JavaTokenType.RBRACE, Indent.getNoneIndent())
|
||||
.setIndent(JavaTokenType.LBRACE, Indent.getNoneIndent())
|
||||
|
||||
.setDefaultWrap(wrap)
|
||||
.setNoWrap(JavaTokenType.COMMA)
|
||||
.setNoWrap(JavaTokenType.RBRACE)
|
||||
.setNoWrap(JavaTokenType.LBRACE)
|
||||
|
||||
.setDefaultAlignment(alignment)
|
||||
.setNoAlignment(JavaTokenType.COMMA)
|
||||
.setNoAlignment(JavaTokenType.LBRACE)
|
||||
.setAlignmentIf(JavaTokenType.RBRACE, alignment, new Condition<ASTNode>() {
|
||||
@Override
|
||||
public boolean value(ASTNode node) {
|
||||
PsiElement prev = PsiTreeUtil.skipSiblingsBackward(node.getPsi(), PsiWhiteSpace.class);
|
||||
if (prev == null) return false;
|
||||
return prev.getNode().getElementType() == JavaTokenType.COMMA;
|
||||
}
|
||||
});
|
||||
|
||||
return config.createBuilder().buildNodeChildBlocks(myNode, myBlockFactory);
|
||||
}
|
||||
}
|
||||
@@ -17,9 +17,7 @@ package com.intellij.psi.formatter.java;
|
||||
|
||||
import com.intellij.formatting.*;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.JavaTokenType;
|
||||
import com.intellij.psi.PsiStatement;
|
||||
import com.intellij.psi.PsiTypeElement;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.psi.formatter.FormatterUtil;
|
||||
@@ -255,8 +253,8 @@ public class BlockContainingJavaBlock extends AbstractJavaBlock{
|
||||
if (prevBlock instanceof ASTBlock && nextBlock instanceof ASTBlock) {
|
||||
ASTNode prevNode = ((ASTBlock)prevBlock).getNode();
|
||||
ASTNode nextNode = ((ASTBlock)nextBlock).getNode();
|
||||
if (prevNode != null && nextNode != null && prevNode.getElementType() == JavaTokenType.RPARENTH
|
||||
&& nextNode.getElementType() != JavaTokenType.LBRACE)
|
||||
if (prevNode != null && nextNode != null && prevNode.getElementType() == JavaTokenType.RPARENTH
|
||||
&& nextNode.getElementType() != JavaTokenType.LBRACE)
|
||||
{
|
||||
useExternalIndent = true;
|
||||
}
|
||||
@@ -267,7 +265,7 @@ public class BlockContainingJavaBlock extends AbstractJavaBlock{
|
||||
return new ChildAttributes(getCodeBlockChildExternalIndent(newChildIndex), null);
|
||||
}
|
||||
else {
|
||||
return new ChildAttributes(myIndentsBefore.get(newChildIndex), null);
|
||||
return new ChildAttributes(myIndentsBefore.get(newChildIndex), getUsedAlignment(newChildIndex));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.psi.formatter.java;
|
||||
|
||||
import com.intellij.formatting.Alignment;
|
||||
import com.intellij.formatting.Block;
|
||||
import com.intellij.formatting.Indent;
|
||||
import com.intellij.formatting.Wrap;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
|
||||
public interface BlockFactory {
|
||||
|
||||
Block createBlock(ASTNode node, Indent indent, Alignment alignment, Wrap wrap);
|
||||
|
||||
CommonCodeStyleSettings getSettings();
|
||||
|
||||
JavaCodeStyleSettings getJavaSettings();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.psi.formatter.java;
|
||||
|
||||
import com.intellij.formatting.Alignment;
|
||||
import com.intellij.formatting.Block;
|
||||
import com.intellij.formatting.Indent;
|
||||
import com.intellij.formatting.Wrap;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.psi.formatter.FormatterUtil;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChildrenBlocksBuilder {
|
||||
private Config myConfig;
|
||||
|
||||
private ChildrenBlocksBuilder(Config builder) {
|
||||
myConfig = builder;
|
||||
}
|
||||
|
||||
public List<Block> buildNodeChildBlocks(ASTNode node, BlockFactory factory) {
|
||||
List<Block> blocks = ContainerUtil.newArrayList();
|
||||
|
||||
for (ASTNode child : node.getChildren(null)) {
|
||||
if (FormatterUtil.isWhitespaceOrEmpty(child)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Alignment alignment = myConfig.getAlignment(child);
|
||||
|
||||
IElementType type = child.getElementType();
|
||||
Indent indent = myConfig.getIndent(type);
|
||||
Wrap wrap = myConfig.getWrap(type);
|
||||
|
||||
blocks.add(factory.createBlock(child, indent, alignment, wrap));
|
||||
}
|
||||
|
||||
return blocks;
|
||||
}
|
||||
|
||||
public static class Config {
|
||||
private static final Alignment NO_ALIGNMENT = Alignment.createAlignment();
|
||||
private static final Wrap NO_WRAP = Wrap.createWrap(0, false);
|
||||
|
||||
private Map<IElementType, Alignment> myAlignments = ContainerUtil.newHashMap();
|
||||
private Map<IElementType, Indent> myIndents = ContainerUtil.newHashMap();
|
||||
private Map<IElementType, Wrap> myWraps = ContainerUtil.newHashMap();
|
||||
|
||||
private Map<IElementType, Condition<ASTNode>> myApplyAlignCondition = ContainerUtil.newHashMap();
|
||||
|
||||
private Alignment myDefaultAlignment;
|
||||
private Indent myDefaultIndent;
|
||||
private Wrap myDefaultWrap;
|
||||
|
||||
public ChildrenBlocksBuilder createBuilder() {
|
||||
return new ChildrenBlocksBuilder(this);
|
||||
}
|
||||
|
||||
public Config setDefaultAlignment(Alignment alignment) {
|
||||
myDefaultAlignment = alignment;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Config setDefaultWrap(Wrap wrap) {
|
||||
myDefaultWrap = wrap;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Config setDefaultIndent(Indent indent) {
|
||||
myDefaultIndent = indent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Config setAlignment(@NotNull IElementType elementType, @NotNull Alignment alignment) {
|
||||
myAlignments.put(elementType, alignment);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Config setNoAlignment(IElementType elementType) {
|
||||
myAlignments.put(elementType, NO_ALIGNMENT);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Config setAlignmentIf(IElementType elementType, Alignment alignment, Condition<ASTNode> applyAlignCondition) {
|
||||
myAlignments.put(elementType, alignment);
|
||||
myApplyAlignCondition.put(elementType, applyAlignCondition);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Config setIndent(IElementType elementType, Indent indent) {
|
||||
myIndents.put(elementType, indent);
|
||||
return this;
|
||||
}
|
||||
|
||||
private Indent getIndent(IElementType elementType) {
|
||||
Indent indent = myIndents.get(elementType);
|
||||
return indent != null ? indent : myDefaultIndent;
|
||||
}
|
||||
|
||||
private Alignment getAlignment(ASTNode node) {
|
||||
IElementType elementType = node.getElementType();
|
||||
Alignment alignment = myAlignments.get(elementType);
|
||||
if (alignment != null) {
|
||||
Condition<ASTNode> applyAlignCondition = myApplyAlignCondition.get(elementType);
|
||||
if (applyAlignCondition == null || applyAlignCondition.value(node)) {
|
||||
return alignment == NO_ALIGNMENT ? null : alignment;
|
||||
}
|
||||
}
|
||||
return myDefaultAlignment;
|
||||
}
|
||||
|
||||
private Wrap getWrap(IElementType elementType) {
|
||||
Wrap wrap = myWraps.get(elementType);
|
||||
if (wrap == NO_WRAP) return null;
|
||||
return wrap != null ? wrap : myDefaultWrap;
|
||||
}
|
||||
|
||||
public Config setNoWrap(IElementType elementType) {
|
||||
myWraps.put(elementType, NO_WRAP);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -18,11 +18,7 @@ package com.intellij.psi.formatter.java;
|
||||
import com.intellij.formatting.*;
|
||||
import com.intellij.formatting.alignment.AlignmentStrategy;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.JavaTokenType;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiSyntheticClass;
|
||||
import com.intellij.psi.TokenType;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.psi.formatter.FormatterUtil;
|
||||
@@ -115,8 +111,10 @@ public class CodeBlockBlock extends AbstractJavaBlock {
|
||||
state = INSIDE_BODY;
|
||||
}
|
||||
|
||||
ChildAlignmentStrategyProvider provider = getStrategyProvider();
|
||||
while (child != null) {
|
||||
if (!FormatterUtil.containsWhiteSpacesOnly(child) && child.getTextLength() > 0) {
|
||||
AlignmentStrategy alignmentStrategy = provider.getNextChildStrategy(child);
|
||||
final Indent indent = calcCurrentIndent(child, state);
|
||||
state = calcNewState(child, state);
|
||||
|
||||
@@ -132,7 +130,7 @@ public class CodeBlockBlock extends AbstractJavaBlock {
|
||||
child = composeCodeBlock(result, child, indent, myChildrenIndent, childWrap);
|
||||
}
|
||||
else {
|
||||
child = processChild(result, child, chooseAlignment(child, childAlignment), childWrap, indent);
|
||||
child = processChild(result, child, alignmentStrategy, childWrap, indent);
|
||||
}
|
||||
}
|
||||
if (child != null) {
|
||||
@@ -141,26 +139,6 @@ public class CodeBlockBlock extends AbstractJavaBlock {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Alignment chooseAlignment(@NotNull ASTNode child, @Nullable Alignment defaultAlignment) {
|
||||
if (defaultAlignment != null) {
|
||||
return defaultAlignment;
|
||||
}
|
||||
// Take special care about anonymous classes.
|
||||
if (child.getElementType() != JavaTokenType.RBRACE) {
|
||||
return defaultAlignment;
|
||||
}
|
||||
final ASTNode parent = child.getTreeParent();
|
||||
if (parent == null || parent.getElementType() != JavaElementType.ANONYMOUS_CLASS) {
|
||||
return defaultAlignment;
|
||||
}
|
||||
final ASTNode whiteSpaceCandidate = parent.getTreePrev();
|
||||
if (whiteSpaceCandidate == null || whiteSpaceCandidate.getElementType() != TokenType.WHITE_SPACE) {
|
||||
return defaultAlignment;
|
||||
}
|
||||
return StringUtil.countNewLines(whiteSpaceCandidate.getChars()) > 0 ? myAlignment : defaultAlignment;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ASTNode processCaseAndStatementAfter(final ArrayList<Block> result,
|
||||
ASTNode child,
|
||||
|
||||
+13
-5
@@ -51,11 +51,19 @@ public class JavaLineWrapPositionStrategy extends DefaultLineWrapPositionStrateg
|
||||
private static boolean isInsideTag(Document document, int offset, String tagStart, String tagEnd) {
|
||||
CharSequence sequence = document.getCharsSequence();
|
||||
|
||||
int lineNumber = document.getLineNumber(offset);
|
||||
int lineStartOffset = document.getLineStartOffset(lineNumber);
|
||||
int lineEndOffset = document.getLineEndOffset(lineNumber);
|
||||
final int lineNumber = document.getLineNumber(offset);
|
||||
final int lineStartOffset = document.getLineStartOffset(lineNumber);
|
||||
final int lineEndOffset = document.getLineEndOffset(lineNumber);
|
||||
|
||||
return CharArrayUtil.indexOf(sequence, tagStart, lineStartOffset, offset) > 0
|
||||
&& CharArrayUtil.indexOf(sequence, tagEnd, offset, lineEndOffset) > 0;
|
||||
int searchStartOffset = lineStartOffset;
|
||||
int searchEndOffset = lineEndOffset;
|
||||
|
||||
if (lineEndOffset - lineStartOffset > 200) {
|
||||
searchStartOffset = Math.max(offset - 100, lineStartOffset);
|
||||
searchEndOffset = Math.min(offset + 100, lineEndOffset);
|
||||
}
|
||||
|
||||
return CharArrayUtil.indexOf(sequence, tagStart, searchStartOffset, offset) > 0
|
||||
&& CharArrayUtil.indexOf(sequence, tagEnd, offset, searchEndOffset) > 0;
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,6 @@ public class HelpID {
|
||||
public static final String METHOD_DUPLICATES = "refactoring.replaceMethodCodeDuplicates";
|
||||
public static final String CHANGE_CLASS_SIGNATURE = "change.class.signature.dialog";
|
||||
public static final String MOVE_INSTANCE_METHOD = "refactoring.moveInstMethod";
|
||||
public static final String INVERT_BOOLEAN = "refactoring.invertBoolean";
|
||||
public static final String EXTRACT_METHOD_OBJECT = "refactoring.extractMethodObject";
|
||||
public static final String REPLACE_CONSTRUCTOR_WITH_BUILDER = "refactoring.replaceConstructorWithBuilder";
|
||||
@NonNls public static final String ExtractClass = "refactorj.extractClass";
|
||||
|
||||
@@ -193,7 +193,7 @@ public class ExtractMethodDialog extends DialogWrapper implements AbstractExtrac
|
||||
}
|
||||
|
||||
if (myGenerateAnnotations != null && myGenerateAnnotations.isEnabled()) {
|
||||
PropertiesComponent.getInstance(myProject).setValue(EXTRACT_METHOD_GENERATE_ANNOTATIONS, String.valueOf(myGenerateAnnotations.isSelected()));
|
||||
PropertiesComponent.getInstance(myProject).setValue(EXTRACT_METHOD_GENERATE_ANNOTATIONS, myGenerateAnnotations.isSelected(), true);
|
||||
}
|
||||
super.doOKAction();
|
||||
}
|
||||
|
||||
+6
-8
@@ -63,14 +63,12 @@ public class ReplaceInstanceVariableIncrementDecrement extends FixableUsageInfo
|
||||
final PsiElement qualifier = lhs.getQualifier();
|
||||
final String operator = sign.getText();
|
||||
final String newExpression;
|
||||
final String strippedOperator = getStrippedOperator(operator);
|
||||
if (qualifier != null) {
|
||||
final String qualifierText = qualifier.getText();
|
||||
newExpression = qualifierText + '.' + delegateName + '.' +
|
||||
callSetter(qualifierText + '.' + delegateName + '.' + callGetter() + strippedOperator + "1");
|
||||
}
|
||||
else {
|
||||
newExpression = delegateName + '.' + callSetter(delegateName + '.' + callGetter() + strippedOperator + "1");
|
||||
if (getterName == null && setterName == null) {
|
||||
newExpression = (qualifier != null ? qualifier.getText() + "." : "") + delegateName + "." + fieldName + operator;
|
||||
} else {
|
||||
final String strippedOperator = getStrippedOperator(operator);
|
||||
newExpression = (qualifier != null ? qualifier.getText() + "." : "") + delegateName +
|
||||
'.' + callSetter(delegateName + '.' + callGetter() + strippedOperator + "1");
|
||||
}
|
||||
MutationUtils.replaceExpression(newExpression, reference);
|
||||
}
|
||||
|
||||
+3
-3
@@ -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.
|
||||
@@ -272,10 +272,10 @@ class IntroduceConstantDialog extends DialogWrapper {
|
||||
LanguageLevelProjectExtension.getInstance(psiManager.getProject()).getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_5) &&
|
||||
JavaPsiFacade.getInstance(psiManager.getProject()).findClass(AnnotationUtil.NON_NLS, myParentClass.getResolveScope()) != null) {
|
||||
final PropertiesComponent component = PropertiesComponent.getInstance(myProject);
|
||||
myCbNonNls.setSelected(component.isTrueValue(NONNLS_SELECTED_PROPERTY));
|
||||
myCbNonNls.setSelected(component.getBoolean(NONNLS_SELECTED_PROPERTY));
|
||||
myCbNonNls.addItemListener(new ItemListener() {
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
component.setValue(NONNLS_SELECTED_PROPERTY, Boolean.toString(myCbNonNls.isSelected()));
|
||||
component.setValue(NONNLS_SELECTED_PROPERTY, myCbNonNls.isSelected());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -329,7 +329,7 @@ public abstract class IntroduceFieldCentralPanel {
|
||||
public void saveFinalState() {
|
||||
if (myCbFinal != null && myCbFinal.isEnabled()) {
|
||||
ourLastCbFinalState = myCbFinal.isSelected();
|
||||
PropertiesComponent.getInstance().setValue(INTRODUCE_FIELD_FINAL_CHECKBOX, String.valueOf(ourLastCbFinalState));
|
||||
PropertiesComponent.getInstance().setValue(INTRODUCE_FIELD_FINAL_CHECKBOX, ourLastCbFinalState, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -183,7 +183,7 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase {
|
||||
}
|
||||
|
||||
public static boolean isPreferStatements() {
|
||||
return Boolean.valueOf(PropertiesComponent.getInstance().getBoolean(PREFER_STATEMENTS_OPTION, false)) || Registry.is(PREFER_STATEMENTS_OPTION, false);
|
||||
return Boolean.valueOf(PropertiesComponent.getInstance().getBoolean(PREFER_STATEMENTS_OPTION)) || Registry.is(PREFER_STATEMENTS_OPTION, false);
|
||||
}
|
||||
|
||||
public static List<PsiExpression> collectExpressions(final PsiFile file,
|
||||
|
||||
+1
-1
@@ -258,7 +258,7 @@ public class IntroduceParameterObjectDialog extends RefactoringDialog {
|
||||
IntroduceParameterObjectDialog.this.doCancelAction();
|
||||
}
|
||||
};
|
||||
myParamsPanel.add(paramsPanel, BorderLayout.NORTH);
|
||||
myParamsPanel.add(paramsPanel, BorderLayout.CENTER);
|
||||
return myWholePanel;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.refactoring.invertBoolean;
|
||||
|
||||
import com.intellij.ide.util.SuperMethodWarningUtil;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ScrollType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.refactoring.HelpID;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
public class InvertBooleanHandler implements RefactoringActionHandler {
|
||||
static final String REFACTORING_NAME = RefactoringBundle.message("invert.boolean.title");
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
|
||||
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
|
||||
PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
|
||||
if (element instanceof PsiMethod) {
|
||||
invoke((PsiMethod)element, project, editor);
|
||||
}
|
||||
else if (element instanceof PsiVariable) {
|
||||
invoke((PsiVariable)element, project, editor);
|
||||
}
|
||||
else {
|
||||
CommonRefactoringUtil.showErrorHint(project, editor, RefactoringBundle.getCannotRefactorMessage(
|
||||
RefactoringBundle.message("error.wrong.caret.position.method.or.variable.name")), REFACTORING_NAME, HelpID.INVERT_BOOLEAN);
|
||||
}
|
||||
}
|
||||
|
||||
private static void invoke(PsiVariable var, final Project project, Editor editor) {
|
||||
final PsiType returnType = var.getType();
|
||||
if (!PsiType.BOOLEAN.equals(returnType)) {
|
||||
CommonRefactoringUtil.showErrorHint(project, editor, RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("invert.boolean.wrong.type")), REFACTORING_NAME, HelpID.INVERT_BOOLEAN);
|
||||
return;
|
||||
}
|
||||
|
||||
if (var instanceof PsiParameter && ((PsiParameter)var).getDeclarationScope() instanceof PsiMethod) {
|
||||
final PsiMethod method = (PsiMethod)((PsiParameter)var).getDeclarationScope();
|
||||
final PsiMethod superMethod = SuperMethodWarningUtil.checkSuperMethod(method, RefactoringBundle.message("to.refactor"));
|
||||
if (superMethod == null) return;
|
||||
var = superMethod.getParameterList().getParameters()[method.getParameterList().getParameterIndex((PsiParameter)var)];
|
||||
}
|
||||
|
||||
new InvertBooleanDialog(var).show();
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, @NotNull PsiElement[] elements, DataContext dataContext) {
|
||||
if (elements.length == 1) {
|
||||
if (elements[0] instanceof PsiMethod) {
|
||||
invoke((PsiMethod)elements[0], project, null);
|
||||
}
|
||||
else if (elements[0] instanceof PsiVariable) {
|
||||
invoke((PsiVariable)elements[0], project, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void invoke(PsiMethod method, final Project project, Editor editor) {
|
||||
final PsiType returnType = method.getReturnType();
|
||||
if (!PsiType.BOOLEAN.equals(returnType)) {
|
||||
CommonRefactoringUtil.showErrorHint(project, editor, RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("invert.boolean.wrong.type")), REFACTORING_NAME, HelpID.INVERT_BOOLEAN);
|
||||
return;
|
||||
}
|
||||
|
||||
final PsiMethod superMethod = SuperMethodWarningUtil.checkSuperMethod(method, RefactoringBundle.message("to.refactor"));
|
||||
if (superMethod == null) return;
|
||||
method = superMethod;
|
||||
|
||||
new InvertBooleanDialog(method).show();
|
||||
}
|
||||
}
|
||||
-308
@@ -1,308 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.refactoring.invertBoolean;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightServicesUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.RecursiveCallLineMarkerProvider;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.searches.MethodReferencesSearch;
|
||||
import com.intellij.psi.search.searches.OverridingMethodsSearch;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.rename.RenameProcessor;
|
||||
import com.intellij.refactoring.rename.RenameUtil;
|
||||
import com.intellij.refactoring.util.MoveRenameUsageInfo;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.usageView.UsageViewDescriptor;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.Query;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
public class InvertBooleanProcessor extends BaseRefactoringProcessor {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.invertBoolean.InvertBooleanMethodProcessor");
|
||||
|
||||
private PsiNamedElement myElement;
|
||||
private final String myNewName;
|
||||
private final RenameProcessor myRenameProcessor;
|
||||
private final Map<UsageInfo, SmartPsiElementPointer> myToInvert = new HashMap<UsageInfo, SmartPsiElementPointer>();
|
||||
private final SmartPointerManager mySmartPointerManager;
|
||||
|
||||
public InvertBooleanProcessor(final PsiNamedElement namedElement, final String newName) {
|
||||
super(namedElement.getProject());
|
||||
myElement = namedElement;
|
||||
myNewName = newName;
|
||||
final Project project = namedElement.getProject();
|
||||
myRenameProcessor = Comparing.equal(namedElement.getName(), myNewName) ? null : new RenameProcessor(project, namedElement, newName, false, false);
|
||||
mySmartPointerManager = SmartPointerManager.getInstance(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected UsageViewDescriptor createUsageViewDescriptor(@NotNull UsageInfo[] usages) {
|
||||
return new InvertBooleanUsageViewDescriptor(myElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
|
||||
final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
|
||||
for (UsageInfo info : myToInvert.keySet()) {
|
||||
final PsiElement element = info.getElement();
|
||||
if (element instanceof PsiMethodReferenceExpression) {
|
||||
conflicts.putValue(element, "Method is used in method reference expression");
|
||||
}
|
||||
}
|
||||
|
||||
if (!conflicts.isEmpty()) {
|
||||
return showConflicts(conflicts, null);
|
||||
}
|
||||
|
||||
if (myRenameProcessor == null || myRenameProcessor.preprocessUsages(refUsages)) {
|
||||
prepareSuccessful();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected UsageInfo[] findUsages() {
|
||||
final List<SmartPsiElementPointer> toInvert = new ArrayList<SmartPsiElementPointer>();
|
||||
|
||||
addRefsToInvert(toInvert, myElement);
|
||||
|
||||
if (myElement instanceof PsiMethod) {
|
||||
final Collection<PsiMethod> overriders = OverridingMethodsSearch.search((PsiMethod)myElement).findAll();
|
||||
if (myRenameProcessor != null) {
|
||||
for (PsiMethod overrider : overriders) {
|
||||
myRenameProcessor.addElement(overrider, myNewName);
|
||||
}
|
||||
}
|
||||
|
||||
Collection<PsiMethod> allMethods = new HashSet<PsiMethod>(overriders);
|
||||
allMethods.add((PsiMethod)myElement);
|
||||
|
||||
for (PsiMethod method : allMethods) {
|
||||
method.accept(new JavaRecursiveElementWalkingVisitor() {
|
||||
@Override public void visitReturnStatement(PsiReturnStatement statement) {
|
||||
final PsiExpression returnValue = statement.getReturnValue();
|
||||
if (returnValue != null && PsiType.BOOLEAN.equals(returnValue.getType())) {
|
||||
toInvert.add(mySmartPointerManager.createSmartPsiElementPointer(returnValue));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitClass(PsiClass aClass) {}
|
||||
|
||||
@Override
|
||||
public void visitLambdaExpression(PsiLambdaExpression expression) {}
|
||||
});
|
||||
}
|
||||
} else if (myElement instanceof PsiParameter && ((PsiParameter)myElement).getDeclarationScope() instanceof PsiMethod) {
|
||||
final PsiMethod method = (PsiMethod)((PsiParameter)myElement).getDeclarationScope();
|
||||
int index = method.getParameterList().getParameterIndex((PsiParameter)myElement);
|
||||
LOG.assertTrue(index >= 0);
|
||||
final Query<PsiReference> methodQuery = MethodReferencesSearch.search(method);
|
||||
final Collection<PsiReference> methodRefs = methodQuery.findAll();
|
||||
for (PsiReference ref : methodRefs) {
|
||||
PsiElement parent = ref.getElement().getParent();
|
||||
if (parent instanceof PsiAnonymousClass) {
|
||||
parent = parent.getParent();
|
||||
}
|
||||
if (parent instanceof PsiCall) {
|
||||
final PsiCall call = (PsiCall)parent;
|
||||
final PsiReferenceExpression methodExpression = call instanceof PsiMethodCallExpression ?
|
||||
((PsiMethodCallExpression)call).getMethodExpression() :
|
||||
null;
|
||||
final PsiExpressionList argumentList = call.getArgumentList();
|
||||
if (argumentList != null) {
|
||||
final PsiExpression[] args = argumentList.getExpressions();
|
||||
if (index < args.length) {
|
||||
if (methodExpression == null ||
|
||||
canInvert(methodExpression, args[index] instanceof PsiReferenceExpression && ((PsiReferenceExpression)args[index]).resolve() == myElement)) {
|
||||
toInvert.add(mySmartPointerManager.createSmartPsiElementPointer(args[index]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
final Collection<PsiMethod> overriders = OverridingMethodsSearch.search(method).findAll();
|
||||
for (PsiMethod overrider : overriders) {
|
||||
final PsiParameter overriderParameter = overrider.getParameterList().getParameters()[index];
|
||||
if (myRenameProcessor != null) {
|
||||
myRenameProcessor.addElement(overriderParameter, myNewName);
|
||||
}
|
||||
addRefsToInvert(toInvert, overriderParameter);
|
||||
}
|
||||
}
|
||||
|
||||
final UsageInfo[] renameUsages = myRenameProcessor != null ? myRenameProcessor.findUsages() : UsageInfo.EMPTY_ARRAY;
|
||||
|
||||
final SmartPsiElementPointer[] usagesToInvert = toInvert.toArray(new SmartPsiElementPointer[toInvert.size()]);
|
||||
|
||||
//merge rename and invert usages
|
||||
Map<PsiElement, UsageInfo> expressionsToUsages = new HashMap<PsiElement, UsageInfo>();
|
||||
List<UsageInfo> result = new ArrayList<UsageInfo>();
|
||||
for (UsageInfo renameUsage : renameUsages) {
|
||||
expressionsToUsages.put(renameUsage.getElement(), renameUsage);
|
||||
result.add(renameUsage);
|
||||
}
|
||||
|
||||
for (SmartPsiElementPointer pointer : usagesToInvert) {
|
||||
final PsiExpression expression = (PsiExpression)pointer.getElement();
|
||||
if (!expressionsToUsages.containsKey(expression)) {
|
||||
final UsageInfo usageInfo = new UsageInfo(expression);
|
||||
expressionsToUsages.put(expression, usageInfo);
|
||||
result.add(usageInfo); //fake UsageInfo
|
||||
myToInvert.put(usageInfo, pointer);
|
||||
} else {
|
||||
myToInvert.put(expressionsToUsages.get(expression), pointer);
|
||||
}
|
||||
}
|
||||
|
||||
return result.toArray(new UsageInfo[result.size()]);
|
||||
}
|
||||
|
||||
private static boolean canInvert(PsiReferenceExpression methodExpression, boolean checkRecursive) {
|
||||
PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
|
||||
if (qualifierExpression == null || !"super".equals(qualifierExpression.getText())) {
|
||||
PsiElement parent = methodExpression.getParent();
|
||||
if (parent instanceof PsiMethodCallExpression) {
|
||||
return !(checkRecursive && RecursiveCallLineMarkerProvider.isRecursiveMethodCall((PsiMethodCallExpression)parent));
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void addRefsToInvert(final List<SmartPsiElementPointer> toInvert, final PsiNamedElement namedElement) {
|
||||
final Query<PsiReference> query = namedElement instanceof PsiMethod ?
|
||||
MethodReferencesSearch.search((PsiMethod)namedElement) :
|
||||
ReferencesSearch.search(namedElement);
|
||||
final Collection<PsiReference> refs = query.findAll();
|
||||
|
||||
for (PsiReference ref : refs) {
|
||||
final PsiElement element = ref.getElement();
|
||||
if (element instanceof PsiReferenceExpression) {
|
||||
final PsiReferenceExpression refExpr = (PsiReferenceExpression)element;
|
||||
PsiElement parent = refExpr.getParent();
|
||||
if (parent instanceof PsiAssignmentExpression && refExpr.equals(((PsiAssignmentExpression)parent).getLExpression())) {
|
||||
toInvert.add(mySmartPointerManager.createSmartPsiElementPointer(((PsiAssignmentExpression)parent).getRExpression()));
|
||||
}
|
||||
else {
|
||||
if (namedElement instanceof PsiParameter) { //filter usages in super method calls
|
||||
PsiElement gParent = refExpr.getParent().getParent();
|
||||
if (gParent instanceof PsiMethodCallExpression) {
|
||||
if (!canInvert(((PsiMethodCallExpression)gParent).getMethodExpression(), true)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
toInvert.add(mySmartPointerManager.createSmartPsiElementPointer(refExpr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (namedElement instanceof PsiVariable) {
|
||||
final PsiExpression initializer = ((PsiVariable)namedElement).getInitializer();
|
||||
if (initializer != null) {
|
||||
toInvert.add(mySmartPointerManager.createSmartPsiElementPointer(initializer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshElements(@NotNull PsiElement[] elements) {
|
||||
LOG.assertTrue(elements.length == 1 && elements[0] instanceof PsiMethod);
|
||||
myElement = (PsiMethod)elements[0];
|
||||
}
|
||||
|
||||
private static UsageInfo[] extractUsagesForElement(PsiElement element, UsageInfo[] usages) {
|
||||
final ArrayList<UsageInfo> extractedUsages = new ArrayList<UsageInfo>(usages.length);
|
||||
for (UsageInfo usage : usages) {
|
||||
if (usage instanceof MoveRenameUsageInfo) {
|
||||
MoveRenameUsageInfo usageInfo = (MoveRenameUsageInfo)usage;
|
||||
if (element.equals(usageInfo.getReferencedElement())) {
|
||||
extractedUsages.add(usageInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
return extractedUsages.toArray(new UsageInfo[extractedUsages.size()]);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void performRefactoring(@NotNull UsageInfo[] usages) {
|
||||
if (myRenameProcessor != null) {
|
||||
for (final PsiElement element : myRenameProcessor.getElements()) {
|
||||
try {
|
||||
RenameUtil.doRename(element, myRenameProcessor.getNewName(element), extractUsagesForElement(element, usages), myProject, null);
|
||||
}
|
||||
catch (final IncorrectOperationException e) {
|
||||
RenameUtil.showErrorMessage(e, element, myProject);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (UsageInfo usage : usages) {
|
||||
final SmartPsiElementPointer pointerToInvert = myToInvert.get(usage);
|
||||
if (pointerToInvert != null) {
|
||||
PsiExpression expression = (PsiExpression)pointerToInvert.getElement();
|
||||
LOG.assertTrue(expression != null);
|
||||
if (expression.getParent() instanceof PsiMethodCallExpression) expression = (PsiExpression)expression.getParent();
|
||||
try {
|
||||
while (expression.getParent() instanceof PsiPrefixExpression &&
|
||||
((PsiPrefixExpression)expression.getParent()).getOperationTokenType() == JavaTokenType.EXCL) {
|
||||
expression = (PsiExpression)expression.getParent();
|
||||
}
|
||||
if (!(expression.getParent() instanceof PsiExpressionStatement)) {
|
||||
expression.replace(CodeInsightServicesUtil.invertCondition(expression));
|
||||
}
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (myElement instanceof PsiField && ((PsiField)myElement).getInitializer() == null) {
|
||||
((PsiField)myElement).setInitializer(JavaPsiFacade.getElementFactory(myProject).createExpressionFromText("true", myElement));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCommandName() {
|
||||
return InvertBooleanHandler.REFACTORING_NAME;
|
||||
}
|
||||
}
|
||||
+266
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.refactoring.invertBoolean;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightServicesUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.RecursiveCallLineMarkerProvider;
|
||||
import com.intellij.ide.util.SuperMethodWarningUtil;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.searches.MethodReferencesSearch;
|
||||
import com.intellij.psi.search.searches.OverridingMethodsSearch;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.rename.RenameProcessor;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.Query;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class JavaInvertBooleanDelegate extends InvertBooleanDelegate {
|
||||
@Override
|
||||
public boolean isVisibleOnElement(@NotNull PsiElement element) {
|
||||
return element instanceof PsiVariable || element instanceof PsiMethod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailableOnElement(@NotNull PsiElement element) {
|
||||
if (element instanceof PsiVariable) {
|
||||
return PsiType.BOOLEAN.equals(((PsiVariable) element).getType());
|
||||
}
|
||||
else if (element instanceof PsiMethod) {
|
||||
return PsiType.BOOLEAN.equals(((PsiMethod) element).getReturnType());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement adjustElement(PsiElement element, Project project, Editor editor) {
|
||||
if (element instanceof PsiVariable) {
|
||||
PsiVariable var = (PsiVariable)element;
|
||||
final PsiType returnType = var.getType();
|
||||
if (!PsiType.BOOLEAN.equals(returnType)) {
|
||||
CommonRefactoringUtil.showErrorHint(project, editor,
|
||||
RefactoringBundle
|
||||
.getCannotRefactorMessage(RefactoringBundle.message("invert.boolean.wrong.type")),
|
||||
InvertBooleanHandler.REFACTORING_NAME, InvertBooleanHandler.INVERT_BOOLEAN_HELP_ID);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (var instanceof PsiParameter && ((PsiParameter)var).getDeclarationScope() instanceof PsiMethod) {
|
||||
final PsiMethod method = (PsiMethod)((PsiParameter)var).getDeclarationScope();
|
||||
final PsiMethod superMethod = SuperMethodWarningUtil.checkSuperMethod(method, RefactoringBundle.message("to.refactor"));
|
||||
if (superMethod == null) {
|
||||
return null;
|
||||
}
|
||||
var = superMethod.getParameterList().getParameters()[method.getParameterList().getParameterIndex((PsiParameter)var)];
|
||||
}
|
||||
return var;
|
||||
}
|
||||
else if (element instanceof PsiMethod) {
|
||||
final PsiMethod method = (PsiMethod)element;
|
||||
final PsiType returnType = method.getReturnType();
|
||||
if (!PsiType.BOOLEAN.equals(returnType)) {
|
||||
CommonRefactoringUtil.showErrorHint(project, editor,
|
||||
RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("invert.boolean.wrong.type")),
|
||||
InvertBooleanHandler.REFACTORING_NAME,
|
||||
InvertBooleanHandler.INVERT_BOOLEAN_HELP_ID);
|
||||
return null;
|
||||
}
|
||||
|
||||
return SuperMethodWarningUtil.checkSuperMethod(method, RefactoringBundle.message("to.refactor"));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void collectRefsToInvert(PsiElement namedElement, Collection<PsiElement> elementsToInvert) {
|
||||
final Query<PsiReference> query = namedElement instanceof PsiMethod ?
|
||||
MethodReferencesSearch.search((PsiMethod)namedElement) :
|
||||
ReferencesSearch.search(namedElement);
|
||||
final Collection<PsiReference> refs = query.findAll();
|
||||
|
||||
for (PsiReference ref : refs) {
|
||||
final PsiElement element = ref.getElement();
|
||||
PsiElement refElement = getElementToInvert(namedElement, element);
|
||||
if (refElement == null) {
|
||||
refElement = getForeignElementToInvert(namedElement, element, JavaLanguage.INSTANCE);
|
||||
}
|
||||
if (refElement != null) {
|
||||
elementsToInvert.add(refElement);
|
||||
}
|
||||
}
|
||||
|
||||
if (namedElement instanceof PsiVariable) {
|
||||
final PsiExpression initializer = ((PsiVariable)namedElement).getInitializer();
|
||||
if (initializer != null) {
|
||||
elementsToInvert.add(initializer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PsiElement getElementToInvert(PsiElement namedElement, PsiElement element) {
|
||||
if (element instanceof PsiReferenceExpression) {
|
||||
final PsiReferenceExpression refExpr = (PsiReferenceExpression)element;
|
||||
PsiElement parent = refExpr.getParent();
|
||||
if (parent instanceof PsiAssignmentExpression && refExpr.equals(((PsiAssignmentExpression)parent).getLExpression())) {
|
||||
return ((PsiAssignmentExpression)parent).getRExpression();
|
||||
}
|
||||
else {
|
||||
if (namedElement instanceof PsiParameter) { //filter usages in super method calls
|
||||
PsiElement gParent = refExpr.getParent().getParent();
|
||||
if (gParent instanceof PsiMethodCallExpression) {
|
||||
if (!canInvertReferenceElement(((PsiMethodCallExpression)gParent).getMethodExpression(), true)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return refExpr;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean canInvertReferenceElement(PsiElement expression, boolean recursive) {
|
||||
PsiExpression qualifierExpression = expression instanceof PsiReferenceExpression ? ((PsiReferenceExpression)expression).getQualifierExpression()
|
||||
: null;
|
||||
if (qualifierExpression == null || !"super".equals(qualifierExpression.getText())) {
|
||||
PsiElement parent = expression.getParent();
|
||||
if (parent instanceof PsiMethodCallExpression) {
|
||||
return !(recursive && RecursiveCallLineMarkerProvider.isRecursiveMethodCall((PsiMethodCallExpression)parent));
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceWithNegatedExpression(@NotNull PsiElement expression) {
|
||||
if (!(expression instanceof PsiExpression)) {
|
||||
return;
|
||||
}
|
||||
if (expression.getParent() instanceof PsiMethodCallExpression) {
|
||||
expression = expression.getParent();
|
||||
}
|
||||
while (expression.getParent() instanceof PsiPrefixExpression &&
|
||||
((PsiPrefixExpression)expression.getParent()).getOperationTokenType() == JavaTokenType.EXCL) {
|
||||
expression = expression.getParent();
|
||||
}
|
||||
|
||||
if (!(expression.getParent() instanceof PsiExpressionStatement)) {
|
||||
expression.replace(CodeInsightServicesUtil.invertCondition((PsiExpression)expression));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invertDefaultElementInitializer(final PsiElement element) {
|
||||
if (element instanceof PsiField && ((PsiField)element).getInitializer() == null) {
|
||||
((PsiField)element).setInitializer(JavaPsiFacade.getElementFactory(element.getProject()).createExpressionFromText("true", element));
|
||||
}
|
||||
}
|
||||
|
||||
public void collectRefElements(final PsiElement element,
|
||||
final Collection<PsiElement> elementsToInvert,
|
||||
final RenameProcessor renameProcessor,
|
||||
@NotNull final String newName) {
|
||||
collectRefsToInvert(element, elementsToInvert);
|
||||
|
||||
if (element instanceof PsiMethod) {
|
||||
final Collection<PsiMethod> overriders = OverridingMethodsSearch.search((PsiMethod)element).findAll();
|
||||
if (renameProcessor != null) {
|
||||
for (PsiMethod overrider : overriders) {
|
||||
renameProcessor.addElement(overrider, newName);
|
||||
}
|
||||
}
|
||||
|
||||
Collection<PsiMethod> allMethods = new HashSet<PsiMethod>(overriders);
|
||||
allMethods.add((PsiMethod)element);
|
||||
|
||||
for (PsiMethod method : allMethods) {
|
||||
method.accept(new JavaRecursiveElementWalkingVisitor() {
|
||||
@Override public void visitReturnStatement(PsiReturnStatement statement) {
|
||||
final PsiExpression returnValue = statement.getReturnValue();
|
||||
if (returnValue != null && PsiType.BOOLEAN.equals(returnValue.getType())) {
|
||||
elementsToInvert.add(returnValue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitClass(PsiClass aClass) {}
|
||||
|
||||
@Override
|
||||
public void visitLambdaExpression(PsiLambdaExpression expression) {}
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (element instanceof PsiParameter && ((PsiParameter)element).getDeclarationScope() instanceof PsiMethod) {
|
||||
final PsiMethod method = (PsiMethod)((PsiParameter)element).getDeclarationScope();
|
||||
int index = method.getParameterList().getParameterIndex((PsiParameter)element);
|
||||
assert index >= 0;
|
||||
final Query<PsiReference> methodQuery = MethodReferencesSearch.search(method);
|
||||
final Collection<PsiReference> methodRefs = methodQuery.findAll();
|
||||
for (PsiReference ref : methodRefs) {
|
||||
PsiElement parent = ref.getElement().getParent();
|
||||
if (parent instanceof PsiAnonymousClass) {
|
||||
parent = parent.getParent();
|
||||
}
|
||||
if (parent instanceof PsiCall) {
|
||||
final PsiCall call = (PsiCall)parent;
|
||||
final PsiReferenceExpression methodExpression = call instanceof PsiMethodCallExpression ?
|
||||
((PsiMethodCallExpression)call).getMethodExpression() :
|
||||
null;
|
||||
final PsiExpressionList argumentList = call.getArgumentList();
|
||||
if (argumentList != null) {
|
||||
final PsiExpression[] args = argumentList.getExpressions();
|
||||
if (index < args.length) {
|
||||
if (methodExpression == null ||
|
||||
canInvertReferenceElement(methodExpression,
|
||||
args[index] instanceof PsiReferenceExpression &&
|
||||
((PsiReferenceExpression)args[index]).resolve() == element)) {
|
||||
elementsToInvert.add(args[index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final Collection<PsiMethod> overriders = OverridingMethodsSearch.search(method).findAll();
|
||||
for (PsiMethod overrider : overriders) {
|
||||
final PsiParameter overriderParameter = overrider.getParameterList().getParameters()[index];
|
||||
if (renameProcessor != null) {
|
||||
renameProcessor.addElement(overriderParameter, newName);
|
||||
}
|
||||
collectRefsToInvert(overriderParameter, elementsToInvert);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void findConflicts(MultiMap<PsiElement, String> conflicts, UsageInfo[] usageInfos) {
|
||||
for (UsageInfo info : usageInfos) {
|
||||
final PsiElement element = info.getElement();
|
||||
if (element instanceof PsiMethodReferenceExpression) {
|
||||
conflicts.putValue(element, "Method is used in method reference expression");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
/*
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -239,7 +239,7 @@ public class MigrationMapSet {
|
||||
for(int i = 0; i < myMaps.size(); i++){
|
||||
MigrationMap map = myMaps.get(i);
|
||||
|
||||
filePaths[i] = dir + File.separator + namesProvider.generateUniqueName(FileUtil.sanitizeName(map.getName())) + ".xml";
|
||||
filePaths[i] = dir + File.separator + namesProvider.generateUniqueName(FileUtil.sanitizeFileName(map.getName(), false)) + ".xml";
|
||||
documents[i] = saveMap(map);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -41,7 +41,7 @@ public abstract class MoveDialogBase extends RefactoringDialog {
|
||||
|
||||
protected void saveOpenInEditorOption() {
|
||||
if (myOpenEditorCb != null) {
|
||||
PropertiesComponent.getInstance().setValue("Move" + getMovePropertySuffix() +".OpenInEditor", String.valueOf(myOpenEditorCb.isSelected()));
|
||||
PropertiesComponent.getInstance().setValue("Move" + getMovePropertySuffix() +".OpenInEditor", myOpenEditorCb.isSelected(), isEnabledByDefault());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -108,13 +108,7 @@ public abstract class SlicePanel extends JPanel implements TypeSafeDataProvider,
|
||||
}
|
||||
}
|
||||
};
|
||||
ToolWindowManagerEx.getInstanceEx(project).addToolWindowManagerListener(listener);
|
||||
Disposer.register(this, new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
ToolWindowManagerEx.getInstanceEx(project).removeToolWindowManagerListener(listener);
|
||||
}
|
||||
});
|
||||
ToolWindowManagerEx.getInstanceEx(project).addToolWindowManagerListener(listener, this);
|
||||
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
myProject = project;
|
||||
|
||||
@@ -41,23 +41,29 @@ public class TestRunLineMarkerProvider extends RunLineMarkerContributor {
|
||||
@Nullable
|
||||
@Override
|
||||
public Info getInfo(PsiElement e) {
|
||||
if (e instanceof PsiIdentifier) {
|
||||
if (isIdentifier(e)) {
|
||||
PsiElement element = e.getParent();
|
||||
if (element instanceof PsiClass) {
|
||||
TestFramework framework = TestFrameworks.detectFramework((PsiClass)element);
|
||||
if (framework != null && framework.isTestClass(element)) {
|
||||
return new Info(framework.getIcon(), TOOLTIP_PROVIDER, ExecutorAction.ACTIONS);
|
||||
return new Info(framework.getIcon(), TOOLTIP_PROVIDER, ExecutorAction.getActions(1));
|
||||
}
|
||||
}
|
||||
if (element instanceof PsiMethod) {
|
||||
PsiClass psiClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
|
||||
TestFramework framework = TestFrameworks.detectFramework(psiClass);
|
||||
if (psiClass != null && framework != null && framework.isTestMethod(element)) {
|
||||
// String url = "java:test://" + psiClass.getQualifiedName() + "." + ((PsiMethod)element).getName();
|
||||
return new Info(framework.getIcon(), TOOLTIP_PROVIDER, ExecutorAction.ACTIONS);
|
||||
if (psiClass != null) {
|
||||
TestFramework framework = TestFrameworks.detectFramework(psiClass);
|
||||
if (framework != null && framework.isTestMethod(element)) {
|
||||
// String url = "java:test://" + psiClass.getQualifiedName() + "." + ((PsiMethod)element).getName();
|
||||
return new Info(framework.getIcon(), TOOLTIP_PROVIDER, ExecutorAction.getActions(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected boolean isIdentifier(PsiElement e) {
|
||||
return e instanceof PsiIdentifier;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -106,13 +106,13 @@ public class CreateTestAction extends PsiElementBaseIntentionAction {
|
||||
final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
|
||||
final HashSet<VirtualFile> testFolders = new HashSet<VirtualFile>();
|
||||
checkForTestRoots(srcModule, testFolders);
|
||||
if (testFolders.isEmpty() && !propertiesComponent.getBoolean(CREATE_TEST_IN_THE_SAME_ROOT, false)) {
|
||||
if (testFolders.isEmpty() && !propertiesComponent.getBoolean(CREATE_TEST_IN_THE_SAME_ROOT)) {
|
||||
if (Messages.showOkCancelDialog(project, "Create test in the same source root?", "No Test Roots Found", Messages.getQuestionIcon()) !=
|
||||
Messages.OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
propertiesComponent.setValue(CREATE_TEST_IN_THE_SAME_ROOT, String.valueOf(true));
|
||||
propertiesComponent.setValue(CREATE_TEST_IN_THE_SAME_ROOT, true);
|
||||
}
|
||||
|
||||
final CreateTestDialog d = createTestDialog(project, srcModule, srcClass, srcPackage);
|
||||
|
||||
@@ -186,13 +186,11 @@ public class CreateTestDialog extends DialogWrapper {
|
||||
}
|
||||
|
||||
private void restoreShowInheritedMembersStatus() {
|
||||
String v = getProperties().getValue(SHOW_INHERITED_MEMBERS_PROPERTY);
|
||||
myShowInheritedMethodsBox.setSelected(v != null && v.equals("true"));
|
||||
myShowInheritedMethodsBox.setSelected(getProperties().getBoolean(SHOW_INHERITED_MEMBERS_PROPERTY));
|
||||
}
|
||||
|
||||
private void saveShowInheritedMembersStatus() {
|
||||
boolean v = myShowInheritedMethodsBox.isSelected();
|
||||
getProperties().setValue(SHOW_INHERITED_MEMBERS_PROPERTY, Boolean.toString(v));
|
||||
getProperties().setValue(SHOW_INHERITED_MEMBERS_PROPERTY, myShowInheritedMethodsBox.isSelected());
|
||||
}
|
||||
|
||||
private PropertiesComponent getProperties() {
|
||||
|
||||
+2
-1
@@ -16,6 +16,7 @@
|
||||
package com.intellij.psi.impl.search;
|
||||
|
||||
import com.intellij.openapi.application.QueryExecutorBase;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.*;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
@@ -36,7 +37,7 @@ public class VariableInIncompleteCodeSearcher extends QueryExecutorBase<PsiRefer
|
||||
if (!refElement.isValid() || !(refElement instanceof PsiVariable)) return;
|
||||
|
||||
final String name = ((PsiVariable)refElement).getName();
|
||||
if (name == null) return;
|
||||
if (StringUtil.isEmptyOrSpaces(name)) return;
|
||||
|
||||
SearchScope scope = p.getEffectiveSearchScope();
|
||||
if (!(scope instanceof LocalSearchScope)) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.psi.util.PsiModificationTracker;
|
||||
import com.intellij.testIntegration.TestFramework;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -54,7 +55,7 @@ public abstract class TestFrameworks {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static TestFramework detectFramework(final PsiClass psiClass) {
|
||||
public static TestFramework detectFramework(@NotNull final PsiClass psiClass) {
|
||||
return CachedValuesManager.getCachedValue(psiClass, new CachedValueProvider<TestFramework>() {
|
||||
@Nullable
|
||||
@Override
|
||||
|
||||
@@ -25,12 +25,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
public class PsiFormatUtil extends PsiFormatUtilBase {
|
||||
@MagicConstant(flags = {
|
||||
SHOW_MODIFIERS, SHOW_TYPE, TYPE_AFTER, SHOW_CONTAINING_CLASS, SHOW_FQ_NAME, SHOW_NAME, SHOW_MODIFIERS,
|
||||
SHOW_INITIALIZER, SHOW_RAW_TYPE, SHOW_RAW_NON_TOP_TYPE, SHOW_FQ_CLASS_NAMES})
|
||||
SHOW_INITIALIZER, SHOW_RAW_TYPE, SHOW_RAW_NON_TOP_TYPE, SHOW_FQ_CLASS_NAMES, USE_INTERNAL_CANONICAL_TEXT})
|
||||
public @interface FormatVariableOptions { }
|
||||
|
||||
@MagicConstant(flags = {
|
||||
SHOW_MODIFIERS, MODIFIERS_AFTER, SHOW_TYPE, TYPE_AFTER, SHOW_CONTAINING_CLASS, SHOW_FQ_NAME, SHOW_NAME,
|
||||
SHOW_PARAMETERS, SHOW_THROWS, SHOW_RAW_TYPE, SHOW_RAW_NON_TOP_TYPE, SHOW_FQ_CLASS_NAMES})
|
||||
SHOW_PARAMETERS, SHOW_THROWS, SHOW_RAW_TYPE, SHOW_RAW_NON_TOP_TYPE, SHOW_FQ_CLASS_NAMES, USE_INTERNAL_CANONICAL_TEXT})
|
||||
public @interface FormatMethodOptions { }
|
||||
|
||||
@MagicConstant(flags = {
|
||||
@@ -388,7 +388,9 @@ public class PsiFormatUtil extends PsiFormatUtilBase {
|
||||
}
|
||||
}
|
||||
if (type == null) return "null";
|
||||
return (options & SHOW_FQ_CLASS_NAMES) == 0 ? type.getPresentableText() : type.getInternalCanonicalText();
|
||||
return (options & SHOW_FQ_CLASS_NAMES) == 0 ? type.getPresentableText() :
|
||||
(options & USE_INTERNAL_CANONICAL_TEXT) == 0 ? type.getCanonicalText(false) :
|
||||
type.getInternalCanonicalText();
|
||||
}
|
||||
|
||||
public static String formatReference(PsiJavaCodeReferenceElement ref, int options) {
|
||||
@@ -450,40 +452,6 @@ public class PsiFormatUtil extends PsiFormatUtilBase {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getRawExternalName(PsiModifierListOwner owner) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
final PsiClass psiClass = PsiTreeUtil.getParentOfType(owner, PsiClass.class, false);
|
||||
if (psiClass == null) return null;
|
||||
ClassUtil.formatClassName(psiClass, builder);
|
||||
if (owner instanceof PsiMethod) {
|
||||
builder.append(" ");
|
||||
formatMethod((PsiMethod)owner, PsiSubstitutor.EMPTY,
|
||||
SHOW_NAME | SHOW_FQ_NAME | SHOW_TYPE | SHOW_RAW_TYPE | SHOW_PARAMETERS | SHOW_FQ_CLASS_NAMES,
|
||||
SHOW_TYPE | SHOW_RAW_TYPE | SHOW_FQ_CLASS_NAMES,
|
||||
Integer.MAX_VALUE, builder);
|
||||
}
|
||||
else if (owner instanceof PsiParameter) {
|
||||
final PsiElement declarationScope = ((PsiParameter)owner).getDeclarationScope();
|
||||
if (!(declarationScope instanceof PsiMethod)) {
|
||||
return null;
|
||||
}
|
||||
final PsiMethod psiMethod = (PsiMethod)declarationScope;
|
||||
|
||||
builder.append(" ");
|
||||
formatMethod(psiMethod, PsiSubstitutor.EMPTY,
|
||||
SHOW_NAME | SHOW_FQ_NAME | SHOW_TYPE | SHOW_RAW_TYPE | SHOW_PARAMETERS | SHOW_FQ_CLASS_NAMES,
|
||||
SHOW_TYPE | SHOW_RAW_TYPE | SHOW_FQ_CLASS_NAMES,
|
||||
Integer.MAX_VALUE, builder);
|
||||
builder.append(" ");
|
||||
builder.append(psiMethod.getParameterList().getParameterIndex((PsiParameter)owner));
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String getPackageDisplayName(@NotNull final PsiClass psiClass) {
|
||||
if (psiClass instanceof PsiTypeParameter) {
|
||||
PsiTypeParameterListOwner owner = ((PsiTypeParameter)psiClass).getOwner();
|
||||
|
||||
@@ -157,6 +157,17 @@ public class RedundantCastUtil {
|
||||
super.visitAssignmentExpression(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitArrayInitializerExpression(PsiArrayInitializerExpression expression) {
|
||||
PsiType type = expression.getType();
|
||||
if (type instanceof PsiArrayType) {
|
||||
for (PsiExpression initializer : expression.getInitializers()) {
|
||||
processPossibleTypeCast(initializer, ((PsiArrayType)type).getComponentType());
|
||||
}
|
||||
}
|
||||
super.visitArrayInitializerExpression(expression);
|
||||
}
|
||||
|
||||
@Override public void visitVariable(PsiVariable variable) {
|
||||
processPossibleTypeCast(variable.getInitializer(), variable.getType());
|
||||
super.visitVariable(variable);
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ public class HighlightMessageUtil {
|
||||
else if (symbol instanceof PsiMethod) {
|
||||
symbolName = PsiFormatUtil.formatMethod((PsiMethod)symbol,
|
||||
substitutor, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS,
|
||||
PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_FQ_CLASS_NAMES);
|
||||
PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_FQ_CLASS_NAMES | PsiFormatUtilBase.USE_INTERNAL_CANONICAL_TEXT);
|
||||
}
|
||||
else if (symbol instanceof PsiVariable) {
|
||||
symbolName = ((PsiVariable)symbol).getName();
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.psi.impl;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiSubstitutor;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.PsiTypeParameter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class DelegateSubstitutor implements PsiSubstitutor {
|
||||
|
||||
private final @NotNull PsiSubstitutor myDelegate;
|
||||
|
||||
public DelegateSubstitutor(@NotNull PsiSubstitutor delegate) {
|
||||
myDelegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public PsiType substitute(@NotNull PsiTypeParameter typeParameter) {
|
||||
return myDelegate.substitute(typeParameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiType substitute(@Nullable PsiType type) {
|
||||
return myDelegate.substitute(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiType substituteWithBoundsPromotion(@NotNull PsiTypeParameter typeParameter) {
|
||||
return myDelegate.substituteWithBoundsPromotion(typeParameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiSubstitutor put(@NotNull PsiTypeParameter classParameter, PsiType mapping) {
|
||||
return myDelegate.put(classParameter, mapping);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiSubstitutor putAll(@NotNull PsiClass parentClass, PsiType[] mappings) {
|
||||
return myDelegate.putAll(parentClass, mappings);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiSubstitutor putAll(@NotNull PsiSubstitutor another) {
|
||||
return myDelegate.putAll(another);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Map<PsiTypeParameter, PsiType> getSubstitutionMap() {
|
||||
return myDelegate.getSubstitutionMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return myDelegate.isValid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ensureValid() {
|
||||
myDelegate.ensureValid();
|
||||
}
|
||||
}
|
||||
+17
-5
@@ -1335,6 +1335,7 @@ public class InferenceSession {
|
||||
*/
|
||||
public static boolean isMoreSpecific(PsiMethod m1,
|
||||
PsiMethod m2,
|
||||
PsiSubstitutor siteSubstitutor1,
|
||||
PsiExpression[] args,
|
||||
PsiElement context,
|
||||
boolean varargs) {
|
||||
@@ -1342,7 +1343,10 @@ public class InferenceSession {
|
||||
for (PsiTypeParameter param : PsiUtil.typeParametersIterable(m2)) {
|
||||
params.add(param);
|
||||
}
|
||||
final InferenceSession session = new InferenceSession(params.toArray(new PsiTypeParameter[params.size()]), PsiSubstitutor.EMPTY, m2.getManager(), context);
|
||||
|
||||
siteSubstitutor1 = getSiteSubstitutor(siteSubstitutor1, params);
|
||||
|
||||
final InferenceSession session = new InferenceSession(params.toArray(new PsiTypeParameter[params.size()]), siteSubstitutor1, m2.getManager(), context);
|
||||
|
||||
final PsiParameter[] parameters1 = m1.getParameterList().getParameters();
|
||||
final PsiParameter[] parameters2 = m2.getParameterList().getParameters();
|
||||
@@ -1352,8 +1356,8 @@ public class InferenceSession {
|
||||
|
||||
final int paramsLength = !varargs ? parameters1.length : parameters1.length - 1;
|
||||
for (int i = 0; i < paramsLength; i++) {
|
||||
PsiType sType = getParameterType(parameters1, i, PsiSubstitutor.EMPTY, false);
|
||||
PsiType tType = session.substituteWithInferenceVariables(getParameterType(parameters2, i, PsiSubstitutor.EMPTY, varargs));
|
||||
PsiType sType = getParameterType(parameters1, i, siteSubstitutor1, false);
|
||||
PsiType tType = session.substituteWithInferenceVariables(getParameterType(parameters2, i, siteSubstitutor1, varargs));
|
||||
if (LambdaUtil.isFunctionalType(sType) && LambdaUtil.isFunctionalType(tType) && !relates(sType, tType)) {
|
||||
if (!isFunctionalTypeMoreSpecific(sType, tType, session, args[i])) {
|
||||
return false;
|
||||
@@ -1369,14 +1373,22 @@ public class InferenceSession {
|
||||
}
|
||||
|
||||
if (varargs) {
|
||||
PsiType sType = getParameterType(parameters1, paramsLength, PsiSubstitutor.EMPTY, true);
|
||||
PsiType tType = session.substituteWithInferenceVariables(getParameterType(parameters2, paramsLength, PsiSubstitutor.EMPTY, true));
|
||||
PsiType sType = getParameterType(parameters1, paramsLength, siteSubstitutor1, true);
|
||||
PsiType tType = session.substituteWithInferenceVariables(getParameterType(parameters2, paramsLength, siteSubstitutor1, true));
|
||||
session.addConstraint(new StrictSubtypingConstraint(tType, sType));
|
||||
}
|
||||
|
||||
return session.repeatInferencePhases(true);
|
||||
}
|
||||
|
||||
private static PsiSubstitutor getSiteSubstitutor(PsiSubstitutor siteSubstitutor1, List<PsiTypeParameter> params) {
|
||||
PsiSubstitutor subst = PsiSubstitutor.EMPTY;
|
||||
for (PsiTypeParameter param : params) {
|
||||
subst = subst.put(param, siteSubstitutor1.substitute(param));
|
||||
}
|
||||
return subst;
|
||||
}
|
||||
|
||||
/**
|
||||
* 15.12.2.5 Choosing the Most Specific Method
|
||||
* "a functional interface type S is more specific than a functional interface type T for an expression exp" part
|
||||
|
||||
+5
-4
@@ -544,10 +544,10 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
|
||||
|
||||
final PsiSubstitutor methodSubstitutor1 = calculateMethodSubstitutor(typeParameters1, method1, siteSubstitutor1, types1, types2AtSite,
|
||||
languageLevel);
|
||||
boolean applicable12 = isApplicableTo(types2AtSite, method1, languageLevel, varargsPosition, methodSubstitutor1, method2);
|
||||
boolean applicable12 = isApplicableTo(types2AtSite, method1, languageLevel, varargsPosition, methodSubstitutor1, method2, siteSubstitutor2);
|
||||
|
||||
final PsiSubstitutor methodSubstitutor2 = calculateMethodSubstitutor(typeParameters2, method2, siteSubstitutor2, types2, types1AtSite, languageLevel);
|
||||
boolean applicable21 = isApplicableTo(types1AtSite, method2, languageLevel, varargsPosition, methodSubstitutor2, method1);
|
||||
boolean applicable21 = isApplicableTo(types1AtSite, method2, languageLevel, varargsPosition, methodSubstitutor2, method1, siteSubstitutor1);
|
||||
|
||||
if (!myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
|
||||
final boolean typeArgsApplicable12 = GenericsUtil.isTypeArgumentsApplicable(typeParameters1, methodSubstitutor1, myArgumentsList, !applicable21);
|
||||
@@ -641,11 +641,12 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
|
||||
@NotNull LanguageLevel languageLevel,
|
||||
boolean varargsPosition,
|
||||
@NotNull PsiSubstitutor methodSubstitutor1,
|
||||
@NotNull PsiMethod method2) {
|
||||
@NotNull PsiMethod method2,
|
||||
PsiSubstitutor siteSubstitutor1) {
|
||||
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8) && method1.getTypeParameters().length > 0 && myArgumentsList instanceof PsiExpressionList) {
|
||||
final PsiElement parent = myArgumentsList.getParent();
|
||||
if (parent instanceof PsiCallExpression) {
|
||||
return InferenceSession.isMoreSpecific(method2, method1, ((PsiExpressionList)myArgumentsList).getExpressions(), myArgumentsList, varargsPosition);
|
||||
return InferenceSession.isMoreSpecific(method2, method1, siteSubstitutor1, ((PsiExpressionList)myArgumentsList).getExpressions(), myArgumentsList, varargsPosition);
|
||||
}
|
||||
}
|
||||
final PsiUtil.ApplicabilityChecker applicabilityChecker = languageLevel.isAtLeast(LanguageLevel.JDK_1_8)
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import java.lang.String;
|
||||
|
||||
class X {
|
||||
void m() {
|
||||
|
||||
if ("asd".intern().equa<caret>ls(String.valueOf("qwe"))) {
|
||||
// do something
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import java.lang.String;
|
||||
|
||||
class X {
|
||||
void m() {
|
||||
|
||||
if (java.util.Objects.equals("asd".intern(), String.valueOf("qwe"))) {
|
||||
// do something
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class X {
|
||||
|
||||
void m(X x2) {
|
||||
if (equa<caret>ls(x2, x2, x2)) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
boolean equals(X x, X x2, X x3) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class X {
|
||||
void m() {
|
||||
|
||||
if ("asd".equa<caret>ls("qwe")) {
|
||||
// do something
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class X {
|
||||
void m() {
|
||||
|
||||
if (java.util.Objects.equals("asd", "qwe")) {
|
||||
// do something
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Fixes ABC-1123 and ABC-2. See details at BBB-22
|
||||
*/
|
||||
class IssueLinksInJavaDoc {
|
||||
// Fixes ABC-22 and ABC-11. See details at BBB-33
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
class Test {
|
||||
interface One<T> {
|
||||
<S extends T> S save(S entity);
|
||||
<S extends T> Iterable<S> save(Iterable<S> entities);
|
||||
}
|
||||
static One<String> foo;
|
||||
public static void main(String[] args) throws Exception {
|
||||
foo.save <error descr="Ambiguous method call: both 'One.save(String)' and 'One.save(Iterable<String>)' match">(null)</error>;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
class Test {
|
||||
{
|
||||
((Runnable) () -> {
|
||||
|
||||
|
||||
}).getClass();;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user