Package org.eclipse.ltk.core.refactoring

Examples of org.eclipse.ltk.core.refactoring.TextFileChange


  private static Change createDirlinkChange(DirlinkRefactoringInformation info) throws Exception {

   
    if(info.getArguments() instanceof MoveArguments || info.getArguments() instanceof RenameArguments){
      TextFileChange change = new TextFileChange("", info.getFile());
      IDocument doc = change.getCurrentDocument(new NullProgressMonitor());
      // create Textedit
   
 
      FindReplaceDocumentAdapter find = new FindReplaceDocumentAdapter(doc);
      IRegion resultStart = find.find(0, "location\\s*=\\s*\"", true, true, false, true);
      IRegion resultStop = find.find(resultStart.getOffset() + resultStart.getLength(), "\"", true, true, false, false);
 
      String linkTarget = WGADesignStructureHelper.computeDirLinkTarget(info.getFile().getParent(), computeNewLinkTarget(info));
      TextEdit edit = new ReplaceEdit(resultStart.getLength() + resultStart.getOffset(), resultStop.getOffset() - (resultStart.getLength() + resultStart.getOffset()), linkTarget);
     
      change.setEdit(edit);
      return change;
      }else if (info.getArguments() instanceof DeleteArguments) {
        // check if resource to delete will still exists after parent deletion is performed - otherwise we can skip any change here
        if (!info.getElement().getFullPath().isPrefixOf(info.getFile().getParent().getFullPath())) {
          CompositeChange delChange = new CompositeChange("Deletions");
View Full Code Here


  }

  private static Change createRenameDesignReferenceChange(ContentStoreRefactoringInfo info) throws Exception {
   
 
    TextFileChange change = new TextFileChange("", info.getRuntime().getWGAConfigFile());   
    WGAConfiguration config = info.getRuntime().retrieveWGAConfig(false);
    ContentStore currentContentStore = (ContentStore)config.getByUid(info.getContentStoreUID());
   
   
    boolean configChanged = false;
    if(info.getArguments() instanceof RenameArguments){         
      currentContentStore.getDesign().setName(computeNewDesignReference(info));     
      configChanged=true;
    }else if(info.getArguments() instanceof MoveArguments){
      currentContentStore.setEnabled(false)
      configChanged=true;
    }else if(info.getArguments() instanceof DeleteArguments) {
      // check if wgaconfig will still exists after deletion is performed - otherwise we can skip any change here
      if (!info.getElement().getFullPath().isPrefixOf(info.getRuntime().getWGAConfigFile().getFullPath())) {
        currentContentStore.setEnabled(false);     
        configChanged=true;
     
    }   
   
   
   
    if(configChanged){
      List<ValidationError> errors =  config.validate();
      if(errors.isEmpty()) {
       
     
      ByteArrayOutputStream configContent = new ByteArrayOutputStream();   
      WGAConfiguration.write(config, configContent);
      change.setEdit(new ReplaceEdit(0, change.getCurrentDocument((new NullProgressMonitor())).getLength(), configContent.toString()))
      return change;
      } else {
        for(ValidationError current : errors){
          WGADesignerPlugin.getDefault().logError(current.getMessage());
        }
View Full Code Here

                 * not store it yet: wait until we know if there are actually changes in the file
                 */
                TextChange fileChange = getTextChange(resource);
                final boolean fileChangeIsNew = (fileChange == null);
                if (fileChange == null) {
                    fileChange = new TextFileChange(proxy.getName(), resource);
                    fileChange.setEdit(new MultiTextEdit());
                }
                TextEdit rootEdit = fileChange.getEdit();

                /* loop over all renames to perform */
 
View Full Code Here

   
    TextSearchRequestor collector= new TextSearchRequestor() {
      @Override
      public boolean acceptPatternMatch(TextSearchMatchAccess matchAccess) throws CoreException {
        IFile file= matchAccess.getFile();
        TextFileChange change= (TextFileChange) changes.get(file);
        if (change == null) {
          TextChange textChange= getTextChange(file); // an other participant already modified that file?
          if (textChange != null) {
            return false; // don't try to merge changes
          }
          change= new TextFileChange(file.getName(), file);
          change.setEdit(new MultiTextEdit());
          changes.put(file, change);
        }
        ReplaceEdit edit= new ReplaceEdit(matchAccess.getMatchOffset(), matchAccess.getMatchLength(), newName);
        change.addEdit(edit);
        change.addTextEditGroup(new TextEditGroup("Update type reference", edit)); //$NON-NLS-1$
        return true;
      }
    };
    TextSearchEngine.create().search(scope, collector, pattern, pm);
   
View Full Code Here

            eclipseRep = findEclipseRepresentation(oldPath);
        } else {
            eclipseRep = file;
        }

        final TextFileChange change = new TextFileChange(oldPath, eclipseRep);
        // change.setSaveMode(TextFileChange.FORCE_SAVE);
        final File tf = new File(oldPath);
        final List<TextEdit> edits = ChangesetMaker.createEdits(tf, newFileContent);
        final MultiTextEdit multiEdit = new MultiTextEdit();
        if (edits.size() != 0) {
            for (final TextEdit edit : edits) {
                multiEdit.addChild(edit);
            }
            change.setEdit(multiEdit);
            return change;
        }
        return null;
    }
View Full Code Here

    public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
        CompositeChange changes = new CompositeChange("Reorganize DRL " + currentName + " Type ");
        drlFiles = drlProjectDetector.detect(file.getProject());
        classPattern = Pattern.compile("(?<=\\W)" + currentName + "(?=\\W)");
        for (IFile drlFile : drlFiles) {
          TextFileChange change = createChangesForFile(drlFile);
            if ( change != null && change.getEdit().getChildrenSize() > 0 ) {
                changes.add(change);
            }
        }
       
        if (changes.getChildren().length == 0) {
View Full Code Here

    String content = FileUtil.readFile(drlFile);
    if ( content == null ) {
        return null;
    }
   
    TextFileChange change = new TextFileChange(drlFile.getName(), drlFile);
    MultiTextEdit mte = new MultiTextEdit();
    change.setEdit(mte);
   
    boolean isImported = false;
    for (ImportDescr importDescr : drlInfo.getPackageDescr().getImports()) {
      isImported |= importDescr.getTarget().equals(className) || importDescr.getTarget().equals(packageName + ".*");
      addReplace(mte, importDescr.getTarget(), content, importDescr.getStartCharacter(), importDescr.getEndCharacter());
View Full Code Here

                return null;

            Pattern pattern = Pattern.compile("(?<=\\.|\\s)" + currentName + "(?=\\(|\\n|\\s)");
            matcher = pattern.matcher(content);

            TextFileChange change = new TextFileChange(drlFile.getName(), drlFile);
            MultiTextEdit mte = new MultiTextEdit();
            change.setEdit(mte);
            while (matcher.find()) {
                ReplaceEdit replace = new ReplaceEdit(matcher.start(), currentName.length(), newName);
                mte.addChild(replace);
            }
            if (change.getEdit().getChildrenSize() > 0)
                changes.add(change);
        }
        if (changes.getChildren().length==0)
            return null;
        return (changes.getChildren().length > 0)?changes:null;
View Full Code Here

            for (IFile drlFile : drlFiles) {

                if ((content = readFile(drlFile))==null)
                    return null;

                TextFileChange change = new TextFileChange(drlFile.getName(), drlFile);
                MultiTextEdit mte = new MultiTextEdit();
                change.setEdit(mte);

                // rename the field name
                Pattern pattern = Pattern.compile(FIELD_NAME.replaceAll("FIELD_NAME", currentName));
                matcher = pattern.matcher(content);
                while (matcher.find()) {
                    ReplaceEdit replace = new ReplaceEdit(matcher.start(), currentName.length(), newName);
                    mte.addChild(replace);
                }

                // search all the variables of the type to replace the getters/setters
                pattern = Pattern.compile(VARIABLE_ASSIGNED.replace("TYPE", typeName));
                matcher = pattern.matcher(content);
                while (matcher.find()) {
                    if (matcher.group().length() > 0) {
                        String variableNameAssigned = matcher.group();
                        if (renameFieldProcessor.getRenameGetter()) {
                            String newGetterName = renameFieldProcessor.getNewGetterName();
                            String currentGetterName = renameFieldProcessor.getGetter().getElementName();
                            String regexp = GETTER_NAME.replace("VARIABLE_NAME", variableNameAssigned).replace("CURRENT_GETTER_NAME", currentGetterName);
                            createFieldRenameChanges(mte, content, regexp, currentGetterName, newGetterName);
                        }
                        if (renameFieldProcessor.getRenameSetter()) {
                            String newSetterName = renameFieldProcessor.getNewSetterName();
                            String currentSetterName = renameFieldProcessor.getSetter().getElementName();
                            String regexp = SETTER_NAME.replace("VARIABLE_NAME", variableNameAssigned).replace("CURRENT_SETTER_NAME", currentSetterName);
                            createFieldRenameChanges(mte, content, regexp, currentSetterName, newSetterName);
                        }
                    }
                }

                if (change.getEdit().getChildrenSize() > 0)
                    changes.add(change);

            }
        }
        return (changes.getChildren().length > 0)?changes:null;
View Full Code Here

            Pattern pattern = Pattern.compile(toReplace);
            matcher = pattern.matcher(content);

            if (matcher.find()) {
                TextFileChange change = new TextFileChange(drlFile.getName(), drlFile);
                MultiTextEdit mte = new MultiTextEdit();
                change.setEdit(mte);
                ReplaceEdit replace = new ReplaceEdit(matcher.start(), toReplace.length(), replaceWith);
                mte.addChild(replace);
                changes.add(change);
                refactoringContent.updateContent(drlFile, content.replace(toReplace, replaceWith));
            }
View Full Code Here

TOP

Related Classes of org.eclipse.ltk.core.refactoring.TextFileChange

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.