本文整理汇总了Java中com.intellij.codeInsight.daemon.impl.HighlightInfoType类的典型用法代码示例。如果您正苦于以下问题:Java HighlightInfoType类的具体用法?Java HighlightInfoType怎么用?Java HighlightInfoType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HighlightInfoType类属于com.intellij.codeInsight.daemon.impl包,在下文中一共展示了HighlightInfoType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: highlightVariableName
import com.intellij.codeInsight.daemon.impl.HighlightInfoType; //导入依赖的package包/类
@Nullable
static HighlightInfo highlightVariableName(final PsiVariable variable,
final PsiElement elementToHighlight,
@NotNull TextAttributesScheme colorsScheme) {
HighlightInfoType varType = getVariableNameHighlightType(variable);
if (varType != null) {
if (variable instanceof PsiField) {
TextAttributes attributes = mergeWithScopeAttributes(variable, varType, colorsScheme);
HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(varType).range(elementToHighlight.getTextRange());
if (attributes != null) {
builder.textAttributes(attributes);
}
return builder.createUnconditionally();
}
return HighlightInfo.newHighlightInfo(varType).range(elementToHighlight).create();
}
return null;
}
示例2: checkMethodMustHaveBody
import com.intellij.codeInsight.daemon.impl.HighlightInfoType; //导入依赖的package包/类
static HighlightInfo checkMethodMustHaveBody(PsiMethod method, PsiClass aClass) {
HighlightInfo errorResult = null;
if (method.getBody() == null
&& !method.hasModifierProperty(PsiModifier.ABSTRACT)
&& !method.hasModifierProperty(PsiModifier.NATIVE)
&& aClass != null
&& !aClass.isInterface()
&& !PsiUtilCore.hasErrorElementChild(method)) {
int start = method.getModifierList().getTextRange().getStartOffset();
int end = method.getTextRange().getEndOffset();
String description = JavaErrorMessages.message("missing.method.body");
errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(start, end).descriptionAndTooltip(description).create();
if (HighlightUtil.getIncompatibleModifier(PsiModifier.ABSTRACT, method.getModifierList()) == null) {
QuickFixAction.registerQuickFixAction(errorResult,
QUICK_FIX_FACTORY.createModifierListFix(method, PsiModifier.ABSTRACT, true, false));
}
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createAddMethodBodyFix(method));
}
return errorResult;
}
示例3: checkAbstractMethodInConcreteClass
import com.intellij.codeInsight.daemon.impl.HighlightInfoType; //导入依赖的package包/类
static HighlightInfo checkAbstractMethodInConcreteClass(PsiMethod method, PsiElement elementToHighlight) {
HighlightInfo errorResult = null;
PsiClass aClass = method.getContainingClass();
if (method.hasModifierProperty(PsiModifier.ABSTRACT)
&& aClass != null
&& !aClass.hasModifierProperty(PsiModifier.ABSTRACT)
&& !aClass.isEnum()
&& !PsiUtilCore.hasErrorElementChild(method)) {
String description = JavaErrorMessages.message("abstract.method.in.non.abstract.class");
errorResult =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(elementToHighlight).descriptionAndTooltip(description).create();
if (method.getBody() != null) {
QuickFixAction.registerQuickFixAction(errorResult,
QUICK_FIX_FACTORY.createModifierListFix(method, PsiModifier.ABSTRACT, false, false));
}
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createAddMethodBodyFix(method));
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createModifierListFix(aClass, PsiModifier.ABSTRACT, true, false));
}
return errorResult;
}
示例4: checkConstructorName
import com.intellij.codeInsight.daemon.impl.HighlightInfoType; //导入依赖的package包/类
static HighlightInfo checkConstructorName(PsiMethod method) {
String methodName = method.getName();
PsiClass aClass = method.getContainingClass();
HighlightInfo errorResult = null;
if (aClass != null) {
String className = aClass instanceof PsiAnonymousClass ? null : aClass.getName();
if (className == null || !Comparing.strEqual(methodName, className)) {
PsiElement element = method.getNameIdentifier();
String description = JavaErrorMessages.message("missing.return.type");
errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(element).descriptionAndTooltip(description).create();
if (className != null) {
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createRenameElementFix(method, className));
}
}
}
return errorResult;
}
示例5: checkConstructorCallMustBeFirstStatement
import com.intellij.codeInsight.daemon.impl.HighlightInfoType; //导入依赖的package包/类
@Nullable
static HighlightInfo checkConstructorCallMustBeFirstStatement(@NotNull PsiMethodCallExpression methodCall) {
if (!RefactoringChangeUtil.isSuperOrThisMethodCall(methodCall)) return null;
PsiElement codeBlock = methodCall.getParent().getParent();
if (codeBlock instanceof PsiCodeBlock
&& codeBlock.getParent() instanceof PsiMethod
&& ((PsiMethod)codeBlock.getParent()).isConstructor()) {
PsiElement prevSibling = methodCall.getParent().getPrevSibling();
while (true) {
if (prevSibling == null) return null;
if (prevSibling instanceof PsiStatement) break;
prevSibling = prevSibling.getPrevSibling();
}
}
PsiReferenceExpression expression = methodCall.getMethodExpression();
String message = JavaErrorMessages.message("constructor.call.must.be.first.statement", expression.getText() + "()");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(methodCall).descriptionAndTooltip(message).create();
}
示例6: checkConstructorHandleSuperClassExceptions
import com.intellij.codeInsight.daemon.impl.HighlightInfoType; //导入依赖的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;
}
示例7: bindMessageToAstNode
import com.intellij.codeInsight.daemon.impl.HighlightInfoType; //导入依赖的package包/类
private void bindMessageToAstNode(final PsiElement childByRole,
final HighlightInfoType warning,
final int offset,
int length,
@NotNull String localizedMessage,
IntentionAction... quickFixActions) {
if(childByRole != null) {
final TextRange textRange = childByRole.getTextRange();
if (length == -1) length = textRange.getLength();
final int startOffset = textRange.getStartOffset() + offset;
HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(warning).range(childByRole, startOffset, startOffset + length).descriptionAndTooltip(localizedMessage).create();
if (highlightInfo == null) {
highlightInfo = HighlightInfo.newHighlightInfo(warning).range(new TextRange(startOffset, startOffset + length)).textAttributes(NONEMPTY_TEXT_ATTRIBUTES).descriptionAndTooltip(localizedMessage).create();
}
for (final IntentionAction quickFixAction : quickFixActions) {
if (quickFixAction == null) continue;
QuickFixAction.registerQuickFixAction(highlightInfo, textRange, quickFixAction);
}
addToResults(highlightInfo);
}
}
示例8: checkInstantiationOfAbstractClass
import com.intellij.codeInsight.daemon.impl.HighlightInfoType; //导入依赖的package包/类
@Nullable
static HighlightInfo checkInstantiationOfAbstractClass(PsiClass aClass, @NotNull PsiElement highlightElement) {
HighlightInfo errorResult = null;
if (aClass != null && aClass.hasModifierProperty(PsiModifier.ABSTRACT)
&& (!(highlightElement instanceof PsiNewExpression) || !(((PsiNewExpression)highlightElement).getType() instanceof PsiArrayType))) {
String baseClassName = aClass.getName();
String message = JavaErrorMessages.message("abstract.cannot.be.instantiated", baseClassName);
errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(highlightElement).descriptionAndTooltip(message).create();
final PsiMethod anyAbstractMethod = ClassUtil.getAnyAbstractMethod(aClass);
if (!aClass.isInterface() && anyAbstractMethod == null) {
// suggest to make not abstract only if possible
QuickFixAction.registerQuickFixAction(errorResult,
QUICK_FIX_FACTORY.createModifierListFix(aClass, PsiModifier.ABSTRACT, false, false));
}
if (anyAbstractMethod != null && highlightElement instanceof PsiNewExpression && ((PsiNewExpression)highlightElement).getClassReference() != null) {
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createImplementAbstractClassMethodsFix(highlightElement));
}
}
return errorResult;
}
示例9: checkImplementsAllowed
import com.intellij.codeInsight.daemon.impl.HighlightInfoType; //导入依赖的package包/类
@Nullable
static HighlightInfo checkImplementsAllowed(PsiReferenceList list) {
if (list.getParent() instanceof PsiClass) {
PsiClass aClass = (PsiClass)list.getParent();
if (aClass.isInterface()) {
boolean isImplements = list.equals(aClass.getImplementsList());
if (isImplements) {
String description = JavaErrorMessages.message("implements.after.interface");
HighlightInfo result =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(list).descriptionAndTooltip(description).create();
final PsiClassType[] referencedTypes = list.getReferencedTypes();
if (referencedTypes.length > 0) {
QuickFixAction.registerQuickFixAction(result, QUICK_FIX_FACTORY.createChangeExtendsToImplementsFix(aClass, referencedTypes[0]));
}
return result;
}
}
}
return null;
}
示例10: checkClassExtendsOnlyOneClass
import com.intellij.codeInsight.daemon.impl.HighlightInfoType; //导入依赖的package包/类
@Nullable
static HighlightInfo checkClassExtendsOnlyOneClass(PsiReferenceList list) {
PsiClassType[] referencedTypes = list.getReferencedTypes();
PsiElement parent = list.getParent();
if (!(parent instanceof PsiClass)) return null;
PsiClass aClass = (PsiClass)parent;
if (!aClass.isInterface()
&& referencedTypes.length > 1
&& aClass.getExtendsList() == list) {
String description = JavaErrorMessages.message("class.cannot.extend.multiple.classes");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(list).descriptionAndTooltip(description).create();
}
return null;
}
示例11: checkInferredTypeArguments
import com.intellij.codeInsight.daemon.impl.HighlightInfoType; //导入依赖的package包/类
@Nullable
static HighlightInfo checkInferredTypeArguments(PsiTypeParameter[] typeParameters,
PsiElement call,
PsiSubstitutor substitutor) {
final Pair<PsiTypeParameter, PsiType> inferredTypeArgument = GenericsUtil.findTypeParameterWithBoundError(typeParameters, substitutor, call, false);
if (inferredTypeArgument != null) {
final PsiType extendsType = inferredTypeArgument.second;
final PsiTypeParameter typeParameter = inferredTypeArgument.first;
PsiClass boundClass = extendsType instanceof PsiClassType ? ((PsiClassType)extendsType).resolve() : null;
@NonNls String messageKey = boundClass == null || typeParameter.isInterface() == boundClass.isInterface()
? "generics.inferred.type.for.type.parameter.is.not.within.its.bound.extend"
: "generics.inferred.type.for.type.parameter.is.not.within.its.bound.implement";
String description = JavaErrorMessages.message(
messageKey,
HighlightUtil.formatClass(typeParameter),
JavaHighlightUtil.formatType(extendsType),
JavaHighlightUtil.formatType(substitutor.substitute(typeParameter))
);
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(call).descriptionAndTooltip(description).create();
}
return null;
}
示例12: checkFunctionalInterface
import com.intellij.codeInsight.daemon.impl.HighlightInfoType; //导入依赖的package包/类
@Nullable
static HighlightInfo checkFunctionalInterface(@NotNull PsiAnnotation annotation, @NotNull LanguageLevel languageLevel) {
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8) && Comparing.strEqual(annotation.getQualifiedName(), CommonClassNames.JAVA_LANG_FUNCTIONAL_INTERFACE)) {
final PsiAnnotationOwner owner = annotation.getOwner();
if (owner instanceof PsiModifierList) {
final PsiElement parent = ((PsiModifierList)owner).getParent();
if (parent instanceof PsiClass) {
final String errorMessage = LambdaHighlightingUtil.checkInterfaceFunctional((PsiClass)parent, ((PsiClass)parent).getName() + " is not a functional interface");
if (errorMessage != null) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(annotation).descriptionAndTooltip(errorMessage).create();
}
}
}
}
return null;
}
示例13: checkDefaultMethodOverrideEquivalentToObjectNonPrivate
import com.intellij.codeInsight.daemon.impl.HighlightInfoType; //导入依赖的package包/类
static HighlightInfo checkDefaultMethodOverrideEquivalentToObjectNonPrivate(@NotNull LanguageLevel languageLevel,
@NotNull PsiClass aClass,
@NotNull PsiMethod method,
@NotNull PsiElement methodIdentifier) {
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8) && aClass.isInterface() && method.hasModifierProperty(PsiModifier.DEFAULT)) {
HierarchicalMethodSignature sig = method.getHierarchicalMethodSignature();
for (HierarchicalMethodSignature methodSignature : sig.getSuperSignatures()) {
final PsiMethod objectMethod = methodSignature.getMethod();
final PsiClass containingClass = objectMethod.getContainingClass();
if (containingClass != null && CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName()) && objectMethod.hasModifierProperty(PsiModifier.PUBLIC)) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.descriptionAndTooltip("Default method '" + sig.getName() + "' overrides a member of 'java.lang.Object'")
.range(methodIdentifier)
.create();
}
}
}
return null;
}
示例14: addInspectionSeverityAttributes
import com.intellij.codeInsight.daemon.impl.HighlightInfoType; //导入依赖的package包/类
private static void addInspectionSeverityAttributes(List<AttributesDescriptor> descriptors) {
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.unknown.symbol"), CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.deprecated.symbol"), CodeInsightColors.DEPRECATED_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.unused.symbol"), CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.error"), CodeInsightColors.ERRORS_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.warning"), CodeInsightColors.WARNINGS_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.weak.warning"), CodeInsightColors.WEAK_WARNING_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.server.problems"), CodeInsightColors.GENERIC_SERVER_ERROR_OR_WARNING));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.server.duplicate"), CodeInsightColors.DUPLICATE_FROM_SERVER));
for (SeveritiesProvider provider : Extensions.getExtensions(SeveritiesProvider.EP_NAME)) {
for (HighlightInfoType highlightInfoType : provider.getSeveritiesHighlightInfoTypes()) {
final TextAttributesKey attributesKey = highlightInfoType.getAttributesKey();
descriptors.add(new AttributesDescriptor(toDisplayName(attributesKey), attributesKey));
}
}
}
示例15: doApplyInformationToEditor
import com.intellij.codeInsight.daemon.impl.HighlightInfoType; //导入依赖的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());
}