@Test(dependsOnMethods = "testUpdateFile") public void testLockFile() { Optional<Lock> lock = Optional.empty(); try { lock = documentManager.lockFile(filePath); Assert.assertTrue(lock.isPresent()); } finally { lock.ifPresent(Lock::unlock); } }
@Override public Optional<Lock> lockFile(Path filePath) { Optional<Lock> lock = Optional.ofNullable(filePath).map(path -> Optional.ofNullable(documentList.get(path)) .map(DocumentPair::getLock) .orElseGet(() -> { synchronized (this) { return Optional.ofNullable(documentList.get(path)) .map(DocumentPair::getLock) .orElseGet(() -> { DocumentPair docPair = new DocumentPair(null); documentList.put(filePath, docPair); return docPair.getLock(); }); } }) ); lock.ifPresent(Lock::lock); return lock; }
WorkspaceDocumentManagerImpl implements WorkspaceDocumentManager { @Override public Optional<Lock> lockFile(Path filePath) { Optional<Lock> lock = Optional.ofNullable(filePath).map(path -> Optional.ofNullable(documentList.get(path)) .map(DocumentPair::getLock) .orElseGet(() -> { synchronized (this) { return Optional.ofNullable(documentList.get(path)) .map(DocumentPair::getLock) .orElseGet(() -> { DocumentPair docPair = new DocumentPair(null); documentList.put(filePath, docPair); return docPair.getLock(); }); } }) ); lock.ifPresent(Lock::lock); return lock; } }
WorkspaceDocumentManagerImpl implements WorkspaceDocumentManager { @Override public Optional<Lock> lockFile(Path filePath) { Optional<Lock> lock = Optional.ofNullable(filePath).map(path -> Optional.ofNullable(documentList.get(path)) .map(DocumentPair::getLock) .orElseGet(() -> { synchronized (this) { return Optional.ofNullable(documentList.get(path)) .map(DocumentPair::getLock) .orElseGet(() -> { DocumentPair docPair = new DocumentPair(null); documentList.put(filePath, docPair); return docPair.getLock(); }); } }) ); lock.ifPresent(Lock::lock); return lock; } protected  WorkspaceDocumentManagerImpl(); }
WorkspaceDocumentManagerImpl implements WorkspaceDocumentManager { @Override public Optional<Lock> lockFile(Path filePath) { Optional<Lock> lock = Optional.ofNullable(filePath).map(path -> Optional.ofNullable(documentList.get(path)) .map(DocumentPair::getLock) .orElseGet(() -> { synchronized (this) { return Optional.ofNullable(documentList.get(path)) .map(DocumentPair::getLock) .orElseGet(() -> { DocumentPair docPair = new DocumentPair(null); documentList.put(filePath, docPair); return docPair.getLock(); }); } }) ); lock.ifPresent(Lock::lock); return lock; } protected  WorkspaceDocumentManagerImpl(); static WorkspaceDocumentManagerImpl getInstance(); @Override boolean isFileOpen(Path filePath); @Override void openFile(Path filePath, String content); @Override void updateFile(Path filePath, List<TextDocumentContentChangeEvent> changeEvent); @Override void setCodeLenses(Path filePath, List<CodeLens> codeLens); @Override void closeFile(Path filePath); @Override List<CodeLens> getCodeLenses(Path filePath); @Override LSDocumentIdentifier getLSDocument(Path filePath); @Override String getFileContent(Path filePath); @Override Optional<Lock> lockFile(Path filePath); @Override Set<Path> getAllFilePaths(); @Override void clearAllFilePaths(); @Override SyntaxTree getTree(Path filePath); @Override void setTree(Path filePath, SyntaxTree newTree); }
WorkspaceDocumentManagerImpl implements WorkspaceDocumentManager { @Override public Optional<Lock> lockFile(Path filePath) { Optional<Lock> lock = Optional.ofNullable(filePath).map(path -> Optional.ofNullable(documentList.get(path)) .map(DocumentPair::getLock) .orElseGet(() -> { synchronized (this) { return Optional.ofNullable(documentList.get(path)) .map(DocumentPair::getLock) .orElseGet(() -> { DocumentPair docPair = new DocumentPair(null); documentList.put(filePath, docPair); return docPair.getLock(); }); } }) ); lock.ifPresent(Lock::lock); return lock; } protected  WorkspaceDocumentManagerImpl(); static WorkspaceDocumentManagerImpl getInstance(); @Override boolean isFileOpen(Path filePath); @Override void openFile(Path filePath, String content); @Override void updateFile(Path filePath, List<TextDocumentContentChangeEvent> changeEvent); @Override void setCodeLenses(Path filePath, List<CodeLens> codeLens); @Override void closeFile(Path filePath); @Override List<CodeLens> getCodeLenses(Path filePath); @Override LSDocumentIdentifier getLSDocument(Path filePath); @Override String getFileContent(Path filePath); @Override Optional<Lock> lockFile(Path filePath); @Override Set<Path> getAllFilePaths(); @Override void clearAllFilePaths(); @Override SyntaxTree getTree(Path filePath); @Override void setTree(Path filePath, SyntaxTree newTree);  }