本文整理汇总了Java中com.siyeh.ig.psiutils.ExceptionUtils类的典型用法代码示例。如果您正苦于以下问题:Java ExceptionUtils类的具体用法?Java ExceptionUtils怎么用?Java ExceptionUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExceptionUtils类属于com.siyeh.ig.psiutils包,在下文中一共展示了ExceptionUtils类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findMaskedExceptions
import com.siyeh.ig.psiutils.ExceptionUtils; //导入依赖的package包/类
private List<PsiType> findMaskedExceptions(Set<PsiType> thrownTypes, PsiType caughtType, Set<PsiType> caughtTypes) {
if (thrownTypes.contains(caughtType)) {
if (ignoreThrown) {
return Collections.emptyList();
}
caughtTypes.add(caughtType);
thrownTypes.remove(caughtType);
}
if (onlyWarnOnRootExceptions) {
if (!ExceptionUtils.isGenericExceptionClass(caughtType)) {
return Collections.emptyList();
}
}
final List<PsiType> maskedTypes = new ArrayList<PsiType>();
for (PsiType typeThrown : thrownTypes) {
if (!caughtTypes.contains(typeThrown) && caughtType.isAssignableFrom(typeThrown)) {
caughtTypes.add(typeThrown);
maskedTypes.add(typeThrown);
}
}
return maskedTypes;
}
示例2: visitCatchSection
import com.siyeh.ig.psiutils.ExceptionUtils; //导入依赖的package包/类
@Override
public void visitCatchSection(PsiCatchSection section) {
super.visitCatchSection(section);
final PsiParameter parameter = section.getParameter();
if (parameter == null) {
return;
}
final PsiCodeBlock catchBlock = section.getCatchBlock();
if (catchBlock == null) {
return;
}
final PsiTypeElement typeElement = parameter.getTypeElement();
if (typeElement == null) {
return;
}
final PsiType type = typeElement.getType();
if (!hasJavaLangErrorType(type) || ExceptionUtils.isThrowableRethrown(parameter, catchBlock)) {
return;
}
registerVariableError(parameter);
}
示例3: visitCatchSection
import com.siyeh.ig.psiutils.ExceptionUtils; //导入依赖的package包/类
@Override
public void visitCatchSection(PsiCatchSection section) {
super.visitCatchSection(section);
final PsiParameter parameter = section.getParameter();
if (parameter == null) {
return;
}
final PsiCodeBlock catchBlock = section.getCatchBlock();
if (catchBlock == null) {
return;
}
final PsiTypeElement typeElement = parameter.getTypeElement();
if (typeElement == null) {
return;
}
final PsiType type = typeElement.getType();
if (!hasJavaLangThreadDeathType(type) || ExceptionUtils.isThrowableRethrown(parameter, catchBlock)) {
return;
}
registerVariableError(parameter);
}
示例4: findMaskedExceptions
import com.siyeh.ig.psiutils.ExceptionUtils; //导入依赖的package包/类
private List<PsiClass> findMaskedExceptions(Set<PsiClassType> exceptionsThrown, Set<PsiType> exceptionsCaught, PsiType typeCaught) {
if (exceptionsThrown.contains(typeCaught)) {
if (ignoreThrown) {
return Collections.emptyList();
}
exceptionsCaught.add(typeCaught);
exceptionsThrown.remove(typeCaught);
}
if (onlyWarnOnRootExceptions) {
if (!ExceptionUtils.isGenericExceptionClass(typeCaught)) {
return Collections.emptyList();
}
}
final List<PsiClass> typesMasked = new ArrayList();
for (PsiClassType typeThrown : exceptionsThrown) {
if (!exceptionsCaught.contains(typeThrown) && typeCaught.isAssignableFrom(typeThrown)) {
exceptionsCaught.add(typeThrown);
final PsiClass aClass = typeThrown.resolve();
if (aClass != null) {
typesMasked.add(aClass);
}
}
}
return typesMasked;
}
示例5: visitMethod
import com.siyeh.ig.psiutils.ExceptionUtils; //导入依赖的package包/类
@Override
public void visitMethod(@NotNull PsiMethod method) {
// note: no call to super
if (!MethodUtils.methodMatches(method, CommonClassNames.JAVA_UTIL_ITERATOR, null,
HardcodedMethodConstants.NEXT)) {
return;
}
final Set<PsiClassType> exceptions =
ExceptionUtils.calculateExceptionsThrown(method);
for (final PsiType exception : exceptions) {
if (exception.equalsToText(
"java.util.NoSuchElementException")) {
return;
}
}
if (IteratorUtils.containsCallToIteratorNext(method, null, false)) {
return;
}
final CalledMethodsVisitor visitor = new CalledMethodsVisitor();
method.accept(visitor);
if (visitor.isNoSuchElementExceptionThrown()) {
return;
}
registerMethodError(method);
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:26,代码来源:IteratorNextDoesNotThrowNoSuchElementExceptionInspection.java
示例6: visitMethodCallExpression
import com.siyeh.ig.psiutils.ExceptionUtils; //导入依赖的package包/类
@Override
public void visitMethodCallExpression(
PsiMethodCallExpression expression) {
if (noSuchElementExceptionThrown) {
return;
}
super.visitMethodCallExpression(expression);
final PsiReferenceExpression methodExpression =
expression.getMethodExpression();
final PsiElement method = methodExpression.resolve();
if (method == null) {
return;
}
final Set<PsiClassType> exceptions =
ExceptionUtils.calculateExceptionsThrown(method);
for (final PsiType exception : exceptions) {
if (exception.equalsToText(
"java.util.NoSuchElementException")) {
noSuchElementExceptionThrown = true;
}
}
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:23,代码来源:IteratorNextDoesNotThrowNoSuchElementExceptionInspection.java
示例7: visitTryStatement
import com.siyeh.ig.psiutils.ExceptionUtils; //导入依赖的package包/类
@Override
public void visitTryStatement(@NotNull PsiTryStatement statement) {
super.visitTryStatement(statement);
final PsiCodeBlock tryBlock = statement.getTryBlock();
if (tryBlock == null) {
return;
}
final Set<PsiType> thrownTypes = ExceptionUtils.calculateExceptionsThrown(tryBlock);
ExceptionUtils.calculateExceptionsThrown(statement.getResourceList(), thrownTypes);
final Set<PsiType> caughtTypes = new HashSet<PsiType>(thrownTypes.size());
final PsiCatchSection[] catchSections = statement.getCatchSections();
boolean runtimeExceptionSeen = false;
for (final PsiCatchSection catchSection : catchSections) {
final PsiParameter parameter = catchSection.getParameter();
if (parameter == null) {
continue;
}
final PsiTypeElement typeElement = parameter.getTypeElement();
if (typeElement == null) {
continue;
}
final PsiTypeElement[] children = PsiTreeUtil.getChildrenOfType(typeElement, PsiTypeElement.class);
if (children != null) {
for (PsiTypeElement child : children) {
runtimeExceptionSeen = check(thrownTypes, child, runtimeExceptionSeen, caughtTypes);
}
}
else {
runtimeExceptionSeen = check(thrownTypes, typeElement, runtimeExceptionSeen, caughtTypes);
}
}
}
示例8: visitThrowStatement
import com.siyeh.ig.psiutils.ExceptionUtils; //导入依赖的package包/类
@Override
public void visitThrowStatement(PsiThrowStatement statement) {
super.visitThrowStatement(statement);
final PsiExpression exception = statement.getException();
if (exception == null) {
return;
}
final PsiType exceptionType = exception.getType();
if (exceptionType == null) {
return;
}
PsiTryStatement containingTryStatement = PsiTreeUtil.getParentOfType(statement, PsiTryStatement.class, true, PsiLambdaExpression.class, PsiClass.class);
while (containingTryStatement != null) {
final PsiCodeBlock tryBlock = containingTryStatement.getTryBlock();
if (tryBlock == null) {
return;
}
if (PsiTreeUtil.isAncestor(tryBlock, statement, true)) {
final PsiParameter[] catchBlockParameters = containingTryStatement.getCatchBlockParameters();
for (PsiParameter parameter : catchBlockParameters) {
final PsiType parameterType = parameter.getType();
if (!parameterType.isAssignableFrom(exceptionType)) {
continue;
}
if (ignoreRethrownExceptions) {
final PsiCatchSection section = (PsiCatchSection)parameter.getParent();
final PsiCodeBlock catchBlock = section.getCatchBlock();
if (ExceptionUtils.isThrowableRethrown(parameter, catchBlock)) {
return;
}
}
registerStatementError(statement);
}
}
containingTryStatement = PsiTreeUtil.getParentOfType(containingTryStatement, PsiTryStatement.class, true, PsiLambdaExpression.class, PsiClass.class);
}
}
示例9: satisfiedBy
import com.siyeh.ig.psiutils.ExceptionUtils; //导入依赖的package包/类
@Override
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof PsiJavaToken)) {
return false;
}
final IElementType tokenType = ((PsiJavaToken)element).getTokenType();
if (!JavaTokenType.TRY_KEYWORD.equals(tokenType) && !JavaTokenType.CATCH_KEYWORD.equals(tokenType)) {
return false;
}
PsiElement parent = element.getParent();
if (parent instanceof PsiCatchSection) {
parent = parent.getParent();
}
if (!(parent instanceof PsiTryStatement)) {
return false;
}
final PsiTryStatement tryStatement = (PsiTryStatement)parent;
final PsiCodeBlock tryBlock = tryStatement.getTryBlock();
final Set<PsiType> exceptionsThrown = ExceptionUtils.calculateExceptionsThrown(tryBlock);
ExceptionUtils.calculateExceptionsThrown(tryStatement.getResourceList(), exceptionsThrown);
final Set<PsiType> exceptionsCaught = ExceptionUtils.getExceptionTypesHandled(tryStatement);
for (PsiType typeThrown : exceptionsThrown) {
if (exceptionsCaught.contains(typeThrown)) {
continue;
}
for (PsiType typeCaught : exceptionsCaught) {
if (typeCaught.isAssignableFrom(typeThrown)) {
return true;
}
}
}
return false;
}
示例10: visitTryStatement
import com.siyeh.ig.psiutils.ExceptionUtils; //导入依赖的package包/类
@Override
public void visitTryStatement(@NotNull PsiTryStatement statement) {
super.visitTryStatement(statement);
final PsiCodeBlock tryBlock = statement.getTryBlock();
if (tryBlock == null) {
return;
}
if (ignoreInTestCode && TestUtils.isInTestCode(statement)) {
return;
}
final Set<PsiClassType> exceptionsThrown = ExceptionUtils.calculateExceptionsThrown(tryBlock);
final int numExceptionsThrown = exceptionsThrown.size();
final Set<PsiType> exceptionsCaught = new HashSet<PsiType>(numExceptionsThrown);
final PsiCatchSection[] catchSections = statement.getCatchSections();
for (final PsiCatchSection catchSection : catchSections) {
final PsiParameter parameter = catchSection.getParameter();
if (parameter == null) {
continue;
}
final PsiType typeCaught = parameter.getType();
if (typeCaught instanceof PsiDisjunctionType) {
final PsiDisjunctionType disjunctionType = (PsiDisjunctionType)typeCaught;
final List<PsiType> types = disjunctionType.getDisjunctions();
for (PsiType type : types) {
check(exceptionsThrown, exceptionsCaught, parameter, type);
}
}
else {
check(exceptionsThrown, exceptionsCaught, parameter, typeCaught);
}
}
}
示例11: visitMethod
import com.siyeh.ig.psiutils.ExceptionUtils; //导入依赖的package包/类
@Override
public void visitMethod(PsiMethod method) {
super.visitMethod(method);
final PsiReferenceList throwsList = method.getThrowsList();
if (!throwsList.isPhysical()) {
return;
}
final PsiJavaCodeReferenceElement[] throwsReferences = throwsList.getReferenceElements();
if (throwsReferences.length == 0) {
return;
}
final PsiCodeBlock body = method.getBody();
if (body == null) {
return;
}
if (ignoreLibraryOverrides && LibraryUtil.isOverrideOfLibraryMethod(method)) {
return;
}
final Set<PsiType> exceptionsThrown = ExceptionUtils.calculateExceptionsThrown(body);
final PsiClassType[] referencedExceptions = throwsList.getReferencedTypes();
final Set<PsiType> exceptionsDeclared = new HashSet<PsiType>(referencedExceptions.length);
ContainerUtil.addAll(exceptionsDeclared, referencedExceptions);
final int referencedExceptionsLength = referencedExceptions.length;
for (int i = 0; i < referencedExceptionsLength; i++) {
final PsiClassType referencedException = referencedExceptions[i];
if (onlyWarnOnRootExceptions) {
if (!ExceptionUtils.isGenericExceptionClass(
referencedException)) {
continue;
}
}
final List<SmartTypePointer> exceptionsMasked = new ArrayList<SmartTypePointer>();
final SmartTypePointerManager pointerManager = SmartTypePointerManager.getInstance(body.getProject());
for (PsiType exceptionThrown : exceptionsThrown) {
if (referencedException.isAssignableFrom(exceptionThrown) && !exceptionsDeclared.contains(exceptionThrown)) {
exceptionsMasked.add(pointerManager.createSmartTypePointer(exceptionThrown));
}
}
if (!exceptionsMasked.isEmpty()) {
final PsiJavaCodeReferenceElement throwsReference = throwsReferences[i];
final boolean originalNeeded = exceptionsThrown.contains(referencedException);
if (ignoreThrown && originalNeeded) {
continue;
}
registerError(throwsReference, exceptionsMasked, Boolean.valueOf(originalNeeded), throwsReference);
}
}
}
示例12: visitMethod
import com.siyeh.ig.psiutils.ExceptionUtils; //导入依赖的package包/类
@Override
public void visitMethod(PsiMethod method) {
super.visitMethod(method);
final PsiAnnotation annotation =
AnnotationUtil.findAnnotation(method, "org.junit.Test");
if (annotation == null) {
return;
}
final PsiAnnotationParameterList parameterList =
annotation.getParameterList();
final PsiNameValuePair[] attributes = parameterList.getAttributes();
PsiAnnotationMemberValue value = null;
for (PsiNameValuePair attribute : attributes) {
if ("expected".equals(attribute.getName())) {
value = attribute.getValue();
break;
}
}
if (!(value instanceof PsiClassObjectAccessExpression)) {
return;
}
final PsiCodeBlock body = method.getBody();
if (body == null) {
return;
}
final PsiClassObjectAccessExpression classObjectAccessExpression =
(PsiClassObjectAccessExpression)value;
final PsiTypeElement operand =
classObjectAccessExpression.getOperand();
final PsiType type = operand.getType();
if (!(type instanceof PsiClassType)) {
return;
}
final PsiClassType classType = (PsiClassType)type;
final PsiClass aClass = classType.resolve();
if (InheritanceUtil.isInheritor(aClass,
CommonClassNames.JAVA_LANG_RUNTIME_EXCEPTION)) {
return;
}
final Set<PsiClassType> exceptionsThrown =
ExceptionUtils.calculateExceptionsThrown(body);
if (exceptionsThrown.contains(classType)) {
return;
}
registerError(operand, method);
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:47,代码来源:ExpectedExceptionNeverThrownInspection.java
示例13: visitMethod
import com.siyeh.ig.psiutils.ExceptionUtils; //导入依赖的package包/类
@Override
public void visitMethod(PsiMethod method) {
super.visitMethod(method);
final PsiReferenceList throwsList = method.getThrowsList();
if (!throwsList.isPhysical()) {
return;
}
final PsiJavaCodeReferenceElement[] throwsReferences = throwsList.getReferenceElements();
if (throwsReferences.length == 0) {
return;
}
final PsiCodeBlock body = method.getBody();
if (body == null) {
return;
}
if (ignoreInTestCode && TestUtils.isInTestCode(method)) {
return;
}
if (ignoreLibraryOverrides && LibraryUtil.isOverrideOfLibraryMethod(method)) {
return;
}
final Set<PsiClassType> exceptionsThrown = ExceptionUtils.calculateExceptionsThrown(body);
final PsiClassType[] referencedExceptions = throwsList.getReferencedTypes();
final Set<PsiClassType> exceptionsDeclared = new HashSet(referencedExceptions.length);
ContainerUtil.addAll(exceptionsDeclared, referencedExceptions);
final int referencedExceptionsLength = referencedExceptions.length;
for (int i = 0; i < referencedExceptionsLength; i++) {
final PsiClassType referencedException = referencedExceptions[i];
if (onlyWarnOnRootExceptions) {
if (!ExceptionUtils.isGenericExceptionClass(
referencedException)) {
continue;
}
}
final List<SmartTypePointer> exceptionsMasked = new ArrayList();
final SmartTypePointerManager pointerManager = SmartTypePointerManager.getInstance(body.getProject());
for (PsiClassType exceptionThrown : exceptionsThrown) {
if (referencedException.isAssignableFrom(exceptionThrown) && !exceptionsDeclared.contains(exceptionThrown)) {
exceptionsMasked.add(pointerManager.createSmartTypePointer(exceptionThrown));
}
}
if (!exceptionsMasked.isEmpty()) {
final PsiJavaCodeReferenceElement throwsReference = throwsReferences[i];
final boolean originalNeeded = exceptionsThrown.contains(referencedException);
if (ignoreThrown && originalNeeded) {
continue;
}
registerError(throwsReference, exceptionsMasked, Boolean.valueOf(originalNeeded));
}
}
}