Example usage for org.eclipse.jdt.internal.core JavaModelManager getDeltaState

List of usage examples for org.eclipse.jdt.internal.core JavaModelManager getDeltaState

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core JavaModelManager getDeltaState.

Prototype

public static DeltaProcessingState getDeltaState() 

Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.search.JavaWorkspaceScope.java

License:Open Source License

/**
 * @see org.eclipse.jdt.internal.core.search.AbstractJavaSearchScope#packageFragmentRoot(String, int, String)
 *///from   ww w.j  a v  a 2  s.  co  m
public IPackageFragmentRoot packageFragmentRoot(String resourcePathString, int jarSeparatorIndex,
        String jarPath) {
    HashMap rootInfos = JavaModelManager.getDeltaState().roots;
    DeltaProcessor.RootInfo rootInfo = null;
    if (jarPath != null) {
        IPath path = new Path(jarPath);
        rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(path);
    } else {
        IPath path = new Path(resourcePathString);
        if (ExternalFoldersManager.isInternalPathForExternalFolder(path)) {
            IResource resource = JavaModel.getWorkspaceTarget(
                    path.uptoSegment(2/*linked folders for external folders are always of size 2*/));
            if (resource != null)
                rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(resource.getLocation());
        } else {
            rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(path);
            while (rootInfo == null && path.segmentCount() > 0) {
                path = path.removeLastSegments(1);
                rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(path);
            }
        }
    }
    if (rootInfo == null)
        return null;
    return rootInfo.getPackageFragmentRoot(null/*no resource hint*/);
}

From source file:org.eclipse.che.plugin.java.server.rest.JavaFormatterServiceTest.java

License:Open Source License

@BeforeClass
protected void initProjectApi() throws Exception {
    TestWorkspaceHolder workspaceHolder = new TestWorkspaceHolder(new ArrayList<>());
    File root = new File("target/test-classes");
    assertTrue(root.exists());/*from ww  w .j a va 2 s  . co m*/

    File indexDir = new File("target/fs_index");
    assertTrue(indexDir.mkdirs());

    Set<PathMatcher> filters = new HashSet<>();
    filters.add(path -> true);
    FSLuceneSearcherProvider sProvider = new FSLuceneSearcherProvider(indexDir, filters);

    EventService eventService = new EventService();
    LocalVirtualFileSystemProvider vfsProvider = new LocalVirtualFileSystemProvider(root, sProvider);
    ProjectTypeRegistry projectTypeRegistry = new ProjectTypeRegistry(new HashSet<>());
    projectTypeRegistry.registerProjectType(new JavaProjectType(new JavaValueProviderFactory()));
    ProjectHandlerRegistry projectHandlerRegistry = new ProjectHandlerRegistry(new HashSet<>());
    ProjectRegistry projectRegistry = new ProjectRegistry(workspaceHolder, vfsProvider, projectTypeRegistry,
            projectHandlerRegistry, eventService);
    projectRegistry.initProjects();

    ProjectImporterRegistry importerRegistry = new ProjectImporterRegistry(new HashSet<>());
    FileWatcherNotificationHandler fileWatcherNotificationHandler = new DefaultFileWatcherNotificationHandler(
            vfsProvider);
    FileTreeWatcher fileTreeWatcher = new FileTreeWatcher(root, new HashSet<>(),
            fileWatcherNotificationHandler);
    projectManager = new ProjectManager(vfsProvider, projectTypeRegistry, projectRegistry,
            projectHandlerRegistry, importerRegistry, fileWatcherNotificationHandler, fileTreeWatcher,
            workspaceHolder, mock(FileWatcherManager.class));

    ResourcesPlugin resourcesPlugin = new ResourcesPlugin("target/index", root.getAbsolutePath(),
            () -> projectRegistry, () -> projectManager);
    resourcesPlugin.start();

    JavaPlugin javaPlugin = new JavaPlugin(root.getAbsolutePath() + "/.settings", resourcesPlugin,
            projectRegistry);
    javaPlugin.start();

    JavaModelManager.getDeltaState().initializeRoots(true);

    createJavaFile();

    Formatter formatter = new Formatter();
    service = new JavaFormatterService(projectManager, formatter);
}

From source file:org.eclipse.che.plugin.jdb.server.JavaDebuggerTest.java

License:Open Source License

@BeforeClass
protected void initProjectApi() throws Exception {
    TestWorkspaceHolder workspaceHolder = new TestWorkspaceHolder(new ArrayList<>());
    File root = new File("target/test-classes/workspace");
    assertTrue(root.exists());/*from w w  w .  j  a  v  a 2 s . c  om*/

    File indexDir = new File("target/fs_index");
    assertTrue(indexDir.mkdirs());

    Set<PathMatcher> filters = new HashSet<>();
    filters.add(path -> true);
    FSLuceneSearcherProvider sProvider = new FSLuceneSearcherProvider(indexDir, filters);

    EventService eventService = new EventService();
    LocalVirtualFileSystemProvider vfsProvider = new LocalVirtualFileSystemProvider(root, sProvider);
    ProjectTypeRegistry projectTypeRegistry = new ProjectTypeRegistry(new HashSet<>());
    projectTypeRegistry.registerProjectType(new JavaProjectType(new JavaValueProviderFactory()));
    ProjectHandlerRegistry projectHandlerRegistry = new ProjectHandlerRegistry(new HashSet<>());
    ProjectRegistry projectRegistry = new ProjectRegistry(workspaceHolder, vfsProvider, projectTypeRegistry,
            projectHandlerRegistry, eventService);
    projectRegistry.initProjects();

    ProjectImporterRegistry importerRegistry = new ProjectImporterRegistry(new HashSet<>());
    FileWatcherNotificationHandler fileWatcherNotificationHandler = new DefaultFileWatcherNotificationHandler(
            vfsProvider);
    FileTreeWatcher fileTreeWatcher = new FileTreeWatcher(root, new HashSet<>(),
            fileWatcherNotificationHandler);
    ProjectManager projectManager = new ProjectManager(vfsProvider, eventService, projectTypeRegistry,
            projectRegistry, projectHandlerRegistry, importerRegistry, fileWatcherNotificationHandler,
            fileTreeWatcher, workspaceHolder, mock(FileWatcherManager.class));

    ResourcesPlugin resourcesPlugin = new ResourcesPlugin("target/index", root.getAbsolutePath(),
            () -> projectRegistry, () -> projectManager);
    resourcesPlugin.start();

    JavaPlugin javaPlugin = new JavaPlugin(root.getAbsolutePath() + "/.settings", resourcesPlugin,
            projectRegistry);
    javaPlugin.start();

    projectRegistry.setProjectType("test", "java", false);

    JavaModelManager.getDeltaState().initializeRoots(true);

    events = new ArrayBlockingQueue<>(10);
    Map<String, String> connectionProperties = ImmutableMap.of("host", "localhost", "port",
            System.getProperty("debug.port"));
    JavaDebuggerFactory factory = new JavaDebuggerFactory();
    debugger = factory.create(connectionProperties, events::add);
}

From source file:org.eclipse.che.plugin.jdb.server.util.ProjectApiUtils.java

License:Open Source License

/** Initialize project API for tests. */
private static void init() throws Exception {
    TestWorkspaceHolder workspaceHolder = new TestWorkspaceHolder(new ArrayList<>());
    File root = new File("target/test-classes/workspace");
    assertTrue(root.exists());/*from w ww.  ja  va 2 s  . c o  m*/

    File indexDir = new File("target/fs_index");
    assertTrue(indexDir.mkdirs());

    Set<PathMatcher> filters = new HashSet<>();
    filters.add(path -> true);
    FSLuceneSearcherProvider sProvider = new FSLuceneSearcherProvider(indexDir, filters);

    EventService eventService = new EventService();
    LocalVirtualFileSystemProvider vfsProvider = new LocalVirtualFileSystemProvider(root, sProvider);
    ProjectTypeRegistry projectTypeRegistry = new ProjectTypeRegistry(new HashSet<>());
    projectTypeRegistry.registerProjectType(new JavaProjectType(new JavaValueProviderFactory()));
    ProjectHandlerRegistry projectHandlerRegistry = new ProjectHandlerRegistry(new HashSet<>());
    ProjectRegistry projectRegistry = new ProjectRegistry(workspaceHolder, vfsProvider, projectTypeRegistry,
            projectHandlerRegistry, eventService);
    projectRegistry.initProjects();

    ProjectImporterRegistry importerRegistry = new ProjectImporterRegistry(new HashSet<>());
    FileWatcherNotificationHandler fileWatcherNotificationHandler = new DefaultFileWatcherNotificationHandler(
            vfsProvider);
    FileTreeWatcher fileTreeWatcher = new FileTreeWatcher(root, new HashSet<>(),
            fileWatcherNotificationHandler);
    ProjectManager projectManager = new ProjectManager(vfsProvider, projectTypeRegistry, projectRegistry,
            projectHandlerRegistry, importerRegistry, fileWatcherNotificationHandler, fileTreeWatcher,
            workspaceHolder, mock(FileWatcherManager.class));

    ResourcesPlugin resourcesPlugin = new ResourcesPlugin("target/index", root.getAbsolutePath(),
            () -> projectRegistry, () -> projectManager);
    resourcesPlugin.start();

    JavaPlugin javaPlugin = new JavaPlugin(root.getAbsolutePath() + "/.settings", resourcesPlugin,
            projectRegistry);
    javaPlugin.start();

    projectRegistry.setProjectType("test", "java", false);

    JavaModelManager.getDeltaState().initializeRoots(true);
}

From source file:org.eclipse.e4.xwt.ui.editor.XWTEditor.java

License:Open Source License

public void addElementChangedListener(IJavaProject javaProject) {
    int eventMask = ElementChangedEvent.POST_CHANGE | ElementChangedEvent.POST_RECONCILE;
    JavaModelManager.getDeltaState().addElementChangedListener(elementChangedListener, eventMask);
}

From source file:org.eclipse.e4.xwt.ui.editor.XWTEditor.java

License:Open Source License

public void removeElementChangedListener(IJavaProject javaProject) {
    int eventMask = ElementChangedEvent.POST_CHANGE | ElementChangedEvent.POST_RECONCILE;
    JavaModelManager.getDeltaState().removeElementChangedListener(elementChangedListener);
}