use of com.intellij.lang.javascript.psi.types.JSRecordTypeImpl in project oxy-template-support-plugin by mutant-industries.
the class InnerJsTypeEvaluator method getMacroFirstParameterType.
// -------------------------------------------------------------------
@NotNull
private JSType getMacroFirstParameterType(@NotNull JSProperty macro) {
assert OxyTemplateIndexUtil.isMacro(macro);
JSTypeSource typeSource = JSTypeSourceFactory.createTypeSource(myContext.targetFile, true);
List<JSRecordTypeImpl.TypeMember> members = new LinkedList<>();
for (MacroParamDescriptor paramDescriptor : MacroParamHelper.getJsMacroParamSuggestions(macro, false)) {
if (!paramDescriptor.isDocumented()) {
continue;
}
JSRecordTypeImpl.PropertySignature signature = new JSRecordTypeImpl.PropertySignatureImpl(paramDescriptor.getName(), paramDescriptor.getType(), !paramDescriptor.isRequired());
members.add(signature);
}
JSRecordTypeImpl type = new JSRecordTypeImpl(typeSource, ImmutableList.copyOf(members));
type.accept(new SimplifiedClassNameResolver(myContext.targetFile));
return type;
}
use of com.intellij.lang.javascript.psi.types.JSRecordTypeImpl in project oxy-template-support-plugin by mutant-industries.
the class GlobalVariableTypeProvider method compute.
@Nullable
@Override
public Result<JSType> compute() {
List<PsiElement> cacheDependencies = new LinkedList<>();
cacheDependencies.add(expression);
// controllers
if (CONTROLLERS_GLOBAL_VARIABLE_NAME.equals(name)) {
Project project = expression.getProject();
GlobalSearchScope allScope = ProjectScope.getAllScope(project);
GlobalSearchScope projectScope = ProjectScope.getProjectScope(project);
List<JSRecordTypeImpl.TypeMember> members = new LinkedList<>();
JSTypeSource typeSource = JSTypeSourceFactory.createTypeSource(expression, true);
PsiClass controller;
PsiClass controllerAnnotation = JavaPsiFacade.getInstance(project).findClass(CONTROLLER_FQN, allScope);
if (controllerAnnotation != null && controllerAnnotation.isAnnotationType()) {
for (PsiReference controllerAnnotationReference : ReferencesSearch.search(controllerAnnotation, projectScope).findAll()) {
PsiElement reference = controllerAnnotationReference.getElement();
if ((controller = PsiTreeUtil.getParentOfType(reference, PsiClass.class)) != null && controller.getQualifiedName() != null) {
JSTypeSource source = JSTypeSourceFactory.createTypeSource(controller, true);
JSType jsType = JSTypeUtils.createType(controller.getQualifiedName(), source);
JSRecordTypeImpl.PropertySignature signature = new JSRecordTypeImpl.PropertySignatureImpl(controller.getName(), jsType, false);
members.add(signature);
cacheDependencies.add(controller);
}
}
}
Collections.addAll(cacheDependencies, FilenameIndex.getFilesByName(project, CONTROLLERS_BEANS_FILE_NAME, ProjectScope.getProjectScope(project)));
return Result.create(new JSRecordTypeImpl(typeSource, ImmutableList.copyOf(members)), cacheDependencies);
}
PsiReturnStatement returnStatement;
PsiClass aClass;
PsiElement elementAt;
// global model provider
if ((returnStatement = PsiTreeUtil.getParentOfType(expression, PsiReturnStatement.class)) != null && (aClass = PsiTreeUtil.getParentOfType(returnStatement, PsiClass.class)) != null && InheritanceUtil.isInheritor(aClass, GLOBAL_MODEL_PROVIDER_FQN)) {
return Result.create(getTypeFromProvider(aClass), cacheDependencies);
} else // model provider registry
{
elementAt = expression;
while (elementAt != null && !((elementAt = elementAt.getNextSibling()) instanceof PsiExpression)) ;
if (elementAt instanceof PsiNewExpression) {
PsiJavaCodeReferenceElement providerClassReference = PsiTreeUtil.getNextSiblingOfType(elementAt.getFirstChild(), PsiJavaCodeReferenceElement.class);
PsiElement providerClass;
if (providerClassReference != null && (providerClass = providerClassReference.resolve()) instanceof PsiClass) {
aClass = (PsiClass) providerClass;
} else if ((aClass = PsiTreeUtil.getNextSiblingOfType(elementAt.getFirstChild(), PsiAnonymousClass.class)) == null) {
return Result.create(null, expression);
}
cacheDependencies.add(aClass);
return Result.create(getTypeFromProvider(aClass), cacheDependencies);
} else if (elementAt != null) {
PsiType type = ((PsiExpression) elementAt).getType();
if (type != null && (aClass = JavaPsiFacade.getInstance(expression.getProject()).findClass(type.getCanonicalText(), ProjectScope.getAllScope(expression.getProject()))) != null) {
return Result.create(getTypeFromProvider(aClass), cacheDependencies);
}
}
}
return Result.create(null, cacheDependencies);
}
Aggregations