本文整理汇总了Java中com.jetbrains.php.lang.psi.PhpPsiUtil.findClass方法的典型用法代码示例。如果您正苦于以下问题:Java PhpPsiUtil.findClass方法的具体用法?Java PhpPsiUtil.findClass怎么用?Java PhpPsiUtil.findClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jetbrains.php.lang.psi.PhpPsiUtil
的用法示例。
在下文中一共展示了PhpPsiUtil.findClass方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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(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;
}
示例3: 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;
}
示例4: 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);
}
}
};
}
示例5: 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;
}
示例6: actionPerformed
import com.jetbrains.php.lang.psi.PhpPsiUtil; //导入方法依赖的package包/类
@Override
public void actionPerformed(AnActionEvent event) {
Project project = getEventProject(event);
if(project == null) {
return;
}
PsiDirectory bundleDirContext = BundleClassGeneratorUtil.getBundleDirContext(event);
if(bundleDirContext == null) {
return;
}
PsiFile data = CommonDataKeys.PSI_FILE.getData(event.getDataContext());
if(!(data instanceof PhpFile)) {
return;
}
String relativePath = VfsUtil.getRelativePath(data.getVirtualFile(), bundleDirContext.getVirtualFile());
if(relativePath == null) {
return;
}
PhpClass aClass = PhpPsiUtil.findClass((PhpFile) data, Conditions.alwaysTrue());
if(aClass == null) {
return;
}
int i = relativePath.lastIndexOf(".");
final String className = "Tests\\" + relativePath.substring(0, i).replace("/", "\\") + "Test";
final PhpClass phpClass = BundleClassGeneratorUtil.getBundleClassInDirectory(bundleDirContext);
if(phpClass == null) {
return;
}
new WriteCommandAction(project) {
@Override
protected void run(@NotNull Result result) throws Throwable {
PsiElement file = null;
try {
file = PhpBundleFileFactory.createBundleFile(phpClass, "web_test_case", className, new HashMap<>());
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error:" + e.getMessage());
}
if(file != null) {
new OpenFileDescriptor(getProject(), file.getContainingFile().getVirtualFile(), 0).navigate(true);
}
}
@Override
public String getGroupID() {
return "Create Symfony WebTestFile";
}
}.execute();
}