Example usage for org.eclipse.jdt.core IType getPath

List of usage examples for org.eclipse.jdt.core IType getPath

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IType getPath.

Prototype

IPath getPath();

Source Link

Document

Returns the path to the innermost resource enclosing this element.

Usage

From source file:ch.qos.logback.beagle.util.EditorUtil.java

License:Open Source License

public static void openInEditor(StackTraceElement ste) {
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();

    IType type;
    IProject project;/*from   w w  w  .  j  a va 2  s . c o m*/
    for (int i = 0; i < projects.length; i++) {
        project = projects[i];
        if (project.isOpen()) {
            try {
                IJavaProject javaProject = JavaCore.create(project);
                String className = ste.getClassName();
                if (className == null) {
                    return;
                }
                type = findType(javaProject, className);
                if (type != null) {
                    String path = type.getPath().toString();
                    if (path.startsWith('/' + project.getName())) {
                        path = path.substring(project.getName().length() + 1);
                    }
                    IFile file = project.getFile(path);
                    if (file.exists()) {
                        openInEditor(file, ste.getLineNumber());
                    }
                }
            } catch (JavaModelException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.HierarchyScope.java

License:Open Source License

public HierarchyScope(IType type, WorkingCopyOwner owner) throws JavaModelException {
    this.focusType = type;
    this.owner = owner;

    this.enclosingProjectsAndJars = computeProjectsAndJars(type);

    // resource path
    IPackageFragmentRoot root = (IPackageFragmentRoot) type.getPackageFragment().getParent();
    if (root.isArchive()) {
        IPath jarPath = root.getPath();//  w  w w  . ja v a 2 s.c  o  m
        Object target = JavaModel.getTarget(jarPath, true);
        String zipFileName;
        if (target instanceof IFile) {
            // internal jar
            zipFileName = jarPath.toString();
        } else if (target instanceof File) {
            // external jar
            zipFileName = ((File) target).getPath();
        } else {
            return; // unknown target
        }
        this.focusPath = zipFileName + JAR_FILE_ENTRY_SEPARATOR + type.getFullyQualifiedName().replace('.', '/')
                + SUFFIX_STRING_class;
    } else {
        this.focusPath = type.getPath().toString();
    }

    this.needsRefresh = true;

    //disabled for now as this could be expensive
    //JavaModelManager.getJavaModelManager().rememberScope(this);
}

From source file:com.nitorcreations.robotframework.eclipseide.editors.ResourceManager.java

License:Apache License

@Override
public Map<IFile, IPath> getJavaFiles(String fullyQualifiedName) {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    Map<IFile, IPath> files = new LinkedHashMap<IFile, IPath>();
    for (IProject project : root.getProjects()) {
        try {//from   w  w w .  j a va 2 s.c o  m
            IJavaProject javaProject = JavaCore.create(project);
            IType type = javaProject.findType(fullyQualifiedName);
            if (type != null) {
                IFile file = root.getFile(type.getPath());
                if (file.exists()) {
                    IJavaElement ancestor = type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
                    IPath path = ancestor != null ? ancestor.getPath() : type.getPath();
                    files.put(file, path);
                }
            }
        } catch (JavaModelException e) {
            // non-Java or unopened projects are simple skipped
        }
    }
    return files;
}

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

License:Open Source License

private void outputType(IType typ, IJavaProject jp, IvyXmlWriter xw) throws JavaModelException {
    xw.begin("TYPE");
    xw.field("NAME", typ.getFullyQualifiedName());
    IPath ip = typ.getPath();
    File f = BedrockUtil.getFileForPath(ip, jp.getProject());
    if (f.exists())
        xw.field("SOURCE", f.getAbsolutePath());
    File bf = findBinaryFor(jp, typ);
    if (bf != null)
        xw.field("BINARY", bf.getAbsolutePath());
    xw.end("TYPE");

    for (IType ntyp : typ.getTypes()) {
        outputType(ntyp, jp, xw);//from   w  w  w  . j  a  v a  2  s.  co  m
    }
}

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

License:Open Source License

static String findFileForClass(String cls) {
    BedrockPlugin bp = BedrockPlugin.getPlugin();
    BedrockProject bpp = bp.getProjectManager();
    for (IProject ip : bpp.getOpenProjects()) {
        IJavaProject ijp = JavaCore.create(ip);
        try {/*from   ww w . ja v  a2  s  . c  o  m*/
            IType ity = ijp.findType(cls);
            if (ity == null && cls.indexOf("$") > 0) {
                ity = ijp.findType(cls.replace('$', '.'));
                if (ity == null) {
                    int idx = cls.indexOf("$");
                    ity = ijp.findType(cls.substring(0, idx));
                }
            }
            if (ity != null) {
                IPath pt = ity.getPath();
                File f = getFileForPath(pt, ip);
                if (f.exists())
                    return f.getAbsolutePath();
            }
        } catch (JavaModelException e) {
        }
    }

    return null;
}

From source file:edu.washington.cs.cupid.scripting.java.wizards.JavaCapabilityWizardPage.java

License:Open Source License

@Override
public void createControl(final Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);// w ww.  j a  v a  2s  .  c o  m
    layout.numColumns = 3;
    layout.verticalSpacing = 9;

    addLabel(container, "&Name:");
    nameText = new Text(container, SWT.BORDER | SWT.SINGLE);
    initText(nameText, 2);
    nameText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(final ModifyEvent e) {
            validateName();
        }
    });

    addLabel(container, "&Description:");
    descriptionText = new Text(container, SWT.BORDER | SWT.SINGLE);
    initText(descriptionText, 2);

    addLabel(container, "&Parameter Type:");
    parameterType = new Text(container, SWT.BORDER | SWT.SINGLE);

    final Button inputSelect = new Button(container, SWT.PUSH);

    inputSelect.addMouseListener(new MouseListener() {
        @Override
        public void mouseDoubleClick(final MouseEvent e) {
            // NO OP
        }

        @Override
        public void mouseDown(final MouseEvent e) {
            // NO OP
        }

        @Override
        public void mouseUp(final MouseEvent e) {
            Object[] objs = showTypeDialog();

            if (objs != null) {
                IType type = (IType) objs[0];
                parameterTypeReference = type.getPath();
                parameterType.setText(type.getFullyQualifiedName());
            }
        }
    });

    inputSelect.setText("Select");
    initText(parameterType, 1);

    addLabel(container, "&Output Type:");
    outputType = new Text(container, SWT.BORDER | SWT.SINGLE);
    final Button outputSelect = new Button(container, SWT.PUSH);
    outputSelect.setText("Select");
    initText(outputType, 1);

    outputSelect.addMouseListener(new MouseListener() {
        @Override
        public void mouseDoubleClick(final MouseEvent e) {
            // NO OP
        }

        @Override
        public void mouseDown(final MouseEvent e) {
            // NO OP
        }

        @Override
        public void mouseUp(final MouseEvent e) {
            Object[] objs = showTypeDialog();
            if (objs != null) {
                IType type = (IType) objs[0];
                outputTypeReference = type.getPath();
                outputType.setText(type.getFullyQualifiedName());
            }
        }
    });

    initialize();
    dialogChanged();
    setControl(container);
}

From source file:org.cubictest.exporters.selenium.ui.SeleniumCustomStepSection.java

License:Open Source License

private void createBrowseClassButton(Composite composite) {
    browseClassButton = new Button(composite, SWT.PUSH);
    browseClassButton.setText("Browse...");
    browseClassButton.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent e) {
        }//from w ww  .  ja v a 2s .  c o m

        public void widgetSelected(SelectionEvent e) {
            Shell shell = new Shell();
            SelectionDialog dialog;
            try {
                dialog = JavaUI.createTypeDialog(shell, new ProgressMonitorDialog(shell),
                        SearchEngine.createWorkspaceScope(), IJavaElementSearchConstants.CONSIDER_CLASSES,
                        false);
                dialog.setTitle("Open ICustomTestStep implementation");
                if (dialog.open() == SelectionDialog.OK) {
                    IType result = (IType) dialog.getResult()[0];

                    ChangeCustomStepClassNameCommand command = new ChangeCustomStepClassNameCommand();
                    command.setCustomTestStepData(data);
                    command.setPath(result.getPath().toPortableString());
                    command.setDisplayText(result.getFullyQualifiedName());
                    getCommandStack().execute(command);
                }
            } catch (JavaModelException ex) {
                ErrorHandler.logAndShowErrorDialog(ex);
            }

        }
    });
    FormData layoutData = new FormData();
    layoutData.left = new FormAttachment(classText, 5);
    browseClassButton.setLayoutData(layoutData);
}

From source file:org.eclipse.che.jdt.JavaTypeHierarchy.java

License:Open Source License

private Type convertToTypeDTO(IType type) throws JavaModelException {
    Type dto = DtoFactory.newDto(Type.class);
    String typeName = type.getElementName();
    if (typeName.isEmpty()) {
        dto.setElementName("Anonymous in " + type.getParent().getElementName());
    } else {//from www .  j  a  v  a 2 s .c o  m
        dto.setElementName(type.getElementName());
    }
    if (type.isBinary()) {
        dto.setRootPath(type.getFullyQualifiedName());
        dto.setLibId(type.getAncestor(IPackageFragmentRoot.PACKAGE_FRAGMENT_ROOT).hashCode());
        dto.setBinary(true);
    } else {
        dto.setRootPath(type.getPath().toOSString());
        dto.setBinary(false);
    }
    setRange(dto, type);

    return dto;
}

From source file:org.eclipse.jst.jsp.core.internal.taglib.BuildPathClassLoader.java

License:Open Source License

protected Class findClass(String className) throws ClassNotFoundException {
    if (DEBUG)/*from  w  w w.  j  a  va  2 s.  c  o m*/
        System.out.println("finding: [" + className + "]"); //$NON-NLS-1$ //$NON-NLS-2$
    try {
        IType type = fProject.findType(className);
        int offset = -1;
        if (type == null && (offset = className.indexOf('$')) != -1) {
            // Internal classes from source files must be referenced by . instead of $
            String cls = className.substring(0, offset) + className.substring(offset).replace('$', '.');
            type = fProject.findType(cls);
        }
        if (type != null) {
            IPath path = null;
            IResource resource = type.getResource();

            if (resource != null)
                path = resource.getLocation();
            if (path == null)
                path = type.getPath();

            // needs to be compiled before we can load it
            if ("class".equalsIgnoreCase(path.getFileExtension())) {
                IFile file = null;

                if (resource != null && resource.getType() == IResource.FILE)
                    file = (IFile) resource;
                else
                    file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);

                if (file != null && file.isAccessible()) {
                    byte[] bytes = loadBytes(file);
                    return defineClass(className, bytes, 0, bytes.length);
                }
            }
            // Look up the class file based on the output location of the java project
            else if ("java".equalsIgnoreCase(path.getFileExtension()) && resource != null) { //$NON-NLS-1$
                if (resource.getProject() != null) {
                    IJavaProject jProject = JavaCore.create(resource.getProject());
                    String outputClass = StringUtils.replace(type.getFullyQualifiedName(), ".", "/") //$NON-NLS-1$//$NON-NLS-2$
                            .concat(".class"); //$NON-NLS-1$
                    IPath classPath = jProject.getOutputLocation().append(outputClass);
                    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(classPath);
                    if (file != null && file.isAccessible()) {
                        byte[] bytes = loadBytes(file);
                        return defineClass(className, bytes, 0, bytes.length);
                    }
                }
            } else if ("jar".equalsIgnoreCase(path.getFileExtension())) {
                String expectedFileName = StringUtils.replace(className, ".", "/").concat(".class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                byte[] bytes = getCachedInputStream(path.toOSString(), expectedFileName);
                return defineClass(className, bytes, 0, bytes.length);
            }
        }
    } catch (JavaModelException e) {
        Logger.logException(e);
    }
    return super.findClass(className);
}

From source file:org.eclipse.pde.api.tools.builder.tests.performance.IncrementalBuildTests.java

License:Open Source License

/**
 * Deploys an incremental build tests with the given summary, changing the
 * type in the given project./*  w ww  . j  a v a2  s  .  c  o m*/
 * 
 * @param summary human readable summary for the test
 * @param testname the name of the test, used to find the source
 * @param projectname the name of the project to deploy to incremental test
 *            to
 * @param typename the fully qualified name of the type to replace
 * @param problemids array of expected problem ids
 * 
 * @throws Exception if something bad happens, or if unexpected problems are
 *             found after a build
 */
protected void deployIncrementalPerformanceTest(String summary, String testname, String projectname,
        String typename, int[] problemids, int iterations) throws Exception {
    tagAsSummary(summary, Dimension.ELAPSED_PROCESS);

    // WARM-UP, must do full build with Java build to get the state
    System.out.println("Warm-up clean builds..."); //$NON-NLS-1$
    for (int i = 0; i < 2; i++) {
        cleanBuild();
        fullBuild();
    }

    // TEST
    System.out.println("Testing incremental build: [" + summary + "]..."); //$NON-NLS-1$ //$NON-NLS-2$
    long start = System.currentTimeMillis();
    IProject proj = getEnv().getWorkspace().getRoot().getProject(projectname);
    IType type = JavaCore.create(proj).findType(typename);
    IPath file = type.getPath();
    for (int i = 0; i < iterations; i++) {
        startMeasuring();
        updateWorkspaceFile(proj, file, getUpdateFilePath(testname, file.lastSegment()));
        stopMeasuring();
        // dispose the workspace baseline
        proj.touch(null);
        updateWorkspaceFile(proj, file, getRevertFilePath(testname, file.lastSegment()));
    }
    commitMeasurements();
    assertPerformance();
    System.out.println("done in: " + ((System.currentTimeMillis() - start) / 1000) + " seconds"); //$NON-NLS-1$ //$NON-NLS-2$
}