mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'master' of git.labs.intellij.net:idea/community
This commit is contained in:
@@ -1769,3 +1769,5 @@ ignore.methods.with.boolean.return.type.option=Ignore methods with &Boolean retu
|
||||
ignore.boolean.methods.in.an.interface.option=Ignore boolean methods in an @&interface
|
||||
ignored.io.resource.types=Ignored I/O resource types
|
||||
choose.io.resource.type.to.ignore=Choose I/O resource type to ignore
|
||||
ignore.accesses.from.the.same.class=ignore accesses from the same class
|
||||
ignore.accesses.from.equals.method=ignore accesses from 'equals()' method
|
||||
|
||||
+44
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,37 +16,63 @@
|
||||
package com.siyeh.ig.encapsulation;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.MethodUtils;
|
||||
import com.siyeh.ig.ui.MultipleCheckboxOptionsPanel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class UseOfAnotherObjectsPrivateFieldInspection
|
||||
extends BaseInspection {
|
||||
|
||||
@SuppressWarnings({"PublicField"})
|
||||
public boolean ignoreSameClass = false;
|
||||
@SuppressWarnings({"PublicField"})
|
||||
public boolean ignoreEquals = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getID(){
|
||||
return "AccessingNonPublicFieldOfAnotherObject";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName(){
|
||||
return InspectionGadgetsBundle.message(
|
||||
"accessing.non.public.field.of.another.object.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String buildErrorString(Object... infos){
|
||||
return InspectionGadgetsBundle.message(
|
||||
"accessing.non.public.field.of.another.object.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
final MultipleCheckboxOptionsPanel panel =
|
||||
new MultipleCheckboxOptionsPanel(this);
|
||||
panel.addCheckbox(InspectionGadgetsBundle.message(
|
||||
"ignore.accesses.from.the.same.class"), "ignoreSameClass");
|
||||
panel.addCheckbox(InspectionGadgetsBundle.message(
|
||||
"ignore.accesses.from.equals.method"), "ignoreEquals");
|
||||
return panel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor(){
|
||||
return new UseOfAnotherObjectsPrivateFieldVisitor();
|
||||
}
|
||||
|
||||
private static class UseOfAnotherObjectsPrivateFieldVisitor
|
||||
private class UseOfAnotherObjectsPrivateFieldVisitor
|
||||
extends BaseInspectionVisitor{
|
||||
|
||||
@Override public void visitReferenceExpression(
|
||||
@NotNull PsiReferenceExpression expression){
|
||||
super.visitReferenceExpression(expression);
|
||||
@@ -54,11 +80,26 @@ public class UseOfAnotherObjectsPrivateFieldInspection
|
||||
if(qualifier == null || qualifier instanceof PsiThisExpression){
|
||||
return;
|
||||
}
|
||||
if(ignoreEquals) {
|
||||
final PsiMethod method =
|
||||
PsiTreeUtil.getParentOfType(expression, PsiMethod.class);
|
||||
if (MethodUtils.isEquals(method)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
final PsiElement referent = expression.resolve();
|
||||
if(!(referent instanceof PsiField)){
|
||||
return;
|
||||
}
|
||||
final PsiField field = (PsiField) referent;
|
||||
if (ignoreSameClass) {
|
||||
final PsiClass parent =
|
||||
PsiTreeUtil.getParentOfType(expression, PsiClass.class);
|
||||
final PsiClass containingClass = field.getContainingClass();
|
||||
if (parent != null && parent.equals(containingClass)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(!field.hasModifierProperty(PsiModifier.PRIVATE) &&
|
||||
!field.hasModifierProperty(PsiModifier.PROTECTED)){
|
||||
return;
|
||||
@@ -68,7 +109,7 @@ public class UseOfAnotherObjectsPrivateFieldInspection
|
||||
}
|
||||
final PsiElement fieldNameElement =
|
||||
expression.getReferenceNameElement();
|
||||
if (fieldNameElement == null) {
|
||||
if(fieldNameElement == null){
|
||||
return;
|
||||
}
|
||||
registerError(fieldNameElement);
|
||||
|
||||
+11
-10
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,18 +27,21 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MapReplaceableByEnumMapInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"map.replaceable.by.enum.map.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"map.replaceable.by.enum.map.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new SetReplaceableByEnumSetVisitor();
|
||||
}
|
||||
@@ -46,7 +49,8 @@ public class MapReplaceableByEnumMapInspection extends BaseInspection {
|
||||
private static class SetReplaceableByEnumSetVisitor
|
||||
extends BaseInspectionVisitor {
|
||||
|
||||
@Override public void visitNewExpression(@NotNull PsiNewExpression expression) {
|
||||
@Override public void visitNewExpression(
|
||||
@NotNull PsiNewExpression expression) {
|
||||
super.visitNewExpression(expression);
|
||||
final PsiType type = expression.getType();
|
||||
if (!(type instanceof PsiClassType)) {
|
||||
@@ -65,19 +69,16 @@ public class MapReplaceableByEnumMapInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
if (!TypeUtils.expressionHasTypeOrSubtype(expression,
|
||||
"java.util.Map")) {
|
||||
"java.util.Map")) {
|
||||
return;
|
||||
}
|
||||
if (TypeUtils.expressionHasTypeOrSubtype(expression,
|
||||
"java.util.EnumMap")) {
|
||||
return;
|
||||
if (null != TypeUtils.expressionHasTypeOrSubtype(expression,
|
||||
"java.util.EnumMap", "java.util.concurrent.ConcurrentMap")) {
|
||||
return;
|
||||
}
|
||||
final PsiClassType argumentClassType = (PsiClassType)argumentType;
|
||||
final PsiClass argumentClass = argumentClassType.resolve();
|
||||
if (argumentClass == null) {
|
||||
return;
|
||||
}
|
||||
if (!argumentClass.isEnum()) {
|
||||
if (argumentClass == null || !argumentClass.isEnum()) {
|
||||
return;
|
||||
}
|
||||
registerNewExpressionError(expression);
|
||||
|
||||
+8
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,18 +27,21 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SetReplaceableByEnumSetInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"set.replaceable.by.enum.set.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"set.replaceable.by.enum.set.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new SetReplaceableByEnumSetVisitor();
|
||||
}
|
||||
@@ -46,7 +49,8 @@ public class SetReplaceableByEnumSetInspection extends BaseInspection {
|
||||
private static class SetReplaceableByEnumSetVisitor
|
||||
extends BaseInspectionVisitor {
|
||||
|
||||
@Override public void visitNewExpression(@NotNull PsiNewExpression expression) {
|
||||
@Override public void visitNewExpression(
|
||||
@NotNull PsiNewExpression expression) {
|
||||
super.visitNewExpression(expression);
|
||||
final PsiType type = expression.getType();
|
||||
if (!(type instanceof PsiClassType)) {
|
||||
@@ -65,11 +69,11 @@ public class SetReplaceableByEnumSetInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
if (!TypeUtils.expressionHasTypeOrSubtype(expression,
|
||||
"java.util.Set")) {
|
||||
"java.util.Set")) {
|
||||
return;
|
||||
}
|
||||
if (TypeUtils.expressionHasTypeOrSubtype(expression,
|
||||
"java.util.EnumSet")) {
|
||||
"java.util.EnumSet")) {
|
||||
return;
|
||||
}
|
||||
final PsiClassType argumentClassType = (PsiClassType)argumentType;
|
||||
|
||||
@@ -7,8 +7,7 @@ discussion of double-checked locking and why it is unsafe, see
|
||||
">http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html</a>
|
||||
<p>
|
||||
Use the checkbox below to ignore double-checked locking on volatile fields. Using
|
||||
a volatile field for double-checked locking works correctly on Java 5 virtual machines,
|
||||
but probably does not have any performance advantages over plain full synchronization
|
||||
of the accessor method.
|
||||
a volatile field for double-checked locking works correctly on virtual machines which
|
||||
implement the new Java Memory Model.
|
||||
</font></td> </tr> <tr> <td height="20"> <font face="verdana" size="-2">Powered by InspectionGadgets </font> </td> </tr> </table> </body>
|
||||
</html>
|
||||
+5
@@ -7,5 +7,10 @@ some coding styles discourage this use. Additionally, such direct access to pri
|
||||
may fail in component-oriented architectures such (e.g. Spring, Hibernate) which expect all access
|
||||
to other objects to be through method calls so as to allow the framework to mediate all access
|
||||
using proxies.
|
||||
<p>
|
||||
Use the first checkbox below to ignore accesses from the same class and only report accesses
|
||||
from inner or outer classes.<br>
|
||||
Use the second checkbox below to ignore accesses from an <b><font color="#000080">equals()</font></b> method.
|
||||
</p>
|
||||
</font></td> </tr> <tr> <td height="20"> <font face="verdana" size="-2">Powered by InspectionGadgets </font> </td> </tr> </table> </body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user