当前位置: 首页>>代码示例>>Java>>正文


Java PhpPsiElementFactory类代码示例

本文整理汇总了Java中com.jetbrains.php.lang.psi.PhpPsiElementFactory的典型用法代码示例。如果您正苦于以下问题:Java PhpPsiElementFactory类的具体用法?Java PhpPsiElementFactory怎么用?Java PhpPsiElementFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PhpPsiElementFactory类属于com.jetbrains.php.lang.psi包,在下文中一共展示了PhpPsiElementFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: applyFix

import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {

    PsiElement psiElement = descriptor.getPsiElement();
    if (DumbService.isDumb(project)) {
        showIsInDumpModeMessage(project, psiElement);
        return;
    }

    if (psiElement instanceof ClassReference) {
        ClassReference classReference = (ClassReference) psiElement;
        String fqn = classReference.getFQN();
        if (fqn != null) {
            String replacementFQN = LegacyClassesForIDEIndex.findReplacementClass(project, fqn);
            if (replacementFQN != null) {
                try {
                    classReference.replace(PhpPsiElementFactory.createClassReference(project, replacementFQN));
                } catch (IncorrectOperationException e) {
                    showErrorMessage(project, "Could not replace class reference", psiElement);
                }
            }
        }
    }
}
 
开发者ID:cedricziel,项目名称:idea-php-typo3-plugin,代码行数:25,代码来源:LegacyClassesForIdeQuickFix.java

示例2: applyFix

import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) {
    PsiElement element = problemDescriptor.getPsiElement();
    if ( ! (element instanceof PhpClass)) {
        return;
    }

    PsiFile containingFile = element.getContainingFile();
    PsiDocumentManager manager = PsiDocumentManager.getInstance(project);
    Document document = manager.getDocument(containingFile);

    PhpClass phpClass = (PhpClass) element;
    String template = "\n\n(new " + phpClass.getName() + "())->run();";
    Statement runMethodCall = PhpPsiElementFactory.createStatement(project, template);

    phpClass.getParent().addAfter(runMethodCall, phpClass);

    if (document != null) {
        manager.doPostponedOperationsAndUnblockDocument(document);
        TextRange reformatRange = runMethodCall.getTextRange();
        CodeStyleManager.getInstance(project).reformatText(containingFile, reformatRange.getStartOffset(), reformatRange.getEndOffset());
    }
}
 
开发者ID:jiripudil,项目名称:intellij-nette-tester,代码行数:24,代码来源:TestCaseIsRunInspection.java

示例3: fixMissingInheritDocForNamedElement

import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入依赖的package包/类
static void fixMissingInheritDocForNamedElement(final PhpNamedElement phpNamedElement)
{
    if (phpNamedElement.getDocComment() != null) {
        return;
    }

    // write a new docblock with inheritdoc
    new WriteCommandAction.Simple(phpNamedElement.getProject(), phpNamedElement.getContainingFile()) {
        @Override
        protected void run() throws Throwable {
            String commentString = "/**\n * {@inheritDoc} \n*/";

            PhpDocComment comment = PhpPsiElementFactory.createFromText(
                    phpNamedElement.getProject(),
                    PhpDocComment.class,
                    commentString
            );

            if (comment == null) {
                return;
            }

            PhpCodeEditUtil.insertDocCommentBeforeAndGetTextRange(phpNamedElement, comment);
        }
    }.execute();
}
 
开发者ID:thanosp,项目名称:phpstorm-inheritdoc,代码行数:27,代码来源:InheritDocUtil.java

示例4: invoke

import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入依赖的package包/类
/**
 * The intent is invoked. Do magic.
 *
 * @param project Current project.
 * @param editor  Current editor.
 * @param element Element selected by the caret.
 */
public void invoke (@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException
{
	String class_name = getUnquotedString(element.getText());

	if (class_name == null)
	{
		return;
	}

	ClassConstantReference ref = PhpPsiElementFactory.createFromText(project, ClassConstantReference.class, class_name + "::class");
	PsiElement container = element.getParent();

	if (ref != null && container instanceof StringLiteralExpression)
	{
		// Replace the string container with the class constant reference.
		container.replace(ref);
	}
}
 
开发者ID:mollie,项目名称:PhpStorm,代码行数:26,代码来源:PhpReplaceClassNameStringWithClassKeyword.java

示例5: invoke

import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile psiFile) throws IncorrectOperationException
{
    int primaryCaretOffset = editor.getCaretModel().getPrimaryCaret().getOffset();

    PsiElement currentPsiElement = psiFile.findElementAt(primaryCaretOffset);
    PsiElement statement = PsiTreeUtil.getParentOfType(currentPsiElement, Statement.class);
    if (statement == null) {
        return;
    }

    String commentStart = "/** @ContentType IDENTIFIER ";
    String commentContent = commentStart + currentPsiElement.getText() + "*/";
    PhpDocComment comment = PhpPsiElementFactory.createFromText(project, PhpDocComment.class, commentContent);
    if (comment == null) {
        return;
    }

    PsiElement result = statement.addBefore(comment, statement.getFirstChild());
    editor.getCaretModel().getPrimaryCaret().moveToOffset(result.getTextOffset() + commentStart.length() - 1);

    editor.getCaretModel().getPrimaryCaret().selectWordAtCaret(true);
}
 
开发者ID:whitefire,项目名称:eZ-completion,代码行数:24,代码来源:EzDocVariableIntention.java

示例6: build

import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入依赖的package包/类
@Override
public void build(@NotNull Project project, @NotNull Collection<FileObject> fileObjects) {
    Map<String, Route> routeMap = new HashMap<>();

    for (FileObject file : fileObjects) {

        String content;
        try {
            content = StreamUtil.readText(file.getContent().getInputStream(), "UTF-8");
        } catch (IOException e) {
            continue;
        }

        if(StringUtils.isBlank(content)) {
            continue;
        }

        routeMap.putAll(RouteHelper.getRoutesInsideUrlGeneratorFile(
            PhpPsiElementFactory.createPsiFileFromText(project, content)
        ));
    }

    this.routeMap = routeMap;
}
 
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:25,代码来源:RoutingRemoteFileStorage.java

示例7: replaceElementWithClassConstant

import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入依赖的package包/类
public static void replaceElementWithClassConstant(@NotNull PhpClass phpClass, @NotNull PsiElement originElement) throws Exception{
    String fqn = phpClass.getFQN();
    if(!fqn.startsWith("\\")) {
        fqn = "\\" + fqn;
    }

    PhpPsiElement scopeForUseOperator = PhpCodeInsightUtil.findScopeForUseOperator(originElement);
    if(scopeForUseOperator == null) {
        throw new Exception("Class fqn error");
    }

    if(!PhpCodeInsightUtil.getAliasesInScope(scopeForUseOperator).values().contains(fqn)) {
        PhpAliasImporter.insertUseStatement(fqn, scopeForUseOperator);
    }

    originElement.replace(PhpPsiElementFactory.createPhpPsiFromText(
        originElement.getProject(),
        ClassConstantReference.class,
        "<?php " + phpClass.getName() + "::class"
    ));
}
 
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:22,代码来源:PhpElementsUtil.java

示例8: testGetClassRepositoryPairForStringValue

import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入依赖的package包/类
/**
 * @see DoctrineUtil#getClassRepositoryPair
 */
public void testGetClassRepositoryPairForStringValue() {
    PsiFile psiFileFromText = PhpPsiElementFactory.createPsiFileFromText(getProject(), "" +
        "<?php\n" +
        "\n" +
        "namespace Foo;\n" +
        "\n" +
        "use Doctrine\\ORM\\Mapping as ORM;\n" +
        "\n" +
        "/**\n" +
        " * @ORM\\Entity(repositoryClass=\"MyBundle\\Entity\\Repository\\AddressRepository\")\n" +
        " */\n" +
        "class Apple {\n" +
        "}\n"
    );

    Collection<Pair<String, String>> classRepositoryPair = DoctrineUtil.getClassRepositoryPair(psiFileFromText);

    Pair<String, String> next = classRepositoryPair.iterator().next();

    assertEquals("Foo\\Apple", next.getFirst());
    assertEquals("MyBundle\\Entity\\Repository\\AddressRepository", next.getSecond());
}
 
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:26,代码来源:DoctrineUtilTest.java

示例9: testGetClassRepositoryPairForClassConstant

import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入依赖的package包/类
/**
 * @see DoctrineUtil#getClassRepositoryPair
 */
public void testGetClassRepositoryPairForClassConstant() {
    myFixture.configureByText(PhpFileType.INSTANCE, "<?php class Foobar {};");

    PsiFile psiFileFromText = PhpPsiElementFactory.createPsiFileFromText(getProject(), "<?php\n" +
        "\n" +
        "namespace Foo;\n" +
        "\n" +
        "use Doctrine\\ORM\\Mapping as ORM;\n" +
        "use Foobar;\n" +
        "\n" +
        "/**\n" +
        " * @ORM\\Entity(repositoryClass=Foobar::class)\n" +
        " */\n" +
        "class Apple {\n" +
        "}\n"
    );

    Collection<Pair<String, String>> classRepositoryPair = DoctrineUtil.getClassRepositoryPair(psiFileFromText);

    Pair<String, String> next = classRepositoryPair.iterator().next();

    assertEquals("Foo\\Apple", next.getFirst());
    assertEquals("Foobar", next.getSecond());
}
 
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:28,代码来源:DoctrineUtilTest.java

示例10: testGetFormTypeClassOnParameter

import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入依赖的package包/类
@SuppressWarnings({"ConstantConditions"})
public void testGetFormTypeClassOnParameter() {
    assertEquals("\\Form\\FormType\\Foo", FormUtil.getFormTypeClassOnParameter(
        PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpTypedElementImpl.class, "<?php new \\Form\\FormType\\Foo();")
    ).getFQN());

    assertEquals("\\Form\\FormType\\Foo", FormUtil.getFormTypeClassOnParameter(
        PhpPsiElementFactory.createPhpPsiFromText(getProject(), StringLiteralExpressionImpl.class, "<?php '\\Form\\FormType\\Foo'")
    ).getFQN());

    assertEquals("\\Form\\FormType\\Foo", FormUtil.getFormTypeClassOnParameter(
        PhpPsiElementFactory.createPhpPsiFromText(getProject(), StringLiteralExpressionImpl.class, "<?php 'Form\\FormType\\Foo'")
    ).getFQN());

    assertEquals("\\Form\\FormType\\Foo", FormUtil.getFormTypeClassOnParameter(
        PhpPsiElementFactory.createPhpPsiFromText(getProject(), ClassConstantReferenceImpl.class, "<?php Form\\FormType\\Foo::class")
    ).getFQN());
}
 
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:19,代码来源:FormUtilTest.java

示例11: 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));
}
 
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:23,代码来源:RouteHelperTest.java

示例12: testCollectMethodVariablesForVariablesReferences

import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入依赖的package包/类
/**
 * @see PhpMethodVariableResolveUtil#collectMethodVariables
 */
public void testCollectMethodVariablesForVariablesReferences() {
    Function function = PhpPsiElementFactory.createFunction(getProject(), "function foobar() {\n" +
        "$myVar = new \\MyVars\\MyVar();\n" +
        "$var['foobar'] = $myVar;\n" +
        "$var = ['foobar1' => $myVar];\n" +
        "\n" +
        "/** @var $x \\Symfony\\Component\\Templating\\EngineInterface */\n" +
        "$x->render('foo', $var);\n" +
        "\n" +
        "}"
    );

    Map<String, PsiVariable> vars = PhpMethodVariableResolveUtil.collectMethodVariables(function);

    assertContainsElements(vars.keySet(), "foobar");
    assertContainsElements(vars.keySet(), "foobar1");
}
 
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:21,代码来源:PhpMethodVariableResolveUtilTest.java

示例13: testCollectMethodVariablesForArrayCreation

import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入依赖的package包/类
/**
 * @see PhpMethodVariableResolveUtil#collectMethodVariables
 */
public void testCollectMethodVariablesForArrayCreation() {
    Function function = PhpPsiElementFactory.createFunction(getProject(), "function foobar() {\n" +
        "$myVar = new \\MyVars\\MyVar();\n" +
        "$var['foobar'] = $myVar;\n" +
        "\n" +
        "/** @var $x \\Symfony\\Component\\Templating\\EngineInterface */\n" +
        "$x->render('foo', ['foobar' => $myVar]);\n" +
        "\n" +
        "}"
    );

    Map<String, PsiVariable> vars = PhpMethodVariableResolveUtil.collectMethodVariables(function);

    assertContainsElements(vars.keySet(), "foobar");
}
 
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:19,代码来源:PhpMethodVariableResolveUtilTest.java

示例14: testCollectMethodVariablesForArrayMerge

import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入依赖的package包/类
/**
 * @see PhpMethodVariableResolveUtil#collectMethodVariables
 */
public void testCollectMethodVariablesForArrayMerge() {
    Function function = PhpPsiElementFactory.createFunction(getProject(), "function foobar() {\n" +
        "$myVar = new \\MyVars\\MyVar();\n" +
        "$var['foobar'] = $myVar;\n" +
        "\n" +
        "/** @var $x \\Symfony\\Component\\Templating\\EngineInterface */\n" +
        "$x->render('foo', array_merge($var, ['foobar1' => $myVar]));\n" +
        "\n" +
        "}"
    );

    Map<String, PsiVariable> vars = PhpMethodVariableResolveUtil.collectMethodVariables(function);

    assertContainsElements(vars.keySet(), "foobar");
    assertContainsElements(vars.keySet(), "foobar1");
}
 
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:20,代码来源:PhpMethodVariableResolveUtilTest.java

示例15: testCollectMethodVariablesForBinaryExpression

import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入依赖的package包/类
/**
 * @see PhpMethodVariableResolveUtil#collectMethodVariables
 */
public void testCollectMethodVariablesForBinaryExpression() {
    Function function = PhpPsiElementFactory.createFunction(getProject(), "function foobar() {\n" +
        "$myVar = new \\MyVars\\MyVar();\n" +
        "$var['foobar'] = $myVar;\n" +
        "\n" +
        "/** @var $x \\Symfony\\Component\\Templating\\EngineInterface */\n" +
        "$x->render('foo', $var + ['foobar1' => $myVar]);\n" +
        "\n" +
        "}"
    );

    Map<String, PsiVariable> vars = PhpMethodVariableResolveUtil.collectMethodVariables(function);

    assertContainsElements(vars.keySet(), "foobar");
    assertContainsElements(vars.keySet(), "foobar1");
}
 
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:20,代码来源:PhpMethodVariableResolveUtilTest.java


注:本文中的com.jetbrains.php.lang.psi.PhpPsiElementFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。