use of com.jetbrains.php.lang.psi.elements.impl.ClassConstImpl in project yii2support by nvlad.
the class DatabaseUtils method getTableByActiveRecordClass.
@Nullable
public static String getTableByActiveRecordClass(PhpClass phpClass) {
Method method = phpClass.findMethodByName("tableName");
if (method != null) {
Collection<PhpReturn> returns = PsiTreeUtil.findChildrenOfType(method, PhpReturn.class);
for (PhpReturn element : returns) {
if ((element).getChildren().length > 0) {
if ((element).getChildren()[0] instanceof ClassConstantReference) {
PsiElement resolved = ((ClassConstantReference) (element).getChildren()[0]).resolve();
if (resolved != null && resolved instanceof ClassConstImpl) {
ClassConstImpl constant = (ClassConstImpl) resolved;
if (constant.getChildren().length > 0) {
String table = ((StringLiteralExpressionImpl) constant.getChildren()[0]).getContents();
return AddTablePrefix(table, false, phpClass.getProject());
}
}
} else if ((element).getChildren()[0] instanceof StringLiteralExpression) {
String table = (element).getChildren()[0].getText();
return AddTablePrefix(table, false, phpClass.getProject());
}
}
}
}
String table = StringUtils.CamelToId(phpClass.getName());
if (method != null && method.getContainingClass() != null && method.getContainingClass().getFQN().equals("\\yii\\db\\ActiveRecord")) {
table = "{{%" + table + "}}";
}
return AddTablePrefix(table, false, phpClass.getProject());
}
Aggregations