use of com.jetbrains.php.lang.documentation.phpdoc.psi.tags.PhpDocPropertyTag in project yii2support by nvlad.
the class MissingPropertiesQuickFix method applyFix.
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) {
List<PhpDocPropertyTag> propertyTags = this.comment.getPropertyTags();
Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
if (editor == null)
return;
Document document = editor.getDocument();
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document);
TemplateManager templateManager = TemplateManager.getInstance(project);
Template template = templateManager.createTemplate("", "");
template.setToReformat(true);
for (VirtualProperty missingProperty : this.missingProperties) {
String propertyText = "* @property " + (missingProperty.getType() != null ? missingProperty.getType() : "") + " $" + missingProperty.getName();
if (missingProperty.getComment() != null) {
propertyText += " " + missingProperty.getComment();
}
template.addTextSegment("\n" + propertyText);
}
template.addTextSegment("\n");
int offset = comment.getLastChild().getTextOffset();
if (propertyTags.size() > 0) {
PhpDocPropertyTag phpDocPropertyTag = propertyTags.get(comment.getPropertyTags().size() - 1);
offset = phpDocPropertyTag.getTextOffset() + phpDocPropertyTag.getTextLength();
}
editor.getCaretModel().moveToOffset(offset);
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document);
templateManager.startTemplate(editor, template);
}
use of com.jetbrains.php.lang.documentation.phpdoc.psi.tags.PhpDocPropertyTag in project yii2support by nvlad.
the class PropertiesInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean isOnTheFly) {
return new PhpElementVisitor() {
@Override
public void visitElement(PsiElement element) {
if (element instanceof PhpDocComment && DatabaseUtils.HasConnections(element.getProject())) {
PhpDocComment docComment = (PhpDocComment) element;
PhpIndex index = PhpIndex.getInstance(element.getProject());
PhpClass phpClass = DatabaseUtils.getClassByClassPhpDoc(docComment);
if (phpClass != null && ClassUtils.isClassInheritsOrEqual(phpClass, ClassUtils.getClass(index, "\\yii\\db\\BaseActiveRecord"))) {
Collection<Field> fields = phpClass.getFields();
String table = DatabaseUtils.getTableByActiveRecordClass(phpClass);
ArrayList<VirtualProperty> notDeclaredColumns = DatabaseUtils.getNotDeclaredColumns(table, fields, element.getProject());
if (notDeclaredColumns.size() > 0) {
MissingPropertiesQuickFix qFix = new MissingPropertiesQuickFix(notDeclaredColumns, docComment);
String str1 = notDeclaredColumns.size() > 1 ? "properties" : "property";
problemsHolder.registerProblem(docComment, "Class " + phpClass.getFQN() + " is missing " + notDeclaredColumns.size() + " " + str1 + " that corresponds to database columns", ProblemHighlightType.WEAK_WARNING, qFix);
}
ArrayList<PhpDocPropertyTag> unusedProperties = DatabaseUtils.getUnusedProperties(table, docComment.getPropertyTags(), phpClass);
if (unusedProperties.size() > 0) {
for (PhpDocPropertyTag tag : unusedProperties) {
problemsHolder.registerProblem(tag, "Property is unused in class " + phpClass.getFQN(), ProblemHighlightType.LIKE_UNUSED_SYMBOL);
}
}
}
}
super.visitElement(element);
}
};
}
use of com.jetbrains.php.lang.documentation.phpdoc.psi.tags.PhpDocPropertyTag in project yii2support by nvlad.
the class DatabaseUtils method getUnusedProperties.
public static ArrayList<PhpDocPropertyTag> getUnusedProperties(String table, List<PhpDocPropertyTag> propertyTags, PhpClass phpClass) {
ArrayList<PhpDocPropertyTag> unusedProperties = new ArrayList<>();
ArrayList<String> columns = getColumnsByTable(table, phpClass.getProject());
for (PhpDocPropertyTag tag : propertyTags) {
PhpDocProperty property = tag.getProperty();
if (!isPropertyUsed(property, columns, phpClass))
unusedProperties.add(tag);
}
return unusedProperties;
}
Aggregations