Example usage for org.eclipse.jdt.core IParent hasChildren

List of usage examples for org.eclipse.jdt.core IParent hasChildren

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IParent hasChildren.

Prototype

boolean hasChildren() throws JavaModelException;

Source Link

Document

Returns whether this element has one or more immediate children.

Usage

From source file:edu.brown.cs.bubbles.bedrock.BedrockEditor.java

License:Open Source License

private IJavaElement findElementForKey(IJavaElement elt, String key) {
    if (key.equals(elt.getHandleIdentifier()))
        return elt;

    if (elt instanceof IParent) {
        IParent ip = (IParent) elt;
        try {//w ww .  ja  v a 2s .c  o m
            if (ip.hasChildren()) {
                for (IJavaElement je : ip.getChildren()) {
                    IJavaElement re = findElementForKey(je, key);
                    if (re != null)
                        return re;
                }
            }
        } catch (JavaModelException e) {
        }
    }

    return null;
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockEditor.java

License:Open Source License

/********************************************************************************/

// This shouldn't be needed since edits in a window should also be made in the default
// buffer and hence in the actual compilation unit that would be reported

void getActiveElements(IJavaElement root, List<IJavaElement> rslt) {
    switch (root.getElementType()) {
    case IJavaElement.ANNOTATION:
    case IJavaElement.CLASS_FILE:
    case IJavaElement.FIELD:
    case IJavaElement.IMPORT_CONTAINER:
    case IJavaElement.IMPORT_DECLARATION:
    case IJavaElement.INITIALIZER:
    case IJavaElement.JAVA_MODEL:
    case IJavaElement.LOCAL_VARIABLE:
    case IJavaElement.METHOD:
    case IJavaElement.PACKAGE_DECLARATION:
    case IJavaElement.TYPE:
    case IJavaElement.TYPE_PARAMETER:
    default://ww w  .  j ava  2  s.  c  o  m
        break;
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
        IPackageFragmentRoot pfr = (IPackageFragmentRoot) root;
        try {
            if (pfr.getKind() == IPackageFragmentRoot.K_SOURCE && pfr.hasChildren()) {
                IJavaElement[] chld = pfr.getChildren();
                for (IJavaElement c : chld)
                    getActiveElements(c, rslt);
            }
        } catch (JavaModelException e) {
        }
        break;
    case IJavaElement.JAVA_PROJECT:
    case IJavaElement.PACKAGE_FRAGMENT:
        IParent par = (IParent) root;
        try {
            if (par.hasChildren()) {
                IJavaElement[] chld = par.getChildren();
                for (IJavaElement c : chld)
                    getActiveElements(c, rslt);
            }
        } catch (JavaModelException e) {
        }
        break;
    case IJavaElement.COMPILATION_UNIT:
        ICompilationUnit cu = (ICompilationUnit) root;
        IProject ip = cu.getJavaProject().getProject();
        File f = BedrockUtil.getFileForPath(cu.getPath(), ip);
        String fnm = f.getPath();
        FileData fd = file_map.get(fnm);
        if (fd == null)
            rslt.add(cu);
        else {
            rslt.add(fd.getSearchUnit());
        }
        break;
    }
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockEditor.java

License:Open Source License

void getWorkingElements(IJavaElement root, List<ICompilationUnit> rslt) {
    switch (root.getElementType()) {
    case IJavaElement.ANNOTATION:
    case IJavaElement.CLASS_FILE:
    case IJavaElement.FIELD:
    case IJavaElement.IMPORT_CONTAINER:
    case IJavaElement.IMPORT_DECLARATION:
    case IJavaElement.INITIALIZER:
    case IJavaElement.JAVA_MODEL:
    case IJavaElement.LOCAL_VARIABLE:
    case IJavaElement.METHOD:
    case IJavaElement.PACKAGE_DECLARATION:
    case IJavaElement.TYPE:
    case IJavaElement.TYPE_PARAMETER:
    default://from   w ww.j  a v a  2 s. com
        break;
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
        IPackageFragmentRoot pfr = (IPackageFragmentRoot) root;
        try {
            if (pfr.getKind() == IPackageFragmentRoot.K_SOURCE && pfr.hasChildren()) {
                IJavaElement[] chld = pfr.getChildren();
                for (IJavaElement c : chld)
                    getWorkingElements(c, rslt);
            }
        } catch (JavaModelException e) {
        }
        break;
    case IJavaElement.JAVA_PROJECT:
    case IJavaElement.PACKAGE_FRAGMENT:
        IParent par = (IParent) root;
        try {
            if (par.hasChildren()) {
                IJavaElement[] chld = par.getChildren();
                for (IJavaElement c : chld)
                    getWorkingElements(c, rslt);
            }
        } catch (JavaModelException e) {
        }
        break;
    case IJavaElement.COMPILATION_UNIT:
        ICompilationUnit cu = (ICompilationUnit) root;
        IProject ip = cu.getJavaProject().getProject();
        File f = BedrockUtil.getFileForPath(cu.getPath(), ip);
        String fnm = f.getPath();
        FileData fd = file_map.get(fnm);
        if (fd != null) {
            rslt.add(fd.getEditableUnit(null));
        }
        break;
    }
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockEditor.java

License:Open Source License

void getCompilationElements(IJavaElement root, List<ICompilationUnit> rslt) {
    switch (root.getElementType()) {
    case IJavaElement.ANNOTATION:
    case IJavaElement.CLASS_FILE:
    case IJavaElement.FIELD:
    case IJavaElement.IMPORT_CONTAINER:
    case IJavaElement.IMPORT_DECLARATION:
    case IJavaElement.INITIALIZER:
    case IJavaElement.JAVA_MODEL:
    case IJavaElement.LOCAL_VARIABLE:
    case IJavaElement.METHOD:
    case IJavaElement.PACKAGE_DECLARATION:
    case IJavaElement.TYPE:
    case IJavaElement.TYPE_PARAMETER:
    default:/*from  www  . j a  v  a  2 s.c o  m*/
        break;
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
        IPackageFragmentRoot pfr = (IPackageFragmentRoot) root;
        try {
            if (pfr.getKind() == IPackageFragmentRoot.K_SOURCE && pfr.hasChildren()) {
                IJavaElement[] chld = pfr.getChildren();
                for (IJavaElement c : chld)
                    getCompilationElements(c, rslt);
            }
        } catch (JavaModelException e) {
        }
        break;
    case IJavaElement.JAVA_PROJECT:
    case IJavaElement.PACKAGE_FRAGMENT:
        IParent par = (IParent) root;
        try {
            if (par.hasChildren()) {
                IJavaElement[] chld = par.getChildren();
                for (IJavaElement c : chld)
                    getCompilationElements(c, rslt);
            }
        } catch (JavaModelException e) {
        }
        break;
    case IJavaElement.COMPILATION_UNIT:
        ICompilationUnit cu = (ICompilationUnit) root;
        IProject ip = cu.getJavaProject().getProject();
        File f = BedrockUtil.getFileForPath(cu.getPath(), ip);
        String fnm = f.getPath();
        FileData fd = file_map.get(fnm);
        if (fd != null) {
            rslt.add(fd.getEditableUnit(null));
        } else
            rslt.add(cu);
        break;
    }
}

From source file:edu.cmu.cs.crystal.internal.WorkspaceUtilities.java

License:Open Source License

/**
 * A recursive traversal of the IJavaModel starting from the given
 * element to collect all ICompilationUnits.
 * Each compilation unit corresponds to each java file.
 *  /*from   w ww . j  a  v a2 s.  c om*/
 * @param javaElement a node in the IJavaModel that will be traversed
 * @return a list of compilation units or <code>null</code> if no comp units are found
 */
public static List<ICompilationUnit> collectCompilationUnits(IJavaElement javaElement) {
    List<ICompilationUnit> list = null, temp = null;
    // We are traversing the JavaModel for COMPILATION_UNITs
    if (javaElement.getElementType() == IJavaElement.COMPILATION_UNIT) {
        list = new ArrayList<ICompilationUnit>();
        list.add((ICompilationUnit) javaElement);
        return list;
    }

    // Non COMPILATION_UNITs will have to be further traversed
    if (javaElement instanceof IParent) {
        IParent parent = (IParent) javaElement;

        // Do not traverse PACKAGE_FRAGMENT_ROOTs that are ReadOnly
        // this ignores libraries and .class files
        if (javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT && javaElement.isReadOnly()) {
            return null;
        }

        // Traverse
        try {
            if (parent.hasChildren()) {
                IJavaElement[] children = parent.getChildren();
                for (int i = 0; i < children.length; i++) {
                    temp = collectCompilationUnits(children[i]);
                    if (temp != null)
                        if (list == null)
                            list = temp;
                        else
                            list.addAll(temp);
                }
            }
        } catch (JavaModelException jme) {
            log.log(Level.SEVERE, "Problem traversing Java model element: " + parent, jme);
        }
    } else {
        log.warning("Encountered a model element that's not a comp unit or parent: " + javaElement);
    }

    return list;
}

From source file:org.eclipse.ocl.xtext.oclstdlib.scoping.JavaClassScope.java

License:Open Source License

private void scanJavaElements(IJavaElement[] elements, Set<String> classNames) {
    for (IJavaElement element : elements) {
        //         System.out.println(getClass().getSimpleName() + " : " + element);
        if (element instanceof IType) {
            IType iType = (IType) element;
            classNames.add(iType.getFullyQualifiedName());
            try {
                if (iType.hasChildren()) {
                    scanJavaElements(iType.getChildren(), classNames);
                }/*from  w w w . ja v  a  2  s. c o m*/
            } catch (JavaModelException e) {
            }
        } else if ((element instanceof IParent) && !(element instanceof IMember)) {
            try {
                IParent iParent = (IParent) element;
                if (iParent.hasChildren()) {
                    scanJavaElements(iParent.getChildren(), classNames);
                }
            } catch (JavaModelException e) {
            }
        }
    }
}