use of com.jetbrains.php.PhpIndex in project yii2support by nvlad.
the class ClassUtils method getPhpClassUniversal.
@Nullable
public static PhpClass getPhpClassUniversal(Project project, PhpPsiElement value) {
if (value instanceof MethodReference && (value.getName().equals("className") || value.getName().equals("tableName"))) {
MethodReference methodRef = (MethodReference) value;
return getPhpClass(methodRef.getClassReference());
}
if (value instanceof ClassConstantReference || value instanceof ConstantReference) {
return getPhpClass(value);
}
if (value instanceof StringLiteralExpression) {
StringLiteralExpression str = (StringLiteralExpression) value;
PhpIndex phpIndex = PhpIndex.getInstance(project);
return getClass(phpIndex, str.getContents());
}
return null;
}
use of com.jetbrains.php.PhpIndex in project yii2support by nvlad.
the class ValidationCompletionProvider method getDefaultValidators.
private static HashMap<String, PhpPsiElement> getDefaultValidators(Project project) {
HashMap<String, PhpPsiElement> validators = new LinkedHashMap<>();
PhpIndex phpIndex = PhpIndex.getInstance(project);
Collection<PhpClass> classesByFQN = phpIndex.getClassesByFQN("\\yii\\validators\\Validator");
if (!classesByFQN.isEmpty()) {
PhpClass validatorClass = classesByFQN.iterator().next();
Field builtInValidatorsField = validatorClass.findOwnFieldByName("builtInValidators", false);
// Default validators not found
if (builtInValidatorsField == null)
return null;
ArrayCreationExpression fieldArray = (ArrayCreationExpression) builtInValidatorsField.getDefaultValue();
Iterable<ArrayHashElement> hashElements = fieldArray.getHashElements();
for (ArrayHashElement elem : hashElements) {
if (elem.getValue() instanceof ArrayCreationExpression) {
PhpClass phpClass = ObjectFactoryUtils.findClassByArray((ArrayCreationExpression) elem.getValue());
validators.put(ClassUtils.removeQuotes(elem.getKey().getText()), phpClass);
} else {
PhpClass phpClass = phpIndex.getClassesByFQN(ClassUtils.removeQuotes(elem.getValue().getText())).iterator().next();
String validatorName = ClassUtils.removeQuotes(elem.getKey().getText());
validators.put(validatorName, phpClass);
}
}
}
return validators;
}
use of com.jetbrains.php.PhpIndex 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.PhpIndex in project idea-php-typo3-plugin by cedricziel.
the class PhpElementsUtil method allExtendedClasses.
public static List<PhpClass> allExtendedClasses(PhpClass phpClass) {
List<PhpClass> classReferences = new ArrayList<>();
PhpIndex index = PhpIndex.getInstance(phpClass.getProject());
List<ClassReference> referenceElements = phpClass.getExtendsList().getReferenceElements();
for (ClassReference reference : referenceElements) {
Collection<PhpClass> classesByFQN = index.getClassesByFQN(reference.getFQN());
for (PhpClass phpClass1 : classesByFQN) {
classReferences.add(phpClass);
classReferences.addAll(allExtendedClasses(phpClass1));
}
}
return classReferences;
}
Aggregations