use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.
the class QuickAssistProcessor method getConvertAnonymousToNestedProposal.
private static boolean getConvertAnonymousToNestedProposal(IInvocationContext context, final ASTNode node, Collection<ICommandAccess> proposals) throws CoreException {
if (!(node instanceof Name))
return false;
ASTNode normalized = ASTNodes.getNormalizedNode(node);
if (normalized.getLocationInParent() != ClassInstanceCreation.TYPE_PROPERTY)
return false;
final AnonymousClassDeclaration anonymTypeDecl = ((ClassInstanceCreation) normalized.getParent()).getAnonymousClassDeclaration();
if (anonymTypeDecl == null || anonymTypeDecl.resolveBinding() == null) {
return false;
}
if (proposals == null) {
return true;
}
final ICompilationUnit cu = context.getCompilationUnit();
final ConvertAnonymousToNestedRefactoring refactoring = new ConvertAnonymousToNestedRefactoring(anonymTypeDecl);
String extTypeName = ASTNodes.getSimpleNameIdentifier((Name) node);
ITypeBinding anonymTypeBinding = anonymTypeDecl.resolveBinding();
String className;
if (anonymTypeBinding.getInterfaces().length == 0) {
className = Messages.format(CorrectionMessages.QuickAssistProcessor_name_extension_from_interface, extTypeName);
} else {
className = Messages.format(CorrectionMessages.QuickAssistProcessor_name_extension_from_class, extTypeName);
}
String[][] existingTypes = ((IType) anonymTypeBinding.getJavaElement()).resolveType(className);
int i = 1;
while (existingTypes != null) {
i++;
existingTypes = ((IType) anonymTypeBinding.getJavaElement()).resolveType(className + i);
}
refactoring.setClassName(i == 1 ? className : className + i);
if (refactoring.checkInitialConditions(new NullProgressMonitor()).isOK()) {
LinkedProposalModel linkedProposalModel = new LinkedProposalModel();
refactoring.setLinkedProposalModel(linkedProposalModel);
String label = CorrectionMessages.QuickAssistProcessor_convert_anonym_to_nested;
Image image = JavaPlugin.getImageDescriptorRegistry().get(JavaElementImageProvider.getTypeImageDescriptor(true, false, Flags.AccPrivate, false));
RefactoringCorrectionProposal proposal = new RefactoringCorrectionProposal(label, cu, refactoring, IProposalRelevance.CONVERT_ANONYMOUS_TO_NESTED, image);
proposal.setLinkedProposalModel(linkedProposalModel);
proposal.setCommandId(CONVERT_ANONYMOUS_TO_LOCAL_ID);
proposals.add(proposal);
}
return false;
}
use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.
the class CodeAssist method createOrganizeImportOperation.
private OrganizeImportResult createOrganizeImportOperation(ICompilationUnit compilationUnit, List<String> chosen) throws CoreException {
CodeGenerationSettings settings = JavaPreferencesSettings.getCodeGenerationSettings(compilationUnit.getJavaProject());
OrganizeImportsOperation operation = new OrganizeImportsOperation(compilationUnit, null, settings.importIgnoreLowercase, !compilationUnit.isWorkingCopy(), true, chosen, null);
NullProgressMonitor monitor = new NullProgressMonitor();
TextEdit edit = operation.createTextEdit(monitor);
OrganizeImportResult result = DtoFactory.newDto(OrganizeImportResult.class);
TypeNameMatch[][] choices = operation.getChoices();
//or all conflicts were resolved (!chosen.isEmpty())
if ((chosen != null && !chosen.isEmpty()) || choices == null || choices.length == 0) {
IBuffer buffer = compilationUnit.getBuffer();
IDocument document = new Document(buffer.getContents());
DocumentChangeListener documentChangeListener = new DocumentChangeListener(document);
try {
edit.apply(document);
} catch (BadLocationException e) {
LOG.debug("Applying Organize import text edits goes wrong:", e);
}
result.setChanges(documentChangeListener.getChanges());
return result;
}
result.setConflicts(createListOfDTOMatches(choices));
return result;
}
use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.
the class JavaTypeHierarchy method findSubTypes.
private void findSubTypes(IJavaElement element, List<Type> implementations) throws JavaModelException {
IType type = (IType) element;
ITypeHierarchy typeHierarchy = type.newTypeHierarchy(new NullProgressMonitor());
IType[] implTypes = typeHierarchy.getAllSubtypes(type);
for (IType implType : implTypes) {
Type dto = convertToTypeDTO(implType);
implementations.add(dto);
}
}
use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.
the class ProjectListeners method handleEvent.
public void handleEvent(ProjectItemModifiedEvent event) {
final String eventPath = event.getPath();
if (!isJavaProject(event.getProject())) {
return;
}
try {
JavaModelManager.getJavaModelManager().deltaState.resourceChanged(new ResourceChangedEvent(workspace, event));
} catch (Throwable t) {
//catch all exceptions that may be happened
LOG.error("Can't update java model in " + eventPath, t);
}
if (event.getType() == ProjectItemModifiedEvent.EventType.UPDATED) {
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
ITextFileBuffer fileBuffer = manager.getTextFileBuffer(new Path(eventPath), LocationKind.IFILE);
if (fileBuffer != null) {
try {
fileBuffer.revert(new NullProgressMonitor());
} catch (CoreException e) {
LOG.error("Can't read file content: " + eventPath, e);
}
}
}
}
use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.
the class MoveRefactoringSessionTest method setUp.
@Before
public void setUp() throws Exception {
setup.setUp();
super.setUp();
manager = new RefactoringManager();
getPackageP().createCompilationUnit("A.java", "package p;class A{}", false, new NullProgressMonitor());
p1 = getRoot().createPackageFragment("p1", false, new NullProgressMonitor());
}
Aggregations