Search in sources :

Example 6 with NullProgressMonitor

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;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ConvertAnonymousToNestedRefactoring(org.eclipse.jdt.internal.corext.refactoring.code.ConvertAnonymousToNestedRefactoring) LinkedProposalModel(org.eclipse.jdt.internal.corext.fix.LinkedProposalModel) Image(org.eclipse.swt.graphics.Image) RefactoringCorrectionProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.RefactoringCorrectionProposal) IType(org.eclipse.jdt.core.IType)

Example 7 with NullProgressMonitor

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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OrganizeImportsOperation(org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation) CodeGenerationSettings(org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings) OrganizeImportResult(org.eclipse.che.ide.ext.java.shared.dto.OrganizeImportResult) TextEdit(org.eclipse.text.edits.TextEdit) DocumentChangeListener(org.eclipse.jdt.internal.corext.format.DocumentChangeListener) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IBuffer(org.eclipse.jdt.core.IBuffer) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 8 with NullProgressMonitor

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);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) IType(org.eclipse.jdt.core.IType) Type(org.eclipse.che.ide.ext.java.shared.dto.model.Type) IType(org.eclipse.jdt.core.IType)

Example 9 with NullProgressMonitor

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);
            }
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) ResourceChangedEvent(org.eclipse.che.jdt.core.resources.ResourceChangedEvent)

Example 10 with NullProgressMonitor

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());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RefactoringManager(org.eclipse.che.plugin.java.server.refactoring.RefactoringManager) Before(org.junit.Before)

Aggregations

NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1626 CoreException (org.eclipse.core.runtime.CoreException)430 Test (org.junit.Test)353 IFile (org.eclipse.core.resources.IFile)316 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)276 IProject (org.eclipse.core.resources.IProject)261 File (java.io.File)213 IPath (org.eclipse.core.runtime.IPath)184 IOException (java.io.IOException)162 Path (org.eclipse.core.runtime.Path)141 ArrayList (java.util.ArrayList)125 IStatus (org.eclipse.core.runtime.IStatus)116 IFolder (org.eclipse.core.resources.IFolder)90 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)70 List (java.util.List)63 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)63 InvocationTargetException (java.lang.reflect.InvocationTargetException)61 IProjectDescription (org.eclipse.core.resources.IProjectDescription)58 Status (org.eclipse.core.runtime.Status)57 IResource (org.eclipse.core.resources.IResource)56