private static HashMap<String, String> getFormDefaultKeys( Project project, String formTypeName, HashMap<String, String> defaultValues, int depth) { PhpClass phpClass = FormUtil.getFormTypeToClass(project, formTypeName); if (phpClass == null) { return defaultValues; } String typeClass = phpClass.getPresentableFQN(); attachOnDefaultOptions(project, defaultValues, typeClass); // recursive search for parent form types PsiElement getParent = PhpElementsUtil.getPsiElementsBySignatureSingle( project, "#M#C\\" + phpClass.getPresentableFQN() + ".getParent"); if (getParent != null && depth < 10) { PhpReturn phpReturn = PsiTreeUtil.findChildOfType(getParent, PhpReturn.class); if (phpReturn != null) { PhpPsiElement returnValue = phpReturn.getFirstPsiChild(); if (returnValue instanceof StringLiteralExpression) { getFormDefaultKeys( project, ((StringLiteralExpression) returnValue).getContents(), defaultValues, depth++); } } } return defaultValues; }
/** finishView, buildView: $this->vars */ public static Set<String> getFormViewVars(Project project, String... formTypeNames) { Set<String> stringSet = new HashSet<String>(); ArrayList<PhpClass> phpClasses = new ArrayList<PhpClass>(); // attach core form phpclass // @TODO: add formtype itself PhpClass coreForm = FormUtil.getFormTypeToClass(project, "form"); if (coreForm != null) { phpClasses.add(coreForm); } // for extension can also provide vars for (Map.Entry<String, String> entry : FormOptionsUtil.getFormExtensionKeys(project, formTypeNames).entrySet()) { PhpClass phpClass = PhpElementsUtil.getClassInterface(project, entry.getValue()); if (phpClass != null) { phpClasses.add(phpClass); } } for (PhpClass phpClass : phpClasses) { for (String stringMethod : new String[] {"finishView", "buildView"}) { Method method = PhpElementsUtil.getClassMethod(phpClass, stringMethod); if (method != null) { // self method getMethodVars(stringSet, method); // allow parent:: // @TODO: provide global util method for (ClassReference classReference : PsiTreeUtil.collectElementsOfType(method, ClassReference.class)) { if ("parent".equals(classReference.getName())) { PsiElement methodReference = classReference.getContext(); if (methodReference instanceof MethodReference) { PsiElement parentMethod = ((MethodReference) methodReference).resolve(); if (parentMethod instanceof Method) { getMethodVars(stringSet, (Method) parentMethod); } } } } } } } return stringSet; }