Example usage for org.eclipse.jdt.core IPackageDeclaration getParent

List of usage examples for org.eclipse.jdt.core IPackageDeclaration getParent

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IPackageDeclaration getParent.

Prototype

IJavaElement getParent();

Source Link

Document

Returns the element directly containing this element, or null if this element has no parent.

Usage

From source file:org.jboss.tools.cdi.internal.core.impl.definition.PackageDefinition.java

License:Open Source License

public void setPackage(IPackageDeclaration pkg, IRootDefinitionContext context) {
    qualifiedName = pkg.getElementName();
    IType contextType = null;// www. j  ava2 s . c o  m
    ICompilationUnit u = null;
    if (pkg.getParent() instanceof ICompilationUnit) {
        try {
            u = ((ICompilationUnit) pkg.getParent()).getWorkingCopy(new NullProgressMonitor());
            contextType = u.createType("class A {}", null, false, new NullProgressMonitor());
        } catch (JavaModelException e) {

        }
    }
    super.setAnnotatable(pkg, contextType, context, 0);
    if (u != null) {
        try {
            u.discardWorkingCopy();
        } catch (JavaModelException e) {

        }
    }
}

From source file:org.jboss.tools.cdi.internal.core.impl.definition.PackageDefinition.java

License:Open Source License

public String resolveType(String typeName) {
    if (binaryType != null) {
        return typeName;
    }//  w w  w  . j  a  va  2  s  . c om
    String result = typeName;
    IPackageDeclaration pkg = (IPackageDeclaration) member;
    IType contextType = null;
    ICompilationUnit u = null;
    if (pkg.getParent() instanceof ICompilationUnit) {
        try {
            u = ((ICompilationUnit) pkg.getParent()).getWorkingCopy(new NullProgressMonitor());
            contextType = u.createType("class A {}", null, false, new NullProgressMonitor());
        } catch (JavaModelException e) {

        }
    }

    if (contextType != null) {
        result = EclipseJavaUtil.resolveType(contextType, typeName);
    }

    if (u != null) {
        try {
            u.discardWorkingCopy();
        } catch (JavaModelException e) {

        }
    }

    return result == null ? typeName : result;
}