-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache completion based on XML Schema/DTD
Fixes #547 Signed-off-by: azerr <azerr@redhat.com>
- Loading branch information
1 parent
23a4a81
commit 022b75e
Showing
5 changed files
with
236 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
.../src/main/java/org/eclipse/lsp4xml/extensions/contentmodel/model/FilesChangedTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.lsp4xml.extensions.contentmodel.model; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.nio.file.attribute.FileTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* File changed tracker. | ||
* | ||
* @author Angelo ZERR | ||
* | ||
*/ | ||
public class FilesChangedTracker { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(FilesChangedTracker.class.getName()); | ||
|
||
private static class FileChangedTracker { | ||
|
||
private final Path file; | ||
private FileTime lastModified; | ||
|
||
public FileChangedTracker(Path file) { | ||
this.file = file; | ||
try { | ||
lastModified = Files.getLastModifiedTime(file); | ||
} catch (IOException e) { | ||
LOGGER.log(Level.SEVERE, "Get last modified time failed", e); | ||
} | ||
} | ||
|
||
public boolean isDirty() { | ||
try { | ||
FileTime currentLastMofied = Files.getLastModifiedTime(file); | ||
if (!currentLastMofied.equals(lastModified)) { | ||
lastModified = currentLastMofied; | ||
return true; | ||
} | ||
} catch (IOException e) { | ||
LOGGER.log(Level.SEVERE, "Get last modified time failed", e); | ||
} | ||
return false; | ||
} | ||
|
||
} | ||
|
||
private final List<FileChangedTracker> files; | ||
|
||
public FilesChangedTracker() { | ||
files = new ArrayList<>(); | ||
} | ||
|
||
/** | ||
* Add file URI to track | ||
* | ||
* @param fileURI | ||
*/ | ||
public void addFileURI(String fileURI) { | ||
try { | ||
files.add(new FileChangedTracker(Paths.get(new URI(fileURI)))); | ||
} catch (URISyntaxException e) { | ||
LOGGER.log(Level.SEVERE, "Add file URI to track failed", e); | ||
} | ||
} | ||
|
||
/** | ||
* Returns true if one file has changed and false otherwise. | ||
* | ||
* @return true if one file has changed and false otherwise. | ||
*/ | ||
public boolean isDirty() { | ||
for (FileChangedTracker dirtyFile : files) { | ||
if (dirtyFile.isDirty()) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters