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

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

Introduction

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

Prototype

int IMPORT_CONTAINER

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

Click Source Link

Document

Constant representing all import declarations within a compilation unit.

Usage

From source file:at.bestsolution.fxide.jdt.text.viewersupport.JavaElementLabelComposer.java

License:Open Source License

/**
 * Appends the label for a Java element with the flags as defined by this class.
 *
 * @param element the element to render//from ww  w  .j  a va 2 s .c  o  m
 * @param flags the rendering flags.
 */
public void appendElementLabel(IJavaElement element, long flags) {
    int type = element.getElementType();
    IPackageFragmentRoot root = null;

    if (type != IJavaElement.JAVA_MODEL && type != IJavaElement.JAVA_PROJECT
            && type != IJavaElement.PACKAGE_FRAGMENT_ROOT)
        root = JavaModelUtil.getPackageFragmentRoot(element);
    if (root != null && getFlag(flags, JavaElementLabels.PREPEND_ROOT_PATH)) {
        appendPackageFragmentRootLabel(root, JavaElementLabels.ROOT_QUALIFIED);
        fBuffer.append(JavaElementLabels.CONCAT_STRING);
    }

    switch (type) {
    case IJavaElement.METHOD:
        appendMethodLabel((IMethod) element, flags);
        break;
    case IJavaElement.FIELD:
        appendFieldLabel((IField) element, flags);
        break;
    case IJavaElement.LOCAL_VARIABLE:
        appendLocalVariableLabel((ILocalVariable) element, flags);
        break;
    case IJavaElement.TYPE_PARAMETER:
        appendTypeParameterLabel((ITypeParameter) element, flags);
        break;
    case IJavaElement.INITIALIZER:
        appendInitializerLabel((IInitializer) element, flags);
        break;
    case IJavaElement.TYPE:
        appendTypeLabel((IType) element, flags);
        break;
    case IJavaElement.CLASS_FILE:
        appendClassFileLabel((IClassFile) element, flags);
        break;
    case IJavaElement.COMPILATION_UNIT:
        appendCompilationUnitLabel((ICompilationUnit) element, flags);
        break;
    case IJavaElement.PACKAGE_FRAGMENT:
        appendPackageFragmentLabel((IPackageFragment) element, flags);
        break;
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
        appendPackageFragmentRootLabel((IPackageFragmentRoot) element, flags);
        break;
    case IJavaElement.IMPORT_CONTAINER:
    case IJavaElement.IMPORT_DECLARATION:
    case IJavaElement.PACKAGE_DECLARATION:
        appendDeclarationLabel(element, flags);
        break;
    case IJavaElement.JAVA_PROJECT:
    case IJavaElement.JAVA_MODEL:
        fBuffer.append(element.getElementName());
        break;
    default:
        fBuffer.append(element.getElementName());
    }

    if (root != null && getFlag(flags, JavaElementLabels.APPEND_ROOT_PATH)) {
        int offset = fBuffer.length();
        fBuffer.append(JavaElementLabels.CONCAT_STRING);
        appendPackageFragmentRootLabel(root, JavaElementLabels.ROOT_QUALIFIED);

        //         if (getFlag(flags, JavaElementLabels.COLORIZE)) {
        //            fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE);
        //         }

    }
}

From source file:at.bestsolution.fxide.jdt.text.viewersupport.JavaElementLabelComposer.java

License:Open Source License

/**
 * Appends the label for a import container, import or package declaration. Considers the D_* flags.
 *
 * @param declaration the element to render
 * @param flags the rendering flags. Flags with names starting with 'D_' are considered.
 *///from  w w  w .  ja  v a2s .  c om
public void appendDeclarationLabel(IJavaElement declaration, long flags) {
    if (getFlag(flags, JavaElementLabels.D_QUALIFIED)) {
        IJavaElement openable = (IJavaElement) declaration.getOpenable();
        if (openable != null) {
            appendElementLabel(openable, JavaElementLabels.CF_QUALIFIED | JavaElementLabels.CU_QUALIFIED
                    | (flags & QUALIFIER_FLAGS));
            fBuffer.append('/');
        }
    }
    if (declaration.getElementType() == IJavaElement.IMPORT_CONTAINER) {
        fBuffer.append(JavaUIMessages.JavaElementLabels_import_container);
    } else {
        fBuffer.append(getElementName(declaration));
    }
    // post qualification
    if (getFlag(flags, JavaElementLabels.D_POST_QUALIFIED)) {
        int offset = fBuffer.length();
        IJavaElement openable = (IJavaElement) declaration.getOpenable();
        if (openable != null) {
            fBuffer.append(JavaElementLabels.CONCAT_STRING);
            appendElementLabel(openable, JavaElementLabels.CF_QUALIFIED | JavaElementLabels.CU_QUALIFIED
                    | (flags & QUALIFIER_FLAGS));
        }
        //         if (getFlag(flags, JavaElementLabels.COLORIZE)) {
        //            fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE);
        //         }
    }
}

From source file:ca.uvic.chisel.diver.mylyn.logger.logging.PageSelectionListener.java

License:Open Source License

/**
 * @param je/*from   w  w w.ja v a  2  s .  c om*/
 * @return
 */
private String getElementType(IJavaElement je) {
    switch (je.getElementType()) {
    case IJavaElement.ANNOTATION:
        return "annotation";
    case IJavaElement.CLASS_FILE:
        return "classfile";
    case IJavaElement.COMPILATION_UNIT:
        return "compilationunit";
    case IJavaElement.FIELD:
        return "field";
    case IJavaElement.IMPORT_CONTAINER:
        return "importcontainer";
    case IJavaElement.IMPORT_DECLARATION:
        return "importdeclaration";
    case IJavaElement.INITIALIZER:
        return "initializer";
    case IJavaElement.JAVA_MODEL:
        return "javamodel";
    case IJavaElement.JAVA_PROJECT:
        return "javaproject";
    case IJavaElement.LOCAL_VARIABLE:
        return "localvariable";
    case IJavaElement.METHOD:
        return "method";
    case IJavaElement.PACKAGE_DECLARATION:
        return "packagedeclaration";
    case IJavaElement.PACKAGE_FRAGMENT:
        return "packagefragment";
    case IJavaElement.TYPE:
        return "type";
    case IJavaElement.TYPE_PARAMETER:
        return "typeparameter";
    }
    return "null";
}

From source file:ca.uvic.cs.tagsea.folding.TagseaJavaFoldingStructureProvider.java

License:Open Source License

@Override
protected void computeFoldingStructure(IJavaElement element, FoldingStructureComputationContext ctx) {
    super.computeFoldingStructure(element, ctx);

    switch (element.getElementType()) {
    case IJavaElement.METHOD:
        return;//from w  ww .  ja  va  2 s.co  m

    case IJavaElement.IMPORT_CONTAINER:
    case IJavaElement.TYPE:
    case IJavaElement.FIELD:
    case IJavaElement.INITIALIZER:
        break;
    default:
        return;
    }

    IRegion[] tags = TagExtractor.getTagRegions(getDocument(), (ISourceReference) element);

    for (IRegion region : tags) {

        JavaProjectionAnnotation annotation = new JavaProjectionAnnotation(true, element, false);
        IRegion normalized = alignRegion(region, ctx);

        /* A null here indicates that we are attempting to fold a single line region */
        if (normalized != null) {
            Position position = createCommentPosition(normalized);
            ctx.addProjectionRange(annotation, position);
        }
    }

}

From source file:com.cb.eclipse.folding.java.calculation.StrategyFactory.java

License:Open Source License

/**
 * Get a CalculationStrategy instance that is capable of handling the region
 * building for <code>elem</code>
 * /*w w w  .ja v a2 s  .com*/
 * @param elem
 *            The java element to find a calculation strategy for.
 * @return The Calculation strategy meant for processing elem.
 */
public static RegionCalculationStrategy instance(JavaProjectionCalculator calculator, IJavaElement elem) {
    int type = elem.getElementType();
    switch (type) {
    case IJavaElement.TYPE:
        return new CommentPrefixStrategy(new TypeStrategy());
    case IJavaElement.FIELD:
    case IJavaElement.METHOD:
        return new CommentPrefixStrategy(new MethodStrategy());
    case IJavaElement.IMPORT_CONTAINER:
        return new ImportContainerStrategy();
    case IJavaElement.COMPILATION_UNIT:
    case IJavaElement.CLASS_FILE:
        return new UserDefinedStrategy(new RootStrategy());
    case IJavaElement.INITIALIZER:
        return new CommentPrefixStrategy(new StaticInitializerStrategy());
    default:
        return NO_OP_STRATEGY;
    }
}

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)
 *//*ww  w  .java2s .  com*/
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.javadoc.JavaElementLabelComposer.java

License:Open Source License

/**
 * Appends the label for a import container, import or package declaration. Considers the D_* flags.
 *
 * @param declaration the element to render
 * @param flags the rendering flags. Flags with names starting with 'D_' are considered.
 *//*  w ww . j  a  v a2 s  .c  o  m*/
public void appendDeclarationLabel(IJavaElement declaration, long flags) {
    if (getFlag(flags, JavaElementLabels.D_QUALIFIED)) {
        IJavaElement openable = (IJavaElement) declaration.getOpenable();
        if (openable != null) {
            appendElementLabel(openable, JavaElementLabels.CF_QUALIFIED | JavaElementLabels.CU_QUALIFIED
                    | (flags & QUALIFIER_FLAGS));
            fBuffer.append('/');
        }
    }
    if (declaration.getElementType() == IJavaElement.IMPORT_CONTAINER) {
        fBuffer.append("import declarations");
    } else {
        fBuffer.append(getElementName(declaration));
    }
    // post qualification
    if (getFlag(flags, JavaElementLabels.D_POST_QUALIFIED)) {
        int offset = fBuffer.length();
        IJavaElement openable = (IJavaElement) declaration.getOpenable();
        if (openable != null) {
            fBuffer.append(JavaElementLabels.CONCAT_STRING);
            appendElementLabel(openable, JavaElementLabels.CF_QUALIFIED | JavaElementLabels.CU_QUALIFIED
                    | (flags & QUALIFIER_FLAGS));
        }
        //         if (getFlag(flags, JavaElementLabels.COLORIZE)) {
        //            fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE);
        //         }
    }
}

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

License:Open Source License

/**
 * Computes the folding structure for a given {@link IJavaElement java element}. Computed
 * projection annotations are//from  w  ww . java 2s.c  o m
 * {@link FoldingStructureProvider.FoldingStructureComputationContext#addProjectionRange(FoldingStructureProvider.JavaProjectionAnnotation, Position)
 * added} to the computation context.
 * <p>
 * Subclasses may extend or replace. The default implementation creates projection annotations for
 * the following elements:
 * <ul>
 * <li>true members (not for top-level types)</li>
 * <li>the javadoc comments of any member</li>
 * <li>header comments (javadoc or multi-line comments appearing before the first type's javadoc
 * or before the package or import declarations).</li>
 * </ul>
 * </p>
 * @param element the java element to compute the folding structure for
 * @param ctx the computation context
 */
protected void computeFoldingStructure(IJavaElement element, FoldingStructureComputationContext ctx) {

    IMethod lambdaMethod = null;
    /*      boolean importContainer = false;*/
    boolean collapse = false;
    boolean collapseCode = true;
    switch (element.getElementType()) {

    case IJavaElement.IMPORT_CONTAINER: {

        IImportContainer importContainer = (IImportContainer) element;
        IRegion projectionRegion = computeImportProjectionRanges(importContainer, ctx);

        if (projectionRegion != null) {
            JavaImportPosition importPosition = new JavaImportPosition(projectionRegion, importContainer);

            ctx.addProjectionRange(
                    new JavaProjectionAnnotation(ctx.collapseImportContainer(), ctx, element, true),
                    importPosition);
        }

        return;
    }
    case IJavaElement.TYPE:
        collapseCode = isInnerType((IType) element) && !isAnonymousEnum((IType) element);
        collapse = ctx.collapseInnerTypes() && collapseCode;

        lambdaMethod = findLambdaMethodIn(element);

        if (lambdaMethod != null) {
            // Let collapse initially by default
            collapse = ctx.initial;
        } else {
            try {
                if (((IType) element).isAnonymous())
                    return;
            } catch (Exception e) {
            }
        }
        break;
    case IJavaElement.METHOD:
    case IJavaElement.FIELD:
    case IJavaElement.INITIALIZER:
        collapse = ctx.collapseMembers();
        collapseCode = false;
        break;
    default:
        return;
    }

    IRegion[] regions = computeProjectionRanges((ISourceReference) element, ctx);

    if (regions.length == 0)
        return;

    // comments
    for (int i = 0; i < regions.length - 1; i++) {
        IRegion normalized = alignRegion(regions[i], ctx);
        if (normalized != null) {
            Position position = createCommentPosition(normalized);
            if (position != null) {
                boolean commentCollapse;
                if (i == 0 && (regions.length > 2 || ctx.hasHeaderComment()) && element == ctx.getFirstType()) {
                    commentCollapse = ctx.collapseHeaderComments();
                } else {
                    commentCollapse = ctx.collapseJavadoc();
                }
                ctx.addProjectionRange(new JavaProjectionAnnotation(commentCollapse, ctx, element, true),
                        position);
            }
        }
    }
    // code
    if (!collapseCode)
        return;

    // IRegion lastRegion = regions[regions.length - 1];

    IRegion codeRegion = regions[regions.length - 1];

    // if (lambdaMethod != null) {
    // normalized = alignRegion(lastRegion, ctx);
    // }

    if (codeRegion != null) {
        Position position = element instanceof IMember
                ? createMemberPosition(codeRegion, (IMember) element, lambdaMethod)
                : createCommentPosition(codeRegion);

        if (position != null)
            ctx.addProjectionRange(new JavaProjectionAnnotation(collapse, ctx, element, false), position);
    }
}

From source file:com.ibm.research.tagging.java.folding.WaypointAwareJavaFoldingStructureProvider.java

License:Open Source License

@Override
protected void computeFoldingStructure(IJavaElement element, FoldingStructureComputationContext ctx) {
    super.computeFoldingStructure(element, ctx);

    switch (element.getElementType()) {
    case IJavaElement.METHOD:
        return;//from  w  w  w  . j a  v a  2  s  . c o  m

    case IJavaElement.IMPORT_CONTAINER:
    case IJavaElement.TYPE:
    case IJavaElement.FIELD:
    case IJavaElement.INITIALIZER:
        break;
    default:
        return;
    }

    IRegion[] waypointRegions = WaypointDefinitionExtractor.getWaypointRegions(getDocument(),
            (ISourceReference) element);

    for (IRegion region : waypointRegions) {

        JavaProjectionAnnotation annotation = new JavaProjectionAnnotation(true, element, false);
        IRegion normalized = alignRegion(region, ctx);

        /* A null here indicates that we are attempting to fold a single line region */
        if (normalized != null) {
            Position position = createCommentPosition(normalized);
            ctx.addProjectionRange(annotation, position);
        }
    }

}

From source file:com.microsoft.javapkgsrv.JavaElementLabelComposer.java

License:Open Source License

/**
 * Appends the label for a Java element with the flags as defined by this class.
 *
 * @param element the element to render//w  ww  . ja  v  a2  s .  co  m
 * @param flags the rendering flags.
 */
public void appendElementLabel(IJavaElement element, long flags) {
    int type = element.getElementType();
    IPackageFragmentRoot root = null;

    if (type != IJavaElement.JAVA_MODEL && type != IJavaElement.JAVA_PROJECT
            && type != IJavaElement.PACKAGE_FRAGMENT_ROOT)
        root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
    if (root != null && getFlag(flags, PREPEND_ROOT_PATH)) {
        appendPackageFragmentRootLabel(root, ROOT_QUALIFIED);
        fBuffer.append(CONCAT_STRING);
    }

    switch (type) {
    case IJavaElement.METHOD:
        appendMethodLabel((IMethod) element, flags);
        break;
    case IJavaElement.FIELD:
        appendFieldLabel((IField) element, flags);
        break;
    case IJavaElement.LOCAL_VARIABLE:
        appendLocalVariableLabel((ILocalVariable) element, flags);
        break;
    case IJavaElement.TYPE_PARAMETER:
        appendTypeParameterLabel((ITypeParameter) element, flags);
        break;
    case IJavaElement.INITIALIZER:
        appendInitializerLabel((IInitializer) element, flags);
        break;
    case IJavaElement.TYPE:
        appendTypeLabel((IType) element, flags);
        break;
    case IJavaElement.CLASS_FILE:
        appendClassFileLabel((IClassFile) element, flags);
        break;
    case IJavaElement.COMPILATION_UNIT:
        appendCompilationUnitLabel((ICompilationUnit) element, flags);
        break;
    case IJavaElement.PACKAGE_FRAGMENT:
        appendPackageFragmentLabel((IPackageFragment) element, flags);
        break;
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
        appendPackageFragmentRootLabel((IPackageFragmentRoot) element, flags);
        break;
    case IJavaElement.IMPORT_CONTAINER:
    case IJavaElement.IMPORT_DECLARATION:
    case IJavaElement.PACKAGE_DECLARATION:
        appendDeclarationLabel(element, flags);
        break;
    case IJavaElement.JAVA_PROJECT:
    case IJavaElement.JAVA_MODEL:
        fBuffer.append(element.getElementName());
        break;
    default:
        fBuffer.append(element.getElementName());
    }

    if (root != null && getFlag(flags, APPEND_ROOT_PATH)) {
        int offset = fBuffer.length();
        fBuffer.append(CONCAT_STRING);
        appendPackageFragmentRootLabel(root, ROOT_QUALIFIED);
    }
}