com.intellij.codeInsight.daemon.impl.HighlightInfoType Java Examples

The following examples show how to use com.intellij.codeInsight.daemon.impl.HighlightInfoType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChangeSignaturePassFactory.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void doApplyInformationToEditor() {
  HighlightInfo info = null;
  final InplaceChangeSignature currentRefactoring = InplaceChangeSignature.getCurrentRefactoring(myEditor);
  if (currentRefactoring != null) {
    final ChangeInfo changeInfo = currentRefactoring.getStableChange();
    final PsiElement element = changeInfo.getMethod();
    int offset = myEditor.getCaretModel().getOffset();
    if (element == null || !element.isValid()) return;
    final TextRange elementTextRange = element.getTextRange();
    if (elementTextRange == null || !elementTextRange.contains(offset)) return;
    final LanguageChangeSignatureDetector<ChangeInfo> detector = LanguageChangeSignatureDetectors.INSTANCE.forLanguage(changeInfo.getLanguage());
    TextRange range = detector.getHighlightingRange(changeInfo);
    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(range);
    builder.textAttributes(attributes);
    builder.descriptionAndTooltip(SIGNATURE_SHOULD_BE_POSSIBLY_CHANGED);
    info = builder.createUnconditionally();
    QuickFixAction.registerQuickFixAction(info, new ApplyChangeSignatureAction(currentRefactoring.getInitialName()));
  }
  Collection<HighlightInfo> infos = info != null ? Collections.singletonList(info) : Collections.emptyList();
  UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, myFile.getTextLength(), infos, getColorsScheme(), getId());
}
 
Example #2
Source File: SharpLabHighlightVisitor.java    From consulo-unity3d with Apache License 2.0 6 votes vote down vote up
@Override
public void visitPropertyType(ShaderPropertyTypeElement type)
{
	super.visitPropertyType(type);

	PsiElement element = type.getTargetElement();

	ShaderLabPropertyType shaderLabPropertyType = ShaderLabPropertyType.find(element.getText());
	if(shaderLabPropertyType == null)
	{
		myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.WRONG_REF).range(element).descriptionAndTooltip("Wrong type").create());
	}
	else
	{
		myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(element).textAttributes(DefaultLanguageHighlighterColors.TYPE_ALIAS_NAME).create());
	}
}
 
Example #3
Source File: ColorSettingsUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
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));
    }
  }
}
 
Example #4
Source File: SharpLabHighlightVisitor.java    From consulo-unity3d with Apache License 2.0 6 votes vote down vote up
@Override
public void visitElement(PsiElement element)
{
	super.visitElement(element);

	ASTNode node = element.getNode();

	if(node != null)
	{
		if(node.getElementType() == ShaderLabKeyTokens.VALUE_KEYWORD)
		{
			myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(node).textAttributes(DefaultLanguageHighlighterColors.MACRO_KEYWORD).create());
		}
		else if(node.getElementType() == ShaderLabKeyTokens.START_KEYWORD)
		{
			myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(node).textAttributes(DefaultLanguageHighlighterColors.KEYWORD).create());
		}
	}
}
 
Example #5
Source File: GenericParameterHighlightUtil.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
private static void registerInOutProblem(DotNetGenericParameter parameter,
		HighlightInfoHolder highlightInfoHolder,
		PsiElement modifierElement,
		CSharpModifier modifier)
{
	CSharpModifier revertModifier = modifier == CSharpModifier.IN ? CSharpModifier.OUT : CSharpModifier.IN;
	HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR);
	builder.descriptionAndTooltip(CSharpErrorBundle.message("conflicting.0.modifier.with.1.modifier", modifier.getPresentableText(),
			revertModifier.getPresentableText()));
	builder.range(modifierElement);

	HighlightInfo info = builder.create();
	if(info != null)
	{
		QuickFixAction.registerQuickFixAction(info, modifierElement.getTextRange(), new RemoveModifierFix(modifier, parameter));
		highlightInfoHolder.add(info);
	}
}
 
Example #6
Source File: CSharpHighlightVisitor.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public void visitElement(PsiElement element)
{
	ProgressIndicatorProvider.checkCanceled();

	IElementType elementType = PsiUtilCore.getElementType(element);
	if(CSharpSoftTokens.ALL.contains(elementType))
	{
		myHighlightInfoHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(element).textAttributes(CSharpHighlightKey.SOFT_KEYWORD).create());
	}
	else if(elementType == CSharpTokens.NON_ACTIVE_SYMBOL || elementType == CSharpPreprocessorElements.DISABLED_PREPROCESSOR_DIRECTIVE)
	{
		if(myDocument == null)
		{
			return;
		}
		int lineNumber = myDocument.getLineNumber(element.getTextOffset());
		if(!myProcessedLines.contains(lineNumber))
		{
			myProcessedLines.add(lineNumber);

			TextRange textRange = new TextRange(myDocument.getLineStartOffset(lineNumber), myDocument.getLineEndOffset(lineNumber));
			myHighlightInfoHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(textRange).textAttributes(CSharpHighlightKey.DISABLED_BLOCK).create());
		}
	}
}
 
Example #7
Source File: CSharpHighlightVisitor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public void visitLinqExpression(CSharpLinqExpressionImpl expression)
{
	super.visitLinqExpression(expression);

	myHighlightInfoHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(expression).textAttributes(EditorColors.INJECTED_LANGUAGE_FRAGMENT).create());
}
 
Example #8
Source File: InspectionProfileManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void registerProvidedSeverities() {
  for (SeveritiesProvider provider : Extensions.getExtensions(SeveritiesProvider.EP_NAME)) {
    for (HighlightInfoType t : provider.getSeveritiesHighlightInfoTypes()) {
      HighlightSeverity highlightSeverity = t.getSeverity(null);
      SeverityRegistrar.registerStandard(t, highlightSeverity);
      TextAttributesKey attributesKey = t.getAttributesKey();
      Icon icon = t instanceof HighlightInfoType.Iconable ? ((HighlightInfoType.Iconable)t).getIcon() : null;
      HighlightDisplayLevel.registerSeverity(highlightSeverity, attributesKey, icon);
    }
  }
}
 
Example #9
Source File: SyntaxInfoBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void findNextSuitableRange() {
  myNextAttributes = null;
  while (myIterator.hasNext()) {
    RangeHighlighterEx highlighter = myIterator.next();
    if (highlighter == null || !highlighter.isValid() || !isInterestedInLayer(highlighter.getLayer())) {
      continue;
    }
    // LINES_IN_RANGE highlighters are not supported currently
    myNextStart = Math.max(highlighter.getStartOffset(), myStartOffset);
    myNextEnd = Math.min(highlighter.getEndOffset(), myEndOffset);
    if (myNextStart >= myEndOffset) {
      break;
    }
    if (myNextStart < myCurrentEnd) {
      continue; // overlapping ranges withing document markup model are not supported currently
    }
    TextAttributes attributes = null;
    HighlightInfo info = HighlightInfo.fromRangeHighlighter(highlighter);
    if (info != null) {
      TextAttributesKey key = info.forcedTextAttributesKey;
      if (key == null) {
        HighlightInfoType type = info.type;
        key = type.getAttributesKey();
      }
      if (key != null) {
        attributes = myColorsScheme.getAttributes(key);
      }
    }
    if (attributes == null) {
      continue;
    }
    Color foreground = attributes.getForegroundColor();
    Color background = attributes.getBackgroundColor();
    if ((foreground == null || myDefaultForeground.equals(foreground)) && (background == null || myDefaultBackground.equals(background)) && attributes.getFontType() == Font.PLAIN) {
      continue;
    }
    myNextAttributes = attributes;
    break;
  }
}
 
Example #10
Source File: GeneralColorsPage.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static String getCustomSeveritiesDemoText() {
  final StringBuilder buff = new StringBuilder();

  for (SeveritiesProvider provider : Extensions.getExtensions(SeveritiesProvider.EP_NAME)) {
    for (HighlightInfoType highlightInfoType : provider.getSeveritiesHighlightInfoTypes()) {
      final String tag = getHighlightDescTagName(highlightInfoType);
      buff.append("  <").append(tag).append(">");
      buff.append(tag.toLowerCase());
      buff.append("</").append(tag).append(">").append("\n");
    }
  }

  return buff.toString();
}
 
Example #11
Source File: DefaultInspectionToolPresentation.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected static String getTextAttributeKey(@Nonnull Project project,
                                            @Nonnull HighlightSeverity severity,
                                            @Nonnull ProblemHighlightType highlightType) {
  if (highlightType == ProblemHighlightType.LIKE_DEPRECATED) {
    return HighlightInfoType.DEPRECATED.getAttributesKey().getExternalName();
  }
  if (highlightType == ProblemHighlightType.LIKE_UNKNOWN_SYMBOL && severity == HighlightSeverity.ERROR) {
    return HighlightInfoType.WRONG_REF.getAttributesKey().getExternalName();
  }
  if (highlightType == ProblemHighlightType.LIKE_UNUSED_SYMBOL) {
    return HighlightInfoType.UNUSED_SYMBOL.getAttributesKey().getExternalName();
  }
  SeverityRegistrar registrar = InspectionProjectProfileManagerImpl.getInstanceImpl(project).getSeverityRegistrar();
  return registrar.getHighlightInfoTypeBySeverity(severity).getAttributesKey().getExternalName();
}
 
Example #12
Source File: ProblemDescriptorUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static HighlightInfoType highlightTypeFromDescriptor(@Nonnull ProblemDescriptor problemDescriptor,
                                                            @Nonnull HighlightSeverity severity,
                                                            @Nonnull SeverityRegistrar severityRegistrar) {
  final ProblemHighlightType highlightType = problemDescriptor.getHighlightType();
  switch (highlightType) {
    case GENERIC_ERROR_OR_WARNING:
      return severityRegistrar.getHighlightInfoTypeBySeverity(severity);
    case LIKE_DEPRECATED:
      return new HighlightInfoType.HighlightInfoTypeImpl(severity, HighlightInfoType.DEPRECATED.getAttributesKey());
    case LIKE_UNKNOWN_SYMBOL:
      if (severity == HighlightSeverity.ERROR) {
        return new HighlightInfoType.HighlightInfoTypeImpl(severity, HighlightInfoType.WRONG_REF.getAttributesKey());
      }
      if (severity == HighlightSeverity.WARNING) {
        return new HighlightInfoType.HighlightInfoTypeImpl(severity, CodeInsightColors.WEAK_WARNING_ATTRIBUTES);
      }
      return severityRegistrar.getHighlightInfoTypeBySeverity(severity);
    case LIKE_UNUSED_SYMBOL:
      return new HighlightInfoType.HighlightInfoTypeImpl(severity, HighlightInfoType.UNUSED_SYMBOL.getAttributesKey());
    case INFO:
      return HighlightInfoType.INFO;
    case WEAK_WARNING:
      return HighlightInfoType.WEAK_WARNING;
    case ERROR:
      return HighlightInfoType.WRONG_REF;
    case GENERIC_ERROR:
      return HighlightInfoType.ERROR;
    case INFORMATION:
      final TextAttributesKey attributes = ((ProblemDescriptorBase)problemDescriptor).getEnforcedTextAttributes();
      if (attributes != null) {
        return new HighlightInfoType.HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, attributes);
      }
      return HighlightInfoType.INFORMATION;
  }
  throw new RuntimeException("Cannot map " + highlightType);
}
 
Example #13
Source File: ExpectedHighlightingDataTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static HighlightInfo eolError(int start, int end, @Nonnull String description) {
  HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR);
  builder.range(start, end);
  builder.description(description);
  builder.endOfLine();
  return builder.createUnconditionally();
}
 
Example #14
Source File: ExpectedHighlightingData.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ExpectedHighlightingData(@Nonnull final Document document, PsiFile file) {
  myDocument = document;
  myFile = file;
  myText = document.getText();
  highlightingTypes = new LinkedHashMap<String, ExpectedHighlightingSet>();
  new WriteCommandAction.Simple(file == null ? null : file.getProject()) {
    public void run() {
      boolean checkWarnings = false;
      boolean checkWeakWarnings = false;
      boolean checkInfos = false;

      highlightingTypes.put(ERROR_MARKER, new ExpectedHighlightingSet(HighlightSeverity.ERROR, false, true));
      highlightingTypes.put(WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WARNING, false, checkWarnings));
      highlightingTypes.put(WEAK_WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WEAK_WARNING, false, checkWeakWarnings));
      highlightingTypes.put("inject", new ExpectedHighlightingSet(HighlightInfoType.INJECTED_FRAGMENT_SEVERITY, false, checkInfos));
      highlightingTypes.put(INFO_MARKER, new ExpectedHighlightingSet(HighlightSeverity.INFORMATION, false, checkInfos));
      highlightingTypes.put("symbolName", new ExpectedHighlightingSet(HighlightInfoType.SYMBOL_TYPE_SEVERITY, false, false));
      for (SeveritiesProvider provider : SeveritiesProvider.EP_NAME.getExtensionList()) {
        for (HighlightInfoType type : provider.getSeveritiesHighlightInfoTypes()) {
          final HighlightSeverity severity = type.getSeverity(null);
          highlightingTypes.put(severity.getName(), new ExpectedHighlightingSet(severity, false, true));
        }
      }
      highlightingTypes.put(END_LINE_HIGHLIGHT_MARKER, new ExpectedHighlightingSet(HighlightSeverity.ERROR, true, true));
      highlightingTypes.put(END_LINE_WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WARNING, true, checkWarnings));
      initAdditionalHighlightingTypes();
    }
  }.execute().throwException();
}
 
Example #15
Source File: UnusedEntrySeveritiesProvider.java    From idea-gitignore with MIT License 5 votes vote down vote up
/**
 * Defines the style of matched entry.
 *
 * @return style definition
 */
@NotNull
@Override
public List<HighlightInfoType> getSeveritiesHighlightInfoTypes() {
    final List<HighlightInfoType> result = new ArrayList<>();

    result.add(new HighlightInfoType.HighlightInfoTypeImpl(
            UNUSED_ENTRY,
            TextAttributesKey.createTextAttributesKey(
                    IgnoreBundle.message("codeInspection.unusedEntry"),
                    IgnoreHighlighterColors.UNUSED
            )
    ));
    return result;
}
 
Example #16
Source File: UnresolvedResourceStatsCollector.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public Set<HighlightInfoType> supportedHighlightInfoTypes() {
  if (!enabled.getValue()) {
    return ImmutableSet.of();
  }
  return SUPPORTED_HIGHLIGHT_TYPES;
}
 
Example #17
Source File: CompilerCheck.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public HighlightInfo create(boolean insideDoc)
{
	HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(insideDoc ? HighlightInfoType.WEAK_WARNING : getHighlightInfoType());
	builder = builder.descriptionAndTooltip(getText());
	builder = builder.range(getTextRange());

	TextAttributesKey textAttributesKey = getTextAttributesKey();
	if(textAttributesKey != null)
	{
		builder = builder.textAttributes(textAttributesKey);
	}
	return builder.create();
}
 
Example #18
Source File: HighlightInfo.java    From intellij with Apache License 2.0 5 votes vote down vote up
public static Type convertHighlightInfoType(HighlightInfoType type) {
  if (HighlightInfoType.WRONG_REF.equals(type)) {
    return Type.WRONG_REF;
  } else if (HighlightInfoType.UNUSED_SYMBOL.equals(type)) {
    return Type.UNUSED_SYMBOL;
  } else if (HighlightInfoType.DEPRECATED.equals(type)) {
    return Type.DEPRECATED;
  } else if (HighlightInfoType.MARKED_FOR_REMOVAL.equals(type)) {
    return Type.MARKED_FOR_REMOVAL;
  }
  throw new IllegalArgumentException("Unhandled HighlightInfoType: " + type);
}
 
Example #19
Source File: BlazeHighlightStatsCollector.java    From intellij with Apache License 2.0 5 votes vote down vote up
/** Returns a map from {@link HighlightInfoType} to the collectors that support them. */
static Multimap<HighlightInfoType, BlazeHighlightStatsCollector>
    getCollectorsByHighlightInfoTypes(Set<BlazeHighlightStatsCollector> collectors) {
  Multimap<HighlightInfoType, BlazeHighlightStatsCollector> map = HashMultimap.create();
  for (BlazeHighlightStatsCollector collector : collectors) {
    for (HighlightInfoType highlightInfoType : collector.supportedHighlightInfoTypes()) {
      map.put(highlightInfoType, collector);
    }
  }
  return map;
}
 
Example #20
Source File: SharpLabHighlightVisitor.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@Override
public void visitProperty(ShaderPropertyElement p)
{
	super.visitProperty(p);

	PsiElement nameIdentifier = p.getNameIdentifier();
	if(nameIdentifier != null)
	{
		myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(nameIdentifier).textAttributes(DefaultLanguageHighlighterColors.INSTANCE_FIELD).create());
	}
}
 
Example #21
Source File: SharpLabHighlightVisitor.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredReadAction
public void visitReference(ShaderReference reference)
{
	if(!reference.isSoft())
	{
		PsiElement resolve = reference.resolve();
		if(resolve == null)
		{
			myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.WRONG_REF).range(reference.getReferenceElement()).descriptionAndTooltip("'" + reference.getReferenceName() + "' is not " +
					"resolved").create());
		}
		else
		{
			ShaderReference.ResolveKind kind = reference.kind();
			TextAttributesKey key = null;
			switch(kind)
			{
				case ATTRIBUTE:
					key = DefaultLanguageHighlighterColors.METADATA;
					break;
				case PROPERTY:
					key = DefaultLanguageHighlighterColors.INSTANCE_FIELD;
					break;
				default:
					return;
			}
			myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(reference.getReferenceElement()).textAttributes(key).create());
		}
	}
}
 
Example #22
Source File: CSharpHighlightVisitor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredReadAction
public void visit(@Nonnull PsiElement element)
{
	if(element instanceof CSharpPreprocessorReferenceExpressionImpl)
	{
		if(((CSharpPreprocessorReferenceExpressionImpl) element).resolve() != null)
		{
			myHighlightInfoHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(element).textAttributes(TemplateColors.TEMPLATE_VARIABLE_ATTRIBUTES).create());
		}
		else
		{
			myHighlightInfoHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(element).textAttributes(DefaultLanguageHighlighterColors.LINE_COMMENT).create());
		}
	}
	else if(element instanceof CSharpPreprocessorDefine)
	{
		if(((CSharpPreprocessorDefine) element).isUnDef())
		{
			PsiElement varElement = ((CSharpPreprocessorDefine) element).getVarElement();
			if(varElement != null)
			{
				myHighlightInfoHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(varElement).textAttributes(DefaultLanguageHighlighterColors.LINE_COMMENT).create());
			}
		}
		else
		{
			CSharpPreprocessorVariable variable = ((CSharpPreprocessorDefine) element).getVariable();
			if(variable != null)
			{
				myHighlightInfoHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(variable.getNameIdentifier()).textAttributes(TemplateColors
						.TEMPLATE_VARIABLE_ATTRIBUTES).create());
			}
		}
	}
	else
	{
		element.accept(this);
	}
}
 
Example #23
Source File: CSharpHighlightUtil.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
@RequiredReadAction
public static HighlightInfo highlightNamed(@Nonnull HighlightInfoHolder holder, @Nullable PsiElement element, @Nullable PsiElement target, @Nullable PsiElement owner)
{
	if(target == null || element == null)
	{
		return null;
	}

	IElementType elementType = target.getNode().getElementType();
	if(CSharpTokenSets.KEYWORDS.contains(elementType))  // don't highlight keywords
	{
		return null;
	}

	if(isMethodRef(owner, element))
	{
		HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(target).textAttributes(CSharpHighlightKey.METHOD_REF).create();
		holder.add(highlightInfo);
	}

	TextAttributesKey defaultTextAttributeKey = getDefaultTextAttributeKey(element, target);
	if(defaultTextAttributeKey == null)
	{
		return null;
	}

	HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(target).textAttributes(defaultTextAttributeKey).create();
	holder.add(info);
	if(!(target instanceof CSharpIdentifier) && DotNetAttributeUtil.hasAttribute(element, DotNetTypes.System.ObsoleteAttribute))
	{
		holder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(target).textAttributes(CodeInsightColors.DEPRECATED_ATTRIBUTES).create());
	}

	return info;
}
 
Example #24
Source File: ConstructorHighlightUtil.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
@RequiredReadAction
public static HighlightInfo checkConstructorDeclaration(@Nonnull CSharpConstructorDeclaration declaration)
{
	PsiElement nameIdentifier = declaration.getNameIdentifier();

	if(nameIdentifier == null)
	{
		return null;
	}

	PsiElement parent = declaration.getParent();
	if(!(parent instanceof CSharpTypeDeclaration))
	{
		return null;
	}

	String expectedTypeName = ((CSharpTypeDeclaration) parent).getName();
	if(expectedTypeName == null)
	{
		return null;
	}
	if(!Comparing.equal(expectedTypeName, CSharpPsiUtilImpl.getNameWithoutAt(nameIdentifier.getText())))
	{
		HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR);
		builder = builder.descriptionAndTooltip("Expected method name");
		builder = builder.range(nameIdentifier);
		HighlightInfo highlightInfo = builder.create();
		QuickFixAction.registerQuickFixAction(highlightInfo, new RenameQuickFix(expectedTypeName, declaration));
		return highlightInfo;
	}
	return null;
}
 
Example #25
Source File: ExpectedHighlightingData.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void checkInfos() {
  highlightingTypes.put(INFO_MARKER, new ExpectedHighlightingSet(HighlightSeverity.INFORMATION, false, true));
  highlightingTypes.put("inject", new ExpectedHighlightingSet(HighlightInfoType.INJECTED_FRAGMENT_SEVERITY, false, true));
}
 
Example #26
Source File: ExpectedHighlightingData.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void checkSymbolNames() {
  highlightingTypes.put("symbolName", new ExpectedHighlightingSet(HighlightInfoType.SYMBOL_TYPE_SEVERITY, false, true));
}
 
Example #27
Source File: ExpectedHighlightingDataTest.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static HighlightInfo error(int start, int end, @Nonnull String description) {
  HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR);
  builder.range(start, end);
  builder.descriptionAndTooltip(description);
  return builder.createUnconditionally();
}
 
Example #28
Source File: ExpectedHighlightingDataTest.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static HighlightInfo warning(int start, int end, @Nonnull String description) {
  HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(HighlightInfoType.WARNING);
  builder.range(start, end);
  builder.descriptionAndTooltip(description);
  return builder.createUnconditionally();
}
 
Example #29
Source File: CS1644.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public CompilerCheckBuilder checkImpl(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull PsiElement element)
{
	for(Feature feature : myFeatures)
	{
		if(languageVersion.ordinal() < feature.myLanguageVersion.ordinal())
		{
			PsiElement fun = feature.myFunc.fun(element);
			if(fun == null)
			{
				continue;
			}

			CompilerCheckBuilder result = newBuilder(fun, feature.myName, languageVersion.getPresentableName());

			result.addQuickFix(new SetLanguageVersionFix(feature.myLanguageVersion));

			IElementType elementType = fun.getNode().getElementType();
			if(!myAllKeywords.contains(elementType))
			{
				boolean foundKeywordAndItSolo = false;
				ASTNode[] children = fun.getNode().getChildren(null);
				for(ASTNode child : children)
				{
					if(CSharpTokenSets.COMMENTS.contains(child.getElementType()) || child.getElementType() == CSharpTokenSets.WHITE_SPACE)
					{
						continue;
					}

					if(myAllKeywords.contains(child.getElementType()))
					{
						foundKeywordAndItSolo = true;
					}
					else if(foundKeywordAndItSolo)  // if we found keyword but parent have other elements - we cant highlight as error
					{
						return result;
					}
				}

				if(foundKeywordAndItSolo)
				{
					result.setHighlightInfoType(HighlightInfoType.WRONG_REF);
				}
			}
			else
			{
				result.setHighlightInfoType(HighlightInfoType.WRONG_REF);
			}
			return result;
		}
	}
	return null;
}
 
Example #30
Source File: CompilerCheck.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
public CompilerCheckBuilder setHighlightInfoType(HighlightInfoType highlightInfoType)
{
	myHighlightInfoType = highlightInfoType;
	return this;
}