Search in sources :

Example 11 with IMember

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

the class AbstractJavaCompletionProposal method getAdditionalProposalInfo.

/*
	 * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension5#getAdditionalProposalInfo(org.eclipse.core.runtime.IProgressMonitor)
	 */
public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
    if (getProposalInfo() != null) {
        String info = getProposalInfo().getInfo(monitor);
        if (info != null && info.length() > 0) {
            StringBuffer buffer = new StringBuffer();
            HTMLPrinter.insertPageProlog(buffer, 0, getCSSStyles());
            buffer.append(info);
            IJavaElement element = null;
            try {
                element = getProposalInfo().getJavaElement();
                if (element instanceof IMember) {
                //TODO
                //						String base= JavaDocLocations.getBaseURL(element, ((IMember)element).isBinary());
                //						if (base != null) {
                //							int endHeadIdx= buffer.indexOf("</head>"); //$NON-NLS-1$
                //							buffer.insert(endHeadIdx, "\n<base href='" + base + "'>\n"); //$NON-NLS-1$ //$NON-NLS-2$
                //						}
                }
            } catch (JavaModelException e) {
                JavaPlugin.log(e);
            }
            HTMLPrinter.addPageEpilog(buffer);
            info = buffer.toString();
            return new JavadocBrowserInformationControlInput(info);
        }
    }
    return null;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaModelException(org.eclipse.jdt.core.JavaModelException) JavadocBrowserInformationControlInput(org.eclipse.jdt.internal.ui.text.java.hover.JavadocBrowserInformationControlInput) StyledString(org.eclipse.jface.viewers.StyledString) IMember(org.eclipse.jdt.core.IMember)

Example 12 with IMember

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

the class JavaElementImageProvider method computeJavaAdornmentFlags.

// ---- Methods to compute the adornments flags ---------------------------------
private int computeJavaAdornmentFlags(IJavaElement element, int renderFlags) {
    int flags = 0;
    if (showOverlayIcons(renderFlags)) {
        try {
            if (element instanceof IMember) {
                IMember member = (IMember) element;
                int modifiers = member.getFlags();
                if (confirmAbstract(member) && JdtFlags.isAbstract(member))
                    flags |= JavaElementImageDescriptor.ABSTRACT;
                if (Flags.isFinal(modifiers) || isInterfaceOrAnnotationField(member) || isEnumConstant(member, modifiers))
                    flags |= JavaElementImageDescriptor.FINAL;
                if (Flags.isStatic(modifiers) || isInterfaceOrAnnotationFieldOrType(member) || isEnumConstant(member, modifiers))
                    flags |= JavaElementImageDescriptor.STATIC;
                if (Flags.isDeprecated(modifiers))
                    flags |= JavaElementImageDescriptor.DEPRECATED;
                int elementType = element.getElementType();
                if (elementType == IJavaElement.METHOD) {
                    if (((IMethod) element).isConstructor())
                        flags |= JavaElementImageDescriptor.CONSTRUCTOR;
                    if (// collides with 'super' flag
                    Flags.isSynchronized(modifiers))
                        flags |= JavaElementImageDescriptor.SYNCHRONIZED;
                    if (Flags.isNative(modifiers))
                        flags |= JavaElementImageDescriptor.NATIVE;
                    if (Flags.isDefaultMethod(modifiers))
                        flags |= JavaElementImageDescriptor.DEFAULT_METHOD;
                    if (Flags.isAnnnotationDefault(modifiers))
                        flags |= JavaElementImageDescriptor.ANNOTATION_DEFAULT;
                }
                if (member.getElementType() == IJavaElement.TYPE) {
                    if (JavaModelUtil.hasMainMethod((IType) member)) {
                        flags |= JavaElementImageDescriptor.RUNNABLE;
                    }
                }
                if (member.getElementType() == IJavaElement.FIELD) {
                    if (Flags.isVolatile(modifiers))
                        flags |= JavaElementImageDescriptor.VOLATILE;
                    if (Flags.isTransient(modifiers))
                        flags |= JavaElementImageDescriptor.TRANSIENT;
                }
            } else if (element instanceof ILocalVariable && Flags.isFinal(((ILocalVariable) element).getFlags())) {
                flags |= JavaElementImageDescriptor.FINAL;
            }
        } catch (JavaModelException e) {
        // do nothing. Can't compute runnable adornment or get flags
        }
    }
    return flags;
}
Also used : ILocalVariable(org.eclipse.jdt.core.ILocalVariable) JavaModelException(org.eclipse.jdt.core.JavaModelException) IMethod(org.eclipse.jdt.core.IMethod) IMember(org.eclipse.jdt.core.IMember) Point(org.eclipse.swt.graphics.Point)

Example 13 with IMember

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

the class JavaSearchScope method add.

/**
     * Add an element to the java search scope.
     * @param element The element we want to add to current java search scope
     * @throws JavaModelException May happen if some Java Model info are not available
     */
public void add(IJavaElement element) throws JavaModelException {
    IPath containerPath = null;
    String containerPathToString = null;
    PackageFragmentRoot root = null;
    int includeMask = SOURCES | APPLICATION_LIBRARIES | SYSTEM_LIBRARIES;
    switch(element.getElementType()) {
        case IJavaElement.JAVA_MODEL:
            // a workspace sope should be used
            break;
        case IJavaElement.JAVA_PROJECT:
            add((JavaProject) element, null, includeMask, new HashSet(2), new HashSet(2), null);
            break;
        case IJavaElement.PACKAGE_FRAGMENT_ROOT:
            root = (PackageFragmentRoot) element;
            IPath rootPath = root.internalPath();
            containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath;
            containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
            IResource rootResource = root.resource();
            String projectPath = root.getJavaProject().getPath().toString();
            if (rootResource != null && rootResource.isAccessible()) {
                String relativePath = Util.relativePath(rootResource.getFullPath(), containerPath.segmentCount());
                add(projectPath, relativePath, containerPathToString, false, /*not a package*/
                null);
            } else {
                //$NON-NLS-1$
                add(projectPath, "", containerPathToString, false, /*not a package*/
                null);
            }
            break;
        case IJavaElement.PACKAGE_FRAGMENT:
            root = (PackageFragmentRoot) element.getParent();
            projectPath = root.getJavaProject().getPath().toString();
            if (root.isArchive()) {
                String relativePath = Util.concatWith(((PackageFragment) element).names, '/');
                containerPath = root.getPath();
                containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
                add(projectPath, relativePath, containerPathToString, true, /*package*/
                null);
            } else {
                IResource resource = ((JavaElement) element).resource();
                if (resource != null) {
                    if (resource.isAccessible()) {
                        containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.internalPath();
                    } else {
                        // for working copies, get resource container full path
                        containerPath = resource.getParent().getFullPath();
                    }
                    containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
                    String relativePath = Util.relativePath(resource.getFullPath(), containerPath.segmentCount());
                    add(projectPath, relativePath, containerPathToString, true, /*package*/
                    null);
                }
            }
            break;
        default:
            // remember sub-cu (or sub-class file) java elements
            if (element instanceof IMember) {
                if (this.elements == null) {
                    this.elements = new ArrayList();
                }
                this.elements.add(element);
            }
            root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
            projectPath = root.getJavaProject().getPath().toString();
            String relativePath;
            if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
                containerPath = root.getParent().getPath();
                relativePath = Util.relativePath(getPath(element, false), root.getJavaProject().getPath().segmentCount());
            } else {
                containerPath = root.internalPath();
                relativePath = getPath(element, true).toString();
            }
            containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
            add(projectPath, relativePath, containerPathToString, false, /*not a package*/
            null);
    }
    if (root != null)
        addEnclosingProjectOrJar(root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.getPath());
}
Also used : PackageFragmentRoot(org.eclipse.jdt.internal.core.PackageFragmentRoot) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) JavaElement(org.eclipse.jdt.internal.core.JavaElement) IJavaElement(org.eclipse.jdt.core.IJavaElement) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) IMember(org.eclipse.jdt.core.IMember) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Example 14 with IMember

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

the class SourceMapper method getNameRange.

/**
     * Returns the SourceRange for the name of the given element, or
     * {-1, -1} if no source range is known for the name of the element.
     */
public SourceRange getNameRange(IJavaElement element) {
    switch(element.getElementType()) {
        case IJavaElement.METHOD:
            if (((IMember) element).isBinary()) {
                IJavaElement[] el = getUnqualifiedMethodHandle((IMethod) element, false);
                if (el[1] != null && this.sourceRanges.get(el[0]) == null) {
                    element = getUnqualifiedMethodHandle((IMethod) element, true)[0];
                } else {
                    element = el[0];
                }
            }
            break;
        case IJavaElement.TYPE_PARAMETER:
            IJavaElement parent = element.getParent();
            if (parent.getElementType() == IJavaElement.METHOD) {
                IMethod method = (IMethod) parent;
                if (method.isBinary()) {
                    IJavaElement[] el = getUnqualifiedMethodHandle(method, false);
                    if (el[1] != null && this.sourceRanges.get(el[0]) == null) {
                        method = (IMethod) getUnqualifiedMethodHandle(method, true)[0];
                    } else {
                        method = (IMethod) el[0];
                    }
                    element = method.getTypeParameter(element.getElementName());
                }
            }
            break;
        case IJavaElement.LOCAL_VARIABLE:
            LocalVariableElementKey key = new LocalVariableElementKey(element.getParent(), element.getElementName());
            SourceRange[] ranges = (SourceRange[]) this.parametersRanges.get(key);
            if (ranges == null) {
                return UNKNOWN_RANGE;
            } else {
                return ranges[1];
            }
    }
    SourceRange[] ranges = (SourceRange[]) this.sourceRanges.get(element);
    if (ranges == null) {
        return UNKNOWN_RANGE;
    } else {
        return ranges[1];
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IMethod(org.eclipse.jdt.core.IMethod) ISourceRange(org.eclipse.jdt.core.ISourceRange) SourceRange(org.eclipse.jdt.core.SourceRange) IMember(org.eclipse.jdt.core.IMember)

Example 15 with IMember

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

the class IntroduceIndirectionRefactoring method adjustVisibility.

private RefactoringStatus adjustVisibility(IMember whoToAdjust, ModifierKeyword neededVisibility, boolean alsoIncreaseEnclosing, IProgressMonitor monitor) throws CoreException {
    Map<IMember, IncomingMemberVisibilityAdjustment> adjustments;
    if (isRewriteKept(whoToAdjust.getCompilationUnit()))
        adjustments = fIntermediaryAdjustments;
    else
        adjustments = new HashMap<IMember, IncomingMemberVisibilityAdjustment>();
    int existingAdjustments = adjustments.size();
    addAdjustment(whoToAdjust, neededVisibility, adjustments);
    if (alsoIncreaseEnclosing)
        while (whoToAdjust.getDeclaringType() != null) {
            whoToAdjust = whoToAdjust.getDeclaringType();
            addAdjustment(whoToAdjust, neededVisibility, adjustments);
        }
    boolean hasNewAdjustments = (adjustments.size() - existingAdjustments) > 0;
    if (hasNewAdjustments && ((whoToAdjust.isReadOnly() || whoToAdjust.isBinary())))
        return RefactoringStatus.createErrorStatus(Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_cannot_update_binary_target_visibility, new String[] { JavaElementLabels.getElementLabel(whoToAdjust, JavaElementLabels.ALL_DEFAULT) }), JavaStatusContext.create(whoToAdjust));
    RefactoringStatus status = new RefactoringStatus();
    // Don't create a rewrite if it is not necessary
    if (!hasNewAdjustments)
        return status;
    try {
        monitor.beginTask(RefactoringCoreMessages.MemberVisibilityAdjustor_adjusting, 2);
        Map<ICompilationUnit, CompilationUnitRewrite> rewrites;
        if (!isRewriteKept(whoToAdjust.getCompilationUnit())) {
            CompilationUnitRewrite rewrite = new CompilationUnitRewrite(whoToAdjust.getCompilationUnit());
            rewrite.setResolveBindings(false);
            rewrites = new HashMap<ICompilationUnit, CompilationUnitRewrite>();
            rewrites.put(whoToAdjust.getCompilationUnit(), rewrite);
            status.merge(rewriteVisibility(adjustments, rewrites, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)));
            rewrite.attachChange((CompilationUnitChange) fTextChangeManager.get(whoToAdjust.getCompilationUnit()), true, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
        }
    } finally {
        monitor.done();
    }
    return status;
}
Also used : CompilationUnitRewrite(org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite) IncomingMemberVisibilityAdjustment(org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor.IncomingMemberVisibilityAdjustment) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) HashMap(java.util.HashMap) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IMember(org.eclipse.jdt.core.IMember) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Aggregations

IMember (org.eclipse.jdt.core.IMember)34 IType (org.eclipse.jdt.core.IType)16 IJavaElement (org.eclipse.jdt.core.IJavaElement)14 IMethod (org.eclipse.jdt.core.IMethod)13 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)12 JavaModelException (org.eclipse.jdt.core.JavaModelException)6 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)5 List (java.util.List)4 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)4 IField (org.eclipse.jdt.core.IField)4 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)4 CompilationUnitRewrite (org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite)4 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 ISourceRange (org.eclipse.jdt.core.ISourceRange)3 ASTNode (org.eclipse.jdt.core.dom.ASTNode)3 HashMap (java.util.HashMap)2 IInitializer (org.eclipse.jdt.core.IInitializer)2