use of com.intellij.lang.annotation.Annotation in project intellij-plugins by JetBrains.
the class HbBlockMismatchAnnotator method annotate.
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
if (element instanceof HbOpenBlockMustache) {
HbOpenBlockMustache openBlockMustache = (HbOpenBlockMustache) element;
HbMustacheName openBlockMustacheName = openBlockMustache.getBlockMustacheName();
HbCloseBlockMustache closeBlockMustache = openBlockMustache.getPairedElement();
if (closeBlockMustache != null) {
HbMustacheName closeBlockMustacheName = closeBlockMustache.getBlockMustacheName();
if (openBlockMustacheName == null || closeBlockMustacheName == null) {
return;
}
String openBlockName = openBlockMustacheName.getName();
String closeBlockName = closeBlockMustacheName.getName();
if (!openBlockName.equals(closeBlockName)) {
Annotation openBlockAnnotation = holder.createErrorAnnotation(openBlockMustacheName, HbBundle.message("hb.block.mismatch.inspection.open.block", openBlockName, closeBlockName));
openBlockAnnotation.registerFix(new HbBlockMismatchFix(closeBlockName, openBlockName, true));
openBlockAnnotation.registerFix(new HbBlockMismatchFix(openBlockName, closeBlockName, false));
Annotation closeBlockAnnotation = holder.createErrorAnnotation(closeBlockMustacheName, HbBundle.message("hb.block.mismatch.inspection.close.block", openBlockName, closeBlockName));
closeBlockAnnotation.registerFix(new HbBlockMismatchFix(openBlockName, closeBlockName, false));
closeBlockAnnotation.registerFix(new HbBlockMismatchFix(closeBlockName, openBlockName, true));
}
} else {
if (openBlockMustacheName == null) {
return;
}
holder.createErrorAnnotation(openBlockMustacheName, HbBundle.message("hb.block.mismatch.inspection.missing.end.block", openBlockMustache.getName()));
}
}
if (element instanceof HbCloseBlockMustache) {
HbCloseBlockMustache closeBlockMustache = (HbCloseBlockMustache) element;
PsiElement openBlockElement = closeBlockMustache.getPairedElement();
if (openBlockElement == null) {
HbMustacheName closeBlockMustacheName = closeBlockMustache.getBlockMustacheName();
if (closeBlockMustacheName == null) {
return;
}
holder.createErrorAnnotation(closeBlockMustacheName, HbBundle.message("hb.block.mismatch.inspection.missing.start.block", closeBlockMustache.getName()));
}
}
}
use of com.intellij.lang.annotation.Annotation in project intellij-plugins by JetBrains.
the class StrutsFileSetCheckingAnnotator method annotate.
public void annotate(@NotNull final PsiElement psiElement, @NotNull final AnnotationHolder holder) {
if (!(psiElement instanceof XmlFile)) {
return;
}
if (psiElement instanceof JspFile) {
return;
}
final Module module = ModuleUtilCore.findModuleForPsiElement(psiElement);
if (module == null) {
return;
}
// do not run when facet not enabled
if (StrutsFacet.getInstance(module) == null) {
return;
}
final XmlFile xmlFile = (XmlFile) psiElement;
final Project project = psiElement.getProject();
final StrutsManager strutsManager = StrutsManager.getInstance(project);
if (!strutsManager.isStruts2ConfigFile(xmlFile)) {
return;
}
final VirtualFile currentVirtualFile = xmlFile.getVirtualFile();
assert currentVirtualFile != null;
final Set<StrutsFileSet> allConfigFileSets = strutsManager.getAllConfigFileSets(module);
for (final StrutsFileSet configFileSet : allConfigFileSets) {
if (configFileSet.hasFile(currentVirtualFile)) {
return;
}
}
final boolean fileSetAvailable = allConfigFileSets.size() != 0;
final Annotation annotation = holder.createWarningAnnotation(xmlFile, fileSetAvailable ? StrutsBundle.message("annotators.fileset.file.not.registered") : StrutsBundle.message("annotators.fileset.no.file.sets"));
annotation.setFileLevelAnnotation(true);
if (fileSetAvailable) {
final AddToFileSetFix addToFileSetFix = new AddToFileSetFix(xmlFile.getName());
annotation.registerFix(addToFileSetFix);
} else {
annotation.registerFix(new IntentionAction() {
@SuppressWarnings("DialogTitleCapitalization")
@NotNull
public String getText() {
return StrutsBundle.message("annotators.fileset.edit.facet.settings");
}
@NotNull
public String getFamilyName() {
return StrutsBundle.message("intentions.family.name");
}
public boolean isAvailable(@NotNull final Project project, final Editor editor, final PsiFile psiFile) {
return true;
}
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile psiFile) throws IncorrectOperationException {
final StrutsFacet strutsFacet = StrutsFacet.getInstance(module);
assert strutsFacet != null;
ModulesConfigurator.showFacetSettingsDialog(strutsFacet, null);
}
public boolean startInWriteAction() {
return false;
}
});
}
}
Aggregations