use of com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocProperty in project yii2support by nvlad.
the class DatabaseUtils method getNotDeclaredColumns.
public static ArrayList<VirtualProperty> getNotDeclaredColumns(String table, Collection<Field> fields, Project project) {
DbPsiFacade facade = DbPsiFacade.getInstance(project);
List<DbDataSource> dataSources = facade.getDataSources();
final ArrayList<VirtualProperty> result = new ArrayList<>();
if (table == null)
return result;
for (DbDataSource source : dataSources) {
for (Object item : source.getModel().traverser().filter(DasTable.class)) {
table = ClassUtils.removeQuotes(table);
if (item instanceof DasTable && ((DasTable) item).getName().equals(table)) {
TableInfo tableInfo = new TableInfo((DasTable) item);
for (DasColumn column : tableInfo.getColumns()) {
boolean found = false;
PhpDocProperty prevProperty = null;
for (Field field : fields) {
if (field != null && field.getName().equals(column.getName())) {
found = true;
break;
}
}
if (!found) {
VirtualProperty newItem = new VirtualProperty(column.getName(), column.getDataType().typeName, column.getDataType().toString(), column.getComment(), null);
result.add(newItem);
}
}
}
}
}
return result;
}
use of com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocProperty 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;
}
use of com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocProperty in project yii2support by nvlad.
the class DatabaseUtils method buildLookup.
@NotNull
public static LookupElementBuilder buildLookup(Object field, boolean showSchema, Project project) {
String lookupString = "-";
if (field instanceof DasObject) {
lookupString = ((DasObject) field).getName();
lookupString = RemoveTablePrefix(lookupString, project);
}
if (field instanceof Field) {
lookupString = ((Field) field).getName();
}
LookupElementBuilder builder = LookupElementBuilder.create(field, lookupString);
if (field instanceof Field) {
builder = builder.withTypeText(((Field) field).getType().toString()).withIcon(((Field) field).getIcon());
}
if (field instanceof PhpDocProperty) {
builder = builder.withTypeText(((PhpDocProperty) field).getType().toString()).withIcon(((PhpDocProperty) field).getIcon());
}
if (field instanceof DasColumn) {
DasColumn column = (DasColumn) field;
builder = builder.withTypeText(column.getDataType().typeName, true);
if (column.getDbParent() != null && showSchema && column.getDbParent().getDbParent() != null) {
builder = builder.withTailText(" (" + column.getDbParent().getDbParent().getName() + "." + RemoveTablePrefix(column.getDbParent().getName(), project) + ")", true);
}
if (column instanceof DasColumn)
builder = builder.withIcon(TypePresentationService.getService().getIcon(field));
if (column instanceof DbColumnImpl)
builder = builder.withIcon(((DbColumnImpl) column).getIcon());
}
if (field instanceof DasTable) {
DasTable table = (DasTable) field;
DasObject tableSchema = table.getDbParent();
if (tableSchema != null) {
if (tableSchema instanceof DbNamespaceImpl) {
Object dataSource = tableSchema.getDbParent();
// DbDataSourceImpl dataSource = (DbDataSourceImpl) ((DbNamespaceImpl) tableSchema).getDbParent();
if (dataSource != null && dataSource instanceof DbDataSourceImpl) {
builder = builder.withTypeText(((DbDataSourceImpl) dataSource).getName(), true);
}
if (dataSource != null && dataSource instanceof DbDataSourceImpl) {
builder = builder.withTypeText(((DbDataSourceImpl) dataSource).getName(), true);
}
}
}
if (showSchema && tableSchema != null) {
builder = builder.withTailText(" (" + table.getDbParent().getName() + ")", true);
}
if (table instanceof DasTable)
builder = builder.withIcon(TypePresentationService.getService().getIcon(table));
if (table instanceof DbElement)
builder = builder.withIcon(((DbElement) table).getIcon());
builder = builder.withInsertHandler((insertionContext, lookupElement) -> {
if (Yii2SupportSettings.getInstance(project).insertWithTablePrefix) {
Document document = insertionContext.getDocument();
int insertPosition = insertionContext.getSelectionEndOffset();
document.insertString(insertPosition - lookupElement.getLookupString().length(), "{{%");
document.insertString(insertPosition + 3, "}}");
insertionContext.getEditor().getCaretModel().getCurrentCaret().moveToOffset(insertPosition + 5);
}
});
}
return builder;
}
Aggregations