use of com.jetbrains.php.lang.psi.elements.PhpClass in project idea-php-typo3-plugin by cedricziel.
the class ExtbaseControllerActionAction method actionPerformed.
/**
* @param event Carries information on the invocation place
*/
@Override
public void actionPerformed(AnActionEvent event) {
final Project project = getEventProject(event);
if (project == null) {
this.setStatus(event, false);
return;
}
DataContext dataContext = event.getDataContext();
final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);
final PhpClass targetClass = editor == null || file == null ? null : PhpCodeEditUtil.findClassAtCaret(editor, file);
if (targetClass == null) {
JOptionPane.showMessageDialog(null, "Could not find containing class");
return;
}
String actionName = Messages.showInputDialog(project, "New action name:", "New Extbase ActionController Action", TYPO3CMSIcons.TYPO3_ICON);
if (StringUtils.isBlank(actionName)) {
return;
}
actionName = Character.toLowerCase(actionName.charAt(0)) + actionName.substring(1);
if (!actionName.endsWith("Action")) {
actionName += "Action";
}
if (!PhpNameUtil.isValidMethodName(actionName)) {
JOptionPane.showMessageDialog(null, "Invalid method name");
return;
}
write(project, targetClass, actionName);
}
use of com.jetbrains.php.lang.psi.elements.PhpClass in project idea-php-typo3-plugin by cedricziel.
the class ExtbaseControllerActionAction method update.
public void update(AnActionEvent event) {
Project project = getEventProject(event);
if (project == null) {
this.setStatus(event, false);
return;
}
if (DumbService.isDumb(project)) {
this.setStatus(event, false);
return;
}
DataContext dataContext = event.getDataContext();
final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);
final PhpClass targetClass = editor == null || file == null ? null : PhpCodeEditUtil.findClassAtCaret(editor, file);
if (targetClass == null) {
setStatus(event, false);
return;
}
if (ExtensionUtility.getExtensionDirectory(event) == null) {
this.setStatus(event, false);
return;
}
this.setStatus(event, PhpElementsUtil.hasSuperClass(targetClass, "\\TYPO3\\CMS\\Extbase\\Mvc\\Controller\\AbstractController"));
}
use of com.jetbrains.php.lang.psi.elements.PhpClass in project idea-php-typo3-plugin by cedricziel.
the class TCAUtil method findAvailableRenderTypes.
private static Set<PsiElement> findAvailableRenderTypes(Project project) {
PhpIndex phpIndex = PhpIndex.getInstance(project);
PsiFile[] extLocalConfFiles = FilenameIndex.getFilesByName(project, EXT_LOCALCONF_FILENAME, GlobalSearchScope.allScope(project));
Collection<PhpClass> nodeRegistries = phpIndex.getClassesByFQN(NODE_FACTORY_CLASS);
Set<PsiElement> elements = new HashSet<>();
for (PhpClass registry : nodeRegistries) {
Collections.addAll(elements, PsiTreeUtil.collectElements(registry, element -> PlatformPatterns.psiElement(StringLiteralExpression.class).withParent(PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY).withAncestor(3, PlatformPatterns.psiElement(PhpElementTypes.CLASS_FIELD).withName("nodeTypes"))).accepts(element)));
}
for (PsiFile file : extLocalConfFiles) {
Collections.addAll(elements, PsiTreeUtil.collectElements(file, element -> PlatformPatterns.psiElement(StringLiteralExpression.class).withParent(PlatformPatterns.psiElement(PhpElementTypes.ARRAY_VALUE).withParent(PlatformPatterns.psiElement(PhpElementTypes.HASH_ARRAY_ELEMENT).withChild(PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY).withText("'nodeName'")))).accepts(element)));
}
return elements;
}
use of com.jetbrains.php.lang.psi.elements.PhpClass in project idea-php-typo3-plugin by cedricziel.
the class RouteHelper method getTargetMethods.
@NotNull
private static PsiElement[] getTargetMethods(@NotNull Project project, @NotNull String routeName) {
List<PsiElement> result = new ArrayList<>();
List<RouteStub> values = FileBasedIndex.getInstance().getValues(RouteIndex.KEY, routeName, GlobalSearchScope.allScope(project));
PhpIndex phpIndex = PhpIndex.getInstance(project);
for (RouteStub routeStub : values) {
String fqn = routeStub.getController();
Collection<PhpClass> classesByFQN = phpIndex.getClassesByFQN(fqn);
classesByFQN.forEach(c -> {
if (c.findMethodByName(routeStub.getMethod()) != null) {
result.add(c.findMethodByName(routeStub.getMethod()));
}
});
}
return result.toArray(new PsiElement[result.size()]);
}
use of com.jetbrains.php.lang.psi.elements.PhpClass in project phpinspectionsea by kalessil.
the class ThrowRawExceptionInspector method buildVisitor.
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new BasePhpElementVisitor() {
@Override
public void visitPhpThrowExpression(@NotNull PhpThrowExpression expression) {
final PsiElement argument = expression.getArgument();
if (argument instanceof NewExpression) {
final NewExpression newExpression = (NewExpression) argument;
final ClassReference classReference = newExpression.getClassReference();
final String classFqn = classReference == null ? null : classReference.getFQN();
if (classFqn != null) {
if (classFqn.equals("\\Exception")) {
holder.registerProblem(classReference, MessagesPresentationUtil.prefixWithEa(messageRawException), new TheLocalFix());
} else if (REPORT_MISSING_ARGUMENTS && newExpression.getParameters().length == 0) {
final PsiElement resolved = OpenapiResolveUtil.resolveReference(classReference);
if (resolved instanceof PhpClass && this.isTarget((PhpClass) resolved)) {
holder.registerProblem(newExpression, MessagesPresentationUtil.prefixWithEa(messageNoArguments));
}
}
}
}
}
private boolean isTarget(@NotNull PhpClass clazz) {
final Method constructor = clazz.getConstructor();
return constructor != null && constructor.getParameters().length == 3 && clazz.findOwnFieldByName("message", false) == null;
}
};
}
Aggregations