mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
http://ea.jetbrains.com/browser/ea_problems/15404 2nd exception
& cleanup
This commit is contained in:
@@ -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.
|
||||
@@ -25,6 +25,7 @@ import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.psiutils.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -34,21 +35,25 @@ import java.util.Map;
|
||||
|
||||
public class StaticImportInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName(){
|
||||
return InspectionGadgetsBundle.message("static.import.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String buildErrorString(Object... infos){
|
||||
return InspectionGadgetsBundle.message(
|
||||
"static.import.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor(){
|
||||
return new StaticImportVisitor();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InspectionGadgetsFix buildFix(Object... infos){
|
||||
return new StaticImportFix();
|
||||
}
|
||||
@@ -61,6 +66,7 @@ public class StaticImportInspection extends BaseInspection {
|
||||
"static.import.replace.quickfix");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFix(Project project, ProblemDescriptor descriptor)
|
||||
throws IncorrectOperationException{
|
||||
final PsiImportStaticStatement importStatement =
|
||||
@@ -103,7 +109,10 @@ public class StaticImportInspection extends BaseInspection {
|
||||
private static void removeReference(
|
||||
PsiJavaCodeReferenceElement reference, PsiMember target) {
|
||||
final PsiManager manager = reference.getManager();
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
|
||||
final Project project = manager.getProject();
|
||||
final JavaPsiFacade psiFacade =
|
||||
JavaPsiFacade.getInstance(project);
|
||||
final PsiElementFactory factory = psiFacade.getElementFactory();
|
||||
final PsiClass aClass = target.getContainingClass();
|
||||
final String qualifiedName = aClass.getQualifiedName();
|
||||
final String text = reference.getText();
|
||||
@@ -129,24 +138,6 @@ public class StaticImportInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
private static StringBuilder replace(
|
||||
PsiElement element, PsiJavaCodeReferenceElement reference,
|
||||
String newReferenceText, StringBuilder out) {
|
||||
if (element.equals(reference)) {
|
||||
out.append(newReferenceText);
|
||||
return out;
|
||||
}
|
||||
final PsiElement[] children = element.getChildren();
|
||||
if (children.length == 0) {
|
||||
out.append(element.getText());
|
||||
return out;
|
||||
}
|
||||
for (PsiElement child : children) {
|
||||
replace(child, reference, newReferenceText, out);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static class StaticImportReferenceCollector
|
||||
extends JavaRecursiveElementVisitor {
|
||||
|
||||
@@ -225,7 +216,7 @@ public class StaticImportInspection extends BaseInspection {
|
||||
return references;
|
||||
}
|
||||
|
||||
public boolean isFullyQualifiedReference(
|
||||
public static boolean isFullyQualifiedReference(
|
||||
PsiJavaCodeReferenceElement reference) {
|
||||
if (!reference.isQualified()) {
|
||||
return false;
|
||||
@@ -251,17 +242,10 @@ public class StaticImportInspection extends BaseInspection {
|
||||
if (fqName == null) {
|
||||
return false;
|
||||
}
|
||||
final String text = stripAngleBrackets(reference.getText());
|
||||
final String text =
|
||||
StringUtils.stripAngleBrackets(reference.getText());
|
||||
return text.equals(fqName);
|
||||
}
|
||||
|
||||
private static String stripAngleBrackets(String string) {
|
||||
final int index = string.indexOf('<');
|
||||
if (index == -1) {
|
||||
return string;
|
||||
}
|
||||
return string.substring(0, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
@@ -23,6 +23,7 @@ import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.psiutils.StringUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -88,6 +89,11 @@ public class InstantiatingObjectToGetClassObjectInspection
|
||||
text.append("[]");
|
||||
final PsiArrayType arrayType = (PsiArrayType)type;
|
||||
getTypeText(arrayType.getComponentType(), text);
|
||||
} else if (type instanceof PsiClassType) {
|
||||
final String canonicalText = type.getCanonicalText();
|
||||
final String typeText =
|
||||
StringUtils.stripAngleBrackets(canonicalText);
|
||||
text.insert(0, typeText);
|
||||
} else {
|
||||
text.insert(0, type.getCanonicalText());
|
||||
}
|
||||
@@ -123,6 +129,10 @@ public class InstantiatingObjectToGetClassObjectInspection
|
||||
if (!(qualifier instanceof PsiNewExpression)) {
|
||||
return;
|
||||
}
|
||||
final PsiNewExpression newExpression = (PsiNewExpression)qualifier;
|
||||
if (newExpression.getAnonymousClass() != null) {
|
||||
return;
|
||||
}
|
||||
registerError(expression);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2008 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.
|
||||
@@ -105,16 +105,16 @@ public class StringUtils{
|
||||
} else if(name.charAt(nameLength - 1) == 'S'){
|
||||
singularName = name.substring(0, nameLength - 1);
|
||||
} else{
|
||||
singularName = preprendIndefiniteArticle(name);
|
||||
singularName = prependIndefiniteArticle(name);
|
||||
}
|
||||
if(keywordTable.contains(singularName)){
|
||||
return preprendIndefiniteArticle(singularName);
|
||||
return prependIndefiniteArticle(singularName);
|
||||
} else{
|
||||
return singularName;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull private static String preprendIndefiniteArticle(
|
||||
@NotNull private static String prependIndefiniteArticle(
|
||||
String singularName){
|
||||
switch(singularName.charAt(0)){
|
||||
case 'a':
|
||||
@@ -127,4 +127,12 @@ public class StringUtils{
|
||||
return 'a' + StringUtil.capitalize(singularName);
|
||||
}
|
||||
}
|
||||
|
||||
public static String stripAngleBrackets(String string) {
|
||||
final int index = string.indexOf('<');
|
||||
if (index == -1) {
|
||||
return string;
|
||||
}
|
||||
return string.substring(0, index);
|
||||
}
|
||||
}
|
||||
+4
-10
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2009 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.
|
||||
@@ -35,6 +35,7 @@ import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.HighlightUtils;
|
||||
import com.siyeh.ig.psiutils.ImportUtils;
|
||||
import com.siyeh.ig.psiutils.StringUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -279,7 +280,8 @@ public class UnnecessaryFullyQualifiedNameInspection extends BaseInspection {
|
||||
if (fqName == null) {
|
||||
return;
|
||||
}
|
||||
final String text = stripAngleBrackets(reference.getText());
|
||||
final String referenceText = reference.getText();
|
||||
final String text = StringUtils.stripAngleBrackets(referenceText);
|
||||
if(!text.equals(fqName)){
|
||||
return;
|
||||
}
|
||||
@@ -293,13 +295,5 @@ public class UnnecessaryFullyQualifiedNameInspection extends BaseInspection {
|
||||
final boolean inSameFile = elementPackageName.equals(packageName);
|
||||
registerError(reference, Boolean.valueOf(inSameFile));
|
||||
}
|
||||
|
||||
private String stripAngleBrackets(String string) {
|
||||
final int index = string.indexOf('<');
|
||||
if (index == -1) {
|
||||
return string;
|
||||
}
|
||||
return string.substring(0, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user