use of com.intellij.psi.codeStyle.VariableKind in project intellij-community by JetBrains.
the class ChangeMethodSignatureFromUsageFix method suggestUniqueParameterName.
static String suggestUniqueParameterName(JavaCodeStyleManager codeStyleManager, PsiExpression expression, PsiType exprType, Set<String> existingNames) {
SuggestedNameInfo nameInfo = codeStyleManager.suggestVariableName(VariableKind.PARAMETER, null, expression, exprType);
@NonNls String[] names = nameInfo.names;
if (expression instanceof PsiReferenceExpression) {
final PsiElement resolve = ((PsiReferenceExpression) expression).resolve();
if (resolve instanceof PsiVariable) {
final VariableKind variableKind = codeStyleManager.getVariableKind((PsiVariable) resolve);
final String propertyName = codeStyleManager.variableNameToPropertyName(((PsiVariable) resolve).getName(), variableKind);
final String parameterName = codeStyleManager.propertyNameToVariableName(propertyName, VariableKind.PARAMETER);
names = ArrayUtil.mergeArrays(new String[] { parameterName }, names);
}
}
if (names.length == 0)
names = new String[] { "param" };
int suffix = 0;
while (true) {
for (String name : names) {
String suggested = name + (suffix == 0 ? "" : String.valueOf(suffix));
if (existingNames.add(suggested)) {
return suggested;
}
}
suffix++;
}
}
use of com.intellij.psi.codeStyle.VariableKind in project intellij-community by JetBrains.
the class CreatePropertyFromUsageFix method getVariableName.
private static String getVariableName(PsiMethodCallExpression methodCall, boolean isStatic) {
JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(methodCall.getProject());
String methodName = methodCall.getMethodExpression().getReferenceName();
String propertyName = PropertyUtil.getPropertyName(methodName);
if (propertyName != null && !propertyName.isEmpty()) {
VariableKind kind = isStatic ? VariableKind.STATIC_FIELD : VariableKind.FIELD;
return codeStyleManager.propertyNameToVariableName(propertyName, kind);
}
return null;
}
use of com.intellij.psi.codeStyle.VariableKind in project intellij-community by JetBrains.
the class IntroduceFieldDialog method createGenerator.
static NameSuggestionsGenerator createGenerator(final boolean willBeDeclaredStatic, final PsiLocalVariable localVariable, final PsiExpression initializerExpression, final boolean isInvokedOnDeclaration, @Nullable final String enteredName, final PsiClass parentClass, final Project project) {
return new NameSuggestionsGenerator() {
private final JavaCodeStyleManager myCodeStyleManager = JavaCodeStyleManager.getInstance(project);
public SuggestedNameInfo getSuggestedNameInfo(PsiType type) {
VariableKind variableKind = willBeDeclaredStatic ? VariableKind.STATIC_FIELD : VariableKind.FIELD;
String propertyName = null;
if (isInvokedOnDeclaration) {
propertyName = myCodeStyleManager.variableNameToPropertyName(localVariable.getName(), VariableKind.LOCAL_VARIABLE);
}
final SuggestedNameInfo nameInfo = myCodeStyleManager.suggestVariableName(variableKind, propertyName, initializerExpression, type);
if (initializerExpression != null) {
String[] names = nameInfo.names;
for (int i = 0, namesLength = names.length; i < namesLength; i++) {
String name = names[i];
if (parentClass.findFieldByName(name, false) != null) {
names[i] = myCodeStyleManager.suggestUniqueVariableName(name, initializerExpression, true);
}
}
}
final String[] strings = AbstractJavaInplaceIntroducer.appendUnresolvedExprName(JavaCompletionUtil.completeVariableNameForRefactoring(myCodeStyleManager, type, VariableKind.LOCAL_VARIABLE, nameInfo), initializerExpression);
return new SuggestedNameInfo.Delegate(enteredName != null ? ArrayUtil.mergeArrays(new String[] { enteredName }, strings) : strings, nameInfo);
}
};
}
use of com.intellij.psi.codeStyle.VariableKind in project intellij-community by JetBrains.
the class InputVariables method getParameterName.
private String getParameterName(PsiVariable var) {
String name = var.getName();
if (!(var instanceof PsiParameter)) {
JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(myProject);
VariableKind kind = codeStyleManager.getVariableKind(var);
name = codeStyleManager.variableNameToPropertyName(name, kind);
name = codeStyleManager.propertyNameToVariableName(name, VariableKind.PARAMETER);
}
return name;
}
use of com.intellij.psi.codeStyle.VariableKind in project intellij-community by JetBrains.
the class JavaStatisticsManager method getAllVariableNamesUsed.
public static String[] getAllVariableNamesUsed(VariableKind variableKind, String propertyName, PsiType type) {
StatisticsInfo[] keys2 = StatisticsManager.getInstance().getAllValues(getVariableNameUseKey1(propertyName, type));
ArrayList<String> list = new ArrayList<>();
for (StatisticsInfo key2 : keys2) {
VariableKind variableKind1 = getVariableKindFromKey2(key2.getValue());
if (variableKind1 != variableKind)
continue;
String name = getVariableNameFromKey2(key2.getValue());
list.add(name);
}
return ArrayUtil.toStringArray(list);
}
Aggregations