Example usage for org.eclipse.jdt.core Signature getQualifier

List of usage examples for org.eclipse.jdt.core Signature getQualifier

Introduction

In this page you can find the example usage for org.eclipse.jdt.core Signature getQualifier.

Prototype

public static String getQualifier(String name) 

Source Link

Document

Returns a string containing all but the last segment of the given dot-separated qualified name.

Usage

From source file:com.google.gdt.eclipse.core.JavaProjectTestUtilities.java

License:Open Source License

/**
 * Creates an {@link ICompilationUnit} with the given fully qualified name and
 * code in the <code>javaProject</code>.
 * //from   w w  w .  j  a va 2  s.  c  o  m
 * @param javaProject java project to host the new class
 * @param fullyQualifiedClassName fully qualified name for the class
 * @param source code for the classs
 * @return newly created {@link ICompilationUnit}
 * @throws JavaModelException
 */
public static ICompilationUnit createCompilationUnit(IJavaProject javaProject, String fullyQualifiedClassName,
        String source) throws JavaModelException {
    IPackageFragmentRoot root = javaProject.findPackageFragmentRoot(javaProject.getPath());
    if (root == null) {
        addRawClassPathEntry(javaProject, JavaCore.newSourceEntry(javaProject.getPath()));
        root = javaProject.findPackageFragmentRoot(javaProject.getPath());
    }

    String qualifier = Signature.getQualifier(fullyQualifiedClassName);
    IProgressMonitor monitor = new NullProgressMonitor();
    IPackageFragment packageFragment = root.createPackageFragment(qualifier, true, monitor);
    String name = Signature.getSimpleName(fullyQualifiedClassName);
    return packageFragment.createCompilationUnit(name + ".java", source, false, monitor);
}

From source file:com.google.gdt.eclipse.core.JavaProjectUtilities.java

License:Open Source License

/**
 * Creates an {@link ICompilationUnit} with the given fully qualified name and
 * code in the <code>javaProject</code>.
 *
 * @param javaProject java project to host the new class
 * @param fullyQualifiedClassName fully qualified name for the class
 * @param source code for the classs/*from  www  .j  av a 2  s  .co m*/
 * @return newly created {@link ICompilationUnit}
 * @throws JavaModelException
 */
public static ICompilationUnit createCompilationUnit(IJavaProject javaProject, String fullyQualifiedClassName,
        String source) throws JavaModelException {
    IPackageFragmentRoot root = javaProject.findPackageFragmentRoot(javaProject.getPath());
    if (root == null) {
        addRawClassPathEntry(javaProject, JavaCore.newSourceEntry(javaProject.getPath()));
        root = javaProject.findPackageFragmentRoot(javaProject.getPath());
    }

    String qualifier = Signature.getQualifier(fullyQualifiedClassName);
    IProgressMonitor monitor = new NullProgressMonitor();
    IPackageFragment packageFragment = root.createPackageFragment(qualifier, true, monitor);
    String name = Signature.getSimpleName(fullyQualifiedClassName);
    ICompilationUnit cu = packageFragment.createCompilationUnit(name + ".java", source, false, monitor);
    JobsUtilities.waitForIdle();
    return cu;
}

From source file:com.google.gwt.eclipse.core.modules.AbstractModule.java

License:Open Source License

@Override
public String getPackageName() {
    return Signature.getQualifier(getQualifiedName());
}

From source file:com.google.gwt.eclipse.core.modules.ModuleUtils.java

License:Open Source License

/**
 * Finds a particular GWT module by its fully-qualified name.
 *
 * @param javaProject project in which to search for modules
 * @param qualifiedName fully-qualified module name
 * @param includeJars indicates whether to include JAR files in search
 * @return the module, if found; otherwise <code>null</code>
 *///from   www. j  a  va  2  s . co  m
public static IModule findModule(IJavaProject javaProject, String qualifiedName, final boolean includeJars) {
    final String modulePckg = Signature.getQualifier(qualifiedName);
    final String simpleName = Signature.getSimpleName(qualifiedName);

    return visitFragments(javaProject, includeJars, new IPackageFragmentVisitor<IModule>() {
        @Override
        public IModule visit(IPackageFragment pckg) throws JavaModelException {
            // Look for the package fragment matching the module qualifier
            if (modulePckg.equals(pckg.getElementName())) {
                for (Object resource : pckg.getNonJavaResources()) {
                    IModule module = create(resource, includeJars);
                    // Now compare the resource name to the module name
                    if (module != null && module.getSimpleName().equals(simpleName)) {
                        return module;
                    }
                }
            }

            return null;
        }
    });
}

From source file:com.google.gwt.eclipse.core.modules.ModuleUtils.java

License:Open Source License

/**
 * Validates a fully-qualified module name. Module names are validated like fully-qualified Java
 * type names; the package should be made up of lower-case segments that are valid Java
 * identifiers, and the name should be a camel-cased valid Java identifier.
 *
 * @param qualifiedName fully-qualified module name
 * @return a status object with code <code>IStatus.OK</code> if the given name is valid, otherwise
 *         a status object indicating what is wrong with the name
 *//* ww w.ja  va2s .c  om*/
public static IStatus validateQualifiedModuleName(String qualifiedName) {
    // Validate the module package name according to Java conventions
    String pckg = Signature.getQualifier(qualifiedName);
    if (!Util.isValidPackageName(pckg)) {
        return Util.newErrorStatus("The module package name is invalid");
    }

    return validateSimpleModuleName(Signature.getSimpleName(qualifiedName));
}

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

License:Open Source License

static CompilationUnitChange createAddImportChange(ICompilationUnit cu, Name name, String fullyQualifiedName)
        throws CoreException {
    String[] args = { BasicElementLabels.getJavaElementName(Signature.getSimpleName(fullyQualifiedName)),
            BasicElementLabels.getJavaElementName(Signature.getQualifier(fullyQualifiedName)) };
    String label = Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_importtype_description,
            args);/*w w w .j a  v  a 2s.c  om*/

    CompilationUnitChange cuChange = new CompilationUnitChange(label, cu);
    ImportRewrite importRewrite = StubUtility.createImportRewrite((CompilationUnit) name.getRoot(), true);
    importRewrite.addImport(fullyQualifiedName);
    cuChange.setEdit(importRewrite.rewriteImports(null));
    return cuChange;
}

From source file:com.sun.codemodel.ClassGenerator.java

License:Apache License

private boolean alreadyExists(String fullName) {
    String localname = Signature.getSimpleName(fullName);
    String pack = Signature.getQualifier(fullName);
    IPackageFragment pf = pfr.getPackageFragment(pack);
    if (pf != null && pf.exists()) {
        ICompilationUnit cu = pf.getCompilationUnit(localname + ".java");
        if (cu != null && cu.exists()) {
            return true;
        } else/*  www .j a  v  a  2 s  . c o m*/
            return false;
    } else {
        return false;
    }
}

From source file:es.bsc.servicess.ide.editors.CommonFormPage.java

License:Apache License

/** Get the eclipse compilation unit for the core element interface 
 * form a selected orchestration class/*from  w w w  .j  a va  2 s  .c  o m*/
 * @param serviceClass Orchestration class
 * @param project Service implementation project
 * @param prMetadata Project Metadata
 * @return Core element interface
 * @throws PartInitException
 * @throws JavaModelException
 */
public static ICompilationUnit getCEInterface(String serviceClass, IJavaProject project,
        ProjectMetadata prMetadata) throws PartInitException, JavaModelException {
    IPackageFragmentRoot root = prMetadata.getPackageFragmentRoot(project);
    log.debug("Getting Package fragment " + Signature.getQualifier(serviceClass));
    IPackageFragment frag = root.getPackageFragment(Signature.getQualifier(serviceClass));
    log.debug("Comparing " + frag.getElementName() + " with " + serviceClass);
    if (frag.exists()) {
        log.debug("Looking for " + Signature.getSimpleName(serviceClass) + "Itf.java in " + frag.getPath());
        return frag.getCompilationUnit(Signature.getSimpleName(serviceClass) + "Itf.java");
    } else
        throw new PartInitException("Package fragment for " + serviceClass + " not found");
}

From source file:es.bsc.servicess.ide.editors.CommonFormPage.java

License:Apache License

/** Get the eclipse compilation unit for the orchestration class
 * @param serviceClass Name of the orchestration class
 * @param project Service implementation project
 * @param prMetadata Project Metadata/*from  ww w  .j a v a 2 s  .c  o m*/
 * @return Compilation unit of the orchetration class
 * @throws Exception 
 */
public static IType getExternalOrchestrationClass(String serviceClass, IJavaProject project,
        ProjectMetadata prMetadata) throws Exception {
    String libraryLocation = (prMetadata.getOrchestrationClass(serviceClass).getLibraryLocation());
    IType type = null;
    for (IPackageFragmentRoot r : project.getAllPackageFragmentRoots()) {
        /*log.debug("PFR: " + r.getElementName()+ " entry: "
           + r.getResolvedClasspathEntry().getPath() + "(Looking for: "+ libraryLocation+")");*/
        if (r.getResolvedClasspathEntry().getPath().toOSString().trim().equals(libraryLocation.trim())) {
            IPackageFragment frag = r.getPackageFragment(Signature.getQualifier(serviceClass));
            return frag.getClassFile(Signature.getSimpleName(serviceClass) + ".class").getType();
        }
    }
    throw new PartInitException("Type not found");
}

From source file:es.bsc.servicess.ide.editors.CommonFormPage.java

License:Apache License

/** Get the fully qualified domain name of a compilation unit
 * @param cu Compilation unit//  w w w.  ja va2 s .co m
 * @param signature Class signature
 * @param project Service implementation project
 * @return Fully qualified domain name
 * @throws JavaModelException
 */
private static String getFQType(ICompilationUnit cu, String signature, IJavaProject project)
        throws JavaModelException {
    if (signature.equals(Signature.SIG_BOOLEAN) || signature.equals(Signature.SIG_BYTE)
            || signature.equals(Signature.SIG_CHAR) || signature.equals(Signature.SIG_DOUBLE)
            || signature.equals(Signature.SIG_FLOAT) || signature.equals(Signature.SIG_INT)
            || signature.equals(Signature.SIG_LONG) || signature.equals(Signature.SIG_SHORT)
            || signature.equals(Signature.SIG_VOID)) {
        return Signature.toString(signature);
    } else {
        String qualifier = Signature.getQualifier(signature);
        if (qualifier != null && qualifier.length() > 0) {
            return Signature.toString(signature);
        } else {
            String classname = Signature.getSignatureSimpleName(signature);
            IImportDeclaration[] imports = cu.getImports();
            for (IImportDeclaration imp : imports) {
                String name = imp.getElementName();
                if (name.endsWith(".*")) {
                    String fqclass = searchClassInPackages(project, name.substring(0, name.indexOf(".*")),
                            classname);
                    if (fqclass != null)
                        return fqclass;
                } else if (name.endsWith(classname)) {
                    return name;
                }
            }
            return "java.lang." + classname;
        }
    }
}