Cleanups: more type-checked representation of LanguageId
This commit is contained in:
@@ -28,7 +28,7 @@ public interface IDocument {
|
||||
int getLineOffset(int line) throws BadLocationException;
|
||||
void replace(int start, int len, String text) throws BadLocationException;
|
||||
String textBetween(int start, int end) throws BadLocationException;
|
||||
String getLanguageId();
|
||||
LanguageId getLanguageId();
|
||||
int getVersion();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.util.text;
|
||||
|
||||
/**
|
||||
* Central place to define constants for the known language-ids that we care
|
||||
* about.
|
||||
*
|
||||
* @author Kris De Volder
|
||||
*/
|
||||
public class LanguageId {
|
||||
|
||||
public static final LanguageId PLAINTEXT = of("plaintext");
|
||||
public static final LanguageId CONCOURSE_TASK = of("concourse-task-yaml");
|
||||
public static final LanguageId CONCOURSE_PIPELINE = of("concourse-pipeline-yaml");
|
||||
public static final LanguageId JAVA = of("java");
|
||||
public static final LanguageId YAML = of("yaml");
|
||||
|
||||
private final String id;
|
||||
|
||||
private LanguageId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
LanguageId other = (LanguageId) obj;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LanguageId ["+ id + "]";
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static LanguageId of(String languageId) {
|
||||
return new LanguageId(languageId);
|
||||
}
|
||||
}
|
||||
@@ -32,12 +32,12 @@ public class TextDocument implements IDocument {
|
||||
ILineTracker lineTracker = new DefaultLineTracker();
|
||||
private static final Pattern NEWLINE = Pattern.compile("\\r|\\n|\\r\\n|\\n\\r");
|
||||
|
||||
private final String languageId;
|
||||
private final LanguageId languageId;
|
||||
private final String uri;
|
||||
private Text text = new Text("");
|
||||
private int version;
|
||||
|
||||
public TextDocument(String uri, String languageId) {
|
||||
public TextDocument(String uri, LanguageId languageId) {
|
||||
this(uri, languageId, 0, "");
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class TextDocument implements IDocument {
|
||||
this.version = other.version;
|
||||
}
|
||||
|
||||
public TextDocument(String uri, String languageId, int version, String text) {
|
||||
public TextDocument(String uri, LanguageId languageId, int version, String text) {
|
||||
this.uri = uri;
|
||||
this.languageId = languageId;
|
||||
this.version = version;
|
||||
@@ -274,7 +274,7 @@ public class TextDocument implements IDocument {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguageId() {
|
||||
public LanguageId getLanguageId() {
|
||||
return languageId;
|
||||
}
|
||||
|
||||
@@ -282,6 +282,7 @@ public class TextDocument implements IDocument {
|
||||
return toRange(region.getOffset(), region.getLength());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user