use of org.eclipse.core.internal.filebuffers.SynchronizableDocument in project jbosstools-hibernate by jbosstools.
the class JPAMapToolActor method updateSelectedItems.
/**
* @param sel - current selected workspace element for processing
*/
private synchronized void updateSelectedItems(ISelection sel) {
// System.out.println("Blah! " + selection); //$NON-NLS-1$
if (sel instanceof TextSelection) {
// $NON-NLS-1$
String fullyQualifiedName = "";
IDocument fDocument = null;
SynchronizableDocument sDocument = null;
org.eclipse.jdt.core.dom.CompilationUnit resultCU = null;
Class<?> clazz = sel.getClass();
Field fd = null;
try {
// $NON-NLS-1$
fd = clazz.getDeclaredField("fDocument");
} catch (NoSuchFieldException e) {
// just ignore it!
}
if (fd != null) {
try {
fd.setAccessible(true);
fDocument = (IDocument) fd.get(sel);
if (fDocument instanceof SynchronizableDocument) {
sDocument = (SynchronizableDocument) fDocument;
}
if (sDocument != null) {
ASTParser parser = ASTParser.newParser(AST.JLS9);
parser.setSource(sDocument.get().toCharArray());
parser.setResolveBindings(false);
resultCU = (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(null);
}
if (resultCU != null && resultCU.types().size() > 0) {
if (resultCU.getPackage() != null) {
// $NON-NLS-1$
fullyQualifiedName = resultCU.getPackage().getName().getFullyQualifiedName() + ".";
} else {
// $NON-NLS-1$
fullyQualifiedName = "";
}
Object tmp = resultCU.types().get(0);
if (tmp instanceof AbstractTypeDeclaration) {
fullyQualifiedName += ((AbstractTypeDeclaration) tmp).getName();
}
if (!(tmp instanceof TypeDeclaration)) {
// ignore EnumDeclaration & AnnotationTypeDeclaration
// $NON-NLS-1$
fullyQualifiedName = "";
}
}
} catch (IllegalArgumentException e) {
// $NON-NLS-1$
HibernateConsolePlugin.getDefault().logErrorMessage("IllegalArgumentException: ", e);
} catch (IllegalAccessException e) {
// $NON-NLS-1$
HibernateConsolePlugin.getDefault().logErrorMessage("IllegalAccessException: ", e);
} catch (SecurityException e) {
// $NON-NLS-1$
HibernateConsolePlugin.getDefault().logErrorMessage("SecurityException: ", e);
}
}
clearSelectionCU();
if (fullyQualifiedName.length() > 0) {
ICompilationUnit cu = Utils.findCompilationUnit(fullyQualifiedName);
addCompilationUnit(cu);
}
} else if (sel instanceof TreeSelection) {
clearSelectionCU();
TreeSelection treeSelection = (TreeSelection) sel;
Iterator<?> it = treeSelection.iterator();
while (it.hasNext()) {
Object obj = it.next();
processJavaElements(obj);
}
} else {
// System.out.println("2 Blah! " + selection); //$NON-NLS-1$
sel = null;
}
}
Aggregations