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

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

Introduction

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

Prototype

int FIELD

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

Click Source Link

Document

Constant representing a field.

Usage

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

License:Open Source License

/**
 * @see org.eclipse.jdt.core.ICompilationUnit#findElements(org.eclipse.jdt.core.IJavaElement)
 *//*w  w w  .  ja v  a  2s. c o m*/
public IJavaElement[] findElements(IJavaElement element) {
    ArrayList children = new ArrayList();
    while (element != null && element.getElementType() != IJavaElement.COMPILATION_UNIT) {
        children.add(element);
        element = element.getParent();
    }
    if (element == null)
        return null;
    IJavaElement currentElement = this;
    for (int i = children.size() - 1; i >= 0; i--) {
        SourceRefElement child = (SourceRefElement) children.get(i);
        switch (child.getElementType()) {
        case IJavaElement.PACKAGE_DECLARATION:
            currentElement = ((ICompilationUnit) currentElement).getPackageDeclaration(child.getElementName());
            break;
        case IJavaElement.IMPORT_CONTAINER:
            currentElement = ((ICompilationUnit) currentElement).getImportContainer();
            break;
        case IJavaElement.IMPORT_DECLARATION:
            currentElement = ((IImportContainer) currentElement).getImport(child.getElementName());
            break;
        case IJavaElement.TYPE:
            switch (currentElement.getElementType()) {
            case IJavaElement.COMPILATION_UNIT:
                currentElement = ((ICompilationUnit) currentElement).getType(child.getElementName());
                break;
            case IJavaElement.TYPE:
                currentElement = ((IType) currentElement).getType(child.getElementName());
                break;
            case IJavaElement.FIELD:
            case IJavaElement.INITIALIZER:
            case IJavaElement.METHOD:
                currentElement = ((IMember) currentElement).getType(child.getElementName(),
                        child.occurrenceCount);
                break;
            }
            break;
        case IJavaElement.INITIALIZER:
            currentElement = ((IType) currentElement).getInitializer(child.occurrenceCount);
            break;
        case IJavaElement.FIELD:
            currentElement = ((IType) currentElement).getField(child.getElementName());
            break;
        case IJavaElement.METHOD:
            currentElement = ((IType) currentElement).getMethod(child.getElementName(),
                    ((IMethod) child).getParameterTypes());
            break;
        }

    }
    if (currentElement != null && currentElement.exists()) {
        return new IJavaElement[] { currentElement };
    } else {
        return null;
    }
}

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;/*ww w  .  ja  v  a2s  . 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 w  ww  .  j  a va 2s  .c om
 */
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 w  w  w  .j av a  2  s  .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 w  w  w .  j a  v  a 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);
}

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

License:Open Source License

protected int referenceType() {
    return IJavaElement.FIELD;
}

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

License:Open Source License

public SearchMatch newDeclarationMatch(IJavaElement element, Binding binding, int accuracy, int offset,
        int length, SearchParticipant participant, IResource resource) {
    switch (element.getElementType()) {
    case IJavaElement.PACKAGE_FRAGMENT:
        return new PackageDeclarationMatch(element, accuracy, offset, length, participant, resource);
    case IJavaElement.TYPE:
        return new TypeDeclarationMatch(binding == null ? element : ((JavaElement) element).resolved(binding),
                accuracy, offset, length, participant, resource);
    case IJavaElement.FIELD:
        return new FieldDeclarationMatch(binding == null ? element : ((JavaElement) element).resolved(binding),
                accuracy, offset, length, participant, resource);
    case IJavaElement.METHOD:
        return new MethodDeclarationMatch(binding == null ? element : ((JavaElement) element).resolved(binding),
                accuracy, offset, length, participant, resource);
    case IJavaElement.LOCAL_VARIABLE:
        return new LocalVariableDeclarationMatch(element, accuracy, offset, length, participant, resource);
    case IJavaElement.PACKAGE_DECLARATION:
        return new PackageDeclarationMatch(element, accuracy, offset, length, participant, resource);
    case IJavaElement.TYPE_PARAMETER:
        return new TypeParameterDeclarationMatch(element, accuracy, offset, length, participant, resource);
    default:/*from w ww. j  a  va 2  s. c o m*/
        return null;
    }
}

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

License:Open Source License

/**
 * Reports the match of the given reference.
 *//*  w  w w .j a v  a 2  s. c om*/
protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding,
        int accuracy, MatchLocator locator) throws CoreException {
    this.match = null;
    int referenceType = referenceType();
    int offset = reference.sourceStart;
    switch (referenceType) {
    case IJavaElement.PACKAGE_FRAGMENT:
        this.match = locator.newPackageReferenceMatch(element, accuracy, offset,
                reference.sourceEnd - offset + 1, reference);
        break;
    case IJavaElement.TYPE:
        this.match = locator.newTypeReferenceMatch(element, elementBinding, accuracy, offset,
                reference.sourceEnd - offset + 1, reference);
        break;
    case IJavaElement.FIELD:
        this.match = locator.newFieldReferenceMatch(element, null, elementBinding, accuracy, offset,
                reference.sourceEnd - offset + 1, reference);
        break;
    case IJavaElement.LOCAL_VARIABLE:
        this.match = locator.newLocalVariableReferenceMatch(element, accuracy, offset,
                reference.sourceEnd - offset + 1, reference);
        break;
    case IJavaElement.TYPE_PARAMETER:
        this.match = locator.newTypeParameterReferenceMatch(element, accuracy, offset,
                reference.sourceEnd - offset + 1, reference);
        break;
    }
    if (this.match != null) {
        locator.report(this.match);
    }
}

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

License:Open Source License

public IJavaElement getPrimaryElement(boolean checkOwner) {
    if (checkOwner) {
        CompilationUnit cu = (CompilationUnit) getAncestor(COMPILATION_UNIT);
        if (cu.isPrimary())
            return this;
    }/*from w ww  .j  av a2 s . c o  m*/
    IJavaElement primaryParent = this.parent.getPrimaryElement(false);
    switch (primaryParent.getElementType()) {
    case IJavaElement.COMPILATION_UNIT:
        return ((ICompilationUnit) primaryParent).getType(this.name);
    case IJavaElement.TYPE:
        return ((IType) primaryParent).getType(this.name);
    case IJavaElement.FIELD:
    case IJavaElement.INITIALIZER:
    case IJavaElement.METHOD:
        return ((IMember) primaryParent).getType(this.name, this.occurrenceCount);
    }
    return this;
}

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

License:Open Source License

/**
 * @see org.eclipse.jdt.core.IType#isLocal()
 *//* w  ww .  j a va2s  .c  o  m*/
public boolean isLocal() {
    switch (this.parent.getElementType()) {
    case IJavaElement.METHOD:
    case IJavaElement.INITIALIZER:
    case IJavaElement.FIELD:
        return true;
    default:
        return false;
    }
}