use of com.intellij.psi.codeStyle.JavaCodeStyleManager in project intellij-community by JetBrains.
the class GrPullUpHelper method replaceMovedMemberTypeParameters.
public static void replaceMovedMemberTypeParameters(final PsiElement member, final Iterable<PsiTypeParameter> parametersIterable, final PsiSubstitutor substitutor, final GroovyPsiElementFactory factory) {
final Map<PsiElement, PsiElement> replacement = new LinkedHashMap<>();
for (PsiTypeParameter parameter : parametersIterable) {
PsiType substitutedType = substitutor.substitute(parameter);
PsiType type = substitutedType != null ? substitutedType : TypeConversionUtil.erasure(factory.createType(parameter));
PsiElement scopeElement = member instanceof GrField ? member.getParent() : member;
for (PsiReference reference : ReferencesSearch.search(parameter, new LocalSearchScope(scopeElement))) {
final PsiElement element = reference.getElement();
final PsiElement parent = element.getParent();
if (parent instanceof PsiTypeElement) {
replacement.put(parent, factory.createTypeElement(type));
} else if (element instanceof GrCodeReferenceElement && type instanceof PsiClassType) {
replacement.put(element, factory.createReferenceElementByType((PsiClassType) type));
}
}
}
final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(member.getProject());
for (PsiElement element : replacement.keySet()) {
if (element.isValid()) {
final PsiElement replaced = element.replace(replacement.get(element));
codeStyleManager.shortenClassReferences(replaced);
}
}
}
use of com.intellij.psi.codeStyle.JavaCodeStyleManager in project GsonFormat by zzz40500.
the class Processor method formatJavCode.
protected void formatJavCode(PsiClass cls) {
if (cls == null) {
return;
}
JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(cls.getProject());
styleManager.optimizeImports(cls.getContainingFile());
styleManager.shortenClassReferences(cls);
}
use of com.intellij.psi.codeStyle.JavaCodeStyleManager in project intellij-community by JetBrains.
the class IntroduceVariableBase method getSuggestedName.
public static SuggestedNameInfo getSuggestedName(@Nullable PsiType type, @NotNull final PsiExpression expression, final PsiElement anchor) {
final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(expression.getProject());
final SuggestedNameInfo nameInfo = codeStyleManager.suggestVariableName(VariableKind.LOCAL_VARIABLE, null, expression, type);
final String[] strings = JavaCompletionUtil.completeVariableNameForRefactoring(codeStyleManager, type, VariableKind.LOCAL_VARIABLE, nameInfo);
final SuggestedNameInfo.Delegate delegate = new SuggestedNameInfo.Delegate(strings, nameInfo);
return codeStyleManager.suggestUniqueVariableName(delegate, anchor, true);
}
use of com.intellij.psi.codeStyle.JavaCodeStyleManager in project intellij-community by JetBrains.
the class MakeClassStaticProcessor method convertToFieldName.
private String convertToFieldName(final String parameterName) {
JavaCodeStyleManager manager = JavaCodeStyleManager.getInstance(myProject);
final String propertyName = manager.variableNameToPropertyName(parameterName, VariableKind.PARAMETER);
final String fieldName = manager.propertyNameToVariableName(propertyName, VariableKind.FIELD);
return fieldName;
}
use of com.intellij.psi.codeStyle.JavaCodeStyleManager in project intellij-community by JetBrains.
the class AbstractJavaInplaceIntroducer method suggestNames.
@Override
protected String[] suggestNames(boolean replaceAll, PsiVariable variable) {
final PsiType defaultType = getType();
final String propertyName = variable != null ? JavaCodeStyleManager.getInstance(myProject).variableNameToPropertyName(variable.getName(), VariableKind.LOCAL_VARIABLE) : null;
final String[] names = suggestNames(defaultType, propertyName);
if (propertyName != null && names.length > 1) {
final JavaCodeStyleManager javaCodeStyleManager = JavaCodeStyleManager.getInstance(myProject);
final String paramName = javaCodeStyleManager.propertyNameToVariableName(propertyName, getVariableKind());
final int idx = ArrayUtil.find(names, paramName);
if (idx > -1) {
ArrayUtil.swap(names, 0, idx);
}
}
return names;
}
Aggregations