use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.
the class HighlightClassUtil method checkQualifiedNew.
@Nullable
static HighlightInfo checkQualifiedNew(PsiNewExpression expression, PsiType type, PsiClass aClass) {
PsiExpression qualifier = expression.getQualifier();
if (qualifier == null)
return null;
if (type instanceof PsiArrayType) {
String description = JavaErrorMessages.message("invalid.qualified.new");
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create();
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createRemoveNewQualifierFix(expression, null));
return info;
}
HighlightInfo info = null;
if (aClass != null) {
if (aClass.hasModifierProperty(PsiModifier.STATIC)) {
String description = JavaErrorMessages.message("qualified.new.of.static.class");
info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create();
if (!aClass.isEnum()) {
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createModifierListFix(aClass, PsiModifier.STATIC, false, false));
}
} else if (aClass instanceof PsiAnonymousClass) {
final PsiClass baseClass = PsiUtil.resolveClassInType(((PsiAnonymousClass) aClass).getBaseClassType());
if (baseClass != null && baseClass.isInterface()) {
info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip("Anonymous class implements interface; cannot have qualifier for new").create();
}
}
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createRemoveNewQualifierFix(expression, aClass));
}
return info;
}
use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.
the class HighlightClassUtil method checkCannotInheritFromFinal.
@Nullable
static HighlightInfo checkCannotInheritFromFinal(PsiClass superClass, PsiElement elementToHighlight) {
HighlightInfo errorResult = null;
if (superClass.hasModifierProperty(PsiModifier.FINAL) || superClass.isEnum()) {
String message = JavaErrorMessages.message("inheritance.from.final.class", superClass.getQualifiedName());
errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(elementToHighlight).descriptionAndTooltip(message).create();
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createModifierListFix(superClass, PsiModifier.FINAL, false, false));
}
return errorResult;
}
use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.
the class HighlightClassUtil method checkAbstractInstantiation.
/**
* new ref(...) or new ref(..) { ... } where ref is abstract class
*/
@Nullable
static HighlightInfo checkAbstractInstantiation(@NotNull PsiJavaCodeReferenceElement ref) {
PsiElement parent = ref.getParent();
HighlightInfo highlightInfo = null;
if (parent instanceof PsiAnonymousClass && parent.getParent() instanceof PsiNewExpression && !PsiUtilCore.hasErrorElementChild(parent.getParent())) {
PsiAnonymousClass aClass = (PsiAnonymousClass) parent;
highlightInfo = checkClassWithAbstractMethods(aClass, ref.getTextRange());
}
return highlightInfo;
}
use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.
the class VariableAccessFromInnerClassFix method canBeFinal.
private static boolean canBeFinal(@NotNull PsiVariable variable, @NotNull List<PsiReferenceExpression> references) {
// if there is at least one assignment to this variable, it cannot be final
Map<PsiElement, Collection<PsiReferenceExpression>> uninitializedVarProblems = new THashMap<>();
Map<PsiElement, Collection<ControlFlowUtil.VariableInfo>> finalVarProblems = new THashMap<>();
for (PsiReferenceExpression expression : references) {
if (ControlFlowUtil.isVariableAssignedInLoop(expression, variable))
return false;
HighlightInfo highlightInfo = HighlightControlFlowUtil.checkVariableInitializedBeforeUsage(expression, variable, uninitializedVarProblems, variable.getContainingFile());
if (highlightInfo != null)
return false;
highlightInfo = HighlightControlFlowUtil.checkFinalVariableMightAlreadyHaveBeenAssignedTo(variable, expression, finalVarProblems);
if (highlightInfo != null)
return false;
if (variable instanceof PsiParameter && PsiUtil.isAccessedForWriting(expression))
return false;
}
return true;
}
use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.
the class LossyEncodingTest method testDetectWrongEncoding0.
public void testDetectWrongEncoding0() throws Exception {
String threeNotoriousRussianLetters = "ЖОП";
configureByText(FileTypes.PLAIN_TEXT, threeNotoriousRussianLetters);
VirtualFile virtualFile = getFile().getVirtualFile();
final Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
WriteCommandAction.runWriteCommandAction(getProject(), () -> {
document.insertString(0, " ");
document.deleteString(0, 1);
});
assertTrue(FileDocumentManager.getInstance().isDocumentUnsaved(document));
assertEquals(CharsetToolkit.UTF8_CHARSET, virtualFile.getCharset());
Charset WINDOWS_1251 = Charset.forName("windows-1251");
virtualFile.setCharset(WINDOWS_1251);
// save in wrong encoding
FileDocumentManager.getInstance().saveAllDocuments();
assertEquals(WINDOWS_1251, virtualFile.getCharset());
assertEquals(threeNotoriousRussianLetters, new String(virtualFile.contentsToByteArray(), WINDOWS_1251));
virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
doHighlighting();
List<HighlightInfo> infos = DaemonCodeAnalyzerEx.getInstanceEx(getProject()).getFileLevelHighlights(getProject(), getFile());
HighlightInfo info = assertOneElement(infos);
assertEquals("File was loaded in the wrong encoding: 'UTF-8'", info.getDescription());
}
Aggregations