本文整理汇总了Java中com.intellij.psi.util.PsiUtil.getAccessModifier方法的典型用法代码示例。如果您正苦于以下问题:Java PsiUtil.getAccessModifier方法的具体用法?Java PsiUtil.getAccessModifier怎么用?Java PsiUtil.getAccessModifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.util.PsiUtil
的用法示例。
在下文中一共展示了PsiUtil.getAccessModifier方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invokeImpl
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
protected void invokeImpl(PsiClass targetClass) {
if (CreateFromUsageUtils.isValidReference(myReferenceExpression, false)) return;
final Project project = myReferenceExpression.getProject();
PsiType[] expectedTypes = CreateFromUsageUtils.guessType(myReferenceExpression, false);
PsiType type = expectedTypes[0];
final String varName = myReferenceExpression.getReferenceName();
PsiMethod method = PsiTreeUtil.getParentOfType(myReferenceExpression, PsiMethod.class);
LOG.assertTrue(method != null);
method = IntroduceParameterHandler.chooseEnclosingMethod(method);
if (method == null) return;
method = SuperMethodWarningUtil.checkSuperMethod(method, RefactoringBundle.message("to.refactor"));
if (method == null) return;
final List<ParameterInfoImpl> parameterInfos =
new ArrayList<ParameterInfoImpl>(Arrays.asList(ParameterInfoImpl.fromMethod(method)));
ParameterInfoImpl parameterInfo = new ParameterInfoImpl(-1, varName, type, varName, false);
if (!method.isVarArgs()) {
parameterInfos.add(parameterInfo);
}
else {
parameterInfos.add(parameterInfos.size() - 1, parameterInfo);
}
final Application application = ApplicationManager.getApplication();
if (application.isUnitTestMode()) {
ParameterInfoImpl[] array = parameterInfos.toArray(new ParameterInfoImpl[parameterInfos.size()]);
String modifier = PsiUtil.getAccessModifier(PsiUtil.getAccessLevel(method.getModifierList()));
ChangeSignatureProcessor processor =
new ChangeSignatureProcessor(project, method, false, modifier, method.getName(), method.getReturnType(), array);
processor.run();
}
else {
final PsiMethod finalMethod = method;
application.invokeLater(new Runnable() {
@Override
public void run() {
if (project.isDisposed()) return;
try {
JavaChangeSignatureDialog dialog =
JavaChangeSignatureDialog.createAndPreselectNew(project, finalMethod, parameterInfos, true, myReferenceExpression);
dialog.setParameterInfos(parameterInfos);
if (dialog.showAndGet()) {
for (ParameterInfoImpl info : parameterInfos) {
if (info.getOldIndex() == -1) {
final String newParamName = info.getName();
if (!Comparing.strEqual(varName, newParamName)) {
final PsiExpression newExpr =
JavaPsiFacade.getElementFactory(project).createExpressionFromText(newParamName, finalMethod);
new WriteCommandAction(project) {
@Override
protected void run(@NotNull Result result) throws Throwable {
final PsiReferenceExpression[] refs =
CreateFromUsageUtils.collectExpressions(myReferenceExpression, PsiMember.class, PsiFile.class);
for (PsiReferenceExpression ref : refs) {
ref.replace(newExpr.copy());
}
}
}.execute();
}
break;
}
}
}
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
}