Java Code Examples for com.intellij.lang.annotation.AnnotationHolder

The following are top voted examples for showing how to use com.intellij.lang.annotation.AnnotationHolder. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: intellij-spring-assistant   File: PropertyNotInModelAnnotator.java   Source Code and License 6 votes vote down vote up
@Override
public void annotate(@NotNull final PsiElement element,
    @NotNull final AnnotationHolder annotationHolder) {
  // TODO: Fix this
  //    final ModelProvider modelProvider = ModelProvider.INSTANCE;
  //    final ResourceTypeKey resourceKey = KubernetesYamlPsiUtil.findResourceKey(element);
  //    if (resourceKey != null && element instanceof YAMLKeyValue) {
  //      final YAMLKeyValue keyValue = (YAMLKeyValue) element;
  //      final Model model = KubernetesYamlPsiUtil.modelForKey(modelProvider, resourceKey, keyValue);
  //      if (keyValue.getValue() instanceof YAMLMapping && model != null) {
  //        final YAMLMapping mapping = (YAMLMapping) keyValue.getValue();
  //        final Set<String> expectedProperties = model.getProperties().keySet();
  //        //noinspection ConstantConditions
  //        mapping.getKeyValues().stream()
  //            .filter(k -> !expectedProperties.contains(k.getKeyText().trim())).forEach(
  //            k -> annotationHolder.createWarningAnnotation(k.getKey(),
  //                "SpringConfigurationMetadataProperty '" + k.getKeyText()
  //                    + "' is not expected here.").registerFix(new DeletePropertyIntentionAction()));
  //      }
  //    }
}
 
Example 2
Project: intellij-spring-assistant   File: DuplicateKeyAnnotator.java   Source Code and License 6 votes vote down vote up
@Override
public void annotate(@NotNull final PsiElement element,
    @NotNull final AnnotationHolder annotationHolder) {
  if (element instanceof YAMLMapping) {
    // TODO: Fix
    //      final YAMLMapping mapping = (YAMLMapping) element;
    //      final Collection<YAMLKeyValue> keyValues = mapping.getKeyValues();
    //      final Set<String> existingKeys = new HashSet<>(keyValues.size());
    //      for (final YAMLKeyValue keyValue : keyValues) {
    //        if (keyValue.getKey() != null && !existingKeys.add(keyValue.getKeyText().trim())) {
    //          annotationHolder.createErrorAnnotation(keyValue.getKey(),
    //              "Duplicated PROPERTY '" + keyValue.getKeyText() + "'")
    //              .registerFix(new DeletePropertyIntentionAction());
    //        }
    //      }
  }
}
 
Example 3
Project: reasonml-idea-plugin   File: BsErrorAnnotator.java   Source Code and License 6 votes vote down vote up
@Override
public void apply(@NotNull PsiFile file, Collection<BsbErrorAnnotation> annotationResult, @NotNull AnnotationHolder holder) {
    LineNumbering lineNumbering = new LineNumbering(file.getText());
    for (BsbErrorAnnotation annotation : annotationResult) {
        PsiElement elementAtOffset = null;
        /*
        if (annotation.m_element != null) {
            elementAtOffset = annotation.m_element;
        } else {
            int startOffset = lineNumbering.positionToOffset(annotation.m_line, annotation.m_startOffset);
            elementAtOffset = findElementAtOffset(file, startOffset);
        }
        */

        if (elementAtOffset != null) {
            holder.createErrorAnnotation(elementAtOffset, annotation.m_message);
            BucklescriptProjectComponent.getInstance(file.getProject()).associatePsiElement(file.getVirtualFile(), elementAtOffset);
        } else {
            int startOffset = lineNumbering.positionToOffset(annotation.m_line, annotation.m_startOffset);
            int endOffset = lineNumbering.positionToOffset(annotation.m_line, annotation.m_endOffset);
            holder.createErrorAnnotation(new TextRangeInterval(startOffset, endOffset), annotation.m_message);
        }
    }
}
 
Example 4
Project: idea-php-typo3-plugin   File: RouteAnnotator.java   Source Code and License 6 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {

    if (!(psiElement instanceof StringLiteralExpression)) {
        return;
    }

    StringLiteralExpression literalExpression = (StringLiteralExpression) psiElement;
    String value = literalExpression.getContents();

    if (value.isEmpty()) {
        return;
    }

    for (PsiReference psiReference : literalExpression.getReferences()) {
        if (psiReference instanceof RouteReference) {
            annotateRoute(psiElement, annotationHolder, value);
        }
    }
}
 
Example 5
Project: idea-php-typo3-plugin   File: IconAnnotator.java   Source Code and License 6 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {

    if (!(psiElement instanceof StringLiteralExpression)) {
        return;
    }

    StringLiteralExpression literalExpression = (StringLiteralExpression) psiElement;
    String value = literalExpression.getContents();

    if (value.isEmpty()) {
        return;
    }

    PsiElement methodReference = PsiTreeUtil.getParentOfType(psiElement, MethodReference.class);
    if (PhpElementsUtil.isMethodWithFirstStringOrFieldReference(methodReference, "getIcon")) {
        annotateIconUsage(psiElement, annotationHolder, value);
    }
}
 
Example 6
Project: bamboo-soy   File: CaseAndDefaultAnnotator.java   Source Code and License 6 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
  if (psiElement instanceof ChoiceStatementElement) {
    boolean foundDefault = false;
    for (PsiElement child : psiElement.getChildren()) {
      if (!(child instanceof SoyChoiceClause)) {
        continue;
      }

      SoyChoiceClause clause = (SoyChoiceClause) child;

      if (foundDefault) {
        if (!clause.isDefault()) {
          annotationHolder.createErrorAnnotation(
              child, "{case} clauses are not allowed after {default}.");
        } else if (clause.isDefault()) {
          annotationHolder.createErrorAnnotation(
              child, "There can only be one {default} clause.");
        }
      } else if (clause.isDefault()) {
        foundDefault = true;
      }
    }
  }
}
 
Example 7
Project: intellij-postfix-templates   File: CptAnnotator.java   Source Code and License 6 votes vote down vote up
@Override
public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) {
	if (element instanceof LeafPsiElement) {
		final LeafPsiElement psiElement = (LeafPsiElement) element;

		if (psiElement.getElementType().equals(CptTypes.CLASS_NAME)) {
			final String className = element.getText();

			SupportedLanguages.getCptLang(element).ifPresent(lang -> {
				final CptLangAnnotator annotator = lang.getAnnotator();

				if (!annotator.isMatchingType(psiElement, className)) {
					holder.createErrorAnnotation(element.getTextRange(), "Class not found");
				}
			});
		}
	}
}
 
Example 8
Project: manifold-ij   File: ExtensionClassAnnotator.java   Source Code and License 6 votes vote down vote up
@Override
public void annotate( PsiElement element, AnnotationHolder holder )
{
  if( DumbService.getInstance( element.getProject() ).isDumb() )
  {
    // skip processing during index rebuild
    return;
  }

  PsiClass psiExtensionClass = findExtensionClass( element );

  if( psiExtensionClass != null )
  {
    // The enclosing class a @Extension class, verify usage of @This etc.

    verifyPackage( element, holder );
    verifyExtensionInterfaces( element, holder );
    verifyExtensionMethods( element, holder );
  }
  else
  {
    // The enclosing class is *not* an extension class; usage of @This or @Extension on methods are errors

    errrantThisOrExtension( element, holder );
  }
}
 
Example 9
Project: manifold-ij   File: ExtensionClassAnnotator.java   Source Code and License 6 votes vote down vote up
private void verifyExtensionInterfaces( PsiElement element, AnnotationHolder holder )
{
  if( element instanceof PsiJavaCodeReferenceElementImpl &&
      ((PsiJavaCodeReferenceElementImpl)element).getTreeParent() instanceof ReferenceListElement &&
      ((PsiJavaCodeReferenceElementImpl)element).getTreeParent().getText().startsWith( PsiKeyword.IMPLEMENTS ) )
  {
    final PsiElement resolve = element.getReference().resolve();
    if( resolve instanceof PsiExtensibleClass )
    {
      PsiExtensibleClass iface = (PsiExtensibleClass)resolve;
      if( !isStructuralInterface( iface ) )
      {
        TextRange range = new TextRange( element.getTextRange().getStartOffset(),
                                         element.getTextRange().getEndOffset() );
        holder.createErrorAnnotation( range, ExtIssueMsg.MSG_ONLY_STRUCTURAL_INTERFACE_ALLOWED_HERE.get( iface.getName() ) );
      }
    }
  }
}
 
Example 10
Project: manifold-ij   File: ExtensionClassAnnotator.java   Source Code and License 6 votes vote down vote up
private void errrantThisOrExtension( PsiElement element, AnnotationHolder holder )
{
  if( element instanceof PsiModifierList )
  {
    PsiModifierList mods = (PsiModifierList)element;
    PsiAnnotation annotation;
    if( (annotation = mods.findAnnotation( Extension.class.getName() )) != null ||
        (annotation = mods.findAnnotation( This.class.getName() )) != null)
    {
      TextRange range = new TextRange( annotation.getTextRange().getStartOffset(),
                                       annotation.getTextRange().getEndOffset() );
      //noinspection ConstantConditions
      holder.createErrorAnnotation( range, ExtIssueMsg.MSG_NOT_IN_EXTENSION_CLASS.get( ClassUtil.extractClassName( annotation.getQualifiedName() ) ) );
    }
  }
}
 
Example 11
Project: weex-language-support   File: WeexAnnotator.java   Source Code and License 6 votes vote down vote up
private void checkStructure(PsiElement document, @NotNull AnnotationHolder annotationHolder) {
    PsiElement[] children = document.getChildren();
    List<String> acceptedTag = Arrays.asList("template","element","script", "style");
    for (PsiElement element : children) {
        if (element instanceof HtmlTag) {
            if (!acceptedTag.contains(((HtmlTag) element).getName().toLowerCase())) {
                annotationHolder.createErrorAnnotation(element, "Invalid tag '"
                        + ((HtmlTag) element).getName() + "', only the [template, element, script, style] tags are allowed here.");
            }
            checkAttributes((XmlTag) element, annotationHolder);
        } else {
            if (!(element instanceof PsiWhiteSpace)
                    && !(element instanceof XmlProlog)
                    && !(element instanceof XmlText)
                    && !(element instanceof XmlComment)) {
                String s = element.getText();
                if (s.length() > 20) {
                    s = s.substring(0, 20);
                }
                annotationHolder.createErrorAnnotation(element, "Invalid content '" + s +
                        "', only the [template, script, style] tags are allowed here.");
            }
        }
    }
}
 
Example 12
Project: intellij-ce-playground   File: GroovyAnnotator.java   Source Code and License 6 votes vote down vote up
static void checkMethodReturnType(PsiMethod method, PsiElement toHighlight, AnnotationHolder holder) {
  final HierarchicalMethodSignature signature = method.getHierarchicalMethodSignature();
  final List<HierarchicalMethodSignature> superSignatures = signature.getSuperSignatures();

  PsiType returnType = signature.getSubstitutor().substitute(method.getReturnType());

  for (HierarchicalMethodSignature superMethodSignature : superSignatures) {
    PsiMethod superMethod = superMethodSignature.getMethod();
    PsiType declaredReturnType = superMethod.getReturnType();
    PsiType superReturnType = superMethodSignature.getSubstitutor().substitute(declaredReturnType);
    if (superReturnType == PsiType.VOID && method instanceof GrMethod && ((GrMethod)method).getReturnTypeElementGroovy() == null) return;
    if (superMethodSignature.isRaw()) superReturnType = TypeConversionUtil.erasure(declaredReturnType);
    if (returnType == null || superReturnType == null || method == superMethod) continue;
    PsiClass superClass = superMethod.getContainingClass();
    if (superClass == null) continue;
    String highlightInfo = checkSuperMethodSignature(superMethod, superMethodSignature, superReturnType, method, signature, returnType);
    if (highlightInfo != null) {
      holder.createErrorAnnotation(toHighlight, highlightInfo);
      return;
    }
  }
}
 
Example 13
Project: intellij-ce-playground   File: MavenDomGutterAnnotator.java   Source Code and License 6 votes vote down vote up
private static void annotateMavenDomPlugin(@NotNull MavenDomPlugin plugin, @NotNull AnnotationHolder holder) {
  XmlTag xmlTag = plugin.getArtifactId().getXmlTag();
  if (xmlTag == null) return;

  DomElement plugins = plugin.getParent();
  if (plugins == null) return;

  DomElement parent = plugins.getParent();
  if (parent instanceof MavenDomPluginManagement) {
    annotateMavenDomPluginInManagement(plugin, holder);
    return;
  }

  MavenDomPlugin managingPlugin = MavenDomProjectProcessorUtils.searchManagingPlugin(plugin);

  if (managingPlugin != null) {
    NavigationGutterIconBuilder<MavenDomPlugin> iconBuilder =
      NavigationGutterIconBuilder.create(AllIcons.General.OverridingMethod, PluginConverter.INSTANCE);

    iconBuilder.
      setTargets(Collections.singletonList(managingPlugin)).
      setTooltipText(MavenDomBundle.message("overriden.plugin.title")).
      install(holder, xmlTag);
  }
}
 
Example 14
Project: intellij-ce-playground   File: XPathAnnotator.java   Source Code and License 6 votes vote down vote up
private static void checkKindTestArguments(AnnotationHolder holder,
                                           XPathNodeTypeTest test,
                                           boolean wildcardAllowed,
                                           int min,
                                           int max) {
  final XPathExpression[] arguments = test.getArgumentList();
  if (arguments.length >= min) {
    for (XPathExpression arg : arguments) {
      final PrefixedName argument = findQName(arg);
      if (argument == null) {
        holder.createErrorAnnotation(arg, "QName expected");
      } else {
        if (!wildcardAllowed && ("*".equals(argument.getPrefix()) || "*".equals(argument.getLocalName()))) {
          holder.createErrorAnnotation(arg, "QName expected");
        }
      }
    }
  } else {
    holder.createErrorAnnotation(test, "Missing argument for node kind test");
  }

  markExceedingArguments(holder, arguments, max);
}
 
Example 15
Project: cs-intellij-plugin   File: ExecutableAnnotator.java   Source Code and License 6 votes vote down vote up
private void createErrorAnnotations(PsiElement element, PsiFile file, AnnotationHolder holder, List<RuntimeException> annotationResult) {
    Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
    if (document == null) {
        return;
    }
    PsiElement psiElementWithError = element;
    for (RuntimeException exception : annotationResult) {
        if (exception instanceof LocatedRuntimeException) {
            LocatedRuntimeException locatedException = (LocatedRuntimeException) exception;
            PsiElement childAtLine = file.findElementAt(document.getLineStartOffset(locatedException.getLineNumber() - 1));
            if (childAtLine != null) {
                psiElementWithError = childAtLine;
            }
        }
        holder.createErrorAnnotation(psiElementWithError, exception.getMessage());
    }
}
 
Example 16
Project: intellij-ce-playground   File: FieldAnnotationChecker.java   Source Code and License 6 votes vote down vote up
@Override
public boolean checkApplicability(@NotNull AnnotationHolder holder, @NotNull GrAnnotation annotation) {
  final String qname = annotation.getQualifiedName();
  if (!GroovyCommonClassNames.GROOVY_TRANSFORM_FIELD.equals(qname)) return false;

  checkScriptField(holder, annotation);

  PsiElement annoParent = annotation.getParent();
  PsiElement ownerToUse = annoParent instanceof PsiModifierList ? annoParent.getParent() : annoParent;
  if (!(ownerToUse instanceof GrVariableDeclaration) ||
      !PsiUtil.isLocalVariable(((GrVariableDeclaration)ownerToUse).getVariables()[0])) {
    return false;
  }

  if (!GrAnnotationImpl.isAnnotationApplicableTo(annotation, PsiAnnotation.TargetType.LOCAL_VARIABLE)) {
    GrCodeReferenceElement ref = annotation.getClassReference();
    String target = JavaErrorMessages.message("annotation.target.LOCAL_VARIABLE");
    String description = JavaErrorMessages.message("annotation.not.applicable", ref.getText(), target);
    holder.createErrorAnnotation(ref, description);
  }

  return true;
}
 
Example 17
Project: intellij-ce-playground   File: MavenDomGutterAnnotator.java   Source Code and License 6 votes vote down vote up
private static void annotateMavenDomPluginInManagement(@NotNull MavenDomPlugin plugin, @NotNull AnnotationHolder holder) {
  XmlTag xmlTag = plugin.getArtifactId().getXmlTag();
  if (xmlTag == null) return;

  Collection<MavenDomPlugin> children = MavenDomProjectProcessorUtils.searchManagedPluginUsages(plugin);

  if (children.size() > 0) {
    NavigationGutterIconBuilder<MavenDomPlugin> iconBuilder =
      NavigationGutterIconBuilder.create(AllIcons.General.OverridenMethod, PluginConverter.INSTANCE);

    iconBuilder.
      setTargets(children).
      setPopupTitle(MavenDomBundle.message("navigate.parent.plugin.title")).
      setCellRenderer(MyListCellRenderer.INSTANCE).
      setTooltipText(MavenDomBundle.message("overriding.plugin.title")).
      install(holder, xmlTag);
  }
}
 
Example 18
Project: intellij-ce-playground   File: MavenDomGutterAnnotator.java   Source Code and License 6 votes vote down vote up
private static void annotateDependencyUsages(@NotNull MavenDomDependency dependency, AnnotationHolder holder) {
  final XmlTag tag = dependency.getXmlTag();
  if (tag == null) return;

  final Set<MavenDomDependency> children = MavenDomProjectProcessorUtils.searchDependencyUsages(dependency);
  if (children.size() > 0) {
    final NavigationGutterIconBuilder<MavenDomDependency> iconBuilder =
      NavigationGutterIconBuilder.create(AllIcons.General.OverridenMethod, DependencyConverter.INSTANCE);
    iconBuilder.
      setTargets(children).
      setPopupTitle(MavenDomBundle.message("navigate.parent.dependency.title")).
      setCellRenderer(MyListCellRenderer.INSTANCE).
      setTooltipText(MavenDomBundle.message("overriding.dependency.title")).
      install(holder, dependency.getXmlTag());
  }
}
 
Example 19
Project: arma-intellij-plugin   File: SQFControlStructureCommandAnnotator.java   Source Code and License 6 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
	if (!(element instanceof SQFCommand)) {
		return;
	}
	SQFCommand command = (SQFCommand) element;
	switch (command.getCommandName().toLowerCase()) {
		case "if": //fall
		case "then": //fall
		case "else": //fall
		case "for": //fall
		case "foreach": //fall
		case "switch": //fall
		case "case": //fall
		case "default": //fall
		case "while"://fall
		case "do": {
			Annotation annotation = holder.createInfoAnnotation(command, "");
			annotation.setTextAttributes(SQFSyntaxHighlighter.CONTROL_STRUCTURE_COMMAND);
			break;
		}
	}
}
 
Example 20
Project: intellij-kubernetes   File: MissingRequiredPropertiesAnnotator.java   Source Code and License 6 votes vote down vote up
@Override
public void annotate(@NotNull final PsiElement element, @NotNull final AnnotationHolder annotationHolder) {
    if (!KubernetesYamlPsiUtil.isKubernetesFile(element)) {
        return;
    }
    final ModelProvider modelProvider = ModelProvider.INSTANCE;
    final ResourceTypeKey resourceKey = KubernetesYamlPsiUtil.findResourceKey(element);
    if (resourceKey != null && element instanceof YAMLKeyValue) {
        final YAMLKeyValue keyValue = (YAMLKeyValue) element;
        final Model model = KubernetesYamlPsiUtil.modelForKey(modelProvider, resourceKey, keyValue);
        if (model != null && keyValue.getKey() != null) {
            if (keyValue.getValue() instanceof YAMLMapping) {
                final YAMLMapping mapping = (YAMLMapping) keyValue.getValue();
                addErrors(annotationHolder, model, keyValue.getKey(), mapping);
            } else if (keyValue.getValue() instanceof YAMLSequence) {
                final YAMLSequence sequence = (YAMLSequence) keyValue.getValue();
                for (final YAMLSequenceItem item : sequence.getItems()) {
                    if (item.getValue() instanceof YAMLMapping) {
                        addErrors(annotationHolder, model, item.getFirstChild(), (YAMLMapping) item.getValue());
                    }
                }
            }
        }
    }
}
 
Example 21
Project: intellij-ce-playground   File: CustomAnnotationChecker.java   Source Code and License 6 votes vote down vote up
private static void checkAnnotationValue(@NotNull PsiClass annotation,
                                         @NotNull PsiElement identifierToHighlight,
                                         @NotNull String name,
                                         @NotNull Set<String> usedAttrs,
                                         @Nullable GrAnnotationMemberValue value,
                                         @NotNull AnnotationHolder holder) {
  if (usedAttrs.contains(name)) {
    holder.createErrorAnnotation(identifierToHighlight, GroovyBundle.message("duplicate.attribute"));
  }

  usedAttrs.add(name);

  final PsiMethod[] methods = annotation.findMethodsByName(name, false);
  if (methods.length == 0) {
    holder.createErrorAnnotation(identifierToHighlight,
                                 GroovyBundle.message("at.interface.0.does.not.contain.attribute", annotation.getQualifiedName(), name));
  }
  else {
    final PsiMethod method = methods[0];
    final PsiType ltype = method.getReturnType();
    if (ltype != null && value != null) {
      checkAnnotationValueByType(holder, value, ltype, true);
    }
  }
}
 
Example 22
Project: intellij-kubernetes   File: DuplicateKeyAnnotator.java   Source Code and License 6 votes vote down vote up
@Override
public void annotate(@NotNull final PsiElement element, @NotNull final AnnotationHolder annotationHolder) {
    if (!KubernetesYamlPsiUtil.isKubernetesFile(element)) {
        return;
    }
    if (element instanceof YAMLMapping) {
        final YAMLMapping mapping = (YAMLMapping) element;
        final Collection<YAMLKeyValue> keyValues = mapping.getKeyValues();
        final Set<String> existingKeys = new HashSet<>(keyValues.size());
        for (final YAMLKeyValue keyValue : keyValues) {
            if (keyValue.getKey() != null && !existingKeys.add(keyValue.getKeyText().trim())) {
                annotationHolder.createErrorAnnotation(keyValue.getKey(), "Duplicated property '" + keyValue.getKeyText() + "'").registerFix(new DeletePropertyIntentionAction());
            }
        }
    }
}
 
Example 23
Project: intellij-ce-playground   File: GroovyAnnotator.java   Source Code and License 6 votes vote down vote up
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);
  }
}
 
Example 24
Project: intellij-ce-playground   File: GroovyPostHighlightingPass.java   Source Code and License 6 votes vote down vote up
@Override
public void doApplyInformationToEditor() {
  if (myUnusedDeclarations == null || myUnusedImports == null) {
    return;
  }

  AnnotationHolder annotationHolder = new AnnotationHolderImpl(new AnnotationSession(myFile));
  List<HighlightInfo> infos = new ArrayList<HighlightInfo>(myUnusedDeclarations);
  for (GrImportStatement unusedImport : myUnusedImports) {
    Annotation annotation = annotationHolder.createWarningAnnotation(calculateRangeToUse(unusedImport), GroovyInspectionBundle.message("unused.import"));
    annotation.setHighlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL);
    annotation.registerFix(GroovyQuickFixFactory.getInstance().createOptimizeImportsFix(false));
    infos.add(HighlightInfo.fromAnnotation(annotation));
  }

  UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, myFile.getTextLength(), infos, getColorsScheme(), getId());

  if (myUnusedImports != null && !myUnusedImports.isEmpty()) {
    IntentionAction fix = GroovyQuickFixFactory.getInstance().createOptimizeImportsFix(true);
    if (fix.isAvailable(myProject, myEditor, myFile) && myFile.isWritable()) {
      fix.invoke(myProject, myEditor, myFile);
    }
  }
}
 
Example 25
Project: intellij-spring-assistant   File: DataTypeCheckerAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(@NotNull final PsiElement element,
    @NotNull final AnnotationHolder annotationHolder) {
  // TODO: Complete this
  //    final ModelProvider modelProvider = ModelProvider.INSTANCE;
  //    final ResourceTypeKey resourceKey = KubernetesYamlPsiUtil.findResourceKey(element);
  //    if (resourceKey != null && element instanceof YAMLKeyValue) {
  //      final YAMLKeyValue keyValue = (YAMLKeyValue) element;
  //      final Property property =
  //          KubernetesYamlPsiUtil.propertyForKey(modelProvider, resourceKey, keyValue);
  //      final YAMLValue value = keyValue.getValue();
  //      if (property != null && property.getType() != null && value != null) {
  //        switch (property.getType()) {
  //          case ARRAY:
  //            if (!(value instanceof YAMLSequence)) {
  //              annotationHolder.createErrorAnnotation(value,
  //                  "The content of " + keyValue.getKeyText() + " should be an ARRAY.");
  //            }
  //            break;
  //          case OBJECT:
  //            if (!(value instanceof YAMLMapping)) {
  //              annotationHolder.createErrorAnnotation(value,
  //                  "The content of " + keyValue.getKeyText() + " should be an OBJECT.");
  //            }
  //            break;
  //        }
  //      }
  //    }
}
 
Example 26
Project: TS-IJ   File: TSClassNameAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    PsiElement classElement = null;
    if (element instanceof  TSDatablockDecl) {
        TSDatablockDecl db = (TSDatablockDecl) element;

        //Find the first id node, this is kinda wonky since we have to account for whitespace nodes
        //datablock ClassName(...)
        ASTNode node = db.getNode();
        if (node == null) {
            return;
        }
        node = node.findChildByType(TSTypes.ID);
        if (node == null) {
            return;
        }
        classElement = node.getPsi();
    } else if (element instanceof TSObjectExpr) {
        TSObjectExpr obj = (TSObjectExpr) element;

        //Class name should be the second thing in the element:
        // new ClassName(...)
        classElement = PsiTreeUtil.getChildOfType(obj, TSClassNameExpr.class);

        if (classElement == null) {
            return;
        }
        classElement = classElement.getFirstChild();
    }
    if (classElement == null) {
        return;
    }

    //Only annotate if it's an id, can't really tell if it's an expr
    if (classElement.getNode().getElementType().equals(TSTypes.ID)) {
        createSuccessAnnotation(classElement, holder, TSSyntaxHighlighter.CLASSNAME);
    }
}
 
Example 27
Project: TS-IJ   File: TSObjectAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    if (element instanceof TSLiteralExpr) {
        boolean valid = false;
        TSLiteralReference ref = (TSLiteralReference)element.getReference();
        if (ref != null) {
            valid = ref.multiResolve(false).length > 0;
        }

        if (valid) {
            createSuccessAnnotation(element, holder, TSSyntaxHighlighter.OBJECT_NAME);
        }
    }
}
 
Example 28
Project: AppleScript-IDEA   File: AppleScriptColorAnnotator.java   Source Code and License 5 votes vote down vote up
private static void createInfoAnnotation(final @NotNull AnnotationHolder holder,
                                         final @Nullable PsiElement element,
                                         final @Nullable TextAttributesKey attributeKey) {
  if (element != null && attributeKey != null) {
    holder.createInfoAnnotation(element, null).setTextAttributes(attributeKey);
  }
}
 
Example 29
Project: reasonml-idea-plugin   File: MerlinErrorAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void apply(@NotNull PsiFile file, List<MerlinError> annotationResult, @NotNull AnnotationHolder holder) {
    LineNumbering lineNumbering = new LineNumbering(file.getText());
    for (MerlinError error : annotationResult) {
        if (error.start != null) {
            int startOffset = lineNumbering.positionToOffset(error.start);
            int endOffset = lineNumbering.positionToOffset(error.end);
            if (0 < startOffset && 0 < endOffset && startOffset < endOffset) {
                holder.createAnnotation(severities.get(error.type), new TextRangeInterval(startOffset, endOffset), "[merlin] " + error.message);
            }
        }
    }
}
 
Example 30
Project: idea-php-typo3-plugin   File: IconAnnotator.java   Source Code and License 5 votes vote down vote up
private void annotateIcon(PsiElement psiElement, AnnotationHolder annotationHolder, String value) {
    if (IconIndex.getAllAvailableIcons(psiElement.getProject()).contains(value)) {
        annotationHolder.createInfoAnnotation(psiElement, null);
    } else {
        annotationHolder.createWarningAnnotation(psiElement, "Unresolved icon - this may also occur if the icon is defined in your extension, but not in the global icon registry.");
    }
}
 
Example 31
Project: idea-php-typo3-plugin   File: PathResourceAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    if (!(element instanceof StringLiteralExpression)) {
        return;
    }

    String content = ((StringLiteralExpression) element).getContents();
    if (!content.startsWith("EXT:") || element.getProject().getBasePath() == null) {
        return;
    }

    String resourceName = content.substring(4, content.length());
    if (resourceName.contains(":")) {
        // resource name points to a sub-resource such as a translation string, not here.
        return;
    }

    if (ResourcePathIndex.projectContainsResourceFile(element.getProject(), content)) {
        // exact match found
        return;
    }

    if (ResourcePathIndex.projectContainsResourceDirectory(element.getProject(), content)) {
        return;
    }

    createErrorMessage(element, holder, resourceName);
}
 
Example 32
Project: idea-php-typo3-plugin   File: TranslationAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {

    if (!(psiElement instanceof StringLiteralExpression)) {
        return;
    }

    StringLiteralExpression literalExpression = (StringLiteralExpression) psiElement;
    String value = literalExpression.getContents();

    if (TranslationUtil.isTranslationKeyString(value) && value.length() > 4 && !(psiElement.getParent() instanceof ConcatenationExpression)) {
        annotateTranslationUsage(psiElement, annotationHolder, value);
    }
}
 
Example 33
Project: idea-php-typo3-plugin   File: TranslationAnnotator.java   Source Code and License 5 votes vote down vote up
private void annotateTranslation(PsiElement psiElement, AnnotationHolder annotationHolder, String value) {
    if (TranslationUtil.keyExists(psiElement.getProject(), value)) {
        annotationHolder.createInfoAnnotation(psiElement, null);
    } else {
        annotationHolder.createErrorAnnotation(psiElement, "Unresolved translation - this may occur if you defined the translation key only in TypoScript");
    }
}
 
Example 34
Project: bamboo-soy   File: DoubleQuotedStringAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
  if (psiElement instanceof SoyAnyStringLiteral
      && psiElement.getParent() instanceof SoyExpr
      && psiElement.getText().startsWith("\"")) {
    annotationHolder.createErrorAnnotation(
        psiElement, "Strings in expressions must use single quotes.");
  }
}
 
Example 35
Project: bamboo-soy   File: IdentifierSanityAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(PsiElement element, AnnotationHolder holder) {
  if (element instanceof SoyXidStatement) {
    if (((SoyXidStatement) element).getCssXidIdentifier().getText().startsWith("%")) {
      holder.createErrorAnnotation(element, "Xid identifiers cannot start with '%'.");
    }
  }
  if (element instanceof SoyCssStatement) {
    if (((SoyCssStatement) element).getCssXidIdentifier().getText().contains(".")) {
      holder.createErrorAnnotation(element, "CSS identifiers cannot contain '.'.");
    }
  }
}
 
Example 36
Project: bamboo-soy   File: IncompleteBlockAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
  if (psiElement instanceof TagBlockElement) {
    TagBlockElement block = (TagBlockElement) psiElement;
    if (block.isIncomplete() && !(block instanceof ChoiceClauseElement)) {
      annotationHolder.createErrorAnnotation(block.getOpeningTag(),
          "{" + block.getTagName() + "} is not closed.");
    }
  }
}
 
Example 37
Project: bamboo-soy   File: MissingParametersAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
  if (psiElement instanceof CallStatementElement) {
    CallStatementElement statement = (CallStatementElement) psiElement;

    Collection<String> givenParameters = ParamUtils.getGivenParameters(statement);

    // TODO(thso): Detect data="" in more robust way.
    if (statement.getText().contains("data=")) return;

    PsiElement identifier =
        PsiTreeUtil.findChildOfType(statement, SoyTemplateReferenceIdentifier.class);

    if (identifier == null) return;

    List<String> requiredParameters =
        ParamUtils.getParametersForInvocation(statement, identifier.getText())
            .stream()
            .filter((var) -> !var.isOptional)
            .map((var) -> var.name)
            .collect(Collectors.toList());

    if (!givenParameters.containsAll(requiredParameters)) {
      requiredParameters.removeAll(givenParameters);
      annotationHolder.createErrorAnnotation(
          identifier, "Missing required parameters: " + String.join(",", requiredParameters));
    }
  }
}
 
Example 38
Project: bamboo-soy   File: UnfinishedIdentifiersAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
  if (psiElement instanceof SoyVariableReferenceIdentifier && psiElement.getText().equals("$")) {
    annotationHolder.createErrorAnnotation(psiElement, "Variable name expected.");
  } else if (psiElement instanceof SoyFieldExpr && psiElement.getText().endsWith(".")) {
    annotationHolder.createErrorAnnotation(psiElement, "Field name expected.");
  }
}
 
Example 39
Project: bamboo-soy   File: UnexpectedStatementsAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
  if (psiElement instanceof SoyUnexpectedStatements) {
    PsiElement parent = psiElement.getParent();
    if (parent instanceof CallStatementElement) {
      annotationHolder.createErrorAnnotation(psiElement, "Expected a {param ...} tag.");
    } else if (parent instanceof ChoiceStatementElement) {
      annotationHolder.createErrorAnnotation(
          psiElement, "Expected a {case ...} or {default ...} tag.");
    }
  }
}
 
Example 40
Project: bamboo-soy   File: DeltemplateIdentifierAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
  if (psiElement instanceof SoyTemplateBlock) {
    SoyTemplateBlock block = (SoyTemplateBlock) psiElement;
    if (block.isDelegate() && block.getName() != null && block.getName().startsWith(".")) {
      annotationHolder.createErrorAnnotation(
          // cannot be null since getName is not null
          block.getDefinitionIdentifier(), "Delegate template names cannot start with '.'.");
    }
  }
}
 
Example 41
Project: bamboo-soy   File: ClosingBraceSanityAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
  if (psiElement instanceof TagElement) {
    TagElement tagElement = (TagElement) psiElement;

    TokenSet allowedRBraces = SoyTokenTypes.RIGHT_BRACES;
    if (mustCloseRBraceTags.contains(tagElement.getClass())) {
      allowedRBraces = TokenSet.andNot(allowedRBraces, SoyTokenTypes.SLASH_R_BRACES);
    } else if (mustCloseSlashRBraceTags.contains(tagElement.getClass())) {
      allowedRBraces = TokenSet.andSet(allowedRBraces, SoyTokenTypes.SLASH_R_BRACES);
    }

    if (tagElement.isDoubleBraced()) {
      allowedRBraces = TokenSet.andSet(allowedRBraces, SoyTokenTypes.DOUBLE_BRACES);
    } else {
      allowedRBraces = TokenSet.andNot(allowedRBraces, SoyTokenTypes.DOUBLE_BRACES);
    }

    if (!allowedRBraces.contains(tagElement.getClosingBraceType())) {
      annotationHolder.createErrorAnnotation(tagElement, "Must close by " +
          Stream.of(allowedRBraces.getTypes())
              .map(SoyTokenTypes.BRACE_TYPE_TO_STRING::get)
              .sorted()
              .collect(Collectors.joining(" or ")));
    }
  }
}
 
Example 42
Project: bamboo-soy   File: UnusedParameterAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder annotationHolder) {
  if (element instanceof SoyTemplateBlock) {
    // Abort if values are passed with data="...", parameter are sometimes defined for the sake
    // of added documentation even when not technically used directly in the template body.
    if (element.getText().contains("data=")) {
      return;
    }

    Collection<Parameter> parameters = ParamUtils.getParamDefinitions(element);

    Collection<String> usedVariableIdentifiers =
        PsiTreeUtil.findChildrenOfType(element, IdentifierElement.class)
            .stream()
            .map(IdentifierElement::getReferences)
            .flatMap(references -> Arrays.stream(references))
            .map(PsiReference::getCanonicalText)
            .filter(id -> id.startsWith("$"))
            .map(id -> id.substring(1))
            .collect(Collectors.toList());

    for (Variable parameter : parameters) {
      boolean isMatched = false;
      for (String usedIdentifier : usedVariableIdentifiers) {
        if (usedIdentifier.startsWith(parameter.name)) {
          isMatched = true;
          break;
        }
      }

      if (!isMatched) {
        annotationHolder.createInfoAnnotation(parameter.element,
            "Parameter " + parameter.name + " is unused.");
      }
    }
  }
}
 
Example 43
Project: intellij-plugin   File: CoffigYamlAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
    if (isConfigFile(psiElement) && psiElement instanceof YAMLKeyValue && isYamlLeaf(psiElement)) {
        if (hasNoConfigurationObject(psiElement) && hasNoExplicitReference(psiElement)) {
            TextRange range = new TextRange(psiElement.getTextRange().getStartOffset(), psiElement.getTextRange().getStartOffset() + ((YAMLKeyValue) psiElement).getKeyText().length());
            Annotation warningAnnotation = annotationHolder.createWarningAnnotation(range, "Unused configuration property");
            warningAnnotation.setHighlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL);
        }
    }
}
 
Example 44
Project: mule-intellij-plugins   File: RamlAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void apply(@NotNull PsiFile file, RamlValidationResult annotationResult, @NotNull AnnotationHolder holder)
{
    final List<ErrorNode> errorNodes = annotationResult.getErrorNodes();
    for (ErrorNode errorNode : errorNodes)
    {
        if (file.getVirtualFile().getPath().endsWith(errorNode.getStartPosition().getPath()))
        {
            holder.createAnnotation(HighlightSeverity.ERROR, new TextRange(errorNode.getStartPosition().getIndex(), errorNode.getEndPosition().getIndex()), errorNode.getErrorMessage());
        }
    }

}
 
Example 45
Project: mule-intellij-plugins   File: WeaveAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    if (element instanceof WeaveKeyExpression) {
        holder.createInfoAnnotation(element, "Property key").setTextAttributes(WeaveSyntaxHighlighter.KEY);
    }
    if (element instanceof WeaveIdentifier && element.getParent() instanceof WeaveFunctionDefinition) {
        holder.createInfoAnnotation(element, "Function").setTextAttributes(WeaveSyntaxHighlighter.FUNCTION_DECLARATION);
    }
    if (element instanceof WeaveIdentifier && element.getParent() instanceof WeaveVariableDefinition) {
        holder.createInfoAnnotation(element, "Variable").setTextAttributes(WeaveSyntaxHighlighter.VARIABLE);
    }
    if (element instanceof WeaveIdentifier && element.getParent() instanceof WeaveFunctionCallExpression) {
        holder.createInfoAnnotation(element, "Function call").setTextAttributes(WeaveSyntaxHighlighter.FUNCTION_CALL);
    }
}
 
Example 46
Project: intellij-ce-playground   File: GroovyAnnotator.java   Source Code and License 5 votes vote down vote up
private static void checkOverrideAnnotation(AnnotationHolder holder, GrModifierList list, GrMethod method) {
  final PsiAnnotation overrideAnnotation = list.findAnnotation("java.lang.Override");
  if (overrideAnnotation == null) {
    return;
  }
  try {
    MethodSignatureBackedByPsiMethod superMethod = SuperMethodsSearch.search(method, null, true, false).findFirst();
    if (superMethod == null) {
      holder.createWarningAnnotation(overrideAnnotation, GroovyBundle.message("method.doesnot.override.super"));
    }
  }
  catch (IndexNotReadyException ignored) {
    //nothing to do
  }
}
 
Example 47
Project: intellij-ce-playground   File: GradleDslAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
  if (element instanceof GrReferenceExpression) {
    GrReferenceExpression referenceExpression = (GrReferenceExpression)element;
    final GrExpression qualifier = ResolveUtil.getSelfOrWithQualifier(referenceExpression);
    if (qualifier == null) return;
    if (qualifier instanceof GrReferenceExpression && ((GrReferenceExpression)qualifier).resolve() instanceof PsiClass) return;

    PsiType psiType = GradleResolverUtil.getTypeOf(qualifier);
    if (psiType == null) return;
    if (InheritanceUtil.isInheritor(psiType, GradleCommonClassNames.GRADLE_API_NAMED_DOMAIN_OBJECT_COLLECTION)) {
      final GroovyPsiManager psiManager = GroovyPsiManager.getInstance(element.getProject());
      PsiClass defaultGroovyMethodsClass =
        psiManager.findClassWithCache(GroovyCommonClassNames.DEFAULT_GROOVY_METHODS, element.getResolveScope());
      if (canBeMethodOf(referenceExpression.getReferenceName(), defaultGroovyMethodsClass)) return;

      final String qualifiedName = TypesUtil.getQualifiedName(psiType);
      final PsiClass containerClass =
        qualifiedName != null ? psiManager.findClassWithCache(qualifiedName, element.getResolveScope()) : null;
      if (canBeMethodOf(referenceExpression.getReferenceName(), containerClass)) return;

      PsiElement nameElement = referenceExpression.getReferenceNameElement();
      if (nameElement != null) {
        holder.createInfoAnnotation(nameElement, null).setTextAttributes(MAP_KEY);
      }
    }
  }
}
 
Example 48
Project: sutr-io   File: SutrAnnotator.java   Source Code and License 5 votes vote down vote up
private void validateLiteralPhrase(final @NotNull PsiElement psiElement, final @NotNull AnnotationHolder annotationHolder) {

        final SutrLiteralPhrases phrases = ((SutrLiteralPhrasesImpl) psiElement.getParent().getParent());
        for (final SutrLiteralPhrase sutrLiteralPhrase : phrases.getLiteralPhraseList()) {
            final boolean textMatch = sutrLiteralPhrase.getText().equals(psiElement.getText());
            final boolean nodeMatch = sutrLiteralPhrase.getNode().equals(psiElement.getParent().getNode());
            if (textMatch && !nodeMatch) {
                annotationHolder.createErrorAnnotation(psiElement, "Duplicate Literal Phrase");
            }
        }

        annotationHolder.createInfoAnnotation(psiElement, null).setTextAttributes(SutrSyntaxHighlighter.LITERAL_PHRASE);
    }
 
Example 49
Project: intellij-ce-playground   File: MavenDomGutterAnnotator.java   Source Code and License 5 votes vote down vote up
private static void annotateManagedDependency(MavenDomDependency dependency, AnnotationHolder holder) {
  final XmlTag tag = dependency.getXmlTag();
  if (tag == null) return;

  MavenDomDependency managingDependency = getManagingDependency(dependency);
  if (managingDependency != null) {

    final NavigationGutterIconBuilder<MavenDomDependency> iconBuilder =
      NavigationGutterIconBuilder.create(AllIcons.General.OverridingMethod, DependencyConverter.INSTANCE);
    iconBuilder.
      setTargets(managingDependency).
      setTooltipText(generateTooltip(managingDependency)).
      install(holder, tag);
  }
}
 
Example 50
Project: intellij-ce-playground   File: XPathAnnotator.java   Source Code and License 5 votes vote down vote up
private static void checkSillyNodeTest(AnnotationHolder holder, XPathNodeTest nodeTest) {
  if (nodeTest.getPrincipalType() != XPathNodeTest.PrincipalType.ELEMENT) {
    final XPathNodeTypeTest typeTest = PsiTreeUtil.getChildOfType(nodeTest, XPathNodeTypeTest.class);
    if (typeTest != null) {
      holder.createWarningAnnotation(typeTest, "Silly node type test on axis '" + nodeTest.getPrincipalType().getType() + "'");
    }
  }
}
 
Example 51
Project: sutr-io   File: SutrAnnotator.java   Source Code and License 5 votes vote down vote up
private void validateSlot(final @NotNull PsiElement psiElement, final @NotNull AnnotationHolder annotationHolder) {

        if (psiElement instanceof SutrSlotName) {

            if (!hasParam(psiElement)) {
                annotationHolder.createErrorAnnotation(psiElement, "Slot slotName not defined in Sutr params.");
            }
            if (isDuplicatedSlot(psiElement)) {
                annotationHolder.createErrorAnnotation(psiElement, "Slot used more than once in utterance.");
            }
        }

        annotationHolder.createInfoAnnotation(psiElement, null).setTextAttributes(SutrSyntaxHighlighter.SLOT);
    }
 
Example 52
Project: sutr-io   File: SutrAnnotator.java   Source Code and License 5 votes vote down vote up
private void validateTypeName(final @NotNull PsiElement psiElement, final AnnotationHolder annotationHolder) {

        final PsiElement parent = psiElement.getParent().getParent();

        if (parent instanceof SutrImportStmt && ((SutrImportStmt) parent).resolveReference() == null) {
            annotationHolder.createErrorAnnotation(psiElement, "Unable to resolve import statement.");
            return;
        }

        if (parent instanceof SutrTypeDefinitionReference) {
            validateTypeDeclaration((SutrTypeDefinitionReference) parent, annotationHolder);
        }

        annotationHolder.createInfoAnnotation(psiElement, null).setTextAttributes(SutrSyntaxHighlighter.TYPE_NAME);
    }
 
Example 53
Project: intellij-ce-playground   File: XPathAnnotator.java   Source Code and License 5 votes vote down vote up
private static void checkSillyStep(AnnotationHolder holder, XPathStep step) {
  final XPathExpression previousStep = step.getPreviousStep();
  if (previousStep instanceof XPathStep) {
    final XPathNodeTest nodeTest = ((XPathStep)previousStep).getNodeTest();
    if (nodeTest != null) {
      final XPathNodeTest.PrincipalType principalType = nodeTest.getPrincipalType();
      if (principalType != XPathNodeTest.PrincipalType.ELEMENT) {
        XPathNodeTest test = step.getNodeTest();
        if (test != null) {
          holder.createWarningAnnotation(test, "Silly location step on " + principalType.getType() + " axis");
        }
      }
    }
  }
}
 
Example 54
Project: lua-for-idea   File: InferenceAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    if (!LuaPsiManager.isTypeInferenceEnabled()) return;
    if (element instanceof LuaPsiElement) {
        ((LuaPsiElement) element).accept(this);
    }
}
 
Example 55
Project: intellij-ce-playground   File: GroovyAnnotator.java   Source Code and License 5 votes vote down vote up
private static void checkModifierIsNotAllowedImpl(@NotNull GrModifierList modifierList,
                                                  @NotNull @GrModifier.GrModifierConstant String modifier,
                                                  @Nullable String message,
                                                  @NotNull AnnotationHolder holder,
                                                  final boolean explicit) {
  if (explicit ? modifierList.hasModifierProperty(modifier) : modifierList.hasExplicitModifier(modifier)) {
    PsiElement modifierOrList = getModifierOrList(modifierList, modifier);
    final Annotation annotation = holder.createErrorAnnotation(modifierOrList, message);
    registerFix(annotation, new GrModifierFix((PsiMember)modifierList.getParent(), modifier, true, false, GrModifierFix.MODIFIER_LIST), modifierList);
  }
}
 
Example 56
Project: intellij-ce-playground   File: GroovyAnnotator.java   Source Code and License 5 votes vote down vote up
private static void checkGrDocReferenceElement(AnnotationHolder holder, PsiElement element) {
  ASTNode node = element.getNode();
  if (node != null && TokenSets.BUILT_IN_TYPES.contains(node.getElementType())) {
    Annotation annotation = holder.createInfoAnnotation(element, null);
    annotation.setTextAttributes(GroovySyntaxHighlighter.KEYWORD);
  }
}
 
Example 57
Project: smcplugin   File: SmcNamedElementExistsAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) {
    for (TypeDescriptor<SmcNamedElement> descriptor : validateClasses) {
        Class<? extends SmcNamedElement> typeClass = descriptor.getTypeClass();
        if (typeClass.isInstance(element)) {
            SmcNamedElement smcCustomNamed = (SmcNamedElement) element;
            if (smcCustomNamed.getName() != null && !SmcPsiUtil.hasNamedElementsByTypeWithinParentType(element, SmcMap.class, SmcState.class, smcCustomNamed.getName())) {
                holder.createErrorAnnotation(element, getNoElementDeclarationFoundMessage(descriptor.getTypeType(), smcCustomNamed.getName()));
            }
        }
    }
}
 
Example 58
Project: smcplugin   File: SmcTypeIsAvailableAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    if (element instanceof SmcParameterType) {
        SmcParameterType type = (SmcParameterType) element;
        String name = type.getName();
        PsiElement nameIdentifier = type.getNameIdentifier();
        if (name == null || nameIdentifier == null) return;
        if (!SmcPsiUtil.isTypeAvailableFromSmc(type)) {
            Annotation errorAnnotation = holder.createErrorAnnotation(nameIdentifier, getMessage(name));
            errorAnnotation.setTextAttributes(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
        }
    }
}
 
Example 59
Project: intellij-ce-playground   File: MavenDomGutterAnnotator.java   Source Code and License 5 votes vote down vote up
private static void annotateMavenDomParent(@NotNull MavenDomParent mavenDomParent, @NotNull AnnotationHolder holder) {
  MavenDomProjectModel parent = MavenDomProjectProcessorUtils.findParent(mavenDomParent, mavenDomParent.getManager().getProject());

  if (parent != null) {
    NavigationGutterIconBuilder.create(MavenIcons.ParentProject, MavenProjectConverter.INSTANCE).
      setTargets(parent).
      setTooltipText(MavenDomBundle.message("parent.pom.title")).
      install(holder, mavenDomParent.getXmlElement());
  }
}
 
Example 60
Project: smcplugin   File: SmcPushStateAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) {

    if (element instanceof SmcPushMapNameElement) {
        SmcPushMapNameElement mapNameElement = (SmcPushMapNameElement) element;
        if (mapNameElement.getName() != null && SmcPsiUtil.findMap(element.getContainingFile(), mapNameElement.getName()).isEmpty()) {
            holder.createErrorAnnotation(element, getNoElementDeclarationFoundMessage(SmcTypes.MAP, mapNameElement.getName()));
        }
    }

    if (element instanceof SmcPushStateNameElement) {
        SmcPushStateNameElement stateNameElement = (SmcPushStateNameElement) element;
        SmcPushState start = (SmcPushState) element.getParent();
        String name = stateNameElement.getName();
        String mapName = start.getMapName();
        if (name != null) {
            if (mapName != null) {
                if (SmcPsiUtil.getElementsByTypeAndNameWithinNamedType(element,
                        SmcMap.class,
                        mapName,
                        SmcState.class,
                        name).isEmpty()) {
                    holder.createErrorAnnotation(element, getNoElementFoundInsideOtherElementMessage(SmcTypes.STATE,
                            name, SmcTypes.MAP, mapName));
                }
            }else if(!SmcPsiUtil.hasNamedElementsByTypeWithinParentType(element, SmcMap.class, SmcState.class, name)){
                holder.createErrorAnnotation(element, getNoElementDeclarationFoundMessage(SmcTypes.STATE, name));
            }
        }
    }
}