本文整理汇总了Java中com.intellij.psi.codeStyle.VariableKind.FIELD属性的典型用法代码示例。如果您正苦于以下问题:Java VariableKind.FIELD属性的具体用法?Java VariableKind.FIELD怎么用?Java VariableKind.FIELD使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.intellij.psi.codeStyle.VariableKind
的用法示例。
在下文中一共展示了VariableKind.FIELD属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findFieldToAssign
@Nullable
private static PsiField findFieldToAssign(@NotNull Project project,
@NotNull PsiParameter myParameter) {
final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project);
final String parameterName = myParameter.getName();
final String propertyName = styleManager.variableNameToPropertyName(parameterName, VariableKind.PARAMETER);
final PsiMethod method = (PsiMethod)myParameter.getDeclarationScope();
final boolean isMethodStatic = method.hasModifierProperty(PsiModifier.STATIC);
final VariableKind kind = isMethodStatic ? VariableKind.STATIC_FIELD : VariableKind.FIELD;
final SuggestedNameInfo suggestedNameInfo = styleManager.suggestVariableName(kind, propertyName, null, FieldFromParameterUtils.getSubstitutedType(myParameter));
final String fieldName = suggestedNameInfo.names[0];
PsiClass aClass = method.getContainingClass();
if (aClass == null) return null;
PsiField field = aClass.findFieldByName(fieldName, false);
if (field == null) return null;
if (!field.hasModifierProperty(PsiModifier.STATIC) && isMethodStatic) return null;
return field;
}
示例2: getPropertyName
public static String getPropertyName(FieldElement fieldElement, Project project)
{
final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
final VariableKind variableKind = fieldElement.isModifierStatic() ? VariableKind.STATIC_FIELD : VariableKind.FIELD;
final String propertyName = codeStyleManager.variableNameToPropertyName(fieldElement.getName(), variableKind);
if(!fieldElement.isModifierStatic() && fieldElement.isBoolean())
{
if(propertyName.startsWith("is") &&
propertyName.length() > "is".length() &&
Character.isUpperCase(propertyName.charAt("is".length())))
{
return StringUtil.decapitalize(propertyName.substring("is".length()));
}
}
return propertyName;
}
示例3: getMapByVariableKind
@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;
}
return null;
}
示例4: 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;
}
示例5: 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);
}
};
}
示例6: getPropertyName
public static String getPropertyName(FieldElement fieldElement, Project project) {
final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
final VariableKind variableKind = fieldElement.isModifierStatic() ? VariableKind.STATIC_FIELD : VariableKind.FIELD;
final String propertyName = codeStyleManager.variableNameToPropertyName(fieldElement.getName(), variableKind);
if (!fieldElement.isModifierStatic() && fieldElement.isBoolean()) {
if (propertyName.startsWith("is") &&
propertyName.length() > "is".length() &&
Character.isUpperCase(propertyName.charAt("is".length()))) {
return StringUtil.decapitalize(propertyName.substring("is".length()));
}
}
return propertyName;
}
示例7: 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.length() > 0) {
VariableKind kind = isStatic ? VariableKind.STATIC_FIELD : VariableKind.FIELD;
return codeStyleManager.propertyNameToVariableName(propertyName, kind);
}
return null;
}
示例8: processParameter
private void processParameter(final @NotNull Project project,
final @NotNull PsiParameter myParameter,
final boolean isInteractive) {
final PsiType type = getSubstitutedType(myParameter);
final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project);
final String parameterName = myParameter.getName();
String propertyName = styleManager.variableNameToPropertyName(parameterName, VariableKind.PARAMETER);
String fieldNameToCalc;
boolean isFinalToCalc;
final PsiClass targetClass = PsiTreeUtil.getParentOfType(myParameter, PsiClass.class);
final PsiMethod method = (PsiMethod)myParameter.getDeclarationScope();
final boolean isMethodStatic = method.hasModifierProperty(PsiModifier.STATIC);
VariableKind kind = isMethodStatic ? VariableKind.STATIC_FIELD : VariableKind.FIELD;
SuggestedNameInfo suggestedNameInfo = styleManager.suggestVariableName(kind, propertyName, null, type);
String[] names = suggestedNameInfo.names;
if (isInteractive) {
List<String> namesList = new ArrayList<String>();
ContainerUtil.addAll(namesList, names);
String defaultName = styleManager.propertyNameToVariableName(propertyName, kind);
if (namesList.contains(defaultName)) {
Collections.swap(namesList, 0, namesList.indexOf(defaultName));
}
else {
namesList.add(0, defaultName);
}
names = ArrayUtil.toStringArray(namesList);
final CreateFieldFromParameterDialog dialog = new CreateFieldFromParameterDialog(
project,
names,
targetClass,
method.isConstructor(),
type
);
if (!dialog.showAndGet()) {
return;
}
fieldNameToCalc = dialog.getEnteredName();
isFinalToCalc = dialog.isDeclareFinal();
suggestedNameInfo.nameChosen(fieldNameToCalc);
}
else {
isFinalToCalc = !isMethodStatic && method.isConstructor();
fieldNameToCalc = names[0];
}
final boolean isFinal = isFinalToCalc;
final String fieldName = fieldNameToCalc;
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
try {
performRefactoring(project, targetClass, method, myParameter, type, fieldName, isMethodStatic, isFinal);
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
}
});
}
示例9: nameToCanonicalName
protected String nameToCanonicalName(@NonNls final String name, final PsiNamedElement element) {
final JavaCodeStyleManager javaCodeStyleManager = JavaCodeStyleManager.getInstance(element.getProject());
final VariableKind variableKind = element instanceof PsiVariable ? javaCodeStyleManager.getVariableKind((PsiVariable)element) : VariableKind.FIELD;
return javaCodeStyleManager.variableNameToPropertyName(name, variableKind);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:ConstructorParameterOnFieldRenameRenamer.java
示例10: getVariableKind
@Override
protected VariableKind getVariableKind() {
return VariableKind.FIELD;
}
示例11: processParameter
private void processParameter(final @NotNull Project project,
final @NotNull PsiParameter myParameter,
final boolean isInteractive) {
final PsiType type = getSubstitutedType(myParameter);
final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project);
final String parameterName = myParameter.getName();
String propertyName = styleManager.variableNameToPropertyName(parameterName, VariableKind.PARAMETER);
String fieldNameToCalc;
boolean isFinalToCalc;
final PsiClass targetClass = PsiTreeUtil.getParentOfType(myParameter, PsiClass.class);
final PsiMethod method = (PsiMethod)myParameter.getDeclarationScope();
final boolean isMethodStatic = method.hasModifierProperty(PsiModifier.STATIC);
VariableKind kind = isMethodStatic ? VariableKind.STATIC_FIELD : VariableKind.FIELD;
SuggestedNameInfo suggestedNameInfo = styleManager.suggestVariableName(kind, propertyName, null, type);
String[] names = suggestedNameInfo.names;
if (isInteractive) {
List<String> namesList = new ArrayList<String>();
ContainerUtil.addAll(namesList, names);
String defaultName = styleManager.propertyNameToVariableName(propertyName, kind);
if (namesList.contains(defaultName)) {
Collections.swap(namesList, 0, namesList.indexOf(defaultName));
}
else {
namesList.add(0, defaultName);
}
names = ArrayUtil.toStringArray(namesList);
final CreateFieldFromParameterDialog dialog = new CreateFieldFromParameterDialog(
project,
names,
targetClass,
method.isConstructor(),
type
);
dialog.show();
if (!dialog.isOK()) return;
fieldNameToCalc = dialog.getEnteredName();
isFinalToCalc = dialog.isDeclareFinal();
suggestedNameInfo.nameChosen(fieldNameToCalc);
}
else {
isFinalToCalc = !isMethodStatic && method.isConstructor();
fieldNameToCalc = names[0];
}
final boolean isFinal = isFinalToCalc;
final String fieldName = fieldNameToCalc;
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
try {
performRefactoring(project, targetClass, method, myParameter, type, fieldName, isMethodStatic, isFinal);
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
}
});
}
示例12: processParameter
private static void processParameter(final Project project,
final PsiParameter myParameter,
final Set<String> usedNames) {
IdeDocumentHistory.getInstance(project).includeCurrentPlaceAsChangePlace();
final PsiType type = FieldFromParameterUtils.getSubstitutedType(myParameter);
final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project);
final String parameterName = myParameter.getName();
String propertyName = styleManager.variableNameToPropertyName(parameterName, VariableKind.PARAMETER);
final PsiClass targetClass = PsiTreeUtil.getParentOfType(myParameter, PsiClass.class);
final PsiMethod method = (PsiMethod)myParameter.getDeclarationScope();
final boolean isMethodStatic = method.hasModifierProperty(PsiModifier.STATIC);
VariableKind kind = isMethodStatic ? VariableKind.STATIC_FIELD : VariableKind.FIELD;
SuggestedNameInfo suggestedNameInfo = styleManager.suggestVariableName(kind, propertyName, null, type);
String[] names = suggestedNameInfo.names;
final boolean isFinal = !isMethodStatic && method.isConstructor();
String name = names[0];
if (targetClass != null) {
for (String curName : names) {
if (!usedNames.contains(curName) && targetClass.findFieldByName(curName, false) != null) {
name = curName;
break;
}
}
}
final String fieldName = usedNames.add(name) ? name
: JavaCodeStyleManager.getInstance(project).suggestUniqueVariableName(name, myParameter, true);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
try {
FieldFromParameterUtils.createFieldAndAddAssignment(
project,
targetClass,
method,
myParameter,
type,
fieldName,
isMethodStatic,
isFinal);
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
}
});
}