IDEADEV-40452
[fedora-idea.git] / plugins / InspectionGadgets / src / com / siyeh / ig / bugs / ResultOfObjectAllocationIgnoredInspection.java
blob9178f69593bbe617b86ff7e9df55ecabc8984610
1 /*
2 * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.siyeh.ig.bugs;
18 import com.intellij.psi.PsiExpression;
19 import com.intellij.psi.PsiExpressionStatement;
20 import com.intellij.psi.PsiNewExpression;
21 import com.siyeh.InspectionGadgetsBundle;
22 import com.siyeh.ig.BaseInspection;
23 import com.siyeh.ig.BaseInspectionVisitor;
24 import org.jetbrains.annotations.NotNull;
26 public class ResultOfObjectAllocationIgnoredInspection
27 extends BaseInspection {
29 @NotNull
30 public String getDisplayName() {
31 return InspectionGadgetsBundle.message(
32 "result.of.object.allocation.ignored.display.name");
35 @NotNull
36 public String buildErrorString(Object... infos) {
37 return InspectionGadgetsBundle.message(
38 "result.of.object.allocation.ignored.problem.descriptor");
41 public BaseInspectionVisitor buildVisitor() {
42 return new IgnoreResultOfCallVisitor();
45 private static class IgnoreResultOfCallVisitor
46 extends BaseInspectionVisitor {
48 @Override public void visitExpressionStatement(
49 @NotNull PsiExpressionStatement statement) {
50 super.visitExpressionStatement(statement);
51 final PsiExpression expression = statement.getExpression();
52 if (!(expression instanceof PsiNewExpression)) {
53 return;
55 final PsiNewExpression newExpression =
56 (PsiNewExpression) expression;
57 final PsiExpression[] arrayDimensions =
58 newExpression.getArrayDimensions();
59 if (arrayDimensions.length != 0) {
60 return;
62 if (newExpression.getArrayInitializer() != null) {
63 return;
65 registerNewExpressionError(newExpression);