Java 类com.intellij.psi.PsiCatchSection 实例源码

项目:intellij-ce-playground    文件:BadExceptionCaughtInspectionBase.java   
@Override
public void visitCatchSection(PsiCatchSection section) {
  super.visitCatchSection(section);
  final PsiParameter parameter = section.getParameter();
  if (parameter == null) {
    return;
  }
  final PsiTypeElement typeElement = parameter.getTypeElement();
  if (typeElement == null) {
    return;
  }
  final PsiTypeElement[] childTypeElements = PsiTreeUtil.getChildrenOfType(typeElement, PsiTypeElement.class);
  if (childTypeElements != null) {
    for (PsiTypeElement childTypeElement : childTypeElements) {
      checkTypeElement(childTypeElement);
    }
  }
  else {
    checkTypeElement(typeElement);
  }
}
项目:tools-idea    文件:BadExceptionCaughtInspection.java   
@Override
public void visitCatchSection(PsiCatchSection section) {
  super.visitCatchSection(section);
  final PsiParameter parameter = section.getParameter();
  if (parameter == null) {
    return;
  }
  final PsiTypeElement typeElement = parameter.getTypeElement();
  if (typeElement == null) {
    return;
  }
  final PsiTypeElement[] childTypeElements = PsiTreeUtil.getChildrenOfType(typeElement, PsiTypeElement.class);
  if (childTypeElements != null) {
    for (PsiTypeElement childTypeElement : childTypeElements) {
      checkTypeElement(childTypeElement);
    }
  }
  else {
    checkTypeElement(typeElement);
  }
}
项目:tools-idea    文件:ParameterOfConcreteClassInspection.java   
@Override
public void visitParameter(@NotNull PsiParameter parameter) {
  super.visitParameter(parameter);

  if (parameter.getDeclarationScope() instanceof PsiCatchSection) {
    return;
  }
  final PsiTypeElement typeElement = parameter.getTypeElement();
  if (typeElement == null) {
    return;
  }
  if (!ConcreteClassUtil.typeIsConcreteClass(typeElement,
                                             ignoreAbstractClasses)) {
    return;
  }
  final String variableName = parameter.getName();
  registerError(typeElement, variableName);
}
项目:consulo-java    文件:MissingCatchBodyFixer.java   
@Override
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException
{
    if(!(psiElement instanceof PsiCatchSection))
    {
        return;
    }
    PsiCatchSection catchSection = (PsiCatchSection) psiElement;

    final Document doc = editor.getDocument();

    PsiCodeBlock body = catchSection.getCatchBlock();
    if(body != null && startLine(doc, body) == startLine(doc, catchSection))
    {
        return;
    }

    final PsiJavaToken rParenth = catchSection.getRParenth();
    if(rParenth == null)
    {
        return;
    }

    doc.insertString(rParenth.getTextRange().getEndOffset(), "{}");
}
项目:consulo-java    文件:ParameterOfConcreteClassInspection.java   
@Override
public void visitParameter(@NotNull PsiParameter parameter) {
  super.visitParameter(parameter);

  if (parameter.getDeclarationScope() instanceof PsiCatchSection) {
    return;
  }
  final PsiTypeElement typeElement = parameter.getTypeElement();
  if (typeElement == null) {
    return;
  }
  if (!ConcreteClassUtil.typeIsConcreteClass(typeElement,
                                             ignoreAbstractClasses)) {
    return;
  }
  final String variableName = parameter.getName();
  registerError(typeElement, variableName);
}
项目:consulo-java    文件:BadExceptionCaughtInspection.java   
@Override
public void visitCatchSection(PsiCatchSection section) {
  super.visitCatchSection(section);
  final PsiParameter parameter = section.getParameter();
  if (parameter == null) {
    return;
  }
  final PsiTypeElement typeElement = parameter.getTypeElement();
  if (typeElement == null) {
    return;
  }
  final PsiTypeElement[] childTypeElements = PsiTreeUtil.getChildrenOfType(typeElement, PsiTypeElement.class);
  if (childTypeElements != null) {
    for (PsiTypeElement childTypeElement : childTypeElements) {
      checkTypeElement(childTypeElement);
    }
  }
  else {
    checkTypeElement(typeElement);
  }
}
项目:tools-idea    文件:ParameterNamingConventionInspection.java   
@Override
public void visitParameter(@NotNull PsiParameter variable) {
  final PsiElement scope = variable.getDeclarationScope();
  if (scope instanceof PsiCatchSection ||
      scope instanceof PsiForeachStatement) {
    return;
  }
  final String name = variable.getName();
  if (name == null || isValid(name)) {
    return;
  }
  registerVariableError(variable, name);
}
项目:consulo-java    文件:ControlTransferHandler.java   
@NotNull
private List<DfaInstructionState> processCatches(Trap.TryCatch tryCatch, DfaValue thrownValue, FList<Trap> traps)
{
    List<DfaInstructionState> result = new ArrayList<>();
    for(Map.Entry<PsiCatchSection, ControlFlow.ControlFlowOffset> entry : tryCatch.getClauses().entrySet())
    {
        PsiCatchSection catchSection = entry.getKey();
        ControlFlow.ControlFlowOffset jumpOffset = entry.getValue();

        PsiParameter param = catchSection.getParameter();
        if(param == null)
        {
            continue;
        }

        if(throwableState == null)
        {
            throwableState = initVariableState(param, thrownValue);
        }

        for(DfaTypeValue caughtType : allCaughtTypes(param))
        {
            DfaVariableState varState = throwableState.withInstanceofValue(caughtType);
            if(varState != null)
            {
                result.add(new DfaInstructionState(myRunner.getInstruction(jumpOffset.getInstructionOffset()), stateForCatchClause(param, varState)));
            }

            throwableState = throwableState.withNotInstanceofValue(caughtType);

            if(throwableState == null)
            {
                return result;
            }
        }
    }
    return ContainerUtil.concat(result, iteration(traps));
}
项目:consulo-java    文件:CatchDeclarationFixer.java   
@Override
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException
{
    if(psiElement instanceof PsiCatchSection)
    {
        final Document doc = editor.getDocument();
        final PsiCatchSection catchSection = (PsiCatchSection) psiElement;

        final int catchStart = catchSection.getTextRange().getStartOffset();
        int stopOffset = doc.getLineEndOffset(doc.getLineNumber(catchStart));

        final PsiCodeBlock catchBlock = catchSection.getCatchBlock();
        if(catchBlock != null)
        {
            stopOffset = Math.min(stopOffset, catchBlock.getTextRange().getStartOffset());
        }
        stopOffset = Math.min(stopOffset, catchSection.getTextRange().getEndOffset());

        final PsiJavaToken lParenth = catchSection.getLParenth();
        if(lParenth == null)
        {
            doc.replaceString(catchStart, stopOffset, "catch ()");
            processor.registerUnresolvedError(catchStart + "catch (".length());
        }
        else
        {
            if(catchSection.getParameter() == null)
            {
                processor.registerUnresolvedError(lParenth.getTextRange().getEndOffset());
            }
            if(catchSection.getRParenth() == null)
            {
                doc.insertString(stopOffset, ")");
            }
        }
    }
}
项目:consulo-java    文件:ParameterNamingConventionInspection.java   
@Override
public void visitParameter(@NotNull PsiParameter variable) {
  final PsiElement scope = variable.getDeclarationScope();
  if (scope instanceof PsiCatchSection ||
      scope instanceof PsiForeachStatement) {
    return;
  }
  final String name = variable.getName();
  if (name == null || isValid(name)) {
    return;
  }
  registerVariableError(variable, name);
}
项目:consulo-java    文件:UnusedCatchParameterInspection.java   
@Override
public void visitTryStatement(@NotNull PsiTryStatement statement) {
  super.visitTryStatement(statement);
  if (m_ignoreTestCases && TestUtils.isInTestCode(statement)) {
    return;
  }
  final PsiCatchSection[] catchSections = statement.getCatchSections();
  for (PsiCatchSection catchSection : catchSections) {
    checkCatchSection(catchSection);
  }
}
项目:consulo-java    文件:UnusedCatchParameterInspection.java   
private void checkCatchSection(PsiCatchSection section) {
  final PsiParameter parameter = section.getParameter();
  if (parameter == null) {
    return;
  }
  @NonNls final String parameterName = parameter.getName();
  final boolean namedIgnore = parameterName.contains("ignore");
  final PsiCodeBlock block = section.getCatchBlock();
  if (block == null) {
    return;
  }
  if (m_ignoreCatchBlocksWithComments) {
    final PsiElement[] children = block.getChildren();
    for (final PsiElement child : children) {
      if (child instanceof PsiComment) {
        return;
      }
    }
  }
  final CatchParameterUsedVisitor visitor =
    new CatchParameterUsedVisitor(parameter);
  block.accept(visitor);
  if (visitor.isUsed()) {
    if (namedIgnore) {
      registerVariableError(parameter, Boolean.valueOf(true));
    }
    return;
  }
  else if (namedIgnore) {
    return;
  }
  registerVariableError(parameter, Boolean.valueOf(false));
}
项目:Android_Lint_SRP_Practice_Example    文件:PsiClassStructureDetector.java   
@Override
public void visitCatchSection(PsiCatchSection section) {
    mVisitor.report("PsiCatchSection", section.getText(), section);
    super.visitElement(section);
}
项目:intellij-ce-playground    文件:MoveCatchUpFix.java   
public MoveCatchUpFix(@NotNull PsiCatchSection catchSection, @NotNull PsiCatchSection moveBeforeSection) {
  this.myCatchSection = catchSection;
  myMoveBeforeSection = moveBeforeSection;
}
项目:intellij-ce-playground    文件:JavaCatchRemover.java   
@Override
public boolean isApplicableTo(PsiElement e) {
  return e instanceof PsiCatchSection && tryHasSeveralCatchesOrResourcesDefined(e);
}
项目:intellij-ce-playground    文件:AssignmentToCatchBlockParameterInspection.java   
@Override
protected boolean isCorrectScope(PsiElement declarationScope) {
  return declarationScope instanceof PsiCatchSection;
}
项目:tools-idea    文件:MoveCatchUpFix.java   
public MoveCatchUpFix(PsiCatchSection catchSection, PsiCatchSection moveBeforeSection) {
this.myCatchSection = catchSection;
    myMoveBeforeSection = moveBeforeSection;
}
项目:tools-idea    文件:JavaCatchRemover.java   
@Override
public boolean isApplicableTo(PsiElement e) {
  return e instanceof PsiCatchSection && tryHasSeveralCatches(e);
}
项目:consulo-java    文件:CoreJavaPsiImplementationHelper.java   
@Override
public void setupCatchBlock(String exceptionName, PsiElement context, PsiCatchSection element)
{
    throw new UnsupportedOperationException("TODO");
}
项目:consulo-java    文件:Trap.java   
TryCatch(PsiTryStatement tryStatement, Map<PsiCatchSection, ControlFlow.ControlFlowOffset> clauses)
{
    super(tryStatement);
    myTryStatement = tryStatement;
    myClauses = clauses;
}
项目:consulo-java    文件:Trap.java   
@NotNull
public Map<PsiCatchSection, ControlFlow.ControlFlowOffset> getClauses()
{
    return myClauses;
}
项目:consulo-java    文件:MoveCatchUpFix.java   
public MoveCatchUpFix(@NotNull PsiCatchSection catchSection, @NotNull PsiCatchSection moveBeforeSection) {
  this.myCatchSection = catchSection;
  myMoveBeforeSection = moveBeforeSection;
}
项目:consulo-java    文件:JavaCatchRemover.java   
@Override
public boolean isApplicableTo(PsiElement e) {
  return e instanceof PsiCatchSection && tryHasSeveralCatches(e);
}
项目:consulo-java    文件:JavaPsiImplementationHelper.java   
public abstract void setupCatchBlock(String exceptionName, PsiElement context, PsiCatchSection element);