Example usage for org.eclipse.jdt.core IJavaElement getElementName

List of usage examples for org.eclipse.jdt.core IJavaElement getElementName

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaElement getElementName.

Prototype

String getElementName();

Source Link

Document

Returns the name of this element.

Usage

From source file:dynamicrefactoring.util.selection.TreeSelectionInfo.java

License:Open Source License

/**
 * Obtiene el proyecto al que pertenece el elemento seleccionado 
 * en una ventana.//from w  w w  .  java2s.  c  o  m
 * 
 * @return el proyecto al que pertenece el elemento seleccioando.
 */
@Override
public IProject getProjectForSelection() {

    IJavaElement element = getJavaProjectForSelection();

    if (element != null) {
        IProject myProject = getJavaProjectForName(element.getElementName());
        return myProject;
    }

    return null;
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockEditor.java

License:Open Source License

/********************************************************************************/

void rename(String proj, String bid, String file, int start, int end, String name, String handle,
        String newname, boolean keeporig, boolean getters, boolean setters, boolean dohier, boolean qual,
        boolean refs, boolean dosimilar, boolean textocc, boolean doedit, String filespat, IvyXmlWriter xw)
        throws BedrockException {
    FileData fd = file_map.get(file);//from  w  w  w  .  j  a  va2 s  .  c o  m
    ICompilationUnit icu;

    if (doedit) {
        // icu = fd.getDefaultUnit();
        icu = fd.getEditableUnit(bid);
    } else
        icu = fd.getEditableUnit(bid);

    IJavaElement[] elts;
    try {
        elts = icu.codeSelect(start, end - start);
    } catch (JavaModelException e) {
        throw new BedrockException("Bad location: " + e, e);
    }

    IJavaElement relt = null;
    for (IJavaElement ije : elts) {
        if (handle != null && !handle.equals(ije.getHandleIdentifier()))
            continue;
        if (name != null && !name.equals(ije.getElementName()))
            continue;
        relt = ije;
        break;
    }
    if (relt == null)
        throw new BedrockException("Item to rename not found");

    String id = null;
    switch (relt.getElementType()) {
    case IJavaElement.COMPILATION_UNIT:
        id = IJavaRefactorings.RENAME_COMPILATION_UNIT;
        break;
    case IJavaElement.FIELD:
        IField ifld = (IField) relt;
        try {
            if (ifld.isEnumConstant())
                id = IJavaRefactorings.RENAME_ENUM_CONSTANT;
            else
                id = IJavaRefactorings.RENAME_FIELD;
        } catch (JavaModelException e) {
        }
        break;
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
    case IJavaElement.PACKAGE_FRAGMENT:
        id = IJavaRefactorings.RENAME_PACKAGE;
        break;
    case IJavaElement.LOCAL_VARIABLE:
        id = IJavaRefactorings.RENAME_LOCAL_VARIABLE;
        break;
    case IJavaElement.TYPE:
        id = IJavaRefactorings.RENAME_TYPE;
        break;
    case IJavaElement.TYPE_PARAMETER:
        id = IJavaRefactorings.RENAME_TYPE_PARAMETER;
        break;
    case IJavaElement.METHOD:
        id = IJavaRefactorings.RENAME_METHOD;
        break;
    case IJavaElement.ANNOTATION:
    case IJavaElement.CLASS_FILE:
    case IJavaElement.IMPORT_CONTAINER:
    case IJavaElement.IMPORT_DECLARATION:
    case IJavaElement.INITIALIZER:
    case IJavaElement.JAVA_MODEL:
    case IJavaElement.JAVA_PROJECT:
    case IJavaElement.PACKAGE_DECLARATION:
        break;
    }
    if (id == null)
        throw new BedrockException("Invalid element type to rename");

    RenameJavaElementDescriptor renamer;

    RefactoringContribution rfc = RefactoringCore.getRefactoringContribution(id);
    if (rfc == null) {
        xw.begin("FAILURE");
        xw.field("TYPE", "SETUP");
        xw.textElement("ID", id);
        xw.end("FAILURE");
        renamer = new RenameJavaElementDescriptor(id);
    } else {
        renamer = (RenameJavaElementDescriptor) rfc.createDescriptor();
    }

    renamer.setJavaElement(relt);
    renamer.setKeepOriginal(keeporig);
    renamer.setNewName(newname);
    if (proj != null)
        renamer.setProject(proj);
    renamer.setRenameGetters(getters);
    renamer.setRenameSetters(setters);
    renamer.setUpdateHierarchy(dohier);
    renamer.setUpdateQualifiedNames(qual);
    renamer.setUpdateReferences(refs);
    renamer.setUpdateSimilarDeclarations(dosimilar);
    renamer.setUpdateTextualOccurrences(textocc);
    if (filespat != null)
        renamer.setFileNamePatterns(filespat);

    RefactoringStatus sts = renamer.validateDescriptor();
    if (!sts.isOK()) {
        xw.begin("FAILURE");
        xw.field("TYPE", "VALIDATE");
        BedrockUtil.outputStatus(sts, xw);
        xw.end("FAILURE");
        return;
    }

    try {
        Refactoring refactor = renamer.createRefactoring(sts);
        if (refactor == null) {
            xw.begin("FAILURE");
            xw.field("TYPE", "CREATE");
            xw.textElement("RENAMER", renamer.toString());
            xw.textElement("REFACTOR", renamer.toString());
            xw.textElement("STATUS", sts.toString());
            xw.end("FAILURE");
            return;
        }

        refactor.setValidationContext(null);

        // this seems to reset files from disk (mutliple times)
        sts = refactor.checkAllConditions(new NullProgressMonitor());
        if (!sts.isOK()) {
            xw.begin("FAILURE");
            xw.field("TYPE", "CHECK");
            BedrockUtil.outputStatus(sts, xw);
            xw.end("FAILURE");
            if (sts.hasFatalError())
                return;
        }
        BedrockPlugin.logD("RENAME: Refactoring checked");

        Change chng = refactor.createChange(new NullProgressMonitor());
        BedrockPlugin.logD("RENAME: Refactoring change created");

        if (doedit && chng != null) {
            chng.perform(new NullProgressMonitor());
        } else if (chng != null) {
            xw.begin("EDITS");
            BedrockUtil.outputChange(chng, xw);
            xw.end("EDITS");
        }
    } catch (CoreException e) {
        throw new BedrockException("Problem creating refactoring: " + e, e);
    }

    BedrockPlugin.logD("RENAME RESULT = " + xw.toString());
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockEditor.java

License:Open Source License

/********************************************************************************/

void moveElement(String proj, String bid, String what, String file, int start, int end, String name,
        String handle, String target, boolean qual, boolean refs, boolean doedit, IvyXmlWriter xw)
        throws BedrockException {
    FileData fd = findFile(proj, file, null, null);
    IJavaElement relt = null;/*from   ww  w. j av a 2 s.  co m*/
    if (what.equals("COMPUNIT")) {
        if (fd == null)
            throw new BedrockException("Invalid file");
        relt = fd.getSearchUnit();
    } else {
        ICompilationUnit icu = fd.getEditableUnit(bid);
        IJavaElement[] elts;
        try {
            elts = icu.codeSelect(start, end - start);
        } catch (JavaModelException e) {
            throw new BedrockException("Bad location: " + e, e);
        }

        for (IJavaElement ije : elts) {
            if (handle != null && !handle.equals(ije.getHandleIdentifier()))
                continue;
            if (name != null && !name.equals(ije.getElementName()))
                continue;
            relt = ije;
            break;
        }
    }
    if (relt == null)
        throw new BedrockException("Item to rename not found");

    RefactoringContribution rfc = null;
    RefactoringDescriptor rfd = null;
    IJavaElement tgt = null;

    switch (relt.getElementType()) {
    case IJavaElement.COMPILATION_UNIT:
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
    case IJavaElement.PACKAGE_FRAGMENT:
    case IJavaElement.TYPE:
        rfc = RefactoringCore.getRefactoringContribution(IJavaRefactorings.MOVE);
        tgt = our_plugin.getProjectManager().findPackageFragment(proj, target);
        break;
    case IJavaElement.METHOD:
        rfc = RefactoringCore.getRefactoringContribution(IJavaRefactorings.MOVE_METHOD);
        break;
    default:
        throw new BedrockException("Invalid element type to rename");
    }

    if (rfc == null) {
        xw.begin("FAILURE");
        xw.field("TYPE", "SETUP");
        xw.end("FAILURE");
        return;
    } else {
        rfd = rfc.createDescriptor();
    }

    RefactoringStatus sts = null;
    if (rfd instanceof MoveDescriptor) {
        MoveDescriptor md = (MoveDescriptor) rfd;
        md.setDestination(tgt);
        IFile[] ifls = new IFile[0];
        IFolder[] iflds = new IFolder[0];
        ICompilationUnit[] icus = new ICompilationUnit[] { (ICompilationUnit) relt };
        md.setMoveResources(ifls, iflds, icus);
        sts = md.validateDescriptor();
        if (!sts.isOK()) {
            xw.begin("FAILURE");
            xw.field("TYPE", "VALIDATE");
            BedrockUtil.outputStatus(sts, xw);
            xw.end("FAILURE");
            return;
        }
    } else if (rfd instanceof MoveMethodDescriptor) {
        MoveMethodDescriptor mmd = (MoveMethodDescriptor) rfd;
        System.err.println("HANDLE MOVE METHOD" + mmd);
    }

    try {
        Refactoring refactor = rfd.createRefactoring(sts);
        if (refactor == null) {
            xw.begin("FAILURE");
            xw.field("TYPE", "CREATE");
            if (sts != null)
                xw.textElement("STATUS", sts.toString());
            xw.end("FAILURE");
            return;
        }

        refactor.setValidationContext(null);

        sts = refactor.checkAllConditions(new NullProgressMonitor());
        if (!sts.isOK()) {
            xw.begin("FAILURE");
            xw.field("TYPE", "CHECK");
            BedrockUtil.outputStatus(sts, xw);
            xw.end("FAILURE");
            if (sts.hasFatalError())
                return;
        }

        Change chng = refactor.createChange(new NullProgressMonitor());
        BedrockPlugin.logD("RENAME: Refactoring change created");

        if (doedit && chng != null) {
            chng.perform(new NullProgressMonitor());
        } else if (chng != null) {
            xw.begin("EDITS");
            BedrockUtil.outputChange(chng, xw);
            xw.end("EDITS");
        }
    } catch (CoreException e) {
        throw new BedrockException("Problem with move", e);
    }
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockOpenEditorBubbleActionDelegate.java

License:Open Source License

@Override
public void run(IAction action) {
    IWorkbenchPage page = our_window.getActivePage();

    if (page != null) {
        if (!(page.getActiveEditor() instanceof ITextEditor))
            return;

        ITextEditor fileEditor = (ITextEditor) page.getActiveEditor();

        IFileEditorInput fileEditorInput = (IFileEditorInput) fileEditor.getEditorInput();
        String path = fileEditorInput.getFile().getProjectRelativePath().toOSString();
        String filePath = path;/*from www .ja  v a2s.  co m*/
        IProject project = fileEditorInput.getFile().getProject();

        IJavaProject javaProject = JavaModelManager.getJavaModelManager().getJavaModel()
                .getJavaProject(project.getName());

        try {
            for (IClasspathEntry entry : javaProject.getRawClasspath()) {
                if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    String sourcePath = entry.getPath().toOSString().substring(project.getName().length() + 2);

                    if (path.startsWith(sourcePath)) {
                        path = path.substring(sourcePath.length() + 1);
                        path = path.replace(File.separatorChar, '$');
                        path = path.substring(0, path.indexOf("."));

                        filePath = filePath.substring(sourcePath.length() + 1);

                        break;
                    }
                }
            }
        } catch (Exception e1) {
            BedrockPlugin.log("Exception : " + e1.getMessage() + ", " + e1.getClass().toString());
        }

        try {
            IJavaElement javaElement = javaProject.findElement(new Path(filePath));

            if (!(javaElement instanceof ICompilationUnit))
                return;

            ICompilationUnit icu = (ICompilationUnit) javaElement;

            ISelectionProvider selectionProvider = fileEditor.getSelectionProvider();
            ISelection selection = selectionProvider.getSelection();

            if (selection instanceof ITextSelection) {
                ITextSelection textSelection = (ITextSelection) selection;
                int offset = textSelection.getOffset();

                IJavaElement element = icu.getElementAt(offset);

                IvyXmlWriter xw = BedrockPlugin.getPlugin().beginMessage("OPENEDITOR");
                xw.field("PROJECT", project.getName());

                if (element == null) {
                    xw.field("RESOURCEPATH", path);
                } else {
                    boolean isFirstElement = true;
                    boolean isMethod = false;

                    String fileName = path.substring(path.lastIndexOf('$') + 1);

                    List<String> list = new ArrayList<String>();

                    while (element != null && (!element.getElementName().equals(fileName)
                            || element.getElementType() == IJavaElement.METHOD)) {
                        if (isFirstElement && (element.getElementType() == IJavaElement.METHOD
                                || element.getElementType() == IJavaElement.TYPE)) {
                            list.add(element.getElementName());

                            if (element.getElementType() == IJavaElement.METHOD) {
                                isMethod = true;
                            }

                            isFirstElement = false;
                        } else if (!isFirstElement) {
                            list.add(element.getElementName());
                        }

                        element = element.getParent();

                        if ("".equals(element.getElementName())) {
                            xw.field("RESOURCEPATH", path);
                            BedrockPlugin.getPlugin().finishMessage(xw);

                            return;
                        }
                    }

                    String[] aryPath = new String[list.size()];
                    list.toArray(aryPath);

                    for (int i = aryPath.length - 1; i >= 0; i--) {
                        path += ("$" + aryPath[i]);
                    }

                    xw.field("RESOURCEPATH", path);

                    if (isMethod)
                        xw.field("RESOURCETYPE", "Function");
                }

                BedrockPlugin.getPlugin().finishMessage(xw);
            }
        } catch (Exception e2) {
            BedrockPlugin.log("Exception : " + e2.getMessage() + ", " + e2.getClass().toString());
        }
    }
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockRenamer.java

License:Open Source License

/********************************************************************************/

void rename(String proj, String bid, String file, int start, int end, String name, String handle,
        String newname, boolean keeporig, boolean getters, boolean setters, boolean dohier, boolean qual,
        boolean refs, boolean dosimilar, boolean textocc, boolean doedit, String filespat, IvyXmlWriter xw)
        throws BedrockException {
    ICompilationUnit icu = our_plugin.getCompilationUnit(proj, file);

    IJavaElement[] elts;/*  ww w .j  a v  a 2  s.  co m*/
    try {
        elts = icu.codeSelect(start, end - start);
    } catch (JavaModelException e) {
        throw new BedrockException("Bad location: " + e, e);
    }

    IJavaElement relt = null;
    for (IJavaElement ije : elts) {
        if (handle != null && !handle.equals(ije.getHandleIdentifier()))
            continue;
        if (name != null && !name.equals(ije.getElementName()))
            continue;
        relt = ije;
        break;
    }
    if (relt == null)
        throw new BedrockException("Item to rename not found");

    BedrockPlugin.logD("RENAME CHECK " + relt.getElementType() + " " + relt.getParent().getElementType());

    switch (relt.getElementType()) {
    case IJavaElement.COMPILATION_UNIT:
        throw new BedrockException("Compilation unit renaming not supported yet");
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
    case IJavaElement.PACKAGE_FRAGMENT:
        throw new BedrockException("Package renaming not supported yet");
    case IJavaElement.FIELD:
    case IJavaElement.LOCAL_VARIABLE:
    case IJavaElement.TYPE_PARAMETER:
        break;
    case IJavaElement.METHOD:
        IMethod mthd = (IMethod) relt;
        try {
            if (mthd.isConstructor())
                throw new BedrockException("Constructor renaming not supported yet");
        } catch (JavaModelException e) {
        }
        break;
    case IJavaElement.TYPE:
        IJavaElement pelt = relt.getParent();
        if (pelt.getElementType() == IJavaElement.COMPILATION_UNIT) {
            ITypeRoot xcu = (ITypeRoot) pelt;
            if (relt == xcu.findPrimaryType()) {
                throw new BedrockException("Compilation unit renaming based on type not supported yet");
            }
        }
        break;
    default:
        throw new BedrockException("Invalid element type to rename");
    }

    SearchPattern sp = SearchPattern.createPattern(relt, IJavaSearchConstants.ALL_OCCURRENCES,
            SearchPattern.R_EXACT_MATCH);

    List<ICompilationUnit> worku = new ArrayList<ICompilationUnit>();
    for (IJavaElement je : BedrockJava.getAllProjects()) {
        our_plugin.getWorkingElements(je, worku);
    }
    ICompilationUnit[] work = new ICompilationUnit[worku.size()];
    work = worku.toArray(work);

    int fg = IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS;
    IJavaSearchScope scp = SearchEngine.createJavaSearchScope(work, fg);

    SearchEngine se = new SearchEngine(work);
    SearchParticipant[] parts = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
    FindHandler fh = new FindHandler(xw, null);

    try {
        se.search(sp, parts, scp, fh, null);
    } catch (CoreException e) {
        throw new BedrockException("Problem doing find all search: " + e, e);
    }

    BedrockPlugin.logD("RENAME RESULT = " + xw.toString());
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockUtil.java

License:Open Source License

private static void outputJavaElementImpl(IJavaElement elt, Set<String> files, boolean children,
        IvyXmlWriter xw) {/*from  ww w .  j  a  v  a2  s.  co  m*/
    if (elt == null)
        return;

    String close = null;

    switch (elt.getElementType()) {
    case IJavaElement.CLASS_FILE:
        return;
    case IJavaElement.PACKAGE_FRAGMENT:
        IOpenable opn = (IOpenable) elt;
        if (!opn.isOpen()) {
            try {
                opn.open(null);
            } catch (JavaModelException e) {
                BedrockPlugin.logE("Package framgent " + elt.getElementName() + " not open");
                return;
            }
        }
        try {
            outputNameDetails((IPackageFragment) elt, xw);
        } catch (JavaModelException e) {
        }
        break;
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
        IPackageFragmentRoot pfr = (IPackageFragmentRoot) elt;
        try {
            if (!pfr.isOpen() && pfr.getKind() == IPackageFragmentRoot.K_SOURCE) {
                pfr.open(null);
            }
        } catch (JavaModelException e) {
            return;
        }
        outputNameDetails(pfr, xw);
        break;
    case IJavaElement.JAVA_PROJECT:
        IJavaProject ijp = (IJavaProject) elt;
        outputNameDetails(ijp, xw);
        break;
    case IJavaElement.JAVA_MODEL:
    case IJavaElement.IMPORT_CONTAINER:
    case IJavaElement.IMPORT_DECLARATION:
    case IJavaElement.TYPE_PARAMETER:
    default:
        break;
    case IJavaElement.COMPILATION_UNIT:
        IProject ip = elt.getJavaProject().getProject();
        File f = getFileForPath(elt.getPath(), ip);
        if (files != null && !files.contains(f.getPath()) && !files.contains(f.getAbsolutePath())) {
            return;
        }
        xw.begin("FILE");
        xw.textElement("PATH", f.getAbsolutePath());
        String root = getRootForPath(elt.getPath(), ip);
        if (root != null)
            xw.textElement("PATHROOT", root);
        close = "FILE";
        break;
    case IJavaElement.TYPE:
        try {
            outputNameDetails((IType) elt, xw);
        } catch (JavaModelException e) {
        }
        break;
    case IJavaElement.FIELD:
        try {
            outputNameDetails((IField) elt, xw);
        } catch (JavaModelException e) {
        }
        break;
    case IJavaElement.METHOD:
        try {
            outputNameDetails((IMethod) elt, xw);
        } catch (JavaModelException e) {
        }
        break;
    case IJavaElement.INITIALIZER:
        outputNameDetails((IInitializer) elt, xw);
        break;
    case IJavaElement.PACKAGE_DECLARATION:
        outputNameDetails((IPackageDeclaration) elt, xw);
        break;
    case IJavaElement.LOCAL_VARIABLE:
        outputNameDetails((ILocalVariable) elt, xw);
        break;
    }

    if (children && elt instanceof IParent) {
        try {
            for (IJavaElement c : ((IParent) elt).getChildren()) {
                outputJavaElementImpl(c, files, children, xw);
            }
        } catch (JavaModelException e) {
        }
    }

    if (close != null)
        xw.end(close);
}

From source file:edu.buffalo.cse.green.editor.action.refactor.RefactorRenameParticipant.java

License:Open Source License

@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    if (!(getProcessor() instanceof RenameProcessor)) {
        return null;
    }/*from  w  ww .  j  a v  a 2 s. co  m*/

    CompositeChange change = null; //Allows the return of a null change if no applicable changes are found.
    IJavaElement element = ((IJavaElement) (getProcessor()).getElements()[0]);
    String oldName = element.getElementName();
    oldName = oldName.replace(".java", "");
    String handle = element.getHandleIdentifier();
    String newName = ((JavaRenameProcessor) getProcessor()).getNewElementName();
    newName = newName.replace(".java", "");
    ArrayList<HandleNode> handleList = new ArrayList<HandleNode>();

    String handleCopy = handle;
    char prefix = handleCopy.charAt(0);
    handleCopy = handleCopy.substring(1);
    for (int j = 0; j < handleCopy.length(); j++) {
        if (HANDLE_PREFIXES.contains(handleCopy.charAt(j) + "")) {
            handleList.add(new HandleNode(prefix + handleCopy.substring(0, j)));
            prefix = handleCopy.charAt(j);
            handleCopy = handleCopy.substring(j + 1);
            j = 0;
        }
    }
    handleList.add(new HandleNode(prefix + handleCopy));
    handleCopy = "";

    Iterator<HandleNode> itr = handleList.iterator();

    while (itr.hasNext()) {
        HandleNode node = itr.next();
        //         if(node.getName().contains(".")) {
        //            if((node.getName()).substring(0, node.getName().indexOf('.')) == oldName) {
        //               node.setName(newName + ".java");
        //            }
        //         }
        if (node.getName().equals(oldName)) {
            node.setName(newName);
        }
    }
    Iterator<HandleNode> itr2 = handleList.iterator();
    String newHandle = "";
    while (itr2.hasNext()) {
        HandleNode node = itr2.next();
        newHandle += node.toString();
    }

    //      if(newName.indexOf('.') != -1) { //To handle type names that include .java
    //         if(oldName.contains(".java")) {
    //            oldName = oldName.substring(0, oldName.indexOf(".java"));
    //         }
    //         newName = newName.substring(0, newName.indexOf('.'));
    //      }

    //Assumes project is open and exists (which should be the case if the element
    //was able to be selected)
    IProject project = element.getResource().getProject();
    ArrayList<IFile> greenFiles = ResourceUtil.getGreenFiles(project);

    for (IFile file : greenFiles) {
        BufferedReader br = new BufferedReader(new InputStreamReader(file.getContents()));
        String fileText = "";
        String line = null;
        try {
            while ((line = br.readLine()) != null) {
                fileText += line + '\n';
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        //Starting index of element handle
        int[] handleIndices = ResourceUtil.findAllOccurrences(fileText, handle);
        //         ArrayList<Integer> offsets = new ArrayList<Integer>();

        if (change == null) { //Creates a new Change object if necessary
            change = new CompositeChange("Change reference '" + oldName + "' to '" + newName + "'.");
        }
        TextFileChange result = new TextFileChange(file.getName(), file);
        MultiTextEdit fileChangeRootEdit = new MultiTextEdit();
        result.setEdit(fileChangeRootEdit);

        for (int i = 0; i < handleIndices.length; i++) {
            ReplaceEdit edit = new ReplaceEdit(handleIndices[i], handle.length(), newHandle);
            fileChangeRootEdit.addChild(edit);
            change.add(result);
        }

        //         for(int i = 0; i < handleIndices.length; i++) {
        //            int[] tempOffsets = ResourceUtil.findAllOccurrences(handle, oldName);
        //            for(int j = 0; j < tempOffsets.length; j++) {
        //               offsets.add(new Integer(handleIndices[i] + tempOffsets[j]));
        //            }
        //         }

        //         if(!offsets.isEmpty()) { //Changes exist
        //            if(change == null) { //Creates a new Change object if necessary
        //               change = new CompositeChange("Change reference '" + oldName + "' to '" + newName + "'.");
        //            }
        //            
        //            TextFileChange result = new TextFileChange(file.getName(), file);
        //            MultiTextEdit fileChangeRootEdit = new MultiTextEdit();
        //            result.setEdit(fileChangeRootEdit);
        //
        //            for(Integer offset : offsets) {
        //               ReplaceEdit edit = new ReplaceEdit(offset.intValue(), oldName.length(), newName);
        //               fileChangeRootEdit.addChild(edit);
        //            }
        //            change.add(result);
        //         }
    }
    return change;
}

From source file:edu.clarkson.serl.critic.loader.SootClassLoader.java

License:Open Source License

/**
 * The method traverses all of the project types in depth-first order 
 * including inner and anonymous types and loads them in Soot. 
 * /*from  w w  w .  jav  a 2  s.co  m*/
 * 
 * @param monitor The progress monitor.
 * @throws Exception Propagated from JDT APIs.
 */
public void process(IProgressMonitor subMonitor) throws Exception {
    IJavaProject project = CriticPlugin.getIJavaProject();
    IPackageFragmentRoot[] packageFragmentRoots = project.getPackageFragmentRoots();
    subMonitor.beginTask("Loading " + project.getElementName() + " ...", 2);

    SubProgressMonitor monitor = new SubProgressMonitor(subMonitor, 1);
    monitor.beginTask("Loading packages ... ", packageFragmentRoots.length + 1);

    for (IPackageFragmentRoot pkgFragRoot : packageFragmentRoots) {
        if (pkgFragRoot.getKind() == IPackageFragmentRoot.K_SOURCE) {
            IJavaElement[] pkgFrags = (IJavaElement[]) pkgFragRoot.getChildren();
            for (IJavaElement pkgFrag : pkgFrags) {
                if (monitor.isCanceled())
                    return;

                monitor.subTask("Loading classes in " + pkgFrag.getElementName());

                if (pkgFrag.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
                    IPackageFragment pkgFragment = (IPackageFragment) pkgFrag;
                    IJavaElement[] children = pkgFragment.getChildren();
                    for (IJavaElement anElement : children) {
                        if (monitor.isCanceled())
                            return;

                        // Make sure its a java file
                        if (anElement.getElementType() == IJavaElement.COMPILATION_UNIT) {
                            this.dfsDomTree(anElement, monitor);
                        }
                    }
                }
            }
        }
        monitor.worked(1);
    }

    // Load the necessary classes after all of the classes have been loaded.
    Scene.v().loadNecessaryClasses();
    monitor.done();

    // Create an instance of Interpreter before we process anything further
    Interpreter.instance();

    monitor = new SubProgressMonitor(subMonitor, 1);
    monitor.beginTask("Configuring entry points ... ", this.getAllSootClasses().size());

    for (SootClass c : this.getAllSootClasses()) {
        ExtensionManager manager = ExtensionManager.instance();
        // Configure entry methods for extension plugin
        for (SootMethod method : c.getMethods()) {
            if (monitor.isCanceled())
                return;

            manager.checkEntryMethod(method, monitor);
            monitor.worked(1);
        }
    }
    monitor.done();
}

From source file:edu.cmu.cs.crystal.internal.WorkspaceUtilities.java

License:Open Source License

/**
 * Walks up the Java model hierarchy and separates the names of encountered
 * elements by forward slashes//w  w  w . jav  a 2 s  . c om
 * @param element
 * @return Symbolic name of the given Java element relative to the workspace root 
 */
public static String getWorkspaceRelativeName(IJavaElement element) {
    String result = element.getElementName();
    while (element.getParent() != null) {
        element = element.getParent();
        result = element.getElementName() + "/" + result;
    }
    return result;
}

From source file:edu.illinois.jflow.editor.enhancements.JFlowJavaFoldingStructureProvider.java

License:Open Source License

private boolean isNestedDataflowMessagingRunnableMethod(IJavaElement element) {
    if (element.getElementType() == IJavaElement.METHOD) {
        IMethod method = (IMethod) element;
        if (isDataflowMessagingRunnable(method.getParent())) {
            if (element.getElementName().matches(ExtractClosureRefactoring.CLOSURE_METHOD)) {
                return true;
            }/*  w w w.j a  v a 2s.  c o  m*/
        }
    }
    return false;
}