public static void refactorProjectImportsAndDocLinks(
     Tree.Declaration node,
     IFile originalFile,
     IFile targetFile,
     CompositeChange change,
     String originalPackage,
     String targetPackage) {
   if (!originalPackage.equals(targetPackage)) {
     for (PhasedUnit pu : getAllUnits(originalFile.getProject())) {
       //                if (!node.getUnit().equals(pu.getUnit())) {
       IFile file = ((IFileVirtualFile) pu.getUnitFile()).getFile();
       if (!file.equals(originalFile) && !file.equals(targetFile)) {
         TextFileChange tfc = new TextFileChange("Fix Import", file);
         tfc.setEdit(new MultiTextEdit());
         CompilationUnit rootNode = pu.getCompilationUnit();
         refactorImports(node, originalPackage, targetPackage, rootNode, tfc);
         refactorDocLinks(node, targetPackage, rootNode, tfc);
         if (tfc.getEdit().hasChildren()) {
           change.add(tfc);
         }
       }
       //                }
     }
   }
 }
  @Override
  public boolean equals(Object obj) {
    if (obj instanceof IFileWrapper) {
      return mFile.equals(((IFileWrapper) obj).mFile);
    }

    if (obj instanceof IFile) {
      return mFile.equals(obj);
    }

    return super.equals(obj);
  }
Beispiel #3
0
 @Override
 protected RefactoringStatus checkConditionsAfterNameSetting(IProgressMonitor pm) {
   RefactoringStatus status = new RefactoringStatus();
   ProjectUtil projectUtil = getProjectUtil();
   newFileName = projectUtil.appendFileExtension(info.getNewName());
   NesCComponentNameCollissionDetector detector = new NesCComponentNameCollissionDetector();
   detector.handleCollisions4NewFileName(
       newFileName, declaringIdentifier, declaringFile, getProjectUtil(), status, pm);
   try { // Handle Collisions in affected configurations.
     for (IFile file : affectedIdentifiers.keySet()) {
       if (!declaringFile.equals(file)) { // The component itself cannot reference itself.
         AstAnalyzerFactory factory = new AstAnalyzerFactory(file, projectUtil, pm);
         if (factory
             .hasConfigurationAnalyzerCreated()) { // Only configurations can reference other
                                                   // modules.
           detector.handleCollisions4NewComponentNameWithConfigurationLocalName(
               factory.getConfigurationAnalyzer(),
               file,
               info.getOldName(),
               info.getNewName(),
               status);
         }
       }
     }
   } catch (Exception e) {
     status.addFatalError(
         "Exception during condition checking. See project log for more information.");
     projectUtil.log("Exception during condition checking.", e);
   }
   return status;
 }
  /**
   * Builds the FSTModel of the feature project and creates a list of all directives with valid
   * colors
   *
   * @return the directive list
   */
  private void createDirectiveList() {
    directiveMap.clear();
    validDirectiveList.clear();
    FSTModel model = project.getFSTModel();
    if (model == null) {
      composer.buildFSTModel();
      model = project.getFSTModel();
    }
    if (model == null) {
      return;
    }

    int index = 0;
    for (FSTFeature fstFeature : model.getFeatures()) {
      for (FSTRole role : fstFeature.getRoles()) {
        if (file.equals(role.getFile())) {
          for (FSTDirective dir : role.getDirectives()) {
            directiveMap.put(dir.getId(), dir);
            index++;
          }
        }
      }
    }

    for (int i = 0; i < index; i++) {
      FSTDirective dir = directiveMap.get(i);
      if (dir != null && ColorList.isValidColor(dir.getColor())) {
        validDirectiveList.add(dir);
      }
    }
  }
 public void synchronize() {
   XModelObject o = getXModelObject();
   IFile f1 = super.getFile();
   if (o == null || o.getPath() == null) return;
   IFile f2 = getFileByObject(o);
   if (!f1.equals(f2) && f2 != null) hackSetFile(f2);
 }
 public boolean isFileChanged() {
   XModelObject o = getXModelObject();
   IFile f1 = super.getFile();
   if (o == null || o.getPath() == null) return false;
   IFile f2 = getFileByObject(o);
   return !f1.equals(f2);
 }
  /**
   * Find Open Editor for the currently selected ModelExtensionDefinition
   *
   * @param selectedMedFile the mxd file to check
   * @return the currently open editor or <code>null</code> if none open
   */
  private static IEditorPart getOpenEditor(IFile selectedMedFile) {
    final IWorkbenchWindow window = Activator.getDefault().getCurrentWorkbenchWindow();

    if (window != null) {
      final IWorkbenchPage page = window.getActivePage();

      if (page != null) {
        // look through the open editors and see if there is one available for this model file.
        IEditorReference[] editors = page.getEditorReferences();

        for (int i = 0; i < editors.length; ++i) {
          IEditorPart editor = editors[i].getEditor(false);

          if (editor != null) {
            IEditorInput input = editor.getEditorInput();

            if (input instanceof IFileEditorInput) {
              if ((selectedMedFile != null)
                  && selectedMedFile.equals(((IFileEditorInput) input).getFile())) {
                return editor;
              }
            }
          }
        }
      }
    }

    return null;
  }
Beispiel #8
0
  /**
   * Updates the references and project data based on the data in the parsed document.
   *
   * @param monitor Progress monitor
   */
  private void updateReferences(IProgressMonitor monitor) {
    this.updateLabels(parser.getLabels());
    this.updateCommands(parser.getCommands());
    IProject project = getCurrentProject();
    if (project == null) return;
    IFile cFile = ((FileEditorInput) editor.getEditorInput()).getFile();
    boolean isMainFile = cFile.equals(TexlipseProperties.getProjectSourceFile(project));

    pollCancel(monitor);

    // After here we just store those fun properties...
    if (parser.isLocalBib()) {
      TexlipseProperties.setSessionProperty(
          project, TexlipseProperties.SESSION_BIBLATEXLOCALBIB_PROPERTY, new Boolean(true));
    } else {
      TexlipseProperties.setSessionProperty(
          project, TexlipseProperties.SESSION_BIBLATEXLOCALBIB_PROPERTY, null);
    }

    // Only update Preamble, Bibstyle if main Document
    if (isMainFile) {
      boolean biblatexMode = parser.isBiblatexMode();
      updateBiblatex(project, biblatexMode, parser.getBiblatexBackend(), false);

      String[] bibs = parser.getBibs();
      this.updateBibs(bibs, biblatexMode, cFile);

      pollCancel(monitor);

      String preamble = parser.getPreamble();
      if (preamble != null) {
        TexlipseProperties.setSessionProperty(
            project, TexlipseProperties.PREAMBLE_PROPERTY, preamble);
      }
      if (!biblatexMode) {
        String bibstyle = parser.getBibstyle();
        if (bibstyle != null) {
          String oldStyle =
              (String)
                  TexlipseProperties.getSessionProperty(
                      project, TexlipseProperties.BIBSTYLE_PROPERTY);

          if (oldStyle == null || !bibstyle.equals(oldStyle)) {
            TexlipseProperties.setSessionProperty(
                project, TexlipseProperties.BIBSTYLE_PROPERTY, bibstyle);

            // schedule running bibtex on the next build
            TexlipseProperties.setSessionProperty(
                project, TexlipseProperties.BIBFILES_CHANGED, new Boolean(true));
          }
        }
      }
    }
  }
  public void toggleLineBreakpoints(final IWorkbenchPart part, ISelection selection)
      throws CoreException {
    final QvtEditor qvtEditor = getEditor(part);
    if (qvtEditor == null) {
      return;
    }

    IFile unitFile = (IFile) qvtEditor.getEditorInput().getAdapter(IResource.class);
    ITextSelection textSelection = (ITextSelection) selection;
    int lineNumber = textSelection.getStartLine() + 1;

    List<ILineBreakpoint> breakpoints = QVTODebugCore.getQVTOBreakpoints(ILineBreakpoint.class);
    for (ILineBreakpoint next : breakpoints) {
      if (!unitFile.equals(next.getMarker().getResource())) {
        continue;
      }

      if (next.getLineNumber() == lineNumber) {
        try {
          // a breakpoint already exists at this line =>toggle again means remove
          DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint(next, true);
        } catch (CoreException e) {
          QVTODebugUIPlugin.log(e.getStatus());
        }
        next.delete();
        return;
      }
    }

    URI sourceURI = URIUtils.getResourceURI(unitFile);
    final QVTOBreakpoint lineBreakpoint = new QVTOBreakpoint(sourceURI, lineNumber);
    lineBreakpoint.register(true);

    Job job =
        new Job(DebugUIMessages.QVTOToggleBreakpointAdapter_VerifyBreakpointJob) {
          @Override
          protected IStatus run(IProgressMonitor monitor) {
            return new BreakpointLocationVerifier(
                    qvtEditor,
                    lineBreakpoint,
                    DebugUIMessages.QVTOToggleBreakpointAdapter_CannotSetBreakpoint)
                .run();
          }

          @Override
          public boolean belongsTo(Object family) {
            return QVTOBreakpoint.QVTO_BREAKPOINT_JOBFAMILY == family;
          }
        };

    job.setPriority(Job.INTERACTIVE);
    job.setSystem(true);
    job.schedule();
  }
Beispiel #10
0
 public static IDocument getDocFromEditor(IFile file) {
   IWorkbenchPage page = getActivePage();
   if (page == null) return null;
   IEditorReference[] ers = page.getEditorReferences();
   for (int i = 0; i < ers.length; i++) {
     IEditorInput input = getEditorInput(ers[i]);
     if (input == null) continue;
     IFile f = getFile(input);
     if (f == null || !f.equals(file)) continue;
     return getDocument(ers[i]);
   }
   return null;
 }
 public void revalidate() {
   IFile f = getFile();
   if (f == null || f.equals(super.getFile())) return;
   try {
     Field field = FileEditorInput.class.getDeclaredField("file"); // $NON-NLS-1$
     field.setAccessible(true);
     field.set(this, f);
   } catch (NoSuchFieldException e) {
     ModelUIPlugin.getPluginLog().logError(e);
   } catch (IllegalArgumentException e) {
     ModelUIPlugin.getPluginLog().logError(e);
   } catch (IllegalAccessException e) {
     ModelUIPlugin.getPluginLog().logError(e);
   }
 }
 private static PDEFormEditor getOpenEditor(String editorID, String inputContextID, IFile file) {
   // Get the file's project
   IProject project = file.getProject();
   // Check for open editors housed in the specified project
   ArrayList list = (ArrayList) fOpenPDEEditors.get(project);
   // No open editors found
   if (list == null) {
     return null;
   }
   // Get the open editor whose
   // (1) Editor ID matches the specified editor ID
   // (2) Underlying file matches the specified file
   // Check all open editors
   for (int i = 0; i < list.size(); i++) {
     // Get the editor
     PDEFormEditor editor = (PDEFormEditor) list.get(i);
     // Check for the specified type
     // Get the editor ID
     String currentEditorID = editor.getEditorSite().getId();
     if (currentEditorID.equals(editorID) == false) {
       continue;
     }
     // Check for the specified file
     // Find the editor's input context
     InputContext context = editor.getContextManager().findContext(inputContextID);
     // Ensure we have an input context
     if (context == null) {
       continue;
     }
     // Get the editor input
     IEditorInput input = context.getInput();
     // Ensure we have a file editor input
     if ((input instanceof IFileEditorInput) == false) {
       continue;
     }
     // Get the editor's underlying file
     IFile currentFile = ((IFileEditorInput) input).getFile();
     // If the file matches the specified file, we have found the
     // specified editor
     if (currentFile.equals(file)) {
       return editor;
     }
   }
   return null;
 }
 public boolean equals(Object o) {
   getXModelObject();
   if (this == o) return true;
   if (o instanceof FileEditorInput) {
     if (getFile() == null) return false;
     FileEditorInput other = (FileEditorInput) o;
     IFile f1 = getFile();
     IFile f2 = other.getFile();
     if (f1 == null || f2 == null) return f1 == f2;
     if (f1.equals(f2)) return true;
     IPath loc1 = f1.getLocation();
     IPath loc2 = f2.getLocation();
     if (loc1 == null || loc2 == null) return loc1 == loc2;
     return loc1.equals(loc2);
   }
   if (o instanceof XModelObjectEditorInput) {
     return object.equals(((XModelObjectEditorInput) o).getXModelObject());
   }
   return false;
 }
Beispiel #14
0
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.ui.navigator.ILinkHelper#activateEditor(org.eclipse.ui.IWorkbenchPage, org.eclipse.jface.viewers.IStructuredSelection)
   */
  public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
    if (aSelection == null || aSelection.isEmpty()) {
      return;
    }

    Object firstElement = aSelection.getFirstElement();

    // if it is a python element, let's first get the actual object for finding the editor
    if (firstElement instanceof IWrappedResource) {
      IWrappedResource resource = (IWrappedResource) firstElement;
      firstElement = resource.getActualObject();
    }

    // and now, if it is really a file...
    if (firstElement instanceof IFile) {

      // ok, let's check if the active editor is already the selection, because although the
      // findEditor(editorInput) method
      // may return an editor for the correct file, we may have multiple editors for the same file,
      // and if the current
      // editor is already correct, we don't want to change it
      // @see bug:
      // https://sourceforge.net/tracker/?func=detail&atid=577329&aid=2037682&group_id=85796
      IEditorPart activeEditor = aPage.getActiveEditor();
      if (activeEditor != null) {
        IEditorInput editorInput = activeEditor.getEditorInput();
        IFile currFile = (IFile) editorInput.getAdapter(IFile.class);
        if (currFile != null && currFile.equals(firstElement)) {
          return; // the current editor is already the active editor.
        }
      }

      // if we got here, the active editor is not a match, so, let's find one and show it.
      IEditorPart editor = null;
      IEditorInput fileInput = new FileEditorInput((IFile) firstElement);
      if ((editor = aPage.findEditor(fileInput)) != null) {
        aPage.bringToTop(editor);
      }
    }
  }
  @SuppressWarnings("unused")
  private IEditorPart getEditorFor(IFile file) {
    IWorkbenchPage page = getViewSite().getPage();

    for (IEditorReference editorReference : page.getEditorReferences()) {
      try {
        IEditorInput editorInput = editorReference.getEditorInput();

        if (editorInput instanceof IFileEditorInput) {
          IFileEditorInput input = (IFileEditorInput) editorInput;

          if (file.equals(input.getFile())) {
            return editorReference.getEditor(true);
          }
        }
      } catch (PartInitException pie) {
        // ignore
      }
    }

    return null;
  }
  /**
   * Builds the FSTModel of the feature project and creates a list of all directives with valid
   * colors
   *
   * @return the directive list
   */
  private void createDirectiveList() {
    directiveMap.clear();
    validDirectiveList.clear();
    FSTModel model = project.getFSTModel();
    if (model == null || model.getClasses().isEmpty()) {
      composer.buildFSTModel();
      model = project.getFSTModel();
    }
    if (model == null) {
      return;
    }

    for (FSTFeature fstFeature : model.getFeatures()) {
      for (FSTRole role : fstFeature.getRoles()) {
        if (file.equals(role.getFile())) {
          for (FSTDirective dir : role.getDirectives()) {
            directiveMap.put(dir.getId(), dir);
            validDirectiveList.add(dir);
          }
        }
      }
    }
  }
  /**
   * Copies/moves a compilation unit with the name <code>newCUName</code> to the destination
   * package.<br>
   * The package statement in the compilation unit is updated if necessary. The main type of the
   * compilation unit is renamed if necessary.
   *
   * @exception JavaModelException if the operation is unable to complete
   */
  private void processCompilationUnitResource(ICompilationUnit source, PackageFragment dest)
      throws JavaModelException {
    String newCUName = getNewNameFor(source);
    String destName = (newCUName != null) ? newCUName : source.getElementName();
    TextEdit edit = updateContent(source, dest, newCUName); // null if unchanged

    // TODO (frederic) remove when bug 67606 will be fixed (bug 67823)
    // store encoding (fix bug 66898)
    IFile sourceResource = (IFile) source.getResource();
    String sourceEncoding = null;
    try {
      sourceEncoding = sourceResource.getCharset(false);
    } catch (CoreException ce) {
      // no problem, use default encoding
    }
    // end todo
    // copy resource
    IContainer destFolder = (IContainer) dest.getResource(); // can be an IFolder or an IProject
    IFile destFile = destFolder.getFile(new Path(destName));
    org.eclipse.jdt.internal.core.CompilationUnit destCU =
        new org.eclipse.jdt.internal.core.CompilationUnit(
            dest, destName, DefaultWorkingCopyOwner.PRIMARY);
    if (!destFile.equals(sourceResource)) {
      try {
        if (!destCU.isWorkingCopy()) {
          if (destFile.exists()) {
            if (this.force) {
              // we can remove it
              deleteResource(destFile, IResource.KEEP_HISTORY);
              destCU.close(); // ensure the in-memory buffer for the dest CU is closed
            } else {
              // abort
              throw new JavaModelException(
                  new JavaModelStatus(
                      IJavaModelStatusConstants.NAME_COLLISION,
                      Messages.bind(
                          Messages.status_nameCollision, destFile.getFullPath().toString())));
            }
          }
          int flags = this.force ? IResource.FORCE : IResource.NONE;
          if (isMove()) {
            flags |= IResource.KEEP_HISTORY;
            sourceResource.move(destFile.getFullPath(), flags, getSubProgressMonitor(1));
          } else {
            if (edit != null) flags |= IResource.KEEP_HISTORY;
            sourceResource.copy(destFile.getFullPath(), flags, getSubProgressMonitor(1));
          }
          setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
        } else {
          destCU.getBuffer().setContents(source.getBuffer().getContents());
        }
      } catch (JavaModelException e) {
        throw e;
      } catch (CoreException e) {
        throw new JavaModelException(e);
      }

      // update new resource content
      if (edit != null) {
        boolean wasReadOnly = destFile.isReadOnly();
        try {
          saveContent(dest, destName, edit, sourceEncoding, destFile);
        } catch (CoreException e) {
          if (e instanceof JavaModelException) throw (JavaModelException) e;
          throw new JavaModelException(e);
        } finally {
          Util.setReadOnly(destFile, wasReadOnly);
        }
      }

      // register the correct change deltas
      prepareDeltas(source, destCU, isMove());
      if (newCUName != null) {
        // the main type has been renamed
        String oldName = Util.getNameWithoutJavaLikeExtension(source.getElementName());
        String newName = Util.getNameWithoutJavaLikeExtension(newCUName);
        prepareDeltas(source.getType(oldName), destCU.getType(newName), isMove());
      }
    } else {
      if (!this.force) {
        throw new JavaModelException(
            new JavaModelStatus(
                IJavaModelStatusConstants.NAME_COLLISION,
                Messages.bind(Messages.status_nameCollision, destFile.getFullPath().toString())));
      }
      // update new resource content
      // in case we do a saveas on the same resource we have to simply update the contents
      // see http://dev.eclipse.org/bugs/show_bug.cgi?id=9351
      if (edit != null) {
        saveContent(dest, destName, edit, sourceEncoding, destFile);
      }
    }
  }