本文整理汇总了Java中com.jetbrains.php.lang.psi.PhpPsiUtil类的典型用法代码示例。如果您正苦于以下问题:Java PhpPsiUtil类的具体用法?Java PhpPsiUtil怎么用?Java PhpPsiUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PhpPsiUtil类属于com.jetbrains.php.lang.psi包,在下文中一共展示了PhpPsiUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
}
示例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;
}
示例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);
}
示例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());
}
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
});
}
示例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);
}
}
};
}