Example usage for org.eclipse.jdt.internal.core JavaElement getElementType

List of usage examples for org.eclipse.jdt.internal.core JavaElement getElementType

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core JavaElement getElementType.

Prototype

int getElementType();

Source Link

Document

Returns this element's kind encoded as an integer.

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.Member.java

License:Open Source License

/**
 * @see IMember//from   www  .  jav a  2 s.c  om
 */
public IType getDeclaringType() {
    JavaElement parentElement = (JavaElement) getParent();
    if (parentElement.getElementType() == TYPE) {
        return (IType) parentElement;
    }
    return null;
}

From source file:edu.buffalo.cse.green.editor.model.commands.AddJavaElementCommand.java

License:Open Source License

private IType[] getAncestorsOfType(IType t) throws JavaModelException {
    IJavaElement[] children = t.getChildren();
    int size = children.length;
    ArrayList list = new ArrayList(size);
    for (int i = 0; i < size; ++i) {
        JavaElement elt = (JavaElement) children[i];
        if (elt.getElementType() == IJavaElement.TYPE) {
            list.add(elt);//from w  w  w  . ja va 2 s .c  o m
            list.addAll(getAncestors(elt));
        }
    }
    IType[] array = new IType[list.size()];
    list.toArray(array);
    return array;
}

From source file:edu.buffalo.cse.green.editor.model.commands.AddJavaElementCommand.java

License:Open Source License

private ArrayList getAncestors(JavaElement t) throws JavaModelException {
    IJavaElement[] children = t.getChildren();
    int size = children.length;
    ArrayList list = new ArrayList(size);
    for (int i = 0; i < size; ++i) {
        JavaElement elt = (JavaElement) children[i];
        if (elt.getElementType() == IJavaElement.TYPE) {
            list.add(elt);//  ww  w . ja v  a 2 s. c om
            list.addAll(getAncestors(elt));
        }
    }
    return list;
}

From source file:org.eclipse.ajdt.core.parserbridge.AJCompilationUnitStructureRequestor.java

License:Open Source License

/**
 * Common processing for both AJ and JDT types
 *///from   www .  j  a  v  a2 s . co  m
protected void enterType(int declarationStart, int modifiers, char[] name, int nameSourceStart,
        int nameSourceEnd, char[] superclass, char[][] superinterfaces,
        org.eclipse.jdt.internal.compiler.ISourceElementRequestor.TypeParameterInfo[] tpInfo, boolean isAspect,
        boolean isPrivilegedAspect) {

    AspectTypeInfo typeInfo = new AspectTypeInfo();
    typeInfo.declarationStart = declarationStart;
    typeInfo.modifiers = modifiers;
    typeInfo.name = name;
    typeInfo.nameSourceStart = nameSourceStart;
    typeInfo.nameSourceEnd = nameSourceEnd;
    typeInfo.superclass = superclass;
    typeInfo.superinterfaces = superinterfaces;
    typeInfo.typeParameters = tpInfo;
    typeInfo.isAspect = isAspect;
    typeInfo.isPrivilegedAspect = isPrivilegedAspect;

    if (!isAspect) {
        super.enterType(typeInfo);
    } else {
        JavaElement parentHandle = (JavaElement) this.handleStack.peek();
        Object parentInfo = this.infoStack.peek();

        String nameString = new String(name);
        AspectElement handle = new AspectElement(parentHandle, nameString);
        resolveDuplicates(handle);
        this.infoStack.push(typeInfo);
        this.handleStack.push(handle);

        if (parentHandle.getElementType() == IJavaElement.TYPE) {
            ((org.eclipse.jdt.internal.compiler.ISourceElementRequestor.TypeInfo) parentInfo).childrenCategories
                    .put(handle, typeInfo.categories);
        }
        addToChildren(parentInfo, handle);
    }

}

From source file:org.eclipse.ajdt.core.parserbridge.AJCompilationUnitStructureRequestor.java

License:Open Source License

/**
 * use {@link #acceptPackage(ImportReference)} instead
 * @deprecated/*w  w w . ja  v a2  s. c o  m*/
 */
public void acceptPackage(int declarationStart, int declarationEnd, char[] name) {

    // AJDT 1.6 ADE---copied from CompilationUnitStructureProvider.acceptPackage(ImportReference)
    JavaElementInfo parentInfo = (JavaElementInfo) this.infoStack.peek();
    JavaElement parentHandle = (JavaElement) this.handleStack.peek();
    PackageDeclaration handle = null;

    if (parentHandle.getElementType() == IJavaElement.COMPILATION_UNIT) {
        handle = createPackageDeclaration(parentHandle, new String(name));
    } else {
        Assert.isTrue(false); // Should not happen
    }
    resolveDuplicates(handle);

    AJAnnotatableInfo info = new AJAnnotatableInfo();
    info.setSourceRangeStart(declarationStart);
    info.setSourceRangeEnd(declarationEnd);

    addToChildren(parentInfo, handle);
    this.newElements.put(handle, info);
}

From source file:org.eclipse.che.jdt.internal.core.JavaModelManager.java

License:Open Source License

public synchronized Object removeInfoAndChildren(JavaElement element) throws JavaModelException {
    Object info = this.cache.peekAtInfo(element);
    if (info != null) {
        boolean wasVerbose = false;
        try {/*from  w w  w.  j  a va 2 s .c om*/
            if (JavaModelCache.VERBOSE) {
                String elementType;
                switch (element.getElementType()) {
                case IJavaElement.JAVA_PROJECT:
                    elementType = "project"; //$NON-NLS-1$
                    break;
                case IJavaElement.PACKAGE_FRAGMENT_ROOT:
                    elementType = "root"; //$NON-NLS-1$
                    break;
                case IJavaElement.PACKAGE_FRAGMENT:
                    elementType = "package"; //$NON-NLS-1$
                    break;
                case IJavaElement.CLASS_FILE:
                    elementType = "class file"; //$NON-NLS-1$
                    break;
                case IJavaElement.COMPILATION_UNIT:
                    elementType = "compilation unit"; //$NON-NLS-1$
                    break;
                default:
                    elementType = "element"; //$NON-NLS-1$
                }
                System.out.println(Thread.currentThread() + " CLOSING " + elementType + " "
                        + element.toStringWithAncestors()); //$NON-NLS-1$//$NON-NLS-2$
                wasVerbose = true;
                JavaModelCache.VERBOSE = false;
            }
            element.closing(info);
            if (element instanceof IParent) {
                closeChildren(info);
            }
            this.cache.removeInfo(element);
            if (wasVerbose) {
                System.out.println(this.cache.toStringFillingRation("-> ")); //$NON-NLS-1$
            }
        } finally {
            JavaModelCache.VERBOSE = wasVerbose;
        }
        return info;
    }
    return null;
}

From source file:org.eclipse.jdt.internal.core.JavaModelManager.java

License:Open Source License

public synchronized Object removeInfoAndChildren(JavaElement element) throws JavaModelException {
    Object info = this.cache.peekAtInfo(element);
    if (info != null) {
        boolean wasVerbose = false;
        try {//www .ja  va2 s.c  o m
            if (JavaModelCache.VERBOSE) {
                String elementType;
                switch (element.getElementType()) {
                case IJavaElement.JAVA_PROJECT:
                    elementType = "project"; //$NON-NLS-1$
                    break;
                case IJavaElement.PACKAGE_FRAGMENT_ROOT:
                    elementType = "root"; //$NON-NLS-1$
                    break;
                case IJavaElement.PACKAGE_FRAGMENT:
                    elementType = "package"; //$NON-NLS-1$
                    break;
                case IJavaElement.CLASS_FILE:
                    elementType = "class file"; //$NON-NLS-1$
                    break;
                case IJavaElement.COMPILATION_UNIT:
                    elementType = "compilation unit"; //$NON-NLS-1$
                    break;
                default:
                    elementType = "element"; //$NON-NLS-1$
                }
                System.out.println(Thread.currentThread() + " CLOSING " + elementType + " " //$NON-NLS-1$//$NON-NLS-2$
                        + element.toStringWithAncestors());
                wasVerbose = true;
                JavaModelCache.VERBOSE = false;
            }
            element.closing(info);
            if (element instanceof IParent) {
                closeChildren(info);
            }
            this.cache.removeInfo(element);
            if (wasVerbose) {
                System.out.println(this.cache.toStringFillingRation("-> ")); //$NON-NLS-1$
            }
        } finally {
            JavaModelCache.VERBOSE = wasVerbose;
        }
        return info;
    }
    return null;
}