Java Code Examples for com.intellij.psi.PsiElementVisitor#EMPTY_VISITOR

The following examples show how to use com.intellij.psi.PsiElementVisitor#EMPTY_VISITOR . 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: YamlSchemaInspection.java    From intellij-swagger with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(
    @NotNull final ProblemsHolder holder,
    final boolean isOnTheFly,
    @NotNull final LocalInspectionToolSession session) {

  PsiFile file = holder.getFile();

  if (fileDetector.isMainOpenApiYamlFile(file)) {
    return createVisitor("openapi.json", holder, session, file);
  } else if (fileDetector.isMainSwaggerYamlFile(file)) {
    return createVisitor("swagger.json", holder, session, file);
  } else {
    return PsiElementVisitor.EMPTY_VISITOR;
  }
}
 
Example 2
Source File: JsonSchemaInspection.java    From intellij-swagger with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(
    @NotNull final ProblemsHolder holder,
    final boolean isOnTheFly,
    @NotNull final LocalInspectionToolSession session) {

  PsiFile file = holder.getFile();

  if (fileDetector.isMainOpenApiJsonFile(file)) {
    return createVisitor("openapi.json", holder, session, file);
  } else if (fileDetector.isMainSwaggerJsonFile(file)) {
    return createVisitor("swagger.json", holder, session, file);
  } else {
    return PsiElementVisitor.EMPTY_VISITOR;
  }
}
 
Example 3
Source File: AbstractCamelInspection.java    From camel-idea-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, final boolean isOnTheFly) {
    if (isInspectionEnabled(holder.getProject())) {
        return new PsiElementVisitor() {
            @Override
            public void visitElement(PsiElement element) {
                if (accept(element)) {
                    String text = getIdeaUtils().extractTextFromElement(element, false, false, true);
                    if (!StringUtils.isEmpty(text)) {
                        validateText(element, holder, text, isOnTheFly);
                    }
                }
            }
        };
    } else {
        return PsiElementVisitor.EMPTY_VISITOR;
    }
}
 
Example 4
Source File: YamlSchemaInspection.java    From intellij-swagger with MIT License 5 votes vote down vote up
private PsiElementVisitor createVisitor(
    final String schemaFileName,
    final ProblemsHolder holder,
    final LocalInspectionToolSession session,
    final PsiFile file) {
  List<YAMLDocument> documents = ((YAMLFile) file).getDocuments();
  if (documents.size() != 1) return PsiElementVisitor.EMPTY_VISITOR;

  PsiElement root = documents.get(0).getTopLevelValue();
  if (root == null) return PsiElementVisitor.EMPTY_VISITOR;

  JsonSchemaService service = JsonSchemaService.Impl.get(file.getProject());

  final URL url = ResourceUtil.getResource(getClass(), "schemas", schemaFileName);
  final VirtualFile virtualFile = VfsUtil.findFileByURL(url);

  final JsonSchemaObject schema = service.getSchemaObjectForSchemaFile(virtualFile);

  return new YamlPsiElementVisitor() {
    @Override
    public void visitElement(PsiElement element) {
      if (element != root) return;
      final JsonLikePsiWalker walker = JsonLikePsiWalker.getWalker(element, schema);
      if (walker == null) return;

      JsonComplianceCheckerOptions options = new JsonComplianceCheckerOptions(false);

      new JsonSchemaComplianceChecker(schema, holder, walker, session, options).annotate(element);
    }
  };
}
 
Example 5
Source File: JsonSchemaInspection.java    From intellij-swagger with MIT License 5 votes vote down vote up
private PsiElementVisitor createVisitor(
    final String schemaFileName,
    final ProblemsHolder holder,
    final LocalInspectionToolSession session,
    final PsiFile file) {

  JsonValue root =
      file instanceof JsonFile
          ? ObjectUtils.tryCast(file.getFirstChild(), JsonValue.class)
          : null;
  if (root == null) return PsiElementVisitor.EMPTY_VISITOR;

  JsonSchemaService service = JsonSchemaService.Impl.get(file.getProject());

  final URL url = ResourceUtil.getResource(getClass(), "schemas", schemaFileName);
  final VirtualFile virtualFile = VfsUtil.findFileByURL(url);

  final JsonSchemaObject schema = service.getSchemaObjectForSchemaFile(virtualFile);

  return new JsonElementVisitor() {
    @Override
    public void visitElement(PsiElement element) {
      if (element == root) {
        final JsonLikePsiWalker walker = JsonLikePsiWalker.getWalker(element, schema);
        if (walker == null) return;

        JsonComplianceCheckerOptions options = new JsonComplianceCheckerOptions(false);

        new JsonSchemaComplianceChecker(schema, holder, walker, session, options)
            .annotate(element);
      }
    }
  };
}
 
Example 6
Source File: UnityNewMonoBehaviourInspection.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public PsiElementVisitor buildVisitor(@Nonnull final ProblemsHolder holder, boolean isOnTheFly)
{
	if(Unity3dModuleExtensionUtil.getRootModule(holder.getProject()) == null)
	{
		return PsiElementVisitor.EMPTY_VISITOR;
	}

	return new CSharpElementVisitor()
	{
		@Override
		@RequiredReadAction
		public void visitNewExpression(CSharpNewExpression expression)
		{
			DotNetType newType = expression.getNewType();
			if(newType == null)
			{
				return;
			}
			DotNetTypeRef typeRef = expression.toTypeRef(true);
			if(CSharpTypeUtil.isInheritable(new CSharpTypeRefByQName(expression, Unity3dTypes.UnityEngine.MonoBehaviour), typeRef, expression))
			{
				holder.registerProblem(newType, Unity3dBundle.message("new.mono.behaviour.inspection.message"));
			}
		}
	};
}
 
Example 7
Source File: MatchNamespaceInspection.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
@RequiredReadAction
public PsiElementVisitor buildVisitor(@Nonnull ProblemsHolder holder, boolean isOnTheFly, @Nonnull LocalInspectionToolSession session)
{
	PsiFile file = holder.getFile();
	if(!(file instanceof CSharpFile))
	{
		return PsiElementVisitor.EMPTY_VISITOR;
	}

	if(file instanceof PsiCodeFragment)
	{
		return PsiElementVisitor.EMPTY_VISITOR;
	}

	DotNetSimpleModuleExtension extension = ModuleUtilCore.getExtension(file, DotNetSimpleModuleExtension.class);
	if(extension == null)
	{
		return PsiElementVisitor.EMPTY_VISITOR;
	}

	MatchNamespaceVisitor visitor = session.getUserData(KEY);
	if(visitor == null)
	{
		session.putUserData(KEY, visitor = new MatchNamespaceVisitor(holder, extension));
	}
	return visitor;
}
 
Example 8
Source File: UnityCompareTagInspection.java    From consulo-unity3d with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public PsiElementVisitor buildVisitor(@Nonnull ProblemsHolder holder, boolean isOnTheFly)
{
	if(Unity3dModuleExtensionUtil.getRootModule(holder.getProject()) == null)
	{
		return PsiElementVisitor.EMPTY_VISITOR;
	}

	return new CSharpElementVisitor()
	{
		@Override
		@RequiredReadAction
		public void visitBinaryExpression(CSharpBinaryExpressionImpl expression)
		{
			IElementType operatorElementType = expression.getOperatorElement().getOperatorElementType();

			if(operatorElementType == CSharpTokens.EQEQ || operatorElementType == CSharpTokens.NTEQ)
			{
				DotNetExpression leftExpression = expression.getLeftExpression();

				DotNetExpression rightExpression = expression.getRightExpression();
				if(rightExpression == null)
				{
					return;
				}

				if(leftExpression instanceof CSharpReferenceExpression)
				{
					String referenceName = ((CSharpReferenceExpression) leftExpression).getReferenceName();
					if("tag".equals(referenceName))
					{
						PsiElement maybeField = ((CSharpReferenceExpression) leftExpression).resolve();
						if(maybeField instanceof CSharpPropertyDeclaration)
						{

							DotNetExpression qualifier = ((CSharpReferenceExpression) leftExpression).getQualifier();
							CSharpTypeDeclaration target = null;
							if(qualifier == null)
							{
								target = PsiTreeUtil.getParentOfType(leftExpression, CSharpTypeDeclaration.class);
							}
							else if(qualifier instanceof CSharpReferenceExpression)
							{
								PsiElement resolveTarget = ((CSharpReferenceExpression) qualifier).resolve();
								if(resolveTarget instanceof CSharpTypeDeclaration)
								{
									target = (CSharpTypeDeclaration) resolveTarget;
								}
							}

							if(target == null)
							{
								return;
							}

							if(target.isInheritor(Unity3dTypes.UnityEngine.Component, true))
							{
								holder.registerProblem(expression, "Using CompareTag for tag comparison does not cause allocations", new ReplaceByCompareTagFix(expression));
							}
						}
					}
				}
			}
		}
	};
}