Example usage for org.eclipse.jdt.core.dom ASTNode IMPORT_DECLARATION

List of usage examples for org.eclipse.jdt.core.dom ASTNode IMPORT_DECLARATION

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom ASTNode IMPORT_DECLARATION.

Prototype

int IMPORT_DECLARATION

To view the source code for org.eclipse.jdt.core.dom ASTNode IMPORT_DECLARATION.

Click Source Link

Document

Node type constant indicating a node of type ImportDeclaration.

Usage

From source file:cc.kave.eclipse.namefactory.NodeFactory.java

License:Apache License

public static Name createNodeName(ASTNode node) {

    switch (node.getNodeType()) {

    case ASTNode.METHOD_DECLARATION:
        return createMethodDeclName((MethodDeclaration) node);

    case ASTNode.METHOD_INVOCATION:
        return createMethodInvName(node);

    case ASTNode.SUPER_METHOD_INVOCATION:
        return createSuperMethodInvName(node);

    case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
        return createVariableName(node.getParent());

    case ASTNode.QUALIFIED_NAME:
        return createQualifiedName(node);

    case ASTNode.SINGLE_VARIABLE_DECLARATION:
        return createSingleVariableDeclName(node);

    case ASTNode.IMPORT_DECLARATION:
        ImportDeclaration importNode = (ImportDeclaration) node;
        return CsTypeName.newTypeName(BindingFactory.getBindingName(importNode.resolveBinding()));

    case ASTNode.PACKAGE_DECLARATION:
        PackageDeclaration packageNode = (PackageDeclaration) node;
        return CsNamespaceName.newNamespaceName(packageNode.resolveBinding().getName());

    case ASTNode.FIELD_DECLARATION:
        return createVariableName(node);

    case ASTNode.VARIABLE_DECLARATION_STATEMENT:
        return createVariableName(node);

    case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
        return createVariableName(node);

    default://  w ww .j  av  a  2s.  com
        return null;
    }
}

From source file:cideplus.ui.astview.ASTViewLabelProvider.java

License:Open Source License

public Image getImage(Object obj) {
    if (obj instanceof ASTNode) {
        int nodeType = ((ASTNode) obj).getNodeType();
        String image = ISharedImages.IMG_OBJS_CFILE;
        //new JavaElementImageDescriptor()
        switch (nodeType) {
        case ASTNode.ENUM_CONSTANT_DECLARATION:
            image = ISharedImages.IMG_OBJS_ENUM_DEFAULT;
            break;
        case ASTNode.FIELD_DECLARATION:
            image = ISharedImages.IMG_FIELD_DEFAULT;
            break;
        case ASTNode.METHOD_DECLARATION:
            image = ISharedImages.IMG_OBJS_PUBLIC;
            break;
        case ASTNode.MODIFIER:
            image = ISharedImages.IMG_OBJS_DEFAULT;
            break;
        case ASTNode.JAVADOC:
            image = ISharedImages.IMG_OBJS_JAVADOCTAG;
            break;
        case ASTNode.PACKAGE_DECLARATION:
            image = ISharedImages.IMG_OBJS_PACKDECL;
            break;
        case ASTNode.IMPORT_DECLARATION:
            image = ISharedImages.IMG_OBJS_IMPDECL;
            break;
        case ASTNode.ENUM_DECLARATION:
            image = ISharedImages.IMG_OBJS_ENUM;
            break;
        case ASTNode.TYPE_DECLARATION:
            if (((TypeDeclaration) obj).isInterface()) {
                image = ISharedImages.IMG_OBJS_INTERFACE;
            } else {
                image = ISharedImages.IMG_OBJS_CLASS;
            }/*from  www.j  a  v a  2 s  .c  o m*/
            break;
        }
        if (image != null) {
            return JavaUI.getSharedImages().getImage(image);
        }
        return null;
    } else if (obj instanceof ASTAttribute) {
        Image image = ((ASTAttribute) obj).getImage();
        if (image == null) {
            if (((ASTAttribute) obj).getChildren().length > 0) {
                image = PlatformUI.getWorkbench().getSharedImages()
                        .getImage(org.eclipse.ui.ISharedImages.IMG_OBJ_FOLDER);
            } else {
                image = PlatformUI.getWorkbench().getSharedImages()
                        .getImage(org.eclipse.ui.ISharedImages.IMG_TOOL_FORWARD);
            }
        }
        return image;
    }

    return null;
    //      String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
    //      if (obj instanceof ASTNode) {
    //         imageKey = ISharedImages.IMG_OBJ_FOLDER;
    //      }
    //      return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
}

From source file:com.drgarbage.ast.ASTGraphUtil.java

License:Apache License

/**
 * Returns an image corresponding to the AST element.
 * //from w w w  .j  a va  2s.  co m
 * @param node the AST-node
 * @return the image
 */
@SuppressWarnings("restriction")
public static Image getImage(ASTNode node) {
    switch (node.getNodeType()) {
    case ASTNode.COMPILATION_UNIT:
        return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_CUNIT);

    case ASTNode.PACKAGE_DECLARATION:
        return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_PACKDECL);

    case ASTNode.IMPORT_DECLARATION:
        return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_IMPDECL);

    case ASTNode.TYPE_DECLARATION:
        return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_CLASS);

    case ASTNode.ANNOTATION_TYPE_DECLARATION:
        return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_ANNOTATION);

    case ASTNode.ANONYMOUS_CLASS_DECLARATION:
        return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_INNER_CLASS_DEFAULT);

    case ASTNode.ENUM_DECLARATION:
        return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_ENUM);

    case ASTNode.FIELD_DECLARATION:
    case ASTNode.ENUM_CONSTANT_DECLARATION:
        return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PROTECTED);

    case ASTNode.METHOD_DECLARATION:
        return JavaPluginImages.get(JavaPluginImages.IMG_MISC_PUBLIC);

    case ASTNode.JAVADOC:
        return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_JAVADOCTAG);

    case ASTNode.VARIABLE_DECLARATION_STATEMENT:
        return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_LOCAL_VARIABLE);

    case ASTNode.BLOCK:
        return blockImage;

    case ASTNode.MODIFIER:
        return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_DEFAULT);
    }

    /* default */
    return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PRIVATE);
}

From source file:com.drgarbage.ast.ASTPanel.java

License:Apache License

/**
 * Hides the package imports./* ww  w.  j  ava  2  s  . co  m*/
 */
public void hidePackageImports(boolean hidden) {
    if (hidden) {
        ((TreeContentProvider) treeViewer.getContentProvider()).hide(ASTNode.IMPORT_DECLARATION);
    } else {
        ((TreeContentProvider) treeViewer.getContentProvider()).show(ASTNode.IMPORT_DECLARATION);
    }
    treeViewer.refresh();
}

From source file:com.intel.ide.eclipse.mpt.ast.UnresolvedElementsSubProcessor.java

License:Open Source License

public static void importNotFoundProposals(IInvocationContext context, IProblemLocation problem,
        Map<String, LinkedCorrectionProposal> proposals) throws CoreException {
    ICompilationUnit cu = context.getCompilationUnit();

    ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
    if (selectedNode == null) {
        return;//from  ww w .j  a v  a 2 s. c  o  m
    }
    ImportDeclaration importDeclaration = (ImportDeclaration) ASTNodes.getParent(selectedNode,
            ASTNode.IMPORT_DECLARATION);
    if (importDeclaration == null) {
        return;
    }
    if (!importDeclaration.isOnDemand()) {
        Name name = importDeclaration.getName();
        if (importDeclaration.isStatic() && name.isQualifiedName()) {
            name = ((QualifiedName) name).getQualifier();
        }
        int kind = JavaModelUtil.is50OrHigher(cu.getJavaProject()) ? SimilarElementsRequestor.REF_TYPES
                : SimilarElementsRequestor.CLASSES | SimilarElementsRequestor.INTERFACES;
        UnresolvedElementsSubProcessor.addNewTypeProposals(cu, name, kind,
                IProposalRelevance.IMPORT_NOT_FOUND_NEW_TYPE, proposals);
    }
}

From source file:com.liferay.ide.gradle.ui.quickfix.QuickFixGradleDep.java

License:Open Source License

private void importNotFoundProposal(IInvocationContext context, IProblemLocation problem,
        Collection<IJavaCompletionProposal> proposals) {
    ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());

    if (selectedNode == null) {
        return;// w  w w . j a  va2s .c o m
    }

    ImportDeclaration importDeclaration = (ImportDeclaration) ASTNodes.getParent(selectedNode,
            ASTNode.IMPORT_DECLARATION);

    if (importDeclaration == null) {
        return;
    }

    String importName = importDeclaration.getName().toString();
    List<String> serviceWrapperList;
    List<String> servicesList;
    boolean depWrapperCanFixed = false;

    try {
        serviceWrapperList = TargetPlatformUtil.getServiceWrapperList().getServiceList();
        servicesList = TargetPlatformUtil.getServicesList().getServiceList();

        if (serviceWrapperList.contains(importName)) {
            ServiceContainer bundle = TargetPlatformUtil.getServiceWrapperBundle(importName);
            depWrapperCanFixed = true;
            createDepProposal(context, proposals, bundle);
        }

        if (!depWrapperCanFixed) {
            if (servicesList.contains(importName)) {
                ServiceContainer bundle = TargetPlatformUtil.getServiceBundle(importName);
                createDepProposal(context, proposals, bundle);
            }
        }

        if (TargetPlatformUtil.getThirdPartyBundleList(importName) != null) {
            ServiceContainer bundle = TargetPlatformUtil.getThirdPartyBundleList(importName);
            createDepProposal(context, proposals, bundle);
        }
    } catch (Exception e) {
        GradleCore.logError("Gradle dependence got error", e);
    }
}

From source file:com.siteview.mde.internal.ui.correction.java.QuickFixProcessor.java

License:Open Source License

private static ASTNode getParent(ASTNode node) {
    do {//from   w  ww  .java  2  s .  c  o m
        node = node.getParent();
    } while (node != null && node.getNodeType() != ASTNode.IMPORT_DECLARATION);
    return node;
}

From source file:edu.washington.cs.cupid.scripting.java.quickfix.ClasspathProcessor.java

License:Open Source License

private ImportDeclaration parentImport(final ASTNode node) {
    ASTNode current = node;//from   w w  w  . j  a  v  a 2  s . c om
    do {
        if (current.getNodeType() == ASTNode.IMPORT_DECLARATION) {
            return (ImportDeclaration) current;
        }
        current = current.getParent();
    } while (current != null);
    return null;
}

From source file:fede.workspace.dependencies.eclipse.java.fix.DependencyQuickFixProcessor.java

License:Apache License

public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations)
        throws CoreException {
    List<IJavaCompletionProposal> ret = new ArrayList<IJavaCompletionProposal>();
    CompilationUnit astroot = context.getASTRoot();
    IResource r = context.getCompilationUnit().getResource();
    IProject p = r.getProject();/*from  w  w w .ja  va  2s . c o m*/
    IJavaProject jp = JavaCore.create(p);

    Item itemSource = WSPlugin.getItemFromResource(p);
    if (itemSource != null) {
        Object manager = itemSource.getType().getItemManager();
        if (manager instanceof IFixManager) {
            IFixManager fixmanager = (IFixManager) manager;
            for (IProblemLocation problem : locations) {
                ASTNode coveredNode = problem.getCoveredNode(astroot);
                String[] arguments = problem.getProblemArguments();

                switch (problem.getProblemId()) {
                case IProblem.IsClassPathCorrect:
                    if (arguments.length == 1) {
                        String qualifiedType = arguments[0];
                        String packageName = Signature.getQualifier(qualifiedType);
                        String typeName = Signature.getSimpleName(qualifiedType);
                        fixmanager.resolve(jp, itemSource, packageName, typeName, false, ret);
                    }
                    continue;
                case IProblem.UndefinedType:
                    if (coveredNode instanceof SimpleName) {
                        fixmanager.resolve(jp, itemSource, ((SimpleName) coveredNode).getIdentifier(), null,
                                false, ret);
                    }
                    break;
                default:
                    break;
                }
                ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
                if (selectedNode == null)
                    continue;

                ImportDeclaration importDeclaration = (ImportDeclaration) ASTNodes.getParent(selectedNode,
                        ASTNode.IMPORT_DECLARATION);
                if (importDeclaration == null) {
                    continue;
                }

                String name = ASTNodes.asString(importDeclaration.getName());
                String packageName;
                String typeName = null;
                if (importDeclaration.isOnDemand()) {
                    packageName = name;
                } else {
                    packageName = Signature.getQualifier(name);
                    typeName = Signature.getSimpleName(name);
                }

                fixmanager.resolve(jp, itemSource, packageName, typeName,
                        problem.getProblemId() == IProblem.UndefinedType, ret);

            }
        }
    }
    return (IJavaCompletionProposal[]) ret.toArray(new IJavaCompletionProposal[ret.size()]);
}

From source file:org.apache.felix.sigil.eclipse.ui.internal.quickfix.ImportQuickFixProcessor.java

License:Apache License

private String[] readPackage(ASTNode selectedNode, IProblemLocation location) {
    ArrayList<String> packages = new ArrayList<String>();

    ImportDeclaration id = (ImportDeclaration) ASTNodes.getParent(selectedNode, ASTNode.IMPORT_DECLARATION);

    if (id == null) {
        MethodInvocation m = (MethodInvocation) ASTNodes.getParent(selectedNode, ASTNode.METHOD_INVOCATION);

        if (m != null) {
            packages.add(readPackage(m));
            while (m.getExpression() != null && m.getExpression() instanceof MethodInvocation) {
                m = (MethodInvocation) m.getExpression();
                packages.add(readPackage(m));
            }//from www.  ja  v a 2  s. c om
        }
    } else {
        if (id.isOnDemand()) {
            packages.add(id.getName().toString());
        } else {
            String iStr = id.getName().toString();
            packages.add(iStr.substring(0, iStr.lastIndexOf(".")));
        }
    }

    return packages.toArray(new String[packages.size()]);
}