本文整理汇总了Java中com.intellij.codeInsight.daemon.impl.HighlightInfo类的典型用法代码示例。如果您正苦于以下问题:Java HighlightInfo类的具体用法?Java HighlightInfo怎么用?Java HighlightInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HighlightInfo类属于com.intellij.codeInsight.daemon.impl包,在下文中一共展示了HighlightInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkClashesWithSuperMethods
import com.intellij.codeInsight.daemon.impl.HighlightInfo; //导入依赖的package包/类
static HighlightInfo checkClashesWithSuperMethods(@NotNull PsiAnnotationMethod psiMethod) {
final PsiIdentifier nameIdentifier = psiMethod.getNameIdentifier();
if (nameIdentifier != null) {
final PsiMethod[] methods = psiMethod.findDeepestSuperMethods();
for (PsiMethod method : methods) {
final PsiClass containingClass = method.getContainingClass();
if (containingClass != null) {
final String qualifiedName = containingClass.getQualifiedName();
if (CommonClassNames.JAVA_LANG_OBJECT.equals(qualifiedName) || CommonClassNames.JAVA_LANG_ANNOTATION_ANNOTATION.equals(qualifiedName)) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(nameIdentifier).descriptionAndTooltip(
"@interface member clashes with '" + JavaHighlightUtil.formatMethod(method) + "' in " + HighlightUtil.formatClass(containingClass)).create();
}
}
}
}
return null;
}
示例2: doHighlighting
import com.intellij.codeInsight.daemon.impl.HighlightInfo; //导入依赖的package包/类
@NotNull
protected Collection<HighlightInfo> doHighlighting(final Boolean externalToolPass) {
final Project project = myTestFixture.getProject();
PsiDocumentManager.getInstance(project).commitAllDocuments();
final Editor editor = myTestFixture.getEditor();
int[] ignore = externalToolPass == null || externalToolPass ? new int[]{
Pass.LINE_MARKERS,
Pass.LOCAL_INSPECTIONS,
Pass.POPUP_HINTS,
Pass.UPDATE_ALL,
Pass.UPDATE_FOLDING,
Pass.UPDATE_OVERRIDEN_MARKERS,
Pass.VISIBLE_LINE_MARKERS,
} : new int[]{Pass.EXTERNAL_TOOLS};
return CodeInsightTestFixtureImpl.instantiateAndRun(myTestFixture.getFile(), editor, ignore, false);
}
示例3: doFix
import com.intellij.codeInsight.daemon.impl.HighlightInfo; //导入依赖的package包/类
/**
* Invokes action in intentionActionDescriptor on file found in path and writes the file to disk.
*
* @param path
* @param fileContent
* @param intentionActionDescriptor
* @return
*/
public static String doFix(String path, @Nullable String fileContent, HighlightInfo.IntentionActionDescriptor intentionActionDescriptor) {
UIUtil.invokeAndWaitIfNeeded((Runnable)() -> {
PsiFile psiFile = EmbeditorUtil.findTargetFile(path);
Project project = psiFile.getProject();
PsiFile fileCopy = fileContent != null
? EmbeditorUtil.createDummyPsiFile(project, fileContent, psiFile)
: EmbeditorUtil.createDummyPsiFile(project, psiFile.getText(), psiFile);
VirtualFile targetVirtualFile = psiFile.getVirtualFile();
Document document = fileCopy.getViewProvider().getDocument();
Editor editor = EditorFactory.getInstance().createEditor(document, project, targetVirtualFile, false);
intentionActionDescriptor.getAction().invoke(project, editor, fileCopy);
FileDocumentManager.getInstance().saveDocument(psiFile.getViewProvider().getDocument());
});
return null;
}
示例4: visitLiteralExpression
import com.intellij.codeInsight.daemon.impl.HighlightInfo; //导入依赖的package包/类
@Override
public void visitLiteralExpression(PsiLiteralExpression expression) {
final HighlightInfo parsingError = HighlightUtil.checkLiteralExpressionParsingError(expression, null, null);
if (parsingError != null) {
throwEvaluateException(parsingError.getDescription());
return;
}
final PsiType type = expression.getType();
if (type == null) {
throwEvaluateException(expression + ": null type");
return;
}
myResult = new LiteralEvaluator(expression.getValue(), type.getCanonicalText());
}
示例5: registerQuickFixAction
import com.intellij.codeInsight.daemon.impl.HighlightInfo; //导入依赖的package包/类
public static void registerQuickFixAction(@NotNull PsiSuperExpression expr, HighlightInfo highlightInfo) {
LOG.assertTrue(expr.getQualifier() == null);
final PsiClass containingClass = PsiTreeUtil.getParentOfType(expr, PsiClass.class);
if (containingClass != null && containingClass.isInterface()) {
final PsiMethodCallExpression callExpression = PsiTreeUtil.getParentOfType(expr, PsiMethodCallExpression.class);
if (callExpression != null) {
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(callExpression.getProject());
for (PsiClass superClass : containingClass.getSupers()) {
if (superClass.isInterface()) {
final PsiMethodCallExpression copy = (PsiMethodCallExpression)callExpression.copy();
final PsiExpression superQualifierCopy = copy.getMethodExpression().getQualifierExpression();
LOG.assertTrue(superQualifierCopy != null);
superQualifierCopy.delete();
if (((PsiMethodCallExpression)elementFactory.createExpressionFromText(copy.getText(), superClass)).resolveMethod() != null) {
QuickFixAction.registerQuickFixAction(highlightInfo, new QualifySuperArgumentFix(expr, superClass));
}
}
}
}
}
}
示例6: checkGenericCannotExtendException
import com.intellij.codeInsight.daemon.impl.HighlightInfo; //导入依赖的package包/类
static HighlightInfo checkGenericCannotExtendException(PsiReferenceList list) {
PsiElement parent = list.getParent();
if (!(parent instanceof PsiClass)) return null;
PsiClass aClass = (PsiClass)parent;
if (!aClass.hasTypeParameters() || aClass.getExtendsList() != list) return null;
PsiJavaCodeReferenceElement[] referenceElements = list.getReferenceElements();
PsiClass throwableClass = null;
for (PsiJavaCodeReferenceElement referenceElement : referenceElements) {
PsiElement resolved = referenceElement.resolve();
if (!(resolved instanceof PsiClass)) continue;
if (throwableClass == null) {
throwableClass = JavaPsiFacade.getInstance(aClass.getProject()).findClass("java.lang.Throwable", aClass.getResolveScope());
}
if (InheritanceUtil.isInheritorOrSelf((PsiClass)resolved, throwableClass, true)) {
String message = JavaErrorMessages.message("generic.extend.exception");
HighlightInfo highlightInfo =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(referenceElement).descriptionAndTooltip(message).create();
PsiClassType classType = JavaPsiFacade.getInstance(aClass.getProject()).getElementFactory().createType((PsiClass)resolved);
QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createExtendsListFix(aClass, classType, false));
return highlightInfo;
}
}
return null;
}
示例7: findIntentionAction
import com.intellij.codeInsight.daemon.impl.HighlightInfo; //导入依赖的package包/类
protected static IntentionAction findIntentionAction(@NotNull Collection<HighlightInfo> infos, @NotNull String intentionActionName, @NotNull Editor editor,
@NotNull PsiFile file) {
List<IntentionAction> actions = LightQuickFixTestCase.getAvailableActions(editor, file);
IntentionAction intentionAction = LightQuickFixTestCase.findActionWithText(actions, intentionActionName);
if (intentionAction == null) {
final List<IntentionAction> availableActions = new ArrayList<IntentionAction>();
for (HighlightInfo info :infos) {
if (info.quickFixActionRanges != null) {
for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> pair : info.quickFixActionRanges) {
IntentionAction action = pair.first.getAction();
if (action.isAvailable(file.getProject(), editor, file)) availableActions.add(action);
}
}
}
intentionAction = LightQuickFixTestCase.findActionWithText(
availableActions,
intentionActionName
);
}
return intentionAction;
}
示例8: checkExpressionRequired
import com.intellij.codeInsight.daemon.impl.HighlightInfo; //导入依赖的package包/类
@Nullable
static HighlightInfo checkExpressionRequired(@NotNull PsiReferenceExpression expression, @NotNull JavaResolveResult resultForIncompleteCode) {
if (expression.getNextSibling() instanceof PsiErrorElement) return null;
PsiElement resolved = resultForIncompleteCode.getElement();
if (resolved == null || resolved instanceof PsiVariable) return null;
PsiElement parent = expression.getParent();
// String.class or String() are both correct
if (parent instanceof PsiReferenceExpression || parent instanceof PsiMethodCallExpression) return null;
String description = JavaErrorMessages.message("expression.expected");
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create();
UnresolvedReferenceQuickFixProvider.registerReferenceFixes(expression, new QuickFixActionRegistrarImpl(info));
return info;
}
示例9: checkAssignmentOperatorApplicable
import com.intellij.codeInsight.daemon.impl.HighlightInfo; //导入依赖的package包/类
@Nullable
static HighlightInfo checkAssignmentOperatorApplicable(@NotNull PsiAssignmentExpression assignment,@NotNull PsiFile containingFile) {
PsiJavaToken operationSign = assignment.getOperationSign();
IElementType eqOpSign = operationSign.getTokenType();
IElementType opSign = TypeConversionUtil.convertEQtoOperation(eqOpSign);
if (opSign == null) return null;
final PsiType lType = assignment.getLExpression().getType();
final PsiExpression rExpression = assignment.getRExpression();
if (rExpression == null) return null;
final PsiType rType = rExpression.getType();
HighlightInfo errorResult = null;
if (!TypeConversionUtil.isBinaryOperatorApplicable(opSign, lType, rType, true) ||
PsiType.getJavaLangObject(containingFile.getManager(), assignment.getResolveScope()).equals(lType)) {
String operatorText = operationSign.getText().substring(0, operationSign.getText().length() - 1);
String message = JavaErrorMessages.message("binary.operator.not.applicable", operatorText,
JavaHighlightUtil.formatType(lType),
JavaHighlightUtil.formatType(rType));
errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(assignment).descriptionAndTooltip(message).create();
}
return errorResult;
}
示例10: registerMethodReturnFixAction
import com.intellij.codeInsight.daemon.impl.HighlightInfo; //导入依赖的package包/类
private static void registerMethodReturnFixAction(HighlightInfo highlightInfo,
MethodCandidateInfo candidate,
PsiCall methodCall) {
if (methodCall.getParent() instanceof PsiReturnStatement) {
final PsiMethod containerMethod = PsiTreeUtil.getParentOfType(methodCall, PsiMethod.class, true, PsiLambdaExpression.class);
if (containerMethod != null) {
final PsiMethod method = candidate.getElement();
final PsiExpression methodCallCopy =
JavaPsiFacade.getElementFactory(method.getProject()).createExpressionFromText(methodCall.getText(), methodCall);
PsiType methodCallTypeByArgs = methodCallCopy.getType();
//ensure type params are not included
methodCallTypeByArgs = JavaPsiFacade.getElementFactory(method.getProject())
.createRawSubstitutor(method).substitute(methodCallTypeByArgs);
QuickFixAction.registerQuickFixAction(highlightInfo,
getFixRange(methodCall),
QUICK_FIX_FACTORY.createMethodReturnFix(containerMethod, methodCallTypeByArgs, true));
}
}
}
示例11: checkLabelAlreadyInUse
import com.intellij.codeInsight.daemon.impl.HighlightInfo; //导入依赖的package包/类
@Nullable
static HighlightInfo checkLabelAlreadyInUse(@NotNull PsiLabeledStatement statement) {
PsiIdentifier identifier = statement.getLabelIdentifier();
String text = identifier.getText();
PsiElement element = statement;
while (element != null) {
if (element instanceof PsiMethod || element instanceof PsiClass) break;
if (element instanceof PsiLabeledStatement && element != statement &&
Comparing.equal(((PsiLabeledStatement)element).getLabelIdentifier().getText(), text)) {
String description = JavaErrorMessages.message("duplicate.label", text);
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(identifier).descriptionAndTooltip(description).create();
}
element = element.getParent();
}
return null;
}
示例12: doApplyInformationToEditor
import com.intellij.codeInsight.daemon.impl.HighlightInfo; //导入依赖的package包/类
@Override
public void doApplyInformationToEditor() {
HighlightInfo info = null;
if (myRange != null) {
TextAttributes attributes = new TextAttributes(null, null,
myEditor.getColorsScheme().getAttributes(CodeInsightColors.WEAK_WARNING_ATTRIBUTES)
.getEffectColor(),
null, Font.PLAIN);
HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(myRange);
builder.textAttributes(attributes);
builder.descriptionAndTooltip(SIGNATURE_SHOULD_BE_POSSIBLY_CHANGED);
info = builder.createUnconditionally();
final ArrayList<IntentionAction> options = new ArrayList<IntentionAction>();
options.add(new DismissNewSignatureIntentionAction());
QuickFixAction.registerQuickFixAction(info, new ChangeSignatureDetectorAction(), options, null);
}
Collection<HighlightInfo> infos = info != null ? Collections.singletonList(info) : Collections.<HighlightInfo>emptyList();
UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, myFile.getTextLength(), infos, getColorsScheme(), getId());
}
示例13: registerFixesForUnusedParameter
import com.intellij.codeInsight.daemon.impl.HighlightInfo; //导入依赖的package包/类
@Override
public void registerFixesForUnusedParameter(@NotNull PsiParameter parameter, @NotNull Object highlightInfo) {
Project myProject = parameter.getProject();
InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getInspectionProfile();
UnusedParametersInspection unusedParametersInspection =
(UnusedParametersInspection)profile.getUnwrappedTool(UnusedSymbolLocalInspectionBase.UNUSED_PARAMETERS_SHORT_NAME, parameter);
LOG.assertTrue(ApplicationManager.getApplication().isUnitTestMode() || unusedParametersInspection != null);
List<IntentionAction> options = new ArrayList<IntentionAction>();
HighlightDisplayKey myUnusedSymbolKey = HighlightDisplayKey.find(UnusedSymbolLocalInspectionBase.SHORT_NAME);
options.addAll(IntentionManager.getInstance().getStandardIntentionOptions(myUnusedSymbolKey, parameter));
if (unusedParametersInspection != null) {
SuppressQuickFix[] batchSuppressActions = unusedParametersInspection.getBatchSuppressActions(parameter);
Collections.addAll(options, SuppressIntentionActionFromFix.convertBatchToSuppressIntentionActions(batchSuppressActions));
}
//need suppress from Unused Parameters but settings from Unused Symbol
QuickFixAction.registerQuickFixAction((HighlightInfo)highlightInfo, new SafeDeleteFix(parameter),
options, HighlightDisplayKey.getDisplayNameByKey(myUnusedSymbolKey));
}
示例14: checkConditionalExpressionBranchTypesMatch
import com.intellij.codeInsight.daemon.impl.HighlightInfo; //导入依赖的package包/类
@Nullable
static HighlightInfo checkConditionalExpressionBranchTypesMatch(@NotNull final PsiExpression expression, PsiType type) {
PsiElement parent = expression.getParent();
if (!(parent instanceof PsiConditionalExpression)) {
return null;
}
PsiConditionalExpression conditionalExpression = (PsiConditionalExpression)parent;
// check else branches only
if (conditionalExpression.getElseExpression() != expression) return null;
final PsiExpression thenExpression = conditionalExpression.getThenExpression();
assert thenExpression != null;
PsiType thenType = thenExpression.getType();
PsiType elseType = type;
if (thenType == null || elseType == null) return null;
if (conditionalExpression.getType() == null) {
// cannot derive type of conditional expression
// elseType will never be castable to thenType, so no quick fix here
return createIncompatibleTypeHighlightInfo(thenType, elseType, expression.getTextRange(), 0);
}
return null;
}
示例15: checkConstructorHandleSuperClassExceptions
import com.intellij.codeInsight.daemon.impl.HighlightInfo; //导入依赖的package包/类
static HighlightInfo checkConstructorHandleSuperClassExceptions(PsiMethod method) {
if (!method.isConstructor()) {
return null;
}
PsiCodeBlock body = method.getBody();
PsiStatement[] statements = body == null ? null : body.getStatements();
if (statements == null) return null;
// if we have unhandled exception inside method body, we could not have been called here,
// so the only problem it can catch here is with super ctr only
Collection<PsiClassType> unhandled = ExceptionUtil.collectUnhandledExceptions(method, method.getContainingClass());
if (unhandled.isEmpty()) return null;
String description = HighlightUtil.getUnhandledExceptionsDescriptor(unhandled);
TextRange textRange = HighlightNamesUtil.getMethodDeclarationTextRange(method);
HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(description).create();
for (PsiClassType exception : unhandled) {
QuickFixAction.registerQuickFixAction(highlightInfo, new LocalQuickFixOnPsiElementAsIntentionAdapter(QUICK_FIX_FACTORY.createMethodThrowsFix(method, exception, true, false)));
}
return highlightInfo;
}