Skip to content

Commit

Permalink
#82 - prevent the stack trace
Browse files Browse the repository at this point in the history
  • Loading branch information
giraud committed Jul 20, 2018
1 parent 255bd95 commit ef00100
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/main/java/com/reason/lang/core/PsiUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@

public class PsiUtil {

private PsiUtil() {
}

@NotNull
public static String fileNameToModuleName(@NotNull PsiFile file) {
return fileNameToModuleName(file.getName());
}

@NotNull
public static String moduleNameToFileName(@NotNull String name) {
static String moduleNameToFileName(@NotNull String name) {
if (name.isEmpty()) {
return name;
}
return name.substring(0, 1).toLowerCase(Locale.getDefault()) + name.substring(1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import com.reason.lang.core.PsiFinder;
import com.reason.lang.core.psi.*;
import com.reason.lang.reason.RmlTypes;
import gnu.trove.THashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -45,7 +45,7 @@ public PsiElement setName(@NotNull String name) throws IncorrectOperationExcepti

@Override
public Map<String, String> getAttributes() {
Map<String, String> result = Collections.emptyMap();
Map<String, String> result = new THashMap<>();

Project project = getProject();

Expand Down
30 changes: 30 additions & 0 deletions tests/com/reason/lang/core/PsiUtilTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.reason.lang.core;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class PsiUtilTest {

@Test
public void moduleNameToFileNameWhenEmpty() {
assertEquals("", PsiUtil.moduleNameToFileName(""));
}

@Test
public void moduleNameToFileName() {
assertEquals("testLower", PsiUtil.moduleNameToFileName("TestLower"));
}

@Test
public void fileNameToModuleNameWhenEmpty() {
assertEquals("", PsiUtil.fileNameToModuleName(""));
assertEquals("", PsiUtil.fileNameToModuleName(".ml"));
}

@Test
public void fileNameToModuleName() {
assertEquals("Lower", PsiUtil.fileNameToModuleName("lower.ml"));
assertEquals("Upper", PsiUtil.fileNameToModuleName("Upper.ml"));
}
}

0 comments on commit ef00100

Please sign in to comment.