use of org.jetbrains.android.dom.converters.OnClickConverter in project android by JetBrains.
the class AndroidCreateOnClickHandlerAction method invoke.
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
final AndroidFacet facet = AndroidFacet.getInstance(file);
assert facet != null;
final XmlAttributeValue attrValue = getXmlAttributeValue(file, editor);
assert attrValue != null;
final String methodName = attrValue.getValue();
assert methodName != null;
final GenericAttributeValue domValue = DomManager.getDomManager(project).getDomElement((XmlAttribute) attrValue.getParent());
assert domValue != null;
final OnClickConverter converter = (OnClickConverter) domValue.getConverter();
final PsiClass activityBaseClass = JavaPsiFacade.getInstance(project).findClass(AndroidUtils.ACTIVITY_BASE_CLASS_NAME, facet.getModule().getModuleWithDependenciesAndLibrariesScope(false));
if (activityBaseClass == null) {
return;
}
final GlobalSearchScope scope = facet.getModule().getModuleScope(false);
final PsiClass selectedClass;
if (ApplicationManager.getApplication().isUnitTestMode()) {
final Ref<PsiClass> selClassRef = Ref.create();
ClassInheritorsSearch.search(activityBaseClass, scope, true, true, false).forEach(new Processor<PsiClass>() {
@Override
public boolean process(PsiClass psiClass) {
if (!psiClass.isInterface() && !psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
selClassRef.set(psiClass);
return false;
}
return true;
}
});
selectedClass = selClassRef.get();
} else {
final TreeClassChooser chooser = TreeClassChooserFactory.getInstance(project).createInheritanceClassChooser("Choose Activity to Create the Method", scope, activityBaseClass, null, new ClassFilter() {
@Override
public boolean isAccepted(PsiClass aClass) {
return !converter.findHandlerMethod(aClass, methodName);
}
});
chooser.showDialog();
selectedClass = chooser.getSelected();
}
if (selectedClass != null) {
addHandlerMethodAndNavigate(project, selectedClass, methodName, converter.getDefaultMethodParameterType(selectedClass));
}
}
use of org.jetbrains.android.dom.converters.OnClickConverter in project android by JetBrains.
the class AndroidCreateOnClickHandlerAction method isAvailable.
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (editor == null || !(file instanceof XmlFile)) {
return false;
}
final AndroidFacet facet = AndroidFacet.getInstance(file);
if (facet == null) {
return false;
}
final XmlAttributeValue attrValue = getXmlAttributeValue(file, editor);
if (attrValue == null) {
return false;
}
final PsiElement parent = attrValue.getParent();
if (!(parent instanceof XmlAttribute)) {
return false;
}
final GenericAttributeValue domValue = DomManager.getDomManager(project).getDomElement((XmlAttribute) parent);
if (domValue == null || !(domValue.getConverter() instanceof OnClickConverter)) {
return false;
}
final String methodName = attrValue.getValue();
return methodName != null && StringUtil.isJavaIdentifier(methodName);
}
Aggregations