Search in sources :

Example 51 with IJavaElement

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

the class RefactoringAvailabilityTester method isIntroduceFactoryAvailable.

public static boolean isIntroduceFactoryAvailable(final JavaTextSelection selection) throws JavaModelException {
    final IJavaElement[] elements = selection.resolveElementAtOffset();
    if (elements.length == 1 && elements[0] instanceof IMethod)
        return isIntroduceFactoryAvailable((IMethod) elements[0]);
    // there's no IMethod for the default constructor
    if (!Checks.isAvailable(selection.resolveEnclosingElement()))
        return false;
    ASTNode node = selection.resolveCoveringNode();
    if (node == null) {
        ASTNode[] selectedNodes = selection.resolveSelectedNodes();
        if (selectedNodes != null && selectedNodes.length == 1) {
            node = selectedNodes[0];
            if (node == null)
                return false;
        } else {
            return false;
        }
    }
    if (node.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION)
        return true;
    node = ASTNodes.getNormalizedNode(node);
    if (node.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY)
        return true;
    return false;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ASTNode(org.eclipse.jdt.core.dom.ASTNode) IMethod(org.eclipse.jdt.core.IMethod)

Example 52 with IJavaElement

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

the class RefactoringAvailabilityTester method isReplaceInvocationsAvailable.

public static boolean isReplaceInvocationsAvailable(final JavaTextSelection selection) throws JavaModelException {
    final IJavaElement[] elements = selection.resolveElementAtOffset();
    if (elements.length != 1)
        return false;
    IJavaElement element = elements[0];
    return (element instanceof IMethod) && isReplaceInvocationsAvailable(((IMethod) element));
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IMethod(org.eclipse.jdt.core.IMethod)

Example 53 with IJavaElement

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

the class JavaElementUtil method getPackageAndSubpackages.

/**
	 * @param pack a package fragment
	 * @return an array containing the given package and all subpackages
	 * @throws JavaModelException if getting the all sibling packages fails
	 */
public static IPackageFragment[] getPackageAndSubpackages(IPackageFragment pack) throws JavaModelException {
    if (pack.isDefaultPackage())
        return new IPackageFragment[] { pack };
    IPackageFragmentRoot root = (IPackageFragmentRoot) pack.getParent();
    IJavaElement[] allPackages = root.getChildren();
    ArrayList<IPackageFragment> subpackages = new ArrayList<IPackageFragment>();
    subpackages.add(pack);
    String prefix = pack.getElementName() + '.';
    for (int i = 0; i < allPackages.length; i++) {
        IPackageFragment currentPackage = (IPackageFragment) allPackages[i];
        if (currentPackage.getElementName().startsWith(prefix))
            subpackages.add(currentPackage);
    }
    return subpackages.toArray(new IPackageFragment[subpackages.size()]);
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) ArrayList(java.util.ArrayList) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 54 with IJavaElement

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

the class MemberVisibilityAdjustor method adjustOutgoingVisibility.

/**
	 * Adjusts the visibilities of the outgoing references from the member represented by the specified search result groups.
	 *
	 * @param groups the search result groups representing the references
	 * @param monitor the progress monitor to us
	 * @throws JavaModelException if the visibility could not be determined
	 */
private void adjustOutgoingVisibility(final SearchResultGroup[] groups, final IProgressMonitor monitor) throws JavaModelException {
    try {
        //$NON-NLS-1$
        monitor.beginTask("", groups.length);
        monitor.setTaskName(RefactoringCoreMessages.MemberVisibilityAdjustor_checking);
        IJavaElement element = null;
        SearchMatch[] matches = null;
        SearchResultGroup group = null;
        for (int index = 0; index < groups.length; index++) {
            group = groups[index];
            element = JavaCore.create(group.getResource());
            if (element instanceof ICompilationUnit) {
                matches = group.getSearchResults();
                for (int offset = 0; offset < matches.length; offset++) adjustOutgoingVisibility(matches[offset], new SubProgressMonitor(monitor, 1));
            }
            // else if (element != null)
            // fStatus.merge(RefactoringStatus.createStatus(fFailureSeverity, RefactoringCoreMessages.getFormattedString
            // ("MemberVisibilityAdjustor.binary.outgoing.project", new String[] { element.getJavaProject().getElementName(), getLabel
            // (fReferenced)}), null, null, RefactoringStatusEntry.NO_CODE, null)); //$NON-NLS-1$
            // else if (group.getResource() != null)
            // fStatus.merge(RefactoringStatus.createStatus(fFailureSeverity, RefactoringCoreMessages.getFormattedString
            // ("MemberVisibilityAdjustor.binary.outgoing.resource", new String[] { group.getResource().getName(), getLabel
            // (fReferenced)}), null, null, RefactoringStatusEntry.NO_CODE, null)); //$NON-NLS-1$
            // TW: enable when bug 78387 is fixed
            monitor.worked(1);
        }
    } finally {
        monitor.done();
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) SearchResultGroup(org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 55 with IJavaElement

use of org.eclipse.jdt.core.IJavaElement 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)

Aggregations

IJavaElement (org.eclipse.jdt.core.IJavaElement)226 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)49 IType (org.eclipse.jdt.core.IType)44 ArrayList (java.util.ArrayList)35 IJavaProject (org.eclipse.jdt.core.IJavaProject)35 IMethod (org.eclipse.jdt.core.IMethod)34 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)32 JavaModelException (org.eclipse.jdt.core.JavaModelException)32 IResource (org.eclipse.core.resources.IResource)30 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)28 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)23 IField (org.eclipse.jdt.core.IField)16 IMember (org.eclipse.jdt.core.IMember)14 Test (org.junit.Test)14 CoreException (org.eclipse.core.runtime.CoreException)13 StringTokenizer (java.util.StringTokenizer)11 ISourceRange (org.eclipse.jdt.core.ISourceRange)11 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)11 IPath (org.eclipse.core.runtime.IPath)10 HashMap (java.util.HashMap)9