String packageName = "";
IEditorInput editorInput = editor.textEditor.getEditorInput();
ITextSelection selection = (ITextSelection) editor.textEditor.getSelectionProvider().getSelection();
IJavaElement elem = JavaUI.getEditorInputJavaElement(editorInput);
ICompilationUnit unit = null;
if (elem instanceof ICompilationUnit) {
unit = (ICompilationUnit) elem;
try {
IPackageDeclaration[] packs = unit.getPackageDeclarations();
if (packs.length < 1) {
info("This action can only apply to controllers.");
return null;
} else {
packageName = packs[0].getElementName();
if (!packageName.startsWith("controllers")) {
info("This action can only apply to controllers.");
return null;
}
}
// get the class declaration line
IType type = unit.getType(controllerName);
ITypeHierarchy superTypes = type.newSupertypeHierarchy(null);
// String name = JapidController.class.getName(); // this will require play.jar
String name = "cn.bran.play.JapidController";
IType japidController = jProject.findType(name);
if (superTypes.contains(japidController)) {
useJapid = true;
}
else {
useJapid = false;
}
// String superclassName = type.getSuperclassName();
// if (superclassName.toLowerCase().contains("japid")) {
// useJapid = true;
// }
// current selected elem
IJavaElement[] elements= unit.codeSelect(selection.getOffset(), selection.getLength());
if (elements.length > 0) {
// TODO extract the current selection to tell if the cursor in on renderJapidXXX line
System.out.println(elements);
}