Example usage for org.eclipse.jdt.core IJavaElement COMPILATION_UNIT

List of usage examples for org.eclipse.jdt.core IJavaElement COMPILATION_UNIT

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaElement COMPILATION_UNIT.

Prototype

int COMPILATION_UNIT

To view the source code for org.eclipse.jdt.core IJavaElement COMPILATION_UNIT.

Click Source Link

Document

Constant representing a Java compilation unit.

Usage

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

License:Open Source License

public IJavaElement getExistingElement(IJavaElement element) {
    switch (element.getElementType()) {
    case IJavaElement.JAVA_MODEL:
        return element;
    case IJavaElement.JAVA_PROJECT:
        return element; // projectCache is a Hashtable and Hashtables don't support getKey(...)
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
        return (IJavaElement) this.rootCache.getKey(element);
    case IJavaElement.PACKAGE_FRAGMENT:
        return (IJavaElement) this.pkgCache.getKey(element);
    case IJavaElement.COMPILATION_UNIT:
    case IJavaElement.CLASS_FILE:
        return (IJavaElement) this.openableCache.getKey(element);
    case IJavaElement.TYPE:
        return element; // jarTypeCache or childrenCache are Hashtables and Hashtables don't support getKey(...)
    default://from   ww w.  j  a va  2 s .c om
        return element; // childrenCache is a Hashtable and Hashtables don't support getKey(...)
    }
}

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

License:Open Source License

/**
 *  Returns the info for this element without
 *  disturbing the cache ordering.//from ww  w  .  jav a2  s.  c  o m
 */
protected Object peekAtInfo(IJavaElement element) {
    switch (element.getElementType()) {
    case IJavaElement.JAVA_MODEL:
        return this.modelInfo;
    case IJavaElement.JAVA_PROJECT:
        return this.projectCache.get(element);
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
        return this.rootCache.peek(element);
    case IJavaElement.PACKAGE_FRAGMENT:
        return this.pkgCache.peek(element);
    case IJavaElement.COMPILATION_UNIT:
    case IJavaElement.CLASS_FILE:
        return this.openableCache.peek(element);
    case IJavaElement.TYPE:
        Object result = this.jarTypeCache.peek(element);
        if (result != null)
            return result;
        else
            return this.childrenCache.get(element);
    default:
        return this.childrenCache.get(element);
    }
}

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

License:Open Source License

/**
 * Remember the info for the element.//from   w  w w  .  j  av  a2s.  c  om
 */
protected void putInfo(IJavaElement element, Object info) {
    switch (element.getElementType()) {
    case IJavaElement.JAVA_MODEL:
        this.modelInfo = info;
        break;
    case IJavaElement.JAVA_PROJECT:
        this.projectCache.put(element, info);
        this.rootCache.ensureSpaceLimit(info, element);
        break;
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
        this.rootCache.put(element, info);
        this.pkgCache.ensureSpaceLimit(info, element);
        break;
    case IJavaElement.PACKAGE_FRAGMENT:
        this.pkgCache.put(element, info);
        this.openableCache.ensureSpaceLimit(info, element);
        break;
    case IJavaElement.COMPILATION_UNIT:
    case IJavaElement.CLASS_FILE:
        this.openableCache.put(element, info);
        break;
    default:
        this.childrenCache.put(element, info);
    }
}

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

License:Open Source License

/**
 * Removes the info of the element from the cache.
 *///from   www .java 2s  . c  om
protected void removeInfo(JavaElement element) {
    switch (element.getElementType()) {
    case IJavaElement.JAVA_MODEL:
        this.modelInfo = null;
        break;
    case IJavaElement.JAVA_PROJECT:
        this.projectCache.remove(element);
        this.rootCache.resetSpaceLimit((int) (DEFAULT_ROOT_SIZE * getMemoryRatio()), element);
        break;
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
        this.rootCache.remove(element);
        this.pkgCache.resetSpaceLimit((int) (DEFAULT_PKG_SIZE * getMemoryRatio()), element);
        break;
    case IJavaElement.PACKAGE_FRAGMENT:
        this.pkgCache.remove(element);
        this.openableCache.resetSpaceLimit(
                (int) (DEFAULT_OPENABLE_SIZE * getMemoryRatio() * getOpenableRatio()), element);
        break;
    case IJavaElement.COMPILATION_UNIT:
    case IJavaElement.CLASS_FILE:
        this.openableCache.remove(element);
        break;
    default:
        this.childrenCache.remove(element);
    }
}

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

License:Open Source License

/**
 * Converts an <code>IResourceDelta</code> and its children into
 * the corresponding <code>IJavaElementDelta</code>s.
 * Return whether the delta corresponds to a resource on the classpath.
 * If it is not a resource on the classpath, it will be added as a non-java
 * resource by the sender of this method.
 *//* w  w  w  . ja  va2 s . c  o m*/
protected void traverseDelta(IJavaElementDelta delta, IPackageFragmentRoot root, IJavaProject project) {

    boolean processChildren = true;

    Openable element = (Openable) delta.getElement();
    switch (element.getElementType()) {
    case IJavaElement.JAVA_PROJECT:
        project = (IJavaProject) element;
        break;
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
        root = (IPackageFragmentRoot) element;
        break;
    case IJavaElement.COMPILATION_UNIT:
        // filter out working copies that are not primary (we don't want to add/remove them to/from the package fragment
        CompilationUnit cu = (CompilationUnit) element;
        if (cu.isWorkingCopy() && !cu.isPrimary()) {
            return;
        }
        // $FALL-THROUGH$
    case IJavaElement.CLASS_FILE:
        processChildren = false;
        break;
    }

    switch (delta.getKind()) {
    case IJavaElementDelta.ADDED:
        elementAdded(element);
        break;
    case IJavaElementDelta.REMOVED:
        elementRemoved(element);
        break;
    case IJavaElementDelta.CHANGED:
        if ((delta.getFlags() & IJavaElementDelta.F_CONTENT) != 0) {
            elementChanged(element);
        }
        break;
    }
    if (processChildren) {
        IJavaElementDelta[] children = delta.getAffectedChildren();
        for (int i = 0; i < children.length; i++) {
            IJavaElementDelta childDelta = children[i];
            traverseDelta(childDelta, root, project);
        }
    }
}

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

License:Open Source License

protected String getKey(IType type, boolean forceOpen) throws JavaModelException {
    StringBuffer key = new StringBuffer();
    key.append('L');
    String packageName = type.getPackageFragment().getElementName();
    key.append(packageName.replace('.', '/'));
    if (packageName.length() > 0)
        key.append('/');
    String typeQualifiedName = type.getTypeQualifiedName('$');
    ICompilationUnit cu = (ICompilationUnit) type.getAncestor(IJavaElement.COMPILATION_UNIT);
    if (cu != null) {
        String cuName = cu.getElementName();
        String mainTypeName = cuName.substring(0, cuName.lastIndexOf('.'));
        int end = typeQualifiedName.indexOf('$');
        if (end == -1)
            end = typeQualifiedName.length();
        String topLevelTypeName = typeQualifiedName.substring(0, end);
        if (!mainTypeName.equals(topLevelTypeName)) {
            key.append(mainTypeName);/*from   w w w .j av a  2s  .c om*/
            key.append('~');
        }
    }
    key.append(typeQualifiedName);
    key.append(';');
    return key.toString();
}

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

License:Open Source License

public String getTypeQualifiedName(char enclosingTypeSeparator, boolean showParameters)
        throws JavaModelException {
    NamedMember declaringType;// www. ja v  a  2 s. co m
    switch (this.parent.getElementType()) {
    case IJavaElement.COMPILATION_UNIT:
        if (showParameters) {
            StringBuffer buffer = new StringBuffer(this.name);
            appendTypeParameters(buffer);
            return buffer.toString();
        }
        return this.name;
    case IJavaElement.CLASS_FILE:
        String classFileName = this.parent.getElementName();
        String typeName;
        if (classFileName.indexOf('$') == -1) {
            // top level class file: name of type is same as name of class file
            typeName = this.name;
        } else {
            // anonymous or local class file
            typeName = classFileName.substring(0, classFileName.lastIndexOf('.'))/*remove .class*/.replace('$',
                    enclosingTypeSeparator);
        }
        if (showParameters) {
            StringBuffer buffer = new StringBuffer(typeName);
            appendTypeParameters(buffer);
            return buffer.toString();
        }
        return typeName;
    case IJavaElement.TYPE:
        declaringType = (NamedMember) this.parent;
        break;
    case IJavaElement.FIELD:
    case IJavaElement.INITIALIZER:
    case IJavaElement.METHOD:
        declaringType = (NamedMember) ((IMember) this.parent).getDeclaringType();
        break;
    default:
        return null;
    }
    StringBuffer buffer = new StringBuffer(
            declaringType.getTypeQualifiedName(enclosingTypeSeparator, showParameters));
    buffer.append(enclosingTypeSeparator);
    String simpleName = this.name.length() == 0 ? getOccurrenceCountSignature() : this.name;
    buffer.append(simpleName);
    if (showParameters) {
        appendTypeParameters(buffer);
    }
    return buffer.toString();
}

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

License:Open Source License

/**
 * Searches for all declarations of the fields accessed in the given element.
 * The element can be a compilation unit or a source type/method/field.
 * Reports the field declarations using the given requestor.
 *
 * @see org.eclipse.jdt.core.search.SearchEngine#searchDeclarationsOfAccessedFields(org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.core.search.SearchRequestor, org.eclipse.core.runtime.IProgressMonitor)
 *    for detailed comment//from   ww w .  j a v  a2 s .  c  o m
 */
public void searchDeclarationsOfAccessedFields(IJavaElement enclosingElement, SearchRequestor requestor,
        IProgressMonitor monitor) throws JavaModelException {
    if (VERBOSE) {
        Util.verbose(
                "BasicSearchEngine.searchDeclarationsOfAccessedFields(IJavaElement, SearchRequestor, SearchPattern, IProgressMonitor)"); //$NON-NLS-1$
    }
    // Do not accept other kind of element type than those specified in the spec
    switch (enclosingElement.getElementType()) {
    case IJavaElement.FIELD:
    case IJavaElement.METHOD:
    case IJavaElement.TYPE:
    case IJavaElement.COMPILATION_UNIT:
        // valid element type
        break;
    default:
        throw new IllegalArgumentException();
    }
    SearchPattern pattern = new DeclarationOfAccessedFieldsPattern(enclosingElement);
    searchDeclarations(enclosingElement, requestor, pattern, monitor);
}

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

License:Open Source License

/**
 * Searches for all declarations of the types referenced in the given element.
 * The element can be a compilation unit or a source type/method/field.
 * Reports the type declarations using the given requestor.
 *
 * @see org.eclipse.jdt.core.search.SearchEngine#searchDeclarationsOfReferencedTypes(org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.core.search.SearchRequestor, org.eclipse.core.runtime.IProgressMonitor)
 *    for detailed comment//from  ww w . j  ava2s  .co  m
 */
public void searchDeclarationsOfReferencedTypes(IJavaElement enclosingElement, SearchRequestor requestor,
        IProgressMonitor monitor) throws JavaModelException {
    if (VERBOSE) {
        Util.verbose(
                "BasicSearchEngine.searchDeclarationsOfReferencedTypes(IJavaElement, SearchRequestor, SearchPattern, IProgressMonitor)"); //$NON-NLS-1$
    }
    // Do not accept other kind of element type than those specified in the spec
    switch (enclosingElement.getElementType()) {
    case IJavaElement.FIELD:
    case IJavaElement.METHOD:
    case IJavaElement.TYPE:
    case IJavaElement.COMPILATION_UNIT:
        // valid element type
        break;
    default:
        throw new IllegalArgumentException();
    }
    SearchPattern pattern = new DeclarationOfReferencedTypesPattern(enclosingElement);
    searchDeclarations(enclosingElement, requestor, pattern, monitor);
}

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

License:Open Source License

/**
 * Searches for all declarations of the methods invoked in the given element.
 * The element can be a compilation unit or a source type/method/field.
 * Reports the method declarations using the given requestor.
 *
 * @see org.eclipse.jdt.core.search.SearchEngine#searchDeclarationsOfSentMessages(org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.core.search.SearchRequestor, org.eclipse.core.runtime.IProgressMonitor)
 *    for detailed comment/*from   ww w. ja  va 2  s.c  o m*/
 */
public void searchDeclarationsOfSentMessages(IJavaElement enclosingElement, SearchRequestor requestor,
        IProgressMonitor monitor) throws JavaModelException {
    if (VERBOSE) {
        Util.verbose(
                "BasicSearchEngine.searchDeclarationsOfSentMessages(IJavaElement, SearchRequestor, SearchPattern, IProgressMonitor)"); //$NON-NLS-1$
    }
    // Do not accept other kind of element type than those specified in the spec
    switch (enclosingElement.getElementType()) {
    case IJavaElement.FIELD:
    case IJavaElement.METHOD:
    case IJavaElement.TYPE:
    case IJavaElement.COMPILATION_UNIT:
        // valid element type
        break;
    default:
        throw new IllegalArgumentException();
    }
    SearchPattern pattern = new DeclarationOfReferencedMethodsPattern(enclosingElement);
    searchDeclarations(enclosingElement, requestor, pattern, monitor);
}