Package org.eclipse.jdt.core

Examples of org.eclipse.jdt.core.IPackageFragment


    setTitle("Prose Aspect");
    setDescription("Create or extend a Prose aspect.");

    fPackageDialogField = new StringButtonStatusDialogField(new IStringButtonAdapter() {
      public void changeControlPressed(DialogField field) {
        IPackageFragment pack= choosePackage()
        if (pack != null) {
          fPackageDialogField.setText(pack.getElementName());
        }
      }
    });
    fPackageDialogField.setDialogFieldListener(new IDialogFieldListener() {
      public void dialogFieldChanged(DialogField field) {
View Full Code Here


   * @param elem Java element used to initialize this page or <code>null</code>
   * if no selection was available
   */
  protected void initAspectPage(IJavaElement elem) {
    if (elem != null) {
      IPackageFragment pack = (IPackageFragment) elem.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
      if (pack != null) {
        fPackageDialogField.setText(pack.getElementName());
      }

      IType aspect = null;
      IType typeInCU = (IType) elem.getAncestor(IJavaElement.TYPE);
      if (typeInCU != null) {
View Full Code Here

  /**
   * @return Resource handle that corresponds to the compilation unit (aspect)
   * that has been created or modified
   */
  public IResource getModifiedResource() {
    IPackageFragment pack = getPackageFragment();
    return pack != null ? pack.getCompilationUnit(getAspectName() + ".java").getResource() : null; //$NON-NLS-1$
  }
View Full Code Here

      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

    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

    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

   * 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

    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

     *
     */
    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

    /**
     * @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

TOP

Related Classes of org.eclipse.jdt.core.IPackageFragment

Copyright © 2018 www.massapicom. 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.