-
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.
Preference 'xml.symbols.exclude' for an array of patterns to exclude …
…symbols for file(s) Signed-off-by: Nikolas Komonen <[email protected]>
- Loading branch information
1 parent
d19768c
commit b87140e
Showing
7 changed files
with
270 additions
and
53 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
88 changes: 88 additions & 0 deletions
88
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/settings/PathPatternMatcher.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,88 @@ | ||
/******************************************************************************* | ||
* 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.settings; | ||
|
||
import java.net.URI; | ||
import java.nio.file.FileSystems; | ||
import java.nio.file.PathMatcher; | ||
import java.nio.file.Paths; | ||
import java.util.Objects; | ||
|
||
public class PathPatternMatcher { | ||
|
||
private transient PathMatcher pathMatcher; | ||
private String pattern; | ||
|
||
public String getPattern() { | ||
return pattern; | ||
} | ||
|
||
public void setPattern(String pattern) { | ||
this.pattern = pattern; | ||
this.pathMatcher = null; | ||
} | ||
|
||
public PathMatcher getPathMatcher() { | ||
return pathMatcher; | ||
} | ||
|
||
public void setPathMatcher(PathMatcher pathMatcher) { | ||
this.pathMatcher = pathMatcher; | ||
} | ||
|
||
public boolean matches(String uri) { | ||
try { | ||
return matches(new URI(uri)); | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
} | ||
|
||
public boolean matches(URI uri) { | ||
if (pattern.length() < 1) { | ||
return false; | ||
} | ||
if (pathMatcher == null) { | ||
char c = pattern.charAt(0); | ||
String glob = pattern; | ||
if (c != '*' && c != '?' && c != '/') { | ||
// in case of pattern like this pattern="myFile*.xml", we must add '**/' before | ||
glob = "**/" + glob; | ||
} | ||
pathMatcher = FileSystems.getDefault().getPathMatcher("glob:" + glob); | ||
} | ||
try { | ||
return pathMatcher.matches(Paths.get(uri)); | ||
} catch (Exception e) { | ||
// e.printStackTrace(); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if(this == obj) { | ||
return true; | ||
} | ||
|
||
if(obj instanceof PathPatternMatcher) { | ||
PathPatternMatcher other = (PathPatternMatcher) obj; | ||
if(!Objects.equals(pathMatcher, other.getPathMatcher())) { | ||
return false; | ||
} | ||
if(!Objects.equals(pattern, other.getPattern())) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/settings/XMLExcludedSymbolFile.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,46 @@ | ||
/******************************************************************************* | ||
* 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.settings; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* XMLExcludedSymbolFiles | ||
*/ | ||
public class XMLExcludedSymbolFile extends PathPatternMatcher{ | ||
|
||
public XMLExcludedSymbolFile(String pattern) { | ||
setPattern(pattern); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if(this == obj) { | ||
return true; | ||
} | ||
|
||
if(!(obj instanceof XMLExcludedSymbolFile)) { | ||
return false; | ||
} | ||
|
||
XMLExcludedSymbolFile comparison = (XMLExcludedSymbolFile) obj; | ||
if(!Objects.equals(comparison.getPattern(), getPattern())) { | ||
return false; | ||
} | ||
|
||
if(!Objects.equals(comparison.getPathMatcher(), getPathMatcher())) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
|
||
} |
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
Oops, something went wrong.