gpt4 book ai didi

fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlPsiElementFactory类的使用及代码示例

转载 作者:知者 更新时间:2024-03-18 15:03:31 25 4
gpt4 key购买 nike

本文整理了Java中fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlPsiElementFactory类的一些代码示例,展示了YamlPsiElementFactory类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YamlPsiElementFactory类的具体详情如下:
包路径:fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlPsiElementFactory
类名称:YamlPsiElementFactory

YamlPsiElementFactory介绍

暂无

代码示例

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

@Nullable
public static <T extends PsiElement> T createFromText(@NotNull Project p, final Class<T> aClass, String text) {
  final PsiElement[] ret = new PsiElement[]{null};
  createDummyFile(p, text).accept(new PsiRecursiveElementWalkingVisitor() {
    public void visitElement(PsiElement element) {
      if(ret[0] == null && aClass.isInstance(element)) {
        ret[0] = element;
      }
      super.visitElement(element);
    }
  });
  return (T) ret[0];
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

@Override
  public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PsiElement psiElement1 = descriptor.getPsiElement();
    YAMLKeyValue replacement = YamlPsiElementFactory.createFromText(
        project,
        YAMLKeyValue.class,
        "class: " + replacementFQN
    );

    if (replacement != null && replacement.getValue() != null) {
      psiElement1.replace(replacement.getValue());
    }
  }
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

private void insertYamlServiceTag() {
  if(!(this.psiFile instanceof YAMLFile)) {
    return;
  }
  String text = createServiceAsText(ServiceBuilder.OutputType.Yaml, this.psiFile);
  YAMLKeyValue fromText = YamlPsiElementFactory.createFromText(project, YAMLKeyValue.class, text);
  if(fromText == null) {
    return;
  }
  PsiElement psiElement = YamlHelper.insertKeyIntoFile((YAMLFile) psiFile, fromText, "services");
  if(psiElement != null) {
    navigateToElement(new TextRange[] {psiElement.getTextRange()});
  }
  dispose();
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

@NotNull
public static PsiElement createYamlPsiFromText(Project p, final IElementType type, @NotNull String text) {
  final Ref<PsiElement> ret = new Ref<>();
  PsiFile dummyFile = createDummyFile(p, text);
  dummyFile.accept(new PsiRecursiveElementWalkingVisitor() {
    @Override
    public void visitElement(PsiElement element) {
      if(element.getNode() == type) {
        ret.set(element);
      }
      super.visitElement(element);
    }
  });
  assert !ret.isNull() : "cannot create element from text:\n" + dummyFile.getText();
  return ret.get();
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

/**
 * @see fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper#getYamlKeyValueAsString
 */
public void testGetYamlKeyValueAsString() {
  String[] strings = {
    "{ name: routing.loader, method: foo }",
    "{ name: routing.loader, method: 'foo' }",
    "{ name: routing.loader, method: \"foo\" }",
  };
  for (String s : strings) {
    assertEquals("foo", YamlHelper.getYamlKeyValueAsString(
      YamlPsiElementFactory.createFromText(getProject(), YAMLHashImpl.class, s),
      "method"
    ));
  }
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

private int getIndentForTextContent(@NotNull String content) {
  return YamlHelper.getIndentSpaceForFile((YAMLFile) YamlPsiElementFactory.createDummyFile(
    getProject(),
    "foo.yml",
    content
  ));
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

/**
 * @see fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper#getYamlArrayOnSequenceOrArrayElements
 */
public void testGetYamlArrayOnSequenceOrArrayElementsForArray() {
  YAMLCompoundValue fromText = YamlPsiElementFactory.createFromText(getProject(), YAMLCompoundValue.class, "" +
    "calls: [@foo, @bar] \n"
  );
  assertNotNull(fromText);
  String join = StringUtils.join(ContainerUtil.map(YamlHelper.getYamlArrayOnSequenceOrArrayElements(fromText), new Function<PsiElement, String>() {
    @Override
    public String fun(PsiElement psiElement) {
      return psiElement.getText();
    }
  }), ",");
  assertTrue(join.contains("foo"));
  assertTrue(join.contains("bar"));
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

public void testThatNonConfigRootShouldNotProvideLinemarker() {
    PsiElement yaml = YamlPsiElementFactory.createDummyFile(getProject(), "foobar.yml", "foobar_root:\n" +
      "    foo: ~"
    );

    assertLineMarkerIsEmpty(yaml);
  }
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

/**
 * @see fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper#collectServiceTags
 */
public void testCollectServiceTags() {
  YAMLKeyValue fromText = YamlPsiElementFactory.createFromText(getProject(), YAMLKeyValue.class, "" +
    "foo:\n" +
    "  tags:\n" +
    "    - { name: routing.loader, method: crossHint }\n" +
    "    - { name: routing.loader1, method: crossHint }\n"
  );
  assertNotNull(fromText);
  assertContainsElements(YamlHelper.collectServiceTags(fromText), "routing.loader", "routing.loader1");
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

public void testThatConfigRootProvidesLinemarker() {
  PsiElement yaml = YamlPsiElementFactory.createDummyFile(getProject(), "config.yml", "foobar_root:\n" +
    "    foo: ~"
  );
  assertLineMarker(yaml, new LineMarker.ToolTipEqualsAssert("Navigate to configuration"));
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

/**
 * @see fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper#getYamlArrayOnSequenceOrArrayElements
 */
public void testGetYamlArrayOnSequenceOrArrayElements() {
  String[] strings = {
    "calls: [@foo, @bar] \n",
    "calls:\n  - @foo\n  - @bar\n",
  };
  for (String s : strings) {
    YAMLCompoundValue fromText = YamlPsiElementFactory.createFromText(getProject(), YAMLCompoundValue.class, s);
    assertNotNull(fromText);
    List<PsiElement> elements = YamlHelper.getYamlArrayOnSequenceOrArrayElements(fromText);
    assertNotNull(elements);
    String join = StringUtils.join(ContainerUtil.map(elements, new Function<PsiElement, String>() {
      @Override
      public String fun(PsiElement psiElement) {
        return psiElement.getText();
      }
    }), ",");
    assertTrue(join.contains("foo"));
    assertTrue(join.contains("bar"));
  }
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

/**
 * @see TwigUtil#getTwigPathFromYamlConfigResolved
 */
public void testGetTwigPathFromYamlConfigResolved() {
  createFile("app/test/foo.yaml");
  PsiFile dummyFile = YamlPsiElementFactory.createDummyFile(getProject(), "" +
    "twig:\n" +
    "   paths:\n" +
    "       '%kernel.root_dir%/test': foo\n" +
    "       '%kernel.project_dir%/app/test': project\n" +
    "       '%kernel.root_dir%/../app': app\n"
  );
  Collection<Pair<String, String>> paths = TwigUtil.getTwigPathFromYamlConfigResolved((YAMLFile) dummyFile);
  assertNotNull(
    paths.stream().filter(pair -> "foo".equals(pair.getFirst()) && "app/test".equals(pair.getSecond())).findFirst()
  );
  assertNotNull(
    paths.stream().filter(pair -> "project".equals(pair.getFirst()) && "app/test".equals(pair.getSecond())).findFirst()
  );
  assertNotNull(
    paths.stream().filter(pair -> "app".equals(pair.getFirst()) && "app".equals(pair.getSecond())).findFirst()
  );
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

Collection<YAMLDocument> yamlDocuments = new ArrayList<YAMLDocument>();
yamlDocuments.add(YamlPsiElementFactory.createFromText(getProject(), YAMLDocument.class, String.format(
    "route1:\n" +
    "    path: /foo\n" +
)));
yamlDocuments.add(YamlPsiElementFactory.createFromText(getProject(), YAMLDocument.class, String.format(
  "route1:\n" +
    "    path: /foo\n" +
)));
yamlDocuments.add(YamlPsiElementFactory.createFromText(getProject(), YAMLDocument.class, String.format(
  "route1:\n" +
    "    pattern: /foo\n" +

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

public void testBuildForClassWithoutParameter() {
  PsiFile dummyFile = YamlPsiElementFactory.createDummyFile(getProject(), "foo.yml", "services:\n  foobar: ~");
  ServiceBuilder serviceBuilder = new ServiceBuilder(Collections.emptyList(), dummyFile, false);
  assertEquals(
    "foobar:\n  class: Foobar",
    serviceBuilder.build(ServiceBuilder.OutputType.Yaml, "Foobar", "foobar")
  );
  assertEquals(
    "<service class=\"Foobar\" id=\"foobar\"/>",
    StringUtils.trim(serviceBuilder.build(ServiceBuilder.OutputType.XML, "Foobar", "foobar"))
  );
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

/**
 * @see fr.adrienbrault.idea.symfony2plugin.routing.RouteHelper#getYamlRouteDefinitions
 */
public void testGetYamlRouteDefinitionsForControllerKeyword() {
  Collection<StubIndexedRoute> yamlRouteDefinitions = RouteHelper.getYamlRouteDefinitions(YamlPsiElementFactory.createFromText(getProject(), YAMLDocument.class,
    "foo_keyword:\n" +
      "   path: /foo\n" +
      "   controller: 'AppBundle:Blog:list'\n"
  ));
  StubIndexedRoute route = ContainerUtil.find(yamlRouteDefinitions, new MyEqualStubIndexedRouteCondition("foo_keyword"));
  assertNotNull(route);
  assertContainsElements(Collections.singletonList("AppBundle:Blog:list"), route.getController());
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

public void testInsertTranslationForYamlFile() {
    PsiFile dummyFile = YamlPsiElementFactory.createDummyFile(getProject(), "foo.de.yml", "car: 'foo'");

    CommandProcessor.getInstance().executeCommand(getProject(), () -> ApplicationManager.getApplication().runWriteAction(() -> {
      TranslationInsertUtil.invokeTranslation(dummyFile, "foobar", "value");
    }), null, null);

    String text = dummyFile.getText();

    assertTrue(text.contains("foobar: 'value'"));
  }
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

/**
 * @see fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper#collectServiceTags
 */
public void testCollectServiceTagsForSymfony33TagsShortcutInline() {
  YAMLKeyValue fromText = YamlPsiElementFactory.createFromText(getProject(), YAMLKeyValue.class, "" +
    "foo:\n" +
    "  tags: [routing.loader_tags_3, routing.loader_tags_4]\n"
  );
  assertNotNull(fromText);
  Set<String> collection = YamlHelper.collectServiceTags(fromText);
  assertContainsElements(collection, "routing.loader_tags_3");
  assertContainsElements(collection, "routing.loader_tags_4");
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

public void testBuildForConstructor() {
  ServiceBuilder serviceBuilder = new ServiceBuilder(
    getMethodModelParameters(),
    YamlPsiElementFactory.createDummyFile(getProject(), "foo.yml", "services:\n  foobar: ~"),
    false
  );
  String expectedYaml = "" +
    "foobar:\n" +
    "  class: Foo\\Bar\n" +
    "  arguments: ['@foobar']";
  assertEquals(
    expectedYaml,
    serviceBuilder.build(ServiceBuilder.OutputType.Yaml, "Foo\\Bar", "foobar")
  );
  String expectedXml = "" +
    "<service class=\"Foo\\Bar\" id=\"foobar\">\n" +
    "  <argument id=\"foobar\" type=\"service\"/>\n" +
    "</service>";
  assertEquals(
    expectedXml,
    StringUtils.trim(serviceBuilder.build(ServiceBuilder.OutputType.XML, "Foo\\Bar", "foobar"))
  );
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

/**
 * @see fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper#collectServiceTags
 */
public void testCollectServiceTagsForSymfony33TagsShortcut() {
  YAMLKeyValue fromText = YamlPsiElementFactory.createFromText(getProject(), YAMLKeyValue.class, "" +
    "foo:\n" +
    "  tags:\n" +
    "    - routing.loader_tags_1\n" +
    "    - routing.loader_tags_2\n"
  );
  assertNotNull(fromText);
  Set<String> collection = YamlHelper.collectServiceTags(fromText);
  assertContainsElements(collection, "routing.loader_tags_1");
  assertContainsElements(collection, "routing.loader_tags_2");
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

public void testYmlTagAttributeExtraction() {
    YAMLHashImpl fromText = YamlPsiElementFactory.createFromText(getProject(), YAMLHashImpl.class, "{ name: routing.loader, method: foo }");
    YamlServiceTag tag = new YamlServiceTag("foo", "routing.loader", (YAMLMapping) fromText);

    assertEquals("foo", tag.getAttribute("method"));
    assertEquals("routing.loader", tag.getAttribute("name"));
  }
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com