• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java PhpPsiUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: applyFix

import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) {
    PsiElement element = problemDescriptor.getPsiElement();
    if (element instanceof PhpFile) {
        PhpFile phpFile = (PhpFile) element;
        VirtualFile virtualFile = phpFile.getVirtualFile();
        String oldName = virtualFile.getNameWithoutExtension();
        String newName = oldName + "Test";

        PhpClass phpClass = PhpPsiUtil.findClass(phpFile, checkedClass -> checkedClass.getName().equals(oldName));
        if (phpClass != null) {
            phpClass.setName(newName);
        }

        try {
            virtualFile.rename(this, newName + "." + virtualFile.getExtension());

        } catch (IOException e) {
            LOG.error(e);
        }
    }
}
 
开发者ID:jiripudil,项目名称:intellij-nette-tester,代码行数:23,代码来源:TestFileNameInspection.java


示例2: setupConfigurationFromContext

import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入依赖的package包/类
@Override
protected boolean setupConfigurationFromContext(TesterTestMethodRunConfiguration runConfiguration, ConfigurationContext context, Ref<PsiElement> ref) {
    PsiElement element = context.getPsiLocation();
    Method method = PhpPsiUtil.getParentByCondition(element, parent -> parent instanceof Method);

    if (method != null && isValid(method)) {
        VirtualFile file = method.getContainingFile().getVirtualFile();
        ref.set(method);

        if (!FileTypeManager.getInstance().isFileOfType(file, ScratchFileType.INSTANCE)) {
            VirtualFile root = ProjectRootManager.getInstance(element.getProject()).getFileIndex().getContentRootForFile(file);
            if (root == null) {
                return false;
            }
        }

        PhpScriptRunConfiguration.Settings settings = runConfiguration.getSettings();
        settings.setPath(file.getPresentableUrl());
        runConfiguration.setMethod(method);
        runConfiguration.setName(runConfiguration.suggestedName());
        return true;
    }

    return false;
}
 
开发者ID:jiripudil,项目名称:intellij-nette-tester,代码行数:26,代码来源:TesterTestMethodRunConfigurationProducer.java


示例3: isConfigurationFromContext

import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入依赖的package包/类
@Override
public boolean isConfigurationFromContext(TesterTestMethodRunConfiguration runConfiguration, ConfigurationContext context) {
    PsiElement element = context.getPsiLocation();
    Method method = PhpPsiUtil.getParentByCondition(element, parent -> parent instanceof Method);

    if (method != null && isValid(method)) {
        VirtualFile containingVirtualFile = method.getContainingFile().getVirtualFile();
        PhpScriptRunConfiguration.Settings settings = runConfiguration.getSettings();
        String path = settings.getPath();

        if (path != null) {
            VirtualFile configurationFile = LocalFileSystem.getInstance().findFileByPath(path);
            if (configurationFile != null) {
                return StringUtil.equals(containingVirtualFile.getPath(), configurationFile.getPath())
                    && runConfiguration.isMethod(method);
            }
        }
    }

    return false;
}
 
开发者ID:jiripudil,项目名称:intellij-nette-tester,代码行数:22,代码来源:TesterTestMethodRunConfigurationProducer.java


示例4: setupConfigurationFromContext

import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入依赖的package包/类
@Override
protected boolean setupConfigurationFromContext(TesterRunConfiguration runConfiguration, ConfigurationContext configurationContext, Ref<PsiElement> ref) {
    PsiElement location = configurationContext.getPsiLocation();
    if (location instanceof PsiDirectory) {
        PsiDirectory directory = (PsiDirectory) location;
        runConfiguration.getSettings().setTestScope(directory.getVirtualFile().getPresentableUrl());
        runConfiguration.setGeneratedName(runConfiguration.suggestedName());
        ref.set(directory);
        return true;
    }

    if (location instanceof PhpFile) {
        PhpFile phpFile = (PhpFile) location;
        PhpClass testClass = PhpPsiUtil.findClass(phpFile, TesterUtil::isTestClass);
        if (testClass == null) {
            return false;
        }

        runConfiguration.getSettings().setTestScope(phpFile.getVirtualFile().getPresentableUrl());
        runConfiguration.setGeneratedName(runConfiguration.suggestedName());
        ref.set(phpFile);
        return true;
    }

    return false;
}
 
开发者ID:jiripudil,项目名称:intellij-nette-tester,代码行数:27,代码来源:TesterRunConfigurationProducer.java


示例5: invoke

import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement psiElement) throws IncorrectOperationException {
    PhpClass phpClass = PhpPsiUtil.getParentByCondition(psiElement, PhpClass.INSTANCEOF);

    if (phpClass == null) {
        return;
    }

    CommandProcessor.getInstance().executeCommand(project, () -> {
        ApplicationManager.getApplication().runWriteAction(() -> {
            ModelFactory modelFactory = new ModelFactory();
            ClassTypeMatcherInterface classTypeMatcher = modelFactory.createClassTypeMatcher();
            String projectName = classTypeMatcher.matchProjectName(phpClass.getFQN());
            SprykerPluginConfig.getInstance(project, projectName);
            UpdateDocBlockCommand command = modelFactory.createUpdateDocBlockCommand(project, projectName);
            try {
                command.updateDocBlock(phpClass, project);
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        });
    }, "Add Spryker DocBlock", null);

}
 
开发者ID:project-a,项目名称:idea-php-spryker-plugin,代码行数:25,代码来源:SprykerUpdateClassDocBlockIntention.java


示例6: addExtendsClasses

import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入依赖的package包/类
/**
 *
 * We support "extends" on module metadata
 *
 * TODO: use index, this in a performance issue
 */
private void addExtendsClasses(Project project, String parameter, Collection<PhpClass> phpClasses) {

    for (Map.Entry<String, Set<VirtualFile>> entry : ModuleUtil.getExtendsList(project).entrySet()) {

        // ignore cases, so we need an each
        if(!entry.getKey().equalsIgnoreCase(parameter)) {
            continue;
        }

        for (VirtualFile virtualFile : entry.getValue()) {

            PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
            if (!(file instanceof PhpFile)) {
                continue;
            }

            Collection<PhpClass> allClasses = PhpPsiUtil.findAllClasses((PhpFile) file);
            if (allClasses.size() > 0) {
                phpClasses.add(allClasses.iterator().next());
            }

        }
    }
}
 
开发者ID:Haehnchen,项目名称:idea-php-oxid-plugin,代码行数:31,代码来源:OxidFactoryTypeProvider.java


示例7: getArrayValuesAsMap

import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入依赖的package包/类
/**
 * Get array string values mapped with their PsiElements
 *
 * ["value", "value2"]
 */
@NotNull
static public Map<String, PsiElement> getArrayValuesAsMap(@NotNull ArrayCreationExpression arrayCreationExpression) {

    List<PsiElement> arrayValues = PhpPsiUtil.getChildren(arrayCreationExpression, new Condition<PsiElement>() {
        @Override
        public boolean value(PsiElement psiElement) {
            return psiElement.getNode().getElementType() == PhpElementTypes.ARRAY_VALUE;
        }
    });

    Map<String, PsiElement> keys = new HashMap<String, PsiElement>();
    for (PsiElement child : arrayValues) {
        String stringValue = PhpElementsUtil.getStringValue(child.getFirstChild());
        if(stringValue != null && StringUtils.isNotBlank(stringValue)) {
            keys.put(stringValue, child);
        }
    }

    return keys;
}
 
开发者ID:Haehnchen,项目名称:idea-php-laravel-plugin,代码行数:26,代码来源:PhpElementsUtil.java


示例8: getQualifiedName

import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入依赖的package包/类
/**
 * Get class path on "use" path statement
 */
@Nullable
public static String getQualifiedName(@NotNull PsiElement psiElement, @NotNull String fqn) {

    PhpPsiElement scopeForUseOperator = PhpCodeInsightUtil.findScopeForUseOperator(psiElement);
    if (scopeForUseOperator == null) {
        return null;
    }

    PhpReference reference = PhpPsiUtil.getParentByCondition(psiElement, false, PhpReference.INSTANCEOF);
    String qualifiedName = PhpCodeInsightUtil.createQualifiedName(scopeForUseOperator, fqn, reference, false);
    if (!PhpLangUtil.isFqn(qualifiedName)) {
        return qualifiedName;
    }

    // @TODO: remove full fqn fallback
    if(qualifiedName.startsWith("\\")) {
        qualifiedName = qualifiedName.substring(1);
    }

    return qualifiedName;
}
 
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:25,代码来源:AnnotationBackportUtil.java


示例9: getArrayValuesAsMap

import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入依赖的package包/类
/**
 * Get array string values mapped with their PsiElements
 *
 * ["value", "value2"]
 */
@NotNull
static public Map<String, PsiElement> getArrayValuesAsMap(@NotNull ArrayCreationExpression arrayCreationExpression) {
    Collection<PsiElement> arrayValues = PhpPsiUtil.getChildren(arrayCreationExpression, psiElement ->
        psiElement.getNode().getElementType() == PhpElementTypes.ARRAY_VALUE
    );

    Map<String, PsiElement> keys = new HashMap<>();
    for (PsiElement child : arrayValues) {
        String stringValue = PhpElementsUtil.getStringValue(child.getFirstChild());
        if(stringValue != null && StringUtils.isNotBlank(stringValue)) {
            keys.put(stringValue, child);
        }
    }

    return keys;
}
 
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:22,代码来源:PhpElementsUtil.java


示例10: isAvailable

import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement psiElement) {
    if(!Symfony2ProjectComponent.isEnabled(project)) {
        return false;
    }

    PsiElement parentByCondition = PhpPsiUtil.getParentByCondition(psiElement, Method.INSTANCEOF);
    if(parentByCondition == null) {
        return false;
    }

    PhpClass phpClass = PhpPsiUtil.getParentByCondition(psiElement, PhpClass.INSTANCEOF);
    if(phpClass == null) {
        return false;
    }

    return true;
}
 
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:19,代码来源:PhpServiceIntention.java


示例11: getBundleClassInDirectory

import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入依赖的package包/类
@Nullable
public static PhpClass getBundleClassInDirectory(@NotNull PsiDirectory bundleDirContext) {

    for (PsiFile psiFile : bundleDirContext.getFiles()) {

        if(!(psiFile instanceof PhpFile)) {
            continue;
        }

        PhpClass aClass = PhpPsiUtil.findClass((PhpFile) psiFile, phpClass ->
            PhpElementsUtil.isInstanceOf(phpClass, "\\Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface")
        );

        if(aClass != null) {
            return aClass;
        }

    }

    return null;
}
 
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:22,代码来源:BundleClassGeneratorUtil.java


示例12: isReferenceTo

import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入依赖的package包/类
/**
 * Attach element identify name to class of "use" usage
 *
 * @param psiElement PhpClass used in "use" statement
 */
@Override
public boolean isReferenceTo(PsiElement psiElement) {
    if(!(psiElement instanceof PhpNamedElement)) {
        return false;
    }

    String text = getElement().getText();
    if(StringUtils.isBlank(text)) {
        return false;
    }

    PsiElement namespace = element.getPrevSibling();
    if(PhpPsiUtil.isOfType(namespace, PhpDocTokenTypes.DOC_NAMESPACE)) {
        // @TODO: namespace not supported
        return false;
    }

    String classByContext = PhpElementsUtil.getFqnForClassNameByContext(element, text);
    if(classByContext != null) {
        return StringUtils.stripStart(((PhpNamedElement) psiElement).getFQN(), "\\")
            .equalsIgnoreCase(StringUtils.stripStart(fqn, "\\"));
    }

    return false;
}
 
开发者ID:Haehnchen,项目名称:idea-php-annotation-plugin,代码行数:31,代码来源:DocTagNameAnnotationReferenceContributor.java


示例13: invoke

import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement psiElement) throws IncorrectOperationException {
    PhpClass phpClass = PhpPsiUtil.getParentByCondition(psiElement, PhpClass.INSTANCEOF);

    if (phpClass == null || editor == null) {
        return;
    }

    GenerateFactoryInterfaceDialog.create(editor.getComponent(), project, psiElement.getContainingFile(), phpClass, editor);
}
 
开发者ID:jiripudil,项目名称:intellij-nette-factory-generator,代码行数:11,代码来源:GenerateFactoryInterfaceIntention.java


示例14: inspectionFinished

import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入依赖的package包/类
@Override
public void inspectionFinished(@NotNull LocalInspectionToolSession session, @NotNull ProblemsHolder problemsHolder) {
    if ( ! (session.getFile() instanceof PhpFile)) {
        return;
    }

    runMap.forEach((PhpType type, Boolean isRun) -> {
        if ( ! isRun) {
            PhpClass phpClass = PhpPsiUtil.findClass((PhpFile) session.getFile(), (PhpClass foundClass) -> foundClass.getType().equals(type));
            if (phpClass != null && TesterUtil.isTestClass(phpClass)) {
                problemsHolder.registerProblem(phpClass, TesterBundle.message("inspections.runTestCase.description"), ADD_RUN_METHOD_CALL_QUICK_FIX, ! phpClass.isFinal() ? MAKE_ABSTRACT_QUICK_FIX : null);
            }
        }
    });
}
 
开发者ID:jiripudil,项目名称:intellij-nette-tester,代码行数:16,代码来源:TestCaseIsRunInspection.java


示例15: buildVisitor

import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
    return new PhpElementVisitor() {
        @Override
        public void visitPhpFile(PhpFile phpFile) {
            PhpClass testClass = PhpPsiUtil.findClass(phpFile, TesterUtil::isTestClass);
            if (testClass != null && ! hasValidName(phpFile.getVirtualFile())) {
                holder.registerProblem(phpFile, TesterBundle.message("inspections.fileName.description"), CHANGE_EXTENSION_TO_PHPT_QUICK_FIX, ADD_TEST_SUFFIX_QUICK_FIX);
            }
        }
    };
}
 
开发者ID:jiripudil,项目名称:intellij-nette-tester,代码行数:14,代码来源:TestFileNameInspection.java


示例16: findClass

import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入依赖的package包/类
@Nullable
static PhpClass findClass(PsiFile psiFile) {
    if (psiFile instanceof PhpFile) {
        PhpClass phpClass = PhpPsiUtil.findClass((PhpFile) psiFile, Conditions.alwaysTrue());
        if (phpClass != null && !TesterUtil.isTestClass(phpClass)) {
            return phpClass;
        }
    }

    return null;
}
 
开发者ID:jiripudil,项目名称:intellij-nette-tester,代码行数:12,代码来源:TesterTestCreator.java


示例17: addCompletions

import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入依赖的package包/类
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result)
{
	parameters.getPosition();
	PsiElement el = parameters.getPosition();
	PhpClass cls = PhpPsiUtil.getParentByCondition(el, PhpClass.INSTANCEOF);
	if (cls == null) {
		return;
	}

	PhpIndex phpIndex = PhpIndex.getInstance(el.getProject());
	if (!OrmUtils.OrmClass.ENTITY.is(cls, phpIndex)) {
		return;
	}
	for (Field field : cls.getFields()) {
		if (!(field instanceof PhpDocProperty) || !field.getParent().getFirstChild().getText().equals("@property-read")) {
			continue;
		}
		LookupElementBuilder element = LookupElementBuilder.create(field.getName())
			.withInsertHandler(new InsertHandler<LookupElement>()
			{
				@Override
				public void handleInsert(InsertionContext insertionContext, LookupElement lookupElement)
				{
					String phpCode = "$this->setReadOnlyValue('" + lookupElement.getLookupString() + "', );";
					Document document = insertionContext.getDocument();
					document.replaceString(insertionContext.getStartOffset(), insertionContext.getTailOffset(), phpCode);
					PsiDocumentManager.getInstance(insertionContext.getProject()).commitDocument(document);
					insertionContext.getEditor().getCaretModel().moveToOffset(insertionContext.getStartOffset() + phpCode.length() - 2);
				}
			})
			.withTypeText(field.getType().toString())
			.withIcon(PhpIcons.VARIABLE_WRITE_ACCESS)
			.withPresentableText(field.getName() + " = ...");
		result.addElement(element);
	}
}
 
开发者ID:nextras,项目名称:orm-intellij,代码行数:38,代码来源:SetReadOnlyValueCompletionProvider.java


示例18: getTagAttributeValueByName

import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入依赖的package包/类
/**
 * {tag attribute="foobar"}{/s}
 */
@Nullable
public static String getTagAttributeValueByName(@NotNull SmartyTag tag, @NotNull String attribute) {
    PsiElement psiAttribute = getTagAttributeByName(tag, attribute);
    if(psiAttribute == null) {
        return null;
    }

    PsiElement nextSibling = PhpPsiUtil.getNextSibling(psiAttribute, (Condition<PsiElement>) psiElement -> {
        IElementType elementType = psiElement.getNode().getElementType();

        return psiElement instanceof PsiWhiteSpace ||
            elementType == SmartyTokenTypes.EQ ||
            elementType == SmartyTokenTypes.DOUBLE_QUOTE ||
            elementType == SmartyTokenTypes.SINGLE_QUOTE;
    });

    if(nextSibling == null) {
        return null;
    }

    String text = nextSibling.getText();
    if(StringUtils.isNotBlank(text)) {
        return text;
    }

    return null;
}
 
开发者ID:Haehnchen,项目名称:idea-php-shopware-plugin,代码行数:31,代码来源:TemplateUtil.java


示例19: invoke

import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement psiElement) throws IncorrectOperationException {

    PsiElement parentByCondition = PhpPsiUtil.getParentByCondition(psiElement, Method.INSTANCEOF);
    if(parentByCondition == null) {
        return;
    }

    PhpClass phpClass = PhpPsiUtil.getParentByCondition(psiElement, PhpClass.INSTANCEOF);
    if(phpClass == null) {
        return;
    }

    ServiceGenerateAction.invokeServiceGenerator(project, phpClass.getContainingFile(), phpClass, editor);
}
 
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:16,代码来源:PhpServiceIntention.java


示例20: isAvailable

import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement psiElement) {
    PhpClass phpClass = PhpPsiUtil.getParentByCondition(psiElement, PhpClass.INSTANCEOF);
    return phpClass != null && !phpClass.isInternal() && !phpClass.isInterface() && !phpClass.isTrait() && !phpClass.isAbstract() && !phpClass.isAnonymous();
}
 
开发者ID:jiripudil,项目名称:intellij-nette-factory-generator,代码行数:6,代码来源:GenerateFactoryInterfaceIntention.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MaterialSimpleListItem类代码示例发布时间:2022-05-22
下一篇:
Java LinuxResourceCalculatorPlugin类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap