当前位置: 首页>>代码示例>>Java>>正文


Java RefactoringElementsBag.registerTransaction方法代码示例

本文整理汇总了Java中org.netbeans.modules.refactoring.spi.RefactoringElementsBag.registerTransaction方法的典型用法代码示例。如果您正苦于以下问题:Java RefactoringElementsBag.registerTransaction方法的具体用法?Java RefactoringElementsBag.registerTransaction怎么用?Java RefactoringElementsBag.registerTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.netbeans.modules.refactoring.spi.RefactoringElementsBag的用法示例。


在下文中一共展示了RefactoringElementsBag.registerTransaction方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createAndAddElements

import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; //导入方法依赖的package包/类
protected final Problem createAndAddElements(Set<FileObject> files, CancellableTask<WorkingCopy> task, RefactoringElementsBag elements, AbstractRefactoring refactoring, ClasspathInfo info) {
    try {
        final Collection<ModificationResult> results = processFiles(files, task, info);
        elements.registerTransaction(createTransaction(results));
        for (ModificationResult result:results) {
            for (FileObject jfo : result.getModifiedFileObjects()) {
                for (Difference dif: result.getDifferences(jfo)) {
                        elements.add(refactoring,DiffElement.create(dif, jfo, result));
                }
            }
        }
    } catch (IOException e) {
        return createProblemAndLog(null, e);
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:JavaRefactoringPlugin.java

示例2: prepareMethodRefactoring

import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; //导入方法依赖的package包/类
private Problem prepareMethodRefactoring(RefactoringElementsBag refactoringElements, final TreePathHandle treePathHandle) {
    FileObject fo = treePathHandle.getFileObject();

    try {
        RenamedProperty prop = null;
        JavaSource js = JavaSource.forFileObject(fo);
        if (js != null) {
            prop = SpringRefactorings.getRenamedProperty(treePathHandle, js, refactoring.getNewName());
        }

        SpringScope scope = SpringScope.getSpringScope(fo);
        if (scope == null) {
            return null;
        }

        if (prop != null) {
            String newName = prop.getNewName();
            String oldName = prop.getOldName();
            if (newName != null && oldName != null) {
                Modifications mods = new Modifications();
                for (Occurrence occurrence : Occurrences.getPropertyOccurrences(prop, js, scope)) {
                    refactoringElements.add(refactoring,
                            SpringRefactoringElement.createPropertyRefModification(occurrence, mods, prop.getOldName(), prop.getNewName()));
                }
                refactoringElements.registerTransaction(new RefactoringCommit(Collections.singleton(mods)));
            }
        }
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }

    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:SpringRenamePlugin.java

示例3: create

import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; //导入方法依赖的package包/类
public static void create(RefactoringElementsBag bag, FileObject fo, ExtractInterfaceRefactoring refactoring, ElementHandle<TypeElement> sourceType) throws IOException {
    JavaSource js = JavaSource.forFileObject(fo);
    ModificationResult modification = js.runModificationTask(new UpdateClassTask(refactoring, sourceType));
    List<? extends ModificationResult.Difference> diffs = modification.getDifferences(fo);
    for (ModificationResult.Difference diff : diffs) {
        bag.add(refactoring, DiffElement.create(diff, fo, modification));
    }
    bag.registerTransaction(createTransaction(Collections.singletonList(modification)));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:ExtractInterfaceRefactoringPlugin.java

示例4: createAndAddElements

import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; //导入方法依赖的package包/类
public static void createAndAddElements(AbstractRefactoring refactoring, RefactoringElementsBag elements, Collection<ModificationResult> results) {
    elements.registerTransaction(JavaRefactoringPlugin.createTransaction(results));
    for (ModificationResult result:results) {
        for (FileObject jfo : result.getModifiedFileObjects()) {
            for (ModificationResult.Difference diff: result.getDifferences(jfo)) {
                elements.add(refactoring, DiffElement.create(diff, jfo, result));
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:ReplaceConstructorWithBuilderPlugin.java

示例5: prepare

import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; //导入方法依赖的package包/类
@Override
@NbBundle.Messages({
    "rename.variable=Rename variable",
    "rename.mixin=Rename mixin"
})
public Problem prepare(final RefactoringElementsBag refactoringElements) {
    try {
        if (cancelled) {
            return null;
        }
        ModificationResult modificationResult = new ModificationResult();
        Node element = context.getElement();
        if (element != null) {
            switch (element.type()) {
                case cp_variable:
                    refactorElements(modificationResult, context, CPWhereUsedQueryPlugin.findVariables(context), Bundle.rename_variable());
                    break;
                case cp_mixin_name:
                    refactorElements(modificationResult, context, CPWhereUsedQueryPlugin.findMixins(context), Bundle.rename_mixin());
                    break;
            }

            //commit the transaction and add the differences to the result
            refactoringElements.registerTransaction(new RefactoringCommit(Collections.singletonList(modificationResult)));
            for (FileObject fo : modificationResult.getModifiedFileObjects()) {
                for (Difference diff : modificationResult.getDifferences(fo)) {
                    refactoringElements.add(refactoring, DiffElement.create(diff, fo, modificationResult));
                }
            }
        }
        return null; //no problem
    } catch (IOException | ParseException ex) {
        Exceptions.printStackTrace(ex);
        return new Problem(true, ex.getLocalizedMessage() == null ? ex.toString() : ex.getLocalizedMessage());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:CPRenameRefactoringPlugin.java

示例6: prepare

import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; //导入方法依赖的package包/类
public Problem prepare(RefactoringElementsBag refactoringElements) {

        if (fo == null || !fo.getMIMEType().equals(HibernateMappingDataLoader.REQUIRED_MIME)) {
            // Nothing needs to be done
            return null;
        }

        // Get the configuration files
        Project proj = FileOwnerQuery.getOwner(fo);
        HibernateEnvironment env = proj.getLookup().lookup(HibernateEnvironment.class);
        List<FileObject> configFiles = env.getAllHibernateConfigFileObjects();
        if(configFiles.isEmpty())
            return null;
        
        Map<FileObject, List<OccurrenceItem>> occurrences =
                HibernateRefactoringUtil.getMappingResourceOccurrences(configFiles, oldResourceName, false);

        for (FileObject configFile : occurrences.keySet()) {
            List<OccurrenceItem> foundPlaces = occurrences.get(configFile);
            for (OccurrenceItem foundPlace : foundPlaces) {
                HibernateRenameRefactoringElement elem = new HibernateRenameRefactoringElement(configFile,
                        oldResourceName,
                        newResourceName,
                        foundPlace.getLocation(),
                        foundPlace.getText());
                refactoringElements.add(refactoring, elem);
            }
        }
        refactoringElements.registerTransaction(new HibernateMappingRenameTransaction(
                occurrences.keySet(), oldResourceName, newResourceName));

        return null;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:HibernateMappingRenamePlugin.java

示例7: renameJavaClass

import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; //导入方法依赖的package包/类
private void renameJavaClass(RefactoringElementsBag refactoringElements, TreePathHandle treePathHandle,
        FileObject fo) throws IOException {

    RenamedClassName clazz = null;

    // Figure out the old name and new name
    JavaSource js = JavaSource.forFileObject(fo);
    if (js != null) {
        clazz = HibernateRefactoringUtil.getRenamedClassName(treePathHandle, js, refactoring.getNewName());
    }

    if (clazz != null) {
        String oldBinaryName = clazz.getOldBinaryName();
        String newBinaryName = clazz.getNewBinaryName();
        if (oldBinaryName != null && newBinaryName != null) {

            Map<FileObject, List<OccurrenceItem>> occurrences =
                    HibernateRefactoringUtil.getJavaClassOccurrences(mFileObjs, oldBinaryName);

            for (FileObject mFileObj : occurrences.keySet()) {
                List<OccurrenceItem> foundPlaces = occurrences.get(mFileObj);
                for( OccurrenceItem foundPlace : foundPlaces) {
                    HibernateRenameRefactoringElement elem = new HibernateRenameRefactoringElement(mFileObj,
                            oldBinaryName,
                            foundPlace.getMatching(),
                            newBinaryName,
                            foundPlace.getLocation(),
                            foundPlace.getText());
                    refactoringElements.add(refactoring, elem);
                }
            }

            refactoringElements.registerTransaction(new JavaClassRenameTransaction(occurrences.keySet(), oldBinaryName, newBinaryName));
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:HibernateRenamePlugin.java

示例8: prepare

import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; //导入方法依赖的package包/类
public Problem prepare(RefactoringElementsBag refactoringElements) {

        // Get the configuration files
        HibernateEnvironment env = project.getLookup().lookup(HibernateEnvironment.class);
        if (env == null) {
            // The project does not support Hibernate framework
            return null;
        }
        List<FileObject> configFiles = env.getAllHibernateConfigFileObjects();
        if (configFiles.isEmpty()) {
            return null;
        }

        // TODO: have all the modifications in one transaction
        for(MappingFileData tobemoved : toBeMovedMappingFiles) {
            Map<FileObject, List<OccurrenceItem>> occurrences =
                    HibernateRefactoringUtil.getMappingResourceOccurrences(configFiles, tobemoved.getResourceName(), false);

            for (FileObject configFile : occurrences.keySet()) {
                List<OccurrenceItem> foundPlaces = occurrences.get(configFile);
                for (OccurrenceItem foundPlace : foundPlaces) {
                    HibernateRenameRefactoringElement elem = new HibernateRenameRefactoringElement(configFile,
                            tobemoved.getResourceName(),
                            tobemoved.getNewResourcename(),
                            foundPlace.getLocation(),
                            foundPlace.getText());
                    refactoringElements.add(refactoring, elem);
                }
            }
            refactoringElements.registerTransaction(new HibernateMappingRenameTransaction(
                    occurrences.keySet(), tobemoved.getResourceName(), tobemoved.getNewResourcename()));
        }

        return null;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:HibernateMappingMovePlugin.java

示例9: prepare

import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; //导入方法依赖的package包/类
@Override
public Problem prepare(final RefactoringElementsBag refactoringElements) {
    //rename refactoring of files refered from html pages
    Lookup lookup = refactoring.getRefactoringSource();
    FileObject file = lookup.lookup(FileObject.class);
    if (file == null) {
        return null;
    }
    Project project = FileOwnerQuery.getOwner(file);
    if (project == null) {
        return null;
    }
    HtmlIndex index;
    try {
        index = HtmlIndex.get(project);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
        return null;
    }

    ModificationResult modificationResult = new ModificationResult();
    if(file.isFolder()) {
        refactorFolder(file, modificationResult, index);
    } else {
        refactorFile(file, modificationResult, index);
    }
    
    refactoringElements.registerTransaction(new RefactoringCommit(Collections.singletonList(modificationResult)));

    for (FileObject fo : modificationResult.getModifiedFileObjects()) {
        for (Difference diff : modificationResult.getDifferences(fo)) {
            refactoringElements.add(refactoring, DiffElement.create(diff, fo, modificationResult));
        }
    }

    return null;

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:HtmlRenameRefactoringPlugin.java

示例10: prepare

import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; //导入方法依赖的package包/类
@Override public Problem prepare(RefactoringElementsBag refactoringElements) {
    refactoringElements.registerTransaction(refactoring.transaction);
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:5,代码来源:GlobalFormatAction.java

示例11: performApplyPattern

import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; //导入方法依赖的package包/类
protected Collection<MessageImpl> performApplyPattern(Iterable<? extends HintDescription> pattern, Scope scope, RefactoringElementsBag refactoringElements) {
    ProgressHandleWrapper w = new ProgressHandleWrapper(this, 30, 70);
    BatchResult candidates = BatchSearch.findOccurrences(pattern, scope, w, /*XXX:*/HintsSettings.getGlobalSettings());
    Collection<RefactoringElementImplementation> fileChanges = new ArrayList<RefactoringElementImplementation>();
    Collection<MessageImpl> problems = new LinkedList<MessageImpl>(candidates.problems);
    Map<JavaFix, ModificationResult> changesPerFix = new IdentityHashMap<JavaFix, ModificationResult>();
    Collection<? extends ModificationResult> res = BatchUtilities.applyFixes(candidates, w, cancel, fileChanges, changesPerFix, problems);
    Set<ModificationResult> enabled = Collections.newSetFromMap(new IdentityHashMap<ModificationResult, Boolean>());
    Map<FileObject, Map<JavaFix, ModificationResult>> file2Fixes2Changes = new HashMap<FileObject, Map<JavaFix, ModificationResult>>();
    Map<FileObject, Set<FileObject>> affectedFiles = new HashMap<FileObject, Set<FileObject>>();
    Map<FileObject, List<RefactoringElementImplementation>> file2Changes = new TreeMap<FileObject, List<RefactoringElementImplementation>>(FILE_COMPARATOR);
    
    for (Entry<JavaFix, ModificationResult> changesPerFixEntry : changesPerFix.entrySet()) {
        enabled.add(changesPerFixEntry.getValue());
        
        for (FileObject file : changesPerFixEntry.getValue().getModifiedFileObjects()) {
            List<RefactoringElementImplementation> currentFileChanges = file2Changes.get(file);
            
            if (currentFileChanges == null) {
                file2Changes.put(file, currentFileChanges = new ArrayList<RefactoringElementImplementation>());
            }
            
            currentFileChanges.add(new ModificationResultElement(file, changesPerFixEntry.getKey(), changesPerFixEntry.getValue(), enabled));
            
            Map<JavaFix, ModificationResult> perFile = file2Fixes2Changes.get(file);
            
            if (perFile == null) {
                file2Fixes2Changes.put(file, perFile = new IdentityHashMap<JavaFix, ModificationResult>());
            }
            
            perFile.put(changesPerFixEntry.getKey(), changesPerFixEntry.getValue());
            
            Set<FileObject> aff = affectedFiles.get(file);
            
            if (aff == null) {
                affectedFiles.put(file, aff = new HashSet<FileObject>());
            }
            
            aff.addAll(changesPerFixEntry.getValue().getModifiedFileObjects());
        }
    }
    
    for (List<RefactoringElementImplementation> changes : file2Changes.values()) {
        Collections.sort(changes, new Comparator<RefactoringElementImplementation>() {
            @Override public int compare(RefactoringElementImplementation o1, RefactoringElementImplementation o2) {
                return o1.getPosition().getBegin().getOffset() - o2.getPosition().getBegin().getOffset();
            }
        });
        
        refactoringElements.addAll(refactoring, changes);
    }
    
    refactoringElements.registerTransaction(new DelegatingTransaction(enabled, file2Fixes2Changes, affectedFiles, res));

    for (RefactoringElementImplementation fileChange : fileChanges) {
        refactoringElements.addFileChange(refactoring, fileChange);
    }

    w.finish();

    return problems;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:63,代码来源:AbstractApplyHintsRefactoringPlugin.java

示例12: renameJavaField

import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; //导入方法依赖的package包/类
private void renameJavaField(RefactoringElementsBag refactoringElements, final TreePathHandle treePathHandle,
        FileObject fo) throws IOException {

    final String[] classAndVariableNames = new String[]{null, null};
    JavaSource javaSource = JavaSource.forFileObject(fo);
    if (javaSource == null) {
        return;
    }

    javaSource.runUserActionTask(new Task<CompilationController>() {

        public void run(CompilationController cc) throws IOException {
            cc.toPhase(Phase.ELEMENTS_RESOLVED);
            Element element = treePathHandle.resolveElement(cc);
            if (element == null || element.getKind() != ElementKind.FIELD) {
                return;
            }
            classAndVariableNames[0] = ElementUtilities.getBinaryName((TypeElement) element.getEnclosingElement());
            classAndVariableNames[1] = element.getSimpleName().toString();
        }
    }, true);
    
    String className = classAndVariableNames[0];
    String oldVariableName = classAndVariableNames[1];
    String newVariableName = refactoring.getNewName();
    if(oldVariableName != null && newVariableName != null) {
    
        Map<FileObject, List<OccurrenceItem>> occurrences =
                    HibernateRefactoringUtil.getJavaFieldOccurrences(mFileObjs, className, oldVariableName);

            for (FileObject mFileObj : occurrences.keySet()) {
                List<OccurrenceItem> foundPlaces = occurrences.get(mFileObj);
                for (OccurrenceItem foundPlace : foundPlaces) {
                    HibernateRenameRefactoringElement elem = new HibernateRenameRefactoringElement(mFileObj,
                            oldVariableName,
                            foundPlace.getMatching(),
                            newVariableName,
                            foundPlace.getLocation(),
                            foundPlace.getText());
                    refactoringElements.add(refactoring, elem);
                }
            }

            refactoringElements.registerTransaction(new JavaFieldRenameTransaction(occurrences.keySet(), className, oldVariableName, newVariableName));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:47,代码来源:HibernateRenamePlugin.java


注:本文中的org.netbeans.modules.refactoring.spi.RefactoringElementsBag.registerTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。