diff --git a/org.eclipse.editorconfig.core/src/main/java/org/eclipse/editorconfig/core/EditorFileConfig.java b/org.eclipse.editorconfig.core/src/main/java/org/eclipse/editorconfig/core/EditorFileConfig.java index 40e3a71..87679cc 100644 --- a/org.eclipse.editorconfig.core/src/main/java/org/eclipse/editorconfig/core/EditorFileConfig.java +++ b/org.eclipse.editorconfig.core/src/main/java/org/eclipse/editorconfig/core/EditorFileConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 Nathan Jones + * Copyright 2017 Nathan Jones, Jackson Bailey * * This file is part of "EditorConfig Eclipse". * @@ -25,7 +25,7 @@ public class EditorFileConfig { private final String path; - + private final Set configProperties; public EditorFileConfig(final String path, final Set configProperties) { @@ -41,6 +41,15 @@ public Set getConfigProperties() { return configProperties; } + public ConfigProperty getConfigProperty(String name) { + for (ConfigProperty configProperty: configProperties) { + if (name.equals(configProperty.getType().getName())) { + return configProperty; + } + } + return null; + } + @Override public String toString() { return "EditorFileConfig [path=" + path + ", configProperties=" + configProperties + "]"; diff --git a/org.eclipse.editorconfig.core/src/test/java/org/eclipse/editorconfig/core/EditorFileConfigTest.java b/org.eclipse.editorconfig.core/src/test/java/org/eclipse/editorconfig/core/EditorFileConfigTest.java new file mode 100644 index 0000000..7018a68 --- /dev/null +++ b/org.eclipse.editorconfig.core/src/test/java/org/eclipse/editorconfig/core/EditorFileConfigTest.java @@ -0,0 +1,49 @@ +/* + * Copyright 2017 Jackson Bailey + * + * This file is part of "EditorConfig Eclipse". + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.eclipse.editorconfig.core; + +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; + +import java.util.HashSet; +import java.util.Set; +import org.eclipse.editorconfig.core.ConfigPropertyType.IndentSize; +import org.eclipse.editorconfig.core.ConfigPropertyType.IndentStyle; +import org.junit.Test; + +public class EditorFileConfigTest { + + @Test + public void getPropertyReturnsProperty() { + + final ConfigProperty indentStyle = + new ConfigProperty(new IndentStyle(), IndentStyleOption.TAB); + final ConfigProperty indentSize = new ConfigProperty(new IndentSize(), 2); + + @SuppressWarnings("rawtypes") + Set properties = new HashSet(); + properties.add(indentStyle); + properties.add(indentSize); + + EditorFileConfig config = new EditorFileConfig("", properties); + + assertSame(indentStyle, config.getConfigProperty("INDENT_STYLE")); + assertSame(indentSize, config.getConfigProperty("INDENT_SIZE")); + assertNull(config.getConfigProperty("TAB_WIDTH")); + } +}