Migration to new project code style setttings, merged changes

This commit is contained in:
Rustam Vishnyakov
2017-08-10 15:39:20 +03:00
parent d1bf30c732
commit 414025cbc1
127 changed files with 1492 additions and 571 deletions
@@ -28,6 +28,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiClass;
import com.intellij.psi.codeStyle.CodeStyleConfigurable;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.refactoring.RefactoringBundle;
import com.intellij.refactoring.ui.JavaVisibilityPanel;
import com.intellij.ui.SortedListModel;
@@ -101,32 +102,33 @@ public class CodeStyleGenerationConfigurable implements CodeStyleConfigurable {
}
public void reset(@NotNull CodeStyleSettings settings) {
myCbPreferLongerNames.setSelected(settings.PREFER_LONGER_NAMES);
JavaCodeStyleSettings javaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
myCbPreferLongerNames.setSelected(javaSettings.PREFER_LONGER_NAMES);
myFieldPrefixField.setText(settings.FIELD_NAME_PREFIX);
myStaticFieldPrefixField.setText(settings.STATIC_FIELD_NAME_PREFIX);
myParameterPrefixField.setText(settings.PARAMETER_NAME_PREFIX);
myLocalVariablePrefixField.setText(settings.LOCAL_VARIABLE_NAME_PREFIX);
myFieldPrefixField.setText(javaSettings.FIELD_NAME_PREFIX);
myStaticFieldPrefixField.setText(javaSettings.STATIC_FIELD_NAME_PREFIX);
myParameterPrefixField.setText(javaSettings.PARAMETER_NAME_PREFIX);
myLocalVariablePrefixField.setText(javaSettings.LOCAL_VARIABLE_NAME_PREFIX);
myFieldSuffixField.setText(settings.FIELD_NAME_SUFFIX);
myStaticFieldSuffixField.setText(settings.STATIC_FIELD_NAME_SUFFIX);
myParameterSuffixField.setText(settings.PARAMETER_NAME_SUFFIX);
myLocalVariableSuffixField.setText(settings.LOCAL_VARIABLE_NAME_SUFFIX);
myFieldSuffixField.setText(javaSettings.FIELD_NAME_SUFFIX);
myStaticFieldSuffixField.setText(javaSettings.STATIC_FIELD_NAME_SUFFIX);
myParameterSuffixField.setText(javaSettings.PARAMETER_NAME_SUFFIX);
myLocalVariableSuffixField.setText(javaSettings.LOCAL_VARIABLE_NAME_SUFFIX);
myCbGenerateFinalLocals.setSelected(settings.GENERATE_FINAL_LOCALS);
myCbGenerateFinalParameters.setSelected(settings.GENERATE_FINAL_PARAMETERS);
myCbGenerateFinalLocals.setSelected(javaSettings.GENERATE_FINAL_LOCALS);
myCbGenerateFinalParameters.setSelected(javaSettings.GENERATE_FINAL_PARAMETERS);
myCbUseExternalAnnotations.setSelected(settings.USE_EXTERNAL_ANNOTATIONS);
myInsertOverrideAnnotationCheckBox.setSelected(settings.INSERT_OVERRIDE_ANNOTATION);
myRepeatSynchronizedCheckBox.setSelected(settings.REPEAT_SYNCHRONIZED);
myJavaVisibilityPanel.setVisibility(settings.VISIBILITY);
myCbUseExternalAnnotations.setSelected(javaSettings.USE_EXTERNAL_ANNOTATIONS);
myInsertOverrideAnnotationCheckBox.setSelected(javaSettings.INSERT_OVERRIDE_ANNOTATION);
myRepeatSynchronizedCheckBox.setSelected(javaSettings.REPEAT_SYNCHRONIZED);
myJavaVisibilityPanel.setVisibility(javaSettings.VISIBILITY);
myReplaceCastCb.setSelected(settings.REPLACE_CAST);
myReplaceInstanceOfCb.setSelected(settings.REPLACE_INSTANCEOF);
myReplaceNullCheckCb.setSelected(settings.REPLACE_NULL_CHECK);
myReplaceCastCb.setSelected(javaSettings.REPLACE_CAST);
myReplaceInstanceOfCb.setSelected(javaSettings.REPLACE_INSTANCEOF);
myReplaceNullCheckCb.setSelected(javaSettings.REPLACE_NULL_CHECK);
myRepeatAnnotationsModel.clear();
myRepeatAnnotationsModel.addAll(settings.getRepeatAnnotations());
myRepeatAnnotationsModel.addAll(javaSettings.getRepeatAnnotations());
myCommenterForm.reset(settings);
}
@@ -135,34 +137,35 @@ public class CodeStyleGenerationConfigurable implements CodeStyleConfigurable {
}
public void apply(@NotNull CodeStyleSettings settings) throws ConfigurationException {
settings.PREFER_LONGER_NAMES = myCbPreferLongerNames.isSelected();
JavaCodeStyleSettings javaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
javaSettings.PREFER_LONGER_NAMES = myCbPreferLongerNames.isSelected();
settings.FIELD_NAME_PREFIX = setPrefixSuffix(myFieldPrefixField.getText(), true);
settings.STATIC_FIELD_NAME_PREFIX = setPrefixSuffix(myStaticFieldPrefixField.getText(), true);
settings.PARAMETER_NAME_PREFIX = setPrefixSuffix(myParameterPrefixField.getText(), true);
settings.LOCAL_VARIABLE_NAME_PREFIX = setPrefixSuffix(myLocalVariablePrefixField.getText(), true);
javaSettings.FIELD_NAME_PREFIX = setPrefixSuffix(myFieldPrefixField.getText(), true);
javaSettings.STATIC_FIELD_NAME_PREFIX = setPrefixSuffix(myStaticFieldPrefixField.getText(), true);
javaSettings.PARAMETER_NAME_PREFIX = setPrefixSuffix(myParameterPrefixField.getText(), true);
javaSettings.LOCAL_VARIABLE_NAME_PREFIX = setPrefixSuffix(myLocalVariablePrefixField.getText(), true);
settings.FIELD_NAME_SUFFIX = setPrefixSuffix(myFieldSuffixField.getText(), false);
settings.STATIC_FIELD_NAME_SUFFIX = setPrefixSuffix(myStaticFieldSuffixField.getText(), false);
settings.PARAMETER_NAME_SUFFIX = setPrefixSuffix(myParameterSuffixField.getText(), false);
settings.LOCAL_VARIABLE_NAME_SUFFIX = setPrefixSuffix(myLocalVariableSuffixField.getText(), false);
javaSettings.FIELD_NAME_SUFFIX = setPrefixSuffix(myFieldSuffixField.getText(), false);
javaSettings.STATIC_FIELD_NAME_SUFFIX = setPrefixSuffix(myStaticFieldSuffixField.getText(), false);
javaSettings.PARAMETER_NAME_SUFFIX = setPrefixSuffix(myParameterSuffixField.getText(), false);
javaSettings.LOCAL_VARIABLE_NAME_SUFFIX = setPrefixSuffix(myLocalVariableSuffixField.getText(), false);
settings.GENERATE_FINAL_LOCALS = myCbGenerateFinalLocals.isSelected();
settings.GENERATE_FINAL_PARAMETERS = myCbGenerateFinalParameters.isSelected();
javaSettings.GENERATE_FINAL_LOCALS = myCbGenerateFinalLocals.isSelected();
javaSettings.GENERATE_FINAL_PARAMETERS = myCbGenerateFinalParameters.isSelected();
settings.USE_EXTERNAL_ANNOTATIONS = myCbUseExternalAnnotations.isSelected();
settings.INSERT_OVERRIDE_ANNOTATION = myInsertOverrideAnnotationCheckBox.isSelected();
settings.REPEAT_SYNCHRONIZED = myRepeatSynchronizedCheckBox.isSelected();
javaSettings.USE_EXTERNAL_ANNOTATIONS = myCbUseExternalAnnotations.isSelected();
javaSettings.INSERT_OVERRIDE_ANNOTATION = myInsertOverrideAnnotationCheckBox.isSelected();
javaSettings.REPEAT_SYNCHRONIZED = myRepeatSynchronizedCheckBox.isSelected();
settings.VISIBILITY = myJavaVisibilityPanel.getVisibility();
javaSettings.VISIBILITY = myJavaVisibilityPanel.getVisibility();
settings.REPLACE_CAST = myReplaceCastCb.isSelected();
settings.REPLACE_INSTANCEOF = myReplaceInstanceOfCb.isSelected();
settings.REPLACE_NULL_CHECK = myReplaceNullCheckCb.isSelected();
javaSettings.REPLACE_CAST = myReplaceCastCb.isSelected();
javaSettings.REPLACE_INSTANCEOF = myReplaceInstanceOfCb.isSelected();
javaSettings.REPLACE_NULL_CHECK = myReplaceNullCheckCb.isSelected();
myCommenterForm.apply(settings);
settings.setRepeatAnnotations(myRepeatAnnotationsModel.getItems());
javaSettings.setRepeatAnnotations(myRepeatAnnotationsModel.getItems());
for (Project project : ProjectManager.getInstance().getOpenProjects()) {
DaemonCodeAnalyzer.getInstance(project).settingsChanged();
@@ -183,34 +186,35 @@ public class CodeStyleGenerationConfigurable implements CodeStyleConfigurable {
}
public boolean isModified(CodeStyleSettings settings) {
boolean isModified = isModified(myCbPreferLongerNames, settings.PREFER_LONGER_NAMES);
JavaCodeStyleSettings javaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
boolean isModified = isModified(myCbPreferLongerNames, javaSettings.PREFER_LONGER_NAMES);
isModified |= isModified(myFieldPrefixField, settings.FIELD_NAME_PREFIX);
isModified |= isModified(myStaticFieldPrefixField, settings.STATIC_FIELD_NAME_PREFIX);
isModified |= isModified(myParameterPrefixField, settings.PARAMETER_NAME_PREFIX);
isModified |= isModified(myLocalVariablePrefixField, settings.LOCAL_VARIABLE_NAME_PREFIX);
isModified |= isModified(myFieldPrefixField, javaSettings.FIELD_NAME_PREFIX);
isModified |= isModified(myStaticFieldPrefixField, javaSettings.STATIC_FIELD_NAME_PREFIX);
isModified |= isModified(myParameterPrefixField, javaSettings.PARAMETER_NAME_PREFIX);
isModified |= isModified(myLocalVariablePrefixField, javaSettings.LOCAL_VARIABLE_NAME_PREFIX);
isModified |= isModified(myFieldSuffixField, settings.FIELD_NAME_SUFFIX);
isModified |= isModified(myStaticFieldSuffixField, settings.STATIC_FIELD_NAME_SUFFIX);
isModified |= isModified(myParameterSuffixField, settings.PARAMETER_NAME_SUFFIX);
isModified |= isModified(myLocalVariableSuffixField, settings.LOCAL_VARIABLE_NAME_SUFFIX);
isModified |= isModified(myFieldSuffixField, javaSettings.FIELD_NAME_SUFFIX);
isModified |= isModified(myStaticFieldSuffixField, javaSettings.STATIC_FIELD_NAME_SUFFIX);
isModified |= isModified(myParameterSuffixField, javaSettings.PARAMETER_NAME_SUFFIX);
isModified |= isModified(myLocalVariableSuffixField, javaSettings.LOCAL_VARIABLE_NAME_SUFFIX);
isModified |= isModified(myCbGenerateFinalLocals, settings.GENERATE_FINAL_LOCALS);
isModified |= isModified(myCbGenerateFinalParameters, settings.GENERATE_FINAL_PARAMETERS);
isModified |= isModified(myCbGenerateFinalLocals, javaSettings.GENERATE_FINAL_LOCALS);
isModified |= isModified(myCbGenerateFinalParameters, javaSettings.GENERATE_FINAL_PARAMETERS);
isModified |= isModified(myCbUseExternalAnnotations, settings.USE_EXTERNAL_ANNOTATIONS);
isModified |= isModified(myInsertOverrideAnnotationCheckBox, settings.INSERT_OVERRIDE_ANNOTATION);
isModified |= isModified(myRepeatSynchronizedCheckBox, settings.REPEAT_SYNCHRONIZED);
isModified |= isModified(myCbUseExternalAnnotations, javaSettings.USE_EXTERNAL_ANNOTATIONS);
isModified |= isModified(myInsertOverrideAnnotationCheckBox, javaSettings.INSERT_OVERRIDE_ANNOTATION);
isModified |= isModified(myRepeatSynchronizedCheckBox, javaSettings.REPEAT_SYNCHRONIZED);
isModified |= isModified(myReplaceCastCb, settings.REPLACE_CAST);
isModified |= isModified(myReplaceInstanceOfCb, settings.REPLACE_INSTANCEOF);
isModified |= isModified(myReplaceNullCheckCb, settings.REPLACE_NULL_CHECK);
isModified |= isModified(myReplaceCastCb, javaSettings.REPLACE_CAST);
isModified |= isModified(myReplaceInstanceOfCb, javaSettings.REPLACE_INSTANCEOF);
isModified |= isModified(myReplaceNullCheckCb, javaSettings.REPLACE_NULL_CHECK);
isModified |= !settings.VISIBILITY.equals(myJavaVisibilityPanel.getVisibility());
isModified |= !javaSettings.VISIBILITY.equals(myJavaVisibilityPanel.getVisibility());
isModified |= myCommenterForm.isModified(settings);
isModified |= !myRepeatAnnotationsModel.getItems().equals(settings.getRepeatAnnotations());
isModified |= !myRepeatAnnotationsModel.getItems().equals(javaSettings.getRepeatAnnotations());
return isModified;
}
@@ -16,7 +16,9 @@
package com.intellij.application.options;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.ui.OptionGroup;
import org.jetbrains.annotations.NotNull;
class JavaCodeStyleImportsPanel extends CodeStyleImportsPanelBase {
private FullyQualifiedNamesInJavadocOptionProvider myFqnInJavadocOption;
@@ -29,19 +31,23 @@ class JavaCodeStyleImportsPanel extends CodeStyleImportsPanelBase {
@Override
public void apply(CodeStyleSettings settings) {
applyLayoutSettings(settings);
applyLayoutSettings(getJavaSettings(settings));
myFqnInJavadocOption.apply(settings);
}
@Override
public void reset(CodeStyleSettings settings) {
resetLayoutSettings(settings);
resetLayoutSettings(getJavaSettings(settings));
myFqnInJavadocOption.reset(settings);
}
@Override
public boolean isModified(CodeStyleSettings settings) {
return isModifiedLayoutSettings(settings) || myFqnInJavadocOption.isModified(settings);
return isModifiedLayoutSettings(getJavaSettings(settings)) || myFqnInJavadocOption.isModified(settings);
}
private static JavaCodeStyleSettings getJavaSettings(@NotNull CodeStyleSettings settings) {
return settings.getCustomSettings(JavaCodeStyleSettings.class);
}
}
@@ -22,6 +22,7 @@ import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.ui.OnePixelDivider;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider;
import com.intellij.ui.border.CustomLineBorder;
import org.jetbrains.annotations.NotNull;
@@ -152,17 +153,18 @@ public class JavaDocFormattingPanel extends OptionTreeWithPreviewPanel {
public void apply(CodeStyleSettings settings) {
super.apply(settings);
settings.ENABLE_JAVADOC_FORMATTING = myEnableCheckBox.isSelected();
settings.getCustomSettings(JavaCodeStyleSettings.class).ENABLE_JAVADOC_FORMATTING = myEnableCheckBox.isSelected();
}
protected void resetImpl(final CodeStyleSettings settings) {
super.resetImpl(settings);
myEnableCheckBox.setSelected(settings.ENABLE_JAVADOC_FORMATTING);
myEnableCheckBox.setSelected(settings.getCustomSettings(JavaCodeStyleSettings.class).ENABLE_JAVADOC_FORMATTING);
update();
}
public boolean isModified(CodeStyleSettings settings) {
return super.isModified(settings) || myEnableCheckBox.isSelected() != settings.ENABLE_JAVADOC_FORMATTING;
return super.isModified(settings) ||
myEnableCheckBox.isSelected() != settings.getCustomSettings(JavaCodeStyleSettings.class).ENABLE_JAVADOC_FORMATTING;
}
@NotNull
@@ -62,6 +62,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.*;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.xml.XmlDocument;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
@@ -488,7 +489,7 @@ public class ExternalAnnotationsManagerImpl extends ReadableExternalAnnotationsM
//choose external place iff USE_EXTERNAL_ANNOTATIONS option is on,
//otherwise external annotations should be read-only
if (CodeStyleSettingsManager.getSettings(project).USE_EXTERNAL_ANNOTATIONS) {
if (CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class).USE_EXTERNAL_ANNOTATIONS) {
final PsiFile containingFile = element.getContainingFile();
final VirtualFile virtualFile = containingFile.getVirtualFile();
LOG.assertTrue(virtualFile != null);
@@ -760,7 +761,7 @@ public class ExternalAnnotationsManagerImpl extends ReadableExternalAnnotationsM
public static boolean areExternalAnnotationsApplicable(@NotNull PsiModifierListOwner owner) {
if (!owner.isPhysical()) return false;
if (!owner.getManager().isInProject(owner)) return true;
return CodeStyleSettingsManager.getSettings(owner.getProject()).USE_EXTERNAL_ANNOTATIONS;
return CodeStyleSettingsManager.getSettings(owner.getProject()).getCustomSettings(JavaCodeStyleSettings.class).USE_EXTERNAL_ANNOTATIONS;
}
private static class MyExternalPromptDialog extends OptionsMessageDialog {
@@ -809,12 +810,12 @@ public class ExternalAnnotationsManagerImpl extends ReadableExternalAnnotationsM
@Override
protected boolean isToBeShown() {
return CodeStyleSettingsManager.getSettings(myProject).USE_EXTERNAL_ANNOTATIONS;
return CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class).USE_EXTERNAL_ANNOTATIONS;
}
@Override
protected void setToBeShown(boolean value, boolean onOk) {
CodeStyleSettingsManager.getSettings(myProject).USE_EXTERNAL_ANNOTATIONS = value;
CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class).USE_EXTERNAL_ANNOTATIONS = value;
}
@Override
@@ -25,6 +25,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiModifierListOwner;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.util.IncorrectOperationException;
@@ -49,7 +50,7 @@ public class MakeAnnotationExternal extends BaseIntentionAction {
PsiModifierListOwner modifierListOwner = PsiTreeUtil.getParentOfType(annotation, PsiModifierListOwner.class);
if (modifierListOwner != null) {
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(modifierListOwner);
if (CodeStyleSettingsManager.getSettings(project).USE_EXTERNAL_ANNOTATIONS ||
if (CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class).USE_EXTERNAL_ANNOTATIONS ||
virtualFile != null && ExternalAnnotationsManager.getInstance(project).hasAnnotationRootsForFile(virtualFile)) {
setText("Annotate externally");
return true;
@@ -246,7 +246,7 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction {
types.putValue(param.getType(), param);
}
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project);
final JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class);
final boolean preferLongerNames = settings.PREFER_LONGER_NAMES;
for (PsiVariable param : params) {
final PsiType paramType = param.getType();
@@ -296,7 +296,9 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction {
if (isUnique(parameters, newName, usedNames)) {
break;
}
newName = n < nameInfo.names.length && !CodeStyleSettingsManager.getSettings(variable.getProject()).PREFER_LONGER_NAMES
newName = n < nameInfo.names.length &&
!CodeStyleSettingsManager.getSettings(
variable.getProject()).getCustomSettings(JavaCodeStyleSettings.class).PREFER_LONGER_NAMES
? nameInfo.names[n++] : nameInfo.names[0] + n++;
}
return newName;
@@ -37,6 +37,7 @@ import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.PsiUtilCore;
@@ -188,7 +189,7 @@ public abstract class CreateFromUsageBaseFix extends BaseIntentionAction {
if (parentClass != null && (parentClass.equals(targetClass) || PsiTreeUtil.isAncestor(targetClass, parentClass, true))) {
return PsiModifier.PRIVATE;
} else {
return CodeStyleSettingsManager.getSettings(targetClass.getProject()).VISIBILITY;
return CodeStyleSettingsManager.getSettings(targetClass.getProject()).getCustomSettings(JavaCodeStyleSettings.class).VISIBILITY;
}
}
@@ -29,6 +29,7 @@ import com.intellij.openapi.util.TextRange;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.refactoring.introduceParameter.AbstractJavaInplaceIntroducer;
@@ -117,7 +118,8 @@ public class CreateLocalFromUsageFix extends CreateVarFromUsageFix {
PsiVariable var = (PsiVariable)decl.getDeclaredElements()[0];
boolean isFinal =
CodeStyleSettingsManager.getSettings(project).GENERATE_FINAL_LOCALS && !CreateFromUsageUtils.isAccessedForWriting(expressions);
CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS &&
!CreateFromUsageUtils.isAccessedForWriting(expressions);
PsiUtil.setModifierProperty(var, PsiModifier.FINAL, isFinal);
var = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(var);
@@ -19,10 +19,7 @@ import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.codeStyle.*;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
@@ -101,7 +98,7 @@ public class ReplaceIteratorForEachLoopWithIteratorForLoopFix implements Intenti
newItemVariable.getTypeElement().replace(newItemTypeElement);
newItemVariable.setName(iterationParameterName);
final CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(project);
if (codeStyleSettings.GENERATE_FINAL_LOCALS) {
if (codeStyleSettings.getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS) {
final PsiModifierList modifierList = newItemVariable.getModifierList();
if (modifierList != null) modifierList.setModifierProperty(PsiModifier.FINAL, true);
}
@@ -29,6 +29,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.controlFlow.ControlFlowUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
@@ -209,7 +210,7 @@ public class VariableAccessFromInnerClassFix implements IntentionAction {
PsiDeclarationStatement copyDecl = factory.createVariableDeclarationStatement(newName, type, initializer);
PsiVariable newVariable = (PsiVariable)copyDecl.getDeclaredElements()[0];
final boolean mustBeFinal =
!PsiUtil.isLanguageLevel8OrHigher(context) || CodeStyleSettingsManager.getSettings(project).GENERATE_FINAL_LOCALS;
!PsiUtil.isLanguageLevel8OrHigher(context) || CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS;
PsiUtil.setModifierProperty(newVariable, PsiModifier.FINAL, mustBeFinal);
PsiElement statement = getStatementToInsertBefore(variable, context);
if (statement == null) return;
@@ -93,7 +93,7 @@ public class GenerateEqualsHelper implements Runnable {
}
private static boolean shouldAddOverrideAnnotation(PsiElement context) {
CodeStyleSettings style = CodeStyleSettingsManager.getSettings(context.getProject());
JavaCodeStyleSettings style = CodeStyleSettingsManager.getSettings(context.getProject()).getCustomSettings(JavaCodeStyleSettings.class);
return style.INSERT_OVERRIDE_ANNOTATION && PsiUtil.isLanguageLevel5OrHigher(context);
}
@@ -169,7 +169,7 @@ public class GenerateEqualsHelper implements Runnable {
private PsiMethod createEquals() throws IncorrectOperationException {
@NonNls StringBuilder buffer = new StringBuilder();
CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(myProject);
JavaCodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class);
ArrayList<PsiField> equalsFields = new ArrayList<>();
ContainerUtil.addAll(equalsFields, myEqualsFields);
Collections.sort(equalsFields, EqualsFieldsComparator.INSTANCE);
@@ -224,7 +224,8 @@ public class GenerateMembersUtil {
if (member instanceof PsiMethod) {
if (!aClass.isInterface()) {
final PsiParameter[] parameters = ((PsiMethod)member).getParameterList().getParameters();
final boolean generateFinals = CodeStyleSettingsManager.getSettings(aClass.getProject()).GENERATE_FINAL_PARAMETERS;
final boolean generateFinals = CodeStyleSettingsManager.getSettings(aClass.getProject())
.getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS;
for (final PsiParameter parameter : parameters) {
PsiUtil.setModifierProperty(parameter, PsiModifier.FINAL, generateFinals);
}
@@ -710,7 +711,7 @@ public class GenerateMembersUtil {
public static PsiMethod setVisibility(PsiMember member, PsiMethod prototype) {
if (prototype == null) return null;
String visibility = CodeStyleSettingsManager.getSettings(member.getProject()).VISIBILITY;
String visibility = CodeStyleSettingsManager.getSettings(member.getProject()).getCustomSettings(JavaCodeStyleSettings.class).VISIBILITY;
@PsiModifier.ModifierConstant String newVisibility;
if (VisibilityUtil.ESCALATE_VISIBILITY.equals(visibility)) {
@@ -730,7 +731,7 @@ public class GenerateMembersUtil {
public static PsiMethod annotateOnOverrideImplement(@Nullable PsiClass targetClass, @Nullable PsiMethod generated) {
if (generated == null || targetClass == null) return generated;
if (CodeStyleSettingsManager.getSettings(targetClass.getProject()).INSERT_OVERRIDE_ANNOTATION) {
if (CodeStyleSettingsManager.getSettings(targetClass.getProject()).getCustomSettings(JavaCodeStyleSettings.class).INSERT_OVERRIDE_ANNOTATION) {
PsiMethod superMethod = targetClass.findMethodBySignature(generated, true);
if (superMethod != null && superMethod.getContainingClass() != targetClass) {
OverrideImplementUtil.annotateOnOverrideImplement(generated, targetClass, superMethod, true);
@@ -51,10 +51,7 @@ import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.codeStyle.*;
import com.intellij.psi.infos.CandidateInfo;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.util.*;
@@ -96,11 +93,12 @@ public class OverrideImplementUtil extends OverrideImplementExploreUtil {
? TypeConversionUtil.getSuperClassSubstitutor(containingClass, aClass, PsiSubstitutor.EMPTY)
: PsiSubstitutor.EMPTY;
return overrideOrImplementMethod(aClass, method, substitutor, toCopyJavaDoc,
CodeStyleSettingsManager.getSettings(aClass.getProject()).INSERT_OVERRIDE_ANNOTATION);
CodeStyleSettingsManager.getSettings(aClass.getProject())
.getCustomSettings(JavaCodeStyleSettings.class).INSERT_OVERRIDE_ANNOTATION);
}
public static boolean isInsertOverride(PsiMethod superMethod, PsiClass targetClass) {
if (!CodeStyleSettingsManager.getSettings(targetClass.getProject()).INSERT_OVERRIDE_ANNOTATION) {
if (!CodeStyleSettingsManager.getSettings(targetClass.getProject()).getCustomSettings(JavaCodeStyleSettings.class).INSERT_OVERRIDE_ANNOTATION) {
return false;
}
return canInsertOverride(superMethod, targetClass);
@@ -199,7 +197,8 @@ public class OverrideImplementUtil extends OverrideImplementExploreUtil {
annotateOnOverrideImplement(result, aClass, method, insertOverrideIfPossible);
if (CodeStyleSettingsManager.getSettings(aClass.getProject()).REPEAT_SYNCHRONIZED && method.hasModifierProperty(PsiModifier.SYNCHRONIZED)) {
if (CodeStyleSettingsManager.getSettings(aClass.getProject()).getCustomSettings(JavaCodeStyleSettings.class).REPEAT_SYNCHRONIZED &&
method.hasModifierProperty(PsiModifier.SYNCHRONIZED)) {
result.getModifierList().setModifierProperty(PsiModifier.SYNCHRONIZED, true);
}
@@ -235,7 +234,8 @@ public class OverrideImplementUtil extends OverrideImplementExploreUtil {
public static void annotateOnOverrideImplement(PsiMethod method, PsiClass targetClass, PsiMethod overridden) {
annotateOnOverrideImplement(method, targetClass, overridden,
CodeStyleSettingsManager.getSettings(method.getProject()).INSERT_OVERRIDE_ANNOTATION);
CodeStyleSettingsManager.getSettings(method.getProject())
.getCustomSettings(JavaCodeStyleSettings.class).INSERT_OVERRIDE_ANNOTATION);
}
public static void annotateOnOverrideImplement(PsiMethod method, PsiClass targetClass, PsiMethod overridden, boolean insertOverride) {
@@ -618,13 +618,15 @@ public class OverrideImplementUtil extends OverrideImplementExploreUtil {
}
public static void overrideOrImplementMethodsInRightPlace(Editor editor1, PsiClass aClass, Collection<PsiMethodMember> members, boolean copyJavadoc) {
boolean insert = CodeStyleSettingsManager.getSettings(aClass.getProject()).INSERT_OVERRIDE_ANNOTATION;
boolean insert =
CodeStyleSettingsManager.getSettings(aClass.getProject()).getCustomSettings(JavaCodeStyleSettings.class).INSERT_OVERRIDE_ANNOTATION;
overrideOrImplementMethodsInRightPlace(editor1, aClass, members, copyJavadoc, insert);
}
public static List<PsiMethod> overrideOrImplementMethodCandidates(PsiClass aClass, Collection<CandidateInfo> candidatesToImplement,
boolean copyJavadoc) throws IncorrectOperationException {
boolean insert = CodeStyleSettingsManager.getSettings(aClass.getProject()).INSERT_OVERRIDE_ANNOTATION;
boolean insert =
CodeStyleSettingsManager.getSettings(aClass.getProject()).getCustomSettings(JavaCodeStyleSettings.class).INSERT_OVERRIDE_ANNOTATION;
return overrideOrImplementMethodCandidates(aClass, candidatesToImplement, copyJavadoc, insert);
}
}
@@ -21,6 +21,7 @@ import com.intellij.codeInsight.NullableNotNullManager;
import com.intellij.openapi.project.Project;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.util.ArrayUtil;
import java.util.ArrayList;
@@ -38,7 +39,7 @@ public class OverrideImplementsAnnotationsHandlerImpl implements OverrideImpleme
annotations.add(AnnotationUtil.NLS);
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project);
annotations.addAll(settings.getRepeatAnnotations());
annotations.addAll(settings.getCustomSettings(JavaCodeStyleSettings.class).getRepeatAnnotations());
return ArrayUtil.toStringArray(annotations);
}
@@ -166,7 +166,7 @@ public class BindFieldsFromParametersAction extends BaseIntentionAction implemen
for (PsiParameter parameter : parameters) {
types.putValue(parameter.getType(), parameter);
}
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project);
final JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class);
final boolean preferLongerNames = settings.PREFER_LONGER_NAMES;
for (PsiParameter selected : parameters) {
try {
@@ -220,7 +220,8 @@ public class JavaLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSett
public DocCommentSettings getDocCommentSettings(@NotNull PsiFile file) {
if (file.isValid()) {
return new DocCommentSettings() {
private final CodeStyleSettings mySettings = CodeStyleSettingsManager.getSettings(file.getProject());
private final JavaCodeStyleSettings mySettings =
CodeStyleSettingsManager.getSettings(file.getProject()).getCustomSettings(JavaCodeStyleSettings.class);
@Override
public boolean isDocFormattingEnabled() {
@@ -2,7 +2,6 @@ package com.intellij.javadoc;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.editorActions.enter.EnterHandlerDelegateAdapter;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.CaretModel;
@@ -15,6 +14,7 @@ import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiJavaFile;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.util.text.CharArrayUtil;
import org.jetbrains.annotations.NotNull;
@@ -32,7 +32,7 @@ public class EnterInJavadocParamDescriptionHandler extends EnterHandlerDelegateA
public Result postProcessEnter(@NotNull final PsiFile file, @NotNull Editor editor, @NotNull DataContext dataContext) {
if (!(file instanceof PsiJavaFile)
|| !CodeInsightSettings.getInstance().SMART_INDENT_ON_ENTER
|| !CodeStyleSettingsManager.getSettings(file.getProject()).JD_ALIGN_PARAM_COMMENTS) {
|| !CodeStyleSettingsManager.getSettings(file.getProject()).getCustomSettings(JavaCodeStyleSettings.class).JD_ALIGN_PARAM_COMMENTS) {
return Result.Continue;
}
final CaretModel caretModel = editor.getCaretModel();
@@ -27,6 +27,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.javadoc.PsiDocTag;
import com.intellij.psi.javadoc.PsiDocTagValue;
import com.intellij.psi.javadoc.PsiDocToken;
@@ -108,7 +109,7 @@ public class JavadocHelper {
final CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getInstance(psiFile.getProject()).getCurrentSettings();
int column;
if (codeStyleSettings.JD_ALIGN_PARAM_COMMENTS) {
if (codeStyleSettings.getCustomSettings(JavaCodeStyleSettings.class).JD_ALIGN_PARAM_COMMENTS) {
column = Math.max(descriptionStartColumn, parameterNameEndColumn);
if (column <= parameterNameEndColumn) {
column = parameterNameEndColumn + 1;
@@ -428,13 +428,13 @@ public class JavaDocumentationProvider extends DocumentationProviderEx implement
createTypeParamsListComment(builder, project, commenter, typeParameterList);
}
if (psiMethod.getReturnType() != null && !PsiType.VOID.equals(psiMethod.getReturnType())) {
builder.append(CodeDocumentationUtil.createDocCommentLine(RETURN_TAG, project, commenter));
builder.append(CodeDocumentationUtil.createDocCommentLine(RETURN_TAG, _comment.getContainingFile(), commenter));
builder.append(LINE_SEPARATOR);
}
final PsiJavaCodeReferenceElement[] references = psiMethod.getThrowsList().getReferenceElements();
for (PsiJavaCodeReferenceElement reference : references) {
builder.append(CodeDocumentationUtil.createDocCommentLine(THROWS_TAG, project, commenter));
builder.append(CodeDocumentationUtil.createDocCommentLine(THROWS_TAG, _comment.getContainingFile(), commenter));
builder.append(reference.getText());
builder.append(LINE_SEPARATOR);
}
@@ -481,12 +481,12 @@ public class JavaDocumentationProvider extends DocumentationProviderEx implement
for (PsiParameter parameter : parameters) {
String description = param2Description.get(parameter.getName());
if (description != null) {
builder.append(CodeDocumentationUtil.createDocCommentLine("", project, commenter));
builder.append(CodeDocumentationUtil.createDocCommentLine("", psiMethod.getContainingFile(), commenter));
if (description.indexOf('\n') > -1) description = description.substring(0, description.lastIndexOf('\n'));
builder.append(description);
}
else {
builder.append(CodeDocumentationUtil.createDocCommentLine(PARAM_TAG, project, commenter));
builder.append(CodeDocumentationUtil.createDocCommentLine(PARAM_TAG, psiMethod.getContainingFile(), commenter));
builder.append(parameter.getName());
}
builder.append(LINE_SEPARATOR);
@@ -499,7 +499,7 @@ public class JavaDocumentationProvider extends DocumentationProviderEx implement
final PsiTypeParameterList typeParameterList) {
final PsiTypeParameter[] typeParameters = typeParameterList.getTypeParameters();
for (PsiTypeParameter typeParameter : typeParameters) {
buffer.append(CodeDocumentationUtil.createDocCommentLine(PARAM_TAG, project, commenter));
buffer.append(CodeDocumentationUtil.createDocCommentLine(PARAM_TAG, typeParameterList.getContainingFile(), commenter));
buffer.append("<").append(typeParameter.getName()).append(">");
buffer.append(LINE_SEPARATOR);
}
@@ -15,11 +15,65 @@
*/
package com.intellij.psi.codeStyle;
public class JavaCodeStyleSettings extends CustomCodeStyleSettings {
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class JavaCodeStyleSettings extends CustomCodeStyleSettings implements ImportsLayoutSettings {
@NonNls private static final String REPEAT_ANNOTATIONS = "REPEAT_ANNOTATIONS";
public JavaCodeStyleSettings(CodeStyleSettings container) {
super("JavaCodeStyleSettings", container);
initTypeToName();
initImportsByDefault();
}
public String FIELD_NAME_PREFIX = "";
public String STATIC_FIELD_NAME_PREFIX = "";
public String PARAMETER_NAME_PREFIX = "";
public String LOCAL_VARIABLE_NAME_PREFIX = "";
public String FIELD_NAME_SUFFIX = "";
public String STATIC_FIELD_NAME_SUFFIX = "";
public String PARAMETER_NAME_SUFFIX = "";
public String LOCAL_VARIABLE_NAME_SUFFIX = "";
public boolean PREFER_LONGER_NAMES = true;
public boolean GENERATE_FINAL_LOCALS;
public boolean GENERATE_FINAL_PARAMETERS;
public String VISIBILITY = "public";
public final CodeStyleSettings.TypeToNameMap FIELD_TYPE_TO_NAME = new CodeStyleSettings.TypeToNameMap();
public final CodeStyleSettings.TypeToNameMap STATIC_FIELD_TYPE_TO_NAME = new CodeStyleSettings.TypeToNameMap();
@NonNls public final CodeStyleSettings.TypeToNameMap PARAMETER_TYPE_TO_NAME = new CodeStyleSettings.TypeToNameMap();
public final CodeStyleSettings.TypeToNameMap LOCAL_VARIABLE_TYPE_TO_NAME = new CodeStyleSettings.TypeToNameMap();
public boolean USE_EXTERNAL_ANNOTATIONS;
public boolean INSERT_OVERRIDE_ANNOTATION = true;
public boolean REPEAT_SYNCHRONIZED = true;
private List<String> myRepeatAnnotations = new ArrayList<>();
public List<String> getRepeatAnnotations() {
return myRepeatAnnotations;
}
public void setRepeatAnnotations(List<String> repeatAnnotations) {
myRepeatAnnotations.clear();
myRepeatAnnotations.addAll(repeatAnnotations);
}
public boolean REPLACE_INSTANCEOF = false;
public boolean REPLACE_CAST = false;
public boolean REPLACE_NULL_CHECK = true;
public boolean SPACES_WITHIN_ANGLE_BRACKETS;
@@ -46,14 +100,251 @@ public class JavaCodeStyleSettings extends CustomCodeStyleSettings {
public boolean useFqNamesInJavadocAlways() {
return CLASS_NAMES_IN_JAVADOC == FULLY_QUALIFY_NAMES_ALWAYS;
}
// Imports
public boolean LAYOUT_STATIC_IMPORTS_SEPARATELY = true;
public boolean USE_FQ_CLASS_NAMES;
public boolean USE_SINGLE_CLASS_IMPORTS = true;
public boolean INSERT_INNER_CLASS_IMPORTS;
public int CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 5;
public int NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND = 3;
public final PackageEntryTable PACKAGES_TO_USE_IMPORT_ON_DEMAND = new PackageEntryTable();
public final PackageEntryTable IMPORT_LAYOUT_TABLE = new PackageEntryTable();
// region JavaDoc
public boolean ENABLE_JAVADOC_FORMATTING = true;
public boolean JD_ALIGN_PARAM_COMMENTS = true;
public boolean JD_ALIGN_EXCEPTION_COMMENTS = true;
public boolean JD_ADD_BLANK_AFTER_PARM_COMMENTS;
public boolean JD_ADD_BLANK_AFTER_RETURN;
public boolean JD_ADD_BLANK_AFTER_DESCRIPTION = true;
public boolean JD_P_AT_EMPTY_LINES = true;
public boolean JD_KEEP_INVALID_TAGS = true;
public boolean JD_KEEP_EMPTY_LINES = true;
public boolean JD_DO_NOT_WRAP_ONE_LINE_COMMENTS;
public boolean JD_USE_THROWS_NOT_EXCEPTION = true;
public boolean JD_KEEP_EMPTY_PARAMETER = true;
public boolean JD_KEEP_EMPTY_EXCEPTION = true;
public boolean JD_KEEP_EMPTY_RETURN = true;
public boolean JD_LEADING_ASTERISKS_ARE_ENABLED = true;
public boolean JD_PRESERVE_LINE_FEEDS;
public boolean JD_PARAM_DESCRIPTION_ON_NEW_LINE;
public boolean JD_INDENT_ON_CONTINUATION = false;
// endregion
@Override
protected void importLegacySettings() {
CodeStyleSettings settings = getContainer();
boolean isDefaultValue = settings.USE_FQ_CLASS_NAMES_IN_JAVADOC;
if (!isDefaultValue) {
CLASS_NAMES_IN_JAVADOC = SHORTEN_NAMES_ALWAYS_AND_ADD_IMPORT;
settings.USE_FQ_CLASS_NAMES_IN_JAVADOC = true;
public boolean isLayoutStaticImportsSeparately() {
return LAYOUT_STATIC_IMPORTS_SEPARATELY;
}
@Override
public void setLayoutStaticImportsSeparately(boolean value) {
LAYOUT_STATIC_IMPORTS_SEPARATELY = value;
}
@Override
public int getNamesCountToUseImportOnDemand() {
return NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND;
}
@Override
public void setNamesCountToUseImportOnDemand(int value) {
NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND = value;
}
@Override
public int getClassCountToUseImportOnDemand() {
return CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND;
}
@Override
public void setClassCountToUseImportOnDemand(int value) {
CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = value;
}
@Override
public boolean isInsertInnerClassImports() {
return INSERT_INNER_CLASS_IMPORTS;
}
@Override
public void setInsertInnerClassImports(boolean value) {
INSERT_INNER_CLASS_IMPORTS = value;
}
@Override
public boolean isUseSingleClassImports() {
return USE_SINGLE_CLASS_IMPORTS;
}
@Override
public void setUseSingleClassImports(boolean value) {
USE_SINGLE_CLASS_IMPORTS = value;
}
@Override
public boolean isUseFqClassNames() {
return USE_FQ_CLASS_NAMES;
}
@Override
public void setUseFqClassNames(boolean value) {
USE_FQ_CLASS_NAMES = value;
}
@Override
public PackageEntryTable getImportLayoutTable() {
return IMPORT_LAYOUT_TABLE;
}
@Override
public PackageEntryTable getPackagesToUseImportOnDemand() {
return PACKAGES_TO_USE_IMPORT_ON_DEMAND;
}
private void initImportsByDefault() {
PACKAGES_TO_USE_IMPORT_ON_DEMAND.addEntry(new PackageEntry(false, "java.awt", false));
PACKAGES_TO_USE_IMPORT_ON_DEMAND.addEntry(new PackageEntry(false,"javax.swing", false));
IMPORT_LAYOUT_TABLE.addEntry(PackageEntry.ALL_OTHER_IMPORTS_ENTRY);
IMPORT_LAYOUT_TABLE.addEntry(PackageEntry.BLANK_LINE_ENTRY);
IMPORT_LAYOUT_TABLE.addEntry(new PackageEntry(false, "javax", true));
IMPORT_LAYOUT_TABLE.addEntry(new PackageEntry(false, "java", true));
IMPORT_LAYOUT_TABLE.addEntry(PackageEntry.BLANK_LINE_ENTRY);
IMPORT_LAYOUT_TABLE.addEntry(PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY);
}
@SuppressWarnings("unused") // Used in objectEquals.vm
public boolean isGenerateFinalLocals() {
return GENERATE_FINAL_LOCALS;
}
@SuppressWarnings("unused") // Used in objectEquals.vm
public boolean isGenerateFinalParameters() {
return GENERATE_FINAL_PARAMETERS;
}
@SuppressWarnings("Duplicates")
private static void initGeneralLocalVariable(@NonNls CodeStyleSettings.TypeToNameMap map) {
map.addPair("int", "i");
map.addPair("byte", "b");
map.addPair("char", "c");
map.addPair("long", "l");
map.addPair("short", "i");
map.addPair("boolean", "b");
map.addPair("double", "v");
map.addPair("float", "v");
map.addPair("java.lang.Object", "o");
map.addPair("java.lang.String", "s");
}
private void initTypeToName() {
initGeneralLocalVariable(PARAMETER_TYPE_TO_NAME);
initGeneralLocalVariable(LOCAL_VARIABLE_TYPE_TO_NAME);
PARAMETER_TYPE_TO_NAME.addPair("*Exception", "e");
}
@SuppressWarnings("deprecation")
@Override
protected void importLegacySettings(@NotNull CodeStyleSettings rootSettings) {
USE_EXTERNAL_ANNOTATIONS = rootSettings.USE_EXTERNAL_ANNOTATIONS;
INSERT_OVERRIDE_ANNOTATION = rootSettings.INSERT_OVERRIDE_ANNOTATION;
REPEAT_SYNCHRONIZED = rootSettings.REPEAT_SYNCHRONIZED;
setRepeatAnnotations(rootSettings.getRepeatAnnotations());
LAYOUT_STATIC_IMPORTS_SEPARATELY = rootSettings.LAYOUT_STATIC_IMPORTS_SEPARATELY;
USE_FQ_CLASS_NAMES = rootSettings.USE_FQ_CLASS_NAMES;
USE_SINGLE_CLASS_IMPORTS = rootSettings.USE_SINGLE_CLASS_IMPORTS;
INSERT_INNER_CLASS_IMPORTS = rootSettings.INSERT_INNER_CLASS_IMPORTS;
CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = rootSettings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND;
NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND = rootSettings.NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND;
PACKAGES_TO_USE_IMPORT_ON_DEMAND.copyFrom(rootSettings.PACKAGES_TO_USE_IMPORT_ON_DEMAND);
IMPORT_LAYOUT_TABLE.copyFrom(rootSettings.IMPORT_LAYOUT_TABLE);
REPLACE_INSTANCEOF = rootSettings.REPLACE_INSTANCEOF;
REPLACE_CAST = rootSettings.REPLACE_CAST;
REPLACE_NULL_CHECK = rootSettings.REPLACE_NULL_CHECK;
FIELD_NAME_PREFIX = rootSettings.FIELD_NAME_PREFIX;
STATIC_FIELD_NAME_PREFIX = rootSettings.STATIC_FIELD_NAME_PREFIX;
PARAMETER_NAME_PREFIX = rootSettings.PARAMETER_NAME_PREFIX;
LOCAL_VARIABLE_NAME_PREFIX = rootSettings.LOCAL_VARIABLE_NAME_PREFIX;
FIELD_NAME_SUFFIX = rootSettings.FIELD_NAME_SUFFIX;
STATIC_FIELD_NAME_SUFFIX = rootSettings.STATIC_FIELD_NAME_SUFFIX;
PARAMETER_NAME_SUFFIX = rootSettings.PARAMETER_NAME_SUFFIX;
LOCAL_VARIABLE_NAME_SUFFIX = rootSettings.LOCAL_VARIABLE_NAME_SUFFIX;
PREFER_LONGER_NAMES = rootSettings.PREFER_LONGER_NAMES;
GENERATE_FINAL_LOCALS = rootSettings.GENERATE_FINAL_LOCALS;
GENERATE_FINAL_PARAMETERS = rootSettings.GENERATE_FINAL_PARAMETERS;
VISIBILITY = rootSettings.VISIBILITY;
FIELD_TYPE_TO_NAME.copyFrom(rootSettings.FIELD_TYPE_TO_NAME);
LOCAL_VARIABLE_TYPE_TO_NAME.copyFrom(rootSettings.LOCAL_VARIABLE_TYPE_TO_NAME);
PARAMETER_TYPE_TO_NAME.copyFrom(rootSettings.PARAMETER_TYPE_TO_NAME);
STATIC_FIELD_TYPE_TO_NAME.copyFrom(rootSettings.STATIC_FIELD_TYPE_TO_NAME);
ENABLE_JAVADOC_FORMATTING = rootSettings.ENABLE_JAVADOC_FORMATTING;
JD_ALIGN_PARAM_COMMENTS = rootSettings.JD_ALIGN_PARAM_COMMENTS;
JD_ALIGN_EXCEPTION_COMMENTS = rootSettings.JD_ALIGN_EXCEPTION_COMMENTS;
JD_ADD_BLANK_AFTER_PARM_COMMENTS = rootSettings.JD_ADD_BLANK_AFTER_PARM_COMMENTS;
JD_ADD_BLANK_AFTER_RETURN = rootSettings.JD_ADD_BLANK_AFTER_RETURN;
JD_ADD_BLANK_AFTER_DESCRIPTION = rootSettings.JD_ADD_BLANK_AFTER_DESCRIPTION;
JD_P_AT_EMPTY_LINES = rootSettings.JD_P_AT_EMPTY_LINES;
JD_KEEP_INVALID_TAGS = rootSettings.JD_KEEP_INVALID_TAGS;
JD_KEEP_EMPTY_LINES = rootSettings.JD_KEEP_EMPTY_LINES;
JD_DO_NOT_WRAP_ONE_LINE_COMMENTS = rootSettings.JD_DO_NOT_WRAP_ONE_LINE_COMMENTS;
JD_USE_THROWS_NOT_EXCEPTION = rootSettings.JD_USE_THROWS_NOT_EXCEPTION;
JD_KEEP_EMPTY_PARAMETER = rootSettings.JD_KEEP_EMPTY_PARAMETER;
JD_KEEP_EMPTY_EXCEPTION = rootSettings.JD_KEEP_EMPTY_EXCEPTION;
JD_KEEP_EMPTY_RETURN = rootSettings.JD_KEEP_EMPTY_RETURN;
JD_LEADING_ASTERISKS_ARE_ENABLED = rootSettings.JD_LEADING_ASTERISKS_ARE_ENABLED;
JD_PRESERVE_LINE_FEEDS = rootSettings.JD_PRESERVE_LINE_FEEDS;
JD_PARAM_DESCRIPTION_ON_NEW_LINE = rootSettings.JD_PARAM_DESCRIPTION_ON_NEW_LINE;
JD_INDENT_ON_CONTINUATION = rootSettings.JD_INDENT_ON_CONTINUATION;
}
@Override
public void readExternal(Element parentElement) throws InvalidDataException {
super.readExternal(parentElement);
Element child = parentElement.getChild(getTagName());
if (child != null) {
myRepeatAnnotations.clear();
Element annotations = child.getChild(REPEAT_ANNOTATIONS);
if (annotations != null) {
for (Element anno : annotations.getChildren("ANNO")) {
myRepeatAnnotations.add(anno.getAttributeValue("name"));
}
}
}
}
@Override
public void writeExternal(Element parentElement, @NotNull CustomCodeStyleSettings parentSettings) throws WriteExternalException {
super.writeExternal(parentElement, parentSettings);
if (!myRepeatAnnotations.isEmpty()) {
Element child = parentElement.getChild(getTagName());
if (child == null) {
child = new Element(getTagName());
}
Element annos = new Element(REPEAT_ANNOTATIONS);
for (String annotation : myRepeatAnnotations) {
annos.addContent(new Element("ANNO").setAttribute("name", annotation));
}
child.addContent(annos);
}
}
public static JavaCodeStyleSettings getInstance(@NotNull Project project) {
return CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class);
}
}
@@ -29,17 +29,17 @@ public class JavaCodeStyleSettingsFacadeImpl extends JavaCodeStyleSettingsFacade
@Override
public int getNamesCountToUseImportOnDemand() {
return myManager.getCurrentSettings().NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND;
return myManager.getCurrentSettings().getCustomSettings(JavaCodeStyleSettings.class).NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND;
}
@Override
public boolean useFQClassNames() {
return myManager.getCurrentSettings().USE_FQ_CLASS_NAMES;
return myManager.getCurrentSettings().getCustomSettings(JavaCodeStyleSettings.class).USE_FQ_CLASS_NAMES;
}
@Override
public boolean isJavaDocLeadingAsterisksEnabled() {
return myManager.getCurrentSettings().JD_LEADING_ASTERISKS_ARE_ENABLED;
return myManager.getCurrentSettings().getCustomSettings(JavaCodeStyleSettings.class).JD_LEADING_ASTERISKS_ARE_ENABLED;
}
@Override
@@ -49,11 +49,11 @@ public class JavaCodeStyleSettingsFacadeImpl extends JavaCodeStyleSettingsFacade
@Override
public boolean isGenerateFinalParameters() {
return myManager.getCurrentSettings().GENERATE_FINAL_PARAMETERS;
return myManager.getCurrentSettings().getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS;
}
@Override
public boolean isGenerateFinalLocals() {
return myManager.getCurrentSettings().GENERATE_FINAL_LOCALS;
return myManager.getCurrentSettings().getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS;
}
}
@@ -25,6 +25,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.impl.source.SourceTreeToPsiMap;
import com.intellij.psi.impl.source.codeStyle.javadoc.CommentFormatter;
import com.intellij.psi.javadoc.PsiDocComment;
@@ -37,7 +38,7 @@ public class FormatCommentsProcessor implements PreFormatProcessor {
PsiElement e = SourceTreeToPsiMap.treeElementToPsi(element);
assert e != null;
final Project project = e.getProject();
if (!CodeStyleSettingsManager.getSettings(project).ENABLE_JAVADOC_FORMATTING ||
if (!CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class).ENABLE_JAVADOC_FORMATTING ||
element.getPsi().getContainingFile().getLanguage() != JavaLanguage.INSTANCE
|| InjectedLanguageManager.getInstance(project).isInjectedFragment(element.getPsi().getContainingFile()))
{
@@ -25,10 +25,7 @@ import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.PackageEntry;
import com.intellij.psi.codeStyle.PackageEntryTable;
import com.intellij.psi.codeStyle.*;
import com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl;
import com.intellij.psi.impl.source.SourceTreeToPsiMap;
import com.intellij.psi.impl.source.jsp.jspJava.JspxImportStatement;
@@ -65,11 +62,11 @@ import static java.util.stream.Collectors.toSet;
public class ImportHelper{
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.codeStyle.ImportHelper");
private final CodeStyleSettings mySettings;
private final JavaCodeStyleSettings mySettings;
@NonNls private static final String JAVA_LANG_PACKAGE = "java.lang";
public ImportHelper(@NotNull CodeStyleSettings settings){
mySettings = settings;
mySettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
}
@Nullable("null means no need to replace the import list because they are the same")
@@ -149,7 +146,7 @@ public class ImportHelper{
}
public static void collectOnDemandImports(@NotNull List<Pair<String, Boolean>> resultList,
@NotNull CodeStyleSettings settings,
@NotNull JavaCodeStyleSettings settings,
@NotNull Map<String, Boolean> outClassesOrPackagesToImportOnDemand) {
TObjectIntHashMap<String> packageToCountMap = new TObjectIntHashMap<>();
TObjectIntHashMap<String> classToCountMap = new TObjectIntHashMap<>();
@@ -189,7 +186,7 @@ public class ImportHelper{
packageToCountMap.forEachEntry(new MyVisitorProcedure(true));
}
public static List<Pair<String, Boolean>> sortItemsAccordingToSettings(List<Pair<String, Boolean>> names, final CodeStyleSettings settings) {
public static List<Pair<String, Boolean>> sortItemsAccordingToSettings(List<Pair<String, Boolean>> names, final JavaCodeStyleSettings settings) {
int[] entryForName = ArrayUtil.newIntArray(names.size());
PackageEntry[] entries = settings.IMPORT_LAYOUT_TABLE.getEntries();
for(int i = 0; i < names.size(); i++){
@@ -732,7 +729,7 @@ public class ImportHelper{
private static boolean isToUseImportOnDemand(@NotNull String packageName,
int classCount,
boolean isStaticImportNeeded,
@NotNull CodeStyleSettings settings){
@NotNull JavaCodeStyleSettings settings){
if (!settings.USE_SINGLE_CLASS_IMPORTS) return true;
int limitCount = isStaticImportNeeded ? settings.NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND :
settings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND;
@@ -889,7 +889,7 @@ public class JavaCodeStyleManagerImpl extends JavaCodeStyleManager {
@NotNull
private String[] getSuggestionsByName(@NotNull String name, @NotNull VariableKind variableKind, boolean isArray, boolean correctKeywords) {
boolean upperCaseStyle = variableKind == VariableKind.STATIC_FINAL_FIELD;
boolean preferLongerNames = getSettings().PREFER_LONGER_NAMES;
boolean preferLongerNames = getJavaSettings().PREFER_LONGER_NAMES;
String prefix = getPrefixByVariableKind(variableKind);
String suffix = getSuffixByVariableKind(variableKind);
@@ -1071,16 +1071,16 @@ public class JavaCodeStyleManagerImpl extends JavaCodeStyleManager {
String prefix = "";
switch (variableKind) {
case FIELD:
prefix = getSettings().FIELD_NAME_PREFIX;
prefix = getJavaSettings().FIELD_NAME_PREFIX;
break;
case STATIC_FIELD:
prefix = getSettings().STATIC_FIELD_NAME_PREFIX;
prefix = getJavaSettings().STATIC_FIELD_NAME_PREFIX;
break;
case PARAMETER:
prefix = getSettings().PARAMETER_NAME_PREFIX;
prefix = getJavaSettings().PARAMETER_NAME_PREFIX;
break;
case LOCAL_VARIABLE:
prefix = getSettings().LOCAL_VARIABLE_NAME_PREFIX;
prefix = getJavaSettings().LOCAL_VARIABLE_NAME_PREFIX;
break;
case STATIC_FINAL_FIELD:
prefix = "";
@@ -1101,16 +1101,16 @@ public class JavaCodeStyleManagerImpl extends JavaCodeStyleManager {
String suffix = "";
switch (variableKind) {
case FIELD:
suffix = getSettings().FIELD_NAME_SUFFIX;
suffix = getJavaSettings().FIELD_NAME_SUFFIX;
break;
case STATIC_FIELD:
suffix = getSettings().STATIC_FIELD_NAME_SUFFIX;
suffix = getJavaSettings().STATIC_FIELD_NAME_SUFFIX;
break;
case PARAMETER:
suffix = getSettings().PARAMETER_NAME_SUFFIX;
suffix = getJavaSettings().PARAMETER_NAME_SUFFIX;
break;
case LOCAL_VARIABLE:
suffix = getSettings().LOCAL_VARIABLE_NAME_SUFFIX;
suffix = getJavaSettings().LOCAL_VARIABLE_NAME_SUFFIX;
break;
case STATIC_FINAL_FIELD:
suffix = "";
@@ -1127,10 +1127,10 @@ public class JavaCodeStyleManagerImpl extends JavaCodeStyleManager {
@Nullable
private CodeStyleSettings.TypeToNameMap getMapByVariableKind(@NotNull VariableKind variableKind) {
if (variableKind == VariableKind.FIELD) return getSettings().FIELD_TYPE_TO_NAME;
if (variableKind == VariableKind.STATIC_FIELD) return getSettings().STATIC_FIELD_TYPE_TO_NAME;
if (variableKind == VariableKind.PARAMETER) return getSettings().PARAMETER_TYPE_TO_NAME;
if (variableKind == VariableKind.LOCAL_VARIABLE) return getSettings().LOCAL_VARIABLE_TYPE_TO_NAME;
if (variableKind == VariableKind.FIELD) return getJavaSettings().FIELD_TYPE_TO_NAME;
if (variableKind == VariableKind.STATIC_FIELD) return getJavaSettings().STATIC_FIELD_TYPE_TO_NAME;
if (variableKind == VariableKind.PARAMETER) return getJavaSettings().PARAMETER_TYPE_TO_NAME;
if (variableKind == VariableKind.LOCAL_VARIABLE) return getJavaSettings().LOCAL_VARIABLE_TYPE_TO_NAME;
return null;
}
@@ -1152,6 +1152,11 @@ public class JavaCodeStyleManagerImpl extends JavaCodeStyleManager {
return CodeStyleSettingsManager.getSettings(myProject);
}
@NotNull
private JavaCodeStyleSettings getJavaSettings() {
return getSettings().getCustomSettings(JavaCodeStyleSettings.class);
}
private static boolean isStringPsiLiteral(@NotNull PsiElement element) {
if (element instanceof PsiLiteralExpression) {
final String text = element.getText();
@@ -136,7 +136,7 @@ public class JavaReferenceAdjuster implements ReferenceAdjuster {
public ASTNode process(@NotNull ASTNode element, boolean addImports, boolean incompleteCode, Project project) {
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project);
JavaCodeStyleSettings javaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
return process(element, addImports, incompleteCode, javaSettings.useFqNamesInJavadocAlways(), settings.USE_FQ_CLASS_NAMES);
return process(element, addImports, incompleteCode, javaSettings.useFqNamesInJavadocAlways(), javaSettings.USE_FQ_CLASS_NAMES);
}
private static boolean isAnnotated(ASTNode element) {
@@ -179,7 +179,7 @@ public class JavaReferenceAdjuster implements ReferenceAdjuster {
public void processRange(@NotNull ASTNode element, int startOffset, int endOffset, Project project) {
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project);
JavaCodeStyleSettings javaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
processRange(element, startOffset, endOffset, javaSettings.useFqNamesInJavadocAlways(), settings.USE_FQ_CLASS_NAMES);
processRange(element, startOffset, endOffset, javaSettings.useFqNamesInJavadocAlways(), javaSettings.USE_FQ_CLASS_NAMES);
}
private static void addReferencesInRange(List<ASTNode> array, ASTNode parent, int startOffset, int endOffset) {
@@ -239,7 +239,7 @@ public class JavaReferenceAdjuster implements ReferenceAdjuster {
return reference;
}
if (!CodeStyleSettingsManager.getSettings(reference.getProject()).INSERT_INNER_CLASS_IMPORTS) {
if (!CodeStyleSettingsManager.getSettings(reference.getProject()).getCustomSettings(JavaCodeStyleSettings.class).INSERT_INNER_CLASS_IMPORTS) {
final PsiElement qualifier = reference.getQualifier();
if (qualifier instanceof PsiQualifiedReferenceElement) {
return getClassReferenceToShorten(parentClass, addImports, (PsiQualifiedReferenceElement)qualifier);
@@ -20,12 +20,12 @@ import com.intellij.lang.ASTNode;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.openapi.util.text.LineTokenizer;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.impl.source.SourceTreeToPsiMap;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.util.PsiUtil;
@@ -53,8 +53,8 @@ public class CommentFormatter {
myProject = project;
}
public CodeStyleSettings getSettings() {
return mySettings;
public JavaCodeStyleSettings getSettings() {
return mySettings.getCustomSettings(JavaCodeStyleSettings.class);
}
public JDParser getParser() {
@@ -64,7 +64,7 @@ public class JDComment {
@NotNull
protected String continuationIndent() {
CodeStyleSettings settings = myFormatter.getSettings();
CodeStyleSettings settings = myFormatter.getSettings().getContainer();
CommonCodeStyleSettings.IndentOptions indentOptions = settings.getIndentOptions(JavaFileType.INSTANCE);
return new IndentInfo(0, indentOptions.CONTINUATION_INDENT_SIZE, 0).generateNewWhiteSpace(indentOptions);
}
@@ -20,6 +20,7 @@ import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.javadoc.PsiDocComment;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -43,10 +44,10 @@ public class JDParser {
private static final char lineSeparator = '\n';
private final CodeStyleSettings mySettings;
private final JavaCodeStyleSettings mySettings;
public JDParser(@NotNull CodeStyleSettings settings) {
mySettings = settings;
mySettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
}
public void formatCommentText(@NotNull PsiElement element, @NotNull CommentFormatter formatter) {
@@ -565,7 +566,7 @@ public class JDParser {
@NotNull CharSequence firstLinePrefix,
@NotNull CharSequence continuationPrefix)
{
final int rightMargin = mySettings.getRightMargin(JavaLanguage.INSTANCE);
final int rightMargin = mySettings.getContainer().getRightMargin(JavaLanguage.INSTANCE);
final int maxCommentLength = rightMargin - continuationPrefix.length();
final int firstLinePrefixLength = firstLinePrefix.length();
final boolean firstLineShorter = firstLinePrefixLength > continuationPrefix.length();
@@ -576,7 +577,7 @@ public class JDParser {
boolean canWrap = !mySettings.JD_PRESERVE_LINE_FEEDS || hasLineLongerThan(str, maxCommentLength);
//If wrap comments selected, comments should be wrapped by the right margin
if (mySettings.WRAP_COMMENTS && canWrap) {
if (mySettings.getContainer().WRAP_COMMENTS && canWrap) {
list = toArrayWrapping(str, maxCommentLength);
if (firstLineShorter
@@ -29,10 +29,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.codeStyle.VariableKind;
import com.intellij.psi.codeStyle.*;
import com.intellij.psi.impl.source.resolve.JavaResolveUtil;
import com.intellij.psi.scope.processor.VariablesProcessor;
import com.intellij.psi.scope.util.PsiScopesUtil;
@@ -963,7 +960,7 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
type = psiSubstitutor.substitute(type);
}
PsiParameter parameter = factory.createParameter(newParm.getName(), type, list);
if (CodeStyleSettingsManager.getSettings(project).GENERATE_FINAL_PARAMETERS) {
if (CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS) {
PsiUtil.setModifierProperty(parameter, PsiModifier.FINAL, true);
}
return parameter;
@@ -1231,7 +1228,8 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
JavaPsiFacade.getElementFactory(method.getProject()).createTypeFromText(CommonClassNames.JAVA_LANG_OBJECT, method);
}
PsiParameter param = factory.createParameter(info.getName(), parameterType, method);
if (CodeStyleSettingsManager.getSettings(manager.getProject()).GENERATE_FINAL_PARAMETERS) {
if (CodeStyleSettingsManager.getSettings(manager.getProject())
.getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS) {
PsiUtil.setModifierProperty(param, PsiModifier.FINAL, true);
}
prototype.getParameterList().add(param);
@@ -1191,7 +1191,7 @@ public class ExtractMethodProcessor implements MatchProvider {
exc[0] = null;
final PsiParameter[] parameters = method.getParameterList().getParameters();
if (parameters.length > 0) {
if (CodeStyleSettingsManager.getSettings(myProject).GENERATE_FINAL_PARAMETERS) {
if (CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS) {
method.accept(new JavaRecursiveElementVisitor() {
@Override public void visitReferenceExpression(PsiReferenceExpression expression) {
@@ -1385,7 +1385,7 @@ public class ExtractMethodProcessor implements MatchProvider {
PsiCodeBlock body = newMethod.getBody();
LOG.assertTrue(body != null);
boolean isFinal = CodeStyleSettingsManager.getSettings(myProject).GENERATE_FINAL_PARAMETERS;
boolean isFinal = CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS;
PsiParameterList list = newMethod.getParameterList();
for (VariableData data : myVariableDatum) {
if (data.passAsParameter) {
@@ -28,10 +28,7 @@ import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.codeStyle.VariableKind;
import com.intellij.psi.codeStyle.*;
import com.intellij.psi.controlFlow.ControlFlowUtil;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.LocalSearchScope;
@@ -613,7 +610,7 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
final String parameterName = parameter.getName();
LOG.assertTrue(parameterName != null);
PsiParameter parm = myElementFactory.createParameter(parameterName, parameter.getType());
if (CodeStyleSettingsManager.getSettings(myProject).GENERATE_FINAL_PARAMETERS) {
if (CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS) {
final PsiModifierList modifierList = parm.getModifierList();
LOG.assertTrue(modifierList != null);
modifierList.setModifierProperty(PsiModifier.FINAL, true);
@@ -28,10 +28,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.codeStyle.*;
import com.intellij.psi.javadoc.PsiDocTagValue;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.searches.ReferencesSearch;
@@ -231,7 +228,7 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
private String calculateDelegateFieldName() {
final Project project = sourceClass.getProject();
final CodeStyleSettingsManager settingsManager = CodeStyleSettingsManager.getInstance(project);
final CodeStyleSettings settings = settingsManager.getCurrentSettings();
final JavaCodeStyleSettings settings = settingsManager.getCurrentSettings().getCustomSettings(JavaCodeStyleSettings.class);
final String baseName = settings.FIELD_NAME_PREFIX.length() == 0 ? StringUtil.decapitalize(newClassName) : newClassName;
String name = settings.FIELD_NAME_PREFIX + baseName + settings.FIELD_NAME_SUFFIX;
@@ -26,6 +26,7 @@ import com.intellij.patterns.ElementPattern;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
import com.intellij.psi.search.ProjectScope;
import com.intellij.psi.util.PsiTreeUtil;
@@ -272,7 +273,8 @@ class InlineToAnonymousConstructorProcessor {
try {
final PsiDeclarationStatement declaration = myElementFactory.createVariableDeclarationStatement(localName, type, initializer);
PsiVariable variable = (PsiVariable)declaration.getDeclaredElements()[0];
if (!PsiUtil.isLanguageLevel8OrHigher(myNewExpression) || CodeStyleSettingsManager.getSettings(project).GENERATE_FINAL_LOCALS) {
if (!PsiUtil.isLanguageLevel8OrHigher(myNewExpression) ||
CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS) {
PsiUtil.setModifierProperty(variable, PsiModifier.FINAL, true);
}
final PsiElement parent = myNewStatement.getParent();
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiLocalVariable;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiParameter;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.util.PsiUtil;
import com.intellij.refactoring.IntroduceParameterRefactoring;
import com.intellij.refactoring.JavaRefactoringSettings;
@@ -136,6 +137,8 @@ public abstract class InplaceIntroduceParameterUI extends IntroduceParameterSett
public boolean hasFinalModifier() {
if (myHasWriteAccess) return false;
final Boolean createFinals = JavaRefactoringSettings.getInstance().INTRODUCE_PARAMETER_CREATE_FINALS;
return createFinals == null ? CodeStyleSettingsManager.getSettings(myProject).GENERATE_FINAL_PARAMETERS : createFinals.booleanValue();
return createFinals == null ?
CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS :
createFinals.booleanValue();
}
}
@@ -24,6 +24,7 @@ import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.util.PsiUtil;
import com.intellij.refactoring.HelpID;
import com.intellij.refactoring.JavaRefactoringSettings;
@@ -208,7 +209,8 @@ public class IntroduceParameterDialog extends RefactoringDialog {
final Boolean settingsFinals = settings.INTRODUCE_PARAMETER_CREATE_FINALS;
myCbDeclareFinal.setSelected(settingsFinals == null ?
CodeStyleSettingsManager.getSettings(myProject).GENERATE_FINAL_PARAMETERS :
CodeStyleSettingsManager.getSettings(myProject)
.getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS :
settingsFinals.booleanValue());
panel.add(myCbDeclareFinal, gbConstraints);
if (myMustBeFinal) {
@@ -45,10 +45,7 @@ import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.codeStyle.SuggestedNameInfo;
import com.intellij.psi.codeStyle.VariableKind;
import com.intellij.psi.codeStyle.*;
import com.intellij.psi.impl.PsiDiamondTypeUtil;
import com.intellij.psi.impl.source.jsp.jspJava.JspCodeBlock;
import com.intellij.psi.impl.source.jsp.jspJava.JspHolderMethod;
@@ -1219,7 +1216,9 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase {
public static boolean createFinals(Project project) {
final Boolean createFinals = JavaRefactoringSettings.getInstance().INTRODUCE_LOCAL_CREATE_FINALS;
return createFinals == null ? CodeStyleSettingsManager.getSettings(project).GENERATE_FINAL_LOCALS : createFinals.booleanValue();
return createFinals == null ?
CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS :
createFinals.booleanValue();
}
public static boolean checkAnchorBeforeThisOrSuper(final Project project,
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiExpression;
import com.intellij.psi.PsiNameHelper;
import com.intellij.psi.PsiType;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.codeStyle.SuggestedNameInfo;
import com.intellij.refactoring.HelpID;
import com.intellij.refactoring.JavaRefactoringSettings;
@@ -207,7 +208,7 @@ class IntroduceVariableDialog extends DialogWrapper implements IntroduceVariable
myCbFinal.setText(RefactoringBundle.message("declare.final"));
final Boolean createFinals = JavaRefactoringSettings.getInstance().INTRODUCE_LOCAL_CREATE_FINALS;
myCbFinalState = createFinals == null ?
CodeStyleSettingsManager.getSettings(myProject).GENERATE_FINAL_LOCALS :
CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS :
createFinals.booleanValue();
gbConstraints.insets = JBUI.emptyInsets();
@@ -20,6 +20,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.codeStyle.VariableKind;
import com.intellij.psi.javadoc.PsiDocComment;
import org.jetbrains.annotations.NonNls;
@@ -134,7 +135,9 @@ class ParameterObjectBuilder {
final ParameterSpec field = iterator.next();
final PsiParameter parameter = field.getParameter();
outputAnnotationString(parameter, out);
out.append(CodeStyleSettingsManager.getSettings(myProject).GENERATE_FINAL_PARAMETERS ? " final " : "");
out.append(
CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS ?
" final " : "");
final String parameterName = parameter.getName();
final PsiType type = field.getType();
final PsiType fieldType = parameter.isVarArgs() && type instanceof PsiArrayType ?
@@ -18,10 +18,7 @@ package com.intellij.refactoring.makeStatic;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.codeStyle.VariableKind;
import com.intellij.psi.codeStyle.*;
import com.intellij.psi.javadoc.PsiDocTag;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.util.PsiTreeUtil;
@@ -80,7 +77,8 @@ public class MakeClassStaticProcessor extends MakeMethodOrClassStaticProcessor<P
constructors = new PsiMethod[]{defConstructor};
}
boolean generateFinalParams = CodeStyleSettingsManager.getSettings(myProject).GENERATE_FINAL_PARAMETERS;
boolean generateFinalParams =
CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS;
for (PsiMethod constructor : constructors) {
final MethodJavaDocHelper javaDocHelper = new MethodJavaDocHelper(constructor);
PsiParameterList paramList = constructor.getParameterList();
@@ -22,6 +22,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.refactoring.util.NonCodeUsageInfo;
@@ -57,7 +58,7 @@ public class JavaMoveClassToInnerHandler implements MoveClassToInnerHandler {
@Override
public List<PsiElement> filterImports(@NotNull List<UsageInfo> usageInfos, @NotNull Project project) {
final List<PsiElement> importStatements = new ArrayList<>();
if (!CodeStyleSettingsManager.getSettings(project).INSERT_INNER_CLASS_IMPORTS) {
if (!CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class).INSERT_INNER_CLASS_IMPORTS) {
filterUsagesInImportStatements(usageInfos, importStatements);
}
else {
@@ -21,6 +21,7 @@ import com.intellij.psi.PsiType;
import com.intellij.psi.PsiTypeParameter;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.codeStyle.VariableKind;
import java.io.IOException;
@@ -106,7 +107,9 @@ class ReturnValueBeanBuilder {
final String parameterName = JavaCodeStyleManager.getInstance(myProject).propertyNameToVariableName(name, VariableKind.PARAMETER);
final String fieldName = getFieldName(name);
out.append("\tpublic ").append(myClassName).append('(');
out.append(CodeStyleSettingsManager.getSettings(myProject).GENERATE_FINAL_PARAMETERS ? "final " : "");
out.append(
CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS ?
"final " : "");
out.append(typeText).append(' ').append(parameterName);
out.append(") {\n");
if (fieldName.equals(parameterName)) {
@@ -44,6 +44,7 @@ import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.testFramework.PsiTestUtil;
import com.intellij.testFramework.UsefulTestCase;
@@ -85,12 +86,12 @@ public class AddAnnotationFixTest extends UsefulTestCase {
myModule = builder.getFixture().getModule();
myProject = myFixture.getProject();
CodeStyleSettingsManager.getSettings(myProject).USE_EXTERNAL_ANNOTATIONS = true;
CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class).USE_EXTERNAL_ANNOTATIONS = true;
}
@Override
protected void tearDown() throws Exception {
CodeStyleSettingsManager.getSettings(myProject).USE_EXTERNAL_ANNOTATIONS = false;
CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class).USE_EXTERNAL_ANNOTATIONS = false;
try {
myFixture.tearDown();
}
@@ -23,6 +23,7 @@ import com.intellij.openapi.roots.JavaModuleExternalPaths;
import com.intellij.openapi.roots.ModuleRootModificationUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.testFramework.UsefulTestCase;
import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
import com.intellij.testFramework.fixtures.*;
@@ -54,12 +55,12 @@ public class ExternalAnnotationsTest extends UsefulTestCase {
myProject = myFixture.getProject();
CodeStyleSettingsManager.getSettings(myProject).USE_EXTERNAL_ANNOTATIONS = true;
CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class).USE_EXTERNAL_ANNOTATIONS = true;
}
@Override
protected void tearDown() throws Exception {
CodeStyleSettingsManager.getSettings(myProject).USE_EXTERNAL_ANNOTATIONS = false;
CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class).USE_EXTERNAL_ANNOTATIONS = false;
try {
myFixture.tearDown();
}
@@ -25,6 +25,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import org.jetbrains.annotations.NotNull;
@@ -69,12 +70,17 @@ public class GenerateConstructorTest extends LightCodeInsightFixtureTestCase {
}
public void testFieldPrefixCoincidence() {
CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings().FIELD_NAME_PREFIX = "m";
getJavaSettings().FIELD_NAME_PREFIX = "m";
doTest();
}
@NotNull
private JavaCodeStyleSettings getJavaSettings() {
return CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings().getCustomSettings(JavaCodeStyleSettings.class);
}
public void testFieldPrefixCoincidence1() {
CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings().FIELD_NAME_PREFIX = "_";
getJavaSettings().FIELD_NAME_PREFIX = "_";
doTest();
}
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiField;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.testFramework.LightCodeInsightTestCase;
import com.intellij.util.Function;
@@ -61,8 +62,8 @@ public abstract class GenerateEqualsTestCase extends LightCodeInsightTestCase {
boolean insertOverride,
boolean useAccessors) {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).clone();
settings.GENERATE_FINAL_LOCALS = true;
settings.INSERT_OVERRIDE_ANNOTATION = insertOverride;
settings.getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS = true;
settings.getCustomSettings(JavaCodeStyleSettings.class).INSERT_OVERRIDE_ANNOTATION = insertOverride;
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(settings);
try {
PsiElement element = getFile().findElementAt(getEditor().getCaretModel().getOffset());
@@ -21,6 +21,7 @@ import com.intellij.codeInsight.generation.GenerateSetterHandler
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
import com.intellij.psi.codeStyle.JavaCodeStyleSettings
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import com.intellij.util.ui.UIUtil
import com.siyeh.ig.style.UnqualifiedFieldAccessInspection
@@ -98,7 +99,7 @@ class Foo {
}
void "test strip field prefix"() {
def settings = CodeStyleSettingsManager.getInstance(getProject()).currentSettings
def settings = CodeStyleSettingsManager.getInstance(getProject()).currentSettings.getCustomSettings(JavaCodeStyleSettings.class)
String oldPrefix = settings.FIELD_NAME_PREFIX
try {
settings.FIELD_NAME_PREFIX = "my"
@@ -27,6 +27,7 @@ import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.util.MethodSignature;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.TypeConversionUtil;
@@ -79,7 +80,7 @@ public class OverrideImplement15Test extends LightCodeInsightTestCase {
CommonCodeStyleSettings javaSettings = codeStyleSettings.getCommonSettings(JavaLanguage.INSTANCE);
javaSettings.RIGHT_MARGIN = 80;
javaSettings.KEEP_LINE_BREAKS = true;
codeStyleSettings.GENERATE_FINAL_PARAMETERS = true;
codeStyleSettings.getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS = true;
javaSettings.METHOD_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM;
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(codeStyleSettings);
doTest(false);
@@ -92,7 +93,7 @@ public class OverrideImplement15Test extends LightCodeInsightTestCase {
public void testOverridingLibraryFunctionWithConfiguredParameterPrefix() throws Exception {
CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(getProject()).clone();
try {
codeStyleSettings.PARAMETER_NAME_PREFIX = "in";
codeStyleSettings.getCustomSettings(JavaCodeStyleSettings.class).PARAMETER_NAME_PREFIX = "in";
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(codeStyleSettings);
doTest(false);
}
@@ -107,7 +108,7 @@ public class OverrideImplement15Test extends LightCodeInsightTestCase {
CommonCodeStyleSettings javaSettings = codeStyleSettings.getCommonSettings(JavaLanguage.INSTANCE);
javaSettings.RIGHT_MARGIN = 80;
javaSettings.KEEP_LINE_BREAKS = false;
codeStyleSettings.GENERATE_FINAL_PARAMETERS = false;
codeStyleSettings.getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS = false;
javaSettings.METHOD_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM;
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(codeStyleSettings);
doTest(false);
@@ -30,6 +30,7 @@ import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.testFramework.UsefulTestCase;
import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
import com.intellij.testFramework.fixtures.*;
@@ -93,13 +94,14 @@ public class SuppressExternalTest extends UsefulTestCase {
final IntentionAction action = myFixture.getAvailableIntention("Suppress for method", "src/suppressed/" + testName + ".java");
assertNotNull(action);
Project project = myFixture.getProject();
boolean oldUseExternalAnnotations = CodeStyleSettingsManager.getSettings(project).USE_EXTERNAL_ANNOTATIONS;
JavaCodeStyleSettings javaSettings = CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class);
boolean oldUseExternalAnnotations = javaSettings.USE_EXTERNAL_ANNOTATIONS;
try {
CodeStyleSettingsManager.getSettings(project).USE_EXTERNAL_ANNOTATIONS = true;
javaSettings.USE_EXTERNAL_ANNOTATIONS = true;
myFixture.launchAction(action);
}
finally {
CodeStyleSettingsManager.getSettings(project).USE_EXTERNAL_ANNOTATIONS = oldUseExternalAnnotations;
javaSettings.USE_EXTERNAL_ANNOTATIONS = oldUseExternalAnnotations;
}
myFixture.checkResultByFile("content/anno/suppressed/annotations.xml", "content/anno/suppressed/annotations" + testName + "_after.xml", true);
}
@@ -33,6 +33,7 @@ import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiMethod
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
import com.intellij.psi.codeStyle.CommonCodeStyleSettings
import com.intellij.psi.codeStyle.JavaCodeStyleSettings
import com.intellij.psi.impl.PsiDocumentManagerBase
import com.intellij.util.ui.UIUtil
import com.siyeh.ig.style.UnqualifiedFieldAccessInspection
@@ -171,7 +172,7 @@ class NormalCompletionTest extends LightFixtureCompletionTestCase {
LookupManager.getInstance(getProject()).hideActiveLookup()
CodeStyleSettingsManager.getSettings(getProject()).PREFER_LONGER_NAMES = false
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class).PREFER_LONGER_NAMES = false
try{
configureByFile("PreferLongerNamesOption.java")
@@ -181,7 +182,7 @@ class NormalCompletionTest extends LightFixtureCompletionTestCase {
assertEquals("abcdEfghIjk", myItems[2].getLookupString())
}
finally{
CodeStyleSettingsManager.getSettings(getProject()).PREFER_LONGER_NAMES = true
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class).PREFER_LONGER_NAMES = true
}
}
@@ -17,9 +17,9 @@ import com.intellij.codeInsight.template.TemplateManager;
import com.intellij.codeInsight.template.impl.TemplateImpl;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.testFramework.fixtures.CodeInsightTestUtil;
import com.intellij.util.containers.ContainerUtil;
@@ -833,7 +833,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
}
public void testInsertOverride() throws Exception {
CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(getProject());
JavaCodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
styleSettings.INSERT_OVERRIDE_ANNOTATION = true;
doItemTest();
}
@@ -1119,13 +1119,14 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
}
public void testInnerClassImports() throws Throwable {
CodeStyleSettingsManager.getSettings(getProject()).INSERT_INNER_CLASS_IMPORTS = true;
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
settings.INSERT_INNER_CLASS_IMPORTS = true;
try {
myFixture.addClass("package java.awt.geom; public class Point2D { public static class Double {} }");
doActionTest();
}
finally {
CodeStyleSettingsManager.getSettings(getProject()).INSERT_INNER_CLASS_IMPORTS = false;
settings.INSERT_INNER_CLASS_IMPORTS = false;
}
}
@@ -14,11 +14,12 @@
* limitations under the License.
*/
package com.intellij.java.codeInsight.completion
import com.intellij.JavaTestUtil
import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase
import com.intellij.ide.highlighter.JavaFileType
import com.intellij.psi.codeStyle.CodeStyleSettings
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
import com.intellij.psi.codeStyle.JavaCodeStyleSettings
class VariablesCompletionTest extends LightFixtureCompletionTestCase {
public static final String FILE_PREFIX = "/codeInsight/completion/variables/"
@@ -119,7 +120,7 @@ class VariablesCompletionTest extends LightFixtureCompletionTestCase {
}
void testFieldNameCompletion1() throws Exception {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject())
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class)
String oldPrefix = settings.FIELD_NAME_PREFIX
settings.FIELD_NAME_PREFIX = "my"
try {
@@ -131,7 +132,7 @@ class VariablesCompletionTest extends LightFixtureCompletionTestCase {
}
void testFieldNameCompletion2() throws Exception {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project)
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class)
String oldPrefix = settings.FIELD_NAME_PREFIX
settings.FIELD_NAME_PREFIX = "my"
configureByFile(FILE_PREFIX + "locals/" + "FieldNameCompletion2.java")
@@ -140,7 +141,7 @@ class VariablesCompletionTest extends LightFixtureCompletionTestCase {
}
void testFieldNameCompletion3() throws Exception {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project)
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class)
String oldPrefix = settings.FIELD_NAME_PREFIX
settings.FIELD_NAME_PREFIX = "my"
configureByFile(FILE_PREFIX + "locals/" + "FieldNameCompletion3.java")
@@ -214,7 +215,7 @@ class VariablesCompletionTest extends LightFixtureCompletionTestCase {
}
void testConstructorParameterNameWithPrefix() {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project)
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class)
String oldField = settings.FIELD_NAME_PREFIX
String oldParam = settings.PARAMETER_NAME_PREFIX
settings.FIELD_NAME_PREFIX = "my"
@@ -59,7 +59,7 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase {
protected void setUp() throws Exception {
super.setUp();
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).clone();
settings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 100;
settings.getCustomSettings(JavaCodeStyleSettings.class).CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 100;
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(settings);
DaemonCodeAnalyzer.getInstance(getProject()).setUpdateByTimerEnabled(false);
}
@@ -130,7 +130,8 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase {
try {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).clone();
settings.LAYOUT_STATIC_IMPORTS_SEPARATELY = true;
JavaCodeStyleSettings javaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
javaSettings.LAYOUT_STATIC_IMPORTS_SEPARATELY = true;
PackageEntryTable table = new PackageEntryTable();
table.addEntry(PackageEntry.ALL_OTHER_IMPORTS_ENTRY);
table.addEntry(PackageEntry.BLANK_LINE_ENTRY);
@@ -141,7 +142,7 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase {
table.addEntry(PackageEntry.BLANK_LINE_ENTRY);
table.addEntry(PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY);
settings.IMPORT_LAYOUT_TABLE.copyFrom(table);
settings.getCustomSettings(JavaCodeStyleSettings.class).IMPORT_LAYOUT_TABLE.copyFrom(table);
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(settings);
JavaCodeStyleManager.getInstance(getProject()).optimizeImports(file);
@@ -184,7 +185,7 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase {
assertEmpty(highlightErrors());
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).clone();
settings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 2;
settings.getCustomSettings(JavaCodeStyleSettings.class).CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 2;
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(settings);
WriteCommandAction.runWriteCommandAction(getProject(),
() -> JavaCodeStyleManager.getInstance(getProject()).optimizeImports(getFile()));
@@ -477,9 +478,10 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase {
assertEmpty(highlightErrors());
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).clone();
settings.LAYOUT_STATIC_IMPORTS_SEPARATELY = true;
settings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 3;
settings.NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND = 3;
JavaCodeStyleSettings javaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
javaSettings.LAYOUT_STATIC_IMPORTS_SEPARATELY = true;
javaSettings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 3;
javaSettings.NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND = 3;
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(settings);
WriteCommandAction.runWriteCommandAction(getProject(), () -> JavaCodeStyleManager.getInstance(getProject()).optimizeImports(getFile()));
@@ -18,6 +18,7 @@ package com.intellij.java.codeInsight.daemon.quickFix;
import com.intellij.codeInsight.daemon.LightIntentionActionTestCase;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import org.jdom.Element;
/**
@@ -32,8 +33,8 @@ public class AssignFieldFromParameterTest extends LightIntentionActionTestCase {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
myOldSettings = new Element("dummy2");
settings.writeExternal(myOldSettings);
settings.FIELD_NAME_PREFIX = "my";
settings.STATIC_FIELD_NAME_PREFIX = "our";
settings.getCustomSettings(JavaCodeStyleSettings.class).FIELD_NAME_PREFIX = "my";
settings.getCustomSettings(JavaCodeStyleSettings.class).STATIC_FIELD_NAME_PREFIX = "our";
}
@Override
@@ -16,8 +16,8 @@
package com.intellij.java.codeInsight.daemon.quickFix;
import com.intellij.codeInsight.daemon.LightIntentionActionTestCase;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
/**
* @author Danila Ponomarenko
@@ -28,7 +28,7 @@ public class BindFieldsFromParametersTest extends LightIntentionActionTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
settings.FIELD_NAME_PREFIX = "my";
myPreferLongNames = settings.PREFER_LONGER_NAMES;
if (getTestName(false).contains("SameParam")) {
@@ -38,7 +38,7 @@ public class BindFieldsFromParametersTest extends LightIntentionActionTestCase {
@Override
protected void tearDown() throws Exception {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
settings.FIELD_NAME_PREFIX = "";
settings.PREFER_LONGER_NAMES = myPreferLongNames;
super.tearDown();
@@ -17,8 +17,8 @@ package com.intellij.java.codeInsight.daemon.quickFix;
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.siyeh.ig.style.MissortedModifiersInspection;
import com.siyeh.ig.style.UnqualifiedFieldAccessInspection;
@@ -33,7 +33,7 @@ public class CreateConstructorParameterFromFieldTest extends LightQuickFixParame
protected void setUp() throws Exception {
super.setUp();
enableInspectionTools(new UnusedDeclarationInspection(), new MissortedModifiersInspection(), new UnqualifiedFieldAccessInspection());
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
final JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
myPreferLongNames = settings.PREFER_LONGER_NAMES;
if (getTestName(false).contains("SameParameter")) {
settings.PREFER_LONGER_NAMES = false;
@@ -42,7 +42,7 @@ public class CreateConstructorParameterFromFieldTest extends LightQuickFixParame
@Override
protected void tearDown() throws Exception {
CodeStyleSettingsManager.getSettings(getProject()).PREFER_LONGER_NAMES = myPreferLongNames;
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class).PREFER_LONGER_NAMES = myPreferLongNames;
super.tearDown();
}
@@ -17,6 +17,7 @@ package com.intellij.java.codeInsight.daemon.quickFix;
import com.intellij.codeInsight.daemon.LightIntentionActionTestCase;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
/**
* @author ven
@@ -25,12 +26,12 @@ public class CreateFieldFromParameterTest extends LightIntentionActionTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
CodeStyleSettingsManager.getSettings(getProject()).FIELD_NAME_PREFIX = "my";
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class).FIELD_NAME_PREFIX = "my";
}
@Override
protected void tearDown() throws Exception {
CodeStyleSettingsManager.getSettings(getProject()).FIELD_NAME_PREFIX = "";
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class).FIELD_NAME_PREFIX = "";
//noinspection SuperTearDownInFinally
super.tearDown();
}
@@ -17,6 +17,7 @@ package com.intellij.java.codeInsight.daemon.quickFix;
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
/**
* @author ven
@@ -26,12 +27,13 @@ public class CreateLocalFromUsageTest extends LightQuickFixParameterizedTestCase
@Override
protected void setUp() throws Exception {
super.setUp();
CodeStyleSettingsManager.getSettings(getProject()).GENERATE_FINAL_LOCALS = getTestName(true).contains("final");
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS =
getTestName(true).contains("final");
}
@Override
protected void tearDown() throws Exception {
CodeStyleSettingsManager.getSettings(getProject()).GENERATE_FINAL_LOCALS = false;
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS = false;
super.tearDown();
}
@@ -18,8 +18,8 @@ package com.intellij.java.codeInsight.daemon.quickFix;
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
import com.intellij.codeInspection.LambdaCanBeMethodReferenceInspection;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import org.jetbrains.annotations.NotNull;
@@ -27,14 +27,16 @@ public class Lambda2MethodReferenceInspectionTest extends LightQuickFixParameter
@Override
protected void setUp() throws Exception {
super.setUp();
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
settings.REPLACE_CAST = settings.REPLACE_INSTANCEOF = true;
JavaCodeStyleSettings javaSettings =
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
javaSettings.REPLACE_CAST = javaSettings.REPLACE_INSTANCEOF = true;
}
@Override
protected void tearDown() throws Exception {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
settings.REPLACE_CAST = settings.REPLACE_INSTANCEOF = false;
JavaCodeStyleSettings javaSettings =
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
javaSettings.REPLACE_CAST = javaSettings.REPLACE_INSTANCEOF = false;
super.tearDown();
}
@@ -18,6 +18,7 @@ package com.intellij.java.codeInsight.daemon.quickFix;
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
/**
* @author Pavel.Dolgov
@@ -32,7 +33,8 @@ public class ReplaceIteratorForEachLoopWithIteratorForLoopFixTest extends LightQ
protected void setUp() throws Exception {
super.setUp();
if (getTestName(false).startsWith("Final")) {
final CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(getProject());
final JavaCodeStyleSettings codeStyleSettings =
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
myFinalLocals = codeStyleSettings.GENERATE_FINAL_LOCALS;
codeStyleSettings.GENERATE_FINAL_LOCALS = true;
}
@@ -43,7 +45,7 @@ public class ReplaceIteratorForEachLoopWithIteratorForLoopFixTest extends LightQ
try {
if (getTestName(false).startsWith("Final")) {
final CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(getProject());
codeStyleSettings.GENERATE_FINAL_LOCALS = myFinalLocals;
codeStyleSettings.getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS = myFinalLocals;
}
}
finally {
@@ -17,8 +17,8 @@ package com.intellij.java.codeInsight.intention;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
public class AddSingleStaticImportActionTest extends JavaCodeInsightFixtureTestCase {
@@ -127,7 +127,7 @@ public class AddSingleStaticImportActionTest extends JavaCodeInsightFixtureTestC
myFixture.addClass("package foo; class Bar {public static void foo(String s){}}");
myFixture.configureByFile(getTestName(false) + ".java");
CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings();
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings().getCustomSettings(JavaCodeStyleSettings.class);
int old = settings.NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND;
settings.NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND = 1;
try {
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.daemon.LightIntentionActionTestCase;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
/**
* @author yole
@@ -33,7 +34,7 @@ public class CopyAbstractMethodImplementationTest extends LightIntentionActionTe
protected void setUp() throws Exception {
super.setUp();
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).clone();
settings.INSERT_OVERRIDE_ANNOTATION = false;
settings.getCustomSettings(JavaCodeStyleSettings.class).INSERT_OVERRIDE_ANNOTATION = false;
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(settings);
}
@@ -15,8 +15,8 @@
*/
package com.intellij.java.codeInsight.template.postfix.templates;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import org.jetbrains.annotations.NotNull;
public class ForeachTemplateTest extends PostfixTemplateTestCase {
@@ -43,7 +43,7 @@ public class ForeachTemplateTest extends PostfixTemplateTestCase {
}
public void testFinalLocals() {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
boolean oldGenerateFinalLocals = settings.GENERATE_FINAL_LOCALS;
try {
settings.GENERATE_FINAL_LOCALS = true;
@@ -1155,7 +1155,7 @@ public class JavaFormatterTest extends AbstractJavaFormatterTest {
}
public void testJavaDocLeadingAsterisksAreDisabled() throws Exception {
getSettings().getRootSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = false;
getJavaSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = false;
doTextTest("class Foo {\n" +
" /**\n" +
" @param i\n" +
@@ -1298,7 +1298,7 @@ public class JavaFormatterTest extends AbstractJavaFormatterTest {
getSettings().getRootSettings().getIndentOptions(StdFileTypes.JAVA).CONTINUATION_INDENT_SIZE = 2;
getSettings().getRootSettings().getIndentOptions(StdFileTypes.JAVA).TAB_SIZE = 4;
getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = false;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = false;
doTextTest("public interface PsiParser {\n" +
" /**\n" +
@@ -1750,7 +1750,7 @@ public class JavaFormatterTest extends AbstractJavaFormatterTest {
}
public void testFormatComments() throws Exception {
getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
doTextTest("public class Test {\n" + "\n" + " /**\n" + " * The s property.\n" + " */\n" + " private String s;\n" + "}",
"public class Test {\n" + "\n" + " /**\n" + " * The s property.\n" + " */\n" + " private String s;\n" + "}");
@@ -2789,7 +2789,7 @@ public void testSCR260() throws Exception {
}
public void testIDEADEV_6239() throws Exception {
getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
doTextTest("public class Test {\n" +
"\n" +
" /**\n" +
@@ -197,8 +197,8 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
public void testOneLineCommentWrappedByRightMarginIntoMultiLine() throws Exception {
getSettings().getRootSettings().WRAP_COMMENTS = true;
getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
getSettings().getRootSettings().JD_DO_NOT_WRAP_ONE_LINE_COMMENTS = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().JD_DO_NOT_WRAP_ONE_LINE_COMMENTS = true;
getSettings().RIGHT_MARGIN = 35;
doTextTest(
"/** Here is one-line java-doc comment */" +
@@ -215,7 +215,7 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
public void testLineFeedsArePreservedDuringWrap() {
// Inspired by IDEA-61895
getSettings().getRootSettings().WRAP_COMMENTS = true;
getSettings().getRootSettings().JD_PRESERVE_LINE_FEEDS = true;
getJavaSettings().JD_PRESERVE_LINE_FEEDS = true;
getSettings().RIGHT_MARGIN = 48;
doTextTest(
@@ -239,14 +239,14 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
final CommonCodeStyleSettings settings = getSettings();
settings.RIGHT_MARGIN = 50;
settings.getRootSettings().WRAP_COMMENTS = true;
settings.getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
settings.getRootSettings().JD_P_AT_EMPTY_LINES = false;
settings.getRootSettings().JD_KEEP_EMPTY_LINES = false;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().JD_P_AT_EMPTY_LINES = false;
getJavaSettings().JD_KEEP_EMPTY_LINES = false;
doTest();
}
public void testSCR2632() throws Exception {
getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
getSettings().getRootSettings().WRAP_COMMENTS = true;
getSettings().RIGHT_MARGIN = 20;
doTextTest("/**\n" +
@@ -266,7 +266,7 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
}
public void test_PreserveExistingSelfClosingTags_AndGenerateOnlyPTag() {
getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
LanguageLevel before = LanguageLevelProjectExtension.getInstance(getProject()).getLanguageLevel();
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7);
try {
@@ -296,8 +296,8 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
public void testParagraphTagGeneration() {
// Inspired by IDEA-61811
getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
getSettings().getRootSettings().JD_P_AT_EMPTY_LINES = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().JD_P_AT_EMPTY_LINES = true;
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7);
doTextTest(
"/**\n" +
@@ -329,8 +329,8 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
public void testParameterDescriptionNotOnNewLine() throws Exception {
// IDEA-107383
getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
getSettings().getRootSettings().JD_ALIGN_PARAM_COMMENTS = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().JD_ALIGN_PARAM_COMMENTS = true;
doClassTest(
"/**\n" +
@@ -353,9 +353,9 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
public void testWrappedParameterDescription() throws Exception {
// Inspired by IDEA-13072
getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
getSettings().getRootSettings().WRAP_COMMENTS = true;
getSettings().getRootSettings().JD_PARAM_DESCRIPTION_ON_NEW_LINE = true;
getJavaSettings().JD_PARAM_DESCRIPTION_ON_NEW_LINE = true;
doClassTest(
"/**\n" +
" * test description\n" +
@@ -385,8 +385,8 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
}
public void testExceptionAlignmentCorrect() {
getCurrentCodeStyleSettings().ENABLE_JAVADOC_FORMATTING = true;
getCurrentCodeStyleSettings().JD_ALIGN_EXCEPTION_COMMENTS = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().JD_ALIGN_EXCEPTION_COMMENTS = true;
String before =
"public class Controller {\n" +
@@ -422,8 +422,8 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
}
public void testDoNotWrapMultiLineCommentIntoOneLine() throws Exception {
getCurrentCodeStyleSettings().ENABLE_JAVADOC_FORMATTING = true;
getCurrentCodeStyleSettings().JD_DO_NOT_WRAP_ONE_LINE_COMMENTS = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().JD_DO_NOT_WRAP_ONE_LINE_COMMENTS = true;
String test = "/**\n" +
" * foo\n" +
" */\n" +
@@ -434,8 +434,8 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
}
public void testLeaveOneLineComment() throws Exception {
getCurrentCodeStyleSettings().ENABLE_JAVADOC_FORMATTING = true;
getCurrentCodeStyleSettings().JD_DO_NOT_WRAP_ONE_LINE_COMMENTS = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().JD_DO_NOT_WRAP_ONE_LINE_COMMENTS = true;
String test = "/** foo */\n" +
"public Object next() {\n" +
" return new Object();\n" +
@@ -444,8 +444,8 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
}
public void testWrapOneLineComment() throws Exception {
getCurrentCodeStyleSettings().ENABLE_JAVADOC_FORMATTING = true;
getCurrentCodeStyleSettings().JD_DO_NOT_WRAP_ONE_LINE_COMMENTS = false;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().JD_DO_NOT_WRAP_ONE_LINE_COMMENTS = false;
String test = "/** foo */\n" +
"public Object next() {\n" +
" return new Object();\n" +
@@ -460,8 +460,8 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
}
public void testWrapStrangeComment() throws Exception {
getCurrentCodeStyleSettings().ENABLE_JAVADOC_FORMATTING = true;
getCurrentCodeStyleSettings().JD_DO_NOT_WRAP_ONE_LINE_COMMENTS = false;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().JD_DO_NOT_WRAP_ONE_LINE_COMMENTS = false;
String test = "/** foo" +
" */\n" +
"public Object next() {\n" +
@@ -477,8 +477,8 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
}
public void testWrapStrangeCommentIfNotWrapOneLines() throws Exception {
getCurrentCodeStyleSettings().ENABLE_JAVADOC_FORMATTING = true;
getCurrentCodeStyleSettings().JD_DO_NOT_WRAP_ONE_LINE_COMMENTS = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().JD_DO_NOT_WRAP_ONE_LINE_COMMENTS = true;
String test = "/** foo\n" +
" */" +
"public Object next() {\n" +
@@ -495,9 +495,9 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
public void testReturnTagAlignment() throws Exception {
getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
getSettings().RIGHT_MARGIN = 80;
getSettings().getRootSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = true;
getJavaSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = true;
getSettings().getRootSettings().WRAP_COMMENTS = true;
getSettings().getRootSettings().getCommonSettings(JavaLanguage.INSTANCE).WRAP_LONG_LINES = true;
@@ -523,9 +523,9 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
public void testReturnTagAlignmentWithPreTagOnFirstLine() throws Exception {
getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
getSettings().RIGHT_MARGIN = 80;
getSettings().getRootSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = true;
getJavaSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = true;
getSettings().getRootSettings().WRAP_COMMENTS = true;
getSettings().getRootSettings().getCommonSettings(JavaLanguage.INSTANCE).WRAP_LONG_LINES = true;
@@ -550,8 +550,8 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
}
public void testDoNotMergeCommentLines() {
getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
getSettings().getRootSettings().JD_PRESERVE_LINE_FEEDS = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().JD_PRESERVE_LINE_FEEDS = true;
getSettings().getRootSettings().WRAP_COMMENTS = true;
doClassTest(
@@ -575,9 +575,9 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
}
public void testSeeTagAlignment() throws Exception {
getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
getSettings().RIGHT_MARGIN = 80;
getSettings().getRootSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = true;
getJavaSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = true;
getSettings().getRootSettings().WRAP_COMMENTS = true;
getSettings().getRootSettings().getCommonSettings(JavaLanguage.INSTANCE).WRAP_LONG_LINES = true;
@@ -602,9 +602,9 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
}
public void testDummySinceTagAlignment() throws Exception {
getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
getSettings().RIGHT_MARGIN = 80;
getSettings().getRootSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = true;
getJavaSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = true;
getSettings().getRootSettings().WRAP_COMMENTS = true;
getSettings().getRootSettings().getCommonSettings(JavaLanguage.INSTANCE).WRAP_LONG_LINES = true;
@@ -629,9 +629,9 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
}
public void testDummyDeprecatedTagAlignment() throws Exception {
getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
getSettings().RIGHT_MARGIN = 80;
getSettings().getRootSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = true;
getJavaSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = true;
getSettings().getRootSettings().WRAP_COMMENTS = true;
getSettings().getRootSettings().getCommonSettings(JavaLanguage.INSTANCE).WRAP_LONG_LINES = true;
@@ -657,12 +657,12 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
public void testJavadocFormattingIndependentOfMethodIndentation() {
getCurrentCodeStyleSettings().setRightMargin(JavaLanguage.INSTANCE, 50);
getCurrentCodeStyleSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
getCurrentCodeStyleSettings().WRAP_COMMENTS = true;
getCurrentCodeStyleSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = true;
getCurrentCodeStyleSettings().JD_P_AT_EMPTY_LINES = false;
getCurrentCodeStyleSettings().JD_KEEP_EMPTY_LINES = false;
getCurrentCodeStyleSettings().JD_ADD_BLANK_AFTER_DESCRIPTION = false;
getJavaSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = true;
getJavaSettings().JD_P_AT_EMPTY_LINES = false;
getJavaSettings().JD_KEEP_EMPTY_LINES = false;
getJavaSettings().JD_ADD_BLANK_AFTER_DESCRIPTION = false;
String before1 = "class A {\n" +
" /**\n" +
" * Some really great independent test approach purpose live fish\n" +
@@ -696,9 +696,9 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
public void testJavadocAlignmentForInnerClasses() {
getCurrentCodeStyleSettings().setRightMargin(JavaLanguage.INSTANCE, 40);
getCurrentCodeStyleSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
getCurrentCodeStyleSettings().WRAP_COMMENTS = true;
getCurrentCodeStyleSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = true;
getJavaSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = true;
String code = "public class Outer {\n" +
" class Inner {\n" +
@@ -747,7 +747,7 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
public void testAlignmentWithNoTopClassMembersIndentation() {
getCurrentCodeStyleSettings().setRightMargin(JavaLanguage.INSTANCE, 40);
getCurrentCodeStyleSettings().WRAP_COMMENTS = true;
getCurrentCodeStyleSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = true;
getJavaSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = true;
getCurrentCodeStyleSettings().getCommonSettings(JavaLanguage.INSTANCE).DO_NOT_INDENT_TOP_LEVEL_CLASS_MEMBERS = true;
String before = "public class Outer {\n" +
@@ -833,8 +833,8 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
public void testNotGenerateSelfClosingPTagIfLanguageLevelJava8() throws Exception {
getSettings().getRootSettings().JD_P_AT_EMPTY_LINES = true;
getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().JD_P_AT_EMPTY_LINES = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
String before = "/**\n" +
" * Super method\n" +
" *\n" +
@@ -853,8 +853,8 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
}
public void testPTagIfLanguageLevelNotJava8() throws Exception {
getSettings().getRootSettings().JD_P_AT_EMPTY_LINES = true;
getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().JD_P_AT_EMPTY_LINES = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7);
String before = "/**\n" +
" * Super method\n" +
@@ -874,8 +874,8 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
}
public void test_DoNotTouch_SingleLineComments() {
getSettings().getRootSettings().JD_DO_NOT_WRAP_ONE_LINE_COMMENTS = true;
getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().JD_DO_NOT_WRAP_ONE_LINE_COMMENTS = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
doClassTest(
"/****** AAAAAAA *******/\n" +
@@ -890,8 +890,8 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
}
public void test_Keep_P_Tags() {
getSettings().getRootSettings().JD_P_AT_EMPTY_LINES = true;
getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
getJavaSettings().JD_P_AT_EMPTY_LINES = true;
getJavaSettings().ENABLE_JAVADOC_FORMATTING = true;
doClassTest(
"/**\n" +
@@ -945,9 +945,9 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
getCurrentCodeStyleSettings().getIndentOptions(JavaFileType.INSTANCE).CONTINUATION_INDENT_SIZE = 2;
getCurrentCodeStyleSettings().JD_INDENT_ON_CONTINUATION = true;
getCurrentCodeStyleSettings().JD_ALIGN_PARAM_COMMENTS = false;
getCurrentCodeStyleSettings().JD_ALIGN_EXCEPTION_COMMENTS = false;
getJavaSettings().JD_INDENT_ON_CONTINUATION = true;
getJavaSettings().JD_ALIGN_PARAM_COMMENTS = false;
getJavaSettings().JD_ALIGN_EXCEPTION_COMMENTS = false;
getCurrentCodeStyleSettings().WRAP_COMMENTS = true;
doClassTest(
@@ -19,6 +19,7 @@ import com.intellij.java.psi.GenericsTestCase;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.search.GlobalSearchScope;
/**
@@ -33,14 +34,14 @@ public class BindToGenericClassTest extends GenericsTestCase {
setupGenericSampleClasses();
final CodeStyleSettings currentSettings = CodeStyleSettingsManager.getInstance(myProject).getCurrentSettings();
myOldFQNamesSetting = currentSettings.USE_FQ_CLASS_NAMES;
currentSettings.USE_FQ_CLASS_NAMES = true;
myOldFQNamesSetting = currentSettings.getCustomSettings(JavaCodeStyleSettings.class).USE_FQ_CLASS_NAMES;
currentSettings.getCustomSettings(JavaCodeStyleSettings.class).USE_FQ_CLASS_NAMES = true;
}
@Override
protected void tearDown() throws Exception {
final CodeStyleSettings currentSettings = CodeStyleSettingsManager.getInstance(myProject).getCurrentSettings();
currentSettings.USE_FQ_CLASS_NAMES = myOldFQNamesSetting;
currentSettings.getCustomSettings(JavaCodeStyleSettings.class).USE_FQ_CLASS_NAMES = myOldFQNamesSetting;
super.tearDown();
}
@@ -20,8 +20,8 @@ import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.CodeInsightUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiExpression;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.refactoring.extractMethodObject.ExtractMethodObjectHandler;
import com.intellij.refactoring.extractMethodObject.ExtractMethodObjectProcessor;
import org.jetbrains.annotations.NotNull;
@@ -165,7 +165,7 @@ public class ExtractMethodObjectWithMultipleExitPointsTest extends LightRefactor
}
private void doTestWithIdeaCodeStyleSettings() throws Exception {
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
final JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
String oldPrefix = settings.FIELD_NAME_PREFIX;
settings.FIELD_NAME_PREFIX = "my";
boolean oldPrefer = settings.PREFER_LONGER_NAMES;
@@ -27,6 +27,7 @@ import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.refactoring.extractMethod.ExtractMethodHandler;
@@ -266,7 +267,7 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
}
public void testFinalParamUsedInsideAnon() throws Exception {
CodeStyleSettingsManager.getSettings(getProject()).GENERATE_FINAL_PARAMETERS = false;
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS = false;
doTestWithJava17();
}
@@ -283,7 +284,7 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
}
public void testNonFinalWritableParam() throws Exception {
CodeStyleSettingsManager.getSettings(getProject()).GENERATE_FINAL_PARAMETERS = true;
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS = true;
doTest();
}
@@ -547,7 +548,7 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
}
public void testReassignedVarAfterCall() throws Exception {
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
final JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
boolean oldGenerateFinalLocals = settings.GENERATE_FINAL_LOCALS;
try {
settings.GENERATE_FINAL_LOCALS = true;
@@ -862,7 +863,7 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
}
public void testDefaultNamesConflictResolution() throws Exception {
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
final JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
final String oldPrefix = settings.LOCAL_VARIABLE_NAME_PREFIX;
try {
settings.LOCAL_VARIABLE_NAME_PREFIX = "_";
@@ -26,8 +26,8 @@ import com.intellij.openapi.util.Pass;
import com.intellij.psi.PsiExpression;
import com.intellij.psi.PsiLiteralExpression;
import com.intellij.psi.PsiLocalVariable;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.refactoring.introduce.inplace.AbstractInplaceIntroducer;
@@ -63,7 +63,7 @@ public class InplaceIntroduceVariableTest extends AbstractJavaInplaceIntroduceTe
}
public void testConflictingInnerClassName() throws Exception {
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
final JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
final boolean oldOption = settings.INSERT_INNER_CLASS_IMPORTS;
try {
settings.INSERT_INNER_CLASS_IMPORTS = true;
@@ -19,8 +19,8 @@ import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.TargetElementUtil;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.refactoring.makeStatic.MakeClassStaticProcessor;
import com.intellij.refactoring.makeStatic.MakeStaticUtil;
import com.intellij.refactoring.makeStatic.Settings;
@@ -64,7 +64,7 @@ public class MakeClassStaticTest extends LightRefactoringTestCase {
}
public void testFieldWithMyPrefix() throws Exception {
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
final JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
String oldPrefix = settings.FIELD_NAME_PREFIX;
settings.FIELD_NAME_PREFIX = "my";
try {
@@ -23,6 +23,7 @@ import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
import com.intellij.psi.search.ProjectScope;
import com.intellij.refactoring.RefactoringTestCase;
@@ -56,13 +57,14 @@ public class MoveClassToInnerTest extends RefactoringTestCase {
}
public void testInsertInnerClassImport() throws Exception {
final boolean imports = CodeStyleSettingsManager.getSettings(myProject).INSERT_INNER_CLASS_IMPORTS;
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class);
final boolean imports = settings.INSERT_INNER_CLASS_IMPORTS;
try {
CodeStyleSettingsManager.getSettings(myProject).INSERT_INNER_CLASS_IMPORTS = true;
settings.INSERT_INNER_CLASS_IMPORTS = true;
doTest(new String[] { "pack1.Class1" }, "pack2.A");
}
finally {
CodeStyleSettingsManager.getSettings(myProject).INSERT_INNER_CLASS_IMPORTS = imports;
settings.INSERT_INNER_CLASS_IMPORTS = imports;
}
}
@@ -12,6 +12,7 @@ import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.impl.AllowedApiFilterExtension;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiUtil;
@@ -134,7 +135,7 @@ public class ConvertFieldToAtomicIntention extends PsiElementBaseIntentionAction
static void postProcessVariable(@NotNull PsiVariable var, @NotNull String toType) {
Project project = var.getProject();
if (var instanceof PsiField || CodeStyleSettingsManager.getSettings(project).GENERATE_FINAL_LOCALS) {
if (var instanceof PsiField || CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS) {
PsiModifierList modifierList = assertNotNull(var.getModifierList());
WriteAction.run(() -> {
if (var.getInitializer() == null) {
@@ -26,7 +26,7 @@ class CodeStyleTest {
@Test fun `do not remove unknown`() {
val settings = CodeStyleSettings()
val loaded = """
<code_scheme name="testSchemeName">
<code_scheme name="testSchemeName" version="${CodeStyleSettings.CURR_VERSION}">
<UnknownDoNotRemoveMe>
<option name="ALIGN_OBJECT_PROPERTIES" value="2" />
</UnknownDoNotRemoveMe>
@@ -105,7 +105,7 @@ class CodeStyleTest {
val settings = CodeStyleSettings()
val text : (param: String) -> String = { param ->
"""
<code_scheme name="testSchemeName">
<code_scheme name="testSchemeName" version="${CodeStyleSettings.CURR_VERSION}">
<NewComponent>
<option name="MAIN" value="${param}" />
</NewComponent>
@@ -136,4 +136,24 @@ class CodeStyleTest {
Disposer.dispose(disposable)
}
}
@Test fun `reset deprecations`() {
val settings = CodeStyleSettings()
val initial = """
<code_scheme name="testSchemeName">
<option name="RIGHT_MARGIN" value="64" />
<option name="USE_FQ_CLASS_NAMES_IN_JAVADOC" value="false" />
</code_scheme>""".trimIndent()
val expected = """
<code_scheme name="testSchemeName" version="${CodeStyleSettings.CURR_VERSION}">
<option name="RIGHT_MARGIN" value="64" />
</code_scheme>""".trimIndent();
settings.readExternal(loadElement(initial))
settings.resetDeprecatedFields()
val serialized = Element("code_scheme").setAttribute("name", "testSchemeName")
settings.writeExternal(serialized)
assertThat(JDOMUtil.writeElement(serialized)).isEqualTo(expected)
}
}
@@ -22,6 +22,9 @@ public interface CodeStyleScheme extends Scheme {
String DEFAULT_SCHEME_NAME = "Default";
String PROJECT_SCHEME_NAME = "Project";
String CODE_STYLE_TAG_NAME = "code_scheme";
String CODE_STYLE_NAME_ATTR = "name";
@Override
@NotNull
String getName();
@@ -45,14 +45,18 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import javax.swing.*;
import java.lang.reflect.Field;
import java.util.*;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
public class CodeStyleSettings extends CommonCodeStyleSettings implements Cloneable, JDOMExternalizable, ImportsLayoutSettings {
public static final int CURR_VERSION = 173;
public static final int MAX_RIGHT_MARGIN = 1000;
private static final Logger LOG = Logger.getInstance(CodeStyleSettings.class);
public static final String VERSION_ATTR = "version";
private final ClassMap<CustomCodeStyleSettings> myCustomSettings = new ClassMap<>();
@@ -66,6 +70,8 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
private UnknownElementWriter myUnknownElementWriter = UnknownElementWriter.EMPTY;
private int myVersion = CURR_VERSION;
public CodeStyleSettings() {
this(true);
}
@@ -187,13 +193,6 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
public boolean AUTODETECT_INDENTS = true;
@Deprecated
public final IndentOptions JAVA_INDENT_OPTIONS = new IndentOptions();
@Deprecated
public final IndentOptions JSP_INDENT_OPTIONS = new IndentOptions();
@Deprecated
public final IndentOptions XML_INDENT_OPTIONS = new IndentOptions();
public final IndentOptions OTHER_INDENT_OPTIONS = new IndentOptions();
private final Map<FileType,IndentOptions> myAdditionalIndentOptions = new LinkedHashMap<>();
@@ -216,46 +215,90 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
// region Java settings (legacy)
//----------------- NAMING CONVENTIONS --------------------
/** @deprecated Use JavaCodeStyleSettings.FIELD_NAME_PREFIX */
@Deprecated
public String FIELD_NAME_PREFIX = "";
/** @deprecated Use JavaCodeStyleSettings.STATIC_FIELD_NAME_PREFIX */
@Deprecated
public String STATIC_FIELD_NAME_PREFIX = "";
/** @deprecated Use JavaCodeStyleSettings.PARAMETER_NAME_PREFIX */
@Deprecated
public String PARAMETER_NAME_PREFIX = "";
/** @deprecated Use JavaCodeStyleSettings.LOCAL_VARIABL_NAME_PREFIX */
@Deprecated
public String LOCAL_VARIABLE_NAME_PREFIX = "";
/** @deprecated Use JavaCodeStyleSettings.FIELD_NAME_SUFFIX */
@Deprecated
public String FIELD_NAME_SUFFIX = "";
/** @deprecated Use JavaCodeStyleSettings.STATIC_FIELD_NAME_SUFFIX */
@Deprecated
public String STATIC_FIELD_NAME_SUFFIX = "";
/** @deprecated Use JavaCodeStyleSettings.PARAMETER_NAME_SUFFIX */
@Deprecated
public String PARAMETER_NAME_SUFFIX = "";
/** @deprecated Use JavaCodeStyleSettings.LOCAL_VARIABLE_NAME_SUFFIX */
@Deprecated
public String LOCAL_VARIABLE_NAME_SUFFIX = "";
/** @deprecated Use JavaCodeStyleSettings.PREFER_LONGER_NAMES */
@Deprecated
public boolean PREFER_LONGER_NAMES = true;
/** @deprecated Use JavaCodeStyleSettings.FILED_TYPE_TO_NAME */
@Deprecated
public final TypeToNameMap FIELD_TYPE_TO_NAME = new TypeToNameMap();
/** @deprecated Use JavaCodeStyleSettings.STATIC_FIELD_TYPE_TO_NAME */
@Deprecated
public final TypeToNameMap STATIC_FIELD_TYPE_TO_NAME = new TypeToNameMap();
/** @deprecated Use JavaCodeStyleSettings.PARAMETER_TYPE_TO_NAME */
@Deprecated
@NonNls public final TypeToNameMap PARAMETER_TYPE_TO_NAME = new TypeToNameMap();
/** @deprecated Use JavaCodeStyleSettings.LOCAL_VARIABLE_TYPE_TO_NAME */
@Deprecated
public final TypeToNameMap LOCAL_VARIABLE_TYPE_TO_NAME = new TypeToNameMap();
//----------------- 'final' modifier settings -------
/** @deprecated Use JavaCodeStyleSettings.GENERATE_FINAL_LOCALS */
@Deprecated
public boolean GENERATE_FINAL_LOCALS;
/** @deprecated Use JavaCodeStyleSettings.GENERATE_FINAL_PARAMETERS */
@Deprecated
public boolean GENERATE_FINAL_PARAMETERS;
//----------------- visibility -----------------------------
/** @deprecated Use JavaCodeStyleSettings.VISIBILITY */
@Deprecated
public String VISIBILITY = "public";
//----------------- generate parentheses around method arguments ----------
/** @deprecated Use RubyCodeStyleSettings.PARENTHESES_AROUND_METHOD_ARGUMENTS */
@Deprecated
public boolean PARENTHESES_AROUND_METHOD_ARGUMENTS = true;
//----------------- annotations ----------------
/** @deprecated Use JavaCodeStyleSettings.USE_EXTERNAL_ANNOTATIONS */
@Deprecated
public boolean USE_EXTERNAL_ANNOTATIONS;
/** @deprecated Use JavaCodeStyleSettings.INSERT_OVERRIDE_ANNOTATIONS */
@Deprecated
public boolean INSERT_OVERRIDE_ANNOTATION = true;
//----------------- override -------------------
/** @deprecated Use JavaCodeStyleSettings.REPEAT_SYNCHRONIZED */
@Deprecated
public boolean REPEAT_SYNCHRONIZED = true;
private List<String> myRepeatAnnotations = new ArrayList<>();
/** @deprecated Use JavaCodeStyleSettings.getRepeatAnnotations() */
@Deprecated
public List<String> getRepeatAnnotations() {
return myRepeatAnnotations;
}
/** @deprecated Use JavaCodeStyleSettings.setRepeatAnnotations() */
@Deprecated
public void setRepeatAnnotations(List<String> repeatAnnotations) {
myRepeatAnnotations.clear();
myRepeatAnnotations.addAll(repeatAnnotations);
@@ -263,91 +306,142 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
//----------------- FUNCTIONAL EXPRESSIONS -----
/** @deprecated Use JavaCodeStyleSettings.REPLACE_INSTANCE_OF */
@Deprecated
public boolean REPLACE_INSTANCEOF = false;
/** @deprecated Use JavaCodeStyleSettings.REPLACE_CAST */
@Deprecated
public boolean REPLACE_CAST = false;
/** @deprecated Use JavaCodeStyleSettings.REPLACE_NULL_CHECK */
@Deprecated
public boolean REPLACE_NULL_CHECK = true;
//----------------- IMPORTS --------------------
//----------------- JAVA IMPORTS (deprecated, moved to JavaCodeStyleSettings) --------------------
/** @deprecated Use JavaCodeStyleSettings.LAYOUT_STATIC_IMPORTS_SEPARATELY */
@SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
public boolean LAYOUT_STATIC_IMPORTS_SEPARATELY = true;
/** @deprecated Use JavaCodeStyleSettings.USE_FQ_CLASS_NAMES */
@SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
public boolean USE_FQ_CLASS_NAMES;
/** @deprecated use com.intellij.psi.codeStyle.JavaCodeStyleSettings.CLASS_NAMES_IN_JAVADOC */
@Deprecated
public boolean USE_FQ_CLASS_NAMES_IN_JAVADOC = true;
/** @deprecated Use JavaCodeStyleSettings.USE_SINGLE_CLASS_IMPORTS */
@SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
public boolean USE_SINGLE_CLASS_IMPORTS = true;
/** @deprecated Use JavaCodeStyleSettings.INSERT_INNER_CLASS_IMPORTS */
@SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
public boolean INSERT_INNER_CLASS_IMPORTS;
/** @deprecated Use JavaCodeStyleSettings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND */
@SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
public int CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 5;
/** @deprecated Use JavaCodeStyleSettings.NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND */
@SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
public int NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND = 3;
/** @deprecated Use JavaCodeStyleSettings.PACKAGES_TO_USE_IMPORT_ON_DEMAND */
@SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
public final PackageEntryTable PACKAGES_TO_USE_IMPORT_ON_DEMAND = new PackageEntryTable();
/** @deprecated Use JavaCodeStyleSettings.IMPORT_LAYOUT_TABLE */
@SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
public final PackageEntryTable IMPORT_LAYOUT_TABLE = new PackageEntryTable();
@Override
@Deprecated
public boolean isLayoutStaticImportsSeparately() {
return LAYOUT_STATIC_IMPORTS_SEPARATELY;
}
@Override
@Deprecated
public void setLayoutStaticImportsSeparately(boolean value) {
LAYOUT_STATIC_IMPORTS_SEPARATELY = value;
}
@Deprecated
@Override
public int getNamesCountToUseImportOnDemand() {
return NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND;
}
@Deprecated
@Override
public void setNamesCountToUseImportOnDemand(int value) {
NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND = value;
}
@Deprecated
@Override
public int getClassCountToUseImportOnDemand() {
return CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND;
}
@Deprecated
@Override
public void setClassCountToUseImportOnDemand(int value) {
CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = value;
}
@Deprecated
@Override
public boolean isInsertInnerClassImports() {
return INSERT_INNER_CLASS_IMPORTS;
}
@Deprecated
@Override
public void setInsertInnerClassImports(boolean value) {
INSERT_INNER_CLASS_IMPORTS = value;
}
@Deprecated
@Override
public boolean isUseSingleClassImports() {
return USE_SINGLE_CLASS_IMPORTS;
}
@Deprecated
@Override
public void setUseSingleClassImports(boolean value) {
USE_SINGLE_CLASS_IMPORTS = value;
}
@Deprecated
@Override
public boolean isUseFqClassNames() {
return USE_FQ_CLASS_NAMES;
}
@Deprecated
@Override
public void setUseFqClassNames(boolean value) {
USE_FQ_CLASS_NAMES = value;
}
@Deprecated
@Override
public PackageEntryTable getImportLayoutTable() {
return IMPORT_LAYOUT_TABLE;
}
@Deprecated
@Override
public PackageEntryTable getPackagesToUseImportOnDemand() {
return PACKAGES_TO_USE_IMPORT_ON_DEMAND;
@@ -357,13 +451,13 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
// region ORDER OF MEMBERS
public int STATIC_FIELDS_ORDER_WEIGHT = 1;
public int FIELDS_ORDER_WEIGHT = 2;
public int CONSTRUCTORS_ORDER_WEIGHT = 3;
public int STATIC_METHODS_ORDER_WEIGHT = 4;
public int METHODS_ORDER_WEIGHT = 5;
public int STATIC_INNER_CLASSES_ORDER_WEIGHT = 6;
public int INNER_CLASSES_ORDER_WEIGHT = 7;
@Deprecated public int STATIC_FIELDS_ORDER_WEIGHT = 1;
@Deprecated public int FIELDS_ORDER_WEIGHT = 2;
@Deprecated public int CONSTRUCTORS_ORDER_WEIGHT = 3;
@Deprecated public int STATIC_METHODS_ORDER_WEIGHT = 4;
@Deprecated public int METHODS_ORDER_WEIGHT = 5;
@Deprecated public int STATIC_INNER_CLASSES_ORDER_WEIGHT = 6;
@Deprecated public int INNER_CLASSES_ORDER_WEIGHT = 7;
// endregion
@@ -371,7 +465,7 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
/**
* @deprecated Use get/setRightMargin() methods instead.
*/
@Deprecated
@SuppressWarnings("DeprecatedIsStillUsed")
public int RIGHT_MARGIN = 120;
/**
* <b>Do not use this field directly since it doesn't reflect a setting for a specific language which may
@@ -385,100 +479,108 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
// region Javadoc formatting options
/**
* @deprecated Use JavaCodeStyleSettings.ENABLE_JAVADOC_FORMATTING
*/
@Deprecated
public boolean ENABLE_JAVADOC_FORMATTING = true;
/**
* Align parameter comments to longest parameter name
* Align parameter comments to longest parameter name.JD_ALIGN_PARAM_COMMENTS
* @deprecated Use JavaCodeStyleSettings.JD_ALIGN_PARAM_COMMENTS
*/
@Deprecated
public boolean JD_ALIGN_PARAM_COMMENTS = true;
/**
* Align exception comments to longest exception name
* @deprecated Use JavaCodeStyleSettings.JD_ALIGN_EXCEPTION_COMMENTS
*/
@Deprecated
public boolean JD_ALIGN_EXCEPTION_COMMENTS = true;
/**
* @deprecated Use JavaCodeStyleSettings.
*/
@Deprecated
public boolean JD_ADD_BLANK_AFTER_PARM_COMMENTS;
/**
* @deprecated Use JavaCodeStyleSettings.
*/
@Deprecated
public boolean JD_ADD_BLANK_AFTER_RETURN;
/**
* @deprecated Use JavaCodeStyleSettings.
*/
@Deprecated
public boolean JD_ADD_BLANK_AFTER_DESCRIPTION = true;
/**
* @deprecated Use JavaCodeStyleSettings.
*/
@Deprecated
public boolean JD_P_AT_EMPTY_LINES = true;
/**
* @deprecated Use JavaCodeStyleSettings.
*/
@Deprecated
public boolean JD_KEEP_INVALID_TAGS = true;
/**
* @deprecated Use JavaCodeStyleSettings.
*/
@Deprecated
public boolean JD_KEEP_EMPTY_LINES = true;
/**
* @deprecated Use JavaCodeStyleSettings.
*/
@Deprecated
public boolean JD_DO_NOT_WRAP_ONE_LINE_COMMENTS;
/**
* @deprecated Use JavaCodeStyleSettings.
*/
@Deprecated
public boolean JD_USE_THROWS_NOT_EXCEPTION = true;
/**
* @deprecated Use JavaCodeStyleSettings.
*/
@Deprecated
public boolean JD_KEEP_EMPTY_PARAMETER = true;
/**
* @deprecated Use JavaCodeStyleSettings.
*/
@Deprecated
public boolean JD_KEEP_EMPTY_EXCEPTION = true;
/**
* @deprecated Use JavaCodeStyleSettings.
*/
@Deprecated
public boolean JD_KEEP_EMPTY_RETURN = true;
/**
* @deprecated Use JavaCodeStyleSettings.JD_LEADING_ASTERISKS_ARE_ENABLED
*/
@Deprecated
public boolean JD_LEADING_ASTERISKS_ARE_ENABLED = true;
/**
* @deprecated Use JavaCodeStyleSettings.JD_PRESERVE_LINE_FEEDS
*/
@Deprecated
public boolean JD_PRESERVE_LINE_FEEDS;
/**
* @deprecated Use JavaCodeStyleSettings.JD_PARAM_DESCRIPTION_ON_NEW_LINE
*/
@Deprecated
public boolean JD_PARAM_DESCRIPTION_ON_NEW_LINE;
/**
* @deprecated Use JavaCodeStyleSettings.JD_INDENT_ON_CONTINUATION
*/
@Deprecated
public boolean JD_INDENT_ON_CONTINUATION = false;
// endregion
// region Legacy(!) XML formatting options
/**
* @deprecated Use XmlCodeStyleSettings.
*/
public boolean XML_KEEP_WHITESPACES;
/**
* @deprecated Use XmlCodeStyleSettings.
*/
public int XML_ATTRIBUTE_WRAP = WRAP_AS_NEEDED;
/**
* @deprecated Use XmlCodeStyleSettings.
*/
public int XML_TEXT_WRAP = WRAP_AS_NEEDED;
/**
* @deprecated Use XmlCodeStyleSettings.
*/
public boolean XML_KEEP_LINE_BREAKS = true;
/**
* @deprecated Use XmlCodeStyleSettings.
*/
public boolean XML_KEEP_LINE_BREAKS_IN_TEXT = true;
/**
* @deprecated Use XmlCodeStyleSettings.
*/
public int XML_KEEP_BLANK_LINES = 2;
/**
* @deprecated Use XmlCodeStyleSettings.
*/
public boolean XML_ALIGN_ATTRIBUTES = true;
/**
* @deprecated Use XmlCodeStyleSettings.
*/
public boolean XML_ALIGN_TEXT;
/**
* @deprecated Use XmlCodeStyleSettings.
*/
public boolean XML_SPACE_AROUND_EQUALITY_IN_ATTRIBUTE;
/**
* @deprecated Use XmlCodeStyleSettings.
*/
public boolean XML_SPACE_AFTER_TAG_NAME;
/**
* @deprecated Use XmlCodeStyleSettings.
*/
public boolean XML_SPACE_INSIDE_EMPTY_TAG;
/**
* @deprecated Use XmlCodeStyleSettings.
*/
public boolean XML_KEEP_WHITE_SPACES_INSIDE_CDATA;
/**
* @deprecated Use XmlCodeStyleSettings.
*/
public int XML_WHITE_SPACE_AROUND_CDATA;
// endregion
// region HTML formatting options (legacy)
public boolean HTML_KEEP_WHITESPACES;
@@ -512,9 +614,7 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
// endregion
// true if <%page import="x.y.z, x.y.t"%>
// false if <%page import="x.y.z"%>
// <%page import="x.y.t"%>
@Deprecated
public boolean JSP_PREFER_COMMA_SEPARATED_IMPORT_LIST;
//----------------------------------------------------------------------------------------
@@ -580,8 +680,28 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
}
}
private static void setVersion(@NotNull Element element, int version) {
element.setAttribute(VERSION_ATTR, Integer.toString(version));
}
private static int getVersion(@NotNull Element element) {
String versionStr = element.getAttributeValue(VERSION_ATTR);
if (versionStr == null) {
return 0;
}
else {
try {
return Integer.parseInt(versionStr);
}
catch (NumberFormatException nfe) {
return CURR_VERSION;
}
}
}
@Override
public void readExternal(Element element) throws InvalidDataException {
myVersion = getVersion(element);
DefaultJDOMExternalizer.readExternal(this, element);
if (LAYOUT_STATIC_IMPORTS_SEPARATELY) {
// add <all other static imports> entry if there is none
@@ -639,10 +759,13 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
if (USE_SAME_INDENTS) {
IGNORE_SAME_INDENTS_FOR_LANGUAGES = true;
}
migrateLegacySettings();
}
@Override
public void writeExternal(Element element) throws WriteExternalException {
setVersion(element, myVersion);
CodeStyleSettings parentSettings = new CodeStyleSettings();
DefaultJDOMExternalizer.writeExternal(this, element, new DifferenceFilter<>(this, parentSettings));
@@ -854,18 +977,6 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
return getIndentOptions(fileType).USE_TAB_CHARACTER;
}
//used in generate equals/hashCode
@SuppressWarnings("unused")
public boolean isGenerateFinalLocals() {
return GENERATE_FINAL_LOCALS;
}
//used in generate equals/hashCode
@SuppressWarnings("unused")
public boolean isGenerateFinalParameters() {
return GENERATE_FINAL_PARAMETERS;
}
public static class TypeToNameMap implements JDOMExternalizable {
private final List<String> myPatterns = new ArrayList<>();
private final List<String> myNames = new ArrayList<>();
@@ -1164,4 +1275,31 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
}
return myDefaults;
}
private void migrateLegacySettings() {
if (myVersion < CURR_VERSION) {
for (CustomCodeStyleSettings settings : myCustomSettings.values()) {
settings.importLegacySettings(this);
}
myVersion = CURR_VERSION;
}
}
@SuppressWarnings("deprecation")
public void resetDeprecatedFields() {
CodeStyleSettings defaults = getDefaults();
ReflectionUtil.copyFields(this.getClass().getFields(), defaults, this, new DifferenceFilter<CodeStyleSettings>(this, defaults){
@Override
public boolean isAccept(@NotNull Field field) {
return field.getAnnotation(Deprecated.class) != null;
}
});
IMPORT_LAYOUT_TABLE.copyFrom(defaults.IMPORT_LAYOUT_TABLE);
PACKAGES_TO_USE_IMPORT_ON_DEMAND.copyFrom(defaults.PACKAGES_TO_USE_IMPORT_ON_DEMAND);
myRepeatAnnotations.clear();
}
public int getVersion() {
return myVersion;
}
}
@@ -30,10 +30,19 @@ import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.lang.reflect.Field;
public class CodeStyleSettingsManager implements PersistentStateComponent<Element> {
private static final Logger LOG = Logger.getInstance(CodeStyleSettingsManager.class);
/**
* Use {@code get/setMainProjectCodeStyle()} instead
* @Deprecated
*/
@SuppressWarnings("DeprecatedIsStillUsed") @Deprecated
@Nullable
public volatile CodeStyleSettings PER_PROJECT_SETTINGS;
public volatile boolean USE_PER_PROJECT_SETTINGS;
public volatile String PREFERRED_PROJECT_CODE_STYLE;
private volatile CodeStyleSettings myTemporarySettings;
@@ -41,7 +50,7 @@ public class CodeStyleSettingsManager implements PersistentStateComponent<Elemen
public static CodeStyleSettingsManager getInstance(@Nullable Project project) {
if (project == null || project.isDefault()) return getInstance();
ProjectCodeStyleSettingsManager projectSettingsManager = ServiceManager.getService(project, ProjectCodeStyleSettingsManager.class);
projectSettingsManager.importLegacySettings(project);
projectSettingsManager.initProjectSettings(project);
return projectSettingsManager;
}
@@ -63,7 +72,7 @@ public class CodeStyleSettingsManager implements PersistentStateComponent<Elemen
public CodeStyleSettings getCurrentSettings() {
CodeStyleSettings temporarySettings = myTemporarySettings;
if (temporarySettings != null) return temporarySettings;
CodeStyleSettings projectSettings = PER_PROJECT_SETTINGS;
CodeStyleSettings projectSettings = getMainProjectCodeStyle();
if (USE_PER_PROJECT_SETTINGS && projectSettings != null) return projectSettings;
return CodeStyleSchemes.getInstance().findPreferredScheme(PREFERRED_PROJECT_CODE_STYLE).getCodeStyleSettings();
}
@@ -72,7 +81,12 @@ public class CodeStyleSettingsManager implements PersistentStateComponent<Elemen
public Element getState() {
Element result = new Element("state");
try {
DefaultJDOMExternalizer.writeExternal(this, result, new DifferenceFilter<>(this, new CodeStyleSettingsManager()));
DefaultJDOMExternalizer.writeExternal(this, result, new DifferenceFilter<CodeStyleSettingsManager>(this, new CodeStyleSettingsManager()){
@Override
public boolean isAccept(@NotNull Field field) {
return !isIgnoredOnSave(field.getName()) && super.isAccept(field);
}
});
}
catch (WriteExternalException e) {
LOG.error(e);
@@ -80,6 +94,10 @@ public class CodeStyleSettingsManager implements PersistentStateComponent<Elemen
return result;
}
protected boolean isIgnoredOnSave(@NotNull String fieldName) {
return false;
}
@Override
public void loadState(Element state) {
try {
@@ -90,6 +108,24 @@ public class CodeStyleSettingsManager implements PersistentStateComponent<Elemen
}
}
/**
* Sets main project settings by the name "Project". For default project it's the only named code style.
* @param settings The code style settings which can be assigned to project.
*/
public void setMainProjectCodeStyle(@Nullable CodeStyleSettings settings) {
//noinspection deprecation
PER_PROJECT_SETTINGS = settings;
}
/**
* @return The main project code style settings. For default project, that's the only code style.
*/
@Nullable
public CodeStyleSettings getMainProjectCodeStyle() {
//noinspection deprecation
return PER_PROJECT_SETTINGS;
}
@Deprecated
public boolean isLoaded() {
return true;
@@ -421,6 +421,8 @@ public class CommonCodeStyleSettings {
public boolean ALIGN_MULTILINE_PARAMETERS_IN_CALLS = false;
public boolean ALIGN_MULTILINE_RESOURCES = true;
public boolean ALIGN_MULTILINE_FOR = true;
/** @deprecated Use RubyCodeStyleSettings.INDENT_WITH_CASES */
@Deprecated
public boolean INDENT_WHEN_CASES = true;
public boolean ALIGN_MULTILINE_BINARY_OPERATION = false;
@@ -60,7 +60,6 @@ public abstract class CustomCodeStyleSettings implements Cloneable {
Element child = parentElement.getChild(myTagName);
if (child != null) {
DefaultJDOMExternalizer.readExternal(this, child);
importLegacySettings();
}
}
@@ -85,7 +84,7 @@ public abstract class CustomCodeStyleSettings implements Cloneable {
/**
* For compatibility with old code style settings stored in CodeStyleSettings.
*/
protected void importLegacySettings() {
protected void importLegacySettings(@NotNull CodeStyleSettings rootSettings) {
}
@Override
@@ -21,11 +21,11 @@ import com.intellij.openapi.components.Storage;
import org.jdom.Element;
/**
* Supports old code style settings (before version 11.x). The settings are returned as is without any
* Supports old code style settings (before version 2017.3). The settings are returned as is without any
* changes.
* @author Rustam Vishnyakov
*/
@State(name = "CodeStyleSettingsManager", storages = @Storage("projectCodeStyle.xml"))
@State(name = "ProjectCodeStyleSettingsManager", storages = @Storage("codeStyleSettings.xml"))
public class LegacyCodeStyleSettingsManager implements PersistentStateComponent<Element> {
private Element myState;
@@ -16,23 +16,47 @@
package com.intellij.psi.codeStyle;
import com.intellij.openapi.components.MainConfigurationStateSplitter;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.util.containers.ContainerUtil;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import static com.intellij.psi.codeStyle.CodeStyleScheme.CODE_STYLE_NAME_ATTR;
import static com.intellij.psi.codeStyle.CodeStyleScheme.CODE_STYLE_TAG_NAME;
@State(name = "ProjectCodeStyleSettingsManager", storages = @Storage("codeStyleSettings.xml"))
public class ProjectCodeStyleSettingsManager extends CodeStyleSettingsManager{
@State(
name = "ProjectCodeStyleConfiguration",
storages = @Storage(value = "codeStyles", stateSplitter = ProjectCodeStyleSettingsManager.StateSplitter.class)
)
public class ProjectCodeStyleSettingsManager extends CodeStyleSettingsManager {
private static final Logger LOG = Logger.getInstance("#" + ProjectCodeStyleSettingsManager.class);
public static final String MAIN_PROJECT_CODE_STYLE_NAME = "Project";
public static final String PROJECT_CODE_STYLE_CONFIG_FILE_NAME = "codeStyleConfig";
private volatile boolean myIsLoaded;
private final static Object LEGACY_SETTINGS_IMPORT_LOCK = new Object();
private final Map<String,CodeStyleSettings> mySettingsMap = ContainerUtil.newHashMap();
void importLegacySettings(@NotNull Project project) {
@SuppressWarnings("unused")
public ProjectCodeStyleSettingsManager(Project project) {
this();
}
public ProjectCodeStyleSettingsManager() {
setMainProjectCodeStyle(null);
}
void initProjectSettings(@NotNull Project project) {
if (!myIsLoaded) {
synchronized (LEGACY_SETTINGS_IMPORT_LOCK) {
if (!myIsLoaded) {
@@ -41,14 +65,105 @@ public class ProjectCodeStyleSettingsManager extends CodeStyleSettingsManager{
loadState(legacySettingsManager.getState());
LOG.info("Imported old project code style settings.");
}
else {
initDefaults();
LOG.info("Initialized from default code style settings.");
}
}
}
}
}
@Override
public void loadState(Element state) {
super.loadState(state);
public void setMainProjectCodeStyle(@Nullable CodeStyleSettings settings) {
// TODO<rv>: Remove the assignment below when there are no direct usages of PER_PROJECT_SETTINGS.
//noinspection deprecation
PER_PROJECT_SETTINGS = settings;
mySettingsMap.put(MAIN_PROJECT_CODE_STYLE_NAME, settings != null ? settings : new CodeStyleSettings());
}
@NotNull
@Override
public CodeStyleSettings getMainProjectCodeStyle() {
return mySettingsMap.get(MAIN_PROJECT_CODE_STYLE_NAME);
}
private void initDefaults() {
CodeStyleSettingsManager appCodeStyleSettingsManager = CodeStyleSettingsManager.getInstance();
if (appCodeStyleSettingsManager != null) {
CodeStyleSettings defaultProjectSettings = appCodeStyleSettingsManager.getMainProjectCodeStyle();
setMainProjectCodeStyle(defaultProjectSettings != null ? defaultProjectSettings.clone() : null);
this.USE_PER_PROJECT_SETTINGS = appCodeStyleSettingsManager.USE_PER_PROJECT_SETTINGS;
this.PREFERRED_PROJECT_CODE_STYLE = appCodeStyleSettingsManager.PREFERRED_PROJECT_CODE_STYLE;
}
myIsLoaded = true;
}
@Override
public void loadState(Element state) {
super.loadState(state);
updateFromOldProjectSettings();
for (Element subStyle : state.getChildren(CODE_STYLE_TAG_NAME)) {
String name = subStyle.getAttributeValue(CODE_STYLE_NAME_ATTR);
CodeStyleSettings settings = new CodeStyleSettings();
settings.readExternal(subStyle);
if (MAIN_PROJECT_CODE_STYLE_NAME.equals(name)) {
setMainProjectCodeStyle(settings);
}
else {
mySettingsMap.put(name, settings);
}
}
myIsLoaded = true;
}
@SuppressWarnings("deprecation")
private void updateFromOldProjectSettings() {
CodeStyleSettings oldProjectSettings = PER_PROJECT_SETTINGS;
if (oldProjectSettings != null) oldProjectSettings.resetDeprecatedFields();
setMainProjectCodeStyle(oldProjectSettings);
}
@Override
public Element getState() {
Element e = super.getState();
if (e != null) {
for (String name : mySettingsMap.keySet()) {
CodeStyleSettings settings = mySettingsMap.get(name);
Element codeStyle = new Element(CODE_STYLE_TAG_NAME);
codeStyle.setAttribute(CODE_STYLE_NAME_ATTR, name);
settings.writeExternal(codeStyle);
if (!codeStyle.getContent().isEmpty()) {
e.addContent(codeStyle);
}
}
}
return e;
}
@Override
protected boolean isIgnoredOnSave(@NotNull String fieldName) {
return "PER_PROJECT_SETTINGS".equals(fieldName);
}
public static final class StateSplitter extends MainConfigurationStateSplitter {
@NotNull
@Override
protected String getComponentStateFileName() {
return PROJECT_CODE_STYLE_CONFIG_FILE_NAME;
}
@NotNull
@Override
protected String getSubStateTagName() {
return CODE_STYLE_TAG_NAME;
}
@NotNull
@Override
protected String getSubStateFileName(@NotNull Element element) {
return element.getAttributeValue(CODE_STYLE_NAME_ATTR);
}
}
}
@@ -151,7 +151,7 @@ public class CodeStyleSchemesModel implements SchemesModel<CodeStyleScheme> {
CodeStyleSettingsManager projectSettingsManager = getProjectSettings();
projectSettingsManager.USE_PER_PROJECT_SETTINGS = isProjectScheme(mySelectedScheme);
projectSettingsManager.PREFERRED_PROJECT_CODE_STYLE = mySelectedScheme instanceof ProjectScheme ? null : mySelectedScheme.getName();
projectSettingsManager.PER_PROJECT_SETTINGS = myProjectScheme.getCodeStyleSettings();
projectSettingsManager.setMainProjectCodeStyle(myProjectScheme.getCodeStyleSettings());
}
private void commitClonedSettings() {
@@ -279,7 +279,7 @@ public class CodeStyleSchemesModel implements SchemesModel<CodeStyleScheme> {
private class ProjectScheme extends CodeStyleSchemeImpl {
public ProjectScheme() {
super(CodeStyleScheme.PROJECT_SCHEME_NAME, false, CodeStyleSchemes.getInstance().getDefaultScheme());
CodeStyleSettings perProjectSettings = getProjectSettings().PER_PROJECT_SETTINGS;
CodeStyleSettings perProjectSettings = getProjectSettings().getMainProjectCodeStyle();
if (perProjectSettings != null) setCodeStyleSettings(perProjectSettings);
}
}
@@ -22,7 +22,8 @@ import com.intellij.lang.LanguageCommenters;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.DocCommentSettings;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.util.text.CharArrayUtil;
import org.jetbrains.annotations.NotNull;
@@ -36,8 +37,23 @@ public class CodeDocumentationUtil {
private CodeDocumentationUtil() {
}
/**
* @deprecated Use createDocCommentLine(lineData,file,commenter) instead.
*/
@SuppressWarnings("unused")
@Deprecated
public static String createDocCommentLine(String lineData, Project project, CodeDocumentationAwareCommenter commenter) {
if (!CodeStyleSettingsManager.getSettings(project).JD_LEADING_ASTERISKS_ARE_ENABLED) {
return createLine(lineData, commenter, DocCommentSettings.DEFAULTS);
}
public static String createDocCommentLine(String lineData, PsiFile file, CodeDocumentationAwareCommenter commenter) {
DocCommentSettings settings = CodeStyleManager.getInstance(file.getProject()).getDocCommentSettings(file);
return createLine(lineData, commenter, settings);
}
@NotNull
private static String createLine(String lineData, CodeDocumentationAwareCommenter commenter, DocCommentSettings settings) {
if (!settings.isLeadingAsteriskEnabled()) {
return " " + lineData + " ";
}
else {
@@ -700,7 +700,7 @@ public class EnterHandler extends BaseEnterHandler {
}
else {
removeTrailingSpaces(myDocument, myOffset);
String toInsert = previousLineIndentUsed ? "*" : CodeDocumentationUtil.createDocCommentLine("", getProject(), commenter);
String toInsert = previousLineIndentUsed ? "*" : CodeDocumentationUtil.createDocCommentLine("", myFile, commenter);
myDocument.insertString(myOffset, toInsert);
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
}
@@ -25,7 +25,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.util.text.CharArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -79,7 +79,9 @@ public class EnterAfterJavadocTagHandler extends EnterHandlerDelegateAdapter {
originalHandler.execute(editor, dataContext);
Project project = editor.getProject();
if (indentInsideJavadoc != null && project != null && CodeStyleSettingsManager.getSettings(project).JD_LEADING_ASTERISKS_ARE_ENABLED) {
if (indentInsideJavadoc != null &&
project != null &&
CodeStyleManager.getInstance(project).getDocCommentSettings(file).isLeadingAsteriskEnabled()) {
document.insertString(editor.getCaretModel().getOffset(), "*" + indentInsideJavadoc);
}
@@ -29,7 +29,6 @@ import com.intellij.psi.PsiComment;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.text.CharArrayUtil;
@@ -74,7 +73,9 @@ public class EnterBetweenBracesHandler extends EnterHandlerDelegateAdapter {
originalHandler.execute(editor, editor.getCaretModel().getCurrentCaret(), dataContext);
Project project = editor.getProject();
if (indentInsideJavadoc != null && project != null && CodeStyleSettingsManager.getSettings(project).JD_LEADING_ASTERISKS_ARE_ENABLED) {
if (indentInsideJavadoc != null &&
project != null &&
CodeStyleManager.getInstance(project).getDocCommentSettings(file).isLeadingAsteriskEnabled()) {
document.insertString(editor.getCaretModel().getOffset(), "*" + indentInsideJavadoc);
}
@@ -35,7 +35,7 @@ public class QuickChangeCodeStyleSchemeAction extends QuickSwitchSchemeAction {
@Override
protected void fillActions(Project project, @NotNull DefaultActionGroup group, @NotNull DataContext dataContext) {
final CodeStyleSettingsManager manager = CodeStyleSettingsManager.getInstance(project);
if (manager.PER_PROJECT_SETTINGS != null) {
if (manager.getMainProjectCodeStyle() != null) {
//noinspection HardCodedStringLiteral
group.add(new AnAction("<project>", "",
manager.USE_PER_PROJECT_SETTINGS ? ourCurrentAction : ourNotCurrentAction) {
@@ -130,8 +130,8 @@ public class CodeStyleSchemeImpl extends ExternalizableSchemeAdapter implements
}
if (dataHolder == null) {
Element newElement = new Element("code_scheme");
newElement.setAttribute("name", getName());
Element newElement = new Element(CODE_STYLE_TAG_NAME);
newElement.setAttribute(CODE_STYLE_NAME_ATTR, getName());
myCodeStyleSettings.writeExternal(newElement);
return newElement;
}
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<component name="ProjectCodeStyleSettingsManager">
<option name="PER_PROJECT_SETTINGS">
<value>
<option name="RIGHT_MARGIN" value="77"/>
<option name="FIELD_NAME_PREFIX" value="my"/>
</value>
</option>
<option name="USE_PER_PROJECT_SETTINGS" value="true"/>
</component>
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<component name="ProjectCodeStyleSettingsManager">
<option name="USE_PER_PROJECT_SETTINGS" value="true"/>
</component>
@@ -110,6 +110,7 @@ public class CodeStyleConfigurationTest extends CodeStyleTestCase {
settings.OTHER_INDENT_OPTIONS.INDENT_SIZE = 2;
Element root = createOption("config", "root");
settings.writeExternal(root);
root.removeAttribute("version");
assertXmlOutputEquals(
"<option name=\"config\" value=\"root\">\n" +
" <option name=\"OTHER_INDENT_OPTIONS\">\n" +
@@ -16,11 +16,16 @@
package com.intellij.ide.codeStyleSettings;
import com.intellij.openapi.application.ex.PathManagerEx;
import com.intellij.openapi.project.Project;
import com.intellij.testFramework.LightPlatformTestCase;
import com.intellij.testFramework.LightProjectDescriptor;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
@@ -44,4 +49,29 @@ public abstract class CodeStyleTestCase extends LightPlatformTestCase {
optionElement.setAttribute("value", value);
return optionElement;
}
@Nullable
protected String getTestDir() {
return null;
}
@NotNull
protected final String getTestDataPath() {
String testDir = getTestDir();
return BASE_PATH + (testDir != null ? testDir : "") + File.separator;
}
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return new LightProjectDescriptor() {
@Override
public void setUpProject(@NotNull Project project, @NotNull SetupHandler handler) throws Exception {
setupProject();
super.setUpProject(project, handler);
}
};
}
protected void setupProject() throws Exception {}
}
@@ -23,7 +23,6 @@ import com.intellij.psi.codeStyle.CodeStyleScheme;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.impl.source.codeStyle.CodeStyleSchemeImpl;
import com.intellij.psi.impl.source.codeStyle.CodeStyleSchemeXmlImporter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
@@ -57,10 +56,11 @@ public class CodeStyleXmlImporterTest extends CodeStyleTestCase {
CodeStyleSchemeXmlImporter importer = new CodeStyleSchemeXmlImporter();
return importer.importScheme(getProject(), vFile, targetScheme, schemeFactory).getCodeStyleSettings();
}
@NotNull
protected String getTestDataPath() {
return BASE_PATH + "importSettings/";
@Nullable
@Override
protected String getTestDir() {
return "importSettings";
}
}
@@ -0,0 +1,76 @@
/*
* Copyright 2000-2017 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.ide.codeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.util.containers.ContainerUtilRt;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
public class NewProjectSettingsTest extends CodeStyleTestCase {
private final static Map<String,Runnable> ourSetupMap = ContainerUtilRt.newHashMap();
static {
ourSetupMap.put("nonDefaultSettings", () -> {
CodeStyleSettingsManager manager = CodeStyleSettingsManager.getInstance();
manager.USE_PER_PROJECT_SETTINGS = true;
CodeStyleSettings testSettings = new CodeStyleSettings();
manager.setMainProjectCodeStyle(testSettings);
testSettings.setDefaultRightMargin(77);
});
}
@Override
public void setUp() throws Exception {
super.setUp();
CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();
}
@Override
public void tearDown() throws Exception {
try {
restoreDefaults();
}
finally {
super.tearDown();
}
}
@Override
protected void setupProject() throws Exception {
Runnable setupRunnable = ourSetupMap.get(getTestName(true));
if (setupRunnable != null) setupRunnable.run();
}
private static void restoreDefaults() {
restoreDefaults(CodeStyleSettingsManager.getInstance());
restoreDefaults(CodeStyleSettingsManager.getInstance(getProject()));
}
private static void restoreDefaults(@NotNull CodeStyleSettingsManager manager) {
manager.USE_PER_PROJECT_SETTINGS = false;
manager.setMainProjectCodeStyle(null);
}
public void testNonDefaultSettings() throws Exception {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
CodeStyleSettings appSettings = CodeStyleSettingsManager.getInstance().getMainProjectCodeStyle();
assertNotNull(appSettings);
assertNotSame(settings, appSettings);
assertEquals(settings, appSettings);
}
}
@@ -0,0 +1,92 @@
/*
* Copyright 2000-2017 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.ide.codeStyleSettings;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.LegacyCodeStyleSettingsManager;
import com.intellij.psi.codeStyle.ProjectCodeStyleSettingsManager;
import com.intellij.testFramework.LightProjectDescriptor;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import static com.intellij.psi.codeStyle.CodeStyleScheme.CODE_STYLE_TAG_NAME;
public class ProjectCodeStyleMigrationTest extends CodeStyleTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();
}
@Override
public void tearDown() throws Exception {
try {
CodeStyleSettingsManager.getSettings(getProject()).copyFrom(CodeStyleSettings.getDefaults());
}
finally {
super.tearDown();
}
}
@SuppressWarnings("deprecation")
public void testMigrateDefault() throws IOException {
CodeStyleSettingsManager settingsManager = CodeStyleSettingsManager.getInstance(getProject());
assertInstanceOf(settingsManager, ProjectCodeStyleSettingsManager.class);
CodeStyleSettings projectSettings = settingsManager.getCurrentSettings();
assertTrue(settingsManager.USE_PER_PROJECT_SETTINGS);
assertEquals(CodeStyleSettings.getDefaults(), projectSettings);
Element state = settingsManager.getState();
Element codeStyle = state.getChild(CODE_STYLE_TAG_NAME);
assertNull(codeStyle);
}
@SuppressWarnings("deprecation")
public void testMigrateChanged() throws IOException {
CodeStyleSettingsManager settingsManager = CodeStyleSettingsManager.getInstance(getProject());
assertInstanceOf(settingsManager, ProjectCodeStyleSettingsManager.class);
CodeStyleSettings projectSettings = settingsManager.getCurrentSettings();
assertTrue(settingsManager.USE_PER_PROJECT_SETTINGS);
assertEquals(77, projectSettings.RIGHT_MARGIN);
assertEmpty(projectSettings.FIELD_NAME_PREFIX);
Element state = settingsManager.getState();
Element codeStyle = state.getChild(CODE_STYLE_TAG_NAME);
assertNotNull(codeStyle);
}
@Override
protected void setupProject() throws Exception {
LegacyCodeStyleSettingsManager legacyCodeStyleSettingsManager = ServiceManager.getService(getProject(), LegacyCodeStyleSettingsManager.class);
Document document = JDOMUtil.loadDocument(new File(getTestDataPath() + getTestName(true) + ".xml"));
legacyCodeStyleSettingsManager.loadState(document.getRootElement());
}
@Nullable
@Override
protected String getTestDir() {
return "projectSettingsMigration";
}
}
@@ -82,7 +82,6 @@ public abstract class FormatterTestCase extends LightPlatformTestCase {
protected void setUp() throws Exception {
super.setUp();
assertFalse(CodeStyleSettingsManager.getInstance(getProject()).USE_PER_PROJECT_SETTINGS);
assertNull(CodeStyleSettingsManager.getInstance(getProject()).PER_PROJECT_SETTINGS);
}
protected void doTest(String resultNumber) throws Exception {
@@ -25,6 +25,7 @@ import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.impl.source.resolve.graphInference.FunctionalInterfaceParameterizationUtil;
import com.intellij.psi.infos.MethodCandidateInfo;
import com.intellij.psi.tree.IElementType;
@@ -271,14 +272,16 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp
checkQualifier(((PsiMethodCallExpression)expression).getMethodExpression().getQualifier()), true);
}
JavaCodeStyleSettings javaSettings =
CodeStyleSettingsManager.getSettings(expression.getProject()).getCustomSettings(JavaCodeStyleSettings.class);
if (expression instanceof PsiInstanceOfExpression) {
return new MethodReferenceCandidate(expression, true,
CodeStyleSettingsManager.getSettings(expression.getProject()).REPLACE_INSTANCEOF);
javaSettings.REPLACE_INSTANCEOF);
}
else if (expression instanceof PsiBinaryExpression) {
if (ExpressionUtils.getValueComparedWithNull((PsiBinaryExpression)expression) != null) {
return new MethodReferenceCandidate(expression, true,
CodeStyleSettingsManager.getSettings(expression.getProject()).REPLACE_NULL_CHECK);
javaSettings.REPLACE_NULL_CHECK);
}
}
else if (expression instanceof PsiTypeCastExpression) {
@@ -290,7 +293,7 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp
}
PsiType type = typeElement.getType();
if (type instanceof PsiPrimitiveType || PsiUtil.resolveClassInType(type) instanceof PsiTypeParameter) return null;
return new MethodReferenceCandidate(expression, true, CodeStyleSettingsManager.getSettings(expression.getProject()).REPLACE_CAST);
return new MethodReferenceCandidate(expression, true, javaSettings.REPLACE_CAST);
}
}
return null;
@@ -81,7 +81,7 @@ public class RefusedBequestInspection extends RefusedBequestInspectionBase {
final StringBuilder statementText = new StringBuilder();
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
if (returnType != null && !PsiType.VOID.equals(returnType)) {
if (CodeStyleSettingsManager.getSettings(project).GENERATE_FINAL_LOCALS) {
if (CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS) {
statementText.append("final ");
}
statementText.append(returnType.getCanonicalText()).append(' ');
@@ -162,7 +162,7 @@ public class EnumerationCanBeIterationInspection extends EnumerationCanBeIterati
final Project project = methodCallExpression.getProject();
final CodeStyleSettings codeStyleSettings =
CodeStyleSettingsManager.getSettings(project);
if (codeStyleSettings.GENERATE_FINAL_LOCALS) {
if (codeStyleSettings.getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS) {
newStatementText.append("final ");
}
newStatementText.append(CommonClassNames.JAVA_UTIL_ITERATOR);
@@ -304,7 +304,7 @@ public class ForCanBeForeachInspection extends ForCanBeForeachInspectionBase {
final Project project = forStatement.getProject();
final CodeStyleSettings codeStyleSettings =
CodeStyleSettingsManager.getSettings(project);
if (codeStyleSettings.GENERATE_FINAL_LOCALS) {
if (codeStyleSettings.getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS) {
finalString = "final ";
}
else {
@@ -409,7 +409,7 @@ public class ForCanBeForeachInspection extends ForCanBeForeachInspectionBase {
contentVariableName = createNewVariableName(forStatement, componentType, collectionName);
final Project project = forStatement.getProject();
final CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(project);
if (codeStyleSettings.GENERATE_FINAL_LOCALS) {
if (codeStyleSettings.getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS) {
finalString = "final ";
}
else {
@@ -433,7 +433,7 @@ public class ForCanBeForeachInspection extends ForCanBeForeachInspectionBase {
contentVariableName = createNewVariableName(forStatement, componentType, collectionName);
final Project project = forStatement.getProject();
final CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(project);
if (codeStyleSettings.GENERATE_FINAL_LOCALS) {
if (codeStyleSettings.getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS) {
finalString = "final ";
}
else {
@@ -19,6 +19,7 @@ import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.TypeConversionUtil;
@@ -111,7 +112,7 @@ public class WhileCanBeForeachInspection extends WhileCanBeForeachInspectionBase
}
@NonNls final StringBuilder out = new StringBuilder();
out.append("for(");
if (CodeStyleSettingsManager.getSettings(project).GENERATE_FINAL_PARAMETERS) {
if (CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS) {
out.append("final ");
}
out.append(iteratorContentType.getCanonicalText()).append(' ').append(contentVariableName).append(": ");
@@ -20,6 +20,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.containers.ContainerUtil;
import com.siyeh.InspectionGadgetsBundle;
@@ -152,7 +153,8 @@ public class StringBufferReplaceableByStringInspection extends StringBufferRepla
if (statement == null) {
return;
}
final String modifier = CodeStyleSettingsManager.getSettings(project).GENERATE_FINAL_LOCALS ? "final " : "";
final String modifier =
CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS ? "final " : "";
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
final StringBuilder statementText =
new StringBuilder(modifier).append(CommonClassNames.JAVA_LANG_STRING).append(' ').append(variableName).append("=");

Some files were not shown because too many files have changed in this diff Show More