Skip to content

Commit

Permalink
Add a method to get a property by name
Browse files Browse the repository at this point in the history
- See: #41
  • Loading branch information
Jackson Bailey authored and ncjones committed Apr 26, 2017
1 parent bb8757b commit 45787ee
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014 Nathan Jones
* Copyright 2017 Nathan Jones, Jackson Bailey
*
* This file is part of "EditorConfig Eclipse".
*
Expand All @@ -25,7 +25,7 @@
public class EditorFileConfig {

private final String path;

private final Set<ConfigProperty> configProperties;

public EditorFileConfig(final String path, final Set<ConfigProperty> configProperties) {
Expand All @@ -41,6 +41,15 @@ public Set<ConfigProperty> 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 + "]";
Expand Down
Original file line number Diff line number Diff line change
@@ -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<IndentStyleOption> indentStyle =
new ConfigProperty<IndentStyleOption>(new IndentStyle(), IndentStyleOption.TAB);
final ConfigProperty<Integer> indentSize = new ConfigProperty<Integer>(new IndentSize(), 2);

@SuppressWarnings("rawtypes")
Set<ConfigProperty> properties = new HashSet<ConfigProperty>();
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"));
}
}

0 comments on commit 45787ee

Please sign in to comment.