use of com.jetbrains.php.lang.psi.elements.PhpClass in project yii2support by nvlad.
the class UndetectableTableInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
return new PhpElementVisitor() {
@Override
public void visitPhpClass(PhpClass clazz) {
PhpIndex index = PhpIndex.getInstance(problemsHolder.getProject());
if (DatabaseUtils.HasConnections(problemsHolder.getProject()) && ClassUtils.isClassInheritsOrEqual(clazz, ClassUtils.getClass(index, "\\yii\\db\\ActiveRecord"))) {
String table = DatabaseUtils.getTableByActiveRecordClass(clazz);
if (table == null) {
problemsHolder.registerProblem(clazz.getFirstChild(), "Can not detect database table for class " + clazz.getFQN(), ProblemHighlightType.WEAK_WARNING);
} else if (!DatabaseUtils.isTableExists(table, problemsHolder.getProject())) {
problemsHolder.registerProblem(clazz.getFirstChild(), "Table '" + table + "' not found in database connections", ProblemHighlightType.WEAK_WARNING);
}
}
super.visitPhpClass(clazz);
}
};
}
use of com.jetbrains.php.lang.psi.elements.PhpClass in project yii2support by nvlad.
the class UrlUtils method getRoutes.
public static HashMap<String, Method> getRoutes(Project project) {
Collection<PhpClass> controllers = getControllers(project);
HashMap<String, Method> routes = new HashMap<>();
for (PhpClass controller : controllers) {
if (!excludeControllers.contains(controller.getFQN()))
routes.putAll(controllerToRoutes(controller));
}
return routes;
}
use of com.jetbrains.php.lang.psi.elements.PhpClass in project yii2support by nvlad.
the class UrlUtils method getClassesByParent.
private static Collection<PhpClass> getClassesByParent(String parentFqn, Project project) {
Collection<PhpClass> subclasses = new ArrayList<>();
Collection<PhpClass> directSubclasses = PhpIndex.getInstance(project).getDirectSubclasses(parentFqn);
for (PhpClass directSubclass : directSubclasses) {
subclasses.addAll(getClassesByParent(directSubclass.getFQN(), project));
}
subclasses.addAll(directSubclasses);
return subclasses;
}
use of com.jetbrains.php.lang.psi.elements.PhpClass in project idea-php-typo3-plugin by cedricziel.
the class GeneralUtilityServiceTypeProvider method getBySignature.
@Override
public Collection<? extends PhpNamedElement> getBySignature(String expression, Set<String> visited, int depth, Project project) {
Collection<PhpNamedElement> phpNamedElementCollections = new ArrayList<>();
PhpIndex phpIndex = PhpIndex.getInstance(project);
CoreServiceParser serviceParser = new CoreServiceParser();
serviceParser.collect(project);
List<TYPO3ServiceDefinition> resolvedServices = serviceParser.resolve(project, expression);
if (resolvedServices == null || resolvedServices.isEmpty()) {
return phpNamedElementCollections;
}
resolvedServices.forEach(serviceDefinition -> {
Collection<PhpClass> classesByFQN = phpIndex.getClassesByFQN(serviceDefinition.getClassName());
phpNamedElementCollections.addAll(classesByFQN);
});
return phpNamedElementCollections;
}
use of com.jetbrains.php.lang.psi.elements.PhpClass in project idea-php-typo3-plugin by cedricziel.
the class CreateInjectorQuickFix method applyFix.
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) {
PhpDocComment docCommentElement = (PhpDocComment) element.getElement().getParent();
PsiElement owner = docCommentElement.getOwner();
if (!(owner instanceof Field)) {
return;
}
Field field = (Field) owner;
final String fieldName = field.getName();
final PhpClass containingClass = PsiTreeUtil.getParentOfType(element.getElement(), PhpClass.class);
if (containingClass == null) {
return;
}
PhpType type = field.getType();
if (type == PhpType.SCALAR) {
// Scalar type - can't inject those, heh.
return;
}
final String methodName = "inject" + StringUtils.capitalize(fieldName);
Method injectorFunction = PhpPsiElementFactory.createMethod(project, "public function " + methodName + " (" + type + " $" + fieldName + ") {" + " $this->" + fieldName + " = $" + fieldName + ";" + "}");
final Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, element.getContainingFile().getVirtualFile()), true);
if (editor == null) {
return;
}
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
final int insertPos = CodeUtil.getMethodInsertPosition(containingClass, methodName);
if (insertPos == -1) {
return;
}
new WriteCommandAction(project) {
@Override
protected void run(@NotNull Result result) throws Throwable {
StringBuffer textBuf = new StringBuffer();
textBuf.append("\n");
textBuf.append(injectorFunction.getText());
editor.getDocument().insertString(insertPos, textBuf);
final int endPos = insertPos + textBuf.length();
CodeStyleManager.getInstance(project).reformatText(containingClass.getContainingFile(), insertPos, endPos);
PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
Method insertedMethod = containingClass.findMethodByName(methodName);
if (insertedMethod != null) {
editor.getCaretModel().moveToOffset(insertedMethod.getTextRange().getStartOffset());
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
element.getElement().delete();
}
}
@Override
public String getGroupID() {
return "Create Injection Method";
}
}.execute();
}
Aggregations