use of com.avast.android.butterknifezelezny.butterknife.IButterKnife in project android-butterknife-zelezny by avast.
the class InjectAction method showDialog.
protected void showDialog(Project project, Editor editor, ArrayList<Element> elements) {
PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);
if (file == null) {
return;
}
PsiClass clazz = getTargetClass(editor, file);
final IButterKnife butterKnife = ButterKnifeFactory.findButterKnifeForPsiElement(project, file);
if (clazz == null || butterKnife == null) {
return;
}
// get parent classes and check if it's an adapter
boolean createHolder = false;
PsiReferenceList list = clazz.getExtendsList();
if (list != null) {
for (PsiJavaCodeReferenceElement element : list.getReferenceElements()) {
if (Definitions.adapters.contains(element.getQualifiedName())) {
createHolder = true;
}
}
}
// get already generated injections
ArrayList<String> ids = new ArrayList<String>();
PsiField[] fields = clazz.getAllFields();
String[] annotations;
String id;
for (PsiField field : fields) {
annotations = field.getFirstChild().getText().split(" ");
for (String annotation : annotations) {
id = Utils.getInjectionID(butterKnife, annotation.trim());
if (!Utils.isEmptyString(id)) {
ids.add(id);
}
}
}
EntryList panel = new EntryList(project, editor, elements, ids, createHolder, this, this);
mDialog = new JFrame();
mDialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
mDialog.getRootPane().setDefaultButton(panel.getConfirmButton());
mDialog.getContentPane().add(panel);
mDialog.pack();
mDialog.setLocationRelativeTo(null);
mDialog.setVisible(true);
}
use of com.avast.android.butterknifezelezny.butterknife.IButterKnife in project android-butterknife-zelezny by avast.
the class InjectWriter method run.
@Override
public void run() throws Throwable {
final IButterKnife butterKnife = ButterKnifeFactory.findButterKnifeForPsiElement(mProject, mFile);
if (butterKnife == null) {
// Butterknife library is not available for project
return;
}
if (mCreateHolder) {
generateAdapter(butterKnife);
} else {
if (Utils.getInjectCount(mElements) > 0) {
generateFields(butterKnife);
}
generateInjects(butterKnife);
if (Utils.getClickCount(mElements) > 0) {
generateClick();
}
Utils.showInfoNotification(mProject, String.valueOf(Utils.getInjectCount(mElements)) + " injections and " + String.valueOf(Utils.getClickCount(mElements)) + " onClick added to " + mFile.getName());
}
// reformat class
JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(mProject);
styleManager.optimizeImports(mFile);
styleManager.shortenClassReferences(mClass);
new ReformatCodeProcessor(mProject, mClass.getContainingFile(), null, false).runWithoutProgress();
}
Aggregations