mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'master' into upsource-master
Conflicts: java/java-impl/src/com/intellij/codeInsight/intention/impl/ConvertAbsolutePathToRelativeIntentionAction.java java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/ConvertColorRepresentationTest.java jps/jps-builders/testSrc/org/jetbrains/ether/IncrementalTestCase.java jps/model/src/org/jetbrains/ether/dependencyView/IntIntMultiMaplet.java jps/model/src/org/jetbrains/ether/dependencyView/IntObjectMultiMaplet.java jps/model/src/org/jetbrains/ether/dependencyView/Mappings.java platform/lang-api/src/com/intellij/codeInsight/intention/PsiElementBaseIntentionAction.java platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java platform/platform-impl/src/com/intellij/featureStatistics/actions/ShowFeatureUsageStatisticsDialog.java platform/util/src/com/intellij/util/CommonProcessors.java plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/CreateFieldFromParameterTest.groovy plugins/groovy/test/org/jetbrains/plugins/groovy/lang/controlFlow/ControlFlowTest.java
This commit is contained in:
@@ -181,7 +181,7 @@ libraryLicense(name: "Apache Commons HTTPCore", libraryName: "httpcore-4.1.jar",
|
||||
url: "http://hc.apache.org/httpcomponents-core-ga/", licenseUrl: "http://www.apache.org/licenses/LICENSE-2.0")
|
||||
libraryLicense(name: "Antlr", libraryName: "antlr.jar", version: "3.1.3", license: "BSD", url: "http://www.antlr.org",
|
||||
licenseUrl: "http://www.antlr.org/license.html")
|
||||
libraryLicense(name: "Guava", version: "R8", license: "Apache 2.0", url: "http://code.google.com/p/guava-libraries/", licenseUrl: "http://ant.apache.org/license.html")
|
||||
libraryLicense(name: "Guava", version: "12.0", license: "Apache 2.0", url: "http://code.google.com/p/guava-libraries/", licenseUrl: "http://ant.apache.org/license.html")
|
||||
libraryLicense(name: "Groovy", version: "1.7.3", license: "Apache 2.0", url: "http://groovy.codehaus.org/")
|
||||
libraryLicense(name: "Gson", libraryName: "gson", license: "Apache 2.0", url: "http://code.google.com/p/google-gson/")
|
||||
libraryLicense(name: "ini4j", libraryName: "ini4j-0.5.2-patched", version: "0.5.2 (with a patch by JetBrains)", license: "Apache 2.0", url: "http://ini4j.sourceforge.net/", attachedTo: "git4idea")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<component>
|
||||
<version codename="Community Edition" major="11" minor="2" eap="true" update-channel="IDEA11dot1EAP"/>
|
||||
<version codename="Community Edition" major="12" minor="0" eap="true" update-channel="IDEA11dot1EAP"/>
|
||||
|
||||
<build number="__BUILD_NUMBER__" date="__BUILD_DATE__"/>
|
||||
<install-over minbuild="0" maxbuild="0" version="10.5"/>
|
||||
|
||||
@@ -98,7 +98,7 @@
|
||||
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Allow auto-make while run configuration is active"/>
|
||||
<text value="Allow auto-make while a run configuration is active"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
|
||||
@@ -18,20 +18,21 @@ package com.intellij.compiler.options;
|
||||
import com.intellij.compiler.*;
|
||||
import com.intellij.compiler.impl.TranslatingCompilerFilesMonitor;
|
||||
import com.intellij.compiler.server.BuildManager;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.compiler.CompilerBundle;
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.options.SearchableConfigurable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class CompilerUIConfigurable implements SearchableConfigurable, Configurable.NoScroll {
|
||||
@@ -49,10 +50,6 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura
|
||||
|
||||
public CompilerUIConfigurable(final Project project) {
|
||||
myProject = project;
|
||||
final boolean isServerOptionEnabled = Registry.is("compiler.out-of-process.build.enabled") || ApplicationManager.getApplication().isInternal();
|
||||
myCbUseCompileServer.setVisible(isServerOptionEnabled);
|
||||
myCbMakeProjectOnSave.setVisible(isServerOptionEnabled);
|
||||
myCbAllowAutomakeWhileRunningApplication.setVisible(isServerOptionEnabled);
|
||||
|
||||
myPatternLegendLabel.setText("<html>" +
|
||||
"Use <b>;</b> to separate patterns and <b>!</b> to negate a pattern. " +
|
||||
@@ -103,7 +100,7 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura
|
||||
final CompilerWorkspaceConfiguration workspaceConfiguration = CompilerWorkspaceConfiguration.getInstance(myProject);
|
||||
workspaceConfiguration.AUTO_SHOW_ERRORS_IN_EDITOR = myCbAutoShowFirstError.isSelected();
|
||||
workspaceConfiguration.CLEAR_OUTPUT_DIRECTORY = myCbClearOutputDirectory.isSelected();
|
||||
boolean wasUsing = workspaceConfiguration.USE_COMPILE_SERVER;
|
||||
boolean wasUsingExternalMake = workspaceConfiguration.USE_COMPILE_SERVER;
|
||||
workspaceConfiguration.USE_COMPILE_SERVER = myCbUseCompileServer.isSelected();
|
||||
workspaceConfiguration.MAKE_PROJECT_ON_SAVE = myCbMakeProjectOnSave.isSelected();
|
||||
workspaceConfiguration.ALLOW_AUTOMAKE_WHILE_RUNNING_APPLICATION = myCbAllowAutomakeWhileRunningApplication.isSelected();
|
||||
@@ -115,14 +112,7 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura
|
||||
|
||||
// this will schedule for compilation all files that might become compilable after resource patterns' changing
|
||||
final TranslatingCompilerFilesMonitor monitor = TranslatingCompilerFilesMonitor.getInstance();
|
||||
if (!workspaceConfiguration.USE_COMPILE_SERVER) {
|
||||
if (wasUsing) {
|
||||
CompileServerManager.getInstance().shutdownServer();
|
||||
monitor.watchProject(myProject);
|
||||
monitor.scanSourcesForCompilableFiles(myProject);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (workspaceConfiguration.USE_COMPILE_SERVER) {
|
||||
monitor.suspendProject(myProject);
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
@@ -131,6 +121,26 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
// use old make
|
||||
if (wasUsingExternalMake) {
|
||||
CompileServerManager.getInstance().shutdownServer();
|
||||
monitor.watchProject(myProject);
|
||||
monitor.scanSourcesForCompilableFiles(myProject);
|
||||
if (!myProject.isDefault()) {
|
||||
final File buildSystem = BuildManager.getInstance().getBuildSystemDirectory();
|
||||
final File[] subdirs = buildSystem.listFiles();
|
||||
if (subdirs != null) {
|
||||
final String prefix = myProject.getName().toLowerCase(Locale.US) + "_";
|
||||
for (File subdir : subdirs) {
|
||||
if (subdir.getName().startsWith(prefix)) {
|
||||
FileUtil.asyncDelete(subdir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void applyResourcePatterns(String extensionString, final CompilerConfigurationImpl configuration)
|
||||
|
||||
@@ -746,7 +746,7 @@ public class BuildManager implements ApplicationComponent{
|
||||
cmdLine.addParameter(Integer.toString(port));
|
||||
cmdLine.addParameter(sessionId.toString());
|
||||
|
||||
final File workDirectory = new File(mySystemDirectory, SYSTEM_ROOT);
|
||||
final File workDirectory = getBuildSystemDirectory();
|
||||
workDirectory.mkdirs();
|
||||
ensureLogConfigExists(workDirectory);
|
||||
|
||||
@@ -757,6 +757,10 @@ public class BuildManager implements ApplicationComponent{
|
||||
return cmdLine.createProcess();
|
||||
}
|
||||
|
||||
public File getBuildSystemDirectory() {
|
||||
return new File(mySystemDirectory, SYSTEM_ROOT);
|
||||
}
|
||||
|
||||
private static int getMinorVersion(String vs) {
|
||||
final int dashIndex = vs.lastIndexOf('_');
|
||||
if (dashIndex >= 0) {
|
||||
|
||||
@@ -19,10 +19,8 @@
|
||||
*/
|
||||
package com.intellij.compiler;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.util.xmlb.XmlSerializerUtil;
|
||||
|
||||
@State(
|
||||
@@ -54,10 +52,10 @@ public class CompilerWorkspaceConfiguration implements PersistentStateComponent<
|
||||
}
|
||||
|
||||
public boolean useOutOfProcessBuild() {
|
||||
return USE_COMPILE_SERVER && (Registry.is("compiler.out-of-process.build.enabled") || ApplicationManager.getApplication().isInternal());
|
||||
return USE_COMPILE_SERVER;
|
||||
}
|
||||
|
||||
public static boolean useServerlessOutOfProcessBuild() {
|
||||
return !Registry.is("compiler.out-of-process.as-server");
|
||||
return true/*!Registry.is("compiler.out-of-process.as-server")*/;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-7
@@ -369,18 +369,20 @@ public abstract class BreakpointPropertiesPanel {
|
||||
insert(myClassFiltersFieldPanel, myClassFiltersField);
|
||||
|
||||
DebuggerUIUtil.enableEditorOnCheck(myLogExpressionCheckBox, myLogExpressionCombo);
|
||||
ActionListener listener = new ActionListener() {
|
||||
ActionListener updateListener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
updateCheckboxes();
|
||||
}
|
||||
};
|
||||
myPassCountCheckbox.addActionListener(listener);
|
||||
myInstanceFiltersCheckBox.addActionListener(listener);
|
||||
myClassFiltersCheckBox.addActionListener(listener);
|
||||
myPassCountCheckbox.addActionListener(updateListener);
|
||||
myInstanceFiltersCheckBox.addActionListener(updateListener);
|
||||
myClassFiltersCheckBox.addActionListener(updateListener);
|
||||
myConditionCheckbox.addActionListener(updateListener);
|
||||
DebuggerUIUtil.focusEditorOnCheck(myPassCountCheckbox, myPassCountField);
|
||||
DebuggerUIUtil.focusEditorOnCheck(myLogExpressionCheckBox, myLogExpressionCombo);
|
||||
DebuggerUIUtil.focusEditorOnCheck(myInstanceFiltersCheckBox, myInstanceFiltersField.getTextField());
|
||||
DebuggerUIUtil.focusEditorOnCheck(myClassFiltersCheckBox, myClassFiltersField.getTextField());
|
||||
DebuggerUIUtil.focusEditorOnCheck(myConditionCheckbox, myConditionCombo);
|
||||
|
||||
IJSwingUtilities.adjustComponentsOnMac(mySuspendJBCheckBox);
|
||||
IJSwingUtilities.adjustComponentsOnMac(myLogExpressionCheckBox);
|
||||
@@ -873,7 +875,7 @@ public abstract class BreakpointPropertiesPanel {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(selected != null || !myConditionCombo.getText().isEmpty()){
|
||||
if(selected != null || !myConditionCheckbox.isSelected()){
|
||||
myPassCountCheckbox.setEnabled(false);
|
||||
} else {
|
||||
myPassCountCheckbox.setEnabled(true);
|
||||
@@ -886,8 +888,8 @@ public abstract class BreakpointPropertiesPanel {
|
||||
myPassCountField.setEditable(myPassCountCheckbox.isSelected());
|
||||
myPassCountField.setEnabled (myPassCountCheckbox.isSelected());
|
||||
|
||||
myConditionCombo.setEnabled(true);
|
||||
myConditionMagnifierButton.setEnabled(true);
|
||||
myConditionCombo.setEnabled(myConditionCheckbox.isSelected());
|
||||
myConditionMagnifierButton.setEnabled(myConditionCheckbox.isSelected());
|
||||
|
||||
myInstanceFiltersField.setEnabled(myInstanceFiltersCheckBox.isSelected());
|
||||
myInstanceFiltersField.getTextField().setEditable(myInstanceFiltersCheckBox.isSelected());
|
||||
|
||||
@@ -136,7 +136,7 @@ public class ExpectedTypesProvider {
|
||||
|
||||
public static PsiType[] processExpectedTypes(@NotNull ExpectedTypeInfo[] infos,
|
||||
@NotNull PsiTypeVisitor<PsiType> visitor, @NotNull Project project) {
|
||||
Set<PsiType> set = new LinkedHashSet<PsiType>();
|
||||
LinkedHashSet<PsiType> set = new LinkedHashSet<PsiType>();
|
||||
for (ExpectedTypeInfo info : infos) {
|
||||
ExpectedTypeInfoImpl infoImpl = (ExpectedTypeInfoImpl)info;
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ public class JavaInheritorsGetter extends CompletionProvider<CompletionParameter
|
||||
|
||||
for (final PsiType type : ExpectedTypesGetter.extractTypes(infos, true)) {
|
||||
if (type instanceof PsiArrayType) {
|
||||
final LookupItem item = PsiTypeLookupItem.createLookupItem(JavaCompletionUtil.eliminateWildcards(type), identifierCopy);
|
||||
final LookupItem item = PsiTypeLookupItem.createLookupItem(TypeConversionUtil.erasure(type), identifierCopy);
|
||||
if (item.getObject() instanceof PsiClass) {
|
||||
JavaCompletionUtil.setShowFQN(item);
|
||||
}
|
||||
|
||||
+53
-37
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.impl.analysis;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.util.containers.CollectionFactory;
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.codeInsight.daemon.JavaErrorMessages;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
@@ -53,7 +53,8 @@ public class GenericsHighlightUtil {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.analysis.GenericsHighlightUtil");
|
||||
private static final QuickFixFactory QUICK_FIX_FACTORY = QuickFixFactory.getInstance();
|
||||
|
||||
private GenericsHighlightUtil() {}
|
||||
private GenericsHighlightUtil() {
|
||||
}
|
||||
|
||||
public static HighlightInfo checkInferredTypeArguments(PsiMethod genericMethod,
|
||||
PsiMethodCallExpression call,
|
||||
@@ -66,7 +67,7 @@ public class GenericsHighlightUtil {
|
||||
PsiClassType[] extendsTypes = typeParameter.getExtendsListTypes();
|
||||
for (PsiClassType type : extendsTypes) {
|
||||
PsiType extendsType = substitutor.substitute(type);
|
||||
if (substituted instanceof PsiWildcardType && TypeConversionUtil.erasure(extendsType).equals(TypeConversionUtil.erasure(((PsiWildcardType)substituted).getExtendsBound()))){
|
||||
if (substituted instanceof PsiWildcardType && TypeConversionUtil.erasure(extendsType).equals(TypeConversionUtil.erasure(((PsiWildcardType)substituted).getExtendsBound()))) {
|
||||
PsiType extendsBound = ((PsiWildcardType)substituted).getExtendsBound();
|
||||
if (extendsBound instanceof PsiClassType) {
|
||||
PsiType[] parameters = ((PsiClassType)extendsBound).getParameters();
|
||||
@@ -148,7 +149,8 @@ public class GenericsHighlightUtil {
|
||||
if (PsiTreeUtil.getParentOfType(referenceParameterList, PsiCall.class) != null &&
|
||||
PsiUtil.isLanguageLevel7OrHigher(referenceParameterList)) {
|
||||
description = null;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
description = JavaErrorMessages.message(
|
||||
"generics.type.or.method.does.not.have.type.parameters",
|
||||
typeParameterListOwnerCategoryDescription(typeParameterListOwner),
|
||||
@@ -157,9 +159,7 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
}
|
||||
else {
|
||||
description = JavaErrorMessages.message(
|
||||
"generics.wrong.number.of.type.arguments", refParametersNum, targetParametersNum
|
||||
);
|
||||
description = JavaErrorMessages.message("generics.wrong.number.of.type.arguments", refParametersNum, targetParametersNum);
|
||||
}
|
||||
|
||||
if (description != null) {
|
||||
@@ -170,7 +170,10 @@ public class GenericsHighlightUtil {
|
||||
PsiElement variable = pparent.getParent();
|
||||
if (variable instanceof PsiVariable) {
|
||||
if (targetParametersNum == 0) {
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new RemoveTypeArgumentsFix(variable), null);
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new RemoveTypeArgumentsFix(variable));
|
||||
}
|
||||
if (typeParameterListOwner instanceof PsiClass) {
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new ChangeClassSignatureFromUsageFix((PsiClass)typeParameterListOwner, referenceParameterList));
|
||||
}
|
||||
VariableParameterizedTypeFix.registerIntentions(highlightInfo, (PsiVariable)variable, referenceParameterList);
|
||||
}
|
||||
@@ -186,10 +189,11 @@ public class GenericsHighlightUtil {
|
||||
final PsiType[] types = inferenceResult.getTypes();
|
||||
for (int i = 0; i < typeParameters.length; i++) {
|
||||
final PsiType type = types[i];
|
||||
final HighlightInfo highlightInfo = checkTypeParameterWithinItsBound(typeParameters[i], substitutor, type, referenceElements[0]);
|
||||
final HighlightInfo highlightInfo = checkTypeParameterWithinItsBound(typeParameters[i], substitutor, type, referenceElements[0]);
|
||||
if (highlightInfo != null) return highlightInfo;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < typeParameters.length; i++) {
|
||||
final PsiTypeElement typeElement = referenceElements[i];
|
||||
final HighlightInfo highlightInfo = checkTypeParameterWithinItsBound(typeParameters[i], substitutor, typeElement.getType(), typeElement);
|
||||
@@ -243,9 +247,10 @@ public class GenericsHighlightUtil {
|
||||
final PsiType type,
|
||||
final PsiElement typeElement2Highlight) {
|
||||
final PsiClass referenceClass;
|
||||
if (type instanceof PsiClassType){
|
||||
if (type instanceof PsiClassType) {
|
||||
referenceClass = ((PsiClassType)type).resolve();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
referenceClass = null;
|
||||
}
|
||||
final PsiType psiType = substitutor.substitute(classParameter);
|
||||
@@ -314,7 +319,8 @@ public class GenericsHighlightUtil {
|
||||
boundBound = ((PsiWildcardType)bound).isSuper()
|
||||
? ((PsiWildcardType)bound).getSuperBound()
|
||||
: ((PsiWildcardType)bound).getExtendsBound();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -335,10 +341,12 @@ public class GenericsHighlightUtil {
|
||||
? ((PsiWildcardType)bound).getExtendsBound()
|
||||
: ((PsiWildcardType)bound).getSuperBound();
|
||||
return !TypeConversionUtil.isAssignable(boundBound, type, allowUncheckedConversion);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return !TypeConversionUtil.isAssignable(bound, type, allowUncheckedConversion);
|
||||
}
|
||||
}
|
||||
@@ -349,7 +357,7 @@ public class GenericsHighlightUtil {
|
||||
final PsiClass classType = ((PsiClassType)type).resolve();
|
||||
if (classType != null) {
|
||||
for (PsiTypeParameter parameter : PsiUtil.typeParametersIterable(classType)) {
|
||||
allowUncheckedConversions &= parameter.getExtendsListTypes().length == 0;
|
||||
allowUncheckedConversions &= parameter.getExtendsListTypes().length == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -404,13 +412,14 @@ public class GenericsHighlightUtil {
|
||||
IntentionAction fix = QUICK_FIX_FACTORY.createExtendsListFix(aClass, type, false);
|
||||
QuickFixAction.registerQuickFixAction(errorResult, fix, null);
|
||||
}
|
||||
if (errorResult == null && JavaVersionService.getInstance().isAtLeast(referenceList, JavaSdkVersion.JDK_1_7) &&
|
||||
if (errorResult == null && JavaVersionService.getInstance().isAtLeast(referenceList, JavaSdkVersion.JDK_1_7) &&
|
||||
referenceElements.length > 1) {
|
||||
//todo suppress erased methods which come from the same class
|
||||
return checkOverrideEquivalentMethods(aClass);
|
||||
}
|
||||
return errorResult;
|
||||
}
|
||||
|
||||
public static HighlightInfo checkInterfaceMultipleInheritance(PsiClass aClass) {
|
||||
if (aClass instanceof PsiTypeParameter) return null;
|
||||
final PsiClassType[] types = aClass.getSuperTypes();
|
||||
@@ -466,7 +475,7 @@ public class GenericsHighlightUtil {
|
||||
PsiManager manager = aClass.getManager();
|
||||
Map<MethodSignature, MethodSignatureBackedByPsiMethod> sameErasureMethods =
|
||||
new THashMap<MethodSignature, MethodSignatureBackedByPsiMethod>(MethodSignatureUtil.METHOD_PARAMETERS_ERASURE_EQUALITY);
|
||||
|
||||
|
||||
for (HierarchicalMethodSignature signature : signaturesWithSupers) {
|
||||
HighlightInfo info = checkSameErasureNotSubSignatureInner(signature, manager, aClass, sameErasureMethods);
|
||||
if (info != null) return info;
|
||||
@@ -529,7 +538,8 @@ public class GenericsHighlightUtil {
|
||||
if (checkEqualsSuper && atLeast17) {
|
||||
if (retErasure1 != null && retErasure2 != null) {
|
||||
differentReturnTypeErasure = !TypeConversionUtil.isAssignable(retErasure1, retErasure2);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
differentReturnTypeErasure = !(retErasure1 == null && retErasure2 == null);
|
||||
}
|
||||
}
|
||||
@@ -565,10 +575,10 @@ public class GenericsHighlightUtil {
|
||||
|
||||
private static HighlightInfo getSameErasureMessage(final boolean sameClass, final PsiMethod method, final PsiMethod superMethod,
|
||||
TextRange textRange) {
|
||||
@NonNls final String key = sameClass ? "generics.methods.have.same.erasure" :
|
||||
method.hasModifierProperty(PsiModifier.STATIC) ?
|
||||
"generics.methods.have.same.erasure.hide" :
|
||||
"generics.methods.have.same.erasure.override";
|
||||
@NonNls final String key = sameClass ? "generics.methods.have.same.erasure" :
|
||||
method.hasModifierProperty(PsiModifier.STATIC) ?
|
||||
"generics.methods.have.same.erasure.hide" :
|
||||
"generics.methods.have.same.erasure.override";
|
||||
String description = JavaErrorMessages.message(key, HighlightMethodUtil.createClashMethodMessage(method, superMethod, !sameClass));
|
||||
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, textRange, description);
|
||||
}
|
||||
@@ -650,7 +660,8 @@ public class GenericsHighlightUtil {
|
||||
if (isRawToGeneric(lType, type)) return true;
|
||||
}
|
||||
return false;
|
||||
} else if (lType instanceof PsiIntersectionType) {
|
||||
}
|
||||
else if (lType instanceof PsiIntersectionType) {
|
||||
for (PsiType type : ((PsiIntersectionType)lType).getConjuncts()) {
|
||||
if (isRawToGeneric(type, rType)) return true;
|
||||
}
|
||||
@@ -672,7 +683,9 @@ public class GenericsHighlightUtil {
|
||||
PsiSubstitutor rSubstitutor = rResolveResult.getSubstitutor();
|
||||
if (lClass == null || rClass == null) return false;
|
||||
if (lClass instanceof PsiTypeParameter &&
|
||||
!InheritanceUtil.isInheritorOrSelf(rClass, lClass, true)) return true;
|
||||
!InheritanceUtil.isInheritorOrSelf(rClass, lClass, true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!lClass.getManager().areElementsEquivalent(lClass, rClass)) {
|
||||
if (lClass.isInheritor(rClass, true)) {
|
||||
@@ -698,7 +711,7 @@ public class GenericsHighlightUtil {
|
||||
PsiType rTypeArg = rSubstitutor.substituteWithBoundsPromotion(rParameter);
|
||||
if (lTypeArg == null) continue;
|
||||
if (rTypeArg == null) {
|
||||
if (lTypeArg instanceof PsiWildcardType && ((PsiWildcardType) lTypeArg).getBound() == null) {
|
||||
if (lTypeArg instanceof PsiWildcardType && ((PsiWildcardType)lTypeArg).getBound() == null) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
@@ -922,7 +935,7 @@ public class GenericsHighlightUtil {
|
||||
for (int i = 0; i < typeParameters.length; i++) {
|
||||
final PsiTypeParameter typeParameter1 = typeParameters[i];
|
||||
String name1 = typeParameter1.getName();
|
||||
for (int j = i+1; j < typeParameters.length; j++) {
|
||||
for (int j = i + 1; j < typeParameters.length; j++) {
|
||||
final PsiTypeParameter typeParameter2 = typeParameters[j];
|
||||
String name2 = typeParameter2.getName();
|
||||
if (Comparing.strEqual(name1, name2)) {
|
||||
@@ -937,7 +950,7 @@ public class GenericsHighlightUtil {
|
||||
@Nullable
|
||||
public static Collection<HighlightInfo> checkCatchParameterIsClass(PsiParameter parameter) {
|
||||
if (!(parameter.getDeclarationScope() instanceof PsiCatchSection)) return null;
|
||||
final Collection<HighlightInfo> result = Lists.newArrayList();
|
||||
final Collection<HighlightInfo> result = CollectionFactory.arrayList();
|
||||
|
||||
final List<PsiTypeElement> typeElements = PsiUtil.getParameterTypeElements(parameter);
|
||||
for (PsiTypeElement typeElement : typeElements) {
|
||||
@@ -975,12 +988,12 @@ public class GenericsHighlightUtil {
|
||||
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, typeElement, JavaErrorMessages.message("illegal.generic.type.for.instanceof"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final PsiType[] parameters = ref.getTypeParameters();
|
||||
for (PsiType parameterType : parameters) {
|
||||
if (parameterType != null &&
|
||||
!(parameterType instanceof PsiWildcardType && ((PsiWildcardType)parameterType).getBound() == null)) {
|
||||
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, typeElement, JavaErrorMessages.message("illegal.generic.type.for.instanceof"));
|
||||
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, typeElement, JavaErrorMessages.message("illegal.generic.type.for.instanceof"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1057,7 +1070,6 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
|
||||
|
||||
|
||||
LOG.assertTrue(varParameter.isVarArgs());
|
||||
final PsiEllipsisType ellipsisType = (PsiEllipsisType)varParameter.getType();
|
||||
final PsiType componentType = ellipsisType.getComponentType();
|
||||
@@ -1099,14 +1111,15 @@ public class GenericsHighlightUtil {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (lastArg instanceof PsiMethodCallExpression) {
|
||||
}
|
||||
else if (lastArg instanceof PsiMethodCallExpression) {
|
||||
if (lastArg.getType() instanceof PsiArrayType) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = parametersCount - 1; i < args.length; i++) {
|
||||
if (!isReifiableType(resolveResult.getSubstitutor().substitute(args[i].getType()))){
|
||||
if (!isReifiableType(resolveResult.getSubstitutor().substitute(args[i].getType()))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1156,7 +1169,8 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
|
||||
static void checkEnumConstantForConstructorProblems(PsiEnumConstant enumConstant, final HighlightInfoHolder holder) {
|
||||
PsiClass containingClass = enumConstant.getContainingClass(); if (enumConstant.getInitializingClass() == null) {
|
||||
PsiClass containingClass = enumConstant.getContainingClass();
|
||||
if (enumConstant.getInitializingClass() == null) {
|
||||
HighlightInfo highlightInfo = HighlightClassUtil.checkInstantiationOfAbstractClass(containingClass, enumConstant.getNameIdentifier());
|
||||
if (highlightInfo != null) {
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createImplementMethodsFix(enumConstant));
|
||||
@@ -1233,8 +1247,9 @@ public class GenericsHighlightUtil {
|
||||
PsiElement parent = refParamList.getParent();
|
||||
if (parent instanceof PsiJavaCodeReferenceElement) {
|
||||
resolveResult = ((PsiJavaCodeReferenceElement)parent).advancedResolve(false);
|
||||
} else if (parent instanceof PsiCallExpression) {
|
||||
resolveResult = ((PsiCallExpression)parent).resolveMethodGenerics();
|
||||
}
|
||||
else if (parent instanceof PsiCallExpression) {
|
||||
resolveResult = ((PsiCallExpression)parent).resolveMethodGenerics();
|
||||
}
|
||||
if (resolveResult != null) {
|
||||
PsiElement element = resolveResult.getElement();
|
||||
@@ -1257,12 +1272,13 @@ public class GenericsHighlightUtil {
|
||||
|
||||
public static HighlightInfo checkCannotInheritFromEnum(PsiClass superClass, PsiElement elementToHighlight) {
|
||||
HighlightInfo errorResult = null;
|
||||
if (Comparing.strEqual("java.lang.Enum",superClass.getQualifiedName())) {
|
||||
if (Comparing.strEqual("java.lang.Enum", superClass.getQualifiedName())) {
|
||||
String message = JavaErrorMessages.message("classes.extends.enum");
|
||||
errorResult = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, elementToHighlight, message);
|
||||
}
|
||||
return errorResult;
|
||||
}
|
||||
|
||||
public static HighlightInfo checkGenericCannotExtendException(PsiReferenceList list) {
|
||||
PsiElement parent = list.getParent();
|
||||
if (!(parent instanceof PsiClass)) return null;
|
||||
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.refactoring.changeClassSignature.ChangeClassSignatureDialog;
|
||||
import com.intellij.refactoring.changeClassSignature.TypeParameterInfo;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Danila Ponomarenko
|
||||
*/
|
||||
public class ChangeClassSignatureFromUsageFix extends BaseIntentionAction {
|
||||
private final PsiClass myClass;
|
||||
private final PsiReferenceParameterList myParameterList;
|
||||
|
||||
public ChangeClassSignatureFromUsageFix(@NotNull PsiClass aClass,
|
||||
@NotNull PsiReferenceParameterList parameterList) {
|
||||
myClass = aClass;
|
||||
myParameterList = parameterList;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return QuickFixBundle.message("change.class.signature.family");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
if (!myClass.isValid() || !myParameterList.isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (myClass.getTypeParameters().length >= myParameterList.getTypeArguments().length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final PsiTypeParameterList classTypeParameterList = myClass.getTypeParameterList();
|
||||
if (classTypeParameterList == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
setText(QuickFixBundle.message("change.class.signature.text", myClass.getName(), myParameterList.getText()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
final PsiTypeParameterList classTypeParameterList = myClass.getTypeParameterList();
|
||||
if (classTypeParameterList == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ChangeClassSignatureDialog dialog = new ChangeClassSignatureDialog(
|
||||
myClass,
|
||||
createTypeParameters(
|
||||
JavaCodeFragmentFactory.getInstance(project),
|
||||
Arrays.asList(classTypeParameterList.getTypeParameters()),
|
||||
Arrays.asList(myParameterList.getTypeParameterElements())
|
||||
),
|
||||
false
|
||||
);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Map<TypeParameterInfo, PsiTypeCodeFragment> createTypeParameters(@NotNull JavaCodeFragmentFactory factory,
|
||||
@NotNull List<PsiTypeParameter> classTypeParameters,
|
||||
@NotNull List<PsiTypeElement> typeElements) {
|
||||
final LinkedHashMap<TypeParameterInfo, PsiTypeCodeFragment> result = new LinkedHashMap<TypeParameterInfo, PsiTypeCodeFragment>();
|
||||
final TypeParameterNameSuggester suggester = new TypeParameterNameSuggester(classTypeParameters);
|
||||
|
||||
int listIndex = 0;
|
||||
for (PsiTypeElement typeElement : typeElements) {
|
||||
if (listIndex < classTypeParameters.size()) {
|
||||
final PsiTypeParameter typeParameter = classTypeParameters.get(listIndex);
|
||||
|
||||
if (isAssignable(typeParameter, typeElement.getType())) {
|
||||
result.put(new TypeParameterInfo(listIndex++), null);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
final PsiClassType type = (PsiClassType)typeElement.getType();
|
||||
result.put(new TypeParameterInfo(suggester.suggest(type), type), factory.createTypeCodeFragment(type.getClassName(), typeElement, true));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean isAssignable(@NotNull PsiTypeParameter typeParameter, @NotNull PsiType type) {
|
||||
for (PsiClassType t : typeParameter.getExtendsListTypes()) {
|
||||
if (!t.isAssignableFrom(type)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static class TypeParameterNameSuggester {
|
||||
private final Set<String> usedNames = new HashSet<String>();
|
||||
|
||||
public TypeParameterNameSuggester(@NotNull PsiTypeParameter... typeParameters) {
|
||||
this(Arrays.asList(typeParameters));
|
||||
}
|
||||
|
||||
public TypeParameterNameSuggester(@NotNull Collection<PsiTypeParameter> typeParameters) {
|
||||
for (PsiTypeParameter p : typeParameters) {
|
||||
usedNames.add(p.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String suggestUnusedName(@NotNull String name) {
|
||||
String unusedName = name;
|
||||
int i = 0;
|
||||
while (true) {
|
||||
if (usedNames.add(unusedName)) {
|
||||
return unusedName;
|
||||
}
|
||||
unusedName = name + ++i;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String suggest(@NotNull PsiClassType type) {
|
||||
return suggestUnusedName(type.getClassName().substring(0, 1).toUpperCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -73,7 +73,7 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction, HighP
|
||||
private final boolean myChangeAllUsages;
|
||||
private final int myMinUsagesNumberToShowDialog;
|
||||
ParameterInfoImpl[] myNewParametersInfo;
|
||||
private static final Logger LOG = Logger.getInstance("#" + ChangeMethodSignatureFromUsageFix.class.getName());
|
||||
private static final Logger LOG = Logger.getInstance(ChangeMethodSignatureFromUsageFix.class);
|
||||
|
||||
ChangeMethodSignatureFromUsageFix(@NotNull PsiMethod targetMethod,
|
||||
@NotNull PsiExpression[] expressions,
|
||||
|
||||
+7
@@ -29,10 +29,13 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author Mike
|
||||
*/
|
||||
public class CreateFieldFromUsageFix extends CreateVarFromUsageFix {
|
||||
public static boolean DEBUG = false;
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.quickfix.CreateFieldFromUsageFix");
|
||||
|
||||
public CreateFieldFromUsageFix(PsiReferenceExpression referenceElement) {
|
||||
@@ -71,6 +74,10 @@ public class CreateFieldFromUsageFix extends CreateVarFromUsageFix {
|
||||
final PsiFile targetFile = targetClass.getContainingFile();
|
||||
|
||||
ExpectedTypeInfo[] expectedTypes = CreateFromUsageUtils.guessExpectedTypes(myReferenceExpression, false);
|
||||
if (DEBUG) {
|
||||
System.out.println("CreateFieldFromUsageFix.invokeImpl");
|
||||
System.out.println("expectedTypes = " + Arrays.toString(expectedTypes));
|
||||
}
|
||||
|
||||
String fieldName = myReferenceExpression.getReferenceName();
|
||||
assert fieldName != null;
|
||||
|
||||
+24
@@ -623,6 +623,7 @@ public class CreateFromUsageUtils {
|
||||
|
||||
getExpectedInformation(expression, typesList, expectedMethodNames, expectedFieldNames);
|
||||
|
||||
|
||||
if (typesList.size() == 1 && (!expectedFieldNames.isEmpty() || !expectedMethodNames.isEmpty())) {
|
||||
ExpectedTypeInfo[] infos = typesList.get(0);
|
||||
if (infos.length == 1 && infos[0].getKind() == ExpectedTypeInfo.TYPE_OR_SUBTYPE &&
|
||||
@@ -773,16 +774,34 @@ public class CreateFromUsageUtils {
|
||||
public int compare(final PsiMember m1, final PsiMember m2) {
|
||||
ProgressManager.checkCanceled();
|
||||
int result = JavaStatisticsManager.createInfo(null, m2).getUseCount() - JavaStatisticsManager.createInfo(null, m1).getUseCount();
|
||||
if (CreateFieldFromUsageFix.DEBUG) {
|
||||
System.out.println("CreateFromUsageUtils.compare");
|
||||
System.out.println("m1 = " + m1);
|
||||
System.out.println("m2 = " + m2);
|
||||
System.out.println("result = " + result);
|
||||
}
|
||||
if (result != 0) return result;
|
||||
final PsiClass aClass = m1.getContainingClass();
|
||||
final PsiClass bClass = m2.getContainingClass();
|
||||
if (aClass == null || bClass == null) return 0;
|
||||
if (CreateFieldFromUsageFix.DEBUG) {
|
||||
System.out.println("aClass = " + aClass);
|
||||
System.out.println("bClass = " + bClass);
|
||||
}
|
||||
result = JavaStatisticsManager.createInfo(null, bClass).getUseCount() - JavaStatisticsManager.createInfo(null, aClass).getUseCount();
|
||||
if (CreateFieldFromUsageFix.DEBUG) {
|
||||
System.out.println("result2 = " + result);
|
||||
}
|
||||
if (result != 0) return result;
|
||||
|
||||
WeighingComparable<PsiElement,ProximityLocation> proximity1 = PsiProximityComparator.getProximity(m1, expression);
|
||||
WeighingComparable<PsiElement,ProximityLocation> proximity2 = PsiProximityComparator.getProximity(m2, expression);
|
||||
if (proximity1 != null && proximity2 != null) {
|
||||
if (CreateFieldFromUsageFix.DEBUG) {
|
||||
System.out.println("proximity1 = " + proximity1);
|
||||
System.out.println("proximity2 = " + proximity2);
|
||||
}
|
||||
|
||||
return proximity2.compareTo(proximity1);
|
||||
}
|
||||
|
||||
@@ -797,6 +816,11 @@ public class CreateFromUsageUtils {
|
||||
ProgressManager.checkCanceled();
|
||||
PsiClass aClass = member.getContainingClass();
|
||||
if (aClass instanceof PsiAnonymousClass || aClass == null) continue;
|
||||
if (CreateFieldFromUsageFix.DEBUG) {
|
||||
System.out.println("CreateFromUsageUtils.addMemberInfo");
|
||||
System.out.println("member = " + member);
|
||||
System.out.println("aClass = " + aClass);
|
||||
}
|
||||
|
||||
if (facade.getResolveHelper().isAccessible(member, expression, null)) {
|
||||
PsiClassType type;
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
* @author ven
|
||||
*/
|
||||
public abstract class MethodArgumentFix implements IntentionAction {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.quickfix.MethodArgumentFix");
|
||||
private static final Logger LOG = Logger.getInstance(MethodArgumentFix.class);
|
||||
|
||||
protected final PsiExpressionList myArgList;
|
||||
protected final int myIndex;
|
||||
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.intention.HighPriorityAction;
|
||||
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static com.intellij.patterns.PlatformPatterns.psiElement;
|
||||
|
||||
/**
|
||||
* @author Danila Ponomarenko
|
||||
*/
|
||||
public abstract class BaseColorIntentionAction extends PsiElementBaseIntentionAction implements HighPriorityAction {
|
||||
protected static final String JAVA_AWT_COLOR = "java.awt.Color";
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
|
||||
if (!psiElement().inside(psiElement(PsiNewExpression.class)).accepts(element)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final PsiNewExpression expression = PsiTreeUtil.getParentOfType(element, PsiNewExpression.class, false);
|
||||
if (expression == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isJavaAwtColor(expression.getClassOrAnonymousClassReference()) && isValueArguments(expression.getArgumentList());
|
||||
}
|
||||
|
||||
private static boolean isJavaAwtColor(@Nullable PsiJavaCodeReferenceElement ref) {
|
||||
if (ref == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final PsiReference reference = ref.getReference();
|
||||
if (reference == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final PsiElement psiElement = reference.resolve();
|
||||
if (psiElement instanceof PsiClass && JAVA_AWT_COLOR.equals(((PsiClass)psiElement).getQualifiedName())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isValueArguments(@Nullable PsiExpressionList arguments) {
|
||||
if (arguments == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (PsiExpression argument : arguments.getExpressions()) {
|
||||
if (argument instanceof PsiReferenceExpression) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+14
-42
@@ -46,9 +46,7 @@ import static com.intellij.patterns.PlatformPatterns.psiElement;
|
||||
* @author spleaner
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class ColorChooserIntentionAction extends PsiElementBaseIntentionAction {
|
||||
private static final String JAVA_AWT_COLOR = "java.awt.Color";
|
||||
|
||||
public class ColorChooserIntentionAction extends BaseColorIntentionAction {
|
||||
private static final PsiMethodPattern DECODE_METHOD = PsiJavaPatterns.psiMethod()
|
||||
.definedInClass(JAVA_AWT_COLOR)
|
||||
.withName("decode");
|
||||
@@ -64,20 +62,7 @@ public class ColorChooserIntentionAction extends PsiElementBaseIntentionAction {
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) {
|
||||
// new Color(...)
|
||||
if (psiElement().inside(psiElement(PsiNewExpression.class)).accepts(element)) {
|
||||
final PsiNewExpression expression = PsiTreeUtil.getParentOfType(element, PsiNewExpression.class, false);
|
||||
if (expression != null) {
|
||||
final PsiJavaCodeReferenceElement ref = PsiTreeUtil.getChildOfType(expression, PsiJavaCodeReferenceElement.class);
|
||||
if (isJavaAwtColor(ref)) return true;
|
||||
}
|
||||
}
|
||||
// Color.decode("...")
|
||||
if (isInsideDecodeOrGetColorMethod(element)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return super.isAvailable(project, editor, element) || isInsideDecodeOrGetColorMethod(element);
|
||||
}
|
||||
|
||||
public static boolean isInsideDecodeOrGetColorMethod(PsiElement element) {
|
||||
@@ -85,24 +70,10 @@ public class ColorChooserIntentionAction extends PsiElementBaseIntentionAction {
|
||||
element = element.getParent();
|
||||
}
|
||||
|
||||
return PsiJavaPatterns.psiExpression().methodCallParameter(0, DECODE_METHOD).accepts(element)
|
||||
||
|
||||
return PsiJavaPatterns.psiExpression().methodCallParameter(0, DECODE_METHOD).accepts(element) ||
|
||||
PsiJavaPatterns.psiExpression().methodCallParameter(0, GET_COLOR_METHOD).accepts(element);
|
||||
}
|
||||
|
||||
private static boolean isJavaAwtColor(final PsiJavaCodeReferenceElement ref) {
|
||||
if (ref != null) {
|
||||
final PsiReference reference = ref.getReference();
|
||||
if (reference != null) {
|
||||
final PsiElement psiElement = reference.resolve();
|
||||
if (psiElement instanceof PsiClass && JAVA_AWT_COLOR.equals(((PsiClass)psiElement).getQualifiedName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
@@ -116,7 +87,8 @@ public class ColorChooserIntentionAction extends PsiElementBaseIntentionAction {
|
||||
final JComponent editorComponent = editor.getComponent();
|
||||
if (isInsideDecodeOrGetColorMethod(element)) {
|
||||
invokeForMethodParam(editorComponent, element);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
invokeForConstructor(editorComponent, element);
|
||||
}
|
||||
}
|
||||
@@ -139,9 +111,9 @@ public class ColorChooserIntentionAction extends PsiElementBaseIntentionAction {
|
||||
if (color == null) return;
|
||||
final int rgb = color.getRGB() - ((255 & 0xFF) << 24);
|
||||
if (color != null && rgb != oldColor.getRGB()) {
|
||||
final String newText = radix == 16 ? hexPrefix + String.format("%6s" ,Integer.toHexString(rgb)).replace(' ', '0')
|
||||
: radix == 8 ? "0" + Integer.toOctalString(rgb)
|
||||
: Integer.toString(rgb);
|
||||
final String newText = radix == 16 ? hexPrefix + String.format("%6s", Integer.toHexString(rgb)).replace(' ', '0')
|
||||
: radix == 8 ? "0" + Integer.toOctalString(rgb)
|
||||
: Integer.toString(rgb);
|
||||
final PsiManager manager = literal.getManager();
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
|
||||
final PsiExpression newLiteral = factory.createExpressionFromText("\"" + newText + "\"", literal);
|
||||
@@ -221,12 +193,12 @@ public class ColorChooserIntentionAction extends PsiElementBaseIntentionAction {
|
||||
final PsiManager manager = expression.getManager();
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
|
||||
final PsiExpression newCall = factory.createExpressionFromText(
|
||||
"new " + JAVA_AWT_COLOR +"("
|
||||
+ color.getRed() + ", "
|
||||
+ color.getGreen() + ", "
|
||||
+ color.getBlue()
|
||||
+ (color.getAlpha() < 255 ? ", " + color.getAlpha() : "")
|
||||
+")", expression);
|
||||
"new " + JAVA_AWT_COLOR + "("
|
||||
+ color.getRed() + ", "
|
||||
+ color.getGreen() + ", "
|
||||
+ color.getBlue()
|
||||
+ (color.getAlpha() < 255 ? ", " + color.getAlpha() : "")
|
||||
+ ")", expression);
|
||||
final PsiElement insertedElement = expression.replace(newCall);
|
||||
final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject());
|
||||
codeStyleManager.reformat(insertedElement);
|
||||
|
||||
+3
-1
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.intention.impl;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightUtilBase;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
@@ -38,7 +39,6 @@ public class ConvertAbsolutePathToRelativeIntentionAction extends BaseIntentionA
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
|
||||
final PsiReference reference = file.findReferenceAt(editor.getCaretModel().getOffset());
|
||||
final FileReference fileReference = reference == null ? null : findFileReference(reference);
|
||||
|
||||
@@ -81,6 +81,8 @@ public class ConvertAbsolutePathToRelativeIntentionAction extends BaseIntentionA
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
if (!CodeInsightUtilBase.prepareFileForWrite(file)) return;
|
||||
|
||||
final PsiReference reference = file.findReferenceAt(editor.getCaretModel().getOffset());
|
||||
final FileReference fileReference = reference == null ? null : findFileReference(reference);
|
||||
if (fileReference != null) {
|
||||
|
||||
+226
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.CodeInsightBundle;
|
||||
import com.intellij.codeInsight.CodeInsightUtilBase;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.JavaConstantExpressionEvaluator;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Danila Ponomarenko
|
||||
*/
|
||||
public class ConvertColorRepresentationIntentionAction extends BaseColorIntentionAction {
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
|
||||
if (!super.isAvailable(project, editor, element)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final PsiNewExpression expression = PsiTreeUtil.getParentOfType(element, PsiNewExpression.class, false);
|
||||
if (expression == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final PsiExpressionList arguments = expression.getArgumentList();
|
||||
if (arguments == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final PsiMethod constructor = expression.resolveConstructor();
|
||||
if (constructor == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final PsiExpressionList newArguments = createNewArguments(JavaPsiFacade.getElementFactory(project), constructor.getParameterList().getParameters(), arguments.getExpressions());
|
||||
|
||||
if (newArguments == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
setText(CodeInsightBundle.message("intention.convert.color.representation.text", newArguments.getText()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
|
||||
if (!CodeInsightUtilBase.preparePsiElementForWrite(element)) return;
|
||||
|
||||
final PsiNewExpression expression = PsiTreeUtil.getParentOfType(element, PsiNewExpression.class, false);
|
||||
if (expression == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final PsiExpressionList arguments = expression.getArgumentList();
|
||||
if (arguments == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final PsiMethod constructor = expression.resolveConstructor();
|
||||
if (constructor == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final PsiExpressionList newArguments = createNewArguments(
|
||||
JavaPsiFacade.getElementFactory(project),
|
||||
constructor.getParameterList().getParameters(),
|
||||
arguments.getExpressions()
|
||||
);
|
||||
|
||||
if (newArguments == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
arguments.replace(newArguments);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiExpressionList createNewArguments(@NotNull PsiElementFactory factory,
|
||||
@NotNull PsiParameter[] parameters,
|
||||
@NotNull PsiExpression[] arguments) {
|
||||
final String[] newValues = createArguments(parameters, arguments);
|
||||
if (newValues == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final PsiExpressionList result = ((PsiNewExpression)factory.createExpressionFromText("new Object()", parameters[0])).getArgumentList();
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
for (String value : newValues) {
|
||||
result.add(factory.createExpressionFromText(value, parameters[0]));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String[] createArguments(@NotNull PsiParameter[] parameters,
|
||||
@NotNull PsiExpression[] arguments) {
|
||||
if (parameters.length != arguments.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (parameters.length) {
|
||||
default:
|
||||
return null;
|
||||
case 1:
|
||||
return createArguments(arguments[0]);
|
||||
case 2:
|
||||
return createArguments(arguments[0], arguments[1]);
|
||||
case 3:
|
||||
return createArguments(arguments[0], arguments[1], arguments[2]);
|
||||
case 4:
|
||||
return createArguments(arguments[0], arguments[1], arguments[2], arguments[3]);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String[] createArguments(@NotNull PsiExpression rgbExpression) {
|
||||
return createArguments(rgbExpression, 3);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String[] createArguments(@NotNull PsiExpression rgbExpression,
|
||||
@NotNull PsiExpression hasAlphaExpression) {
|
||||
final Boolean hasAlpha = computeBoolean(hasAlphaExpression);
|
||||
if (hasAlpha == null) {
|
||||
return null;
|
||||
}
|
||||
return hasAlpha ? createArguments(rgbExpression, 4) : createArguments(rgbExpression);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String[] createArguments(@NotNull PsiExpression rExpression,
|
||||
@NotNull PsiExpression gExpression,
|
||||
@NotNull PsiExpression bExpression) {
|
||||
final Integer value = createInt(computeInteger(rExpression), computeInteger(gExpression), computeInteger(bExpression));
|
||||
return value != null ? new String[]{"0x" + Integer.toHexString(value)} : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String[] createArguments(@NotNull PsiExpression rExpression,
|
||||
@NotNull PsiExpression gExpression,
|
||||
@NotNull PsiExpression bExpression,
|
||||
@NotNull PsiExpression aExpression) {
|
||||
final Integer value = createInt(computeInteger(rExpression), computeInteger(gExpression), computeInteger(bExpression), computeInteger(aExpression));
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new String[]{
|
||||
"0x" + Integer.toHexString(value),
|
||||
"true",
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String[] createArguments(@NotNull PsiExpression rgbExpression,
|
||||
int parts) {
|
||||
final Integer rgb = computeInteger(rgbExpression);
|
||||
if (rgb == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final String[] result = new String[parts];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[result.length - i - 1] = String.valueOf(rgb >> (i * Byte.SIZE) & 0xFF);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Integer createInt(Integer... ints) {
|
||||
int result = 0;
|
||||
for (Integer i : ints) {
|
||||
if (i == null) {
|
||||
return null;
|
||||
}
|
||||
result = result << Byte.SIZE | (i & 0xFF);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Integer computeInteger(@NotNull PsiExpression expr) {
|
||||
final Object result = compute(expr);
|
||||
return result instanceof Integer ? (Integer)result : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Boolean computeBoolean(@NotNull PsiExpression expr) {
|
||||
final Object result = compute(expr);
|
||||
return result instanceof Boolean ? (Boolean)result : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Object compute(@NotNull PsiExpression expr) {
|
||||
return JavaConstantExpressionEvaluator.computeConstantExpression(expr, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return CodeInsightBundle.message("intention.convert.color.representation.family");
|
||||
}
|
||||
}
|
||||
@@ -28,10 +28,9 @@ import com.intellij.psi.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TypeExpression extends Expression {
|
||||
private final Set<SmartTypePointer> myItems;
|
||||
private final LinkedHashSet<SmartTypePointer> myItems;
|
||||
|
||||
public TypeExpression(final Project project, PsiType[] types) {
|
||||
final SmartTypePointerManager manager = SmartTypePointerManager.getInstance(project);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.codeInsight.lookup;
|
||||
|
||||
import com.intellij.codeInsight.completion.*;
|
||||
import com.intellij.ide.highlighter.XmlLikeFileType;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ScrollType;
|
||||
import com.intellij.openapi.util.ClassConditionKey;
|
||||
@@ -79,7 +80,11 @@ public class PsiTypeLookupItem extends LookupItem {
|
||||
PsiElement position = context.getFile().findElementAt(context.getStartOffset());
|
||||
assert position != null;
|
||||
int genericsStart = context.getTailOffset();
|
||||
context.getDocument().insertString(genericsStart, calcGenerics(position, context));
|
||||
String generics = calcGenerics(position, context);
|
||||
if (context.getFile().getFileType() instanceof XmlLikeFileType) {
|
||||
generics = StringUtil.escapeXml(generics);
|
||||
}
|
||||
context.getDocument().insertString(genericsStart, generics);
|
||||
JavaCompletionUtil.shortenReference(context.getFile(), genericsStart - 1);
|
||||
|
||||
int tail = context.getTailOffset();
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.dataFlow.instructions.*;
|
||||
import com.intellij.codeInspection.ex.BaseLocalInspectionTool;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.lang.ASTFactory;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -41,6 +42,8 @@ import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.codeStyle.CodeFormatterFacade;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
@@ -230,8 +233,11 @@ public class DataFlowInspection extends BaseLocalInspectionTool {
|
||||
else if (psiAnchor != null && !reportedAnchors.contains(psiAnchor) && !isCompileConstantInIfCondition(psiAnchor)) {
|
||||
boolean evaluatesToTrue = trueSet.contains(instruction);
|
||||
if (onTheLeftSideOfConditionalAssignemnt(psiAnchor)) {
|
||||
holder.registerProblem(psiAnchor, InspectionsBundle.message("dataflow.message.pointless.assignment.expression",
|
||||
Boolean.toString(evaluatesToTrue)));
|
||||
holder.registerProblem(
|
||||
psiAnchor,
|
||||
InspectionsBundle.message("dataflow.message.pointless.assignment.expression", Boolean.toString(evaluatesToTrue)),
|
||||
createSimplifyToAssignmentFix()
|
||||
);
|
||||
}
|
||||
else {
|
||||
boolean report = !(psiAnchor.getParent() instanceof PsiAssertStatement) || !DONT_REPORT_TRUE_ASSERT_STATEMENTS || !evaluatesToTrue;
|
||||
@@ -370,6 +376,40 @@ public class DataFlowInspection extends BaseLocalInspectionTool {
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static LocalQuickFix createSimplifyToAssignmentFix() {
|
||||
return new LocalQuickFix() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return InspectionsBundle.message("inspection.data.flow.simplify.to.assignment.quickfix.name");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return InspectionsBundle.message("inspection.data.flow.simplify.boolean.expression.quickfix");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement psiElement = descriptor.getPsiElement();
|
||||
if (psiElement == null) return;
|
||||
|
||||
final PsiAssignmentExpression assignmentExpression = PsiTreeUtil.getParentOfType(psiElement, PsiAssignmentExpression.class);
|
||||
if (assignmentExpression == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
|
||||
final String lExpressionText = assignmentExpression.getLExpression().getText();
|
||||
final PsiExpression rExpression = assignmentExpression.getRExpression();
|
||||
final String rExpressionText = rExpression != null ? rExpression.getText() : "";
|
||||
assignmentExpression.replace(factory.createExpressionFromText(lExpressionText + " = " + rExpressionText, psiElement));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static SimplifyBooleanExpressionFix createIntention(PsiElement element, boolean value) {
|
||||
if (!(element instanceof PsiExpression)) return null;
|
||||
final PsiExpression expression = (PsiExpression)element;
|
||||
|
||||
@@ -27,14 +27,15 @@ package com.intellij.codeInspection.dataFlow;
|
||||
import com.intellij.codeInsight.NullableNotNullManager;
|
||||
import com.intellij.codeInspection.dataFlow.value.DfaTypeValue;
|
||||
import com.intellij.codeInspection.dataFlow.value.DfaValue;
|
||||
import com.intellij.psi.PsiPrimitiveType;
|
||||
import com.intellij.psi.PsiVariable;
|
||||
import com.intellij.codeInspection.nullable.NullableStuffInspection;
|
||||
import com.intellij.psi.*;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class DfaVariableState implements Cloneable {
|
||||
@@ -48,8 +49,36 @@ public class DfaVariableState implements Cloneable {
|
||||
myVar = var;
|
||||
myInstanceofValues = new HashSet<DfaTypeValue>();
|
||||
myNotInstanceofValues = new HashSet<DfaTypeValue>();
|
||||
myNullable = var != null && NullableNotNullManager.isNullable(var);
|
||||
myVariableIsDeclaredNotNull = var != null && NullableNotNullManager.isNotNull(var);
|
||||
myNullable = var != null && (NullableNotNullManager.isNullable(var) || isNullableInitialized(var, true));
|
||||
myVariableIsDeclaredNotNull = var != null && (NullableNotNullManager.isNotNull(var) || isNullableInitialized(var, false));
|
||||
}
|
||||
|
||||
private static boolean isNullableInitialized(PsiVariable var, boolean nullable) {
|
||||
if (!var.hasModifierProperty(PsiModifier.FINAL) || !(var instanceof PsiField)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<PsiExpression> initializers = NullableStuffInspection.findAllConstructorInitializers((PsiField)var);
|
||||
if (!nullable && initializers.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (PsiExpression expression : initializers) {
|
||||
if (!(expression instanceof PsiReferenceExpression)) {
|
||||
return false;
|
||||
}
|
||||
PsiElement target = ((PsiReferenceExpression)expression).resolve();
|
||||
if (!(target instanceof PsiParameter)) {
|
||||
return false;
|
||||
}
|
||||
if (nullable && NullableNotNullManager.isNullable((PsiParameter)target)) {
|
||||
return true;
|
||||
}
|
||||
if (!nullable && !NullableNotNullManager.isNotNull((PsiParameter)target)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected DfaVariableState(final DfaVariableState toClone) {
|
||||
|
||||
+52
-50
@@ -42,15 +42,18 @@ import com.intellij.psi.util.*;
|
||||
import com.intellij.refactoring.psi.PropertyUtils;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.Query;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.util.containers.ContainerUtil.addIfNotNull;
|
||||
|
||||
public class NullableStuffInspection extends BaseLocalInspectionTool {
|
||||
// deprecated fields remain to minimize changes to users inspection profiles (which are often located in version control).
|
||||
@Deprecated @SuppressWarnings({"WeakerAccess"}) public boolean REPORT_NULLABLE_METHOD_OVERRIDES_NOTNULL = true;
|
||||
@@ -173,40 +176,13 @@ public class NullableStuffInspection extends BaseLocalInspectionTool {
|
||||
new AddAnnotationFix(anno, parameter, ArrayUtil.toStringArray(annoToRemove)));
|
||||
}
|
||||
}
|
||||
if (containingClass == null) {
|
||||
return;
|
||||
}
|
||||
final PsiMethod[] constructors = containingClass.getConstructors();
|
||||
final Query<PsiReference> search = ReferencesSearch.search(field, new LocalSearchScope(constructors), false);
|
||||
search.forEach(new Processor<PsiReference>() {
|
||||
@Override
|
||||
public boolean process(PsiReference reference) {
|
||||
final PsiElement element = reference.getElement();
|
||||
if (!(element instanceof PsiReferenceExpression)) {
|
||||
return true;
|
||||
}
|
||||
PsiReferenceExpression referenceExpression = (PsiReferenceExpression)element;
|
||||
final PsiAssignmentExpression assignmentExpression = getAssignmentExpressionIfOnAssignmentLefthand(referenceExpression);
|
||||
final PsiMethod method = PsiTreeUtil.getParentOfType(assignmentExpression, PsiMethod.class);
|
||||
if (method == null || !method.isConstructor()) {
|
||||
return true;
|
||||
}
|
||||
if (assignmentExpression == null) {
|
||||
return true;
|
||||
}
|
||||
final PsiExpression rhs = assignmentExpression.getRExpression();
|
||||
if (!(rhs instanceof PsiReferenceExpression)) {
|
||||
return true;
|
||||
}
|
||||
PsiReferenceExpression expression = (PsiReferenceExpression)rhs;
|
||||
final PsiElement target = expression.resolve();
|
||||
if (!(target instanceof PsiParameter)) {
|
||||
return true;
|
||||
}
|
||||
final PsiParameter parameter = (PsiParameter)target;
|
||||
if (!method.equals(parameter.getDeclarationScope())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (PsiExpression rhs : findAllConstructorInitializers(field)) {
|
||||
if (rhs instanceof PsiReferenceExpression) {
|
||||
PsiElement target = ((PsiReferenceExpression)rhs).resolve();
|
||||
if (target instanceof PsiParameter) {
|
||||
PsiParameter parameter = (PsiParameter)target;
|
||||
if (REPORT_NOT_ANNOTATED_GETTER && !AnnotationUtil.isAnnotated(parameter, manager.getAllAnnotations()) && !TypeConversionUtil.isPrimitiveAndNotNull(parameter.getType())) {
|
||||
final PsiIdentifier nameIdentifier2 = parameter.getNameIdentifier();
|
||||
assert nameIdentifier2 != null : parameter;
|
||||
@@ -214,7 +190,7 @@ public class NullableStuffInspection extends BaseLocalInspectionTool {
|
||||
.message("inspection.nullable.problems.annotated.field.constructor.parameter.not.annotated",
|
||||
StringUtil.getShortName(anno)),
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new AddAnnotationFix(anno, parameter, ArrayUtil.toStringArray(annoToRemove)));
|
||||
return true;
|
||||
continue;
|
||||
}
|
||||
if (annotated.isDeclaredNotNull && manager.isNullable(parameter, false)) {
|
||||
final PsiIdentifier nameIdentifier2 = parameter.getNameIdentifier();
|
||||
@@ -234,9 +210,9 @@ public class NullableStuffInspection extends BaseLocalInspectionTool {
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
new AddAnnotationFix(anno, parameter, ArrayUtil.toStringArray(annoToRemove)));
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -246,18 +222,6 @@ public class NullableStuffInspection extends BaseLocalInspectionTool {
|
||||
LOG.assertTrue(parameter.isPhysical(), setter.getText());
|
||||
}
|
||||
|
||||
public PsiAssignmentExpression getAssignmentExpressionIfOnAssignmentLefthand(PsiExpression expression) {
|
||||
PsiElement parent = PsiTreeUtil.skipParentsOfType(expression, PsiParenthesizedExpression.class);
|
||||
if (!(parent instanceof PsiAssignmentExpression)) {
|
||||
return null;
|
||||
}
|
||||
final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)parent;
|
||||
if (!PsiTreeUtil.isAncestor(assignmentExpression.getLExpression(), expression, false)) {
|
||||
return null;
|
||||
}
|
||||
return assignmentExpression;
|
||||
}
|
||||
|
||||
@Override public void visitParameter(PsiParameter parameter) {
|
||||
if (!PsiUtil.isLanguageLevel5OrHigher(parameter)) return;
|
||||
check(parameter, holder, parameter.getType());
|
||||
@@ -519,4 +483,42 @@ public class NullableStuffInspection extends BaseLocalInspectionTool {
|
||||
REPORT_NULLS_PASSED_TO_NON_ANNOTATED_METHOD = myReportNullsPassedToNonAnnotatedParameter.isSelected();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<PsiExpression> findAllConstructorInitializers(PsiField field) {
|
||||
final List<PsiExpression> result = new ArrayList<PsiExpression>();
|
||||
addIfNotNull(result, field.getInitializer());
|
||||
|
||||
PsiClass containingClass = field.getContainingClass();
|
||||
if (containingClass != null) {
|
||||
LocalSearchScope scope = new LocalSearchScope(containingClass.getConstructors());
|
||||
ReferencesSearch.search(field, scope, false).forEach(new Processor<PsiReference>() {
|
||||
@Override
|
||||
public boolean process(PsiReference reference) {
|
||||
final PsiElement element = reference.getElement();
|
||||
if (element instanceof PsiReferenceExpression) {
|
||||
final PsiAssignmentExpression assignment = getAssignmentExpressionIfOnAssignmentLhs(element);
|
||||
final PsiMethod method = PsiTreeUtil.getParentOfType(assignment, PsiMethod.class);
|
||||
if (method != null && method.isConstructor() && assignment != null) {
|
||||
addIfNotNull(result, assignment.getRExpression());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiAssignmentExpression getAssignmentExpressionIfOnAssignmentLhs(PsiElement expression) {
|
||||
PsiElement parent = PsiTreeUtil.skipParentsOfType(expression, PsiParenthesizedExpression.class);
|
||||
if (!(parent instanceof PsiAssignmentExpression)) {
|
||||
return null;
|
||||
}
|
||||
final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)parent;
|
||||
if (!PsiTreeUtil.isAncestor(assignmentExpression.getLExpression(), expression, false)) {
|
||||
return null;
|
||||
}
|
||||
return assignmentExpression;
|
||||
}
|
||||
}
|
||||
|
||||
+77
-39
@@ -25,12 +25,12 @@ import com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor;
|
||||
import com.intellij.refactoring.ui.RefactoringDialog;
|
||||
import com.intellij.refactoring.ui.StringTableCellEditor;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUIUtil;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.table.JBTable;
|
||||
import com.intellij.usageView.UsageViewUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.EditableModel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -39,17 +39,15 @@ import javax.swing.event.TableModelListener;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import javax.swing.table.TableColumn;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class ChangeClassSignatureDialog extends RefactoringDialog {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.changeClassSignature.ChangeClassSignatureDialog");
|
||||
private static final Logger LOG = Logger.getInstance(ChangeClassSignatureDialog.class);
|
||||
private static final int NAME_COLUMN = 0;
|
||||
private static final int VALUE_COLUMN = 1;
|
||||
|
||||
@@ -61,19 +59,53 @@ public class ChangeClassSignatureDialog extends RefactoringDialog {
|
||||
private final MyTableModel myTableModel;
|
||||
private JBTable myTable;
|
||||
static final String REFACTORING_NAME = RefactoringBundle.message("changeClassSignature.refactoring.name");
|
||||
private boolean myHideDefaultValueColumn;
|
||||
|
||||
public ChangeClassSignatureDialog(PsiClass aClass) {
|
||||
public ChangeClassSignatureDialog(@NotNull PsiClass aClass, boolean hideDefaultValueColumn) {
|
||||
this(
|
||||
aClass,
|
||||
initTypeParameterInfos(aClass.getTypeParameters().length),
|
||||
initTypeCodeFragment(aClass.getTypeParameters().length),
|
||||
hideDefaultValueColumn
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<TypeParameterInfo> initTypeParameterInfos(int length) {
|
||||
final List<TypeParameterInfo> result = new ArrayList<TypeParameterInfo>();
|
||||
for (int i = 0; i < length; i++) {
|
||||
result.add(new TypeParameterInfo(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<PsiTypeCodeFragment> initTypeCodeFragment(int length) {
|
||||
final List<PsiTypeCodeFragment> result = new ArrayList<PsiTypeCodeFragment>();
|
||||
for (int i = 0; i < length; i++) {
|
||||
result.add(null);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ChangeClassSignatureDialog(@NotNull PsiClass aClass,
|
||||
@NotNull Map<TypeParameterInfo, PsiTypeCodeFragment> parameters,
|
||||
boolean hideDefaultValueColumn) {
|
||||
this(aClass, parameters.keySet(), parameters.values(), hideDefaultValueColumn);
|
||||
}
|
||||
|
||||
public ChangeClassSignatureDialog(@NotNull PsiClass aClass,
|
||||
@NotNull Collection<TypeParameterInfo> typeParameterInfos,
|
||||
@NotNull Collection<PsiTypeCodeFragment> typeCodeFragments,
|
||||
boolean hideDefaultValueColumn) {
|
||||
super(aClass.getProject(), true);
|
||||
myHideDefaultValueColumn = hideDefaultValueColumn;
|
||||
setTitle(REFACTORING_NAME);
|
||||
myClass = aClass;
|
||||
myProject = myClass.getProject();
|
||||
myTypeParameterInfos = new ArrayList<TypeParameterInfo>();
|
||||
myTypeCodeFragments = new ArrayList<PsiTypeCodeFragment>();
|
||||
myOriginalParameters = myClass.getTypeParameters();
|
||||
for (int i = 0; i < myOriginalParameters.length; i++) {
|
||||
myTypeParameterInfos.add(new TypeParameterInfo(i));
|
||||
myTypeCodeFragments.add(null);
|
||||
}
|
||||
myTypeParameterInfos = new ArrayList<TypeParameterInfo>(typeParameterInfos);
|
||||
myTypeCodeFragments = new ArrayList<PsiTypeCodeFragment>(typeCodeFragments);
|
||||
myTableModel = new MyTableModel();
|
||||
init();
|
||||
}
|
||||
@@ -115,26 +147,28 @@ public class ChangeClassSignatureDialog extends RefactoringDialog {
|
||||
myTable.setCellSelectionEnabled(true);
|
||||
myTable.setFocusCycleRoot(true);
|
||||
|
||||
final TableColumn defaultValue = myTable.getColumnModel().getColumn(1);
|
||||
myTable.removeColumn(defaultValue);
|
||||
myTable.getModel().addTableModelListener(new TableModelListener() {
|
||||
@Override
|
||||
public void tableChanged(TableModelEvent e) {
|
||||
if (e.getType() == TableModelEvent.INSERT) {
|
||||
myTable.getModel().removeTableModelListener(this);
|
||||
final TableColumnAnimator animator = new TableColumnAnimator(myTable);
|
||||
animator.setStep(20);
|
||||
animator.addColumn(defaultValue, myTable.getWidth() / 2);
|
||||
animator.startAndDoWhenDone(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
myTable.editCellAt(myTable.getRowCount() - 1, 0);
|
||||
}
|
||||
});
|
||||
animator.start();
|
||||
if (myHideDefaultValueColumn) {
|
||||
final TableColumn defaultValue = myTable.getColumnModel().getColumn(VALUE_COLUMN);
|
||||
myTable.removeColumn(defaultValue);
|
||||
myTable.getModel().addTableModelListener(new TableModelListener() {
|
||||
@Override
|
||||
public void tableChanged(TableModelEvent e) {
|
||||
if (e.getType() == TableModelEvent.INSERT) {
|
||||
myTable.getModel().removeTableModelListener(this);
|
||||
final TableColumnAnimator animator = new TableColumnAnimator(myTable);
|
||||
animator.setStep(20);
|
||||
animator.addColumn(defaultValue, myTable.getWidth() / 2);
|
||||
animator.startAndDoWhenDone(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
myTable.editCellAt(myTable.getRowCount() - 1, 0);
|
||||
}
|
||||
});
|
||||
animator.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
final JPanel panel = new JPanel(new BorderLayout());
|
||||
panel.add(SeparatorFactory.createSeparator(RefactoringBundle.message("changeClassSignature.parameters.panel.border.title"), myTable), BorderLayout.NORTH);
|
||||
@@ -208,12 +242,13 @@ public class ChangeClassSignatureDialog extends RefactoringDialog {
|
||||
}
|
||||
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
switch(columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case NAME_COLUMN:
|
||||
TypeParameterInfo info = myTypeParameterInfos.get(rowIndex);
|
||||
if (info.isForExistingParameter()) {
|
||||
return myOriginalParameters[info.getOldParameterIndex()].getName();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return info.getNewName();
|
||||
}
|
||||
case VALUE_COLUMN:
|
||||
@@ -228,18 +263,21 @@ public class ChangeClassSignatureDialog extends RefactoringDialog {
|
||||
}
|
||||
|
||||
public String getColumnName(int column) {
|
||||
switch(column) {
|
||||
case NAME_COLUMN: return RefactoringBundle.message("column.name.name");
|
||||
case VALUE_COLUMN: return RefactoringBundle.message("changeSignature.default.value.column");
|
||||
default: LOG.assertTrue(false);
|
||||
switch (column) {
|
||||
case NAME_COLUMN:
|
||||
return RefactoringBundle.message("column.name.name");
|
||||
case VALUE_COLUMN:
|
||||
return RefactoringBundle.message("changeSignature.default.value.column");
|
||||
default:
|
||||
LOG.assertTrue(false);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
|
||||
switch(columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case NAME_COLUMN:
|
||||
myTypeParameterInfos.get(rowIndex).setNewName((String) aValue);
|
||||
myTypeParameterInfos.get(rowIndex).setNewName((String)aValue);
|
||||
break;
|
||||
case VALUE_COLUMN:
|
||||
break;
|
||||
|
||||
+3
-3
@@ -25,17 +25,17 @@ import org.jetbrains.annotations.NonNls;
|
||||
/**
|
||||
* @author dsl
|
||||
*/
|
||||
class TypeParameterInfo {
|
||||
public class TypeParameterInfo {
|
||||
private final int myOldParameterIndex;
|
||||
private String myNewName;
|
||||
private CanonicalTypes.Type myDefaultValue;
|
||||
|
||||
TypeParameterInfo(int oldIndex) {
|
||||
public TypeParameterInfo(int oldIndex) {
|
||||
myOldParameterIndex = oldIndex;
|
||||
myDefaultValue = null;
|
||||
}
|
||||
|
||||
TypeParameterInfo(String name, PsiType aType) {
|
||||
public TypeParameterInfo(String name, PsiType aType) {
|
||||
myOldParameterIndex = -1;
|
||||
myNewName = name;
|
||||
if (aType != null) {
|
||||
|
||||
+7
-1
@@ -20,6 +20,8 @@ import com.intellij.ide.util.SuperMethodWarningUtil;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.LangDataKeys;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ScrollType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -99,8 +101,12 @@ public class JavaChangeSignatureHandler implements ChangeSignatureHandler {
|
||||
}
|
||||
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, aClass)) return;
|
||||
|
||||
ChangeClassSignatureDialog dialog = new ChangeClassSignatureDialog(aClass);
|
||||
ChangeClassSignatureDialog dialog = new ChangeClassSignatureDialog(aClass, true);
|
||||
//if (!ApplicationManager.getApplication().isUnitTestMode()){
|
||||
dialog.show();
|
||||
//}else {
|
||||
// dialog.showAndGetOk()
|
||||
//}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -24,31 +24,31 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Map;
|
||||
|
||||
public class PsiTypesUtil {
|
||||
@NonNls private static final Map<String, String> ourUnboxedTypes = new THashMap<String, String>();
|
||||
@NonNls private static final Map<String, String> ourBoxedTypes = new THashMap<String, String>();
|
||||
@NonNls private static final Map<String, String> ourUnboxedTypes = new THashMap<String, String>() {{
|
||||
put(CommonClassNames.JAVA_LANG_BOOLEAN, "boolean");
|
||||
put(CommonClassNames.JAVA_LANG_BYTE, "byte");
|
||||
put(CommonClassNames.JAVA_LANG_SHORT, "short");
|
||||
put(CommonClassNames.JAVA_LANG_INTEGER, "int");
|
||||
put(CommonClassNames.JAVA_LANG_LONG, "long");
|
||||
put(CommonClassNames.JAVA_LANG_FLOAT, "float");
|
||||
put(CommonClassNames.JAVA_LANG_DOUBLE, "double");
|
||||
put(CommonClassNames.JAVA_LANG_CHARACTER, "char");
|
||||
}};
|
||||
|
||||
static {
|
||||
ourUnboxedTypes.put(CommonClassNames.JAVA_LANG_BOOLEAN, "boolean");
|
||||
ourUnboxedTypes.put(CommonClassNames.JAVA_LANG_BYTE, "byte");
|
||||
ourUnboxedTypes.put(CommonClassNames.JAVA_LANG_SHORT, "short");
|
||||
ourUnboxedTypes.put(CommonClassNames.JAVA_LANG_INTEGER, "int");
|
||||
ourUnboxedTypes.put(CommonClassNames.JAVA_LANG_LONG, "long");
|
||||
ourUnboxedTypes.put(CommonClassNames.JAVA_LANG_FLOAT, "float");
|
||||
ourUnboxedTypes.put(CommonClassNames.JAVA_LANG_DOUBLE, "double");
|
||||
ourUnboxedTypes.put(CommonClassNames.JAVA_LANG_CHARACTER, "char");
|
||||
@NonNls private static final Map<String, String> ourBoxedTypes = new THashMap<String, String>() {{
|
||||
put("boolean", CommonClassNames.JAVA_LANG_BOOLEAN);
|
||||
put("byte", CommonClassNames.JAVA_LANG_BYTE);
|
||||
put("short", CommonClassNames.JAVA_LANG_SHORT);
|
||||
put("int", CommonClassNames.JAVA_LANG_INTEGER);
|
||||
put("long", CommonClassNames.JAVA_LANG_LONG);
|
||||
put("float", CommonClassNames.JAVA_LANG_FLOAT);
|
||||
put("double", CommonClassNames.JAVA_LANG_DOUBLE);
|
||||
put("char", CommonClassNames.JAVA_LANG_CHARACTER);
|
||||
}};
|
||||
|
||||
ourBoxedTypes.put("boolean", CommonClassNames.JAVA_LANG_BOOLEAN);
|
||||
ourBoxedTypes.put("byte", CommonClassNames.JAVA_LANG_BYTE);
|
||||
ourBoxedTypes.put("short", CommonClassNames.JAVA_LANG_SHORT);
|
||||
ourBoxedTypes.put("int", CommonClassNames.JAVA_LANG_INTEGER);
|
||||
ourBoxedTypes.put("long", CommonClassNames.JAVA_LANG_LONG);
|
||||
ourBoxedTypes.put("float", CommonClassNames.JAVA_LANG_FLOAT);
|
||||
ourBoxedTypes.put("double", CommonClassNames.JAVA_LANG_DOUBLE);
|
||||
ourBoxedTypes.put("char", CommonClassNames.JAVA_LANG_CHARACTER);
|
||||
private PsiTypesUtil() {
|
||||
}
|
||||
|
||||
private PsiTypesUtil() { }
|
||||
|
||||
public static String getDefaultValueOfType(PsiType type) {
|
||||
if (type instanceof PsiArrayType) {
|
||||
int count = type.getArrayDimensions() - 1;
|
||||
@@ -86,6 +86,7 @@ public class PsiTypesUtil {
|
||||
|
||||
/**
|
||||
* Returns the unboxed type name or parameter.
|
||||
*
|
||||
* @param type boxed java type name
|
||||
* @return unboxed type name if available; same value otherwise
|
||||
*/
|
||||
@@ -93,11 +94,12 @@ public class PsiTypesUtil {
|
||||
public static String unboxIfPossible(final String type) {
|
||||
if (type == null) return null;
|
||||
final String s = ourUnboxedTypes.get(type);
|
||||
return s == null? type : s;
|
||||
return s == null ? type : s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the boxed type name or parameter.
|
||||
*
|
||||
* @param type primitive java type name
|
||||
* @return boxed type name if available; same value otherwise
|
||||
*/
|
||||
@@ -110,7 +112,7 @@ public class PsiTypesUtil {
|
||||
|
||||
@Nullable
|
||||
public static PsiClass getPsiClass(final PsiType psiType) {
|
||||
return psiType instanceof PsiClassType? ((PsiClassType)psiType).resolve() : null;
|
||||
return psiType instanceof PsiClassType ? ((PsiClassType)psiType).resolve() : null;
|
||||
}
|
||||
|
||||
public static PsiClassType getClassType(@NotNull PsiClass psiClass) {
|
||||
|
||||
@@ -2,6 +2,6 @@ class List<T> {}
|
||||
|
||||
class C {
|
||||
void foo () {
|
||||
List<? extends String>[] array = new List<? extends String>[<caret>];
|
||||
List<? extends String>[] array = new List[<caret>];
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Convert to 'new Color(37, 100, 120)'" "true"
|
||||
|
||||
package java.awt;
|
||||
|
||||
public class A {
|
||||
private Color color = new Color(37, 100, 120);
|
||||
}
|
||||
|
||||
class Color {
|
||||
Color(int r, int g, int b) {
|
||||
}
|
||||
|
||||
Color(int r, int g, int b, int a) {
|
||||
}
|
||||
|
||||
Color(int rgb) {
|
||||
}
|
||||
|
||||
Color(int rgba, boolean hasAlpha) {
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Convert to 'new Color(37, 100, 120, 140)'" "true"
|
||||
|
||||
package java.awt;
|
||||
|
||||
class A {
|
||||
private Color color = new Color(37, 100, 120, 140);
|
||||
}
|
||||
|
||||
class Color {
|
||||
Color(int r, int g, int b) {
|
||||
}
|
||||
|
||||
Color(int r, int g, int b, int a) {
|
||||
}
|
||||
|
||||
Color(int rgb) {
|
||||
}
|
||||
|
||||
Color(int rgba, boolean hasAlpha) {
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Convert to 'new Color(0x256478)'" "true"
|
||||
|
||||
package java.awt;
|
||||
|
||||
class A {
|
||||
private Color color = new Color(0x256478);
|
||||
}
|
||||
|
||||
class Color {
|
||||
Color(int r, int g, int b) {
|
||||
}
|
||||
|
||||
Color(int r, int g, int b, int a) {
|
||||
}
|
||||
|
||||
Color(int rgb) {
|
||||
}
|
||||
|
||||
Color(int rgba, boolean hasAlpha) {
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Convert to 'new Color(0x2564788c,true)'" "true"
|
||||
|
||||
package java.awt;
|
||||
|
||||
class A {
|
||||
private Color color = new Color(0x2564788c, true);
|
||||
}
|
||||
|
||||
class Color {
|
||||
Color(int r, int g, int b) {
|
||||
}
|
||||
|
||||
Color(int r, int g, int b, int a) {
|
||||
}
|
||||
|
||||
Color(int rgb) {
|
||||
}
|
||||
|
||||
Color(int rgba, boolean hasAlpha) {
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Convert to 'new Color(37, 100, 120)'" "true"
|
||||
|
||||
package java.awt;
|
||||
|
||||
public class A {
|
||||
private Color color = new Color(0x25<caret>6478);
|
||||
}
|
||||
|
||||
class Color {
|
||||
Color(int r, int g, int b) {
|
||||
}
|
||||
|
||||
Color(int r, int g, int b, int a) {
|
||||
}
|
||||
|
||||
Color(int rgb) {
|
||||
}
|
||||
|
||||
Color(int rgba, boolean hasAlpha) {
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Convert to 'new Color(37, 100, 120, 140)'" "true"
|
||||
|
||||
package java.awt;
|
||||
|
||||
class A {
|
||||
private Color color = new Color(0x25647<caret>88c, true);
|
||||
}
|
||||
|
||||
class Color {
|
||||
Color(int r, int g, int b) {
|
||||
}
|
||||
|
||||
Color(int r, int g, int b, int a) {
|
||||
}
|
||||
|
||||
Color(int rgb) {
|
||||
}
|
||||
|
||||
Color(int rgba, boolean hasAlpha) {
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Convert to 'new Color(0x256478)'" "true"
|
||||
|
||||
package java.awt;
|
||||
|
||||
class A {
|
||||
private Color color = new Color(37, 100,<caret> 120);
|
||||
}
|
||||
|
||||
class Color {
|
||||
Color(int r, int g, int b) {
|
||||
}
|
||||
|
||||
Color(int r, int g, int b, int a) {
|
||||
}
|
||||
|
||||
Color(int rgb) {
|
||||
}
|
||||
|
||||
Color(int rgba, boolean hasAlpha) {
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Convert to 'new Color(0x2564788c,true)'" "true"
|
||||
|
||||
package java.awt;
|
||||
|
||||
class A {
|
||||
private Color color = new Color(37, 100,<caret> 120, 140);
|
||||
}
|
||||
|
||||
class Color {
|
||||
Color(int r, int g, int b) {
|
||||
}
|
||||
|
||||
Color(int r, int g, int b, int a) {
|
||||
}
|
||||
|
||||
Color(int rgb) {
|
||||
}
|
||||
|
||||
Color(int rgba, boolean hasAlpha) {
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class Doo {
|
||||
private final Object myA;
|
||||
private final Object myB;
|
||||
|
||||
public Doo(@Nullable Object myA, @NotNull Object myB) {
|
||||
this.myA = myA;
|
||||
this.myB = myB;
|
||||
}
|
||||
|
||||
int foo() {
|
||||
if (<warning descr="Condition 'myB != null' is always 'true'">myB != null</warning> &&
|
||||
<warning descr="Method invocation 'myA.equals(myB)' may produce 'java.lang.NullPointerException'">myA.equals(myB)</warning>) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
return myA.hashCode();
|
||||
}
|
||||
}
|
||||
@@ -62,4 +62,12 @@
|
||||
<description>Constructor parameter for @NotNull field might be annotated @NotNull itself</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>Test.java</file>
|
||||
<line>63</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">@NotNull/@Nullable problems</problem_class>
|
||||
<description>Constructor parameter for @NotNull field might be annotated @NotNull itself</description>
|
||||
</problem>
|
||||
|
||||
|
||||
</problems>
|
||||
|
||||
+9
@@ -55,4 +55,13 @@ class D {
|
||||
D(long l) {
|
||||
myL = l;
|
||||
}
|
||||
}
|
||||
|
||||
class E {
|
||||
final @NotNull C c;
|
||||
|
||||
E(C c) {
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.daemon.quickFix;
|
||||
|
||||
/**
|
||||
* @author Danila Ponomarenko
|
||||
*/
|
||||
public class ConvertColorRepresentationTest extends LightQuickFix15TestCase {
|
||||
|
||||
public void test() throws Exception { doAllTests(); }
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/convertColorRepresentation";
|
||||
}
|
||||
}
|
||||
+8
@@ -1,5 +1,6 @@
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.CreateFieldFromUsageFix;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
@@ -22,7 +23,14 @@ public class CreateFieldFromUsageTest extends LightQuickFixTestCase{
|
||||
public void testCreateFromEquals() throws Exception { doSingleTest(); }
|
||||
public void testCreateFromEqualsToPrimitiveType() throws Exception { doSingleTest(); }
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
CreateFieldFromUsageFix.DEBUG = false;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testSortByRelevance() throws Exception {
|
||||
CreateFieldFromUsageFix.DEBUG = true;
|
||||
new WriteCommandAction(getProject()) {
|
||||
@Override
|
||||
protected void run(Result result) throws Exception {
|
||||
|
||||
@@ -365,6 +365,22 @@ class Test {
|
||||
assertTrue(fold('test1').expanded)
|
||||
assertFalse(fold('test2').expanded)
|
||||
}
|
||||
|
||||
public void testUnorderedFoldRegionsRegistration() {
|
||||
def text = '01234567'
|
||||
configure text
|
||||
def foldModel = myFixture.editor.foldingModel as FoldingModelImpl
|
||||
foldModel.runBatchFoldingOperation {
|
||||
def innerFold = foldModel.addFoldRegion(3, 5, '...')
|
||||
def outerFold = foldModel.addFoldRegion(2, 6, '...')
|
||||
innerFold.expanded = false
|
||||
outerFold.expanded = false
|
||||
}
|
||||
def folds = foldModel.fetchVisible()
|
||||
assertEquals(1, folds.length)
|
||||
assertEquals(2, folds[0].startOffset)
|
||||
assertEquals(6, folds[0].endOffset)
|
||||
}
|
||||
|
||||
private def configure(String text) {
|
||||
myFixture.configureByText("a.java", text)
|
||||
|
||||
@@ -65,5 +65,6 @@ public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCas
|
||||
public void testStringTernaryAlwaysTrue() throws Throwable { doTest(); }
|
||||
|
||||
public void testBoxing128() throws Throwable { doTest(); }
|
||||
public void testFinalFieldsInitializedByAnnotatedParameters() throws Throwable { doTest(); }
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileFilter;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
@@ -683,30 +683,8 @@ public class SrcRepositoryUseTest extends PsiTestCase{
|
||||
psiFile.getText();
|
||||
assertNotNull(aClass);
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
VirtualFile newSourceRoot = psiFile.getVirtualFile().getParent();
|
||||
final ModifiableRootModel rootModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
|
||||
final ContentEntry[] content = rootModel.getContentEntries();
|
||||
boolean contentToChangeFound = false;
|
||||
for (ContentEntry contentEntry : content) {
|
||||
final SourceFolder[] sourceFolders = contentEntry.getSourceFolders();
|
||||
for (SourceFolder sourceFolder : sourceFolders) {
|
||||
contentEntry.removeSourceFolder(sourceFolder);
|
||||
}
|
||||
final VirtualFile contentRoot = contentEntry.getFile();
|
||||
if (contentRoot != null && VfsUtil.isAncestor(contentRoot, newSourceRoot, false)) {
|
||||
contentEntry.addSourceFolder(newSourceRoot, false);
|
||||
contentToChangeFound = true;
|
||||
}
|
||||
}
|
||||
assertTrue(contentToChangeFound);
|
||||
rootModel.commit();
|
||||
}
|
||||
}
|
||||
);
|
||||
final VirtualFile newSourceRoot = psiFile.getVirtualFile().getParent();
|
||||
replaceSourceRoot(newSourceRoot);
|
||||
|
||||
assertEquals("MyInterface1", aClass.getName());
|
||||
}
|
||||
@@ -715,11 +693,17 @@ public class SrcRepositoryUseTest extends PsiTestCase{
|
||||
final PsiClass aClass = myJavaFacade.findClass("pack.MyInterface1", GlobalSearchScope.allScope(myProject));
|
||||
assertNotNull(aClass);
|
||||
|
||||
final VirtualFile newSourceRoot = aClass.getContainingFile().getVirtualFile().getParent();
|
||||
replaceSourceRoot(newSourceRoot);
|
||||
|
||||
assertEquals("MyInterface1", aClass.getName());
|
||||
}
|
||||
|
||||
private void replaceSourceRoot(final VirtualFile newSourceRoot) {
|
||||
ApplicationManager.getApplication().runWriteAction(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
VirtualFile newSourceRoot = aClass.getContainingFile().getVirtualFile().getParent();
|
||||
final ModifiableRootModel rootModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
|
||||
final ContentEntry[] content = rootModel.getContentEntries();
|
||||
boolean contentToChangeFound = false;
|
||||
@@ -729,7 +713,7 @@ public class SrcRepositoryUseTest extends PsiTestCase{
|
||||
contentEntry.removeSourceFolder(sourceFolder);
|
||||
}
|
||||
final VirtualFile contentRoot = contentEntry.getFile();
|
||||
if (contentRoot != null && VfsUtil.isAncestor(contentRoot, newSourceRoot, false)) {
|
||||
if (contentRoot != null && VfsUtilCore.isAncestor(contentRoot, newSourceRoot, false)) {
|
||||
contentEntry.addSourceFolder(newSourceRoot, false);
|
||||
contentToChangeFound = true;
|
||||
}
|
||||
@@ -739,8 +723,6 @@ public class SrcRepositoryUseTest extends PsiTestCase{
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
assertEquals("MyInterface1", aClass.getName());
|
||||
}
|
||||
|
||||
public void testParentIdAssert() throws Exception {
|
||||
|
||||
@@ -54,15 +54,7 @@ public class ManagingContentRootsTest extends IdeaTestCase {
|
||||
final String url = root.getUrl();
|
||||
root.delete(null);
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ModifiableRootModel m = getRootManager().getModifiableModel();
|
||||
m.addContentEntry(url);
|
||||
m.commit();
|
||||
}
|
||||
});
|
||||
|
||||
addContentRoot(url);
|
||||
|
||||
assertNotNull(findContentEntry(url));
|
||||
|
||||
@@ -70,10 +62,7 @@ public class ManagingContentRootsTest extends IdeaTestCase {
|
||||
assertSame(root, findContentEntry(url).getFile());
|
||||
}
|
||||
|
||||
public void testCreationOfContentRootWithUrlWhenFileExists() throws IOException {
|
||||
VirtualFile root = dir.createChildDirectory(null, "root");
|
||||
final String url = root.getUrl();
|
||||
|
||||
private void addContentRoot(final String url) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -82,6 +71,13 @@ public class ManagingContentRootsTest extends IdeaTestCase {
|
||||
m.commit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testCreationOfContentRootWithUrlWhenFileExists() throws IOException {
|
||||
VirtualFile root = dir.createChildDirectory(null, "root");
|
||||
final String url = root.getUrl();
|
||||
|
||||
addContentRoot(url);
|
||||
|
||||
|
||||
assertSame(root, findContentEntry(url).getFile());
|
||||
|
||||
@@ -31,10 +31,7 @@ import com.intellij.openapi.extensions.ExtensionPoint;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -153,23 +150,15 @@ public abstract class InspectionTestCase extends PsiTestCase {
|
||||
if (sourceDir[0] == null) {
|
||||
sourceDir[0] = projectDir;
|
||||
}
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
|
||||
final ModifiableRootModel rootModel = rootManager.getModifiableModel();
|
||||
rootModel.clear();
|
||||
// configure source and output path
|
||||
final ContentEntry contentEntry = rootModel.addContentEntry(projectDir);
|
||||
contentEntry.addSourceFolder(sourceDir[0], false);
|
||||
ext_src = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(testDir + "/ext_src"));
|
||||
if (ext_src != null) {
|
||||
contentEntry.addSourceFolder(ext_src, false);
|
||||
}
|
||||
|
||||
// IMPORTANT! The jdk must be obtained in a way it is obtained in the normal program!
|
||||
//ProjectJdkEx jdk = ProjectJdkTable.getInstance().getInternalJdk();
|
||||
|
||||
rootModel.setSdk(getTestProjectSdk());
|
||||
|
||||
rootModel.commit();
|
||||
PsiTestUtil.removeAllRoots(myModule, getTestProjectSdk());
|
||||
PsiTestUtil.addContentRoot(myModule, projectDir);
|
||||
PsiTestUtil.addSourceRoot(myModule, sourceDir[0]);
|
||||
ext_src = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(testDir + "/ext_src"));
|
||||
if (ext_src != null) {
|
||||
PsiTestUtil.addSourceRoot(myModule, ext_src);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -164,7 +164,12 @@ final class BuildSession implements Runnable, CanceledStatus {
|
||||
boolean forceCleanCaches = false;
|
||||
ProjectDescriptor pd;
|
||||
final Project project = loadProject(projectPath);
|
||||
|
||||
final File dataStorageRoot = Utils.getDataStorageRoot(project);
|
||||
if (!dataStorageRoot.exists()) {
|
||||
// invoked the very first time for this project. Force full rebuild
|
||||
buildType = BuildType.PROJECT_REBUILD;
|
||||
}
|
||||
|
||||
final boolean inMemoryMappingsDelta = System.getProperty(GlobalOptions.USE_MEMORY_TEMP_CACHE_OPTION) != null;
|
||||
ProjectTimestamps projectTimestamps = null;
|
||||
|
||||
@@ -161,7 +161,7 @@ public class IncProjectBuilder {
|
||||
}
|
||||
ExternalJavacDescriptor.KEY.set(context, null);
|
||||
}
|
||||
cleanupJavacNameTable();
|
||||
//cleanupJavacNameTable();
|
||||
}
|
||||
|
||||
private static boolean ourClenupFailed = false;
|
||||
|
||||
@@ -38,7 +38,8 @@ import org.jetbrains.jps.incremental.storage.BuildDataManager;
|
||||
import org.jetbrains.jps.incremental.storage.SourceToFormMapping;
|
||||
import org.jetbrains.jps.javac.*;
|
||||
|
||||
import javax.tools.*;
|
||||
import javax.tools.Diagnostic;
|
||||
import javax.tools.JavaFileObject;
|
||||
import java.io.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.ServerSocket;
|
||||
@@ -809,13 +810,17 @@ public class JavaBuilder extends ModuleLevelBuilder {
|
||||
final Map<File, Set<File>> map = new LinkedHashMap<File, Set<File>>();
|
||||
final boolean compilingTests = context.isCompilingTests();
|
||||
for (Module module : chunk.getModules()) {
|
||||
final String output = compilingTests ? module.getTestOutputPath() : module.getOutputPath();
|
||||
if (output == null) {
|
||||
continue;
|
||||
}
|
||||
final Set<File> roots = new LinkedHashSet<File>();
|
||||
for (RootDescriptor descriptor : context.getModuleRoots(module)) {
|
||||
if (descriptor.isTestRoot == compilingTests) {
|
||||
roots.add(descriptor.root);
|
||||
}
|
||||
}
|
||||
map.put(new File(compilingTests ? module.getTestOutputPath() : module.getOutputPath()), roots);
|
||||
map.put(new File(output), roots);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -71,6 +71,9 @@ public class ResourcesBuilder extends ModuleLevelBuilder {
|
||||
String sourceRoot,
|
||||
final SourceToOutputMapping outputToSourceMapping) throws IOException {
|
||||
final String outputRoot = context.isCompilingTests() ? module.getTestOutputPath() : module.getOutputPath();
|
||||
if (outputRoot == null) {
|
||||
return;
|
||||
}
|
||||
final String relativePath = FileUtil.getRelativePath(sourceRoot, FileUtil.toSystemIndependentName(file.getPath()), '/');
|
||||
final String prefix = module.getSourceRootPrefixes().get(sourceRoot);
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ import com.sun.tools.javac.util.*;
|
||||
import com.sun.tools.javac.util.List;
|
||||
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.tools.*;
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.JavaFileObject;
|
||||
import java.io.*;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -152,8 +153,12 @@ class OptimizedFileManager extends DefaultFileManager {
|
||||
private void collectFromDirectory(File directory, Set<JavaFileObject.Kind> fileKinds, boolean recurse, ListBuffer<JavaFileObject> result) {
|
||||
final File[] children = directory.listFiles();
|
||||
if (children != null) {
|
||||
final boolean acceptUnknownFiles = fileKinds.contains(JavaFileObject.Kind.OTHER);
|
||||
for (File child : children) {
|
||||
if (isValidFile(child.getName(), fileKinds) && isFile(child)) {
|
||||
if (isValidFile(child.getName(), fileKinds)) {
|
||||
if (acceptUnknownFiles && !isFile(child)) {
|
||||
continue;
|
||||
}
|
||||
final JavaFileObject fe = new InputFileObject(child);
|
||||
result.append(fe);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.sun.tools.javac.util.List;
|
||||
import com.sun.tools.javac.util.ListBuffer;
|
||||
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.tools.*;
|
||||
import javax.tools.JavaFileObject;
|
||||
import java.io.*;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.SoftReference;
|
||||
@@ -129,11 +129,14 @@ class OptimizedFileManager17 extends com.sun.tools.javac.file.JavacFileManager {
|
||||
if (sortFiles != null) {
|
||||
Arrays.sort(files, sortFiles);
|
||||
}
|
||||
|
||||
final boolean acceptUnknownFiles = fileKinds.contains(JavaFileObject.Kind.OTHER);
|
||||
for (File f: files) {
|
||||
String fileName = f.getName();
|
||||
if (isValidFile(fileName, fileKinds) && isFile(f)) {
|
||||
JavaFileObject fe = new InputFileObject(this, f);
|
||||
final String fileName = f.getName();
|
||||
if (isValidFile(fileName, fileKinds)) {
|
||||
if (acceptUnknownFiles && !isFile(f)) {
|
||||
continue;
|
||||
}
|
||||
final JavaFileObject fe = new InputFileObject(this, f);
|
||||
resultList.append(fe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ public abstract class IncrementalTestCase extends TestCase {
|
||||
|
||||
rebuildDump.close();
|
||||
|
||||
//assertEquals(rebuildDump.toString(), makeDump.toString());
|
||||
// assertEquals(rebuildDump.toString(), makeDump.toString());
|
||||
}
|
||||
}
|
||||
finally {
|
||||
|
||||
Binary file not shown.
@@ -357,7 +357,7 @@ public class ClassRepr extends Proto {
|
||||
return o1.type.getDescr(context).compareTo(o2.type.getDescr(context));
|
||||
}
|
||||
|
||||
return o1.name - o2.name;
|
||||
return context.getValue(o1.name).compareTo(context.getValue(o2.name));
|
||||
}
|
||||
});
|
||||
for (final FieldRepr f : fs) {
|
||||
@@ -401,7 +401,7 @@ public class ClassRepr extends Proto {
|
||||
return c;
|
||||
}
|
||||
|
||||
return o1.name - o2.name;
|
||||
return context.getValue(o1.name).compareTo(context.getValue(o2.name));
|
||||
}
|
||||
});
|
||||
for (final MethodRepr m : ms) {
|
||||
|
||||
@@ -27,7 +27,7 @@ class FieldRepr extends ProtoMember {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
|
||||
@@ -74,6 +74,10 @@ abstract class IntIntMultiMaplet implements Streamable {
|
||||
for (final int a : keys) {
|
||||
final TIntHashSet b = get(a);
|
||||
|
||||
if (b.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
stream.print(" Key: ");
|
||||
stream.println(context.getValue(a));
|
||||
stream.println(" Values:");
|
||||
|
||||
@@ -73,6 +73,11 @@ abstract class IntObjectMultiMaplet<V extends Streamable> implements Streamable
|
||||
|
||||
for (final int a : keys) {
|
||||
final Collection<V> b = get(a);
|
||||
|
||||
if (b.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
stream.print(" Key: ");
|
||||
stream.println(context.getValue(a));
|
||||
stream.println(" Values:");
|
||||
|
||||
@@ -1715,6 +1715,12 @@ public class Mappings {
|
||||
for (final ClassRepr c : state.classDiff.removed()) {
|
||||
myDelta.addDeletedClass(c);
|
||||
|
||||
final int fileName = myClassToSourceFile.get(c.name);
|
||||
|
||||
if (fileName != 0) {
|
||||
myDelta.myChangedFiles.add(fileName);
|
||||
}
|
||||
|
||||
if (!myEasyMode) {
|
||||
mySelf.appendDependents(c, state.dependants);
|
||||
debug("Adding usages of class ", c.name);
|
||||
@@ -1861,7 +1867,7 @@ public class Mappings {
|
||||
final Set<ClassRepr> pastClasses = (Set<ClassRepr>)mySourceFileToClasses.get(fileName);
|
||||
final DiffState state = new DiffState(Difference.make(pastClasses, classes));
|
||||
|
||||
if (!processChangedClasses(state)) {
|
||||
if (!processChangedClasses(state) && !myEasyMode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1995,10 +2001,25 @@ public class Mappings {
|
||||
cleanupRemovedClass(delta, repr, null, dependenciesTrashBin);
|
||||
}
|
||||
|
||||
delta.getRemovedSuperClasses().forEachEntry(new TIntObjectProcedure<TIntHashSet>() {
|
||||
@Override
|
||||
public boolean execute(final int a, final TIntHashSet b) {
|
||||
if (!compiledClasses.contains(a)) {
|
||||
final TIntHashSet old = myClassToSubclasses.get(a);
|
||||
|
||||
if (old != null) {
|
||||
old.removeAll(b.toArray());
|
||||
myClassToSubclasses.replace(a, old);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
delta.myClassToSubclasses.forEachEntry(new TIntObjectProcedure<TIntHashSet>() {
|
||||
@Override
|
||||
public boolean execute(final int className, final TIntHashSet s) {
|
||||
final TIntHashSet newSubClasses = s == null ? new TIntHashSet() : s;
|
||||
public boolean execute(final int className, final TIntHashSet newSubClasses) {
|
||||
final TIntHashSet oldSubClasses = myClassToSubclasses.get(className);
|
||||
|
||||
if (oldSubClasses != null) {
|
||||
@@ -2047,8 +2068,9 @@ public class Mappings {
|
||||
|
||||
delta.getChangedFiles().forEach(new TIntProcedure() {
|
||||
@Override
|
||||
public boolean execute(int fileName) {
|
||||
public boolean execute(final int fileName) {
|
||||
final Collection<ClassRepr> classes = delta.mySourceFileToClasses.get(fileName);
|
||||
|
||||
if (classes != null) {
|
||||
mySourceFileToClasses.replace(fileName, classes);
|
||||
}
|
||||
@@ -2057,6 +2079,7 @@ public class Mappings {
|
||||
}
|
||||
|
||||
final Collection<UsageRepr.Cluster> clusters = delta.mySourceFileToUsages.get(fileName);
|
||||
|
||||
if (clusters != null) {
|
||||
mySourceFileToUsages.replace(fileName, clusters);
|
||||
}
|
||||
@@ -2074,22 +2097,6 @@ public class Mappings {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
delta.getRemovedSuperClasses().forEachEntry(new TIntObjectProcedure<TIntHashSet>() {
|
||||
@Override
|
||||
public boolean execute(final int a, final TIntHashSet b) {
|
||||
if (!compiledClasses.contains(a)) {
|
||||
final TIntHashSet old = myClassToSubclasses.get(a);
|
||||
|
||||
if (old != null) {
|
||||
old.removeAll(b.toArray());
|
||||
myClassToSubclasses.replace(a, old);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
myClassToSubclasses.putAll(delta.myClassToSubclasses);
|
||||
@@ -2346,7 +2353,7 @@ public class Mappings {
|
||||
|
||||
@NotNull
|
||||
private Set<ClassRepr> getDeletedClasses() {
|
||||
return myDeletedClasses != null ? Collections.<ClassRepr>emptySet() : Collections.unmodifiableSet(myDeletedClasses);
|
||||
return myDeletedClasses == null ? Collections.<ClassRepr>emptySet() : Collections.unmodifiableSet(myDeletedClasses);
|
||||
}
|
||||
|
||||
private TIntHashSet getChangedClasses() {
|
||||
|
||||
@@ -104,7 +104,9 @@ public class ProjectPaths {
|
||||
|
||||
private static void addFiles(Set<File> files, final Collection<String> paths) {
|
||||
for (String root : paths) {
|
||||
files.add(new File(root));
|
||||
if (root != null) {
|
||||
files.add(new File(root));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -35,6 +35,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
public abstract class PsiElementBaseIntentionAction extends BaseIntentionAction {
|
||||
@Override
|
||||
public final void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
if (!file.getManager().isInProject(file)) return;
|
||||
final PsiElement element = getElement(editor, file);
|
||||
if (element != null) {
|
||||
invoke(project, editor, element);
|
||||
@@ -54,6 +55,7 @@ public abstract class PsiElementBaseIntentionAction extends BaseIntentionAction
|
||||
|
||||
@Override
|
||||
public final boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
if (!file.getManager().isInProject(file)) return false;
|
||||
final PsiElement element = getElement(editor, file);
|
||||
return element != null && isAvailable(project, editor, element);
|
||||
}
|
||||
@@ -71,7 +73,6 @@ public abstract class PsiElementBaseIntentionAction extends BaseIntentionAction
|
||||
|
||||
@Nullable
|
||||
protected static PsiElement getElement(Editor editor, @NotNull PsiFile file) {
|
||||
if (!file.getManager().isInProject(file)) return null;
|
||||
CaretModel caretModel = editor.getCaretModel();
|
||||
int position = caretModel.getOffset();
|
||||
return file.findElementAt(position);
|
||||
|
||||
+2
-1
@@ -21,6 +21,7 @@ import com.intellij.codeInsight.lookup.*;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||
import com.intellij.codeInsight.template.impl.LiveTemplateLookupElement;
|
||||
import com.intellij.featureStatistics.FeatureUsageTracker;
|
||||
import com.intellij.featureStatistics.FeatureUsageTrackerImpl;
|
||||
import com.intellij.ide.ui.UISettings;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -380,7 +381,7 @@ public class CompletionLookupArranger extends LookupArranger {
|
||||
if (myMain != null) {
|
||||
StatisticsManager.getInstance().incUseCount(myMain);
|
||||
}
|
||||
FeatureUsageTracker.getInstance().registerCharactersSparedByCompletion(mySpared);
|
||||
((FeatureUsageTrackerImpl)FeatureUsageTracker.getInstance()).getCompletionStatistics().registerInvocation(mySpared);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-5
@@ -59,7 +59,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.problems.Problem;
|
||||
import com.intellij.problems.WolfTheProblemSolver;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageFacadeImpl;
|
||||
import com.intellij.psi.impl.source.tree.injected.Place;
|
||||
import com.intellij.psi.search.PsiTodoSearchHelper;
|
||||
import com.intellij.psi.search.TodoItem;
|
||||
@@ -291,7 +291,7 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP
|
||||
@NotNull final List<PsiElement> elements2,
|
||||
@NotNull final ProgressIndicator progress,
|
||||
@NotNull final Set<PsiFile> outInjected) {
|
||||
List<DocumentWindow> injected = InjectedLanguageUtil.getCachedInjectedDocuments(myFile);
|
||||
List<DocumentWindow> injected = InjectedLanguageFacadeImpl.getCachedInjectedDocuments(myFile);
|
||||
Collection<PsiElement> hosts = new THashSet<PsiElement>(elements1.size() + elements2.size() + injected.size());
|
||||
|
||||
//rehighlight all injected PSI regardless the range,
|
||||
@@ -325,7 +325,7 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP
|
||||
@Override
|
||||
public boolean process(PsiElement element) {
|
||||
progress.checkCanceled();
|
||||
InjectedLanguageUtil.enumerate(element, myFile, false, visitor);
|
||||
InjectedLanguageFacadeImpl.enumerate(element, myFile, false, visitor);
|
||||
return true;
|
||||
}
|
||||
})) {
|
||||
@@ -347,7 +347,7 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP
|
||||
public boolean process(final PsiFile injectedPsi) {
|
||||
DocumentWindow documentWindow = (DocumentWindow)PsiDocumentManager.getInstance(myProject).getCachedDocument(injectedPsi);
|
||||
if (documentWindow == null) return true;
|
||||
Place places = InjectedLanguageUtil.getShreds(injectedPsi);
|
||||
Place places = InjectedLanguageFacadeImpl.getShreds(injectedPsi);
|
||||
for (PsiLanguageInjectionHost.Shred place : places) {
|
||||
TextRange textRange = place.getRangeInsideHost().shiftRight(place.getHost().getTextRange().getStartOffset());
|
||||
if (textRange.isEmpty()) continue;
|
||||
@@ -503,7 +503,7 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP
|
||||
}
|
||||
|
||||
private void highlightInjectedSyntax(final PsiFile injectedPsi, HighlightInfoHolder holder) {
|
||||
List<Trinity<IElementType, SmartPsiElementPointer<PsiLanguageInjectionHost>, TextRange>> tokens = InjectedLanguageUtil
|
||||
List<Trinity<IElementType, SmartPsiElementPointer<PsiLanguageInjectionHost>, TextRange>> tokens = InjectedLanguageFacadeImpl
|
||||
.getHighlightTokens(injectedPsi);
|
||||
if (tokens == null) return;
|
||||
|
||||
|
||||
@@ -229,7 +229,11 @@ public class GridCellImpl implements GridCell {
|
||||
@Nullable
|
||||
private static TabInfo updatePresentation(TabInfo info, Content content) {
|
||||
if (info == null) return info;
|
||||
return info.setIcon(content.getIcon()).setText(content.getDisplayName()).setActions(content.getActions(), content.getPlace());
|
||||
return info.
|
||||
setIcon(content.getIcon()).
|
||||
setText(content.getDisplayName()).
|
||||
setActionsContextComponent(content.getActionsContextComponent()).
|
||||
setActions(content.getActions(), content.getPlace());
|
||||
}
|
||||
|
||||
public ActionCallback select(final Content content, final boolean requestFocus) {
|
||||
|
||||
@@ -18,9 +18,6 @@ package com.intellij.featureStatistics;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
@@ -42,11 +39,4 @@ public abstract class FeatureUsageTracker {
|
||||
|
||||
public abstract boolean isToBeAdvertisedInLookup(@NonNls String featureId, Project project);
|
||||
|
||||
public abstract void registerCharactersSparedByCompletion(int spared);
|
||||
|
||||
public abstract int getCharactersSparedByCompletion();
|
||||
|
||||
@Nullable
|
||||
public abstract Date getCompletionStatisticsStartDate();
|
||||
|
||||
}
|
||||
|
||||
@@ -675,6 +675,9 @@ public class ThreeComponentsSplitter extends JPanel implements Disposable {
|
||||
|
||||
protected void processMouseEvent(MouseEvent e) {
|
||||
super.processMouseEvent(e);
|
||||
if (!isShowing()) {
|
||||
return;
|
||||
}
|
||||
switch (e.getID()) {
|
||||
case MouseEvent.MOUSE_ENTERED:
|
||||
setCursor(getResizeCursor());
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.featureStatistics;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class CompletionStatistics {
|
||||
public int sparedCharacters = 0;
|
||||
public int invocations = 0;
|
||||
public long startDate = 0;
|
||||
public int dayCount = 0;
|
||||
public long lastDate = 0;
|
||||
|
||||
public void registerInvocation(int spared) {
|
||||
invocations++;
|
||||
if (spared > 0) {
|
||||
sparedCharacters += spared;
|
||||
}
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||
cal.set(Calendar.MINUTE, 0);
|
||||
cal.set(Calendar.SECOND, 0);
|
||||
cal.set(Calendar.MILLISECOND, 0);
|
||||
long today = cal.getTimeInMillis();
|
||||
|
||||
if (startDate == 0) {
|
||||
startDate = today;
|
||||
}
|
||||
if (lastDate == 0) {
|
||||
lastDate = today;
|
||||
dayCount = 1;
|
||||
} else if (today != lastDate) {
|
||||
lastDate = today;
|
||||
dayCount++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+15
-35
@@ -20,10 +20,11 @@ import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.components.StoragePathMacros;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.xmlb.XmlSerializer;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -35,9 +36,8 @@ import java.util.Set;
|
||||
public class FeatureUsageTrackerImpl extends FeatureUsageTracker implements PersistentStateComponent<Element> {
|
||||
private static final int HOUR = 1000 * 60 * 60;
|
||||
private static final long DAY = HOUR * 24;
|
||||
private int SPARED_BY_COMPLETION = 0;
|
||||
private long COMPLETION_STATS_START = 0;
|
||||
private long FIRST_RUN_TIME = 0;
|
||||
private CompletionStatistics myCompletionStats = new CompletionStatistics();
|
||||
boolean HAVE_BEEN_SHOWN = false;
|
||||
|
||||
private final ProductivityFeaturesRegistry myRegistry;
|
||||
@@ -47,8 +47,7 @@ public class FeatureUsageTrackerImpl extends FeatureUsageTracker implements Pers
|
||||
@NonNls private static final String ATT_SHOW_IN_COMPILATION = "show-in-compilation";
|
||||
@NonNls private static final String ATT_ID = "id";
|
||||
@NonNls private static final String ATT_FIRST_RUN = "first-run";
|
||||
@NonNls private static final String ATT_COMPLETION_STATS_START = "completion-stats-start";
|
||||
@NonNls private static final String ATT_SPARED_BY_COMPLETION = "spared-by-completion";
|
||||
@NonNls private static final String COMPLETION_STATS_TAG = "completionStatsTag";
|
||||
@NonNls private static final String ATT_HAVE_BEEN_SHOWN = "have-been-shown";
|
||||
|
||||
public FeatureUsageTrackerImpl(ProductivityFeaturesRegistry productivityFeaturesRegistry) {
|
||||
@@ -97,22 +96,9 @@ public class FeatureUsageTrackerImpl extends FeatureUsageTracker implements Pers
|
||||
return isToBeShown(featureId, project, HOUR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCharactersSparedByCompletion(int spared) {
|
||||
SPARED_BY_COMPLETION += spared;
|
||||
if (COMPLETION_STATS_START == 0) {
|
||||
COMPLETION_STATS_START = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCharactersSparedByCompletion() {
|
||||
return SPARED_BY_COMPLETION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getCompletionStatisticsStartDate() {
|
||||
return COMPLETION_STATS_START == 0 ? null : new Date(COMPLETION_STATS_START);
|
||||
@NotNull
|
||||
public CompletionStatistics getCompletionStatistics() {
|
||||
return myCompletionStats;
|
||||
}
|
||||
|
||||
public long getFirstRunTime() {
|
||||
@@ -139,17 +125,10 @@ public class FeatureUsageTrackerImpl extends FeatureUsageTracker implements Pers
|
||||
catch (NumberFormatException e) {
|
||||
FIRST_RUN_TIME = 0;
|
||||
}
|
||||
try {
|
||||
COMPLETION_STATS_START = Long.parseLong(element.getAttributeValue(ATT_COMPLETION_STATS_START));
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
COMPLETION_STATS_START = 0;
|
||||
}
|
||||
try {
|
||||
SPARED_BY_COMPLETION = Integer.parseInt(element.getAttributeValue(ATT_SPARED_BY_COMPLETION));
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
SPARED_BY_COMPLETION = 0;
|
||||
|
||||
Element stats = element.getChild(COMPLETION_STATS_TAG);
|
||||
if (stats != null) {
|
||||
myCompletionStats = XmlSerializer.deserialize(stats, CompletionStatistics.class);
|
||||
}
|
||||
|
||||
HAVE_BEEN_SHOWN = Boolean.valueOf(element.getAttributeValue(ATT_HAVE_BEEN_SHOWN)).booleanValue();
|
||||
@@ -169,10 +148,11 @@ public class FeatureUsageTrackerImpl extends FeatureUsageTracker implements Pers
|
||||
element.addContent(featureElement);
|
||||
}
|
||||
|
||||
Element statsTag = new Element(COMPLETION_STATS_TAG);
|
||||
XmlSerializer.serializeInto(myCompletionStats, statsTag);
|
||||
element.addContent(statsTag);
|
||||
|
||||
element.setAttribute(ATT_FIRST_RUN, String.valueOf(getFirstRunTime()));
|
||||
element.setAttribute(ATT_COMPLETION_STATS_START, String.valueOf(COMPLETION_STATS_START));
|
||||
element.setAttribute(ATT_SPARED_BY_COMPLETION, String.valueOf(SPARED_BY_COMPLETION));
|
||||
element.setAttribute(ATT_SPARED_BY_COMPLETION, String.valueOf(SPARED_BY_COMPLETION));
|
||||
element.setAttribute(ATT_HAVE_BEEN_SHOWN, String.valueOf(HAVE_BEEN_SHOWN));
|
||||
element.setAttribute(ATT_SHOW_IN_OTHER, String.valueOf(SHOW_IN_OTHER_PROGRESS));
|
||||
element.setAttribute(ATT_SHOW_IN_COMPILATION, String.valueOf(SHOW_IN_COMPILATION_PROGRESS));
|
||||
|
||||
+23
-26
@@ -21,6 +21,7 @@ import com.intellij.ide.util.TipUIUtil;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ApplicationNamesInfo;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.help.HelpManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
@@ -45,17 +46,10 @@ import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
|
||||
public class ShowFeatureUsageStatisticsDialog extends DialogWrapper {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.featureStatistics.actions.ShowFeatureUsageStatisticsDialog");
|
||||
private static final Comparator<FeatureDescriptor> DISPLAY_NAME_COMPARATOR = new Comparator<FeatureDescriptor>() {
|
||||
public int compare(FeatureDescriptor fd1, FeatureDescriptor fd2) {
|
||||
final String displayName1 = fd1.getDisplayName();
|
||||
final String displayName2 = fd2.getDisplayName();
|
||||
if (displayName1 != null && displayName2 != null) {
|
||||
return displayName1.compareTo(displayName2);
|
||||
}
|
||||
if (displayName2 != null){
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
return fd1.getDisplayName().compareTo(fd2.getDisplayName());
|
||||
}
|
||||
};
|
||||
private static final Comparator<FeatureDescriptor> GROUP_NAME_COMPARATOR = new Comparator<FeatureDescriptor>() {
|
||||
@@ -145,14 +139,14 @@ public class ShowFeatureUsageStatisticsDialog extends DialogWrapper {
|
||||
for (String id : registry.getFeatureIds()) {
|
||||
features.add(registry.getFeatureDescriptor(id));
|
||||
}
|
||||
final TableView table = new TableView(new ListTableModel(COLUMNS, features, 0));
|
||||
final TableView table = new TableView<FeatureDescriptor>(new ListTableModel<FeatureDescriptor>(COLUMNS, features, 0));
|
||||
|
||||
JPanel controlsPanel = new JPanel(new VerticalFlowLayout());
|
||||
|
||||
|
||||
Application app = ApplicationManager.getApplication();
|
||||
long uptime = System.currentTimeMillis() - app.getStartTime();
|
||||
long idletime = app.getIdleTime();
|
||||
long idleTime = app.getIdleTime();
|
||||
|
||||
final String uptimeS = FeatureStatisticsBundle.message("feature.statistics.application.uptime",
|
||||
ApplicationNamesInfo.getInstance().getProductName(),
|
||||
@@ -160,23 +154,15 @@ public class ShowFeatureUsageStatisticsDialog extends DialogWrapper {
|
||||
|
||||
final String idleTimeS = FeatureStatisticsBundle .message("feature.statistics.application.idle.time",
|
||||
ApplicationNamesInfo.getInstance().getProductName(),
|
||||
DateFormatUtil.formatDuration(idletime));
|
||||
DateFormatUtil.formatDuration(idleTime));
|
||||
|
||||
String labelText = uptimeS + ", " + idleTimeS;
|
||||
Date completionDate = FeatureUsageTracker.getInstance().getCompletionStatisticsStartDate();
|
||||
if (completionDate != null) {
|
||||
int spared = FeatureUsageTracker.getInstance().getCharactersSparedByCompletion();
|
||||
String total = spared > 1024 * 1024 ? (spared / 1024 / 1024) + "MB code" :
|
||||
spared > 1024 ? (spared / 1024) + "KB code" :
|
||||
spared + " characters";
|
||||
|
||||
long perDayCount = spared / Math.max(1, DateFormatUtil.getDifferenceInDays(completionDate, new Date()) + 1);
|
||||
String perDay = perDayCount > 1024 * 1024 ? (perDayCount / 1024 / 1024) + "MB" :
|
||||
perDayCount > 1024 ? (perDayCount / 1024) + "KB" :
|
||||
perDayCount + " characters";
|
||||
|
||||
labelText += "<br>Code completion has saved you from typing at least " + total + " since " + DateFormatUtil.formatDate(completionDate) +
|
||||
" (\u2245 " + perDay + " per day)";
|
||||
CompletionStatistics stats = ((FeatureUsageTrackerImpl)FeatureUsageTracker.getInstance()).getCompletionStatistics();
|
||||
if (stats.dayCount > 0 && stats.sparedCharacters > 0) {
|
||||
String total = formatCharacterCount(stats.sparedCharacters, true);
|
||||
String perDay = formatCharacterCount(stats.sparedCharacters / stats.dayCount, false);
|
||||
labelText += "<br>Code completion has saved you from typing at least " + total + " since " + DateFormatUtil.formatDate(stats.startDate) +
|
||||
" (\u2245" + perDay + " per working day)";
|
||||
}
|
||||
controlsPanel.add(new JLabel("<html><body>" + labelText + "</body></html>"), BorderLayout.NORTH);
|
||||
|
||||
@@ -204,6 +190,7 @@ public class ShowFeatureUsageStatisticsDialog extends DialogWrapper {
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
LOG.info(ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -211,6 +198,16 @@ public class ShowFeatureUsageStatisticsDialog extends DialogWrapper {
|
||||
return splitter;
|
||||
}
|
||||
|
||||
private static String formatCharacterCount(int count, boolean full) {
|
||||
String result = count > 1024 * 1024 ? (count / 1024 / 1024) + "MB " :
|
||||
count > 1024 ? (count / 1024) + "KB " :
|
||||
count + " characters";
|
||||
if (full && count > 1024) {
|
||||
return result + " code";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String getGroupName(FeatureDescriptor featureDescriptor) {
|
||||
final ProductivityFeaturesRegistry registry = ProductivityFeaturesRegistry.getInstance();
|
||||
final GroupDescriptor groupDescriptor = registry.getGroupDescriptor(featureDescriptor.getGroupId());
|
||||
|
||||
+1
-1
@@ -474,7 +474,7 @@ public class ApplicationInfoImpl extends ApplicationInfoEx implements JDOMExtern
|
||||
}
|
||||
|
||||
myPluginsListUrl = DEFAULT_PLUGINS_HOST + "/plugins/list/";
|
||||
myPluginsDownloadUrl = DEFAULT_PLUGINS_HOST + "/pluginManager";
|
||||
myPluginsDownloadUrl = DEFAULT_PLUGINS_HOST + "/pluginManager/";
|
||||
|
||||
Element pluginsElement = parentNode.getChild(ELEMENT_PLUGINS);
|
||||
if (pluginsElement != null) {
|
||||
|
||||
+28
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,12 +24,15 @@
|
||||
*/
|
||||
package com.intellij.openapi.editor.actions;
|
||||
|
||||
import com.intellij.openapi.editor.CaretModel;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.SelectionModel;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorAction;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
|
||||
public class DeleteToWordStartAction extends TextComponentEditorAction {
|
||||
public DeleteToWordStartAction() {
|
||||
@@ -45,10 +48,31 @@ public class DeleteToWordStartAction extends TextComponentEditorAction {
|
||||
}
|
||||
|
||||
private static void deleteToWordStart(Editor editor) {
|
||||
int endOffset = editor.getCaretModel().getOffset();
|
||||
EditorActionUtil.moveCaretToPreviousWord(editor, false);
|
||||
int startOffset = editor.getCaretModel().getOffset();
|
||||
final CaretModel caretModel = editor.getCaretModel();
|
||||
int endOffset = caretModel.getOffset();
|
||||
|
||||
// The logic is as follows:
|
||||
// 1. Check are there white-space symbols starting at the current caret position going backwards. Delete them if any;
|
||||
// 2. Otherwise locate previous word start and delete the text up to it;
|
||||
// Example:
|
||||
// 'test string <caret>' -> 'test string<caret>'
|
||||
// 'test string<caret>' -> 'test <caret>'
|
||||
|
||||
Document document = editor.getDocument();
|
||||
final SelectionModel selectionModel = editor.getSelectionModel();
|
||||
int startOffset = -1;
|
||||
if (!selectionModel.hasSelection() && !selectionModel.hasBlockSelection()) {
|
||||
int i = CharArrayUtil.shiftBackward(document.getCharsSequence(), Math.max(0, endOffset - 1), " \t\n");
|
||||
if (i >= 0 && i < endOffset - 1) {
|
||||
startOffset = i + 1; // We need offset of the first white space symbol, not offset of the last non-white space symbol before it.
|
||||
}
|
||||
}
|
||||
|
||||
if (startOffset < 0) {
|
||||
EditorActionUtil.moveCaretToPreviousWord(editor, false);
|
||||
startOffset = caretModel.getOffset();
|
||||
}
|
||||
|
||||
document.deleteString(startOffset, endOffset);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 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.
|
||||
@@ -32,6 +32,7 @@ public abstract class EditorGutterComponentEx extends JComponent implements Edit
|
||||
|
||||
public abstract boolean isAnnotationsShown();
|
||||
|
||||
@Nullable
|
||||
public abstract FoldRegion findFoldingAnchorAt(int x, int y);
|
||||
|
||||
public abstract int getWhitespaceSeparatorOffset();
|
||||
|
||||
+13
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 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.
|
||||
@@ -92,6 +92,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
|
||||
private int myLastPreferredHeight = -1;
|
||||
private Convertor<Integer, Integer> myLineNumberConvertor;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public EditorGutterComponentImpl(EditorImpl editor) {
|
||||
myEditor = editor;
|
||||
myLineNumberConvertor = Convertor.SELF;
|
||||
@@ -742,7 +743,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
|
||||
}
|
||||
|
||||
private void doForVisibleFoldRegions(@NotNull NullableFunction<FoldRegion, Void> action, int firstVisibleOffset, int lastVisibleOffset) {
|
||||
FoldRegion[] visibleFoldRegions = ((FoldingModelImpl)myEditor.getFoldingModel()).fetchVisible();
|
||||
FoldRegion[] visibleFoldRegions = myEditor.getFoldingModel().fetchVisible();
|
||||
final Document document = myEditor.getDocument();
|
||||
for (FoldRegion visibleFoldRegion : visibleFoldRegions) {
|
||||
if (!visibleFoldRegion.isValid()) continue;
|
||||
@@ -833,7 +834,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
|
||||
|
||||
final FoldingGroup group = foldRange.getGroup();
|
||||
|
||||
final boolean drawTop = group == null || ((FoldingModelImpl)myEditor.getFoldingModel()).getFirstRegion(group, foldRange) == foldRange;
|
||||
final boolean drawTop = group == null || myEditor.getFoldingModel().getFirstRegion(group, foldRange) == foldRange;
|
||||
if (!foldRange.isExpanded()) {
|
||||
if (y <= clip.y + clip.height && y + height >= clip.y) {
|
||||
if (drawTop) {
|
||||
@@ -861,7 +862,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
|
||||
private int getEndOffset(FoldRegion foldRange) {
|
||||
LOG.assertTrue(foldRange.isValid(), foldRange);
|
||||
FoldingGroup group = foldRange.getGroup();
|
||||
return group == null ? foldRange.getEndOffset() : ((FoldingModelImpl)myEditor.getFoldingModel()).getEndOffset(group);
|
||||
return group == null ? foldRange.getEndOffset() : myEditor.getFoldingModel().getEndOffset(group);
|
||||
}
|
||||
|
||||
private void drawDirectedBox(Graphics2D g,
|
||||
@@ -910,6 +911,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
|
||||
UIUtil.drawLine(g, anchorX + width / 2, y + 2, anchorX + width / 2, y + width - 2);
|
||||
}
|
||||
|
||||
@SuppressWarnings("SuspiciousNameCombination")
|
||||
private void drawSquareWithMinus(Graphics2D g,
|
||||
int anchorX,
|
||||
int y,
|
||||
@@ -998,7 +1000,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
|
||||
}
|
||||
}
|
||||
|
||||
public int getLineNumberAreaOffset() {
|
||||
public static int getLineNumberAreaOffset() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1024,6 +1026,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
|
||||
return myEditor.getVerticalScrollbarOrientation() != EditorEx.VERTICAL_SCROLLBAR_RIGHT;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public FoldRegion findFoldingAnchorAt(int x, int y) {
|
||||
if (!myEditor.getSettings().isFoldingOutlineShown()) return null;
|
||||
@@ -1031,11 +1034,11 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
|
||||
int anchorX = getFoldingAreaOffset();
|
||||
int anchorWidth = getFoldingAnchorWidth();
|
||||
|
||||
FoldRegion[] visibleRanges = ((FoldingModelImpl)myEditor.getFoldingModel()).fetchVisible();
|
||||
FoldRegion[] visibleRanges = myEditor.getFoldingModel().fetchVisible();
|
||||
for (FoldRegion foldRange : visibleRanges) {
|
||||
if (!foldRange.isValid()) continue;
|
||||
final FoldingGroup group = foldRange.getGroup();
|
||||
if (group != null && ((FoldingModelImpl)myEditor.getFoldingModel()).getFirstRegion(group, foldRange) != foldRange) {
|
||||
if (group != null && myEditor.getFoldingModel().getFirstRegion(group, foldRange) != foldRange) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1080,6 +1083,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
|
||||
&& !myEditor.getSoftWrapModel().getSoftWrapsForRange(startOffset, endOffsetToUse).isEmpty();
|
||||
}
|
||||
|
||||
@SuppressWarnings("SuspiciousNameCombination")
|
||||
private Rectangle rectangleByFoldOffset(int foldStart, int anchorWidth, int anchorX) {
|
||||
int anchorY = myEditor.visibleLineToY(foldStart) + myEditor.getLineHeight() -
|
||||
myEditor.getDescent() - anchorWidth;
|
||||
@@ -1139,7 +1143,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
|
||||
@Override
|
||||
public void process(int x, int y, GutterIconRenderer r) {
|
||||
xPos.put(x, r);
|
||||
if (renderer == r) {
|
||||
if (renderer == r && r != null) {
|
||||
currentPos[0] = x;
|
||||
Icon icon = r.getIcon();
|
||||
t.set(new Point(x + icon.getIconWidth() / 2, y + icon.getIconHeight() / 2));
|
||||
@@ -1254,6 +1258,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ActiveGutterRenderer getActiveRendererByMouseEvent(final MouseEvent e) {
|
||||
if (findFoldingAnchorAt(e.getX(), e.getY()) != null) {
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 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.util.*;
|
||||
*/
|
||||
abstract class FoldRegionsTree {
|
||||
|
||||
@SuppressWarnings("UseOfArchaicSystemPropertyAccessors")
|
||||
public static final boolean DEBUG = Boolean.getBoolean("idea.editor.debug.folding");
|
||||
|
||||
private FoldRegion[] myCachedVisible;
|
||||
@@ -163,8 +164,9 @@ abstract class FoldRegionsTree {
|
||||
boolean addRegion(FoldRegion range) {
|
||||
// During batchProcessing elements are inserted in ascending order,
|
||||
// binary search find acceptable insertion place first time
|
||||
int fastIndex = myCachedLastIndex != -1 && isBatchFoldingProcessing()
|
||||
? myCachedLastIndex + 1 : Collections.binarySearch(myRegions, range, RangeMarker.BY_START_OFFSET);
|
||||
final boolean canUseCachedValue =
|
||||
myCachedLastIndex != -1 && isBatchFoldingProcessing() && myRegions.get(myCachedLastIndex).getStartOffset() <= range.getStartOffset();
|
||||
int fastIndex = canUseCachedValue ? myCachedLastIndex + 1 : Collections.binarySearch(myRegions, range, RangeMarker.BY_START_OFFSET);
|
||||
if (fastIndex < 0) fastIndex = -fastIndex - 1;
|
||||
|
||||
// There is a possible case that given range is the first at the current batch iteration. It's also possible that it
|
||||
|
||||
+3
-1
@@ -513,7 +513,9 @@ public class PersistentFS extends ManagingFS implements ApplicationComponent {
|
||||
// we should cache every local files content
|
||||
// because the local history feature is currently depends on this cache,
|
||||
// perforce offline mode as well
|
||||
if ((!delegate.isReadOnly() || !application.isInternal() && !application.isUnitTestMode()) &&
|
||||
if ((!delegate.isReadOnly() ||
|
||||
// do not cache archive content unless asked
|
||||
(cacheContent && !application.isInternal() && !application.isUnitTestMode())) &&
|
||||
content.length <= PersistentFSConstants.FILE_LENGTH_TO_CACHE_THRESHOLD) {
|
||||
synchronized (INPUT_LOCK) {
|
||||
writeContent(canonicalFile, new ByteSequence(content), delegate.isReadOnly());
|
||||
|
||||
@@ -190,7 +190,7 @@ public abstract class ValidatingTableEditor<Item> implements ComponentWithEmptyT
|
||||
myFixLink = new HoverHyperlinkLabel(null);
|
||||
}
|
||||
|
||||
protected ValidatingTableEditor(AnActionButton extraButton) {
|
||||
protected ValidatingTableEditor(@Nullable AnActionButton ... extraButtons) {
|
||||
ToolbarDecorator decorator =
|
||||
ToolbarDecorator.createDecorator(myTable).disableRemoveAction().disableUpAction().disableDownAction();
|
||||
decorator.setAddAction(new AnActionButtonRunnable() {
|
||||
@@ -211,8 +211,10 @@ public abstract class ValidatingTableEditor<Item> implements ComponentWithEmptyT
|
||||
myRemoveButton.setShortcut(CustomShortcutSet.fromString("alt DELETE")); //NON-NLS
|
||||
decorator.addExtraAction(myRemoveButton);
|
||||
|
||||
if (extraButton != null) {
|
||||
decorator.addExtraAction(extraButton);
|
||||
if (extraButtons != null && extraButtons.length != 0) {
|
||||
for (AnActionButton extraButton : extraButtons) {
|
||||
decorator.addExtraAction(extraButton);
|
||||
}
|
||||
}
|
||||
|
||||
myTablePanel.add(decorator.createPanel(), BorderLayout.CENTER);
|
||||
@@ -240,6 +242,7 @@ public abstract class ValidatingTableEditor<Item> implements ComponentWithEmptyT
|
||||
}
|
||||
|
||||
protected ValidatingTableEditor() {
|
||||
//noinspection NullArgumentToVariableArgMethod
|
||||
this(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -207,6 +207,8 @@ intention.remove.literal.underscores=Remove underscores from literal
|
||||
intention.insert.literal.underscores=Insert underscores into literal
|
||||
intention.replace.cast.with.var.text=Replace ''{0}'' with ''{1}''
|
||||
intention.replace.cast.with.var.family=Replace cast with variable
|
||||
intention.convert.color.representation.text=Convert to ''new Color{0}''
|
||||
intention.convert.color.representation.family=Convert Color representation
|
||||
|
||||
|
||||
intention.create.test=Create Test
|
||||
|
||||
@@ -76,7 +76,7 @@ find.filter.invalid.file.mask.error=Bad file mask \"{0}\"
|
||||
find.filter.empty.file.mask.error=Empty file mask
|
||||
find.options.case.sensitive=&Case sensitive
|
||||
find.options.replace.preserve.case=Preser&ve case
|
||||
find.options.whole.words.only=W&hole words only
|
||||
find.options.whole.words.only=W&hole words only (may be faster)
|
||||
find.options.string.literals.only=S&tring literals only
|
||||
find.options.comments.only=Comm&ents only
|
||||
find.options.regular.expressions=Re&gular expression
|
||||
|
||||
@@ -49,6 +49,7 @@ inspection.data.flow.nullable.quickfix.option=<html><body>Suggest @Nullable anno
|
||||
inspection.data.flow.true.asserts.option=<html><body>Don't report assert statements with condition statically proven to be always <code>true</code></body></html>
|
||||
inspection.data.flow.redundant.instanceof.quickfix=Replace with != null
|
||||
inspection.data.flow.simplify.boolean.expression.quickfix=Simplify Boolean Expression
|
||||
inspection.data.flow.simplify.to.assignment.quickfix.name=Simplify to normal assignment
|
||||
configure.annotations.option=Configure annotations
|
||||
|
||||
#messages from dataflow inspection
|
||||
|
||||
@@ -141,6 +141,7 @@ refactoring.introduceVariable=Extract Variable refactoring
|
||||
refactoring.introduce.selection.error=Cannot perform refactoring using selected element(s)
|
||||
refactoring.introduce.name.error=Incorrect name
|
||||
refactoring.introduce.name.used.error=This name is already used
|
||||
refactoring.introduce.placing.error=Cannot extract {0} variable
|
||||
|
||||
variable.of.type=Variable of &type:
|
||||
convert.to.instance.method.title=Convert To Instance Method
|
||||
|
||||
@@ -133,11 +133,8 @@ compiler.max.static.constants.searches.description=If the number of changed comp
|
||||
|
||||
# out-of-process build parameters
|
||||
|
||||
compiler.out-of-process.build.enabled=false
|
||||
compiler.out-of-process.build.enabled.description=Enable out-of-process compilation
|
||||
|
||||
compiler.out-of-process.as-server=false
|
||||
compiler.out-of-process.as-server.description=Use implementation of out-of-process build as server process
|
||||
#compiler.out-of-process.as-server=false
|
||||
#compiler.out-of-process.as-server.description=Use implementation of out-of-process build as server process
|
||||
|
||||
compiler.process.heap.size=700
|
||||
compiler.process.heap.size.description=Heap size value in MB for the build process
|
||||
|
||||
+5
-42
@@ -160,12 +160,12 @@ public abstract class IntegrationTestCase extends PlatformTestCase {
|
||||
addContentRoot(myModule, path);
|
||||
}
|
||||
|
||||
protected void addContentRoot(final Module module, final String path) {
|
||||
protected static void addContentRoot(final Module module, final String path) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
ModuleRootManager rm = ModuleRootManager.getInstance(module);
|
||||
ModifiableRootModel m = rm.getModifiableModel();
|
||||
m.addContentEntry(VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(path)));
|
||||
m.addContentEntry(VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(path)));
|
||||
m.commit();
|
||||
}
|
||||
});
|
||||
@@ -178,14 +178,14 @@ public abstract class IntegrationTestCase extends PlatformTestCase {
|
||||
ModifiableRootModel m = rm.getModifiableModel();
|
||||
for (ContentEntry e : m.getContentEntries()) {
|
||||
if (e.getFile() != myRoot) continue;
|
||||
e.addExcludeFolder(VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(path)));
|
||||
e.addExcludeFolder(VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(path)));
|
||||
}
|
||||
m.commit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void addFileListenerDuring(VirtualFileListener l, Runnable r) throws Exception {
|
||||
protected static void addFileListenerDuring(VirtualFileListener l, Runnable r) throws Exception {
|
||||
VirtualFileManager.getInstance().addVirtualFileListener(l);
|
||||
try {
|
||||
r.run();
|
||||
@@ -196,44 +196,7 @@ public abstract class IntegrationTestCase extends PlatformTestCase {
|
||||
}
|
||||
|
||||
|
||||
protected void assertContent(String expected, Entry e) {
|
||||
protected static void assertContent(String expected, Entry e) {
|
||||
assertEquals(expected, new String(e.getContent().getBytes()));
|
||||
}
|
||||
|
||||
protected class ContentChangesListener extends VirtualFileAdapter {
|
||||
private final VirtualFile myFile;
|
||||
private final String[] myContents = new String[2];
|
||||
|
||||
public ContentChangesListener(VirtualFile f) {
|
||||
myFile = f;
|
||||
}
|
||||
|
||||
public String getContentBefore() {
|
||||
return myContents[0];
|
||||
}
|
||||
|
||||
public String getContentAfter() {
|
||||
return myContents[1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeContentsChange(VirtualFileEvent e) {
|
||||
logContent(e, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contentsChanged(VirtualFileEvent e) {
|
||||
logContent(e, 1);
|
||||
}
|
||||
|
||||
private void logContent(VirtualFileEvent e, int i) {
|
||||
try {
|
||||
if (!e.getFile().equals(myFile)) return;
|
||||
myContents[i] = new String(myFile.contentsToByteArray());
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -420,12 +420,13 @@ public class SMTestProxy extends AbstractTestProxy {
|
||||
public void printOn(final Printer printer) {
|
||||
final Printer rightPrinter = getRightPrinter(printer);
|
||||
super.printOn(rightPrinter);
|
||||
final AbstractState oldState = myState;
|
||||
|
||||
invokeInAlarm(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//Tests State, that provide and formats additional output
|
||||
myState.printOn(rightPrinter);
|
||||
oldState.printOn(rightPrinter);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+17
-17
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 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.
|
||||
@@ -514,69 +514,69 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
|
||||
}
|
||||
}
|
||||
protected static void backspace() {
|
||||
doAction(IdeActions.ACTION_EDITOR_BACKSPACE);
|
||||
executeAction(IdeActions.ACTION_EDITOR_BACKSPACE);
|
||||
}
|
||||
protected static void delete() {
|
||||
doAction(IdeActions.ACTION_EDITOR_DELETE);
|
||||
executeAction(IdeActions.ACTION_EDITOR_DELETE);
|
||||
}
|
||||
|
||||
protected static void home() {
|
||||
doAction(IdeActions.ACTION_EDITOR_MOVE_LINE_START);
|
||||
executeAction(IdeActions.ACTION_EDITOR_MOVE_LINE_START);
|
||||
}
|
||||
|
||||
protected static void end() {
|
||||
doAction(IdeActions.ACTION_EDITOR_MOVE_LINE_END);
|
||||
executeAction(IdeActions.ACTION_EDITOR_MOVE_LINE_END);
|
||||
}
|
||||
|
||||
protected static void copy() {
|
||||
doAction(IdeActions.ACTION_EDITOR_COPY);
|
||||
executeAction(IdeActions.ACTION_EDITOR_COPY);
|
||||
}
|
||||
|
||||
protected static void paste() {
|
||||
doAction(IdeActions.ACTION_EDITOR_PASTE);
|
||||
executeAction(IdeActions.ACTION_EDITOR_PASTE);
|
||||
}
|
||||
|
||||
protected static void moveCaretToPreviousWordWithSelection() {
|
||||
doAction("EditorPreviousWordWithSelection");
|
||||
executeAction("EditorPreviousWordWithSelection");
|
||||
}
|
||||
|
||||
protected static void moveCaretToNextWordWithSelection() {
|
||||
doAction("EditorNextWordWithSelection");
|
||||
executeAction("EditorNextWordWithSelection");
|
||||
}
|
||||
|
||||
protected static void cutLineBackward() {
|
||||
doAction("EditorCutLineBackward");
|
||||
executeAction("EditorCutLineBackward");
|
||||
}
|
||||
|
||||
protected static void cutToLineEnd() {
|
||||
doAction("EditorCutLineEnd");
|
||||
executeAction("EditorCutLineEnd");
|
||||
}
|
||||
|
||||
protected static void killToWordStart() {
|
||||
doAction("EditorKillToWordStart");
|
||||
executeAction("EditorKillToWordStart");
|
||||
}
|
||||
|
||||
protected static void killToWordEnd() {
|
||||
doAction("EditorKillToWordEnd");
|
||||
executeAction("EditorKillToWordEnd");
|
||||
}
|
||||
|
||||
protected static void killRegion() {
|
||||
doAction("EditorKillRegion");
|
||||
executeAction("EditorKillRegion");
|
||||
}
|
||||
|
||||
protected static void killRingSave() {
|
||||
doAction("EditorKillRingSave");
|
||||
executeAction("EditorKillRingSave");
|
||||
}
|
||||
|
||||
protected static void unindent() {
|
||||
doAction("EditorUnindentSelection");
|
||||
executeAction("EditorUnindentSelection");
|
||||
}
|
||||
|
||||
protected static void lineComment() {
|
||||
new CommentByLineCommentHandler().invoke(getProject(), getEditor(), getFile());
|
||||
}
|
||||
|
||||
private static void doAction(@NotNull final String actionId) {
|
||||
protected static void executeAction(@NotNull final String actionId) {
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.util.ThrowableComputable;
|
||||
import com.intellij.util.containers.ConcurrentFactoryMap;
|
||||
import gnu.trove.THashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.rmi.Remote;
|
||||
@@ -59,34 +60,23 @@ public class RemoteUtil {
|
||||
}
|
||||
};
|
||||
|
||||
@Nullable
|
||||
public static <T> T castToRemote(final Object object, final Class<T> clazz) {
|
||||
if (!Proxy.isProxyClass(object.getClass())) return null;
|
||||
final InvocationHandler handler = Proxy.getInvocationHandler(object);
|
||||
if (handler instanceof RemoteInvocationHandler) {
|
||||
final RemoteInvocationHandler rih = (RemoteInvocationHandler)handler;
|
||||
if (clazz.isInstance(rih.myRemote)) {
|
||||
return (T)rih.myRemote;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T> T castToLocal(final Object remote, final Class<T> clazz) {
|
||||
final ClassLoader loader = clazz.getClassLoader();
|
||||
Object proxy = Proxy.newProxyInstance(loader, new Class[]{clazz}, new InvocationHandler() {
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
if (method.getDeclaringClass() == Object.class) {
|
||||
return method.invoke(remote, args);
|
||||
}
|
||||
else {
|
||||
Method m = ourRemoteToLocalMap.get(Pair.<Class<?>, Class<?>>create(remote.getClass(), clazz)).get(method);
|
||||
if (m == null) throw new NoSuchMethodError(method.getName() + " in " + remote.getClass());
|
||||
try {
|
||||
Object result = m.invoke(remote, args);
|
||||
if (result instanceof Remote) {
|
||||
return castToLocal(result, tryFixReturnType(result, method.getReturnType(), loader));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof RuntimeException) throw cause;
|
||||
if (cause instanceof Error) throw cause;
|
||||
if (canThrow(cause, method)) throw cause;
|
||||
throw new RuntimeException(cause);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return (T)proxy;
|
||||
//noinspection unchecked
|
||||
return (T)Proxy.newProxyInstance(loader, new Class[]{clazz}, new RemoteInvocationHandler(remote, clazz, loader));
|
||||
}
|
||||
|
||||
private static Class<?> tryFixReturnType(Object result, Class<?> returnType, ClassLoader loader) throws Exception {
|
||||
@@ -170,4 +160,40 @@ public class RemoteUtil {
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
private static class RemoteInvocationHandler implements InvocationHandler {
|
||||
private final Object myRemote;
|
||||
private final Class<?> myClazz;
|
||||
private final ClassLoader myLoader;
|
||||
|
||||
public RemoteInvocationHandler(Object remote, Class<?> clazz, ClassLoader loader) {
|
||||
myRemote = remote;
|
||||
myClazz = clazz;
|
||||
myLoader = loader;
|
||||
}
|
||||
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
if (method.getDeclaringClass() == Object.class) {
|
||||
return method.invoke(myRemote, args);
|
||||
}
|
||||
else {
|
||||
Method m = ourRemoteToLocalMap.get(Pair.<Class<?>, Class<?>>create(myRemote.getClass(), myClazz)).get(method);
|
||||
if (m == null) throw new NoSuchMethodError(method.getName() + " in " + myRemote.getClass());
|
||||
try {
|
||||
Object result = m.invoke(myRemote, args);
|
||||
if (result instanceof Remote) {
|
||||
return castToLocal(result, tryFixReturnType(result, method.getReturnType(), myLoader));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof RuntimeException) throw cause;
|
||||
if (cause instanceof Error) throw cause;
|
||||
if (canThrow(cause, method)) throw cause;
|
||||
throw new RuntimeException(cause);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,10 @@ import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.MemoryNotificationInfo;
|
||||
import java.lang.management.MemoryPoolMXBean;
|
||||
import java.lang.management.MemoryType;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
@@ -36,6 +40,34 @@ public class LowMemoryWatcher {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.util.LowMemoryWatcher");
|
||||
|
||||
private static final WeakList<LowMemoryWatcher> ourInstances = new WeakList<LowMemoryWatcher>();
|
||||
private static final ThreadPoolExecutor ourExecutor = new ThreadPoolExecutor(0, 1, 10, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(2), new ThreadFactory() {
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
return new Thread(r, "LowMemoryWatcher janitor");
|
||||
}
|
||||
});
|
||||
private static boolean ourSubmitted;
|
||||
private static final Runnable ourJanitor = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
for (LowMemoryWatcher watcher : ourInstances) {
|
||||
try {
|
||||
watcher.myRunnable.run();
|
||||
}
|
||||
catch (Throwable e) {
|
||||
LOG.info(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
synchronized (ourJanitor) {
|
||||
//noinspection AssignmentToStaticFieldFromInstanceMethod
|
||||
ourSubmitted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final Runnable myRunnable;
|
||||
|
||||
@@ -52,12 +84,11 @@ public class LowMemoryWatcher {
|
||||
((NotificationEmitter)ManagementFactory.getMemoryMXBean()).addNotificationListener(new NotificationListener() {
|
||||
public void handleNotification(Notification n, Object hb) {
|
||||
if (MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED.equals(n.getType()) || MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED.equals(n.getType())) {
|
||||
for (LowMemoryWatcher watcher : ourInstances) {
|
||||
try {
|
||||
watcher.myRunnable.run();
|
||||
}
|
||||
catch (Throwable e) {
|
||||
LOG.info(e);
|
||||
synchronized (ourJanitor) {
|
||||
if (!ourSubmitted) {
|
||||
//noinspection AssignmentToStaticFieldFromInstanceMethod
|
||||
ourSubmitted = true;
|
||||
ourExecutor.submit(ourJanitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,19 +59,6 @@ public class CommonProcessors {
|
||||
return myCollection;
|
||||
}
|
||||
|
||||
public static class Sync<T> extends CollectProcessor<T> {
|
||||
public Sync(final Collection<T> collection) {
|
||||
super(collection);
|
||||
}
|
||||
|
||||
public Sync() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean process(final T t) {
|
||||
return super.process(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 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.
|
||||
@@ -198,17 +198,17 @@ public class CharArrayUtil {
|
||||
return shiftForward(new CharArrayCharSequence(buffer), offset, chars);
|
||||
}
|
||||
|
||||
public static int shiftBackward(CharSequence buffer, int offset, String chars) {
|
||||
public static int shiftBackward(CharSequence buffer, int offset, String charsToSkip) {
|
||||
if (offset >= buffer.length()) return offset;
|
||||
|
||||
while (true) {
|
||||
if (offset < 0) break;
|
||||
char c = buffer.charAt(offset);
|
||||
int i;
|
||||
for (i = 0; i < chars.length(); i++) {
|
||||
if (c == chars.charAt(i)) break;
|
||||
for (i = 0; i < charsToSkip.length(); i++) {
|
||||
if (c == charsToSkip.charAt(i)) break;
|
||||
}
|
||||
if (i == chars.length()) break;
|
||||
if (i == charsToSkip.length()) break;
|
||||
offset--;
|
||||
}
|
||||
return offset;
|
||||
|
||||
+13
-15
@@ -31,21 +31,19 @@ import java.util.Map;
|
||||
public class ReplaceOperatorAssignmentWithAssignmentIntention
|
||||
extends MutablyNamedIntention {
|
||||
|
||||
private static final Map<IElementType, IElementType> tokenMap = new HashMap();
|
||||
|
||||
static {
|
||||
tokenMap.put(JavaTokenType.PLUSEQ, JavaTokenType.PLUS);
|
||||
tokenMap.put(JavaTokenType.MINUSEQ, JavaTokenType.MINUS);
|
||||
tokenMap.put(JavaTokenType.ASTERISKEQ, JavaTokenType.ASTERISK);
|
||||
tokenMap.put(JavaTokenType.DIVEQ, JavaTokenType.DIV);
|
||||
tokenMap.put(JavaTokenType.ANDEQ, JavaTokenType.AND);
|
||||
tokenMap.put(JavaTokenType.OREQ, JavaTokenType.OR);
|
||||
tokenMap.put(JavaTokenType.XOREQ, JavaTokenType.XOR);
|
||||
tokenMap.put(JavaTokenType.PERCEQ, JavaTokenType.PERC);
|
||||
tokenMap.put(JavaTokenType.LTLTEQ, JavaTokenType.LTLT);
|
||||
tokenMap.put(JavaTokenType.GTGTEQ, JavaTokenType.GTGT);
|
||||
tokenMap.put(JavaTokenType.GTGTGTEQ, JavaTokenType.GTGTGT);
|
||||
}
|
||||
private static final Map<IElementType, IElementType> tokenMap = new HashMap<IElementType, IElementType>() {{
|
||||
put(JavaTokenType.PLUSEQ, JavaTokenType.PLUS);
|
||||
put(JavaTokenType.MINUSEQ, JavaTokenType.MINUS);
|
||||
put(JavaTokenType.ASTERISKEQ, JavaTokenType.ASTERISK);
|
||||
put(JavaTokenType.DIVEQ, JavaTokenType.DIV);
|
||||
put(JavaTokenType.ANDEQ, JavaTokenType.AND);
|
||||
put(JavaTokenType.OREQ, JavaTokenType.OR);
|
||||
put(JavaTokenType.XOREQ, JavaTokenType.XOR);
|
||||
put(JavaTokenType.PERCEQ, JavaTokenType.PERC);
|
||||
put(JavaTokenType.LTLTEQ, JavaTokenType.LTLT);
|
||||
put(JavaTokenType.GTGTEQ, JavaTokenType.GTGT);
|
||||
put(JavaTokenType.GTGTGTEQ, JavaTokenType.GTGTGT);
|
||||
}};
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
|
||||
@@ -364,7 +364,7 @@ public class ModelParser extends XmlRecursiveElementVisitor {
|
||||
if (myRootComponent == null) {
|
||||
myRootComponent = createComponent(myXmlFile.getRootTag(), myMetaManager.getModelByTag("<root>"));
|
||||
}
|
||||
else if (session.getRootViews().size() == 1) {
|
||||
else if (myRootComponent.getMetaModel() != myMetaManager.getModelByTag("merge")) {
|
||||
RadViewComponent rootComponent = myRootComponent;
|
||||
myRootComponent = createComponent(myXmlFile.getRootTag(), myMetaManager.getModelByTag("<root>"));
|
||||
myRootComponent.add(rootComponent, null);
|
||||
|
||||
@@ -323,7 +323,8 @@ public class GitMergeProvider implements MergeProvider2 {
|
||||
for (VirtualFile f : files) {
|
||||
String path = VcsFileUtil.relativePath(root, f);
|
||||
Conflict c = cs.get(path);
|
||||
assert c != null : "The conflict not found for the file: " + f.getPath() + "(" + path + ")";
|
||||
log.assertTrue(c != null, String.format("The conflict not found for the file: %s(%s)%nFull ls-files output: %n%s",
|
||||
f.getPath(), path, output));
|
||||
c.myFile = f;
|
||||
if (c.myStatusTheirs == null) {
|
||||
c.myStatusTheirs = Conflict.Status.DELETED;
|
||||
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
print <spot>'''first
|
||||
second'''</spot>
|
||||
+1
@@ -0,0 +1 @@
|
||||
print <spot>'first\n second'</spot>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
This intention converts singleline string literal to multiline literal.
|
||||
</body>
|
||||
</html>
|
||||
@@ -1056,11 +1056,6 @@
|
||||
<categoryKey>intention.category.groovy/intention.category.conversions</categoryKey>
|
||||
<className>org.jetbrains.plugins.groovy.intentions.conversions.IndexedExpressionConversionIntention</className>
|
||||
</intentionAction>
|
||||
<!--<intentionAction>
|
||||
<bundleName>org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle</bundleName>
|
||||
<categoryKey>intention.category.groovy/intention.category.conversions</categoryKey>
|
||||
<className>org.jetbrains.plugins.groovy.intentions.conversions.ConvertStringToGStringIntention</className>
|
||||
</intentionAction>-->
|
||||
<intentionAction>
|
||||
<bundleName>org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle</bundleName>
|
||||
<categoryKey>intention.category.groovy/intention.category.conversions</categoryKey>
|
||||
@@ -1111,6 +1106,11 @@
|
||||
<categoryKey>intention.category.groovy/intention.category.conversions</categoryKey>
|
||||
<className>org.jetbrains.plugins.groovy.intentions.conversions.ConvertMethodToClosureIntention</className>
|
||||
</intentionAction>
|
||||
<intentionAction>
|
||||
<bundleName>org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle</bundleName>
|
||||
<categoryKey>intention.category.groovy/intention.category.conversions</categoryKey>
|
||||
<className>org.jetbrains.plugins.groovy.intentions.conversions.ConvertStringToMultilineIntention</className>
|
||||
</intentionAction>
|
||||
<intentionAction>
|
||||
<bundleName>org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle</bundleName>
|
||||
<categoryKey>intention.category.groovy/intention.category.conversions</categoryKey>
|
||||
|
||||
@@ -124,6 +124,7 @@ import.class=Import Class
|
||||
create.class.family.name=Create Class
|
||||
create.class.text=Create Class {0}
|
||||
create.interface.text=Create Interface {0}
|
||||
create.annotation.text=Create Annotation {0}
|
||||
static.declaration.in.inner.class=Inner classes cannot have static declarations
|
||||
constructors.are.not.allowed.in.anonymous.class=Constructors are not allowed in anonymous class
|
||||
no.such.property=Property ''{0}'' does not exist
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.daemon.JavaErrorMessages;
|
||||
import com.intellij.codeInsight.daemon.QuickFixActionRegistrar;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.AddMethodBodyFix;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.CreateClassKind;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.CreateConstructorMatchingSuperFix;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.OrderEntryFix;
|
||||
import com.intellij.codeInsight.generation.OverrideImplementUtil;
|
||||
@@ -135,8 +136,104 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
}
|
||||
myHolder = null;
|
||||
}
|
||||
else {
|
||||
highlightDeclaration(element, holder);
|
||||
}
|
||||
}
|
||||
|
||||
private static void highlightDeclaration(PsiElement element, AnnotationHolder holder) {
|
||||
PsiElement parent = element.getParent();
|
||||
if (!(parent instanceof GrNamedElement) || ((GrNamedElement)parent).getNameIdentifierGroovy() != element) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (parent instanceof GrTypeParameter) {
|
||||
final Annotation annotation = holder.createInfoAnnotation(element, null);
|
||||
annotation.setTextAttributes(DefaultHighlighter.TYPE_PARAMETER);
|
||||
}
|
||||
else if (parent instanceof GrAnnotationTypeDefinition) {
|
||||
final Annotation annotation = holder.createInfoAnnotation(element, null);
|
||||
annotation.setTextAttributes(DefaultHighlighter.ANNOTATION);
|
||||
}
|
||||
else if (parent instanceof PsiClass) {
|
||||
final Annotation annotation = holder.createInfoAnnotation(element, null);
|
||||
annotation.setTextAttributes(DefaultHighlighter.CLASS_REFERENCE);
|
||||
}
|
||||
else if (parent instanceof PsiMethod) {
|
||||
if (!((PsiMethod)parent).isConstructor()) {
|
||||
final Annotation annotation = holder.createInfoAnnotation(element, null);
|
||||
annotation.setTextAttributes(DefaultHighlighter.METHOD_DECLARATION);
|
||||
}
|
||||
}
|
||||
else if (parent instanceof PsiField) {
|
||||
final boolean isStatic = ((PsiField)parent).hasModifierProperty(PsiModifier.STATIC);
|
||||
final Annotation annotation = holder.createInfoAnnotation(element, null);
|
||||
annotation.setTextAttributes(isStatic ? DefaultHighlighter.STATIC_FIELD : DefaultHighlighter.INSTANCE_FIELD);
|
||||
}
|
||||
else if (parent instanceof GrParameter) {
|
||||
boolean reassigned = isReassigned((GrParameter)parent);
|
||||
final Annotation annotation = holder.createInfoAnnotation(element, null);
|
||||
annotation.setTextAttributes(reassigned ? DefaultHighlighter.REASSIGNED_PARAMETER : DefaultHighlighter.PARAMETER);
|
||||
}
|
||||
else if (parent instanceof GrVariable) {
|
||||
boolean reassigned = isReassigned((GrVariable)parent);
|
||||
final Annotation annotation = holder.createInfoAnnotation(element, null);
|
||||
annotation.setTextAttributes(reassigned ? DefaultHighlighter.REASSIGNED_LOCAL_VARIABLE : DefaultHighlighter.LOCAL_VARIABLE);
|
||||
}
|
||||
}
|
||||
|
||||
private static void highlightResolved(AnnotationHolder holder, GrReferenceElement refElement, PsiElement resolved) {
|
||||
final PsiElement refNameElement = getElementToHighlight(refElement);
|
||||
|
||||
if (resolved instanceof PsiField) {
|
||||
boolean isStatic = ((PsiField)resolved).hasModifierProperty(PsiModifier.STATIC);
|
||||
Annotation annotation = holder.createInfoAnnotation(refNameElement, null);
|
||||
annotation.setTextAttributes(isStatic ? DefaultHighlighter.STATIC_FIELD : DefaultHighlighter.INSTANCE_FIELD);
|
||||
}
|
||||
else if (resolved instanceof GrAccessorMethod) {
|
||||
boolean isStatic = ((GrAccessorMethod)resolved).hasModifierProperty(PsiModifier.STATIC);
|
||||
Annotation annotation = holder.createInfoAnnotation(refNameElement, null);
|
||||
annotation.setTextAttributes(isStatic ? DefaultHighlighter.STATIC_PROPERTY_REFERENCE : DefaultHighlighter.INSTANCE_PROPERTY_REFERENCE);
|
||||
}
|
||||
else if (resolved instanceof PsiMethod) {
|
||||
boolean isStatic = ((PsiMethod)resolved).hasModifierProperty(PsiModifier.STATIC);
|
||||
if (GroovyPropertyUtils.isSimplePropertyAccessor((PsiMethod)resolved)) {
|
||||
Annotation annotation = holder.createInfoAnnotation(refNameElement, null);
|
||||
annotation.setTextAttributes(isStatic ? DefaultHighlighter.STATIC_PROPERTY_REFERENCE : DefaultHighlighter.INSTANCE_PROPERTY_REFERENCE);
|
||||
}
|
||||
else {
|
||||
Annotation annotation = holder.createInfoAnnotation(refNameElement, null);
|
||||
annotation.setTextAttributes(isStatic ? DefaultHighlighter.STATIC_METHOD_ACCESS : DefaultHighlighter.METHOD_CALL);
|
||||
}
|
||||
}
|
||||
else if (resolved instanceof PsiTypeParameter) {
|
||||
Annotation annotation = holder.createInfoAnnotation(refNameElement, null);
|
||||
annotation.setTextAttributes(DefaultHighlighter.TYPE_PARAMETER);
|
||||
}
|
||||
else if (resolved instanceof PsiClass) {
|
||||
if (((PsiClass)resolved).isAnnotationType()) {
|
||||
Annotation annotation = holder.createInfoAnnotation(refNameElement, null);
|
||||
annotation.setTextAttributes(DefaultHighlighter.ANNOTATION);
|
||||
}
|
||||
else {
|
||||
Annotation annotation = holder.createInfoAnnotation(refNameElement, null);
|
||||
annotation.setTextAttributes(DefaultHighlighter.CLASS_REFERENCE);
|
||||
}
|
||||
}
|
||||
else if (resolved instanceof GrParameter) {
|
||||
boolean reassigned = isReassigned((GrParameter)resolved);
|
||||
Annotation annotation = holder.createInfoAnnotation(refNameElement, null);
|
||||
annotation.setTextAttributes(reassigned ? DefaultHighlighter.REASSIGNED_PARAMETER : DefaultHighlighter.PARAMETER);
|
||||
}
|
||||
else if (resolved instanceof GrVariable) {
|
||||
boolean reassigned = isReassigned((GrVariable)resolved);
|
||||
Annotation annotation = holder.createInfoAnnotation(refNameElement, null);
|
||||
annotation.setTextAttributes(reassigned ? DefaultHighlighter.REASSIGNED_LOCAL_VARIABLE : DefaultHighlighter.LOCAL_VARIABLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visitTypeArgumentList(GrTypeArgumentList typeArgumentList) {
|
||||
PsiElement parent = typeArgumentList.getParent();
|
||||
@@ -221,9 +318,7 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
return;
|
||||
}
|
||||
|
||||
if (resolveResult.getElement() instanceof PsiMember) {
|
||||
highlightMemberResolved(myHolder, refElement, ((PsiMember)resolveResult.getElement()));
|
||||
}
|
||||
highlightResolved(myHolder, refElement, resolveResult.getElement());
|
||||
|
||||
checkSingleResolvedElement(myHolder, refElement, resolveResult, true);
|
||||
|
||||
@@ -312,12 +407,7 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
final PsiElement parent = referenceExpression.getParent();
|
||||
|
||||
if (resolved != null) {
|
||||
if (resolved instanceof PsiMember) {
|
||||
highlightMemberResolved(myHolder, referenceExpression, ((PsiMember)resolved));
|
||||
}
|
||||
else if (resolved instanceof GrVariable) {
|
||||
highlightVariable((GrVariable)resolved, getElementToHighlight(referenceExpression));
|
||||
}
|
||||
highlightResolved(myHolder, referenceExpression, resolved);
|
||||
|
||||
if (!resolveResult.isStaticsOK() && resolved instanceof PsiModifierListOwner) {
|
||||
if (!((PsiModifierListOwner)resolved).hasModifierProperty(PsiModifier.STATIC)) {
|
||||
@@ -404,17 +494,6 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
return containingMember != null && GroovyPsiManager.getInstance(containingMember.getProject()).isCompileStatic(containingMember);
|
||||
}
|
||||
|
||||
private void highlightVariable(GrVariable variable, PsiElement toHighlight) {
|
||||
Annotation annotation = myHolder.createInfoAnnotation(toHighlight, null);
|
||||
boolean reassigned = isReassigned(variable);
|
||||
if (variable instanceof GrParameter) {
|
||||
annotation.setTextAttributes(reassigned ? DefaultHighlighter.REASSIGNED_PARAMETER : DefaultHighlighter.PARAMETER);
|
||||
}
|
||||
else {
|
||||
annotation.setTextAttributes(reassigned ? DefaultHighlighter.REASSIGNED_LOCAL_VARIABLE : DefaultHighlighter.LOCAL_VARIABLE);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isReassigned(GrVariable var) {
|
||||
PsiMethod method = PsiTreeUtil.getParentOfType(var, PsiMethod.class);
|
||||
PsiNamedElement scope = method == null ? var.getContainingFile() : method;
|
||||
@@ -528,12 +607,6 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
checkDuplicateMethod(typeDefinition.getMethods(), myHolder);
|
||||
checkImplementedMethodsOfClass(myHolder, typeDefinition);
|
||||
checkConstructors(myHolder, typeDefinition);
|
||||
if (typeDefinition instanceof GrTypeParameter) {
|
||||
highlightTypeParameterReference(myHolder, typeDefinition.getNameIdentifierGroovy());
|
||||
}
|
||||
else {
|
||||
highlightClassReference(myHolder, typeDefinition.getNameIdentifierGroovy());
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkReferenceList(AnnotationHolder holder,
|
||||
@@ -664,9 +737,7 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
|
||||
@Override
|
||||
public void visitMethod(GrMethod method) {
|
||||
if (!method.isConstructor()) {
|
||||
myHolder.createInfoAnnotation(method.getNameIdentifierGroovy(), null).setTextAttributes(DefaultHighlighter.METHOD_DECLARATION);
|
||||
}
|
||||
|
||||
|
||||
checkMethodDefinitionModifiers(myHolder, method);
|
||||
checkMethodWithTypeParamsShouldHaveReturnType(myHolder, method);
|
||||
@@ -763,11 +834,6 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
@Override
|
||||
public void visitVariable(GrVariable variable) {
|
||||
checkName(variable);
|
||||
if (variable instanceof GrMember) {
|
||||
highlightMember(myHolder, ((GrMember)variable));
|
||||
} else {
|
||||
highlightVariable(variable, variable.getNameIdentifierGroovy());
|
||||
}
|
||||
|
||||
PsiNamedElement duplicate = ResolveUtil
|
||||
.resolveExistingElement(variable, new DuplicateVariablesProcessor(variable), GrReferenceExpression.class, GrVariable.class);
|
||||
@@ -1235,14 +1301,13 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
public void visitAnnotation(GrAnnotation annotation) {
|
||||
super.visitAnnotation(annotation);
|
||||
final GrCodeReferenceElement ref = annotation.getClassReference();
|
||||
GroovyResolveResult resolveResult = ref.advancedResolve();
|
||||
final PsiElement resolved = ref.resolve();
|
||||
|
||||
highlightAnnotation(myHolder, ref, resolveResult);
|
||||
|
||||
if (resolved == null) return;
|
||||
assert resolved instanceof PsiClass;
|
||||
|
||||
highlightResolved(myHolder, ref, resolved);
|
||||
|
||||
PsiClass anno = (PsiClass) resolved;
|
||||
if (!anno.isAnnotationType()) {
|
||||
myHolder.createErrorAnnotation(ref, GroovyBundle.message("class.is.not.annotation", ((PsiClass)resolved).getQualifiedName()));
|
||||
@@ -1251,9 +1316,8 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
PsiElement parent = annotation.getParent();
|
||||
PsiElement owner = parent.getParent();
|
||||
String[] elementTypeFields = GrAnnotationImpl.getApplicableElementTypeFields(parent instanceof PsiModifierList ? owner : parent);
|
||||
if (!GrAnnotationImpl.isAnnotationApplicableTo(annotation, false, elementTypeFields)) {
|
||||
String description = JavaErrorMessages
|
||||
.message("annotation.not.applicable", ref.getText(), JavaErrorMessages.message("annotation.target." + elementTypeFields[0]));
|
||||
if (elementTypeFields != null && !GrAnnotationImpl.isAnnotationApplicableTo(annotation, false, elementTypeFields)) {
|
||||
String description = JavaErrorMessages.message("annotation.not.applicable", ref.getText(), JavaErrorMessages.message("annotation.target." + elementTypeFields[0]));
|
||||
myHolder.createErrorAnnotation(ref, description);
|
||||
}
|
||||
}
|
||||
@@ -1623,11 +1687,7 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
|
||||
private static void checkTypeDefinition(AnnotationHolder holder, GrTypeDefinition typeDefinition) {
|
||||
final GroovyConfigUtils configUtils = GroovyConfigUtils.getInstance();
|
||||
if (typeDefinition.isAnnotationType()) {
|
||||
Annotation annotation = holder.createInfoAnnotation(typeDefinition.getNameIdentifierGroovy(), null);
|
||||
annotation.setTextAttributes(DefaultHighlighter.ANNOTATION);
|
||||
}
|
||||
else if (typeDefinition.isAnonymous()) {
|
||||
if (typeDefinition.isAnonymous()) {
|
||||
if (!configUtils.isVersionAtLeast(typeDefinition, GroovyConfigUtils.GROOVY1_7)) {
|
||||
holder.createErrorAnnotation(typeDefinition.getNameIdentifierGroovy(), GroovyBundle.message("anonymous.classes.are.not.supported",
|
||||
configUtils
|
||||
@@ -1827,33 +1887,6 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
}
|
||||
}
|
||||
|
||||
private static void highlightMemberResolved(AnnotationHolder holder, GrReferenceElement refExpr, PsiMember member) {
|
||||
boolean isStatic = member.hasModifierProperty(PsiModifier.STATIC);
|
||||
final PsiElement refNameElement = getElementToHighlight(refExpr);
|
||||
Annotation annotation = holder.createInfoAnnotation(refNameElement, null);
|
||||
|
||||
if (member instanceof PsiField) {
|
||||
annotation.setTextAttributes(isStatic ? DefaultHighlighter.STATIC_FIELD : DefaultHighlighter.INSTANCE_FIELD);
|
||||
}
|
||||
else if (member instanceof GrAccessorMethod) {
|
||||
annotation.setTextAttributes(isStatic ? DefaultHighlighter.STATIC_PROPERTY_REFERENCE : DefaultHighlighter.INSTANCE_PROPERTY_REFERENCE);
|
||||
}
|
||||
else if (member instanceof PsiMethod) {
|
||||
if (GroovyPropertyUtils.isSimplePropertyAccessor((PsiMethod)member)) {
|
||||
annotation.setTextAttributes(isStatic ? DefaultHighlighter.STATIC_PROPERTY_REFERENCE : DefaultHighlighter.INSTANCE_PROPERTY_REFERENCE);
|
||||
}
|
||||
else {
|
||||
annotation.setTextAttributes(isStatic ? DefaultHighlighter.STATIC_METHOD_ACCESS : DefaultHighlighter.METHOD_CALL);
|
||||
}
|
||||
}
|
||||
else if (member instanceof PsiTypeParameter) {
|
||||
highlightTypeParameterReference(holder, refExpr);
|
||||
|
||||
}
|
||||
else if (member instanceof PsiClass) {
|
||||
highlightClassReference(holder, refExpr);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isDeclarationAssignment(GrReferenceExpression refExpr) {
|
||||
if (isAssignmentLhs(refExpr)) {
|
||||
@@ -1949,21 +1982,29 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
}
|
||||
else {
|
||||
if (shouldBeInterface(refElement)) {
|
||||
annotation.registerFix(CreateClassFix.createClassFixAction(refElement, CreateClassActionBase.Type.INTERFACE));
|
||||
annotation.registerFix(CreateClassFix.createClassFixAction(refElement, CreateClassKind.INTERFACE));
|
||||
}
|
||||
else if (shouldBeClass(refElement)) {
|
||||
annotation.registerFix(CreateClassFix.createClassFixAction(refElement, CreateClassActionBase.Type.CLASS));
|
||||
annotation.registerFix(CreateClassFix.createClassFixAction(refElement, CreateClassActionBase.Type.ENUM));
|
||||
annotation.registerFix(CreateClassFix.createClassFixAction(refElement, CreateClassKind.CLASS));
|
||||
annotation.registerFix(CreateClassFix.createClassFixAction(refElement, CreateClassKind.ENUM));
|
||||
}
|
||||
else if (shouldBeAnnotation(refElement)) {
|
||||
annotation.registerFix(CreateClassFix.createClassFixAction(refElement, CreateClassKind.ANNOTATION));
|
||||
}
|
||||
else {
|
||||
annotation.registerFix(CreateClassFix.createClassFixAction(refElement, CreateClassActionBase.Type.CLASS));
|
||||
annotation.registerFix(CreateClassFix.createClassFixAction(refElement, CreateClassActionBase.Type.INTERFACE));
|
||||
annotation.registerFix(CreateClassFix.createClassFixAction(refElement, CreateClassActionBase.Type.ENUM));
|
||||
annotation.registerFix(CreateClassFix.createClassFixAction(refElement, CreateClassKind.CLASS));
|
||||
annotation.registerFix(CreateClassFix.createClassFixAction(refElement, CreateClassKind.INTERFACE));
|
||||
annotation.registerFix(CreateClassFix.createClassFixAction(refElement, CreateClassKind.ENUM));
|
||||
annotation.registerFix(CreateClassFix.createClassFixAction(refElement, CreateClassKind.ANNOTATION));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldBeAnnotation(GrReferenceElement element) {
|
||||
return element.getParent() instanceof GrAnnotation;
|
||||
}
|
||||
|
||||
private static boolean shouldBeInterface(GrReferenceElement myRefElement) {
|
||||
PsiElement parent = myRefElement.getParent();
|
||||
return parent instanceof GrImplementsClause || parent instanceof GrExtendsClause && parent.getParent() instanceof GrInterfaceDefinition;
|
||||
@@ -1974,52 +2015,6 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
return parent instanceof GrExtendsClause && !(parent.getParent() instanceof GrInterfaceDefinition);
|
||||
}
|
||||
|
||||
|
||||
private static void highlightMember(AnnotationHolder holder, GrMember member) {
|
||||
if (member instanceof GrField) {
|
||||
GrField field = (GrField)member;
|
||||
PsiElement identifier = field.getNameIdentifierGroovy();
|
||||
final boolean isStatic = field.hasModifierProperty(PsiModifier.STATIC);
|
||||
holder.createInfoAnnotation(identifier, null).setTextAttributes(
|
||||
isStatic ? DefaultHighlighter.STATIC_FIELD : DefaultHighlighter.INSTANCE_FIELD);
|
||||
}
|
||||
}
|
||||
|
||||
private static void highlightAnnotation(AnnotationHolder holder, PsiElement refElement, GroovyResolveResult result) {
|
||||
PsiElement element = result.getElement();
|
||||
PsiElement parent = refElement.getParent();
|
||||
if (element instanceof PsiClass) {
|
||||
if (((PsiClass)element).isAnnotationType() && !(parent instanceof GrImportStatement)) {
|
||||
final TextRange range = refElement.getTextRange();
|
||||
Annotation annotation = holder.createInfoAnnotation(new TextRange(range.getStartOffset() - 1, range.getEndOffset()), null);
|
||||
annotation.setTextAttributes(DefaultHighlighter.ANNOTATION);
|
||||
GroovyPsiElement context = result.getCurrentFileResolveContext();
|
||||
if (context instanceof GrImportStatement) {
|
||||
final GrCodeReferenceElement importReference = ((GrImportStatement)context).getImportReference();
|
||||
LOG.assertTrue(importReference != null);
|
||||
annotation = holder.createInfoAnnotation(importReference, null);
|
||||
annotation.setTextAttributes(DefaultHighlighter.ANNOTATION);
|
||||
}
|
||||
}
|
||||
else if (element instanceof PsiTypeParameter) {
|
||||
highlightTypeParameterReference(holder, refElement);
|
||||
}
|
||||
else {
|
||||
highlightClassReference(holder, refElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void highlightTypeParameterReference(AnnotationHolder holder, PsiElement element) {
|
||||
final Annotation annotation = holder.createInfoAnnotation(element, null);
|
||||
annotation.setTextAttributes(DefaultHighlighter.TYPE_PARAMETER);
|
||||
}
|
||||
|
||||
private static void highlightClassReference(AnnotationHolder holder, PsiElement classReference) {
|
||||
final Annotation annotation = holder.createInfoAnnotation(classReference, null);
|
||||
annotation.setTextAttributes(DefaultHighlighter.CLASS_REFERENCE);
|
||||
}
|
||||
|
||||
public static class DuplicateVariablesProcessor extends PropertyResolverProcessor {
|
||||
private boolean myBorderPassed;
|
||||
private final boolean myHasVisibilityModifier;
|
||||
|
||||
+22
-6
@@ -16,7 +16,9 @@
|
||||
|
||||
package org.jetbrains.plugins.groovy.annotator.intentions;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.CreateClassKind;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.intention.impl.CreateClassDialog;
|
||||
import com.intellij.openapi.application.AccessToken;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
@@ -24,7 +26,9 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
@@ -40,12 +44,12 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefini
|
||||
* @author ilyas
|
||||
*/
|
||||
public abstract class CreateClassActionBase implements IntentionAction {
|
||||
private Type myType;
|
||||
private CreateClassKind myType;
|
||||
|
||||
protected final GrReferenceElement myRefElement;
|
||||
private static final Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.annotator.intentions.CreateClassActionBase");
|
||||
|
||||
public CreateClassActionBase(Type type, GrReferenceElement refElement) {
|
||||
public CreateClassActionBase(CreateClassKind type, GrReferenceElement refElement) {
|
||||
myType = type;
|
||||
myRefElement = refElement;
|
||||
}
|
||||
@@ -60,6 +64,8 @@ public abstract class CreateClassActionBase implements IntentionAction {
|
||||
return GroovyBundle.message("create.class.text", referenceName);
|
||||
case INTERFACE:
|
||||
return GroovyBundle.message("create.interface.text", referenceName);
|
||||
case ANNOTATION:
|
||||
return GroovyBundle.message("create.annotation.text", referenceName);
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
@@ -75,11 +81,11 @@ public abstract class CreateClassActionBase implements IntentionAction {
|
||||
}
|
||||
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected Type getType() {
|
||||
protected CreateClassKind getType() {
|
||||
return myType;
|
||||
}
|
||||
|
||||
@@ -145,7 +151,17 @@ public abstract class CreateClassActionBase implements IntentionAction {
|
||||
}
|
||||
}
|
||||
|
||||
public static enum Type {
|
||||
ENUM, CLASS, INTERFACE
|
||||
@Nullable
|
||||
protected PsiDirectory getTargetDirectory(Project project, String qualifier, String name, Module module, String title) {
|
||||
CreateClassDialog dialog = new CreateClassDialog(project, title, name, qualifier, getType(), false, module) {
|
||||
@Override
|
||||
protected boolean reportBaseInSourceSelectionInTest() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
dialog.show();
|
||||
if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) return null;
|
||||
|
||||
return dialog.getTargetDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
+96
-62
@@ -16,12 +16,15 @@
|
||||
|
||||
package org.jetbrains.plugins.groovy.annotator.intentions;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.CreateClassKind;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.application.AccessToken;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
@@ -34,7 +37,6 @@ import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
|
||||
@@ -49,58 +51,91 @@ import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
|
||||
public abstract class CreateClassFix {
|
||||
|
||||
public static IntentionAction createClassFromNewAction(final GrNewExpression expression) {
|
||||
return new CreateClassActionBase(CreateClassActionBase.Type.CLASS, expression.getReferenceElement()) {
|
||||
return new CreateClassActionBase(CreateClassKind.CLASS, expression.getReferenceElement()) {
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
if (!(file instanceof GroovyFileBase)) return;
|
||||
GroovyFileBase groovyFile = (GroovyFileBase) file;
|
||||
final String qualifier = groovyFile instanceof GroovyFile ? groovyFile.getPackageName() : "";
|
||||
GroovyFileBase groovyFile = (GroovyFileBase)file;
|
||||
final PsiManager manager = myRefElement.getManager();
|
||||
final String name = myRefElement.getReferenceName();
|
||||
assert name != null;
|
||||
final Module module = ModuleUtil.findModuleForPsiElement(file);
|
||||
|
||||
final String qualifier;
|
||||
final String name;
|
||||
final Module module;
|
||||
final AccessToken accessToken = ReadAction.start();
|
||||
try {
|
||||
qualifier = groovyFile instanceof GroovyFile ? groovyFile.getPackageName() : "";
|
||||
name = myRefElement.getReferenceName();
|
||||
assert name != null;
|
||||
module = ModuleUtil.findModuleForPsiElement(file);
|
||||
}
|
||||
finally {
|
||||
accessToken.finish();
|
||||
}
|
||||
|
||||
PsiDirectory targetDirectory = getTargetDirectory(project, qualifier, name, module, getText());
|
||||
if (targetDirectory == null) return;
|
||||
|
||||
GrTypeDefinition targetClass = createClassByType(targetDirectory, name, manager, myRefElement, NewGroovyClassAction.GROOVY_CLASS);
|
||||
if (targetClass == null) return;
|
||||
|
||||
GrArgumentList argList = expression.getArgumentList();
|
||||
if (argList != null && argList.getNamedArguments().length + argList.getExpressionArguments().length > 0 && targetClass != null) {
|
||||
|
||||
PsiType[] argTypes = PsiUtil.getArgumentTypes(myRefElement, false);
|
||||
assert argTypes != null;
|
||||
|
||||
ChooseTypeExpression[] paramTypesExpressions = new ChooseTypeExpression[argTypes.length];
|
||||
String[] paramTypes = new String[argTypes.length];
|
||||
String[] paramNames = new String[argTypes.length];
|
||||
|
||||
for (int i = 0; i < argTypes.length; i++) {
|
||||
PsiType argType = argTypes[i];
|
||||
if (argType == null) argType = TypesUtil.getJavaLangObject(myRefElement);
|
||||
paramTypes[i] = "Object";
|
||||
paramNames[i] = "o" + i;
|
||||
paramTypesExpressions[i] = new ChooseTypeExpression(new TypeConstraint[]{SupertypeConstraint.create(argType)}, myRefElement.getManager());
|
||||
}
|
||||
|
||||
GrMethod method = GroovyPsiElementFactory.getInstance(project).createConstructorFromText(name, paramTypes, paramNames, "{\n}");
|
||||
method = targetClass.addMemberDeclaration(method, null);
|
||||
final PsiNameIdentifierOwner context = PsiTreeUtil.getParentOfType(myRefElement, PsiMethod.class, PsiClass.class);
|
||||
IntentionUtils.createTemplateForMethod(argTypes, paramTypesExpressions, method, targetClass, new TypeConstraint[0], true, context);
|
||||
} else {
|
||||
PsiType[] argTypes = getArgTypes(myRefElement);
|
||||
if (argTypes != null) {
|
||||
generateConstructor(myRefElement, name, argTypes, targetClass, project);
|
||||
}
|
||||
else {
|
||||
putCursor(project, targetClass.getContainingFile(), targetClass);
|
||||
}
|
||||
addImportForClass(groovyFile, qualifier, targetClass);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
public static IntentionAction createClassFixAction(final GrReferenceElement refElement, CreateClassActionBase.Type type) {
|
||||
return new CreateClassActionBase(type, refElement) {
|
||||
@Nullable
|
||||
private static PsiType[] getArgTypes(GrReferenceElement refElement) {
|
||||
final AccessToken accessToken = ReadAction.start();
|
||||
try {
|
||||
return PsiUtil.getArgumentTypes(refElement, false);
|
||||
}
|
||||
finally {
|
||||
accessToken.finish();
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateConstructor(@NotNull PsiElement refElement,
|
||||
@NotNull String name,
|
||||
@NotNull PsiType[] argTypes,
|
||||
@NotNull GrTypeDefinition targetClass,
|
||||
@NotNull Project project) {
|
||||
final AccessToken writeLock = WriteAction.start();
|
||||
try {
|
||||
ChooseTypeExpression[] paramTypesExpressions = new ChooseTypeExpression[argTypes.length];
|
||||
String[] paramTypes = new String[argTypes.length];
|
||||
String[] paramNames = new String[argTypes.length];
|
||||
|
||||
for (int i = 0; i < argTypes.length; i++) {
|
||||
PsiType argType = argTypes[i];
|
||||
if (argType == null) argType = TypesUtil.getJavaLangObject(refElement);
|
||||
paramTypes[i] = "Object";
|
||||
paramNames[i] = "o" + i;
|
||||
paramTypesExpressions[i] = new ChooseTypeExpression(new TypeConstraint[]{SupertypeConstraint.create(argType)}, refElement.getManager());
|
||||
}
|
||||
|
||||
GrMethod method = GroovyPsiElementFactory.getInstance(project).createConstructorFromText(name, paramTypes, paramNames, "{\n}");
|
||||
|
||||
method = targetClass.addMemberDeclaration(method, null);
|
||||
final PsiNameIdentifierOwner context = PsiTreeUtil.getParentOfType(refElement, PsiMethod.class, PsiClass.class);
|
||||
IntentionUtils.createTemplateForMethod(argTypes, paramTypesExpressions, method, targetClass, new TypeConstraint[0], true, context);
|
||||
}
|
||||
finally {
|
||||
writeLock.finish();
|
||||
}
|
||||
}
|
||||
|
||||
public static IntentionAction createClassFixAction(final GrReferenceElement refElement, CreateClassKind type) {
|
||||
return new CreateClassActionBase(type, refElement) {
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
if (!(file instanceof GroovyFileBase)) return;
|
||||
GroovyFileBase groovyFile = (GroovyFileBase) file;
|
||||
GroovyFileBase groovyFile = (GroovyFileBase)file;
|
||||
final String qualifier = groovyFile instanceof GroovyFile ? groovyFile.getPackageName() : "";
|
||||
final PsiManager manager = PsiManager.getInstance(project);
|
||||
final String name = myRefElement.getReferenceName();
|
||||
@@ -109,18 +144,7 @@ public abstract class CreateClassFix {
|
||||
if (targetDirectory == null) return;
|
||||
|
||||
|
||||
String templateName = null;
|
||||
switch (getType()) {
|
||||
case ENUM:
|
||||
templateName = NewGroovyClassAction.GROOVY_ENUM;
|
||||
break;
|
||||
case CLASS:
|
||||
templateName = NewGroovyClassAction.GROOVY_CLASS;
|
||||
break;
|
||||
case INTERFACE:
|
||||
templateName = NewGroovyClassAction.GROOVY_INTERFACE;
|
||||
break;
|
||||
}
|
||||
String templateName = getTemplateName(getType());
|
||||
assert name != null;
|
||||
PsiClass targetClass = createClassByType(targetDirectory, name, manager, myRefElement, templateName);
|
||||
if (targetClass != null) {
|
||||
@@ -128,29 +152,39 @@ public abstract class CreateClassFix {
|
||||
putCursor(project, targetClass.getContainingFile(), targetClass);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiDirectory getTargetDirectory(Project project, String qualifier, String name, Module module, String title) {
|
||||
GroovyCreateClassDialog dialog = new GroovyCreateClassDialog(project, title, name, qualifier, module);
|
||||
dialog.show();
|
||||
if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) return null;
|
||||
return dialog.getTargetDirectory();
|
||||
private static String getTemplateName(CreateClassKind createClassKind) {
|
||||
switch (createClassKind) {
|
||||
case ENUM:
|
||||
return NewGroovyClassAction.GROOVY_ENUM;
|
||||
case CLASS:
|
||||
return NewGroovyClassAction.GROOVY_CLASS;
|
||||
case INTERFACE:
|
||||
return NewGroovyClassAction.GROOVY_INTERFACE;
|
||||
case ANNOTATION:
|
||||
return NewGroovyClassAction.GROOVY_ANNOTATION;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected static void addImportForClass(GroovyFileBase groovyFile, String qualifier, PsiClass targetClass) throws IncorrectOperationException {
|
||||
if (targetClass != null) {
|
||||
// add import for created class
|
||||
String qualifiedName = targetClass.getQualifiedName();
|
||||
if (qualifiedName != null && qualifiedName.contains(".")) {
|
||||
String packageName = qualifiedName.substring(0, qualifiedName.lastIndexOf("."));
|
||||
if (!packageName.equals(qualifier)) {
|
||||
protected static void addImportForClass(@NotNull GroovyFileBase groovyFile, @NotNull String qualifier, @NotNull PsiClass targetClass)
|
||||
throws IncorrectOperationException {
|
||||
// add import for created class
|
||||
String qualifiedName = targetClass.getQualifiedName();
|
||||
if (qualifiedName != null && qualifiedName.contains(".")) {
|
||||
String packageName = qualifiedName.substring(0, qualifiedName.lastIndexOf("."));
|
||||
if (!packageName.equals(qualifier)) {
|
||||
final AccessToken accessToken = WriteAction.start();
|
||||
try {
|
||||
groovyFile.addImportForClass(targetClass);
|
||||
}
|
||||
finally {
|
||||
accessToken.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user