Search in sources :

Example 6 with IErlExternal

use of org.erlide.engine.model.root.IErlExternal in project erlide_eclipse by erlang.

the class ModelInternalUtils method getElementWithExternalName.

private IErlExternal getElementWithExternalName(final IParent parent, final String name) throws ErlModelException {
    System.out.println(" ?? " + name);
    for (final IErlElement e : parent.getChildrenOfKind(ErlElementKind.EXTERNAL_ROOT, ErlElementKind.EXTERNAL_APP, ErlElementKind.EXTERNAL_FOLDER)) {
        final IErlExternal external = (IErlExternal) e;
        final String externalName = external.getName();
        System.out.println("   ? " + externalName);
        if (externalName.equals(name)) {
            return external;
        }
    }
    return null;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlExternal(org.erlide.engine.model.root.IErlExternal)

Example 7 with IErlExternal

use of org.erlide.engine.model.root.IErlExternal in project erlide_eclipse by erlang.

the class IErlElementTest method accept.

// void accept(IErlElementVisitor visitor, EnumSet<AcceptFlags> flags,
// IErlElement.Kind leafKind) throws ErlModelException;
@Test
public void accept() throws Exception {
    project.open(null);
    // ErlLogger.debug(project.getChildren().toString());
    module.open(null);
    final List<IErlElement> elements = Lists.newArrayList();
    final IErlElementVisitor visitor = new IErlElementVisitor() {

        @Override
        public boolean visit(final IErlElement element) throws ErlModelException {
            if (element instanceof IErlExternal) {
                // avoid digging through otp
                return false;
            }
            final String name = element.getName();
            if ("ebin".equals(name)) {
                // avoid possible beam-files
                return false;
            } else if (name.startsWith(".")) {
                // avoid eclipse internals
                return false;
            }
            elements.add(element);
            return true;
        }
    };
    final EnumSet<AcceptFlags> noneOf = EnumSet.noneOf(AcceptFlags.class);
    project.accept(visitor, noneOf, ErlElementKind.MODULE);
    final List<IErlElement> kindModuleElementsVisited = Lists.newArrayList(elements);
    elements.clear();
    project.accept(visitor, noneOf, ErlElementKind.FUNCTION);
    final List<IErlElement> kindFunctionElementsVisited = Lists.newArrayList(elements);
    elements.clear();
    project.accept(visitor, EnumSet.of(AcceptFlags.CHILDREN_FIRST), ErlElementKind.MODULE);
    final List<IErlElement> childrenFirst = Lists.newArrayList(elements);
    elements.clear();
    project.accept(visitor, EnumSet.of(AcceptFlags.LEAFS_ONLY), ErlElementKind.MODULE);
    final List<IErlElement> leafsOnly = Lists.newArrayList(elements);
    elements.clear();
    // assertEquals(4, kindModuleElementsVisited.size());
    assertEquals(project, kindModuleElementsVisited.get(0));
    // ErlLogger.debug(kindModuleElementsVisited.toString());
    assertEquals("include", kindModuleElementsVisited.get(1).getName());
    assertEquals("src", kindModuleElementsVisited.get(2).getName());
    assertEquals(module, kindModuleElementsVisited.get(3));
    assertEquals(7, kindFunctionElementsVisited.size());
    final int projectIndex = childrenFirst.indexOf(project);
    final int moduleIndex = childrenFirst.indexOf(module);
    assertTrue(moduleIndex < projectIndex);
    assertFalse(leafsOnly.contains(project));
    assertTrue(leafsOnly.contains(module));
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) AcceptFlags(org.erlide.engine.model.IErlElement.AcceptFlags) IErlExternal(org.erlide.engine.model.root.IErlExternal) IErlElementVisitor(org.erlide.engine.model.IErlElementVisitor) Test(org.junit.Test)

Example 8 with IErlExternal

use of org.erlide.engine.model.root.IErlExternal in project erlide_eclipse by erlang.

the class IErlElementTest method isStructureKnown.

// boolean isReadOnly();
// Empty method
// boolean isStructureKnown() throws ErlModelException;
@Test
public void isStructureKnown() throws Exception {
    ((ErlProject) project).setSourceDirs(project.getProperties().getSourceDirs());
    // this sets structureKnown to false
    final boolean structureKnown = project.isStructureKnown();
    project.open(null);
    final boolean structureKnown2 = project.isStructureKnown();
    final boolean structureKnown3 = module.isStructureKnown();
    module.open(null);
    final boolean structureKnown4 = module.isStructureKnown();
    final IErlElementLocator model = ErlangEngine.getInstance().getModel();
    final IErlModule otpFile = model.findModuleFromProject(project, "file.erl", null, IErlElementLocator.Scope.PROJECT_ONLY);
    final IErlExternal external = (IErlExternal) otpFile.getParent();
    final boolean structureKnown5 = external.isStructureKnown();
    final IErlModule module2 = ErlideTestUtils.createModule(project, "yy.erl", "-module(yy).\n% comment\n% same\nf(x) -> y.\n% last");
    final boolean structureKnown6 = module2.isStructureKnown();
    module2.open(null);
    final boolean structureKnown7 = module2.isStructureKnown();
    assertFalse(structureKnown);
    assertTrue(structureKnown2);
    assertFalse(structureKnown3);
    assertTrue(structureKnown4);
    assertTrue(structureKnown5);
    assertFalse(structureKnown6);
    assertTrue(structureKnown7);
}
Also used : IErlExternal(org.erlide.engine.model.root.IErlExternal) ErlProject(org.erlide.engine.internal.model.root.ErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) Test(org.junit.Test)

Example 9 with IErlExternal

use of org.erlide.engine.model.root.IErlExternal in project erlide_eclipse by erlang.

the class IErlExternalTest method isOTP.

// boolean isOTP();
@Test
public void isOTP() throws Exception {
    final List<IErlElement> externals = project.getChildrenOfKind(ErlElementKind.EXTERNAL_ROOT);
    final IErlExternal external = (IErlExternal) externals.get(0);
    external.open(null);
    assertFalse(external.isOTP());
    final IErlExternal external2 = (IErlExternal) externals.get(1);
    external2.open(null);
    assertTrue(external2.isOTP());
    final IErlExternal external3 = (IErlExternal) external.getChildren().get(0);
    assertFalse(external3.isOTP());
    final IErlExternal external4 = (IErlExternal) external2.getChildren().get(0);
    assertTrue(external4.isOTP());
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlExternal(org.erlide.engine.model.root.IErlExternal) Test(org.junit.Test)

Example 10 with IErlExternal

use of org.erlide.engine.model.root.IErlExternal in project erlide_eclipse by erlang.

the class IErlExternalTest method hasIncludes.

// boolean hasIncludes();
@Test
public void hasIncludes() throws Exception {
    final List<IErlElement> externals = project.getChildrenOfKind(ErlElementKind.EXTERNAL_ROOT);
    final IErlExternal external = (IErlExternal) externals.get(0);
    external.open(null);
    final IErlExternal externalOTP = (IErlExternal) externals.get(1);
    externalOTP.open(null);
    final IErlExternal externalDialyzer = (IErlExternal) externalOTP.getChildNamed("dialyzer");
    assertTrue(external.hasIncludes());
    assertTrue(externalOTP.hasIncludes());
    assertFalse(externalDialyzer.hasIncludes());
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlExternal(org.erlide.engine.model.root.IErlExternal) Test(org.junit.Test)

Aggregations

IErlExternal (org.erlide.engine.model.root.IErlExternal)10 IErlElement (org.erlide.engine.model.IErlElement)6 Test (org.junit.Test)4 IErlModule (org.erlide.engine.model.root.IErlModule)3 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 IParent (org.erlide.engine.model.IParent)2 IFileInfo (org.eclipse.core.filesystem.IFileInfo)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 AbstractTreeViewer (org.eclipse.jface.viewers.AbstractTreeViewer)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IFileEditorInput (org.eclipse.ui.IFileEditorInput)1 PartInitException (org.eclipse.ui.PartInitException)1 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)1 FileEditorInput (org.eclipse.ui.part.FileEditorInput)1 ErlProject (org.erlide.engine.internal.model.root.ErlProject)1