本文整理汇总了Java中com.intellij.lang.annotation.Annotation类的典型用法代码示例。如果您正苦于以下问题:Java Annotation类的具体用法?Java Annotation怎么用?Java Annotation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Annotation类属于com.intellij.lang.annotation包,在下文中一共展示了Annotation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitDocTag
import com.intellij.lang.annotation.Annotation; //导入依赖的package包/类
@Override
public void visitDocTag(LuaDocTag e) {
super.visitDocTag(e);
LuaDocSyntaxHighlighter highlighter = new LuaDocSyntaxHighlighter();
PsiElement element = e.getFirstChild();
while (element != null) {
if (element instanceof ASTNode) {
ASTNode astNode = (ASTNode) element;
TextAttributesKey[] keys = highlighter.getTokenHighlights(astNode.getElementType());
for (TextAttributesKey key : keys) {
final Annotation a = myHolder.createInfoAnnotation(element, null);
a.setTextAttributes(key);
}
}
element = element.getNextSibling();
}
}
示例2: visitIdentifier
import com.intellij.lang.annotation.Annotation; //导入依赖的package包/类
public void visitIdentifier(LuaIdentifier id) {
if ((id != null) && id instanceof LuaGlobal) {
addSemanticHighlight(id, LuaHighlightingData.GLOBAL_VAR);
return;
}
if (id instanceof LuaFieldIdentifier) {
addSemanticHighlight(id, LuaHighlightingData.FIELD);
return;
}
if (id instanceof LuaUpvalueIdentifier) {
addSemanticHighlight(id, LuaHighlightingData.UPVAL);
} else if (id instanceof LuaLocalIdentifier) {
PsiReference reference = id.getReference();
if (reference != null) {
PsiElement resolved = reference.resolve();
if (resolved instanceof LuaParameter)
return;
}
final Annotation annotation = myHolder.createInfoAnnotation(id, null);
annotation.setTextAttributes(LuaHighlightingData.LOCAL_VAR);
}
}
示例3: annotate
import com.intellij.lang.annotation.Annotation; //导入依赖的package包/类
@Override
public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) {
if (SmcTypes.ACTION_NAME.equals(element.getNode().getElementType())) {
PsiElement parent = element.getParent();
if (parent == null || !(parent instanceof SmcAction)) {
return;
}
SmcAction action = (SmcAction) parent;
SmcFile containingFile = (SmcFile)action.getContainingFile();
String contextClassName = containingFile.getContextClassQName();
if (!SmcPsiUtil.isMethodInClass(contextClassName, action.getName(), action.getArgumentCount(), element.getProject())) {
Annotation errorAnnotation = holder.createErrorAnnotation(element, getNotResolvedMessage(action.getFullName(), contextClassName));
errorAnnotation.setTextAttributes(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
errorAnnotation.registerFix(new CreateMethodInContextClassFix(action.getName(), action.getArgumentCount()));
} else if (SmcPsiUtil.isMethodInClassNotUnique(contextClassName, action.getName(), action.getArgumentCount(), element.getProject())) {
holder.createWarningAnnotation(element, getAmbiguityMessage(action.getFullName(),contextClassName));
}
}
}
示例4: registerMakeAbstractMethodNotAbstractFix
import com.intellij.lang.annotation.Annotation; //导入依赖的package包/类
private static void registerMakeAbstractMethodNotAbstractFix(Annotation annotation, GrMethod method, boolean makeClassAbstract) {
if (method.getBlock() == null) {
annotation.registerFix(QuickFixFactory.getInstance().createAddMethodBodyFix(method));
}
else {
annotation.registerFix(QuickFixFactory.getInstance().createDeleteMethodBodyFix(method));
}
registerFix(annotation, new GrModifierFix(method, PsiModifier.ABSTRACT, false, false, GrModifierFix.MODIFIER_LIST_OWNER), method);
if (makeClassAbstract) {
final PsiClass containingClass = method.getContainingClass();
if (containingClass != null) {
final PsiModifierList list = containingClass.getModifierList();
if (list != null && !list.hasModifierProperty(PsiModifier.ABSTRACT)) {
registerFix(annotation, new GrModifierFix(containingClass, PsiModifier.ABSTRACT, false, true, GrModifierFix.MODIFIER_LIST_OWNER), containingClass);
}
}
}
}
示例5: checkFieldModifiers
import com.intellij.lang.annotation.Annotation; //导入依赖的package包/类
private static void checkFieldModifiers(AnnotationHolder holder, GrVariableDeclaration fieldDeclaration) {
final GrModifierList modifierList = fieldDeclaration.getModifierList();
final GrField member = (GrField)fieldDeclaration.getVariables()[0];
checkAccessModifiers(holder, modifierList, member);
checkDuplicateModifiers(holder, modifierList, member);
if (modifierList.hasExplicitModifier(PsiModifier.VOLATILE) && modifierList.hasExplicitModifier(PsiModifier.FINAL)) {
final Annotation annotation =
holder.createErrorAnnotation(modifierList, GroovyBundle.message("illegal.combination.of.modifiers.volatile.and.final"));
registerFix(annotation, new GrModifierFix(member, PsiModifier.VOLATILE, true, false, GrModifierFix.MODIFIER_LIST), modifierList);
registerFix(annotation, new GrModifierFix(member, PsiModifier.FINAL, true, false, GrModifierFix.MODIFIER_LIST), modifierList);
}
checkModifierIsNotAllowed(modifierList, PsiModifier.NATIVE, GroovyBundle.message("variable.cannot.be.native"), holder);
checkModifierIsNotAllowed(modifierList, PsiModifier.ABSTRACT, GroovyBundle.message("variable.cannot.be.abstract"), holder);
if (member.getContainingClass() instanceof GrInterfaceDefinition) {
checkModifierIsNotAllowed(modifierList,
PsiModifier.PRIVATE, GroovyBundle.message("interface.members.are.not.allowed.to.be", PsiModifier.PRIVATE), holder);
checkModifierIsNotAllowed(modifierList, PsiModifier.PROTECTED, GroovyBundle.message("interface.members.are.not.allowed.to.be",
PsiModifier.PROTECTED),
holder);
}
}
示例6: registerImplementsMethodsFix
import com.intellij.lang.annotation.Annotation; //导入依赖的package包/类
private static void registerImplementsMethodsFix(@NotNull GrTypeDefinition typeDefinition,
@NotNull PsiMethod abstractMethod,
@NotNull Annotation annotation) {
if (!OverrideImplementExploreUtil.getMethodsToOverrideImplement(typeDefinition, true).isEmpty()) {
annotation.registerFix(QuickFixFactory.getInstance().createImplementMethodsFix(typeDefinition));
}
if (!JavaPsiFacade.getInstance(typeDefinition.getProject()).getResolveHelper().isAccessible(abstractMethod, typeDefinition, null)) {
registerFix(annotation, new GrModifierFix(abstractMethod, PsiModifier.PUBLIC, true, true, GrModifierFix.MODIFIER_LIST_OWNER), abstractMethod);
registerFix(annotation, new GrModifierFix(abstractMethod, PsiModifier.PROTECTED, true, true, GrModifierFix.MODIFIER_LIST_OWNER), abstractMethod);
}
if (!(typeDefinition instanceof GrAnnotationTypeDefinition) && typeDefinition.getModifierList() != null) {
registerFix(annotation, new GrModifierFix(typeDefinition, PsiModifier.ABSTRACT, false, true, GrModifierFix.MODIFIER_LIST_OWNER), typeDefinition);
}
}
示例7: attachColorIcon
import com.intellij.lang.annotation.Annotation; //导入依赖的package包/类
private static void attachColorIcon(final PsiElement element, AnnotationHolder holder, String attributeValueText) {
try {
Color color = null;
if (attributeValueText.startsWith("#")) {
color = ColorUtil.fromHex(attributeValueText.substring(1));
} else {
final String hexCode = ColorMap.getHexCodeForColorName(StringUtil.toLowerCase(attributeValueText));
if (hexCode != null) {
color = ColorUtil.fromHex(hexCode);
}
}
if (color != null) {
final ColorIcon icon = new ColorIcon(8, color);
final Annotation annotation = holder.createInfoAnnotation(element, null);
annotation.setGutterIconRenderer(new ColorIconRenderer(icon, element));
}
}
catch (Exception ignored) {
}
}
示例8: checkPrefixReferences
import com.intellij.lang.annotation.Annotation; //导入依赖的package包/类
private static void checkPrefixReferences(AnnotationHolder holder, QNameElement element, ContextProvider myProvider) {
final PsiReference[] references = element.getReferences();
for (PsiReference reference : references) {
if (reference instanceof PrefixReference) {
final PrefixReference pr = ((PrefixReference)reference);
if (!pr.isSoft() && pr.isUnresolved()) {
final TextRange range = pr.getRangeInElement().shiftRight(pr.getElement().getTextRange().getStartOffset());
final Annotation a = holder.createErrorAnnotation(range, "Unresolved namespace prefix '" + pr.getCanonicalText() + "'");
a.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
final NamespaceContext namespaceContext = myProvider.getNamespaceContext();
final PrefixedName qName = element.getQName();
if (namespaceContext != null && qName != null) {
final IntentionAction[] fixes = namespaceContext.getUnresolvedNamespaceFixes(reference, qName.getLocalName());
for (IntentionAction fix : fixes) {
a.registerFix(fix);
}
}
}
}
}
}
示例9: checkImplementedMethodsOfClass
import com.intellij.lang.annotation.Annotation; //导入依赖的package包/类
private static void checkImplementedMethodsOfClass(AnnotationHolder holder, GrTypeDefinition typeDefinition) {
if (typeDefinition.hasModifierProperty(PsiModifier.ABSTRACT)) return;
if (typeDefinition.isAnnotationType()) return;
if (typeDefinition instanceof GrTypeParameter) return;
PsiMethod abstractMethod = ClassUtil.getAnyAbstractMethod(typeDefinition);
if (abstractMethod == null) return;
String notImplementedMethodName = abstractMethod.getName();
final TextRange range = GrHighlightUtil.getClassHeaderTextRange(typeDefinition);
final Annotation annotation = holder.createErrorAnnotation(range,
GroovyBundle.message("method.is.not.implemented", notImplementedMethodName));
registerImplementsMethodsFix(typeDefinition, abstractMethod, annotation);
}
示例10: visitPyReferenceExpression
import com.intellij.lang.annotation.Annotation; //导入依赖的package包/类
@Override
public void visitPyReferenceExpression(PyReferenceExpression node) {
final String name = node.getName();
if (name == null) return;
final boolean highlightedAsAttribute = highlightAsAttribute(node, name);
if (!highlightedAsAttribute && PyBuiltinCache.isInBuiltins(node)) {
final Annotation ann;
final PsiElement parent = node.getParent();
if (parent instanceof PyDecorator) {
// don't mark the entire decorator, only mark the "@", else we'll conflict with deco annotator
ann = getHolder().createInfoAnnotation(parent.getFirstChild(), null); // first child is there, or we'd not parse as deco
}
else {
ann = getHolder().createInfoAnnotation(node, null);
}
ann.setTextAttributes(PyHighlighter.PY_BUILTIN_NAME);
}
}
示例11: visitXPath2TypeElement
import com.intellij.lang.annotation.Annotation; //导入依赖的package包/类
@Override
public void visitXPath2TypeElement(XPath2TypeElement o) {
final ContextProvider contextProvider = o.getXPathContext();
checkPrefixReferences(myHolder, o, contextProvider);
if (o.getDeclaredType() == XPathType.UNKNOWN) {
final PsiReference[] references = o.getReferences();
for (PsiReference reference : references) {
if (reference instanceof XsltReferenceContributor.SchemaTypeReference ) {
if (!reference.isSoft() && reference.resolve() == null) {
final String message = ((EmptyResolveMessageProvider)reference).getUnresolvedMessagePattern();
final Annotation annotation =
myHolder.createErrorAnnotation(reference.getRangeInElement().shiftRight(o.getTextOffset()), message);
annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
}
}
}
}
super.visitXPath2TypeElement(o);
}
示例12: annotateDocStringStmt
import com.intellij.lang.annotation.Annotation; //导入依赖的package包/类
private void annotateDocStringStmt(final PyStringLiteralExpression stmt) {
if (stmt != null) {
final DocStringFormat format = DocStringUtil.getConfiguredDocStringFormat(stmt);
final String[] tags;
if (format == DocStringFormat.EPYTEXT) {
tags = EpydocString.ALL_TAGS;
}
else if (format == DocStringFormat.REST) {
tags = SphinxDocString.ALL_TAGS;
}
else {
return;
}
int pos = 0;
while (true) {
TextRange textRange = DocStringReferenceProvider.findNextTag(stmt.getText(), pos, tags);
if (textRange == null) break;
Annotation annotation = getHolder().createInfoAnnotation(textRange.shiftRight(stmt.getTextRange().getStartOffset()), null);
annotation.setTextAttributes(PyHighlighter.PY_DOC_COMMENT_TAG);
pos = textRange.getEndOffset();
}
}
}
示例13: checkAccessModifiers
import com.intellij.lang.annotation.Annotation; //导入依赖的package包/类
private static void checkAccessModifiers(AnnotationHolder holder, @NotNull GrModifierList modifierList, PsiMember member) {
boolean hasPrivate = modifierList.hasExplicitModifier(PsiModifier.PRIVATE);
boolean hasPublic = modifierList.hasExplicitModifier(PsiModifier.PUBLIC);
boolean hasProtected = modifierList.hasExplicitModifier(PsiModifier.PROTECTED);
if (hasPrivate && hasPublic || hasPrivate && hasProtected || hasPublic && hasProtected) {
final Annotation annotation = holder.createErrorAnnotation(modifierList, GroovyBundle.message("illegal.combination.of.modifiers"));
if (hasPrivate) {
registerFix(annotation, new GrModifierFix(member, PsiModifier.PRIVATE, false, false, GrModifierFix.MODIFIER_LIST), modifierList);
}
if (hasProtected) {
registerFix(annotation, new GrModifierFix(member, PsiModifier.PROTECTED, false, false, GrModifierFix.MODIFIER_LIST), modifierList);
}
if (hasPublic) {
registerFix(annotation, new GrModifierFix(member, PsiModifier.PUBLIC, false, false, GrModifierFix.MODIFIER_LIST), modifierList);
}
}
else if (member instanceof PsiClass &&
member.getContainingClass() == null &&
GroovyConfigUtils.getInstance().isVersionAtLeast(member, GroovyConfigUtils.GROOVY2_0)) {
checkModifierIsNotAllowed(modifierList, PsiModifier.PRIVATE, GroovyBundle.message("top.level.class.maynot.have.private.modifier"), holder);
checkModifierIsNotAllowed(modifierList, PsiModifier.PROTECTED, GroovyBundle.message("top.level.class.maynot.have.protected.modifier"), holder);
}
}
示例14: visitRegExpNamedGroupRef
import com.intellij.lang.annotation.Annotation; //导入依赖的package包/类
@Override
public void visitRegExpNamedGroupRef(RegExpNamedGroupRef groupRef) {
if (!myLanguageHosts.supportsNamedGroupRefSyntax(groupRef)) {
myHolder.createErrorAnnotation(groupRef, "This named group reference syntax is not supported");
return;
}
if (groupRef.getGroupName() == null) {
return;
}
final RegExpGroup group = groupRef.resolve();
if (group == null) {
final Annotation a = myHolder.createErrorAnnotation(groupRef, "Unresolved named group reference");
if (a != null) {
// IDEA-9381
a.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
}
}
else if (PsiTreeUtil.isAncestor(group, groupRef, true)) {
myHolder.createWarningAnnotation(groupRef, "Group reference is nested into the named group it refers to");
}
}
示例15: createAnnotation
import com.intellij.lang.annotation.Annotation; //导入依赖的package包/类
@Nullable
public static Annotation createAnnotation(final DomElementProblemDescriptor problemDescriptor) {
return createProblemDescriptors(problemDescriptor, new Function<Pair<TextRange, PsiElement>, Annotation>() {
@Override
public Annotation fun(final Pair<TextRange, PsiElement> s) {
String text = problemDescriptor.getDescriptionTemplate();
if (StringUtil.isEmpty(text)) text = null;
final HighlightSeverity severity = problemDescriptor.getHighlightSeverity();
TextRange range = s.first;
if (text == null) range = TextRange.from(range.getStartOffset(), 0);
range = range.shiftRight(s.second.getTextRange().getStartOffset());
final Annotation annotation = createAnnotation(severity, range, text);
if (problemDescriptor instanceof DomElementResolveProblemDescriptor) {
annotation.setTextAttributes(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
}
for(LocalQuickFix fix:problemDescriptor.getFixes()) {
if (fix instanceof IntentionAction) annotation.registerFix((IntentionAction)fix);
}
return annotation;
}
});
}