Using enum instead of string constants for J2K options
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package org.jetbrains.jet.j2k;
|
package org.jetbrains.jet.j2k;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import com.intellij.psi.*;
|
import com.intellij.psi.*;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -35,17 +36,17 @@ public class Converter {
|
|||||||
private static PsiType ourMethodReturnType = null;
|
private static PsiType ourMethodReturnType = null;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static Set<String> settings = new HashSet<String>();
|
private static Set<J2KConverterFlags> flags = Sets.newHashSet();
|
||||||
|
|
||||||
private Converter() {
|
private Converter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean addSetting(@NotNull String value) {
|
public static boolean addFlag(@NotNull J2KConverterFlags flag) {
|
||||||
return settings.add(value);
|
return flags.add(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasSetting(@NotNull String value) {
|
public static boolean hasFlag(@NotNull J2KConverterFlags flag) {
|
||||||
return settings.contains(value);
|
return flags.contains(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setClassIdentifiers(@NotNull Set<String> identifiers) {
|
public static void setClassIdentifiers(@NotNull Set<String> identifiers) {
|
||||||
@@ -394,7 +395,7 @@ public class Converter {
|
|||||||
|
|
||||||
final IdentifierImpl identifier = new IdentifierImpl(method.getName());
|
final IdentifierImpl identifier = new IdentifierImpl(method.getName());
|
||||||
final Type returnType = typeToType(method.getReturnType(), ConverterUtil.isAnnotatedAsNotNull(method.getModifierList()));
|
final Type returnType = typeToType(method.getReturnType(), ConverterUtil.isAnnotatedAsNotNull(method.getModifierList()));
|
||||||
final Block body = hasSetting("declarations-only")
|
final Block body = hasFlag(J2KConverterFlags.SKIP_BODIES)
|
||||||
? Block.EMPTY_BLOCK
|
? Block.EMPTY_BLOCK
|
||||||
: blockToBlock(method.getBody(), notEmpty); // #TODO
|
: blockToBlock(method.getBody(), notEmpty); // #TODO
|
||||||
final Element params = createFunctionParameters(method);
|
final Element params = createFunctionParameters(method);
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package org.jetbrains.jet.j2k;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author abreslav
|
||||||
|
*/
|
||||||
|
public enum J2KConverterFlags {
|
||||||
|
FULLY_QUALIFIED_TYPE_NAMES,
|
||||||
|
SKIP_BODIES,
|
||||||
|
SKIP_NON_PUBLIC_MEMBERS
|
||||||
|
}
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
// String to = commandLine.getOptionValue("to");
|
// String to = commandLine.getOptionValue("to");
|
||||||
//
|
//
|
||||||
// for (Option o : commandLine.getOptions()) {
|
// for (Option o : commandLine.getOptions()) {
|
||||||
// Converter.addSetting(o.getLongOpt());
|
// Converter.addFlag(o.getLongOpt());
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// if (!from.isEmpty() && !to.isEmpty())
|
// if (!from.isEmpty() && !to.isEmpty())
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.jetbrains.jet.j2k.ast;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.j2k.Converter;
|
import org.jetbrains.jet.j2k.Converter;
|
||||||
|
import org.jetbrains.jet.j2k.J2KConverterFlags;
|
||||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -38,7 +39,7 @@ public class Class extends Member {
|
|||||||
|
|
||||||
static List<Member> getMembers(List<Member> members) {
|
static List<Member> getMembers(List<Member> members) {
|
||||||
List<Member> withoutPrivate = new LinkedList<Member>();
|
List<Member> withoutPrivate = new LinkedList<Member>();
|
||||||
if (Converter.hasSetting("public-only")) {
|
if (Converter.hasFlag(J2KConverterFlags.SKIP_NON_PUBLIC_MEMBERS)) {
|
||||||
for (Member m : members) {
|
for (Member m : members) {
|
||||||
if (m.accessModifier().equals("public") || m.accessModifier().equals("protected")) {
|
if (m.accessModifier().equals("public") || m.accessModifier().equals("protected")) {
|
||||||
withoutPrivate.add(m);
|
withoutPrivate.add(m);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.intellij.psi.*;
|
|||||||
import com.intellij.psi.impl.source.PsiClassReferenceType;
|
import com.intellij.psi.impl.source.PsiClassReferenceType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.j2k.Converter;
|
import org.jetbrains.jet.j2k.Converter;
|
||||||
|
import org.jetbrains.jet.j2k.J2KConverterFlags;
|
||||||
import org.jetbrains.jet.j2k.ast.*;
|
import org.jetbrains.jet.j2k.ast.*;
|
||||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||||
|
|
||||||
@@ -81,7 +82,7 @@ public class TypeVisitor extends PsiTypeVisitor<Type> {
|
|||||||
if (psiClass != null) {
|
if (psiClass != null) {
|
||||||
String qualifiedName = psiClass.getQualifiedName();
|
String qualifiedName = psiClass.getQualifiedName();
|
||||||
if (qualifiedName != null) {
|
if (qualifiedName != null) {
|
||||||
if (!qualifiedName.equals("java.lang.Object") && Converter.hasSetting("fqn")) {
|
if (!qualifiedName.equals("java.lang.Object") && Converter.hasFlag(J2KConverterFlags.FULLY_QUALIFIED_TYPE_NAMES)) {
|
||||||
return new IdentifierImpl(qualifiedName);
|
return new IdentifierImpl(qualifiedName);
|
||||||
}
|
}
|
||||||
if (qualifiedName.equals(JAVA_LANG_ITERABLE)) {
|
if (qualifiedName.equals(JAVA_LANG_ITERABLE)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user