Search in sources :

Example 6 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class HandleFactory method getJarPkgFragmentRoot.

private PackageFragmentRoot getJarPkgFragmentRoot(IPath jarPath, Object target, IJavaProject[] projects) {
    for (int i = 0, projectCount = projects.length; i < projectCount; i++) {
        try {
            JavaProject javaProject = (JavaProject) projects[i];
            IClasspathEntry classpathEnty = javaProject.getClasspathEntryFor(jarPath);
            if (classpathEnty != null) {
                if (target instanceof IFile) {
                    // internal jar
                    return (PackageFragmentRoot) javaProject.getPackageFragmentRoot((IFile) target);
                } else {
                    // external jar
                    return (PackageFragmentRoot) javaProject.getPackageFragmentRoot0(jarPath);
                }
            }
        } catch (JavaModelException e) {
        // JavaModelException from getResolvedClasspath - a problem occurred while accessing project: nothing we can do, ignore
        }
    }
    return null;
}
Also used : JavaProject(org.eclipse.jdt.internal.core.JavaProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) PackageFragmentRoot(org.eclipse.jdt.internal.core.PackageFragmentRoot) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) JavaModelException(org.eclipse.jdt.core.JavaModelException) IFile(org.eclipse.core.resources.IFile) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Example 7 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class HandleFactory method getPkgFragmentRoot.

/**
	 * Returns the package fragment root that contains the given resource path.
	 */
private PackageFragmentRoot getPkgFragmentRoot(String pathString) {
    IPath path = new Path(pathString);
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    for (int i = 0, max = projects.length; i < max; i++) {
        try {
            IProject project = projects[i];
            if (!project.isAccessible() || !project.hasNature(JavaCore.NATURE_ID))
                continue;
            IJavaProject javaProject = this.javaModel.getJavaProject(project);
            IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
            for (int j = 0, rootCount = roots.length; j < rootCount; j++) {
                PackageFragmentRoot root = (PackageFragmentRoot) roots[j];
                if (root.internalPath().isPrefixOf(path) && !Util.isExcluded(path, root.fullInclusionPatternChars(), root.fullExclusionPatternChars(), false)) {
                    return root;
                }
            }
        } catch (CoreException e) {
        // CoreException from hasNature - should not happen since we check that the project is accessible
        // JavaModelException from getPackageFragmentRoots - a problem occured while accessing project: nothing we can do, ignore
        }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) PackageFragmentRoot(org.eclipse.jdt.internal.core.PackageFragmentRoot) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 8 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class ASTNodes method getNodeSource.

/**
     * Returns the source of the given node from the location where it was parsed.
     * @param node the node to get the source from
     * @param extendedRange if set, the extended ranges of the nodes should ne used
     * @param removeIndent if set, the indentation is removed.
     * @return return the source for the given node or null if accessing the source failed.
     */
public static String getNodeSource(ASTNode node, boolean extendedRange, boolean removeIndent) {
    ASTNode root = node.getRoot();
    if (root instanceof CompilationUnit) {
        CompilationUnit astRoot = (CompilationUnit) root;
        ITypeRoot typeRoot = astRoot.getTypeRoot();
        try {
            if (typeRoot != null && typeRoot.getBuffer() != null) {
                IBuffer buffer = typeRoot.getBuffer();
                int offset = extendedRange ? astRoot.getExtendedStartPosition(node) : node.getStartPosition();
                int length = extendedRange ? astRoot.getExtendedLength(node) : node.getLength();
                String str = buffer.getText(offset, length);
                if (removeIndent) {
                    IJavaProject project = typeRoot.getJavaProject();
                    int indent = StubUtility.getIndentUsed(buffer, node.getStartPosition(), project);
                    str = Strings.changeIndent(str, indent, project, new String(), typeRoot.findRecommendedLineSeparator());
                }
                return str;
            }
        } catch (JavaModelException e) {
        // ignore
        }
    }
    return null;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) ITypeRoot(org.eclipse.jdt.core.ITypeRoot) IBuffer(org.eclipse.jdt.core.IBuffer)

Example 9 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class StubUtility method getFileComment.

/*
	 * Don't use this method directly, use CodeGeneration.
	 * @see org.eclipse.jdt.ui.CodeGeneration#getFileComment(ICompilationUnit, String)
	 */
public static String getFileComment(ICompilationUnit cu, String lineDelimiter) throws CoreException {
    Template template = getCodeTemplate(CodeTemplateContextType.FILECOMMENT_ID, cu.getJavaProject());
    if (template == null) {
        return null;
    }
    IJavaProject project = cu.getJavaProject();
    CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), project, lineDelimiter);
    context.setCompilationUnitVariables(cu);
    context.setVariable(CodeTemplateContextType.TYPENAME, JavaCore.removeJavaLikeExtension(cu.getElementName()));
    return evaluateTemplate(context, template);
}
Also used : CodeTemplateContext(org.eclipse.jdt.internal.corext.template.java.CodeTemplateContext) IJavaProject(org.eclipse.jdt.core.IJavaProject) Template(org.eclipse.jface.text.templates.Template)

Example 10 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class RenameLocalVariableProcessor method createRefactoringDescriptor.

private RenameJavaElementDescriptor createRefactoringDescriptor() {
    String project = null;
    IJavaProject javaProject = fCu.getJavaProject();
    if (javaProject != null)
        project = javaProject.getElementName();
    final String header = Messages.format(RefactoringCoreMessages.RenameLocalVariableProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fCurrentName), JavaElementLabels.getElementLabel(fLocalVariable.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(fNewName) });
    final String description = Messages.format(RefactoringCoreMessages.RenameLocalVariableProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fCurrentName));
    final String comment = new JDTRefactoringDescriptorComment(project, this, header).asString();
    final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_LOCAL_VARIABLE);
    descriptor.setProject(project);
    descriptor.setDescription(description);
    descriptor.setComment(comment);
    descriptor.setFlags(RefactoringDescriptor.NONE);
    descriptor.setJavaElement(fLocalVariable);
    descriptor.setNewName(getNewElementName());
    descriptor.setUpdateReferences(fUpdateReferences);
    return descriptor;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)

Aggregations

IJavaProject (org.eclipse.jdt.core.IJavaProject)733 IProject (org.eclipse.core.resources.IProject)177 IFile (org.eclipse.core.resources.IFile)149 Test (org.junit.Test)142 CoreException (org.eclipse.core.runtime.CoreException)125 JavaModelException (org.eclipse.jdt.core.JavaModelException)124 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)122 IPath (org.eclipse.core.runtime.IPath)110 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)102 ArrayList (java.util.ArrayList)87 IFolder (org.eclipse.core.resources.IFolder)78 IResource (org.eclipse.core.resources.IResource)75 IJavaElement (org.eclipse.jdt.core.IJavaElement)62 IType (org.eclipse.jdt.core.IType)62 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)60 Path (org.eclipse.core.runtime.Path)57 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)55 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)41 StringInputStream (org.eclipse.xtext.util.StringInputStream)39 HashMap (java.util.HashMap)38