本文整理汇总了Java中com.intellij.psi.util.PropertyUtil.generateSetterPrototype方法的典型用法代码示例。如果您正苦于以下问题:Java PropertyUtil.generateSetterPrototype方法的具体用法?Java PropertyUtil.generateSetterPrototype怎么用?Java PropertyUtil.generateSetterPrototype使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.util.PropertyUtil
的用法示例。
在下文中一共展示了PropertyUtil.generateSetterPrototype方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerQuickFix
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
public static void registerQuickFix(PsiMember refElement,
PsiJavaCodeReferenceElement place,
PsiClass accessObjectClass,
HighlightInfo error) {
if (refElement instanceof PsiField && place instanceof PsiReferenceExpression) {
final PsiField psiField = (PsiField)refElement;
final PsiClass containingClass = psiField.getContainingClass();
if (containingClass != null) {
if (PsiUtil.isOnAssignmentLeftHand((PsiExpression)place)) {
final PsiMethod setterPrototype = PropertyUtil.generateSetterPrototype(psiField);
final PsiMethod setter = containingClass.findMethodBySignature(setterPrototype, true);
if (setter != null && PsiUtil.isAccessible(setter, place, accessObjectClass)) {
QuickFixAction.registerQuickFixAction(error, new ReplaceInaccessibleFieldWithGetterSetterFix(place, setter, true));
}
}
else if (PsiUtil.isAccessedForReading((PsiExpression)place)) {
final PsiMethod getterPrototype = GenerateMembersUtil.generateGetterPrototype(psiField);
final PsiMethod getter = containingClass.findMethodBySignature(getterPrototype, true);
if (getter != null && PsiUtil.isAccessible(getter, place, accessObjectClass)) {
QuickFixAction.registerQuickFixAction(error, new ReplaceInaccessibleFieldWithGetterSetterFix(place, getter, false));
}
}
}
}
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:26,代码来源:ReplaceInaccessibleFieldWithGetterSetterFix.java
示例2: generateSetters
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
@Override
public PsiMethod[] generateSetters(PsiField field) {
final PsiMethod setter = PropertyUtil.generateSetterPrototype(field);
final Project project = field.getProject();
final PsiType wrappedType = JavaFxPsiUtil.getWrappedPropertyType(field, project, JavaFxCommonClassNames.ourWritableMap);
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
final PsiTypeElement newTypeElement = elementFactory.createTypeElement(wrappedType);
final PsiParameter[] parameters = setter.getParameterList().getParameters();
LOG.assertTrue(parameters.length == 1);
final PsiParameter parameter = parameters[0];
final PsiTypeElement typeElement = parameter.getTypeElement();
LOG.assertTrue(typeElement != null);
typeElement.replace(newTypeElement);
final PsiCodeBlock body = setter.getBody();
LOG.assertTrue(body != null);
body.getStatements()[0].replace(elementFactory.createStatementFromText("this." + field.getName() + ".set(" + parameter.getName() + ");", field));
return new PsiMethod[] {setter};
}
示例3: generateGetterSetters
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
public static PsiMethod[] generateGetterSetters(PsiField field, boolean generateGetter) {
for (GetterSetterPrototypeProvider provider : Extensions.getExtensions(EP_NAME)) {
if (provider.canGeneratePrototypeFor(field)) {
return generateGetter ? provider.generateGetters(field) : provider.generateSetters(field);
}
}
return new PsiMethod[] {generateGetter ? PropertyUtil.generateGetterPrototype(field) : PropertyUtil.generateSetterPrototype(field)};
}
示例4: generateConstructor
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
private PsiMethod generateConstructor(final PsiClass targetClass, final PsiType builderType) {
final PsiMethod constructor = psiElementFactory.createConstructor(targetClass.getName());
constructor.getModifierList().setModifierProperty(PsiModifier.PRIVATE, true);
final PsiParameter builderParameter = psiElementFactory.createParameter("builder", builderType);
constructor.getParameterList().add(builderParameter);
final PsiCodeBlock constructorBody = constructor.getBody();
if (constructorBody != null) {
for (final PsiFieldMember member : selectedFields) {
final PsiField field = member.getElement();
final PsiMethod setterPrototype = PropertyUtil.generateSetterPrototype(field);
final PsiMethod setter = targetClass.findMethodBySignature(setterPrototype, true);
final String fieldName = field.getName();
boolean isFinal = false;
final PsiModifierList modifierList = field.getModifierList();
if (modifierList != null) {
isFinal = modifierList.hasModifierProperty(PsiModifier.FINAL);
}
final String assignText;
if (setter == null || isFinal) {
assignText = String.format("%1$s = builder.%1$s;", fieldName);
} else {
assignText = String.format("%s(builder.%s);", setter.getName(), fieldName);
}
final PsiStatement assignStatement = psiElementFactory.createStatementFromText(assignText, null);
constructorBody.add(assignStatement);
}
}
return constructor;
}
示例5: beforeTemplateFinished
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
@Override
protected void beforeTemplateFinished(PsiClass aClass, PsiField field) {
PsiMethod getterPrototype = PropertyUtil.generateGetterPrototype(field);
if (aClass.findMethodsBySignature(getterPrototype, false).length == 0) {
aClass.add(getterPrototype);
}
PsiMethod setterPrototype = PropertyUtil.generateSetterPrototype(field);
if (aClass.findMethodsBySignature(setterPrototype, false).length == 0) {
aClass.add(setterPrototype);
}
super.beforeTemplateFinished(aClass, field);
}
示例6: doTest
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
private static void doTest(final PsiClass aClass, final PsiField field, final String conflicts,
final boolean generateGetters, final boolean generateSetters) {
try {
final Project project = aClass.getProject();
EncapsulateFieldsProcessor processor = new EncapsulateFieldsProcessor(project, new EncapsulateFieldsDescriptor() {
@Override
public PsiField[] getSelectedFields() {
return new PsiField[]{field};
}
@Override
public String[] getGetterNames() {
return new String[]{PropertyUtil.suggestGetterName(project, field)};
}
@Override
public String[] getSetterNames() {
return new String[]{PropertyUtil.suggestSetterName(project, field)};
}
@Override
@Nullable
public PsiMethod[] getGetterPrototypes() {
return isToEncapsulateGet() ? new PsiMethod[]{PropertyUtil.generateGetterPrototype(field)} : null;
}
@Override
@Nullable
public PsiMethod[] getSetterPrototypes() {
return isToEncapsulateSet() ? new PsiMethod[]{PropertyUtil.generateSetterPrototype(field)} : null;
}
@Override
public boolean isToEncapsulateGet() {
return generateGetters;
}
@Override
public boolean isToEncapsulateSet() {
return generateSetters;
}
@Override
public boolean isToUseAccessorsWhenAccessible() {
return true;
}
@Override
public String getFieldsVisibility() {
return null;
}
@Override
public String getAccessorsVisibility() {
return PsiModifier.PUBLIC;
}
@Override
public int getJavadocPolicy() {
return DocCommentPolicy.MOVE;
}
});
processor.run();
LocalFileSystem.getInstance().refresh(false);
FileDocumentManager.getInstance().saveAllDocuments();
}
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
if (conflicts != null) {
Assert.assertEquals(conflicts, e.getMessage());
return;
} else {
e.printStackTrace();
fail(e.getMessage());
}
}
if (conflicts != null) {
fail("Conflicts were not detected: " + conflicts);
}
}
示例7: doTest
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
private static void doTest(final PsiClass aClass,
final PsiField field,
final String conflicts,
final boolean generateGetters,
final boolean generateSetters) {
try {
final Project project = aClass.getProject();
EncapsulateFieldsProcessor processor = new EncapsulateFieldsProcessor(project, new EncapsulateFieldsDescriptor() {
@Override
public FieldDescriptor[] getSelectedFields() {
return new FieldDescriptor[]{new FieldDescriptorImpl(
field,
PropertyUtil.suggestGetterName(field),
PropertyUtil.suggestSetterName(field),
isToEncapsulateGet() ? PropertyUtil.generateGetterPrototype(field) : null,
isToEncapsulateSet() ? PropertyUtil.generateSetterPrototype(field) : null
)};
}
@Override
public boolean isToEncapsulateGet() {
return generateGetters;
}
@Override
public boolean isToEncapsulateSet() {
return generateSetters;
}
@Override
public boolean isToUseAccessorsWhenAccessible() {
return true;
}
@Override
public String getFieldsVisibility() {
return null;
}
@Override
public String getAccessorsVisibility() {
return PsiModifier.PUBLIC;
}
@Override
public int getJavadocPolicy() {
return DocCommentPolicy.MOVE;
}
@Override
public PsiClass getTargetClass() {
return aClass;
}
});
processor.run();
LocalFileSystem.getInstance().refresh(false);
FileDocumentManager.getInstance().saveAllDocuments();
}
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
if (conflicts != null) {
Assert.assertEquals(conflicts, e.getMessage());
return;
}
else {
e.printStackTrace();
fail(e.getMessage());
}
}
if (conflicts != null) {
fail("Conflicts were not detected: " + conflicts);
}
}