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

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

Introduction

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

Prototype

IJavaElement[] getChildren() throws JavaModelException;

Source Link

Document

Returns the immediate children of this element.

Usage

From source file:com.aqua.wikiwizard.WikiExportModel.java

License:Apache License

private void collectAllTypesInProject(ArrayList<IType> allTypes, IParent element) throws JavaModelException {
    IJavaElement[] elements = element.getChildren();

    for (IJavaElement je : elements) {
        // Skip the jars
        if (je.isReadOnly()) {
            continue;
        }/*from w w w.j av a 2 s. c  o m*/

        // End of the road, we found a type
        if (je instanceof IType) {
            allTypes.add((IType) je);
            continue;
        }

        // There are more, enter recursion
        if (je instanceof IParent) {
            collectAllTypesInProject(allTypes, (IParent) je);
        }
    }
}

From source file:com.github.elucash.lambda4jdt.FoldingStructureProvider.java

License:Open Source License

private void computeFoldingStructure(FoldingStructureComputationContext ctx) {
    IParent parent = (IParent) fInput;
    try {// w w w  .j av a 2  s.c o m
        if (!(fInput instanceof ISourceReference))
            return;
        String source = ((ISourceReference) fInput).getSource();
        if (source == null)
            return;

        ctx.getScanner().setSource(source.toCharArray());
        computeFoldingStructure(parent.getChildren(), ctx);
    } catch (JavaModelException x) {
    }
}

From source file:com.redhat.ceylon.eclipse.core.model.JDTModule.java

License:Open Source License

private void listPackages(Set<String> packageList, IParent parent) {
    try {//ww  w. j  a va  2  s. co  m
        for (IJavaElement child : parent.getChildren()) {
            if (child instanceof PackageFragment) {
                packageList.add(child.getElementName());
                listPackages(packageList, (IPackageFragment) child);
            }
        }
    } catch (JavaModelException e) {
        e.printStackTrace();
    }
}

From source file:com.siteview.mde.internal.ui.search.dependencies.DependencyExtentSearchResult.java

License:Open Source License

private void collectMatches(Set matches, IJavaElement element) {
    Match[] m = getMatches(element);/*from  w w w.  java 2s .  co m*/
    if (m.length != 0) {
        for (int i = 0; i < m.length; i++) {
            matches.add(m[i]);
        }
    }
    if (element instanceof IParent) {
        IParent parent = (IParent) element;
        try {
            IJavaElement[] children = parent.getChildren();
            for (int i = 0; i < children.length; i++) {
                collectMatches(matches, children[i]);
            }
        } catch (JavaModelException e) {
            // we will not be tracking these results
        }
    }
}

From source file:de.loskutov.bco.ui.JdtUtils.java

License:Open Source License

public static IJavaElement getMethod(IParent parent, String signature) {
    try {/* ww w .  ja  v  a2 s. c o m*/
        IJavaElement[] children = parent.getChildren();
        for (int i = 0; i < children.length; i++) {
            IJavaElement javaElement = children[i];
            switch (javaElement.getElementType()) {
            case IJavaElement.INITIALIZER:
                // fall through
            case IJavaElement.METHOD:
                if (signature.equals(getMethodSignature(javaElement))) {
                    return javaElement;
                }
                break;
            default:
                break;
            }
            if (javaElement instanceof IParent) {
                javaElement = getMethod((IParent) javaElement, signature);
                if (javaElement != null) {
                    return javaElement;
                }
            }
        }
    } catch (JavaModelException e) {
        // just ignore it. Mostly caused by class files not on the class path
        // which is not a problem for us, but a big problem for JDT
    }
    return null;
}

From source file:de.loskutov.bco.ui.JdtUtils.java

License:Open Source License

/**
 * Traverses down the children tree of this parent and collect all child anon. classes
 * @param list/*from   www . ja  v  a2 s  .  c o  m*/
 * @param parent
 * @param allowNested true to search in IType child elements too
 * @throws JavaModelException
 */
private static void collectAllAnonymous(List<IJavaElement> list, IParent parent, boolean allowNested)
        throws JavaModelException {
    IJavaElement[] children = parent.getChildren();
    for (int i = 0; i < children.length; i++) {
        IJavaElement childElem = children[i];
        if (isAnonymousType(childElem)) {
            list.add(childElem);
        }
        if (childElem instanceof IParent) {
            if (allowNested || !(childElem instanceof IType)) {
                collectAllAnonymous(list, (IParent) childElem, allowNested);
            }
        }
    }
}

From source file:de.loskutov.dh.search.FieldReferencesRequestor.java

License:Open Source License

@Override
public void acceptSearchMatch(SearchMatch match) {
    if (match.isInsideDocComment()) {
        return;/*from  www  . j  ava 2 s . c o  m*/
    }

    if (match.getElement() != null && match.getElement() instanceof IField) {
        IField field = (IField) match.getElement();

        /*
         * Check if the reported field is REALLY from the parent element.
         * This can be NOT the case for fields from member classes of inner types...
         * See bug 237200...
         */
        IParent parent = (IParent) field.getParent();
        boolean fixedBug237200 = false;
        try {
            IJavaElement[] children = parent.getChildren();
            for (IJavaElement child : children) {
                if (child instanceof IField && field.equals(child)) {
                    fixedBug237200 = true;
                }
            }
        } catch (JavaModelException e) {
            DataHierarchyPlugin.logError("getChildren() failed on: " + parent, e);
        }

        if (!fixedBug237200) {
            return;
        }
        if (searchOnlyStatics) {
            int flags = 0;
            try {
                flags = field.getFlags();
            } catch (JavaModelException e) {
                DataHierarchyPlugin.logError("acceptSearchMatch() failed on: " + field, e);
            }

            if ((flags & Flags.AccStatic) == 0 /* || member.isEnumConstant() */) {
                return;
            }
        }
        if (!isTypeAccepted(field)) {
            return;
        }
        addMatch(match);
    }
}

From source file:de.tobject.findbugs.reporter.JdtUtils.java

License:Open Source License

/**
 * Traverses down the children tree of this parent and collect all child
 * anon. classes//w ww  . j  av  a 2  s .c o  m
 *
 * @param list
 * @param parent
 * @param allowNested
 *            true to search in IType child elements too
 * @throws JavaModelException
 */
private static void collectAllAnonymous(List<IType> list, IParent parent, boolean allowNested)
        throws JavaModelException {
    IJavaElement[] children = parent.getChildren();
    for (int i = 0; i < children.length; i++) {
        IJavaElement childElem = children[i];
        if (isAnonymousType(childElem)) {
            list.add((IType) childElem);
        }
        if (childElem instanceof IParent) {
            if (allowNested || !(childElem instanceof IType)) {
                collectAllAnonymous(list, (IParent) childElem, allowNested);
            }
        }
    }
}

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 {//from ww w.  ja v a2  s.  c  om
            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:/*from w  w w . 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)
                    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;
    }
}