moved back to analysis

This commit is contained in:
Alexey Kudravtsev
2014-02-25 15:06:39 +04:00
parent d2bd3563f8
commit 1490fb8b65
11 changed files with 45 additions and 72 deletions
@@ -30,7 +30,6 @@ import com.intellij.codeInsight.daemon.impl.RefCountHolder;
import com.intellij.codeInsight.daemon.impl.quickfix.QuickFixAction;
import com.intellij.codeInsight.intention.QuickFixFactory;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.project.Project;
@@ -233,30 +232,30 @@ public class HighlightClassUtil {
if (aClass.getParent() != containingFile || !aClass.hasModifierProperty(PsiModifier.PUBLIC) || !(containingFile instanceof PsiJavaFile)) return null;
PsiJavaFile file = (PsiJavaFile)containingFile;
VirtualFile virtualFile = file.getVirtualFile();
HighlightInfo errorResult = null;
if (virtualFile != null && !aClass.getName().equals(virtualFile.getNameWithoutExtension())) {
String message = JavaErrorMessages.message("public.class.should.be.named.after.file", aClass.getName());
TextRange range = HighlightNamesUtil.getClassDeclarationTextRange(aClass);
errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).
range(aClass, range.getStartOffset(), range.getEndOffset()).
descriptionAndTooltip(message).create();
PsiModifierList psiModifierList = aClass.getModifierList();
QuickFixAction.registerQuickFixAction(errorResult,
QUICK_FIX_FACTORY.createModifierListFix(psiModifierList, PsiModifier.PUBLIC, false, false));
PsiClass[] classes = file.getClasses();
if (classes.length > 1) {
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createMoveClassToSeparateFileFix(aClass));
}
for (PsiClass otherClass : classes) {
if (!otherClass.getManager().areElementsEquivalent(otherClass, aClass) &&
otherClass.hasModifierProperty(PsiModifier.PUBLIC) &&
otherClass.getName().equals(virtualFile.getNameWithoutExtension())) {
return errorResult;
}
}
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createRenameFileFix(aClass.getName() + JavaFileType.DOT_DEFAULT_EXTENSION));
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createRenameElementFix(aClass));
if (virtualFile == null || aClass.getName().equals(virtualFile.getNameWithoutExtension())) {
return null;
}
String message = JavaErrorMessages.message("public.class.should.be.named.after.file", aClass.getName());
TextRange range = HighlightNamesUtil.getClassDeclarationTextRange(aClass);
HighlightInfo errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).
range(aClass, range.getStartOffset(), range.getEndOffset()).
descriptionAndTooltip(message).create();
PsiModifierList psiModifierList = aClass.getModifierList();
QuickFixAction.registerQuickFixAction(errorResult,
QUICK_FIX_FACTORY.createModifierListFix(psiModifierList, PsiModifier.PUBLIC, false, false));
PsiClass[] classes = file.getClasses();
if (classes.length > 1) {
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createMoveClassToSeparateFileFix(aClass));
}
for (PsiClass otherClass : classes) {
if (!otherClass.getManager().areElementsEquivalent(otherClass, aClass) &&
otherClass.hasModifierProperty(PsiModifier.PUBLIC) &&
otherClass.getName().equals(virtualFile.getNameWithoutExtension())) {
return errorResult;
}
}
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createRenameFileFix(aClass.getName() + JavaFileType.DOT_DEFAULT_EXTENSION));
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createRenameElementFix(aClass));
return errorResult;
}
@@ -288,7 +287,7 @@ public class HighlightClassUtil {
}
@Nullable
private static HighlightInfo checkStaticFieldDeclarationInInnerClass(PsiKeyword keyword) {
private static HighlightInfo checkStaticFieldDeclarationInInnerClass(@NotNull PsiKeyword keyword) {
if (getEnclosingStaticClass(keyword, PsiField.class) == null) {
return null;
}
@@ -340,7 +339,7 @@ public class HighlightClassUtil {
return result;
}
private static PsiElement getEnclosingStaticClass(PsiKeyword keyword, Class<?> parentClass) {
private static PsiElement getEnclosingStaticClass(@NotNull PsiKeyword keyword, @NotNull Class<?> parentClass) {
return new PsiMatcherImpl(keyword)
.dot(PsiMatchers.hasText(PsiModifier.STATIC))
.parent(PsiMatchers.hasClass(PsiModifierList.class))
@@ -2580,9 +2580,9 @@ public class HighlightUtil extends HighlightUtilBase {
}
@Nullable
static HighlightInfo checkPackageAndClassConflict(@NotNull PsiJavaCodeReferenceElement ref) {
static HighlightInfo checkPackageAndClassConflict(@NotNull PsiJavaCodeReferenceElement ref, @NotNull PsiFile containingFile) {
if (ref.isQualified() && isInsidePackageStatement(ref)) {
VirtualFile file = ref.getContainingFile().getVirtualFile();
VirtualFile file = containingFile.getVirtualFile();
if (file != null) {
Module module = ProjectFileIndex.SERVICE.getInstance(ref.getProject()).getModuleForFile(file);
if (module != null) {
@@ -1108,7 +1108,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
}
}
if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkPackageAndClassConflict(ref));
if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkPackageAndClassConflict(ref, myFile));
return result;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,7 +29,8 @@ public class PsiMatchers {
private PsiMatchers() {
}
public static PsiMatcherExpression hasName(final String name) {
@NotNull
public static PsiMatcherExpression hasName(@NotNull final String name) {
return new PsiMatcherExpression() {
@Override
public Boolean match(PsiElement element) {
@@ -39,7 +40,8 @@ public class PsiMatchers {
};
}
public static PsiMatcherExpression hasText(final String text) {
@NotNull
public static PsiMatcherExpression hasText(@NotNull final String text) {
return new PsiMatcherExpression() {
@Override
public Boolean match(PsiElement element) {
@@ -49,6 +51,7 @@ public class PsiMatchers {
};
}
@NotNull
public static PsiMatcherExpression hasText(@NotNull final String... texts) {
return new PsiMatcherExpression() {
@Override
@@ -59,7 +62,8 @@ public class PsiMatchers {
};
}
public static PsiMatcherExpression hasClass(final Class aClass) {
@NotNull
public static PsiMatcherExpression hasClass(@NotNull final Class<?> aClass) {
return new PsiMatcherExpression() {
@Override
public Boolean match(PsiElement element) {
@@ -69,11 +73,12 @@ public class PsiMatchers {
};
}
public static PsiMatcherExpression hasClass(final Class... classes) {
@NotNull
public static PsiMatcherExpression hasClass(@NotNull final Class... classes) {
return new PsiMatcherExpression() {
@Override
public Boolean match(PsiElement element) {
for (Class aClass : classes) {
for (Class<?> aClass : classes) {
if (aClass.isAssignableFrom(element.getClass())) return Boolean.TRUE;
}
return Boolean.FALSE;
@@ -1,31 +0,0 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.psi.util;
import com.intellij.psi.PsiElement;
import com.intellij.psi.xml.XmlTag;
public class XmlMatchers {
public static PsiMatcherExpression hasTagValue(final String value) {
return new PsiMatcherExpression() {
@Override
public Boolean match(PsiElement element) {
if (element instanceof XmlTag && value.equals(((XmlTag) element).getValue().getTrimmedText())) return Boolean.TRUE;
return Boolean.FALSE;
}
};
}
}