Search in sources :

Example 86 with JavaModelException

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

the class JavaElementImageProvider method getPackageFragmentIcon.

private ImageDescriptor getPackageFragmentIcon(IJavaElement element) throws JavaModelException {
    IPackageFragment fragment = (IPackageFragment) element;
    boolean containsJavaElements = false;
    try {
        containsJavaElements = fragment.hasChildren();
    } catch (JavaModelException e) {
    // assuming no children;
    }
    if (!containsJavaElements && (fragment.getNonJavaResources().length > 0))
        return JavaPluginImages.DESC_OBJS_EMPTY_PACKAGE_RESOURCES;
    else if (!containsJavaElements)
        return JavaPluginImages.DESC_OBJS_EMPTY_PACKAGE;
    return JavaPluginImages.DESC_OBJS_PACKAGE;
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) JavaModelException(org.eclipse.jdt.core.JavaModelException)

Example 87 with JavaModelException

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

the class JavaElementLabelComposer method appendInternalArchiveLabel.

private void appendInternalArchiveLabel(IPackageFragmentRoot root, long flags) {
    IResource resource = root.getResource();
    boolean rootQualified = getFlag(flags, JavaElementLabels.ROOT_QUALIFIED);
    if (rootQualified) {
        fBuffer.append(root.getPath().makeRelative().toString());
    } else {
        fBuffer.append(root.getElementName());
        int offset = fBuffer.length();
        boolean referencedPostQualified = getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED);
        if (referencedPostQualified && isReferenced(root)) {
            fBuffer.append(JavaElementLabels.CONCAT_STRING);
            fBuffer.append(resource.getParent().getFullPath().makeRelative().toString());
        } else if (getFlag(flags, JavaElementLabels.ROOT_POST_QUALIFIED)) {
            fBuffer.append(JavaElementLabels.CONCAT_STRING);
            fBuffer.append(root.getParent().getPath().makeRelative().toString());
        }
        if (referencedPostQualified) {
            try {
                IClasspathEntry referencingEntry = JavaModelUtil.getClasspathEntry(root).getReferencingEntry();
                if (referencingEntry != null) {
                    fBuffer.append(Messages.format(JavaUIMessages.JavaElementLabels_onClassPathOf, new Object[] { Name.CLASS_PATH.toString(), referencingEntry.getPath().lastSegment() }));
                }
            } catch (JavaModelException e) {
            // ignore
            }
        }
        if (getFlag(flags, JavaElementLabels.COLORIZE)) {
            fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE);
        }
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IResource(org.eclipse.core.resources.IResource)

Example 88 with JavaModelException

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

the class JavaElementLabelComposer method appendTypeParameterLabel.

/**
	 * Appends the styled label for a type parameter.
	 *
	 * @param typeParameter the element to render
	 * @param flags the rendering flags. Flags with names starting with 'T_' are considered.
	 */
public void appendTypeParameterLabel(ITypeParameter typeParameter, long flags) {
    try {
        appendTypeParameterWithBounds(typeParameter, flags);
        // post qualification
        if (getFlag(flags, JavaElementLabels.TP_POST_QUALIFIED)) {
            fBuffer.append(JavaElementLabels.CONCAT_STRING);
            IMember declaringMember = typeParameter.getDeclaringMember();
            appendElementLabel(declaringMember, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS));
        }
    } catch (JavaModelException e) {
        // NotExistsException will not reach this point
        JavaPlugin.log(e);
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IMember(org.eclipse.jdt.core.IMember)

Example 89 with JavaModelException

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

the class CompletionProposalCollector method createAnonymousTypeProposal.

private IJavaCompletionProposal createAnonymousTypeProposal(CompletionProposal proposal, JavaContentAssistInvocationContext invocationContext) {
    if (fCompilationUnit == null || fJavaProject == null)
        return null;
    char[] declarationKey = proposal.getDeclarationKey();
    if (declarationKey == null)
        return null;
    try {
        IJavaElement element = fJavaProject.findElement(new String(declarationKey), null);
        if (!(element instanceof IType))
            return null;
        IType type = (IType) element;
        String completion = String.valueOf(proposal.getCompletion());
        int start = proposal.getReplaceStart();
        int length = getLength(proposal);
        int relevance = computeRelevance(proposal);
        StyledString label = fLabelProvider.createAnonymousTypeLabel(proposal);
        JavaCompletionProposal javaProposal = new AnonymousTypeCompletionProposal(fJavaProject, fCompilationUnit, invocationContext, start, length, completion, label, String.valueOf(proposal.getDeclarationSignature()), type, relevance);
        javaProposal.setProposalInfo(new AnonymousTypeProposalInfo(fJavaProject, proposal));
        return javaProposal;
    } catch (JavaModelException e) {
        return null;
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaModelException(org.eclipse.jdt.core.JavaModelException) AnonymousTypeProposalInfo(org.eclipse.jdt.internal.ui.text.java.AnonymousTypeProposalInfo) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) AnonymousTypeCompletionProposal(org.eclipse.jdt.internal.ui.text.java.AnonymousTypeCompletionProposal) IType(org.eclipse.jdt.core.IType) JavaCompletionProposal(org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal) LazyJavaCompletionProposal(org.eclipse.jdt.internal.ui.text.java.LazyJavaCompletionProposal)

Example 90 with JavaModelException

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

the class JavaElementLabelComposer method appendExternalArchiveLabel.

private void appendExternalArchiveLabel(IPackageFragmentRoot root, long flags) {
    IPath path;
    IClasspathEntry classpathEntry = null;
    try {
        classpathEntry = JavaModelUtil.getClasspathEntry(root);
        IPath rawPath = classpathEntry.getPath();
        if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER && !rawPath.isAbsolute())
            path = rawPath;
        else
            path = root.getPath();
    } catch (JavaModelException e) {
        path = root.getPath();
    }
    if (getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED)) {
        int segements = path.segmentCount();
        if (segements > 0) {
            fBuffer.append(path.segment(segements - 1));
            int offset = fBuffer.length();
            if (segements > 1 || path.getDevice() != null) {
                fBuffer.append(JavaElementLabels.CONCAT_STRING);
                fBuffer.append(path.removeLastSegments(1).toOSString());
            }
            if (classpathEntry != null) {
                IClasspathEntry referencingEntry = classpathEntry.getReferencingEntry();
                if (referencingEntry != null) {
                    fBuffer.append(Messages.format(JavaUIMessages.JavaElementLabels_onClassPathOf, new Object[] { Name.CLASS_PATH.toString(), referencingEntry.getPath().lastSegment() }));
                }
            }
            if (getFlag(flags, JavaElementLabels.COLORIZE)) {
                fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE);
            }
        } else {
            fBuffer.append(path.toOSString());
        }
    } else {
        fBuffer.append(path.toOSString());
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Aggregations

JavaModelException (org.eclipse.jdt.core.JavaModelException)172 IJavaProject (org.eclipse.jdt.core.IJavaProject)44 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)41 IType (org.eclipse.jdt.core.IType)40 IJavaElement (org.eclipse.jdt.core.IJavaElement)35 CoreException (org.eclipse.core.runtime.CoreException)30 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)25 IPath (org.eclipse.core.runtime.IPath)24 ArrayList (java.util.ArrayList)21 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)17 IFile (org.eclipse.core.resources.IFile)15 IResource (org.eclipse.core.resources.IResource)15 HashMap (java.util.HashMap)14 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)13 IMethod (org.eclipse.jdt.core.IMethod)12 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)12 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)11 SimpleName (org.eclipse.jdt.core.dom.SimpleName)9 Iterator (java.util.Iterator)8 ISourceRange (org.eclipse.jdt.core.ISourceRange)8