Examples of IPackageFragment


Examples of org.eclipse.jdt.core.IPackageFragment

      return status;
    } else if (val.getSeverity() == IStatus.WARNING) {
      status.setWarning("Aspect name is discouraged. " + val.getMessage());
    }

    IPackageFragment pack = getPackageFragment();
    if (pack != null) {
      ICompilationUnit cu = pack.getCompilationUnit(aspectName + ".java"); //$NON-NLS-1$
      IResource resource = cu.getResource();
      if (resource.exists()) {
        status.setWarning("Aspect already exits. Only the crosscut will be created.");
        // TODO Check if aspect is a subclass of
        // ch.ethz.prose.DefaultAspect.
View Full Code Here

Examples of org.eclipse.jdt.core.IPackageFragment

    dialog.setIgnoreCase(false);
    dialog.setTitle("Package Selection");
    dialog.setMessage("&Choose a folder:");
    dialog.setEmptyListMessage("Cannot find packages to select.");
    dialog.setElements(packages);
    IPackageFragment pack = getPackageFragment();
    if (pack != null) {
      dialog.setInitialSelections(new Object[] { pack});
    }

    if (dialog.open() == Window.OK) {
View Full Code Here

Examples of org.eclipse.jdt.core.IPackageFragment

    ICompilationUnit createdWorkingCopy = null;
    try {
      // Step 1: Process package fragment.
      IPackageFragmentRoot root = getPackageFragmentRoot();
      IPackageFragment pack = getPackageFragment();
      if (pack == null) {
        pack = root.getPackageFragment(""); //$NON-NLS-1$
      }
      if (!pack.exists()) {
        String packName = pack.getElementName();
        pack = root.createPackageFragment(packName, true, null);
      }
      monitor.worked(1);

      // Step 2: Create aspect if not already existent.
      boolean needsCommit = false;
      String lineDelimiter = null;
      String aspectName = getAspectName();
      IType aspect = getAspect();
      if (aspect == null) {
        lineDelimiter = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$

        ICompilationUnit parentCU = pack.createCompilationUnit(
            aspectName + ".java", "", false, new SubProgressMonitor(monitor, 2)); //$NON-NLS-1$ //$NON-NLS-2$
        // create a working copy with a new owner
        createdWorkingCopy = parentCU.getWorkingCopy(null);

        // use the compiler template a first time to read the imports
        String content = CodeGeneration.getCompilationUnitContent(createdWorkingCopy, null, "", lineDelimiter); //$NON-NLS-1$
        if (content != null) {
          createdWorkingCopy.getBuffer().setContents(content);
        }

        ImportsManager imports = new ImportsManager(createdWorkingCopy);
        // add an import that will be removed again. Having this import solves 14661
        imports.addImport(JavaModelUtil.concatenateName(pack.getElementName(), aspectName));

        String typeContent = writeBasicAspect(imports, lineDelimiter);
        String cuContent = constructCUContent(parentCU, typeContent, lineDelimiter);
        createdWorkingCopy.getBuffer().setContents(cuContent);
        if (monitor.isCanceled()) {
View Full Code Here

Examples of org.eclipse.jdt.core.IPackageFragment

   * with the given type content.
   * @throws CoreException
   */
  protected String constructCUContent(ICompilationUnit cu, String typeContent, String lineDelimiter) throws CoreException {
    String typeComment = getTypeComment(cu, lineDelimiter);
    IPackageFragment pack = (IPackageFragment) cu.getParent();
    String content = CodeGeneration.getCompilationUnitContent(cu, typeComment, typeContent, lineDelimiter);
    if (content != null) {
      ASTParser parser = ASTParser.newParser(AST.JLS2);
      parser.setSource(content.toCharArray());
      CompilationUnit unit = (CompilationUnit) parser.createAST(null);
      if ((pack.isDefaultPackage() || unit.getPackage() != null) && !unit.types().isEmpty()) { return content; }
    }
    StringBuffer buf = new StringBuffer();
    if (!pack.isDefaultPackage()) {
      buf.append("package ").append(pack.getElementName()).append(';'); //$NON-NLS-1$
    }
    buf.append(lineDelimiter).append(lineDelimiter);
    if (typeComment != null) {
      buf.append(typeComment).append(lineDelimiter);
    }
View Full Code Here

Examples of org.eclipse.jdt.core.IPackageFragment

    protected IType resolveClassName(IJavaProject jproject, String sclassName) throws JavaModelException {
        if (!jproject.exists()) {
            return null;
        }
        IType type = null;
        IPackageFragment currPack = getMainPage().getPackageFragment();
        if (type == null && currPack != null) {
            String packName = currPack.getElementName();
            // search in own package
            if (!currPack.isDefaultPackage()) {
                type = jproject.findType(packName, sclassName);
            }
            // search in java.lang
            if (type == null && !"java.lang".equals(packName)) { //$NON-NLS-1$
                type = jproject.findType("java.lang", sclassName); //$NON-NLS-1$
View Full Code Here

Examples of org.eclipse.jdt.core.IPackageFragment

     *
     */
    protected char[] findSource(IType type, IBinaryType info, IClassFile cf,
        BitSet decompilerFlags) {

        IPackageFragment pkgFrag = type.getPackageFragment();
        IPackageFragmentRoot root = (IPackageFragmentRoot) pkgFrag.getParent();
        String pkg = type.getPackageFragment().getElementName().replace(
            '.', '/');

        String classFile = new String(info.getFileName());
        int p = classFile.lastIndexOf('/');
View Full Code Here

Examples of org.eclipse.jdt.core.IPackageFragment

    /**
     * @param classFile
     * @return full qualified bytecode name of given class
     */
    public static String getFullBytecodeName(IClassFile classFile) {
        IPackageFragment packageFr = (IPackageFragment) classFile
            .getAncestor(IJavaElement.PACKAGE_FRAGMENT);
        if (packageFr == null) {
            return null;
        }
        String packageName = packageFr.getElementName();
        // switch to java bytecode naming conventions
        packageName = packageName.replace(Signature.C_DOT, PACKAGE_SEPARATOR);

        String className = classFile.getElementName();
        if (packageName != null && packageName.length() > 0) {
View Full Code Here

Examples of org.eclipse.jdt.core.IPackageFragment

     * Returns the specified compilation unit in the given project, root, and package
     * fragment or <code>null</code> if it does not exist.
     */
    protected ICompilationUnit getCompilationUnit(String rootPath,
        String packageName, String cuName) throws JavaModelException {
        IPackageFragment pkg = getPackageFragment(rootPath, packageName);
        if (pkg == null) {
            return null;
        }
        return pkg.getCompilationUnit(cuName);
    }
View Full Code Here

Examples of org.eclipse.jdt.core.IPackageFragment

            throws JavaModelException, IOException {
        String s = "org/drools/ide/resource/DroolsTest.java.template";
        IFolder folder = project.getProject().getFolder("src/java");
        IPackageFragmentRoot packageFragmentRoot = project
                .getPackageFragmentRoot(folder);
        IPackageFragment packageFragment = packageFragmentRoot
                .createPackageFragment("com.sample", true, null);
        InputStream inputstream = getClass().getClassLoader()
                .getResourceAsStream(s);
        packageFragment.createCompilationUnit("DroolsTest.java", new String(
                readStream(inputstream)), true, null);
    }
View Full Code Here

Examples of org.eclipse.jdt.core.IPackageFragment

    private final ImageDescriptor excludedIcon = AbstractUIPlugin.imageDescriptorFromPlugin(NewBuilder.PLUGIN_ID, "icons/excluded_ovr.gif");

    public void decorate(Object element, IDecoration decoration) {
        if (element instanceof IPackageFragment) {

            IPackageFragment pkg = (IPackageFragment) element;

            IJavaProject javaProject = pkg.getJavaProject();
            IProject project = javaProject.getProject();
            boolean schedule = true;

            try {
                Collection<IResource> sourceFolders = Central.getSourceFolderModel(project);
                if (sourceFolders == null) {
                    return;
                }

                IResource sourceFolderResource = pkg.getParent().getResource();
                if (!sourceFolders.contains(sourceFolderResource)) {
                    schedule = false;
                    return;
                }

                Map<String, ? extends Collection<Version>> exports = Central.getExportedPackageModel(project);
                if (exports == null) {
                    return;
                }

                schedule = false;

                String pkgName = pkg.getElementName();
                Collection<Version> versions = exports.get(pkgName);
                if (versions != null) {
                    decoration.addOverlay(exportedIcon);
                    if (versions.isEmpty())
                        decoration.addSuffix(" " + Collections.singletonList(Version.emptyVersion).toString());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.