Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Commit

Permalink
LANG: Refactor-add a basic BundleModel
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-medeiros committed Aug 14, 2015
1 parent 9a8c199 commit 3f23825
Show file tree
Hide file tree
Showing 13 changed files with 350 additions and 20 deletions.
1 change: 1 addition & 0 deletions plugin_ide.core/META-INF/MANIFEST.MF
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Export-Package: LANG_PROJECT_ID.ide.core,
melnorme.lang.ide.core.operations, melnorme.lang.ide.core.operations,
melnorme.lang.ide.core.operations.build, melnorme.lang.ide.core.operations.build,
melnorme.lang.ide.core.project_model, melnorme.lang.ide.core.project_model,
melnorme.lang.ide.core.project_model.view,
melnorme.lang.ide.core.text, melnorme.lang.ide.core.text,
melnorme.lang.ide.core.utils, melnorme.lang.ide.core.utils,
melnorme.lang.ide.core.utils.operation, melnorme.lang.ide.core.utils.operation,
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,68 @@
/*******************************************************************************
* Copyright (c) 2015 Bruno Medeiros and other Contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Bruno Medeiros - initial API and implementation
*******************************************************************************/
package melnorme.lang.ide.core.project_model.view;

import static melnorme.utilbox.core.CoreUtil.areEqual;

import melnorme.utilbox.misc.MiscUtil;

public abstract class AbstractBundleModelElement<PARENT> implements IBundleModelElement {

protected final PARENT parent;

public AbstractBundleModelElement(PARENT parent) {
this.parent = parent;
}

@Override
public boolean equals(Object other) {
if(this == other) {
return true;
}
if(!(other instanceof IBundleModelElement)) {
return false;
}
IBundleModelElement otherElement = (IBundleModelElement) other;

if(this.getElementType() != otherElement.getElementType()) {
return false;
}
if(!areEqual(this.getElementName(), otherElement.getElementName())) {
return false;
}

return areEqual(this.getParent(), otherElement.getParent());
}

@Override
public int hashCode() {
return MiscUtil.combineHashCodes(getParent().hashCode(), getElementName().hashCode());
}

@Override
public String toString() {
return getPathString() + " #" + getClass().getSimpleName();
}
@Override
public PARENT getParent() {
return parent;
}

@Override
public boolean hasChildren() {
return false;
}
@Override
public Object[] getChildren() {
return null;
}

}
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,66 @@
/*******************************************************************************
* Copyright (c) 2015 Bruno Medeiros and other Contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Bruno Medeiros - initial API and implementation
*******************************************************************************/
package melnorme.lang.ide.core.project_model.view;


import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull;

import org.eclipse.core.resources.IProject;

import melnorme.lang.ide.core.BundleModelElementKind;

public abstract class AbstractDependenciesContainer<BUNDLEINFO> extends AbstractBundleModelElement<IProject> {

protected final BUNDLEINFO bundleInfo;
protected final IBundleModelElement[] depElements;

public AbstractDependenciesContainer(BUNDLEINFO bundleInfo, IProject project) {
super(project);
this.bundleInfo = assertNotNull(bundleInfo);
depElements = createChildren();
}

protected abstract IBundleModelElement[] createChildren();

@Override
public BundleModelElementKind getElementType() {
return BundleModelElementKind.DEP_CONTAINER;
}

public BUNDLEINFO getBundleInfo() {
return bundleInfo;
}

public IProject getProject() {
return getParent();
}

@Override
public String getElementName() {
return "{Dependencies}";
}

@Override
public String getPathString() {
return getProject().getFullPath().toPortableString() + "/" + getElementName();
}

@Override
public boolean hasChildren() {
return depElements.length > 0;
}

@Override
public IBundleModelElement[] getChildren() {
return depElements;
}

}
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright (c) 2015 Bruno Medeiros and other Contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Bruno Medeiros - initial API and implementation
*******************************************************************************/
package melnorme.lang.ide.core.project_model.view;


import melnorme.lang.ide.core.BundleModelElementKind;
import melnorme.lang.tooling.bundle.DependencyRef;

public abstract class AbstractRawDependencyElement<PARENT extends IBundleModelElement>
extends AbstractBundleModelElement<PARENT> {

protected final DependencyRef dependencyRef;

public AbstractRawDependencyElement(PARENT parent, DependencyRef dependencyRef) {
super(parent);
this.dependencyRef = dependencyRef;
}

public String getBundleName() {
return dependencyRef.bundleName;
}

@Override
public BundleModelElementKind getElementType() {
return BundleModelElementKind.DEP_REFERENCE;
}

@Override
public String getElementName() {
return getBundleName();
}

@Override
public String getPathString() {
return getParent().getPathString() + "/@" + getElementName();
}

}
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2014 Bruno Medeiros and other Contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Bruno Medeiros - initial API and implementation
*******************************************************************************/
package melnorme.lang.ide.core.project_model.view;

import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull;

import melnorme.lang.ide.core.BundleModelElementKind;

public class BundleErrorElement extends AbstractBundleModelElement<IBundleModelElement> {

public final String errorDescription;

public BundleErrorElement(IBundleModelElement parent, String errorDescription) {
super(parent);
this.errorDescription = assertNotNull(errorDescription);
}

@Override
public BundleModelElementKind getElementType() {
return BundleModelElementKind.ERROR_ELEMENT;
}

@Override
public String getElementName() {
return "<error>";
}

@Override
public String getPathString() {
return getParent().getPathString() + "/" + getElementName();
}
}
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2015 Bruno Medeiros and other Contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Bruno Medeiros - initial API and implementation
*******************************************************************************/
package melnorme.lang.ide.core.project_model.view;

import melnorme.lang.ide.core.BundleModelElementKind;
import melnorme.lang.ide.core.INavigatorElement_Actual;

public interface IBundleModelElement extends INavigatorElement_Actual {

Object getParent();

boolean hasChildren();

/** Returns the node's children. */
Object[] getChildren();

public String getElementName();

public BundleModelElementKind getElementType();

public String getPathString();

}
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2015 Bruno Medeiros and other Contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Bruno Medeiros - initial API and implementation
*******************************************************************************/
package melnorme.lang.ide.core;

import melnorme.lang.tooling.LANG_SPECIFIC;

@LANG_SPECIFIC
public enum BundleModelElementKind {
DEP_CONTAINER,
DEP_REFERENCE,

RESOLVED_DEP,
STANDARD_LIB,

ERROR_ELEMENT,

DEP_SRC_FOLDER,
}
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@


import static melnorme.utilbox.core.Assert.AssertNamespace.assertTrue; import static melnorme.utilbox.core.Assert.AssertNamespace.assertTrue;


import melnorme.lang.ide.core.INavigatorElement_Actual;
import melnorme.utilbox.collections.ArrayList2; import melnorme.utilbox.collections.ArrayList2;
import melnorme.utilbox.collections.Indexable; import melnorme.utilbox.collections.Indexable;


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,22 +12,32 @@


import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;


import melnorme.lang.ide.core.project_model.view.IBundleModelElement;

interface NavigatorElementsSwitcher_Default<RET> { interface NavigatorElementsSwitcher_Default<RET> {


default RET switchElement(Object element) { default RET switchElement(Object element) {
if(element instanceof IProject) { if(element instanceof IProject) {
return visitProject((IProject) element); return visitProject((IProject) element);
} else if(element instanceof BuildTargetsContainer) { }
else if(element instanceof BuildTargetsContainer) {
return visitBuildTargetsElement((BuildTargetsContainer) element); return visitBuildTargetsElement((BuildTargetsContainer) element);
} else if(element instanceof BuildTargetElement) { }
else if(element instanceof BuildTargetElement) {
return visitBuildTarget((BuildTargetElement) element); return visitBuildTarget((BuildTargetElement) element);
} else { }
else if(element instanceof IBundleModelElement) {
return visitBundleElement((IBundleModelElement) element);
}
else {
return visitOther(element); return visitOther(element);
} }
} }


public abstract RET visitProject(IProject project); public abstract RET visitProject(IProject project);


public abstract RET visitBundleElement(IBundleModelElement bundleElement);

public abstract RET visitBuildTargetsElement(BuildTargetsContainer buildTargetsContainer); public abstract RET visitBuildTargetsElement(BuildTargetsContainer buildTargetsContainer);


public abstract RET visitBuildTarget(BuildTargetElement buildTarget); public abstract RET visitBuildTarget(BuildTargetElement buildTarget);
Expand Down
Loading

0 comments on commit 3f23825

Please sign in to comment.