当前位置: 首页>>代码示例>>Java>>正文


Java PsiUtil.addException方法代码示例

本文整理汇总了Java中com.intellij.psi.util.PsiUtil.addException方法的典型用法代码示例。如果您正苦于以下问题:Java PsiUtil.addException方法的具体用法?Java PsiUtil.addException怎么用?Java PsiUtil.addException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.util.PsiUtil的用法示例。


在下文中一共展示了PsiUtil.addException方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: invoke

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull Project project,
                   @NotNull PsiFile file,
                   @Nullable("is null when called from inspection") Editor editor,
                   @NotNull PsiElement startElement,
                   @NotNull PsiElement endElement) {
  final PsiClass myClass = (PsiClass)startElement;
  if (!FileModificationService.getInstance().prepareFileForWrite(myClass.getContainingFile())) return;
  PsiCodeBlock body;
  if (myClass.isInterface() && (body = myMethodPrototype.getBody()) != null) body.delete();
  for (String exception : myExceptions) {
    PsiUtil.addException(myMethodPrototype, exception);
  }
  PsiMethod method = (PsiMethod)myClass.add(myMethodPrototype);
  method = (PsiMethod)method.replace(reformat(project, method));
  postAddAction(file, editor, method);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:AddMethodFix.java

示例2: processMethod

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private static void processMethod(@NotNull Project project,
                                  @NotNull PsiMethod targetMethod,
                                  @NotNull Set<PsiClassType> unhandledExceptions) throws IncorrectOperationException {
  for (PsiClassType unhandledException : unhandledExceptions) {
    PsiClass exceptionClass = unhandledException.resolve();
    if (exceptionClass != null) {
      PsiUtil.addException(targetMethod, exceptionClass);
    }
  }

  CodeStyleManager.getInstance(project).reformat(targetMethod.getThrowsList());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:AddExceptionToThrowsFix.java

示例3: performRefactoring

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
protected void performRefactoring(@NotNull UsageInfo[] usages) {
  final List<PsiClassType> thrownExceptions = ExceptionUtil.getThrownCheckedExceptions(new PsiElement[]{myInitializer});
  final Set<PsiVariable> varsUsedInInitializer = new HashSet<PsiVariable>();
  final Set<PsiJavaCodeReferenceElement> paramRefsToInline = new HashSet<PsiJavaCodeReferenceElement>();
  final Map<PsiElement, PsiElement> replacements = new HashMap<PsiElement, PsiElement>();
  for (UsageInfo usage : usages) {
    if (usage instanceof LocalReplacementUsageInfo) {
      final LocalReplacementUsageInfo replacementUsageInfo = (LocalReplacementUsageInfo)usage;
      final PsiElement element = replacementUsageInfo.getElement();
      final PsiElement replacement = replacementUsageInfo.getReplacement();
      if (element != null && replacement != null) {
        replacements.put(element, replacement);
      }
      varsUsedInInitializer.add(replacementUsageInfo.getVariable());
    }
    else {
      LOG.assertTrue(!myCreateLocal);
      paramRefsToInline.add((PsiJavaCodeReferenceElement)usage.getElement());
    }
  }
  myInitializer = (PsiExpression)RefactoringUtil.replaceElementsWithMap(myInitializer, replacements);

  if (myCreateLocal) {
    final PsiElementFactory factory = JavaPsiFacade.getInstance(myMethod.getProject()).getElementFactory();
    PsiDeclarationStatement localDeclaration =
      factory.createVariableDeclarationStatement(myParameter.getName(), myParameter.getType(), myInitializer);
    final PsiLocalVariable declaredVar = (PsiLocalVariable)localDeclaration.getDeclaredElements()[0];
    PsiUtil.setModifierProperty(declaredVar, PsiModifier.FINAL, myParameter.hasModifierProperty(PsiModifier.FINAL));
    final PsiExpression localVarInitializer =
      InlineUtil.inlineVariable(myParameter, myInitializer, (PsiReferenceExpression)factory.createExpressionFromText(myParameter.getName(), myMethod));
    final PsiExpression initializer = declaredVar.getInitializer();
    LOG.assertTrue(initializer != null);
    initializer.replace(localVarInitializer);
    final PsiCodeBlock body = myMethod.getBody();
    if (body != null) {
      PsiElement anchor = findAnchorForLocalVariableDeclaration(body);
      body.addAfter(localDeclaration, anchor);
    }
  } else {
    for (PsiJavaCodeReferenceElement paramRef : paramRefsToInline) {
      InlineUtil.inlineVariable(myParameter, myInitializer, paramRef);
    }
  }

  //delete var if it becomes unused
  for (PsiVariable variable : varsUsedInInitializer) {
    if (variable != null && variable.isValid()) {
      if (ReferencesSearch.search(variable).findFirst() == null) {
        variable.delete();
      }
    }
  }

  SameParameterValueInspection.InlineParameterValueFix.removeParameter(myMethod, myParameter);

  if (!thrownExceptions.isEmpty()) {
    for (PsiClassType exception : thrownExceptions) {
      PsiClass exceptionClass = exception.resolve();
      if (exceptionClass != null) {
        PsiUtil.addException(myMethod, exceptionClass);
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:66,代码来源:InlineParameterExpressionProcessor.java

示例4: doFix

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
  final PsiElement methodNameIdentifier = descriptor.getPsiElement();
  final PsiMethod method = (PsiMethod)methodNameIdentifier.getParent();
  PsiUtil.addException(method, "java.lang.CloneNotSupportedException");
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:CloneDeclaresCloneNotSupportedInspection.java


注:本文中的com.intellij.psi.util.PsiUtil.addException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。