本文整理汇总了Java中com.jetbrains.php.lang.psi.PhpPsiElementFactory.createPhpPsiFromText方法的典型用法代码示例。如果您正苦于以下问题:Java PhpPsiElementFactory.createPhpPsiFromText方法的具体用法?Java PhpPsiElementFactory.createPhpPsiFromText怎么用?Java PhpPsiElementFactory.createPhpPsiFromText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jetbrains.php.lang.psi.PhpPsiElementFactory
的用法示例。
在下文中一共展示了PhpPsiElementFactory.createPhpPsiFromText方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConvertMethodToRouteShortcutControllerForInvoke
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
/**
* @see fr.adrienbrault.idea.symfony2plugin.routing.RouteHelper#convertMethodToRouteShortcutControllerName
*/
public void testConvertMethodToRouteShortcutControllerForInvoke()
{
myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject("GetRoutesOnControllerAction.php"));
PhpClass phpClass = PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpClass.class, "<?php\n" +
"namespace FooBar\\FooBundle\\Controller" +
"{\n" +
" class FooBarController\n" +
" {\n" +
" function __invoke() {}\n" +
" }\n" +
"}"
);
Method fooAction = phpClass.findMethodByName("__invoke");
assertNotNull(fooAction);
assertEquals("FooBar\\FooBundle\\Controller\\FooBarController", RouteHelper.convertMethodToRouteShortcutControllerName(fooAction));
}
示例2: testGetFormAliases
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
public void testGetFormAliases() {
PhpClass phpClass = PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpClass.class, "<?php\n" +
"class Foo implements \\Symfony\\Component\\Form\\FormTypeInterface {\n" +
" public function getName()" +
" {\n" +
" return 'bar';\n" +
" return 'foo';\n" +
" }\n" +
"}"
);
assertContainsElements(Arrays.asList("bar", "foo"), FormUtil.getFormAliases(phpClass));
}
示例3: testGetFormAliasesPhpClassNotImplementsInterfaceAndShouldBeEmpty
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
public void testGetFormAliasesPhpClassNotImplementsInterfaceAndShouldBeEmpty() {
PhpClass phpClass = PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpClass.class, "<?php\n" +
"class Foo {\n" +
" public function getName()" +
" {\n" +
" return 'bar';\n" +
" }\n" +
"}"
);
assertSize(0, FormUtil.getFormAliases(phpClass));
}
示例4: testConvertMethodToRouteShortcutControllerName
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
/**
* @see fr.adrienbrault.idea.symfony2plugin.routing.RouteHelper#convertMethodToRouteShortcutControllerName
*/
public void testConvertMethodToRouteShortcutControllerName() {
myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject("GetRoutesOnControllerAction.php"));
PhpClass phpClass = PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpClass.class, "<?php\n" +
"namespace FooBar\\FooBundle\\Controller" +
"{\n" +
" class FooBarController\n" +
" {\n" +
" function fooAction() {}\n" +
" }\n" +
"}"
);
Method fooAction = phpClass.findMethodByName("fooAction");
assertNotNull(fooAction);
assertEquals("FooBarFooBundle:FooBar:foo", RouteHelper.convertMethodToRouteShortcutControllerName(fooAction));
phpClass = PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpClass.class, "<?php\n" +
"namespace FooBar\\FooBundle\\Controller\\SubFolder" +
"{\n" +
" class SubController\n" +
" {\n" +
" function fooAction() {}\n" +
" }\n" +
"}"
);
fooAction = phpClass.findMethodByName("fooAction");
assertNotNull(fooAction);
assertEquals("FooBarFooBundle:SubFolder\\Sub:foo", RouteHelper.convertMethodToRouteShortcutControllerName(fooAction));
}
示例5: testGetTemplateAnnotationFilesWithSiblingMethod
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
public void testGetTemplateAnnotationFilesWithSiblingMethod() {
PhpDocTag phpDocTag = PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpDocTag.class, "<?php\n" +
"class Foo\n" +
"{\n" +
" /**" +
" * @Template(\"foo.html.twig\")" +
" */" +
" function fooAction()\n" +
" {\n" +
" }\n" +
"}\n"
);
assertContainsElements(TwigUtil.getTemplateAnnotationFilesWithSiblingMethod(phpDocTag).keySet(), "foo.html.twig");
}
示例6: testGetTemplateAnnotationFiles
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
public void testGetTemplateAnnotationFiles() {
PhpDocTag phpPsiFromText = PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpDocTag.class, "/** @Template(\"foo.html.twig\") */");
assertEquals("foo.html.twig", TwigUtil.getTemplateAnnotationFiles(phpPsiFromText).getFirst());
phpPsiFromText = PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpDocTag.class, "/** @Template(template=\"foo.html.twig\") */");
assertEquals("foo.html.twig", TwigUtil.getTemplateAnnotationFiles(phpPsiFromText).getFirst());
phpPsiFromText = PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpDocTag.class, "/** @Template(template=\"foo\\foo.html.twig\") */");
assertEquals("foo/foo.html.twig", TwigUtil.getTemplateAnnotationFiles(phpPsiFromText).getFirst());
}
示例7: testGetPropertyValueOrDefault
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
public void testGetPropertyValueOrDefault() {
Collection<String[]> dataProvider = new ArrayList<String[]>() {{
add(new String[] {"/** @Template(\"Foobar\") */", "property", "Foobar"});
add(new String[] {"/** @Template(name=\"Foo\") */", "name", "Foo"});
add(new String[] {"/** @Template(\"Foobar\", name=\"Foo\") */", "name", "Foo"});
add(new String[] {"/** @Template(\"Foobar\", foo=\"Foo\") */", "name", "Foobar"});
add(new String[] {"/** @Template() */", "property", null});
}};
for (String[] strings : dataProvider) {
PhpDocTag phpDocTag = PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpDocTag.class, "<?php\n" + strings[0]);
assertEquals(strings[2], AnnotationUtil.getPropertyValueOrDefault(phpDocTag, strings[1]));
}
}
示例8: testGetPropertyValue
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
public void testGetPropertyValue() {
Collection<String[]> dataProvider = new ArrayList<String[]>() {{
add(new String[] {"/** @Template(\"Foobar\") */", "property", null});
add(new String[] {"/** @Template(name=\"Foo\") */", "name", "Foo"});
add(new String[] {"/** @Template(\"Foobar\", name=\"Foo\") */", "name", "Foo"});
add(new String[] {"/** @Template(\"Foobar\", foo=\"Foo\") */", "name", null});
add(new String[] {"/** @Template(\"Foobar\", foo=FOO::class) */", "foo", null});
}};
for (String[] strings : dataProvider) {
PhpDocTag phpDocTag = PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpDocTag.class, "<?php\n" + strings[0]);
assertEquals(strings[2], AnnotationUtil.getPropertyValue(phpDocTag, strings[1]));
}
}
示例9: createPhpDoubleQuotedStringPsiFromContent
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
static StringLiteralExpression createPhpDoubleQuotedStringPsiFromContent(Project project, String unescapedContent) {
String escapedContent = escapePhpDoubleQuotedStringContent(unescapedContent);
String phpStringLiteral = CHAR_DOUBLE_QUOTE + escapedContent + CHAR_DOUBLE_QUOTE;
return PhpPsiElementFactory.createPhpPsiFromText(project, StringLiteralExpression.class, phpStringLiteral);
}
示例10: createPhpSingleQuotedStringPsiFromContent
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
static StringLiteralExpression createPhpSingleQuotedStringPsiFromContent(Project project, String unescapedContent) {
String escapedContent = escapePhpSingleQuotedStringContent(unescapedContent);
String phpStringLiteral = CHAR_SINGLE_QUOTE + escapedContent + CHAR_SINGLE_QUOTE;
return PhpPsiElementFactory.createPhpPsiFromText(project, StringLiteralExpression.class, phpStringLiteral);
}
示例11: testGetFormParentOfPhpClass
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
public void testGetFormParentOfPhpClass() {
PhpClass phpClass = PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpClass.class, "<?php\n" +
"class Foo {\n" +
" public function getParent()" +
" {\n" +
" return 'bar';\n" +
" }\n" +
"}"
);
assertContainsElements(FormUtil.getFormParentOfPhpClass(phpClass), "bar");
phpClass = PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpClass.class, "<?php\n" +
"namespace My\\Bar {\n" +
" class Foo {\n" +
" public function getParent()" +
" {\n" +
" return __NAMESPACE__ . '\\Foo';\n" +
" }\n" +
" }\n" +
"}"
);
assertContainsElements(FormUtil.getFormParentOfPhpClass(phpClass), "My\\Bar\\Foo");
phpClass = PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpClass.class, "<?php\n" +
"namespace My\\Bar {\n" +
" class Bar() {}\n" +
" class Foo {\n" +
" public function getParent()" +
" {\n" +
" return Bar::class;\n" +
" }\n" +
" }\n" +
"}"
);
assertContainsElements(FormUtil.getFormParentOfPhpClass(phpClass), "My\\Bar\\Bar");
phpClass = PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpClass.class, "<?php\n" +
"namespace My\\Bar {\n" +
" class Bar() {}\n" +
" class Foo {\n" +
" public function getParent()" +
" {\n" +
" return true ? Bar::class : 'foobar';\n" +
" }\n" +
" }\n" +
"}"
);
assertContainsElements(FormUtil.getFormParentOfPhpClass(phpClass), "My\\Bar\\Bar", "foobar");
}
示例12: testGetRoutesOnControllerAction
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
/**
* @see fr.adrienbrault.idea.symfony2plugin.routing.RouteHelper#getRoutesOnControllerAction
*/
public void testGetRoutesOnControllerAction() {
myFixture.copyFileToProject("GetRoutesOnControllerAction.php");
myFixture.copyFileToProject("GetRoutesOnControllerAction.routing.xml");
myFixture.copyFileToProject("GetRoutesOnControllerAction.services.xml");
PhpClass phpClass = PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpClass.class, "<?php\n" +
"namespace FooBar\\FooBundle\\Controller\\SubFolder" +
"{\n" +
" class FooBarController\n" +
" {\n" +
" function fooAction() {}\n" +
" }\n" +
"}"
);
Method fooAction = phpClass.findMethodByName("fooAction");
assertNotNull(fooAction);
List<Route> routesOnControllerAction = RouteHelper.getRoutesOnControllerAction(fooAction);
assertNotNull(ContainerUtil.find(routesOnControllerAction, route ->
"xml_route_subfolder_backslash".equals(route.getName())
));
assertNotNull(ContainerUtil.find(routesOnControllerAction, route ->
"xml_route_subfolder_slash".equals(route.getName())
));
assertNotNull(ContainerUtil.find(routesOnControllerAction, route ->
"xml_route_subfolder_class_syntax".equals(route.getName())
));
// controller as service
Method indexAction = PhpElementsUtil.getClassMethod(getProject(), "Service\\Controller\\FooController", "indexAction");
assertNotNull(indexAction);
assertNotNull(ContainerUtil.find(RouteHelper.getRoutesOnControllerAction(indexAction), route ->
"xml_route_as_service".equals(route.getName())
));
}