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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations