Search in sources :

Example 6 with ResourceChangedEvent

use of org.eclipse.che.jdt.core.resources.ResourceChangedEvent in project che by eclipse.

the class RenameTypeTest method helperQualifiedName.

private void helperQualifiedName(String oldName, String newName, String textFileName, String filePatterns) throws Exception {
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), oldName);
    IType classA = getType(cu, oldName);
    String content = getFileContents(getTestPath() + name.getMethodName() + TEST_INPUT_INFIX + textFileName);
    IProject project = classA.getJavaProject().getProject();
    IFile file = project.getFile(textFileName);
    file.create(new ByteArrayInputStream(content.getBytes()), true, null);
    ResourceChangedEvent event = new ResourceChangedEvent(new File(BaseTest.class.getResource("/projects").getFile()), new ProjectItemModifiedEvent(ProjectItemModifiedEvent.EventType.CREATED, "projects", fProject.getElementName(), file.getFullPath().toOSString(), false));
    JavaModelManager.getJavaModelManager().deltaState.resourceChanged(event);
    RenameJavaElementDescriptor descriptor = createRefactoringDescriptor(classA, newName);
    descriptor.setUpdateQualifiedNames(true);
    descriptor.setFileNamePatterns(filePatterns);
    assertEquals("was supposed to pass", null, performRefactoring(descriptor));
    ICompilationUnit newcu = getPackageP().getCompilationUnit(newName + ".java");
    assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName(newName)), newcu.getSource());
    InputStreamReader reader = new InputStreamReader(file.getContents(true));
    StringBuffer newContent = new StringBuffer();
    try {
        int ch;
        while ((ch = reader.read()) != -1) newContent.append((char) ch);
    } finally {
        reader.close();
    }
    String definedContent = getFileContents(getTestPath() + name.getMethodName() + TEST_OUTPUT_INFIX + textFileName);
    assertEqualLines("invalid updating", definedContent, newContent.toString());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IFile(org.eclipse.core.resources.IFile) ProjectItemModifiedEvent(org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent) InputStreamReader(java.io.InputStreamReader) IProject(org.eclipse.core.resources.IProject) IType(org.eclipse.jdt.core.IType) ByteArrayInputStream(java.io.ByteArrayInputStream) ResourceChangedEvent(org.eclipse.che.jdt.core.resources.ResourceChangedEvent) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) IFile(org.eclipse.core.resources.IFile) File(java.io.File) BaseTest(org.eclipse.che.plugin.java.server.che.BaseTest)

Example 7 with ResourceChangedEvent

use of org.eclipse.che.jdt.core.resources.ResourceChangedEvent in project che by eclipse.

the class BaseTest method createTestProject.

protected FolderEntry createTestProject(String name, String pomContent) throws ServerException, NotFoundException, ConflictException, ForbiddenException {
    FolderEntry folder = pm.getProjectsRoot().createFolder(name);
    folder.createFile("pom.xml", getPomContent(pomContent).getBytes());
    projectRegistry.setProjectType(folder.getPath().toString(), MAVEN_ID, false);
    //inform DeltaProcessingStat about new project
    JavaModelManager.getJavaModelManager().deltaState.resourceChanged(new ResourceChangedEvent(root, new ProjectCreatedEvent("", folder.getPath().toString())));
    return folder;
}
Also used : ProjectCreatedEvent(org.eclipse.che.api.project.server.ProjectCreatedEvent) FolderEntry(org.eclipse.che.api.project.server.FolderEntry) ResourceChangedEvent(org.eclipse.che.jdt.core.resources.ResourceChangedEvent)

Aggregations

ResourceChangedEvent (org.eclipse.che.jdt.core.resources.ResourceChangedEvent)7 File (java.io.File)4 ProjectItemModifiedEvent (org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent)4 NameEnvironmentAnswer (org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer)3 Test (org.junit.Test)3 FolderEntry (org.eclipse.che.api.project.server.FolderEntry)2 ProjectCreatedEvent (org.eclipse.che.api.project.server.ProjectCreatedEvent)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 BaseTest (org.eclipse.che.plugin.java.server.che.BaseTest)1 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)1 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Path (org.eclipse.core.runtime.Path)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IType (org.eclipse.jdt.core.IType)1