Search in sources :

Example 71 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.

the class StubCreator method appendTypeDeclaration.

protected void appendTypeDeclaration(final IType type, final IProgressMonitor monitor) throws JavaModelException {
    try {
        monitor.beginTask(RefactoringCoreMessages.StubCreationOperation_creating_type_stubs, 1);
        if (type.isAnnotation()) {
            appendFlags(type);
            //$NON-NLS-1$
            fBuffer.append(" @interface ");
            fBuffer.append(type.getElementName());
            //$NON-NLS-1$
            fBuffer.append("{\n");
            appendMembers(type, new SubProgressMonitor(monitor, 1));
            //$NON-NLS-1$
            fBuffer.append("}");
        } else if (type.isInterface()) {
            appendFlags(type);
            //$NON-NLS-1$
            fBuffer.append(" interface ");
            fBuffer.append(type.getElementName());
            appendTypeParameters(type.getTypeParameters());
            appendSuperInterfaceTypes(type);
            //$NON-NLS-1$
            fBuffer.append("{\n");
            appendMembers(type, new SubProgressMonitor(monitor, 1));
            //$NON-NLS-1$
            fBuffer.append("}");
        } else if (type.isClass()) {
            appendFlags(type);
            //$NON-NLS-1$
            fBuffer.append(" class ");
            fBuffer.append(type.getElementName());
            appendTypeParameters(type.getTypeParameters());
            final String signature = type.getSuperclassTypeSignature();
            if (signature != null) {
                //$NON-NLS-1$
                fBuffer.append(" extends ");
                fBuffer.append(Signature.toString(signature));
            }
            appendSuperInterfaceTypes(type);
            //$NON-NLS-1$
            fBuffer.append("{\n");
            appendMembers(type, new SubProgressMonitor(monitor, 1));
            //$NON-NLS-1$
            fBuffer.append("}");
        } else if (type.isEnum()) {
            appendFlags(type);
            //$NON-NLS-1$
            fBuffer.append(" enum ");
            fBuffer.append(type.getElementName());
            appendSuperInterfaceTypes(type);
            //$NON-NLS-1$
            fBuffer.append("{\n");
            appendEnumConstants(type);
            appendMembers(type, new SubProgressMonitor(monitor, 1));
            //$NON-NLS-1$
            fBuffer.append("}");
        }
    } finally {
        monitor.done();
    }
}
Also used : SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 72 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.

the class StubCreator method appendMembers.

protected void appendMembers(final IType type, final IProgressMonitor monitor) throws JavaModelException {
    try {
        monitor.beginTask(RefactoringCoreMessages.StubCreationOperation_creating_type_stubs, 1);
        final IJavaElement[] children = type.getChildren();
        for (int index = 0; index < children.length; index++) {
            final IMember child = (IMember) children[index];
            final int flags = child.getFlags();
            final boolean isPrivate = Flags.isPrivate(flags);
            final boolean isDefault = !Flags.isPublic(flags) && !Flags.isProtected(flags) && !isPrivate;
            final boolean stub = fStubInvisible || (!isPrivate && !isDefault);
            if (child instanceof IType) {
                if (stub)
                    appendTypeDeclaration((IType) child, new SubProgressMonitor(monitor, 1));
            } else if (child instanceof IField) {
                if (stub && !Flags.isEnum(flags) && !Flags.isSynthetic(flags))
                    appendFieldDeclaration((IField) child);
            } else if (child instanceof IMethod) {
                final IMethod method = (IMethod) child;
                final String name = method.getElementName();
                if (method.getDeclaringType().isEnum()) {
                    final int count = method.getNumberOfParameters();
                    if (//$NON-NLS-1$
                    count == 0 && "values".equals(name))
                        continue;
                    if (//$NON-NLS-1$ //$NON-NLS-2$
                    count == 1 && "valueOf".equals(name) && "Ljava.lang.String;".equals(method.getParameterTypes()[0]))
                        continue;
                    if (method.isConstructor())
                        continue;
                }
                //$NON-NLS-1$
                boolean skip = !stub || name.equals("<clinit>");
                if (method.isConstructor())
                    skip = false;
                skip = skip || Flags.isSynthetic(flags) || Flags.isBridge(flags);
                if (!skip)
                    appendMethodDeclaration(method);
            }
            //$NON-NLS-1$
            fBuffer.append("\n");
        }
    } finally {
        monitor.done();
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IMethod(org.eclipse.jdt.core.IMethod) IField(org.eclipse.jdt.core.IField) IMember(org.eclipse.jdt.core.IMember) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IType(org.eclipse.jdt.core.IType)

Example 73 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.

the class RefactoringSearchEngine2 method searchReferencedMethods.

/**
	 * Performs the search of referenced methods.
	 *
	 * @param element the java element whose referenced methods have to be found
	 * @param monitor the progress monitor, or <code>null</code>
	 * @throws JavaModelException if an error occurs during search
	 */
public final void searchReferencedMethods(final IJavaElement element, IProgressMonitor monitor) throws JavaModelException {
    Assert.isNotNull(element);
    if (monitor == null)
        monitor = new NullProgressMonitor();
    try {
        //$NON-NLS-1$
        monitor.beginTask("", 1);
        monitor.setTaskName(RefactoringCoreMessages.RefactoringSearchEngine_searching_referenced_methods);
        try {
            SearchEngine engine = null;
            if (fOwner != null)
                engine = new SearchEngine(fOwner);
            else
                engine = new SearchEngine(fWorkingCopies);
            engine.searchDeclarationsOfSentMessages(element, getCollector(), new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
        } catch (CoreException exception) {
            throw new JavaModelException(exception);
        }
    } finally {
        monitor.done();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) JavaModelException(org.eclipse.jdt.core.JavaModelException) SearchEngine(org.eclipse.jdt.core.search.SearchEngine) CoreException(org.eclipse.core.runtime.CoreException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 74 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor 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 75 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.

the class MemberVisibilityAdjustor method rewriteVisibility.

/**
	 * Rewrites the computed adjustments for the specified compilation unit.
	 *
	 * @param unit the compilation unit to rewrite the adjustments
	 * @param monitor the progress monitor to use
	 * @throws JavaModelException if an error occurs during search
	 */
public final void rewriteVisibility(final ICompilationUnit unit, final IProgressMonitor monitor) throws JavaModelException {
    try {
        //$NON-NLS-1$
        monitor.beginTask("", fAdjustments.keySet().size());
        monitor.setTaskName(RefactoringCoreMessages.MemberVisibilityAdjustor_adjusting);
        IMember member = null;
        IVisibilityAdjustment adjustment = null;
        for (final Iterator<IMember> iterator = fAdjustments.keySet().iterator(); iterator.hasNext(); ) {
            member = iterator.next();
            if (unit.equals(member.getCompilationUnit())) {
                adjustment = fAdjustments.get(member);
                if (adjustment != null)
                    adjustment.rewriteVisibility(this, new SubProgressMonitor(monitor, 1));
            }
        }
    } finally {
        fTypeHierarchies.clear();
        monitor.done();
    }
}
Also used : IMember(org.eclipse.jdt.core.IMember) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Aggregations

SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)217 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)54 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)53 CoreException (org.eclipse.core.runtime.CoreException)40 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)39 ArrayList (java.util.ArrayList)36 IFile (org.eclipse.core.resources.IFile)33 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)31 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)30 IOException (java.io.IOException)23 IType (org.eclipse.jdt.core.IType)19 HashSet (java.util.HashSet)17 IPath (org.eclipse.core.runtime.IPath)17 IResource (org.eclipse.core.resources.IResource)16 IProject (org.eclipse.core.resources.IProject)15 File (java.io.File)14 List (java.util.List)13 IMethod (org.eclipse.jdt.core.IMethod)13 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 HashMap (java.util.HashMap)12