use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.
the class JDTJavaSourcePersistenceKit method doReadModel.
@Override
protected IEntity doReadModel(IPersistenceProvider pp) throws Exception {
String fileStr = StringUtils.readAsString(pp.getInputStream(), pp.getEncoding());
IBindingManager bm = pp.getBindings();
ASTNode ast = null;
// TODO remove when parse/unparse are added
if (bm.wIsSet("parseFragments") && bm.wBooleanValue("parseFragments")) {
IJavaEntity entity = JDTTransformerVisitor.transform(fileStr, JDTUtils.parse(fileStr));
if (Matcher.matchImpl(JavaEntityDescriptorEnum.ClassDeclaration, entity))
bm.wDef("syntheticRoot", ((ClassDeclaration) entity).getBodyDeclarations());
else if (Matcher.matchImpl(JavaEntityDescriptorEnum.Block, entity))
bm.wDef("syntheticRoot", entity);
return entity;
} else {
if (bm.wIsSet("entityURI")) {
String entityURI = bm.wStringValue("entityURI");
if (ResourceUtils.hasFragmentPart(entityURI)) {
EntityDescriptor<?> ed = CommonsDataTypePersistenceParser.getEntityDescriptor(entityURI, true, bm);
if (ed.isLanguageSubtypeOf(JavaEntityDescriptorEnum.Expression)) {
ast = JDTUtils.parseAs(fileStr, JAVA_FRAGMENT.EXPRESSION);
} else if (ed.equals(JavaEntityDescriptorEnum.Block)) {
ast = JDTUtils.parseAs(fileStr, JAVA_FRAGMENT.STATEMENTS);
} else if (ed.isLanguageSubtypeOf(JavaEntityDescriptorEnum.Statement)) {
ast = JDTUtils.parseAs(fileStr, JAVA_FRAGMENT.STATEMENTS);
} else if (ed.isLanguageSubtypeOf(JavaEntityDescriptorEnum.BodyDeclaration)) {
ast = JDTUtils.parseAs(fileStr, JAVA_FRAGMENT.CLASS_BODY_DECLARATIONS);
} else if (ed.equals(JavaEntityDescriptorEnum.BodyDeclarations)) {
ast = JDTUtils.parseAs(fileStr, JAVA_FRAGMENT.CLASS_BODY_DECLARATIONS);
} else if (ed.equals(JavaEntityDescriptorEnum.CompilationUnit))
ast = JDTUtils.parseAsCompilationUnit(fileStr);
}
}
if (ast == null)
ast = JDTUtils.parse(fileStr);
IEntity result = JDTTransformerVisitor.transform(fileStr, ast);
if (bm.wIsSet("entityURI")) {
String entityURI = bm.wStringValue("entityURI");
if (ResourceUtils.hasFragmentPart(entityURI)) {
EntityDescriptor<?> ed = CommonsDataTypePersistenceParser.getEntityDescriptor(entityURI, true, bm);
if (ed.isLanguageSubtypeOf(JavaEntityDescriptorEnum.Expression)) {
if (!result.wGetEntityDescriptor().isLanguageSubtypeOf(ed))
throw new IllegalArgumentException("");
} else if (!ed.equals(JavaEntityDescriptorEnum.Block) && ed.isLanguageSubtypeOf(JavaEntityDescriptorEnum.Statement)) {
if (result.wSize() != 1 || !(result = result.wGet(0)).wGetEntityDescriptor().isLanguageSubtypeOf(ed))
throw new IllegalArgumentException("");
} else if (ed.isLanguageSubtypeOf(JavaEntityDescriptorEnum.BodyDeclaration)) {
if (result.wSize() != 1 || !(result = result.wGet(0)).wGetEntityDescriptor().isLanguageSubtypeOf(ed))
throw new IllegalArgumentException("");
}
} else if (result.wGetEntityDescriptor().equals(JavaEntityDescriptorEnum.Block) && result.wSize() == 1)
result = result.wGet(0);
}
return result;
}
}
use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.
the class MergeResourcesAction method performWorkspaceResourceSelection.
protected IEntity performWorkspaceResourceSelection(Shell shell, IEntity entity) {
IResource input;
if (Matcher.matchImpl(ArtifactsEntityDescriptorEnum.Workspace, entity.wGetParent()))
input = ResourcesPlugin.getWorkspace().getRoot();
else {
IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
ArtifactsWorkspaceUtils.bindPath(entity.wGetParent(), bm, false);
input = (IResource) (bm.wIsSet("folder") ? bm.wGetValue("folder") : bm.wGetValue("project"));
}
IJavaElement javaInput = JavaCore.create(input);
LabelProvider labelProvider = javaInput != null ? new JavaElementLabelProvider() : new WorkbenchLabelProvider();
ITreeContentProvider contentProvider = javaInput != null ? new StandardJavaElementContentProvider() : new WorkbenchContentProvider();
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, labelProvider, contentProvider);
dialog.setInput(javaInput != null ? javaInput : input);
dialog.setTitle(SELECT_RESOURCE_MSG);
dialog.setMessage("Choose a resource");
if (javaInput != null)
dialog.addFilter(new ViewerFilter() {
public boolean select(Viewer viewer, Object parentElement, Object element) {
try {
return !(element instanceof IPackageFragmentRoot) || ((IPackageFragmentRoot) element).getKind() == IPackageFragmentRoot.K_SOURCE;
} catch (Exception e) {
return false;
}
}
});
if (dialog.open() != IDialogConstants.OK_ID)
return NullEntity.instance;
IEntity result = null;
for (Object resource : dialog.getResult()) {
IEntity artifactsPath;
if (resource instanceof IJavaElement) {
IJavaElement toJavaElement = (IJavaElement) resource;
artifactsPath = ArtifactsWorkspaceUtils.toArtifactsPath(javaInput, toJavaElement);
} else {
IResource toResource = (IResource) resource;
IJavaElement parentJavaElement = JavaCore.create(toResource.getParent());
if (javaInput == null || parentJavaElement == null)
artifactsPath = ArtifactsWorkspaceUtils.toArtifactsPath(input, toResource);
else
artifactsPath = ArtifactsWorkspaceUtils.toArtifactsPath(javaInput, toResource);
}
result = result == null ? artifactsPath : EntityUtils.merge(result, artifactsPath, createEntityComparator(), false);
}
int index = Matcher.match(ArtifactsEntityDescriptorEnum.Workspace, result) ? result.wIndexOf(ArtifactsFeatureDescriptorEnum.projects) : result.wIndexOf(ArtifactsFeatureDescriptorEnum.artifacts);
IEntity tree = result.wGet(index);
result.wRemove(index);
return tree;
}
use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.
the class ReplaceWithClassNameAction method update.
@Override
public void update() {
ESelectionService selectionService = getContext().get(ESelectionService.class);
if (selectionService.getSelection() instanceof IBindingManager) {
IBindingManager bm = (IBindingManager) selectionService.getSelection();
IJavaProject javaProject = (IJavaProject) bm.wGetValue("javaProject");
setEnabled(javaProject != null && HandlersBehavior.isValidFocusEntityPart(bm));
} else
setEnabled(false);
}
use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.
the class ReplaceWithResourceAction method run.
@Override
public void run() {
ESelectionService selectionService = getContext().get(ESelectionService.class);
IBindingManager bm = (IBindingManager) selectionService.getSelection();
IEntity focusEntity = bm.wGet("focusEntity");
ResourceKind resourceKind = getResourceKind(focusEntity);
Shell shell = (Shell) getContext().get(IServiceConstants.ACTIVE_SHELL);
boolean selectionPerformed = false;
switch(resourceKind) {
case WORKSPACE:
selectionPerformed = performWorkspaceResourceSelection(shell, focusEntity);
break;
case CLASSPATH:
selectionPerformed = performClasspathResourceSelection(shell, focusEntity);
break;
case FILE_SYSTEM:
case URL:
selectionPerformed = performFilesystemSelection(shell, focusEntity, resourceKind == ResourceKind.URL);
break;
}
if (!selectionPerformed)
return;
IEntity replacement = GenericEntityFactory.instance.create(ed, path);
ModelTransactionCommand mtc = new ModelTransactionCommand(focusEntity);
try {
mtc.setLabel("replace with class name");
mtc.begin();
performReplace(focusEntity, replacement);
mtc.commit();
if (mtc.canUndo()) {
IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
CommandStack commandStack = viewer.getEditDomain().getCommandStack();
commandStack.execute(mtc);
}
} catch (RuntimeException e) {
mtc.rollbackIfNeeded();
throw e;
}
}
use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.
the class PojoJavaModelGeneratorVisitor method visit.
public void visit(Library entity) {
IBindingManager bm = getBindings();
bm.wEnterScope();
ArtifactsGeneratorOperation.generate(entity, bm);
bm.wExitScope();
}
Aggregations