本文整理汇总了Java中com.intellij.codeInsight.generation.GenerateMembersUtil.generateGetterPrototype方法的典型用法代码示例。如果您正苦于以下问题:Java GenerateMembersUtil.generateGetterPrototype方法的具体用法?Java GenerateMembersUtil.generateGetterPrototype怎么用?Java GenerateMembersUtil.generateGetterPrototype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.codeInsight.generation.GenerateMembersUtil
的用法示例。
在下文中一共展示了GenerateMembersUtil.generateGetterPrototype方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processUsagesForMethod
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
private void processUsagesForMethod(final boolean deleteMethodHierarchy, PsiMethod method, int[] paramPermutation, String getterName, PsiMethod delegatedMethod,
List<FixableUsageInfo> usages) {
for (PsiReference reference : ReferencesSearch.search(method)) {
final PsiElement referenceElement = reference.getElement();
final PsiMethodCallExpression call = (PsiMethodCallExpression)referenceElement.getParent();
final String access;
if (call.getMethodExpression().getQualifierExpression() == null) {
access = field.getName();
} else {
access = getterName + "()";
if (getter == null) {
getter = GenerateMembersUtil.generateGetterPrototype(field);
}
}
usages.add(new InlineDelegatingCall(call, paramPermutation, access, delegatedMethod.getName()));
}
if (deleteMethodHierarchy) {
usages.add(new DeleteMethod(method));
}
}
示例2: anyFieldsWithGettersPresent
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
public static boolean anyFieldsWithGettersPresent(List<UsageInfo> classMemberRefs) {
for (UsageInfo usageInfo : classMemberRefs) {
if (usageInfo.getElement() instanceof PsiReferenceExpression) {
PsiElement e = ((PsiReferenceExpression)usageInfo.getElement()).resolve();
if (e instanceof PsiField) {
PsiField psiField = (PsiField)e;
PsiMethod getterPrototype = GenerateMembersUtil.generateGetterPrototype(psiField);
PsiMethod getter = psiField.getContainingClass().findMethodBySignature(getterPrototype, true);
if (getter != null) return true;
}
}
}
return false;
}
示例3: registerQuickFix
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的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
示例4: processUsagesForMethod
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
private void processUsagesForMethod(final boolean deleteMethodHierarchy, PsiMethod method, int[] paramPermutation, String getterName, PsiMethod delegatedMethod,
List<FixableUsageInfo> usages) {
for (PsiReference reference : ReferencesSearch.search(method)) {
final PsiElement referenceElement = reference.getElement();
final PsiMethodCallExpression call = (PsiMethodCallExpression)referenceElement.getParent();
final String access;
if (call.getMethodExpression().getQualifierExpression() == null) {
access = field.getName();
} else {
access = getterName + "()";
if (getter == null) {
getter = GenerateMembersUtil.generateGetterPrototype(field);
}
}
usages.add(new InlineDelegatingCall(call, paramPermutation, access, delegatedMethod.getName()));
}
if (deleteMethodHierarchy) {
usages.add(new DeleteMethod(method));
}
}
示例5: generateMethodPrototype
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
@Override
@Nullable
public PsiMethod generateMethodPrototype(@NotNull PsiField field, @NotNull String methodName, boolean isGetter) {
PsiMethod prototype = isGetter
? GenerateMembersUtil.generateGetterPrototype(field)
: GenerateMembersUtil.generateSetterPrototype(field);
try {
prototype.setName(methodName);
return prototype;
}
catch (IncorrectOperationException e) {
return null;
}
}
示例6: beforeTemplateFinished
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
@Override
protected void beforeTemplateFinished(PsiClass aClass, PsiField field) {
PsiMethod getterPrototype = GenerateMembersUtil.generateGetterPrototype(field);
if (aClass.findMethodsBySignature(getterPrototype, false).length == 0) {
aClass.add(getterPrototype);
}
PsiMethod setterPrototype = GenerateMembersUtil.generateSetterPrototype(field);
if (aClass.findMethodsBySignature(setterPrototype, false).length == 0) {
aClass.add(setterPrototype);
}
super.beforeTemplateFinished(aClass, field);
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:16,代码来源:CreateGetterSetterPropertyFromUsageFix.java
示例7: generateMethodPrototype
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
private PsiMethod generateMethodPrototype(PsiField field, String methodName, boolean isGetter) {
PsiMethod prototype = isGetter
? GenerateMembersUtil.generateGetterPrototype(field)
: GenerateMembersUtil.generateSetterPrototype(field);
try {
PsiElementFactory factory = JavaPsiFacade.getInstance(field.getProject()).getElementFactory();
PsiIdentifier identifier = factory.createIdentifier(methodName);
prototype.getNameIdentifier().replace(identifier);
//prototype.getModifierList().setModifierProperty(getAccessorsVisibility(), true);
return prototype;
} catch (IncorrectOperationException e) {
return null;
}
}
示例8: replaceFieldWithGetter
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
private PsiElement replaceFieldWithGetter(PsiElement expr, PsiField psiField, boolean qualify) throws IncorrectOperationException {
if (RefactoringUtil.isAssignmentLHS(expr)) {
// todo: warning
return expr;
}
PsiElement newExpr = expr;
PsiMethod getterPrototype = GenerateMembersUtil.generateGetterPrototype(psiField);
PsiMethod getter = psiField.getContainingClass().findMethodBySignature(getterPrototype, true);
if (getter != null) {
if (JavaPsiFacade.getInstance(psiField.getProject()).getResolveHelper().isAccessible(getter, newExpr, null)) {
PsiElementFactory factory = JavaPsiFacade.getInstance(newExpr.getProject()).getElementFactory();
String id = getter.getName();
String qualifier = null;
if (newExpr instanceof PsiReferenceExpression) {
final PsiExpression instanceRef = getInstanceRef(factory);
if (qualify && instanceRef != null) {
qualifier = instanceRef.getText();
} else {
final PsiExpression qualifierExpression = ((PsiReferenceExpression)newExpr).getQualifierExpression();
if (qualifierExpression != null) {
qualifier = qualifierExpression.getText();
}
}
}
PsiMethodCallExpression getterCall =
(PsiMethodCallExpression)factory.createExpressionFromText((qualifier != null ? qualifier + "." : "") + id + "()", null);
getterCall = (PsiMethodCallExpression)CodeStyleManager.getInstance(myProject).reformat(getterCall);
if (newExpr.getParent() != null) {
newExpr = newExpr.replace(getterCall);
}
else {
newExpr = getterCall;
}
}
else {
// todo: warning
}
}
return newExpr;
}
示例9: doTest
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
private static void doTest(final PsiClass aClass,
final String conflicts,
final boolean generateGetters,
final boolean generateSetters,
final PsiField... fields) {
try {
final Project project = aClass.getProject();
EncapsulateFieldsProcessor processor = new EncapsulateFieldsProcessor(project, new EncapsulateFieldsDescriptor() {
@Override
public FieldDescriptor[] getSelectedFields() {
final FieldDescriptor[] descriptors = new FieldDescriptor[fields.length];
for (int i = 0; i < fields.length; i++) {
descriptors[i] = new FieldDescriptorImpl(
fields[i],
GenerateMembersUtil.suggestGetterName(fields[i]),
GenerateMembersUtil.suggestSetterName(fields[i]),
isToEncapsulateGet() ? GenerateMembersUtil.generateGetterPrototype(fields[i]) : null,
isToEncapsulateSet() ? GenerateMembersUtil.generateSetterPrototype(fields[i]) : null
);
}
return descriptors;
}
@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);
}
}