IDEADEV-40452
[fedora-idea.git] / plugins / InspectionGadgets / src / com / siyeh / ig / threading / VolatileLongOrDoubleFieldInspection.java
blob0619dc89d24cb651af70de28873e11d354f520a1
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.threading;
18 import com.intellij.psi.PsiField;
19 import com.intellij.psi.PsiModifier;
20 import com.intellij.psi.PsiType;
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 VolatileLongOrDoubleFieldInspection extends BaseInspection {
28 @NotNull
29 public String getDisplayName() {
30 return InspectionGadgetsBundle.message(
31 "volatile.long.or.double.field.display.name");
34 @NotNull
35 public String buildErrorString(Object... infos) {
36 final PsiType type = (PsiType)infos[0];
37 final String typeString = type.getPresentableText();
38 return InspectionGadgetsBundle.message(
39 "volatile.field.problem.descriptor", typeString);
42 public BaseInspectionVisitor buildVisitor() {
43 return new VolatileLongOrDoubleFieldVisitor();
46 private static class VolatileLongOrDoubleFieldVisitor
47 extends BaseInspectionVisitor {
49 @Override public void visitField(@NotNull PsiField field) {
50 super.visitField(field);
51 if (!field.hasModifierProperty(PsiModifier.VOLATILE)) {
52 return;
54 final PsiType type = field.getType();
55 if (PsiType.LONG.equals(type) || PsiType.DOUBLE.equals(type)) {
56 registerFieldError(field, type);