kj2k initial checkin
This commit is contained in:
committed by
Pavel V. Talanov
parent
6fbf97bbcf
commit
34da39c55b
@@ -0,0 +1,655 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AntConfiguration">
|
||||
<defaultAnt bundledAnt="true" />
|
||||
</component>
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" build-on-make="true" name="j2k:jar">
|
||||
<output-path>$PROJECT_DIR$/out/artifacts/j2k_jar</output-path>
|
||||
<root id="archive" name="j2k.jar">
|
||||
<element id="directory" name="META-INF">
|
||||
<element id="file-copy" path="$PROJECT_DIR$/src/META-INF/MANIFEST.MF" />
|
||||
</element>
|
||||
<element id="module-output" name="j2k" />
|
||||
</root>
|
||||
</artifact>
|
||||
<artifact type="jar" build-on-make="true" name="java2kotlin:jar">
|
||||
<output-path>$PROJECT_DIR$/out/artifacts/java2kotlin_jar</output-path>
|
||||
<root id="archive" name="java2kotlin.jar">
|
||||
<element id="directory" name="META-INF">
|
||||
<element id="file-copy" path="$PROJECT_DIR$/src/META-INF/MANIFEST.MF" />
|
||||
</element>
|
||||
<element id="module-output" name="j2k" />
|
||||
<element id="extracted-dir" path="$PROJECT_DIR$/lib/commons-io-2.1.jar" path-in-jar="/" />
|
||||
<element id="extracted-dir" path="$PROJECT_DIR$/lib/commons-cli-1.2.jar" path-in-jar="/" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
||||
<component name="CompilerConfiguration">
|
||||
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||
<resourceExtensions />
|
||||
<wildcardResourcePatterns>
|
||||
<entry name="?*.properties" />
|
||||
<entry name="?*.xml" />
|
||||
<entry name="?*.gif" />
|
||||
<entry name="?*.png" />
|
||||
<entry name="?*.jpeg" />
|
||||
<entry name="?*.jpg" />
|
||||
<entry name="?*.html" />
|
||||
<entry name="?*.dtd" />
|
||||
<entry name="?*.tld" />
|
||||
<entry name="?*.ftl" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing enabled="false" useClasspath="true" />
|
||||
</component>
|
||||
<component name="CopyrightManager" default="">
|
||||
<module2copyright />
|
||||
</component>
|
||||
<component name="DependencyValidationManager">
|
||||
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
|
||||
</component>
|
||||
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
|
||||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0" />
|
||||
</component>
|
||||
<component name="IdProvider" IDEtalkID="85E718DEBECB31403A7B26BEC4D25543" />
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profiles>
|
||||
<profile version="1.0" is_locked="false">
|
||||
<option name="myName" value="Project Default" />
|
||||
<option name="myLocal" value="false" />
|
||||
<inspection_tool class="AbstractMethodCallInConstructor" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="ArchaicSystemPropertyAccess" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AssignmentToForLoopParameter" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="m_checkForeachParameters" value="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="AssignmentToStaticFieldFromInstanceMethod" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<scope name="IDEA Test Sources" level="WARNING" enabled="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="AssignmentUsedAsCondition" enabled="false" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AutoBoxing" enabled="true" level="WARNING" enabled_by_default="false">
|
||||
<scope name="runtime.classes" level="WARNING" enabled="true">
|
||||
<option name="ignoreAddedToCollection" value="false" />
|
||||
</scope>
|
||||
<option name="ignoreAddedToCollection" value="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="AutoUnboxing" enabled="true" level="WARNING" enabled_by_default="false">
|
||||
<scope name="runtime.classes" level="WARNING" enabled="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="BooleanMethodIsAlwaysInverted" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="BusyWait" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="CStyleArrayDeclaration" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="CastConflictsWithInstanceof" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="CastToIncompatibleInterface" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="ChainedEquality" enabled="false" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="ClassNameSameAsAncestorName" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="CloneCallsSuperClone" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="CloneDeclaresCloneNotSupported" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="ComparisonOfShortAndChar" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="ConditionalExpressionWithIdenticalBranches" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="ConfusingOctalEscape" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="ConstantConditionalExpression" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<scope name="IDEA Test Sources" level="WARNING" enabled="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="ConstantConditions" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<scope name="runtime.classes" level="WARNING" enabled="false">
|
||||
<option name="SUGGEST_NULLABLE_ANNOTATIONS" value="false" />
|
||||
<option name="DONT_REPORT_TRUE_ASSERT_STATEMENTS" value="false" />
|
||||
</scope>
|
||||
<option name="SUGGEST_NULLABLE_ANNOTATIONS" value="true" />
|
||||
<option name="DONT_REPORT_TRUE_ASSERT_STATEMENTS" value="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="ConstantIfStatement" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<scope name="IDEA Test Sources" level="WARNING" enabled="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="ContinueOrBreakFromFinallyBlock" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="CovariantCompareTo" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="CovariantEquals" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="DoubleCheckedLocking" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoreOnVolatileVariables" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="DuplicateCondition" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoreMethodCalls" value="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="EmptySynchronizedStatement" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="EnumSwitchStatementWhichMissesCases" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoreSwitchStatementsWithDefault" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="ExceptionNameDoesntEndWithException" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="FieldAccessedSynchronizedAndUnsynchronized" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="countGettersAndSetters" value="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="FieldMayBeStatic" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="Finalize" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoreTrivialFinalizers" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="FinalizeNotProtected" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="ForLoopReplaceableByWhile" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="m_ignoreLoopsWithoutConditions" value="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="ForLoopThatDoesntUseLoopVariable" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="HtmlUnknownTag" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="myValues">
|
||||
<value>
|
||||
<list size="5">
|
||||
<item index="0" class="java.lang.String" itemvalue="nobr" />
|
||||
<item index="1" class="java.lang.String" itemvalue="noembed" />
|
||||
<item index="2" class="java.lang.String" itemvalue="comment" />
|
||||
<item index="3" class="java.lang.String" itemvalue="noscript" />
|
||||
<item index="4" class="java.lang.String" itemvalue="javascript" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
<option name="myCustomValuesEnabled" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="IOResource" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredTypesString" value="java.io.ByteArrayOutputStream,java.io.ByteArrayInputStream,java.io.StringBufferInputStream,java.io.CharArrayWriter,java.io.CharArrayReader,java.io.StringWriter,java.io.StringReader" />
|
||||
<option name="insideTryAllowed" value="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="IfStatementWithIdenticalBranches" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="InnerClassMayBeStatic" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="InstanceofCatchParameter" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="InstanceofIncompatibleInterface" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="JUnitTestClassNamingConvention" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="m_regex" value="[A-Z][A-Za-z0-9]*Test" />
|
||||
<option name="m_minLength" value="8" />
|
||||
<option name="m_maxLength" value="64" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="false">
|
||||
<scope name="IDEA Test Sources" level="WARNING" enabled="false">
|
||||
<option name="TOP_LEVEL_CLASS_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="INNER_CLASS_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="METHOD_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="FIELD_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="IGNORE_DEPRECATED" value="false" />
|
||||
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
|
||||
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
|
||||
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
|
||||
<option name="myAdditionalJavadocTags" value="" />
|
||||
</scope>
|
||||
<scope name="idea openapi" level="WARNING" enabled="true">
|
||||
<option name="TOP_LEVEL_CLASS_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="INNER_CLASS_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="METHOD_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="FIELD_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="IGNORE_DEPRECATED" value="true" />
|
||||
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
|
||||
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
|
||||
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
|
||||
<option name="myAdditionalJavadocTags" value="" />
|
||||
</scope>
|
||||
<scope name="runtime.classes" level="WARNING" enabled="true">
|
||||
<option name="TOP_LEVEL_CLASS_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="INNER_CLASS_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="METHOD_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="FIELD_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="IGNORE_DEPRECATED" value="false" />
|
||||
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
|
||||
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
|
||||
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
|
||||
<option name="myAdditionalJavadocTags" value="" />
|
||||
</scope>
|
||||
<option name="TOP_LEVEL_CLASS_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="INNER_CLASS_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="METHOD_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="FIELD_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="IGNORE_DEPRECATED" value="false" />
|
||||
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
|
||||
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
|
||||
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
|
||||
<option name="myAdditionalJavadocTags" value="" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="JavadocReference" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<scope name="IDEA Test Sources" level="ERROR" enabled="false" />
|
||||
<scope name="idea openapi" level="WARNING" enabled="true" />
|
||||
<scope name="runtime.classes" level="ERROR" enabled="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="MethodMayBeStatic" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="m_onlyPrivateOrFinal" value="false" />
|
||||
<option name="m_ignoreEmptyMethods" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="MethodNamesDifferOnlyByCase" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="MethodOverloadsParentMethod" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="MethodOverridesPrivateMethod" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="MethodOverridesStaticMethod" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="MisspelledCompareTo" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="MisspelledEquals" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="MisspelledHashcode" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="MisspelledSetUp" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="MisspelledTearDown" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="MisspelledToString" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="MultipleDeclaration" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoreForLoopDeclarations" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="MultipleTypedDeclaration" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="NestedSynchronizedStatement" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="NoExplicitFinalizeCalls" enabled="true" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="NonExceptionNameEndsWithException" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="NonStaticFinalLogger" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<scope name="IDEA Test Sources" level="WARNING" enabled="false">
|
||||
<option name="loggerClassName" value="java.util.logging.Logger" />
|
||||
</scope>
|
||||
<option name="loggerClassName" value="java.util.logging.Logger" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="NonSynchronizedMethodOverridesSynchronizedMethod" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="ObjectEqualsNull" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="ObjectNotify" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="ObsoleteCollection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoreRequiredObsoleteCollectionTypes" value="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PointlessArithmeticExpression" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="m_ignoreExpressionsContainingConstants" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="ProtectedMemberInFinalClass" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="PublicFieldAccessedInSynchronizedContext" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="PyCompatibilityInspection" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="fromVersion" value="2.4" />
|
||||
<option name="toVersion" value="3.1" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="ReplaceAssignmentWithOperatorAssignment" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoreLazyOperators" value="true" />
|
||||
<option name="ignoreObscureOperators" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="SSBasedInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<searchConfiguration name="SwingUtilities.invokeLater" text="SwingUtilities.invokeLater($runnable$)" recursive="false" caseInsensitive="false" type="JAVA">
|
||||
<constraint name="Instance" regexp="SwingUtilities" minCount="0" target="true" within="" contains="" />
|
||||
<constraint name="MethodCall" within="" contains="" />
|
||||
<constraint name="Parameter" minCount="0" maxCount="2147483647" within="" contains="" />
|
||||
<constraint name="__context__" within="" contains="" />
|
||||
<constraint name="runnable" within="" contains="" />
|
||||
</searchConfiguration>
|
||||
<replaceConfiguration name="DirectCallOfDispose" text="$Instance$.dispose()" recursive="false" caseInsensitive="false" type="JAVA" reformatAccordingToStyle="true" shortenFQN="true" replacement="Disposer.dispose($Instance$)">
|
||||
<constraint name="Instance" regexp="super" nameOfExprType="Disposable" withinHierarchy="true" exprTypeWithinHierarchy="true" minCount="0" negateName="true" within="" contains="" />
|
||||
<constraint name="MethodCall" target="true" within="" contains="" />
|
||||
<constraint name="Parameter" minCount="0" maxCount="2147483647" within="" contains="" />
|
||||
<constraint name="__context__" within="" contains="" />
|
||||
</replaceConfiguration>
|
||||
<replaceConfiguration name="new Object[0]" text="new Object[0]" recursive="false" caseInsensitive="true" type="JAVA" reformatAccordingToStyle="true" shortenFQN="true" replacement="com.intellij.util.ArrayUtil.EMPTY_OBJECT_ARRAY" />
|
||||
<replaceConfiguration name="new String[0]" text="new String[0]" recursive="false" caseInsensitive="true" type="JAVA" reformatAccordingToStyle="true" shortenFQN="true" replacement="com.intellij.util.ArrayUtil.EMPTY_STRING_ARRAY" />
|
||||
<replaceConfiguration name="new Class[0]" text="new Class[0]" recursive="false" caseInsensitive="true" type="JAVA" reformatAccordingToStyle="true" shortenFQN="true" replacement="com.intellij.util.ArrayUtil.EMPTY_CLASS_ARRAY" />
|
||||
<replaceConfiguration name="Log.error" text="$LOG$.assertTrue(false, $e$)" recursive="false" caseInsensitive="true" type="JAVA" reformatAccordingToStyle="true" shortenFQN="true" replacement="$LOG$.error($e$)">
|
||||
<constraint name="e" within="" contains="" />
|
||||
<constraint name="LOG" within="" contains="" />
|
||||
</replaceConfiguration>
|
||||
<replaceConfiguration name="toStringArray" text="$collection$.toArray(new String[$collection$.size()])" recursive="false" caseInsensitive="true" type="JAVA" reformatAccordingToStyle="true" shortenFQN="true" replacement="com.intellij.util.ArrayUtil.toStringArray($collection$)">
|
||||
<constraint name="collection" within="" contains="" />
|
||||
</replaceConfiguration>
|
||||
<replaceConfiguration name="toObjectArray" text="$collection$.toArray(new Object[$collection$.size()])" recursive="false" caseInsensitive="true" type="JAVA" reformatAccordingToStyle="true" shortenFQN="true" replacement="com.intellij.util.ArrayUtil.toObjectArray($collection$)">
|
||||
<constraint name="collection" within="" contains="" />
|
||||
</replaceConfiguration>
|
||||
<replaceConfiguration name="toStringArray0" text="$collection$.toArray(new String[0])" recursive="false" caseInsensitive="true" type="JAVA" reformatAccordingToStyle="true" shortenFQN="true" replacement="com.intellij.util.ArrayUtil.toStringArray($collection$)">
|
||||
<constraint name="collection" within="" contains="" />
|
||||
</replaceConfiguration>
|
||||
<replaceConfiguration name="toObjectArray0" text="$collection$.toArray(new Object[0])" recursive="false" caseInsensitive="true" type="JAVA" reformatAccordingToStyle="true" shortenFQN="true" replacement="com.intellij.util.ArrayUtil.toObjectArray($collection$)">
|
||||
<constraint name="collection" within="" contains="" />
|
||||
</replaceConfiguration>
|
||||
<replaceConfiguration name="toStringArray00" text="$collection$.toArray(ArrayUtil.EMPTY_STRING_ARRAY)" recursive="false" caseInsensitive="true" type="JAVA" reformatAccordingToStyle="true" shortenFQN="true" replacement="com.intellij.util.ArrayUtil.toStringArray($collection$)">
|
||||
<constraint name="collection" within="" contains="" />
|
||||
</replaceConfiguration>
|
||||
<replaceConfiguration name="toObjectArray00" text="$collection$.toArray(ArrayUtil.EMPTY_OBJECT_ARRAY)" recursive="false" caseInsensitive="true" type="JAVA" reformatAccordingToStyle="true" shortenFQN="true" replacement="com.intellij.util.ArrayUtil.toObjectArray($collection$)">
|
||||
<constraint name="collection" within="" contains="" />
|
||||
</replaceConfiguration>
|
||||
<replaceConfiguration name="File.createTempFile" text="java.io.File.createTempFile($prefix$, $suffix$)" recursive="false" caseInsensitive="true" type="JAVA" reformatAccordingToStyle="true" shortenFQN="true" replacement="com.intellij.openapi.util.io.FileUtil.createTempFile($prefix$, $suffix$)">
|
||||
<constraint name="prefix" within="" contains="" />
|
||||
<constraint name="suffix" within="" contains="" />
|
||||
</replaceConfiguration>
|
||||
<replaceConfiguration name="File.createTempFile(dir)" text="java.io.File.createTempFile($prefix$, $suffix$, $dir$)" recursive="false" caseInsensitive="true" type="JAVA" reformatAccordingToStyle="true" shortenFQN="true" replacement="com.intellij.openapi.util.io.FileUtil.createTempFile($dir$, $prefix$, $suffix$, true)">
|
||||
<constraint name="prefix" within="" contains="" />
|
||||
<constraint name="suffix" within="" contains="" />
|
||||
<constraint name="dir" within="" contains="" />
|
||||
</replaceConfiguration>
|
||||
<searchConfiguration name="Use RecursionManager?" text="class $Class$ { ThreadLocal<$FieldType$> $FieldName$ = $Init$; }" recursive="false" caseInsensitive="false" type="JAVA">
|
||||
<constraint name="Class" script="""" within="" contains="" />
|
||||
<constraint name="FieldType" script="""" regexp="Collection" withinHierarchy="true" maxCount="2147483647" target="true" wholeWordsOnly="true" within="" contains="" />
|
||||
<constraint name="FieldName" script="""" maxCount="2147483647" within="" contains="" />
|
||||
<constraint name="Init" script="""" minCount="0" maxCount="2147483647" within="" contains="" />
|
||||
<constraint name="__context__" script="""" within="" contains="" />
|
||||
</searchConfiguration>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="SetReplaceableByEnumSet" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="SetupCallsSuperSetup" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="SetupIsPublicVoidNoArg" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="SimplifiableIfStatement" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="Since15" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<scope name="IDEA Test Sources" level="ERROR" enabled="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="SocketResource" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="insideTryAllowed" value="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="StaticCallOnSubclass" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="StaticFieldReferenceOnSubclass" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="StaticSuite" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="StringConstructor" enabled="false" level="WARNING" enabled_by_default="false">
|
||||
<option name="ignoreSubstringArguments" value="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="StringEquality" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="StringEqualsEmptyString" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="SwitchStatementWithConfusingDeclaration" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="SynchronizeOnThis" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="SystemOutErr" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<scope name="IDEA Test Sources" level="WARNING" enabled="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="TeardownCallsSuperTeardown" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="TeardownIsPublicVoidNoArg" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="TestMethodIsPublicVoidNoArg" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="TestOnlyProblems" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="TextLabelInSwitchStatement" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="ThreadDumpStack" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<scope name="IDEA Test Sources" level="WARNING" enabled="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="ThreadRun" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="ThreadStartInConstruction" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="ThrowablePrintStackTrace" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<scope name="IDEA Test Sources" level="WARNING" enabled="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="TrivialIf" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="TrivialStringConcatenation" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="UndeclaredTests" enabled="true" level="WARNING" enabled_by_default="false">
|
||||
<scope name="Tests" level="WARNING" enabled="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="UnnecessarilyQualifiedStaticUsage" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<scope name="IDEA Test Sources" level="WARNING" enabled="false">
|
||||
<option name="m_ignoreStaticFieldAccesses" value="false" />
|
||||
<option name="m_ignoreStaticMethodCalls" value="false" />
|
||||
<option name="m_ignoreStaticAccessFromStaticContext" value="false" />
|
||||
</scope>
|
||||
<option name="m_ignoreStaticFieldAccesses" value="false" />
|
||||
<option name="m_ignoreStaticMethodCalls" value="false" />
|
||||
<option name="m_ignoreStaticAccessFromStaticContext" value="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="UnnecessaryBoxing" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="UnnecessaryFullyQualifiedName" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<scope name="IDEA Test Sources" level="WARNING" enabled="false">
|
||||
<option name="m_ignoreJavadoc" value="false" />
|
||||
</scope>
|
||||
<option name="m_ignoreJavadoc" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="UnnecessaryInterfaceModifier" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="UnnecessaryLabelOnBreakStatement" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="UnnecessaryLabelOnContinueStatement" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="UnnecessaryQualifierForThis" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="UnnecessaryUnboxing" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="UseOfPropertiesAsHashtable" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="UtilityClassWithPublicConstructor" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="UtilityClassWithoutPrivateConstructor" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoreClassesWithOnlyMain" value="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="VolatileLongOrDoubleField" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="WaitNotInLoop" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="WaitNotInSynchronizedContext" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="WaitWhileHoldingTwoLocks" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="WeakerAccess" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="SUGGEST_PACKAGE_LOCAL_FOR_MEMBERS" value="false" />
|
||||
<option name="SUGGEST_PACKAGE_LOCAL_FOR_TOP_CLASSES" value="false" />
|
||||
<option name="SUGGEST_PRIVATE_FOR_INNERS" value="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="WhileLoopSpinsOnField" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoreNonEmtpyLoops" value="false" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</profiles>
|
||||
<option name="PROJECT_PROFILE" value="Project Default" />
|
||||
<option name="USE_PROJECT_PROFILE" value="true" />
|
||||
<version value="1.0" />
|
||||
</component>
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
<component name="ProjectCodeStyleSettingsManager">
|
||||
<option name="PER_PROJECT_SETTINGS">
|
||||
<value>
|
||||
<XML>
|
||||
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
|
||||
</XML>
|
||||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="ignatov">
|
||||
<words>
|
||||
<w>kotlin</w>
|
||||
<w>nullable</w>
|
||||
<w>ushr</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/j2k.iml" filepath="$PROJECT_DIR$/j2k.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
<component name="ProjectResources">
|
||||
<default-html-doctype>http://www.w3.org/1999/xhtml</default-html-doctype>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA IC-117.117" project-jdk-type="IDEA JDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
<component name="WebServicesPlugin" addRequiredLibraries="true" />
|
||||
<component name="libraryTable">
|
||||
<library name="commons-cli-1.2">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/commons-cli-1.2.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
<library name="commons-io-2.1">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/commons-io-2.1.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
<library name="KotlinRuntime">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/kotlin-runtime.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/kotlin-runtime.jar!/src" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: org.jetbrains.jet.j2k.JavaToKotlinCli
|
||||
|
||||
@@ -0,0 +1,823 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.j2k.ast.*;
|
||||
import org.jetbrains.jet.j2k.ast.Class;
|
||||
import org.jetbrains.jet.j2k.ast.Enum;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
import org.jetbrains.jet.j2k.visitors.*;
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.j2k.ConverterUtil.countWritingAccesses;
|
||||
import static org.jetbrains.jet.j2k.ConverterUtil.createMainFunction;
|
||||
import static org.jetbrains.jet.j2k.visitors.TypeVisitor.*;
|
||||
import static org.jetbrains.jet.lang.types.expressions.OperatorConventions.*;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class Converter {
|
||||
@NotNull
|
||||
public static final Set<String> NOT_NULL_ANNOTATIONS = ImmutableSet.of(
|
||||
"org.jetbrains.annotations.NotNull",
|
||||
"com.sun.istack.internal.NotNull",
|
||||
"javax.annotation.Nonnull"
|
||||
);
|
||||
|
||||
@NotNull
|
||||
private Set<String> classIdentifiers = Sets.newHashSet();
|
||||
|
||||
@NotNull
|
||||
private final Dispatcher dispatcher = new Dispatcher(this);
|
||||
|
||||
@Nullable
|
||||
private PsiType methodReturnType = null;
|
||||
|
||||
@NotNull
|
||||
private final Set<J2KConverterFlags> flags = Sets.newHashSet();
|
||||
|
||||
public Converter() {
|
||||
}
|
||||
|
||||
public boolean addFlag(@NotNull J2KConverterFlags flag) {
|
||||
return flags.add(flag);
|
||||
}
|
||||
|
||||
public boolean hasFlag(@NotNull J2KConverterFlags flag) {
|
||||
return flags.contains(flag);
|
||||
}
|
||||
|
||||
public void setClassIdentifiers(@NotNull Set<String> identifiers) {
|
||||
classIdentifiers = identifiers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<String> getClassIdentifiers() {
|
||||
return Collections.unmodifiableSet(classIdentifiers);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PsiType getMethodReturnType() {
|
||||
return methodReturnType;
|
||||
}
|
||||
|
||||
public void clearClassIdentifiers() {
|
||||
classIdentifiers.clear();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String elementToKotlin(@NotNull PsiElement element) {
|
||||
if (element instanceof PsiJavaFile) {
|
||||
return fileToFile((PsiJavaFile) element).toKotlin();
|
||||
}
|
||||
|
||||
if (element instanceof PsiClass) {
|
||||
return classToClass((PsiClass) element).toKotlin();
|
||||
}
|
||||
|
||||
if (element instanceof PsiMethod) {
|
||||
return methodToFunction((PsiMethod) element).toKotlin();
|
||||
}
|
||||
|
||||
if (element instanceof PsiField) {
|
||||
PsiField field = (PsiField) element;
|
||||
return fieldToField(field, field.getContainingClass()).toKotlin();
|
||||
}
|
||||
|
||||
if (element instanceof PsiStatement) {
|
||||
return statementToStatement((PsiStatement) element).toKotlin();
|
||||
}
|
||||
|
||||
if (element instanceof PsiExpression) {
|
||||
return expressionToExpression((PsiExpression) element).toKotlin();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public File fileToFile(@NotNull PsiJavaFile javaFile) {
|
||||
return fileToFile(javaFile, Collections.<String>emptyList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public File fileToFileWithCompatibilityImport(@NotNull PsiJavaFile javaFile) {
|
||||
return fileToFile(javaFile, Collections.singletonList("kotlin.compatibility.*"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private File fileToFile(PsiJavaFile javaFile, List<String> additionalImports) {
|
||||
final PsiImportList importList = javaFile.getImportList();
|
||||
List<Import> imports = importList == null
|
||||
? Collections.<Import>emptyList()
|
||||
: importsToImportList(importList.getAllImportStatements());
|
||||
for (String i : additionalImports)
|
||||
imports.add(new Import(i));
|
||||
return new File(quoteKeywords(javaFile.getPackageName()), imports, classesToClassList(javaFile.getClasses()), createMainFunction(javaFile));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String quoteKeywords(@NotNull String packageName) {
|
||||
List<String> result = new LinkedList<String>();
|
||||
for (String part : packageName.split("\\."))
|
||||
result.add(new IdentifierImpl(part).toKotlin());
|
||||
return AstUtil.join(result, ".");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<Class> classesToClassList(@NotNull PsiClass[] classes) {
|
||||
List<Class> result = new LinkedList<Class>();
|
||||
for (PsiClass t : classes) result.add(classToClass(t));
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public AnonymousClass anonymousClassToAnonymousClass(@NotNull PsiAnonymousClass anonymousClass) {
|
||||
return new AnonymousClass(this, getMembers(anonymousClass));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<Member> getMembers(@NotNull PsiClass psiClass) {
|
||||
List<Member> members = new LinkedList<Member>();
|
||||
for (PsiElement e : psiClass.getChildren()) {
|
||||
if (e instanceof PsiMethod) {
|
||||
members.add(methodToFunction((PsiMethod) e, true));
|
||||
}
|
||||
else if (e instanceof PsiField) {
|
||||
members.add(fieldToField((PsiField) e, psiClass));
|
||||
}
|
||||
else if (e instanceof PsiClass) {
|
||||
members.add(classToClass((PsiClass) e));
|
||||
}
|
||||
else if (e instanceof PsiClassInitializer) {
|
||||
members.add(initializerToInitializer((PsiClassInitializer) e));
|
||||
}
|
||||
else if (e instanceof PsiMember) System.out.println(e.getClass() + " " + e.getText());
|
||||
}
|
||||
return members;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<Field> getFinalOrWithEmptyInitializer(@NotNull List<? extends Field> fields) {
|
||||
List<Field> result = new LinkedList<Field>();
|
||||
for (Field f : fields)
|
||||
if (f.isVal() || f.getInitializer().toKotlin().isEmpty()) {
|
||||
result.add(f);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<Parameter> createParametersFromFields(@NotNull List<? extends Field> fields) {
|
||||
List<Parameter> result = new LinkedList<Parameter>();
|
||||
for (Field f : fields)
|
||||
result.add(new Parameter(new IdentifierImpl("_" + f.getIdentifier().getName()), f.getType()));
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<Statement> createInitStatementsFromFields(@NotNull List<? extends Field> fields) {
|
||||
List<Statement> result = new LinkedList<Statement>();
|
||||
for (Field f : fields) {
|
||||
final String identifierToKotlin = f.getIdentifier().toKotlin();
|
||||
result.add(new DummyStringExpression(identifierToKotlin + " = " + "_" + identifierToKotlin));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String createPrimaryConstructorInvocation(@NotNull String s, @NotNull List<? extends Field> fields, @NotNull Map<String, String> initializers) {
|
||||
List<String> result = new LinkedList<String>();
|
||||
for (Field f : fields) {
|
||||
final String id = f.getIdentifier().toKotlin();
|
||||
result.add(initializers.get(id));
|
||||
}
|
||||
return s + "(" + AstUtil.join(result, ", ") + ")";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Class classToClass(@NotNull PsiClass psiClass) {
|
||||
final Set<String> modifiers = modifiersListToModifiersSet(psiClass.getModifierList());
|
||||
final List<Field> fields = fieldsToFieldList(psiClass.getFields(), psiClass);
|
||||
final List<Element> typeParameters = elementsToElementList(psiClass.getTypeParameters());
|
||||
final List<Type> implementsTypes = typesToNotNullableTypeList(psiClass.getImplementsListTypes());
|
||||
final List<Type> extendsTypes = typesToNotNullableTypeList(psiClass.getExtendsListTypes());
|
||||
final IdentifierImpl name = new IdentifierImpl(psiClass.getName());
|
||||
final List<Expression> baseClassParams = new LinkedList<Expression>();
|
||||
|
||||
List<Member> members = getMembers(psiClass);
|
||||
|
||||
// we try to find super() call and generate class declaration like that: class A(name: String, i : Int) : Base(name)
|
||||
final SuperVisitor visitor = new SuperVisitor();
|
||||
psiClass.accept(visitor);
|
||||
final HashSet<PsiExpressionList> resolvedSuperCallParameters = visitor.getResolvedSuperCallParameters();
|
||||
if (resolvedSuperCallParameters.size() == 1) {
|
||||
baseClassParams.addAll(
|
||||
expressionsToExpressionList(
|
||||
resolvedSuperCallParameters.toArray(new PsiExpressionList[1])[0].getExpressions()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// we create primary constructor from all non final fields and fields without initializers
|
||||
if (!psiClass.isEnum() && !psiClass.isInterface() && psiClass.getConstructors().length > 1 && getPrimaryConstructorForThisCase(psiClass) == null) {
|
||||
final List<Field> finalOrWithEmptyInitializer = getFinalOrWithEmptyInitializer(fields);
|
||||
final Map<String, String> initializers = new HashMap<String, String>();
|
||||
|
||||
for (final Member m : members) {
|
||||
// and modify secondaries
|
||||
if (m.getKind() == INode.Kind.CONSTRUCTOR) {
|
||||
Function f = (Function) m;
|
||||
if (!((Constructor) f).isPrimary()) {
|
||||
for (Field fo : finalOrWithEmptyInitializer) {
|
||||
String init = getDefaultInitializer(fo);
|
||||
initializers.put(fo.getIdentifier().toKotlin(), init);
|
||||
}
|
||||
|
||||
final List<Statement> newStatements = new LinkedList<Statement>();
|
||||
|
||||
for (Statement s : f.getBlock().getStatements()) {
|
||||
boolean isRemoved = false;
|
||||
|
||||
if (s.getKind() == INode.Kind.ASSIGNMENT_EXPRESSION) {
|
||||
final AssignmentExpression assignmentExpression = (AssignmentExpression) s;
|
||||
if (assignmentExpression.getLeft().getKind() == INode.Kind.CALL_CHAIN) {
|
||||
for (Field fo : finalOrWithEmptyInitializer) {
|
||||
final String id = fo.getIdentifier().toKotlin();
|
||||
if (((CallChainExpression) assignmentExpression.getLeft()).getIdentifier().toKotlin().endsWith("." + id)) {
|
||||
initializers.put(id, assignmentExpression.getRight().toKotlin());
|
||||
isRemoved = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isRemoved) {
|
||||
newStatements.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
newStatements.add(
|
||||
0,
|
||||
new DummyStringExpression(
|
||||
"val __ = " + createPrimaryConstructorInvocation(
|
||||
name.toKotlin(),
|
||||
finalOrWithEmptyInitializer,
|
||||
initializers)));
|
||||
|
||||
f.setBlock(new Block(newStatements));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
members.add(
|
||||
new Constructor(
|
||||
Identifier.EMPTY_IDENTIFIER,
|
||||
Collections.<String>emptySet(),
|
||||
new ClassType(name),
|
||||
Collections.<Element>emptyList(),
|
||||
new ParameterList(createParametersFromFields(finalOrWithEmptyInitializer)),
|
||||
new Block(createInitStatementsFromFields(finalOrWithEmptyInitializer)),
|
||||
true
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (psiClass.isInterface()) {
|
||||
return new Trait(this, name, modifiers, typeParameters, extendsTypes, Collections.<Expression>emptyList(), implementsTypes, members);
|
||||
}
|
||||
if (psiClass.isEnum()) {
|
||||
return new Enum(this, name, modifiers, typeParameters, Collections.<Type>emptyList(), Collections.<Expression>emptyList(), implementsTypes, members);
|
||||
}
|
||||
return new Class(this, name, modifiers, typeParameters, extendsTypes, baseClassParams, implementsTypes, members);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Initializer initializerToInitializer(@NotNull PsiClassInitializer i) {
|
||||
return new Initializer(
|
||||
blockToBlock(i.getBody(), true),
|
||||
modifiersListToModifiersSet(i.getModifierList())
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getDefaultInitializer(@NotNull Field f) {
|
||||
if (f.getType().isNullable()) {
|
||||
return "null";
|
||||
}
|
||||
else {
|
||||
final String typeToKotlin = f.getType().toKotlin();
|
||||
if (typeToKotlin.equals("Boolean")) return "false";
|
||||
if (typeToKotlin.equals("Char")) return "' '";
|
||||
if (typeToKotlin.equals("Double")) return "0." + OperatorConventions.DOUBLE + "()";
|
||||
if (typeToKotlin.equals("Float")) return "0." + OperatorConventions.FLOAT + "()";
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<Field> fieldsToFieldList(@NotNull PsiField[] fields, PsiClass psiClass) {
|
||||
List<Field> result = new LinkedList<Field>();
|
||||
for (PsiField f : fields) result.add(fieldToField(f, psiClass));
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Field fieldToField(@NotNull PsiField field, PsiClass psiClass) {
|
||||
Set<String> modifiers = modifiersListToModifiersSet(field.getModifierList());
|
||||
if (field instanceof PsiEnumConstant) // TODO: remove instanceof
|
||||
{
|
||||
return new EnumConstant(
|
||||
new IdentifierImpl(field.getName()), // TODO
|
||||
modifiers,
|
||||
typeToType(field.getType()),
|
||||
elementToElement(((PsiEnumConstant) field).getArgumentList())
|
||||
);
|
||||
}
|
||||
return new Field(
|
||||
new IdentifierImpl(field.getName()), // TODO
|
||||
modifiers,
|
||||
typeToType(field.getType()),
|
||||
createSureCallOnlyForChain(field.getInitializer(), field.getType()), // TODO: add modifiers
|
||||
countWritingAccesses(field, psiClass)
|
||||
);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiMethod getPrimaryConstructorForThisCase(@NotNull PsiClass psiClass) {
|
||||
ThisVisitor tv = new ThisVisitor();
|
||||
psiClass.accept(tv);
|
||||
return tv.getPrimaryConstructor();
|
||||
}
|
||||
|
||||
public static boolean isConstructorPrimary(@NotNull PsiMethod constructor) {
|
||||
if (constructor.getParent() instanceof PsiClass) {
|
||||
final PsiClass parent = (PsiClass) constructor.getParent();
|
||||
if (parent.getConstructors().length == 1) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
PsiMethod c = getPrimaryConstructorForThisCase(parent); // TODO: move up to classToClass() method
|
||||
if (c != null && c.hashCode() == constructor.hashCode()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<Statement> removeEmpty(@NotNull List<Statement> statements) {
|
||||
List<Statement> result = new LinkedList<Statement>();
|
||||
for (Statement s : statements)
|
||||
if (s != Statement.EMPTY_STATEMENT && s != Expression.EMPTY_EXPRESSION) {
|
||||
result.add(s);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Function methodToFunction(@NotNull PsiMethod method) {
|
||||
return methodToFunction(method, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Function methodToFunction(@NotNull PsiMethod method, boolean notEmpty) {
|
||||
if (isOverrideObjectDirect(method)) {
|
||||
dispatcher.setExpressionVisitor(new ExpressionVisitorForDirectObjectInheritors(this));
|
||||
}
|
||||
else {
|
||||
dispatcher.setExpressionVisitor(new ExpressionVisitor(this));
|
||||
}
|
||||
|
||||
methodReturnType = method.getReturnType();
|
||||
|
||||
final IdentifierImpl identifier = new IdentifierImpl(method.getName());
|
||||
final Type returnType = typeToType(method.getReturnType(), ConverterUtil.isAnnotatedAsNotNull(method.getModifierList()));
|
||||
final Block body = hasFlag(J2KConverterFlags.SKIP_BODIES)
|
||||
? Block.EMPTY_BLOCK
|
||||
: blockToBlock(method.getBody(), notEmpty); // #TODO
|
||||
final Element params = createFunctionParameters(method);
|
||||
final List<Element> typeParameters = elementsToElementList(method.getTypeParameters());
|
||||
|
||||
final Set<String> modifiers = modifiersListToModifiersSet(method.getModifierList());
|
||||
if (isOverrideAnyMethodExceptMethodsFromObject(method)) {
|
||||
modifiers.add(Modifier.OVERRIDE);
|
||||
}
|
||||
if (method.getParent() instanceof PsiClass && ((PsiClass) method.getParent()).isInterface()) {
|
||||
modifiers.remove(Modifier.ABSTRACT);
|
||||
}
|
||||
if (isNotOpenMethod(method)) {
|
||||
modifiers.add(Modifier.NOT_OPEN);
|
||||
}
|
||||
|
||||
if (method.isConstructor()) { // TODO: simplify
|
||||
boolean isPrimary = isConstructorPrimary(method);
|
||||
return new Constructor(
|
||||
identifier,
|
||||
modifiers,
|
||||
returnType,
|
||||
typeParameters,
|
||||
params,
|
||||
new Block(removeEmpty(body.getStatements()), false),
|
||||
isPrimary
|
||||
);
|
||||
}
|
||||
return new Function(
|
||||
identifier,
|
||||
modifiers,
|
||||
returnType,
|
||||
typeParameters,
|
||||
params,
|
||||
body
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ParameterList createFunctionParameters(@NotNull PsiMethod method) {
|
||||
List<Parameter> result = new LinkedList<Parameter>();
|
||||
for (PsiParameter parameter : method.getParameterList().getParameters()) {
|
||||
result.add(new Parameter(
|
||||
new IdentifierImpl(parameter.getName()),
|
||||
typeToType(parameter.getType(), ConverterUtil.isAnnotatedAsNotNull(parameter.getModifierList())),
|
||||
ConverterUtil.isReadOnly(parameter, method.getBody())
|
||||
));
|
||||
}
|
||||
return new ParameterList(result);
|
||||
}
|
||||
|
||||
private static boolean isNotOpenMethod(@NotNull final PsiMethod method) {
|
||||
if (method.getParent() instanceof PsiClass) {
|
||||
final PsiModifierList parentModifierList = ((PsiClass) method.getParent()).getModifierList();
|
||||
if ((parentModifierList != null && parentModifierList.hasExplicitModifier(Modifier.FINAL)) || ((PsiClass) method.getParent()).isEnum()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isOverrideAnyMethodExceptMethodsFromObject(@NotNull PsiMethod method) {
|
||||
boolean counter = normalCase(method);
|
||||
if (counter) {
|
||||
return true;
|
||||
}
|
||||
if (isInheritFromObject(method)) {
|
||||
return caseForObject(method);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean caseForObject(@NotNull PsiMethod method) {
|
||||
PsiClass containing = method.getContainingClass();
|
||||
if (containing != null) {
|
||||
for (PsiClassType s : containing.getSuperTypes()) {
|
||||
String canonicalText = s.getCanonicalText();
|
||||
if (!canonicalText.equals(JAVA_LANG_OBJECT) && !getClassIdentifiers().contains(canonicalText)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean normalCase(@NotNull PsiMethod method) {
|
||||
int counter = 0;
|
||||
for (HierarchicalMethodSignature s : method.getHierarchicalMethodSignature().getSuperSignatures()) {
|
||||
PsiClass containingClass = s.getMethod().getContainingClass();
|
||||
String qualifiedName = containingClass != null ? containingClass.getQualifiedName() : "";
|
||||
if (qualifiedName != null && !qualifiedName.equals(JAVA_LANG_OBJECT)) {
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
return counter > 0;
|
||||
}
|
||||
|
||||
private static boolean isInheritFromObject(@NotNull PsiMethod method) {
|
||||
List<HierarchicalMethodSignature> superSignatures = method.getHierarchicalMethodSignature().getSuperSignatures();
|
||||
for (HierarchicalMethodSignature s : superSignatures) {
|
||||
PsiClass containingClass = s.getMethod().getContainingClass();
|
||||
String qualifiedName = containingClass != null ? containingClass.getQualifiedName() : "";
|
||||
if (qualifiedName != null && qualifiedName.equals(JAVA_LANG_OBJECT)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isOverrideObjectDirect(@NotNull final PsiMethod method) {
|
||||
List<HierarchicalMethodSignature> superSignatures = method.getHierarchicalMethodSignature().getSuperSignatures();
|
||||
if (superSignatures.size() == 1) {
|
||||
final PsiClass containingClass = superSignatures.get(0).getMethod().getContainingClass();
|
||||
final String qualifiedName = containingClass != null ? containingClass.getQualifiedName() : "";
|
||||
if (qualifiedName != null && qualifiedName.equals(JAVA_LANG_OBJECT)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Block blockToBlock(@Nullable PsiCodeBlock block, boolean notEmpty) {
|
||||
if (block == null) return Block.EMPTY_BLOCK;
|
||||
return new Block(statementsToStatementList(block.getStatements()), notEmpty);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Block blockToBlock(@Nullable PsiCodeBlock block) {
|
||||
return blockToBlock(block, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<Statement> statementsToStatementList(@NotNull PsiStatement[] statements) {
|
||||
List<Statement> result = new LinkedList<Statement>();
|
||||
for (PsiStatement t : statements) result.add(statementToStatement(t));
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<Statement> statementsToStatementList(@NotNull List<PsiStatement> statements) {
|
||||
List<Statement> result = new LinkedList<Statement>();
|
||||
for (PsiStatement t : statements) result.add(statementToStatement(t));
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Statement statementToStatement(@Nullable PsiStatement s) {
|
||||
if (s == null) return Statement.EMPTY_STATEMENT;
|
||||
final StatementVisitor statementVisitor = new StatementVisitor(this);
|
||||
s.accept(statementVisitor);
|
||||
return statementVisitor.getResult();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<Expression> expressionsToExpressionList(@NotNull PsiExpression[] expressions) {
|
||||
List<Expression> result = new LinkedList<Expression>();
|
||||
for (PsiExpression e : expressions) result.add(expressionToExpression(e));
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Expression expressionToExpression(@Nullable PsiExpression e) {
|
||||
if (e == null) return Expression.EMPTY_EXPRESSION;
|
||||
final ExpressionVisitor expressionVisitor = dispatcher.getExpressionVisitor();
|
||||
e.accept(expressionVisitor);
|
||||
return expressionVisitor.getResult();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Element elementToElement(@Nullable PsiElement e) {
|
||||
if (e == null) return Element.EMPTY_ELEMENT;
|
||||
final ElementVisitor elementVisitor = new ElementVisitor(this);
|
||||
e.accept(elementVisitor);
|
||||
return elementVisitor.getResult();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<Element> elementsToElementList(@NotNull PsiElement[] elements) {
|
||||
List<Element> result = new LinkedList<Element>();
|
||||
for (PsiElement e : elements) result.add(elementToElement(e));
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Type typeToType(@Nullable PsiType type) {
|
||||
if (type == null) return Type.EMPTY_TYPE;
|
||||
TypeVisitor typeVisitor = new TypeVisitor(this);
|
||||
type.accept(typeVisitor);
|
||||
return typeVisitor.getResult();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<Type> typesToTypeList(@NotNull PsiType[] types) {
|
||||
List<Type> result = new LinkedList<Type>();
|
||||
for (PsiType t : types) result.add(typeToType(t));
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Type typeToType(PsiType type, boolean notNull) {
|
||||
Type result = typeToType(type);
|
||||
if (notNull) {
|
||||
result.convertedToNotNull();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<Type> typesToNotNullableTypeList(@NotNull PsiType[] types) {
|
||||
List<Type> result = new LinkedList<Type>(typesToTypeList(types));
|
||||
for (Type p : result) p.convertedToNotNull();
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<Import> importsToImportList(@NotNull PsiImportStatementBase[] imports) {
|
||||
List<Import> result = new LinkedList<Import>();
|
||||
for (PsiImportStatementBase i : imports) {
|
||||
Import anImport = importToImport(i);
|
||||
String name = anImport.getName();
|
||||
if (!name.isEmpty() && !NOT_NULL_ANNOTATIONS.contains(name)) {
|
||||
result.add(anImport);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Import importToImport(@NotNull PsiImportStatementBase i) {
|
||||
final PsiJavaCodeReferenceElement reference = i.getImportReference();
|
||||
if (reference != null) {
|
||||
return new Import(quoteKeywords(reference.getQualifiedName()) + (i.isOnDemand() ? ".*" : ""));
|
||||
}
|
||||
return new Import("");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<Parameter> parametersToParameterList(@NotNull PsiParameter[] parameters) {
|
||||
List<Parameter> result = new LinkedList<Parameter>();
|
||||
for (PsiParameter t : parameters) result.add(parameterToParameter(t));
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Parameter parameterToParameter(@NotNull PsiParameter parameter) {
|
||||
return new Parameter(
|
||||
new IdentifierImpl(parameter.getName()),
|
||||
typeToType(parameter.getType(), ConverterUtil.isAnnotatedAsNotNull(parameter.getModifierList()))
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Identifier identifierToIdentifier(@Nullable PsiIdentifier identifier) {
|
||||
if (identifier == null) return Identifier.EMPTY_IDENTIFIER;
|
||||
return new IdentifierImpl(identifier.getText());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Set<String> modifiersListToModifiersSet(@Nullable PsiModifierList modifierList) {
|
||||
HashSet<String> modifiersSet = new HashSet<String>();
|
||||
if (modifierList != null) {
|
||||
if (modifierList.hasExplicitModifier(PsiModifier.ABSTRACT)) modifiersSet.add(Modifier.ABSTRACT);
|
||||
if (modifierList.hasModifierProperty(PsiModifier.FINAL)) modifiersSet.add(Modifier.FINAL);
|
||||
if (modifierList.hasModifierProperty(PsiModifier.STATIC)) modifiersSet.add(Modifier.STATIC);
|
||||
if (modifierList.hasExplicitModifier(PsiModifier.PUBLIC)) modifiersSet.add(Modifier.PUBLIC);
|
||||
if (modifierList.hasExplicitModifier(PsiModifier.PROTECTED)) modifiersSet.add(Modifier.PROTECTED);
|
||||
if (modifierList.hasExplicitModifier(PsiModifier.PACKAGE_LOCAL)) modifiersSet.add(Modifier.INTERNAL);
|
||||
if (modifierList.hasExplicitModifier(PsiModifier.PRIVATE)) modifiersSet.add(Modifier.PRIVATE);
|
||||
}
|
||||
return modifiersSet;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<String> createConversions(@NotNull PsiCallExpression expression) {
|
||||
PsiExpressionList argumentList = expression.getArgumentList();
|
||||
PsiExpression[] arguments = argumentList != null ? argumentList.getExpressions() : new PsiExpression[]{};
|
||||
List<String> conversions = new LinkedList<String>();
|
||||
//noinspection UnusedDeclaration
|
||||
for (final PsiExpression a : arguments) {
|
||||
conversions.add("");
|
||||
}
|
||||
|
||||
PsiMethod resolve = expression.resolveMethod();
|
||||
if (resolve != null) {
|
||||
List<PsiType> expectedTypes = new LinkedList<PsiType>();
|
||||
List<PsiType> actualTypes = new LinkedList<PsiType>();
|
||||
|
||||
for (PsiParameter p : resolve.getParameterList().getParameters())
|
||||
expectedTypes.add(p.getType());
|
||||
|
||||
for (PsiExpression e : arguments)
|
||||
actualTypes.add(e.getType());
|
||||
|
||||
if (conversions.size() == actualTypes.size() && actualTypes.size() == expectedTypes.size()) {
|
||||
for (int i = 0; i < actualTypes.size(); i++)
|
||||
conversions.set(i, createConversionForExpression(arguments[i], expectedTypes.get(i)));
|
||||
}
|
||||
}
|
||||
return conversions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<String> createConversions(@NotNull PsiPolyadicExpression expression, PsiType expectedType) {
|
||||
PsiExpression[] arguments = expression.getOperands();
|
||||
int length = arguments.length;
|
||||
List<String> conversions = new LinkedList<String>();
|
||||
|
||||
List<PsiType> expectedTypes = Collections.nCopies(length, expectedType);
|
||||
List<PsiType> actualTypes = new LinkedList<PsiType>();
|
||||
|
||||
for (PsiExpression e : arguments)
|
||||
actualTypes.add(e.getType());
|
||||
|
||||
assert actualTypes.size() == expectedTypes.size() : "The type list must have the same length";
|
||||
|
||||
for (int i = 0; i < actualTypes.size(); i++)
|
||||
conversions.add(i, createConversionForExpression(arguments[i], expectedTypes.get(i)));
|
||||
|
||||
return conversions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String createConversionForExpression(@Nullable PsiExpression expression, @NotNull PsiType expectedType) {
|
||||
String conversion = "";
|
||||
if (expression != null) {
|
||||
PsiType actualType = expression.getType();
|
||||
boolean isPrimitiveTypeOrNull = actualType == null || Node.PRIMITIVE_TYPES.contains(actualType.getCanonicalText());
|
||||
boolean isRef = (expression instanceof PsiReferenceExpression && ((PsiReferenceExpression) expression).isQualified() || expression instanceof PsiMethodCallExpression);
|
||||
boolean containsQuestDot = expressionToExpression(expression).toKotlin().contains("?.");
|
||||
|
||||
if (isPrimitiveTypeOrNull && isRef && containsQuestDot) {
|
||||
conversion += ".sure()";
|
||||
}
|
||||
|
||||
if (actualType != null) {
|
||||
if (isConversionNeeded(actualType, expectedType)) {
|
||||
conversion += getPrimitiveTypeConversion(expectedType.getCanonicalText());
|
||||
}
|
||||
}
|
||||
}
|
||||
return conversion;
|
||||
}
|
||||
|
||||
private static boolean isConversionNeeded(@Nullable final PsiType actual, @Nullable final PsiType expected) {
|
||||
if (actual == null || expected == null) {
|
||||
return false;
|
||||
}
|
||||
Map<String, String> typeMap = new HashMap<String, String>();
|
||||
typeMap.put(JAVA_LANG_BYTE, "byte");
|
||||
typeMap.put(JAVA_LANG_SHORT, "short");
|
||||
typeMap.put(JAVA_LANG_INTEGER, "int");
|
||||
typeMap.put(JAVA_LANG_LONG, "long");
|
||||
typeMap.put(JAVA_LANG_FLOAT, "float");
|
||||
typeMap.put(JAVA_LANG_DOUBLE, "double");
|
||||
typeMap.put(JAVA_LANG_CHARACTER, "char");
|
||||
String expectedStr = expected.getCanonicalText();
|
||||
String actualStr = actual.getCanonicalText();
|
||||
boolean o1 = AstUtil.getOrElse(typeMap, actualStr, "").equals(expectedStr);
|
||||
boolean o2 = AstUtil.getOrElse(typeMap, expectedStr, "").equals(actualStr);
|
||||
return !actualStr.equals(expectedStr) && (!(o1 ^ o2));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getPrimitiveTypeConversion(@NotNull String type) {
|
||||
Map<String, String> conversions = new HashMap<String, String>();
|
||||
conversions.put("byte", BYTE);
|
||||
conversions.put("short", SHORT);
|
||||
conversions.put("int", INT);
|
||||
conversions.put("long", LONG);
|
||||
conversions.put("float", FLOAT);
|
||||
conversions.put("double", DOUBLE);
|
||||
conversions.put("char", CHAR);
|
||||
|
||||
conversions.put(JAVA_LANG_BYTE, BYTE);
|
||||
conversions.put(JAVA_LANG_SHORT, SHORT);
|
||||
conversions.put(JAVA_LANG_INTEGER, INT);
|
||||
conversions.put(JAVA_LANG_LONG, LONG);
|
||||
conversions.put(JAVA_LANG_FLOAT, FLOAT);
|
||||
conversions.put(JAVA_LANG_DOUBLE, DOUBLE);
|
||||
conversions.put(JAVA_LANG_CHARACTER, CHAR);
|
||||
|
||||
if (conversions.containsKey(type)) {
|
||||
return "." + conversions.get(type) + "()";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// @NotNull
|
||||
// private static String applyConversion(Expression expression, String conversion) {
|
||||
// if (conversion.isEmpty())
|
||||
// return expression.toKotlin();
|
||||
// return "(" + expression.toKotlin() + ")" + conversion;
|
||||
// }
|
||||
|
||||
@NotNull
|
||||
public SureCallChainExpression createSureCallOnlyForChain(@Nullable PsiExpression expression, @NotNull PsiType type) {
|
||||
String conversion = (expression != null && (expression instanceof PsiReferenceExpression || expression instanceof PsiMethodCallExpression))
|
||||
?
|
||||
createConversionForExpression(expression, type)
|
||||
: "";
|
||||
return new SureCallChainExpression(expressionToExpression(expression), conversion);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.j2k.Converter.NOT_NULL_ANNOTATIONS;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ConverterUtil {
|
||||
private ConverterUtil() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String createMainFunction(@NotNull PsiFile file) {
|
||||
List<Pair<String, PsiMethod>> classNamesWithMains = new LinkedList<Pair<String, PsiMethod>>();
|
||||
|
||||
for (PsiClass c : ((PsiJavaFile) file).getClasses()) {
|
||||
PsiMethod main = findMainMethod(c);
|
||||
if (main != null) {
|
||||
classNamesWithMains.add(new Pair<String, PsiMethod>(c.getName(), main));
|
||||
}
|
||||
}
|
||||
if (classNamesWithMains.size() > 0) {
|
||||
String className = classNamesWithMains.get(0).getFirst();
|
||||
return MessageFormat.format("fun main(args : Array<String?>?) = {0}.main(args)", className);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiMethod findMainMethod(@NotNull PsiClass aClass) {
|
||||
if (isMainClass(aClass)) {
|
||||
final PsiMethod[] mainMethods = aClass.findMethodsByName("main", false);
|
||||
return findMainMethod(mainMethods);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiMethod findMainMethod(@NotNull PsiMethod[] mainMethods) {
|
||||
for (PsiMethod mainMethod : mainMethods) {
|
||||
if (isMainMethod(mainMethod)) return mainMethod;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isMainClass(@NotNull PsiClass psiClass) {
|
||||
if (psiClass instanceof PsiAnonymousClass) return false;
|
||||
if (psiClass.isInterface()) return false;
|
||||
return psiClass.getContainingClass() == null || psiClass.hasModifierProperty(PsiModifier.STATIC);
|
||||
}
|
||||
|
||||
public static boolean isMainMethod(@Nullable PsiMethod method) {
|
||||
if (method == null || method.getContainingClass() == null) return false;
|
||||
if (PsiType.VOID != method.getReturnType()) return false;
|
||||
if (!method.hasModifierProperty(PsiModifier.STATIC)) return false;
|
||||
if (!method.hasModifierProperty(PsiModifier.PUBLIC)) return false;
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
if (parameters.length != 1) return false;
|
||||
final PsiType type = parameters[0].getType();
|
||||
if (!(type instanceof PsiArrayType)) return false;
|
||||
final PsiType componentType = ((PsiArrayType) type).getComponentType();
|
||||
return componentType.equalsToText("java.lang.String");
|
||||
}
|
||||
|
||||
public static int countWritingAccesses(@Nullable PsiElement element, @Nullable PsiElement container) {
|
||||
int counter = 0;
|
||||
if (container != null) {
|
||||
ReferenceCollector visitor = new ReferenceCollector();
|
||||
container.accept(visitor);
|
||||
for (PsiReferenceExpression e : visitor.getCollectedReferences())
|
||||
if (e.isReferenceTo(element) && PsiUtil.isAccessedForWriting(e)) {
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
static boolean isReadOnly(PsiElement element, PsiElement container) {
|
||||
return countWritingAccesses(element, container) == 0;
|
||||
}
|
||||
|
||||
public static boolean isAnnotatedAsNotNull(@Nullable PsiModifierList modifierList) {
|
||||
if (modifierList != null) {
|
||||
PsiAnnotation[] annotations = modifierList.getAnnotations();
|
||||
for (PsiAnnotation a : annotations) {
|
||||
String qualifiedName = a.getQualifiedName();
|
||||
if (qualifiedName != null && NOT_NULL_ANNOTATIONS.contains(qualifiedName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static class ReferenceCollector extends JavaRecursiveElementVisitor {
|
||||
public List<PsiReferenceExpression> getCollectedReferences() {
|
||||
return myCollectedReferences;
|
||||
}
|
||||
|
||||
private List<PsiReferenceExpression> myCollectedReferences = new LinkedList<PsiReferenceExpression>();
|
||||
|
||||
@Override
|
||||
public void visitReferenceExpression(PsiReferenceExpression expression) {
|
||||
super.visitReferenceExpression(expression);
|
||||
myCollectedReferences.add(expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public enum J2KConverterFlags {
|
||||
FULLY_QUALIFIED_TYPE_NAMES,
|
||||
SKIP_BODIES,
|
||||
SKIP_NON_PUBLIC_MEMBERS
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
//package org.jetbrains.jet.j2k;
|
||||
//
|
||||
//import com.intellij.psi.PsiFile;
|
||||
//import com.intellij.psi.PsiJavaFile;
|
||||
//import org.apache.commons.cli.*;
|
||||
//import org.jetbrains.annotations.NotNull;
|
||||
//import org.jetbrains.annotations.Nullable;
|
||||
//
|
||||
//import java.io.File;
|
||||
//import java.io.FileNotFoundException;
|
||||
//import java.io.IOException;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.Arrays;
|
||||
//import java.util.List;
|
||||
//import java.util.logging.Logger;
|
||||
//import java.util.regex.Pattern;
|
||||
//
|
||||
//import static org.apache.commons.io.FileUtils.readFileToString;
|
||||
//import static org.apache.commons.io.FileUtils.writeStringToFile;
|
||||
//
|
||||
///**
|
||||
// * @author ignatov
|
||||
// */
|
||||
//@SuppressWarnings({"CallToPrintStackTrace", "UseOfSystemOutOrSystemErr"})
|
||||
//public class JavaToKotlinCli {
|
||||
// private static final Logger myLogger = Logger.getAnonymousLogger();
|
||||
//
|
||||
// private JavaToKotlinCli() {
|
||||
// }
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
// CommandLineParser parser = new BasicParser();
|
||||
// Options options = new Options()
|
||||
// .addOption("h", "help", false, "Print usage information")
|
||||
// .addOption("f", "from", true, "Directory with Java sources")
|
||||
// .addOption("t", "to", true, "Directory with Kotlin sources")
|
||||
// .addOption("p", "public-only", false, "Only public and protected members")
|
||||
// .addOption("fqn", "fqn", false, "Full qualified names")
|
||||
// .addOption("d", "declarations-only", false, "Declarations only")
|
||||
// ;
|
||||
//
|
||||
// try {
|
||||
// CommandLine commandLine = parser.parse(options, args);
|
||||
//
|
||||
// if (commandLine.hasOption("help"))
|
||||
// showHelpAndExit();
|
||||
//
|
||||
// if (commandLine.hasOption("from") && commandLine.hasOption("to")) {
|
||||
// String from = commandLine.getOptionValue("from");
|
||||
// String to = commandLine.getOptionValue("to");
|
||||
//
|
||||
// for (Option o : commandLine.getOptions()) {
|
||||
// Converter.addFlag(o.getLongOpt());
|
||||
// }
|
||||
//
|
||||
// if (!from.isEmpty() && !to.isEmpty())
|
||||
// convertSourceTree(from, to);
|
||||
// else
|
||||
// showHelpAndExit();
|
||||
// } else
|
||||
// showHelpAndExit();
|
||||
// } catch (ParseException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
// private static void convertSourceTree(String javaPath, String kotlinPath) {
|
||||
// try {
|
||||
// File javaDir = new File(javaPath);
|
||||
// File kotlinDir = new File(kotlinPath);
|
||||
//
|
||||
// if (kotlinDir.exists())
|
||||
// kotlinDir.delete();
|
||||
//
|
||||
// if (!kotlinDir.exists() && !kotlinDir.mkdir())
|
||||
// myLogger.warning("Creation failed: " + kotlinDir.getAbsolutePath());
|
||||
//
|
||||
// for (File f : getJavaFiles(javaDir.getAbsolutePath())) {
|
||||
// String relative = javaDir.toURI().relativize(f.toURI()).getPath().replace(".java", ".kt");
|
||||
// File file = new File(kotlinPath, relative);
|
||||
//
|
||||
// if (file.exists())
|
||||
// file.delete();
|
||||
//
|
||||
// if (f.isDirectory())
|
||||
// if (!file.exists() && !file.mkdir())
|
||||
// myLogger.warning("Creation failed: " + file.getAbsolutePath());
|
||||
//
|
||||
// if (f.isFile()) {
|
||||
// writeStringToFile(file, fileToKotlin(f));
|
||||
// }
|
||||
// }
|
||||
// } catch (FileNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @NotNull
|
||||
// private static String fileToKotlin(File f) throws IOException {
|
||||
// final String javaCode = readJavaFileToString(f);
|
||||
// return generateKotlinCode(JavaToKotlinTranslator.createFile(JavaToKotlinTranslator.setUpJavaCoreEnvironment(), javaCode));
|
||||
// }
|
||||
//
|
||||
// @NotNull
|
||||
// private static String generateKotlinCode(@Nullable PsiFile file) {
|
||||
// if (file != null && file instanceof PsiJavaFile) {
|
||||
// JavaToKotlinTranslator.setClassIdentifiers(file);
|
||||
// return JavaToKotlinTranslator.prettify(Converter.fileToFile((PsiJavaFile) file).toKotlin());
|
||||
// }
|
||||
// return "";
|
||||
// }
|
||||
//
|
||||
// @NotNull
|
||||
// private static String readJavaFileToString(@NotNull File javaFile) throws IOException {
|
||||
// return Pattern.compile("\\s*/\\*.*\\*/", Pattern.DOTALL).matcher(readFileToString(javaFile)).replaceAll("");
|
||||
// }
|
||||
//
|
||||
// private static void showHelpAndExit() {
|
||||
// System.err.println("Usage: java -jar java2kotlin.jar -f <from> -t <to>");
|
||||
// System.exit(1);
|
||||
// }
|
||||
//
|
||||
// static public List<File> getJavaFiles(String startDirName) throws FileNotFoundException {
|
||||
// return getJavaFiles(new File(startDirName));
|
||||
// }
|
||||
//
|
||||
// private static List<File> getJavaFiles(File start) throws FileNotFoundException {
|
||||
// List<File> result = new ArrayList<File>();
|
||||
//
|
||||
// if (start.isFile())
|
||||
// return Arrays.asList(start);
|
||||
//
|
||||
// for (File file : Arrays.asList(start.listFiles())) {
|
||||
// if ((file.isFile() && file.getName().endsWith(".java")) || file.isDirectory())
|
||||
// result.add(file);
|
||||
//
|
||||
// if (file.isDirectory()) {
|
||||
// List<File> deeperList = getJavaFiles(file);
|
||||
// result.addAll(deeperList);
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k;
|
||||
|
||||
import com.intellij.core.JavaCoreEnvironment;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import com.intellij.psi.PsiJavaFile;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.j2k.visitors.ClassVisitor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class JavaToKotlinTranslator {
|
||||
private JavaToKotlinTranslator() {
|
||||
}
|
||||
|
||||
private static final Converter CONVERTER = new Converter();
|
||||
|
||||
@Nullable
|
||||
private static PsiFile createFile(@NotNull String text) {
|
||||
JavaCoreEnvironment javaCoreEnvironment = setUpJavaCoreEnvironment();
|
||||
return PsiFileFactory.getInstance(javaCoreEnvironment.getProject()).createFileFromText(
|
||||
"test.java", JavaLanguage.INSTANCE, text
|
||||
);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static PsiFile createFile(@NotNull JavaCoreEnvironment javaCoreEnvironment, @NotNull String text) {
|
||||
return PsiFileFactory.getInstance(javaCoreEnvironment.getProject()).createFileFromText(
|
||||
"test.java", JavaLanguage.INSTANCE, text
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static JavaCoreEnvironment setUpJavaCoreEnvironment() {
|
||||
JavaCoreEnvironment javaCoreEnvironment = new JavaCoreEnvironment(new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
});
|
||||
|
||||
javaCoreEnvironment.addToClasspath(findRtJar());
|
||||
File annotations = findAnnotations();
|
||||
if (annotations != null && annotations.exists()) {
|
||||
javaCoreEnvironment.addToClasspath(annotations);
|
||||
}
|
||||
return javaCoreEnvironment;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static String prettify(@Nullable String code) {
|
||||
if (code == null) {
|
||||
return "";
|
||||
}
|
||||
return code
|
||||
.trim()
|
||||
.replaceAll("\r\n", "\n")
|
||||
.replaceAll(" \n", "\n")
|
||||
.replaceAll("\n ", "\n")
|
||||
.replaceAll("\n+", "\n")
|
||||
.replaceAll(" +", " ")
|
||||
.trim()
|
||||
;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static File findRtJar() {
|
||||
String javaHome = System.getenv("JAVA_HOME");
|
||||
File rtJar;
|
||||
if (javaHome == null) {
|
||||
rtJar = findActiveRtJar(true);
|
||||
|
||||
if (rtJar == null) {
|
||||
throw new SetupJavaCoreEnvironmentException("JAVA_HOME environment variable needs to be defined");
|
||||
}
|
||||
}
|
||||
else {
|
||||
rtJar = findRtJar(javaHome);
|
||||
}
|
||||
|
||||
if (rtJar == null || !rtJar.exists()) {
|
||||
rtJar = findActiveRtJar(true);
|
||||
|
||||
if ((rtJar == null || !rtJar.exists())) {
|
||||
throw new SetupJavaCoreEnvironmentException("No rt.jar found under JAVA_HOME=" + javaHome);
|
||||
}
|
||||
}
|
||||
return rtJar;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static File findRtJar(String javaHome) {
|
||||
File rtJar = new File(javaHome, "jre/lib/rt.jar");
|
||||
if (rtJar.exists()) {
|
||||
return rtJar;
|
||||
}
|
||||
|
||||
File classesJar = new File(new File(javaHome).getParentFile().getAbsolutePath(), "Classes/classes.jar");
|
||||
if (classesJar.exists()) {
|
||||
return classesJar;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static File findAnnotations() {
|
||||
ClassLoader classLoader = JavaToKotlinTranslator.class.getClassLoader();
|
||||
while (classLoader != null) {
|
||||
if (classLoader instanceof URLClassLoader) {
|
||||
URLClassLoader loader = (URLClassLoader) classLoader;
|
||||
for (URL url : loader.getURLs())
|
||||
if ("file".equals(url.getProtocol()) && url.getFile().endsWith("/annotations.jar")) {
|
||||
return new File(url.getFile());
|
||||
}
|
||||
}
|
||||
classLoader = classLoader.getParent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static File findActiveRtJar(boolean failOnError) {
|
||||
ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
|
||||
if (systemClassLoader instanceof URLClassLoader) {
|
||||
URLClassLoader loader = (URLClassLoader) systemClassLoader;
|
||||
for (URL url : loader.getURLs()) {
|
||||
if ("file".equals(url.getProtocol())) {
|
||||
if (url.getFile().endsWith("/lib/rt.jar")) {
|
||||
return new File(url.getFile());
|
||||
}
|
||||
if (url.getFile().endsWith("/Classes/classes.jar")) {
|
||||
return new File(url.getFile()).getAbsoluteFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (failOnError) {
|
||||
throw new SetupJavaCoreEnvironmentException("Could not find rt.jar in system class loader: " + StringUtil.join(loader.getURLs(), new Function<URL, String>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String fun(@NotNull URL url) {
|
||||
return url.toString() + "\n";
|
||||
}
|
||||
}, ", "));
|
||||
}
|
||||
}
|
||||
else if (failOnError) {
|
||||
throw new SetupJavaCoreEnvironmentException("System class loader is not an URLClassLoader: " + systemClassLoader);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static void setClassIdentifiers(@NotNull Converter converter, @NotNull PsiElement psiFile) {
|
||||
ClassVisitor c = new ClassVisitor();
|
||||
psiFile.accept(c);
|
||||
converter.clearClassIdentifiers();
|
||||
converter.setClassIdentifiers(c.getClassIdentifiers());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static String generateKotlinCode(@NotNull String javaCode) {
|
||||
PsiFile file = createFile(javaCode);
|
||||
if (file != null && file instanceof PsiJavaFile) {
|
||||
setClassIdentifiers(CONVERTER, file);
|
||||
return prettify(CONVERTER.fileToFile((PsiJavaFile) file).toKotlin());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static String generateKotlinCodeWithCompatibilityImport(@NotNull String javaCode) {
|
||||
PsiFile file = createFile(javaCode);
|
||||
if (file != null && file instanceof PsiJavaFile) {
|
||||
setClassIdentifiers(CONVERTER, file);
|
||||
return prettify(CONVERTER.fileToFileWithCompatibilityImport((PsiJavaFile) file).toKotlin());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static void main(@NotNull String[] args) throws IOException {
|
||||
//noinspection UseOfSystemOutOrSystemErr
|
||||
final PrintStream out = System.out;
|
||||
if (args.length == 1) {
|
||||
String kotlinCode = "";
|
||||
try {
|
||||
kotlinCode = generateKotlinCode(args[0]);
|
||||
} catch (Exception e) {
|
||||
out.println("EXCEPTION: " + e.getMessage());
|
||||
}
|
||||
if (kotlinCode.isEmpty()) {
|
||||
out.println("EXCEPTION: generated code is empty.");
|
||||
}
|
||||
else {
|
||||
out.println(kotlinCode);
|
||||
}
|
||||
}
|
||||
else {
|
||||
out.println("EXCEPTION: wrong number of arguments (should be 1).");
|
||||
}
|
||||
}
|
||||
|
||||
public static String translateToKotlin(String code) {
|
||||
return generateKotlinCode(code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class SetupJavaCoreEnvironmentException extends RuntimeException {
|
||||
public SetupJavaCoreEnvironmentException(String s) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.Converter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class AnonymousClass extends Class {
|
||||
public AnonymousClass(Converter converter, List<Member> members) {
|
||||
super(converter,
|
||||
new IdentifierImpl("anonClass"),
|
||||
Collections.<String>emptySet(),
|
||||
Collections.<Element>emptyList(),
|
||||
Collections.<Type>emptyList(),
|
||||
Collections.<Expression>emptyList(),
|
||||
Collections.<Type>emptyList(),
|
||||
getMembers(members, converter)
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return bodyToKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
public open class ArrayAccessExpression(val expression : Expression, val index : Expression) : Expression() {
|
||||
public override fun toKotlin() : String {
|
||||
return expression.toKotlin() + "[" + index.toKotlin() + "]"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.util.AstUtil
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions
|
||||
import java.util.*
|
||||
|
||||
public open class ArrayInitializerExpression(val `type` : Type, val initializers : List<Expression>) : Expression() {
|
||||
public override fun toKotlin() : String {
|
||||
return createArrayFunction() + "(" + createInitializers() + ")"
|
||||
}
|
||||
|
||||
private fun createInitializers(): String {
|
||||
return initializers.map { explicitConvertIfNeeded(it) }.makeString(", ")
|
||||
}
|
||||
|
||||
private fun createArrayFunction() : String {
|
||||
var sType : String? = innerTypeStr()
|
||||
if (Node.PRIMITIVE_TYPES.contains(sType))
|
||||
{
|
||||
return sType + "Array"
|
||||
}
|
||||
|
||||
return AstUtil.lowerFirstCharacter(`type`.convertedToNotNull().toKotlin())
|
||||
}
|
||||
|
||||
private fun innerTypeStr() : String {
|
||||
return `type`.convertedToNotNull().toKotlin().replace("Array", "").toLowerCase()
|
||||
}
|
||||
|
||||
private fun explicitConvertIfNeeded(i : Expression) : String {
|
||||
val doubleOrFloatTypes = hashSet("double", "float", "java.lang.double", "java.lang.float")
|
||||
val afterReplace : String = innerTypeStr().replace(">", "").replace("<", "").replace("?", "")
|
||||
if (doubleOrFloatTypes.contains(afterReplace))
|
||||
{
|
||||
if (i.getKind() == INode.Kind.LITERAL)
|
||||
{
|
||||
if (i.toKotlin().contains("."))
|
||||
{
|
||||
return i.toKotlin()
|
||||
}
|
||||
|
||||
return i.toKotlin() + ".0"
|
||||
}
|
||||
|
||||
return "(" + i.toKotlin() + ")" + getConversion(afterReplace)
|
||||
}
|
||||
|
||||
return i.toKotlin()
|
||||
}
|
||||
|
||||
class object {
|
||||
private open fun getConversion(afterReplace : String) : String {
|
||||
if (afterReplace.contains("double").sure())
|
||||
return "." + OperatorConventions.DOUBLE + "()"
|
||||
|
||||
if (afterReplace.contains("float").sure())
|
||||
return "." + OperatorConventions.FLOAT + "()"
|
||||
|
||||
return ""
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ArrayType extends Type {
|
||||
private final Type myType;
|
||||
|
||||
public ArrayType(Type type) {
|
||||
myType = type;
|
||||
}
|
||||
|
||||
public Type getInnerType() {
|
||||
return myType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.ARRAY_TYPE;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
if (PRIMITIVE_TYPES.contains(myType.toKotlin().toLowerCase())) {
|
||||
return myType.toKotlin() + "Array" + isNullableStr(); // returns IntArray, BooleanArray, etc.
|
||||
}
|
||||
return "Array" + "<" + myType.toKotlin() + ">" + isNullableStr();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.util.AstUtil
|
||||
import java.util.List
|
||||
|
||||
public open class ArrayWithoutInitializationExpression(val `type` : Type, val expressions : List<Expression>) : Expression() {
|
||||
public override fun toKotlin() : String {
|
||||
if (`type`.getKind() == INode.Kind.ARRAY_TYPE)
|
||||
{
|
||||
return constructInnerType(`type` as ArrayType, expressions)
|
||||
}
|
||||
|
||||
return getConstructorName(`type`)
|
||||
}
|
||||
|
||||
private fun constructInnerType(hostType : ArrayType, expressions: List<Expression>) : String {
|
||||
if (expressions.size() == 1)
|
||||
{
|
||||
return oneDim(hostType, expressions[0])
|
||||
}
|
||||
|
||||
var innerType : Type? = hostType.getInnerType()
|
||||
if (expressions.size() > 1 && innerType?.getKind() == INode.Kind.ARRAY_TYPE)
|
||||
{
|
||||
return oneDim(hostType, expressions[0], "{" + constructInnerType(innerType as ArrayType, expressions.subList(1, expressions.size())) + "}")
|
||||
}
|
||||
|
||||
return getConstructorName(hostType)
|
||||
}
|
||||
|
||||
class object {
|
||||
private open fun oneDim(`type` : Type, size : Expression) : String {
|
||||
return oneDim(`type`, size, "")
|
||||
}
|
||||
|
||||
private open fun oneDim(`type` : Type, size : Expression, init : String) : String {
|
||||
var commaWithInit : String? = (if (init.isEmpty())
|
||||
""
|
||||
else
|
||||
", " + init)
|
||||
return getConstructorName(`type`) + "(" + size.toKotlin() + commaWithInit + ")"
|
||||
}
|
||||
|
||||
private open fun getConstructorName(`type` : Type) : String {
|
||||
return AstUtil.replaceLastQuest(`type`.toKotlin())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public open class AssertStatement(val condition : Expression, val detail : Expression) : Statement() {
|
||||
public override fun toKotlin() : String {
|
||||
var detail : String? = (if (detail != Expression.EMPTY_EXPRESSION)
|
||||
"(" + detail.toKotlin() + ")"
|
||||
else
|
||||
"")
|
||||
return "assert" + detail + " {" + condition.toKotlin() + "}"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public open class AssignmentExpression(val left : Expression, val right : Expression, val op : String) : Expression() {
|
||||
public override fun toKotlin() : String {
|
||||
return left.toKotlin() + " "+ op + " "+ right.toKotlin()
|
||||
}
|
||||
|
||||
public override fun getKind() : INode.Kind {
|
||||
return INode.Kind.ASSIGNMENT_EXPRESSION
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class BinaryExpression extends Expression {
|
||||
private final Expression myLeft;
|
||||
private final Expression myRight;
|
||||
private final String myOp;
|
||||
private final List<String> myConversions;
|
||||
|
||||
public BinaryExpression(Expression left, Expression right, String op) {
|
||||
this(left, right, op, Arrays.asList("", ""));
|
||||
}
|
||||
|
||||
public BinaryExpression(Expression left, Expression right, String op, List<String> conversions) {
|
||||
myLeft = left;
|
||||
myRight = right;
|
||||
myOp = op;
|
||||
myConversions = conversions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
List<String> expressionsWithConversions = AstUtil.applyConversions(AstUtil.nodesToKotlin(Arrays.asList(myLeft, myRight)), myConversions);
|
||||
return AstUtil.join(expressionsWithConversions, SPACE + myOp + SPACE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class Block extends Statement {
|
||||
@NotNull
|
||||
public final static Block EMPTY_BLOCK = new Block();
|
||||
|
||||
private List<Statement> myStatements;
|
||||
private boolean myNotEmpty = false;
|
||||
|
||||
private Block() {
|
||||
myStatements = new LinkedList<Statement>();
|
||||
}
|
||||
|
||||
public Block(List<Statement> statements) {
|
||||
myStatements = new LinkedList<Statement>();
|
||||
myStatements = statements;
|
||||
}
|
||||
|
||||
public Block(List<Statement> statements, boolean notEmpty) {
|
||||
myStatements = new LinkedList<Statement>();
|
||||
myStatements = statements;
|
||||
myNotEmpty = notEmpty;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return !myNotEmpty && myStatements.size() == 0;
|
||||
}
|
||||
|
||||
public List<Statement> getStatements() {
|
||||
return myStatements;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
if (!isEmpty()) {
|
||||
return "{" + N +
|
||||
AstUtil.joinNodes(myStatements, N) + N +
|
||||
"}";
|
||||
}
|
||||
return EMPTY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class BreakStatement extends Statement {
|
||||
private Identifier myLabel = Identifier.EMPTY_IDENTIFIER;
|
||||
|
||||
public BreakStatement(Identifier label) {
|
||||
myLabel = label;
|
||||
}
|
||||
|
||||
public BreakStatement() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.BREAK;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
if (myLabel.isEmpty()) {
|
||||
return "break";
|
||||
}
|
||||
return "break" + AT + myLabel.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class CallChainExpression extends Expression {
|
||||
private final Expression myExpression;
|
||||
private final Expression myIdentifier;
|
||||
|
||||
public Expression getIdentifier() {
|
||||
return myIdentifier;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.CALL_CHAIN;
|
||||
}
|
||||
|
||||
public CallChainExpression(Expression expression, Expression identifier) {
|
||||
myExpression = expression;
|
||||
myIdentifier = identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNullable() {
|
||||
return myIdentifier.isNullable();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
if (!myExpression.isEmpty()) {
|
||||
if (myExpression.isNullable()) {
|
||||
return myExpression.toKotlin() + QUESTDOT + myIdentifier.toKotlin();
|
||||
}
|
||||
else {
|
||||
return myExpression.toKotlin() + DOT + myIdentifier.toKotlin();
|
||||
}
|
||||
}
|
||||
return myIdentifier.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class CaseContainer extends Statement {
|
||||
private final List<Statement> myCaseStatement;
|
||||
private final Block myBlock;
|
||||
|
||||
public CaseContainer(final List<Statement> caseStatement, @NotNull final List<Statement> statements) {
|
||||
myCaseStatement = caseStatement;
|
||||
List<Statement> newStatements = new LinkedList<Statement>();
|
||||
for (Statement s : statements)
|
||||
if (s.getKind() != Kind.BREAK && s.getKind() != Kind.CONTINUE) {
|
||||
newStatements.add(s);
|
||||
}
|
||||
myBlock = new Block(newStatements);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return AstUtil.joinNodes(myCaseStatement, COMMA_WITH_SPACE) + SPACE + "->" + SPACE + myBlock.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class CatchStatement extends Statement {
|
||||
private final Parameter myVariable;
|
||||
private final Block myBlock;
|
||||
|
||||
public CatchStatement(Parameter variable, Block block) {
|
||||
myVariable = variable;
|
||||
myBlock = block;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "catch" + SPACE + "(" + myVariable.toKotlin() + ")" + SPACE + myBlock.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.j2k.Converter;
|
||||
import org.jetbrains.jet.j2k.J2KConverterFlags;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.j2k.util.AstUtil.*;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class Class extends Member {
|
||||
@NotNull
|
||||
String TYPE = "class";
|
||||
final Identifier myName;
|
||||
private final List<Expression> myBaseClassParams;
|
||||
private final List<Member> myMembers;
|
||||
private final List<Element> myTypeParameters;
|
||||
private final List<Type> myExtendsTypes;
|
||||
private final List<Type> myImplementsTypes;
|
||||
|
||||
public Class(Converter converter, Identifier name, Set<String> modifiers, List<Element> typeParameters, List<Type> extendsTypes,
|
||||
List<Expression> baseClassParams, List<Type> implementsTypes, List<Member> members) {
|
||||
myName = name;
|
||||
myBaseClassParams = baseClassParams;
|
||||
myModifiers = modifiers;
|
||||
myTypeParameters = typeParameters;
|
||||
myExtendsTypes = extendsTypes;
|
||||
myImplementsTypes = implementsTypes;
|
||||
myMembers = getMembers(members, converter);
|
||||
}
|
||||
|
||||
/*package*/ static List<Member> getMembers(List<Member> members, Converter converter) {
|
||||
List<Member> withoutPrivate = new LinkedList<Member>();
|
||||
if (converter.hasFlag(J2KConverterFlags.SKIP_NON_PUBLIC_MEMBERS)) {
|
||||
for (Member m : members) {
|
||||
if (m.accessModifier().equals("public") || m.accessModifier().equals("protected")) {
|
||||
withoutPrivate.add(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
withoutPrivate = members;
|
||||
}
|
||||
return withoutPrivate;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
private Constructor getPrimaryConstructor() {
|
||||
for (Member m : myMembers)
|
||||
if (m.getKind() == Kind.CONSTRUCTOR) {
|
||||
if (((Constructor) m).isPrimary()) {
|
||||
return (Constructor) m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String primaryConstructorSignatureToKotlin() {
|
||||
Constructor maybeConstructor = getPrimaryConstructor();
|
||||
if (maybeConstructor != null) {
|
||||
return maybeConstructor.primarySignatureToKotlin();
|
||||
}
|
||||
return "(" + ")";
|
||||
}
|
||||
|
||||
String primaryConstructorBodyToKotlin() {
|
||||
Constructor maybeConstructor = getPrimaryConstructor();
|
||||
if (maybeConstructor != null && !maybeConstructor.getBlock().isEmpty()) {
|
||||
return maybeConstructor.primaryBodyToKotlin();
|
||||
}
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
private boolean hasWhere() {
|
||||
for (Element t : myTypeParameters)
|
||||
if (t instanceof TypeParameter && ((TypeParameter) t).hasWhere()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
String typeParameterWhereToKotlin() {
|
||||
if (hasWhere()) {
|
||||
List<String> wheres = new LinkedList<String>();
|
||||
for (Element t : myTypeParameters)
|
||||
if (t instanceof TypeParameter) {
|
||||
wheres.add(((TypeParameter) t).getWhereToKotlin());
|
||||
}
|
||||
return SPACE + "where" + SPACE + join(wheres, COMMA_WITH_SPACE) + SPACE;
|
||||
}
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
LinkedList<Member> membersExceptConstructors() {
|
||||
final LinkedList<Member> result = new LinkedList<Member>();
|
||||
for (Member m : myMembers)
|
||||
if (m.getKind() != Kind.CONSTRUCTOR) {
|
||||
result.add(m);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
List<Function> secondaryConstructorsAsStaticInitFunction() {
|
||||
final LinkedList<Function> result = new LinkedList<Function>();
|
||||
for (Member m : myMembers)
|
||||
if (m.getKind() == Kind.CONSTRUCTOR && !((Constructor) m).isPrimary()) {
|
||||
Function f = (Function) m;
|
||||
Set<String> modifiers = new HashSet<String>(m.myModifiers);
|
||||
modifiers.add(Modifier.STATIC);
|
||||
|
||||
final List<Statement> statements = f.getBlock().getStatements();
|
||||
statements.add(new ReturnStatement(new IdentifierImpl("__"))); // TODO: move to one place, find other __ usages
|
||||
final Block block = new Block(statements);
|
||||
|
||||
final List<Element> typeParameters = new LinkedList<Element>();
|
||||
if (f.getTypeParameters().size() == 0) {
|
||||
typeParameters.addAll(myTypeParameters);
|
||||
}
|
||||
else {
|
||||
typeParameters.addAll(myTypeParameters);
|
||||
typeParameters.addAll(f.getTypeParameters());
|
||||
}
|
||||
|
||||
result.add(new Function(
|
||||
new IdentifierImpl("init"),
|
||||
modifiers,
|
||||
new ClassType(myName, typeParameters, false),
|
||||
typeParameters,
|
||||
f.getParams(),
|
||||
block
|
||||
));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
String typeParametersToKotlin() {
|
||||
return myTypeParameters.size() > 0 ? "<" + AstUtil.joinNodes(myTypeParameters, COMMA_WITH_SPACE) + ">" : EMPTY;
|
||||
}
|
||||
|
||||
List<String> baseClassSignatureWithParams() {
|
||||
if (TYPE.equals("class") && myExtendsTypes.size() == 1) {
|
||||
LinkedList<String> result = new LinkedList<String>();
|
||||
result.add(myExtendsTypes.get(0).toKotlin() + "(" + joinNodes(myBaseClassParams, COMMA_WITH_SPACE) + ")");
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
return nodesToKotlin(myExtendsTypes);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
String implementTypesToKotlin() {
|
||||
List<String> allTypes = new LinkedList<String>() {
|
||||
{
|
||||
addAll(baseClassSignatureWithParams());
|
||||
addAll(nodesToKotlin(myImplementsTypes));
|
||||
}
|
||||
};
|
||||
return allTypes.size() == 0 ? EMPTY : SPACE + COLON + SPACE + join(allTypes, COMMA_WITH_SPACE);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
String modifiersToKotlin() {
|
||||
List<String> modifierList = new LinkedList<String>();
|
||||
|
||||
modifierList.add(accessModifier());
|
||||
|
||||
if (needAbstractModifier()) {
|
||||
modifierList.add(Modifier.ABSTRACT);
|
||||
}
|
||||
|
||||
if (needOpenModifier()) {
|
||||
modifierList.add(Modifier.OPEN);
|
||||
}
|
||||
|
||||
if (modifierList.size() > 0) {
|
||||
return join(modifierList, SPACE) + SPACE;
|
||||
}
|
||||
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
boolean needOpenModifier() {
|
||||
return !myModifiers.contains(Modifier.FINAL) && !myModifiers.contains(Modifier.ABSTRACT);
|
||||
}
|
||||
|
||||
boolean needAbstractModifier() {
|
||||
return isAbstract();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
String bodyToKotlin() {
|
||||
return SPACE + "{" + N +
|
||||
AstUtil.joinNodes(getNonStatic(membersExceptConstructors()), N) + N +
|
||||
primaryConstructorBodyToKotlin() + N +
|
||||
classObjectToKotlin() + N +
|
||||
"}";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<Member> getStatic(@NotNull List<? extends Member> members) {
|
||||
List<Member> result = new LinkedList<Member>();
|
||||
for (Member m : members)
|
||||
if (m.isStatic()) {
|
||||
result.add(m);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<Member> getNonStatic(@NotNull List<? extends Member> members) {
|
||||
List<Member> result = new LinkedList<Member>();
|
||||
for (Member m : members)
|
||||
if (!m.isStatic()) {
|
||||
result.add(m);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String classObjectToKotlin() {
|
||||
final List<Member> staticMembers = new LinkedList<Member>(secondaryConstructorsAsStaticInitFunction());
|
||||
staticMembers.addAll(getStatic(membersExceptConstructors()));
|
||||
if (staticMembers.size() > 0) {
|
||||
return "class" + SPACE + "object" + SPACE + "{" + N +
|
||||
AstUtil.joinNodes(staticMembers, N) + N +
|
||||
"}";
|
||||
}
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return modifiersToKotlin() + TYPE + SPACE + myName.toKotlin() + typeParametersToKotlin() + primaryConstructorSignatureToKotlin() +
|
||||
implementTypesToKotlin() +
|
||||
typeParameterWhereToKotlin() +
|
||||
bodyToKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ClassObjectAccessExpression extends Expression {
|
||||
private final Element myTypeElement;
|
||||
|
||||
public ClassObjectAccessExpression(Element typeElement) {
|
||||
myTypeElement = typeElement;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "getJavaClass" + "<" + myTypeElement.toKotlin() + ">";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ClassType extends Type {
|
||||
private final Identifier myType;
|
||||
private final List<? extends Element> myParameters;
|
||||
|
||||
public ClassType(Identifier type, List<? extends Element> parameters, boolean nullable) {
|
||||
myType = type;
|
||||
myParameters = parameters;
|
||||
myNullable = nullable;
|
||||
}
|
||||
|
||||
public ClassType(Identifier type, List<? extends Element> parameters) {
|
||||
myType = type;
|
||||
myParameters = parameters;
|
||||
}
|
||||
|
||||
public ClassType(Identifier type) {
|
||||
myType = type;
|
||||
myNullable = false;
|
||||
myParameters = Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
String params = myParameters.size() == 0
|
||||
? EMPTY
|
||||
: "<" + AstUtil.joinNodes(myParameters, COMMA_WITH_SPACE) + ">";
|
||||
return myType.toKotlin() + params + isNullableStr();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class Constructor extends Function {
|
||||
private final boolean myIsPrimary;
|
||||
|
||||
public Constructor(Identifier identifier, Set<String> modifiers, Type type, List<Element> typeParameters, Element params, Block block, boolean isPrimary) {
|
||||
super(identifier, modifiers, type, typeParameters, params, block);
|
||||
myIsPrimary = isPrimary;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String primarySignatureToKotlin() {
|
||||
return "(" + myParams.toKotlin() + ")";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String primaryBodyToKotlin() {
|
||||
return myBlock.toKotlin();
|
||||
}
|
||||
|
||||
public boolean isPrimary() {
|
||||
return myIsPrimary;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.CONSTRUCTOR;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ContinueStatement extends Statement {
|
||||
private Identifier myLabel = Identifier.EMPTY_IDENTIFIER;
|
||||
|
||||
public ContinueStatement(Identifier label) {
|
||||
myLabel = label;
|
||||
}
|
||||
|
||||
public ContinueStatement() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.CONTINUE;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
if (myLabel.isEmpty()) {
|
||||
return "continue";
|
||||
}
|
||||
return "continue" + AT + myLabel.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class DeclarationStatement extends Statement {
|
||||
private final List<Element> myElements;
|
||||
|
||||
public DeclarationStatement(List<Element> elements) {
|
||||
myElements = elements;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<String> toStringList(@NotNull List<Element> elements) {
|
||||
List<String> result = new LinkedList<String>();
|
||||
for (Element e : elements) {
|
||||
if (e instanceof LocalVariable) {
|
||||
LocalVariable v = (LocalVariable) e;
|
||||
|
||||
final String varKeyword = v.hasModifier(Modifier.FINAL) ? "val" : "var";
|
||||
result.add(
|
||||
varKeyword + SPACE + e.toKotlin()
|
||||
);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return AstUtil.join(toStringList(myElements), N);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class DefaultSwitchLabelStatement extends Statement {
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "else";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class DoWhileStatement extends WhileStatement {
|
||||
public DoWhileStatement(Expression condition, Statement statement) {
|
||||
super(condition, statement);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "do" + N +
|
||||
myStatement.toKotlin() + N +
|
||||
"while" + SPACE + "(" + myCondition.toKotlin() + ")";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class DummyMethodCallExpression extends Expression {
|
||||
private final Element myWho;
|
||||
private final String myMethodName;
|
||||
private final Element myWhat;
|
||||
|
||||
public DummyMethodCallExpression(Element who, String methodName, Element what) {
|
||||
myWho = who;
|
||||
myMethodName = methodName;
|
||||
myWhat = what;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return myWho.toKotlin() + DOT + myMethodName + "(" + myWhat.toKotlin() + ")";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class DummyStringExpression extends Expression {
|
||||
private final String myString;
|
||||
|
||||
public DummyStringExpression(String string) {
|
||||
myString = string;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return myString;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public abstract class Element extends Node {
|
||||
@NotNull
|
||||
public static final Element EMPTY_ELEMENT = new EmptyElement();
|
||||
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
private static class EmptyElement extends Element {
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.Converter;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class Enum extends Class {
|
||||
public Enum(Converter converter, Identifier name, Set<String> modifiers, List<Element> typeParameters, List<Type> extendsTypes,
|
||||
List<Expression> baseClassParams, List<Type> implementsTypes, List<Member> members) {
|
||||
super(converter, name, modifiers, typeParameters, extendsTypes, baseClassParams, implementsTypes, getMembers(members, converter));
|
||||
}
|
||||
|
||||
String primaryConstructorSignatureToKotlin() {
|
||||
String s = super.primaryConstructorSignatureToKotlin();
|
||||
return s.equals("()") ? EMPTY : s;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean needOpenModifier() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return modifiersToKotlin() + "enum class" + SPACE + myName.toKotlin() + primaryConstructorSignatureToKotlin() +
|
||||
typeParametersToKotlin() + implementTypesToKotlin() + SPACE + "{" + N +
|
||||
AstUtil.joinNodes(membersExceptConstructors(), N) + N +
|
||||
primaryConstructorBodyToKotlin() + N +
|
||||
"public fun name() : String { return \"\" }" + N + // TODO : remove hack
|
||||
"public fun order() : Int { return 0 }" + N +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class EnumConstant extends Field {
|
||||
public EnumConstant(Identifier identifier, Set<String> modifiers, @NotNull Type type, Element params) {
|
||||
super(identifier, modifiers, type.convertedToNotNull(), params, 0);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
if (myInitializer.toKotlin().isEmpty()) {
|
||||
return myIdentifier.toKotlin();
|
||||
}
|
||||
return myIdentifier.toKotlin() + SPACE + COLON + SPACE + myType.toKotlin() + "(" + myInitializer.toKotlin() + ")";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public abstract class Expression extends Statement {
|
||||
@NotNull
|
||||
public static final Expression EMPTY_EXPRESSION = new EmptyExpression();
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
private static class EmptyExpression extends Expression {
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
boolean isNullable() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ExpressionList extends Expression {
|
||||
private final List<Expression> myExpressions;
|
||||
|
||||
public ExpressionList(List<Expression> expressions, List<Type> types) {
|
||||
myExpressions = expressions;
|
||||
}
|
||||
|
||||
public ExpressionList(List<Expression> expressions) {
|
||||
myExpressions = expressions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return AstUtil.joinNodes(myExpressions, COMMA_WITH_SPACE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ExpressionListStatement extends Expression {
|
||||
private final List<Expression> myExpressions;
|
||||
|
||||
public ExpressionListStatement(List<Expression> expressions) {
|
||||
myExpressions = expressions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return AstUtil.joinNodes(myExpressions, N);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.j2k.Converter.getDefaultInitializer;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class Field extends Member {
|
||||
final Identifier myIdentifier;
|
||||
private final int myWritingAccesses;
|
||||
final Type myType;
|
||||
final Element myInitializer;
|
||||
|
||||
public Field(Identifier identifier, Set<String> modifiers, Type type, Element initializer, int writingAccesses) {
|
||||
myIdentifier = identifier;
|
||||
myWritingAccesses = writingAccesses;
|
||||
myModifiers = modifiers;
|
||||
myType = type;
|
||||
myInitializer = initializer;
|
||||
}
|
||||
|
||||
public Element getInitializer() {
|
||||
return myInitializer;
|
||||
}
|
||||
|
||||
public Identifier getIdentifier() {
|
||||
return myIdentifier;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return myType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
String modifiersToKotlin() {
|
||||
List<String> modifierList = new LinkedList<String>();
|
||||
|
||||
if (isAbstract()) {
|
||||
modifierList.add(Modifier.ABSTRACT);
|
||||
}
|
||||
|
||||
modifierList.add(accessModifier());
|
||||
|
||||
modifierList.add(isVal() ? "val" : "var");
|
||||
|
||||
if (modifierList.size() > 0) {
|
||||
return AstUtil.join(modifierList, SPACE) + SPACE;
|
||||
}
|
||||
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
public boolean isVal() {
|
||||
return myModifiers.contains(Modifier.FINAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStatic() {
|
||||
return myModifiers.contains(Modifier.STATIC);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
final String declaration = modifiersToKotlin() + myIdentifier.toKotlin() + SPACE + COLON + SPACE + myType.toKotlin();
|
||||
|
||||
if (myInitializer.isEmpty()) {
|
||||
return declaration + (isVal() && !isStatic() && myWritingAccesses == 1
|
||||
? EMPTY
|
||||
: SPACE + EQUAL + SPACE + getDefaultInitializer(this));
|
||||
}
|
||||
|
||||
return declaration + SPACE + EQUAL + SPACE + myInitializer.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class File extends Node {
|
||||
private final String myPackageName;
|
||||
private final List<Import> myImports;
|
||||
private final List<Class> myClasses;
|
||||
private final String myMainFunction;
|
||||
|
||||
public File(String packageName, List<Import> imports, List<Class> classes, String mainFunction) {
|
||||
myPackageName = packageName;
|
||||
myImports = imports;
|
||||
myClasses = classes;
|
||||
myMainFunction = mainFunction;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
final String common = AstUtil.joinNodes(myImports, N) + N2 + AstUtil.joinNodes(myClasses, N) + N + myMainFunction;
|
||||
if (myPackageName.isEmpty()) {
|
||||
return common;
|
||||
}
|
||||
return "package" + SPACE + myPackageName + N +
|
||||
common;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ForeachStatement extends Statement {
|
||||
private final Parameter myVariable;
|
||||
private final Expression myExpression;
|
||||
private final Statement myStatement;
|
||||
|
||||
public ForeachStatement(Parameter variable, Expression expression, Statement statement) {
|
||||
myVariable = variable;
|
||||
myExpression = expression;
|
||||
myStatement = statement;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "for" + SPACE + "(" + myVariable.toKotlin() + SPACE + IN + SPACE + myExpression.toKotlin() + ")" + N +
|
||||
myStatement.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ForeachWithRangeStatement extends Statement {
|
||||
private final Expression myStart;
|
||||
private final IdentifierImpl myIdentifier;
|
||||
private final Expression myEnd;
|
||||
private final Statement myBody;
|
||||
|
||||
public ForeachWithRangeStatement(IdentifierImpl identifier, Expression start, Expression end, Statement body) {
|
||||
myStart = start;
|
||||
myIdentifier = identifier;
|
||||
myEnd = end;
|
||||
myBody = body;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "for" + SPACE + "(" +
|
||||
myIdentifier.toKotlin() + SPACE + "in" + SPACE + myStart.toKotlin() + ".." + myEnd.toKotlin() +
|
||||
")" + SPACE +
|
||||
myBody.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class Function extends Member {
|
||||
private final Identifier myName;
|
||||
private final Type myType;
|
||||
private final List<Element> myTypeParameters;
|
||||
final Element myParams;
|
||||
|
||||
// TODO: maybe remove it?
|
||||
public void setBlock(Block block) {
|
||||
myBlock = block;
|
||||
}
|
||||
|
||||
Block myBlock;
|
||||
|
||||
public Function(Identifier name, Set<String> modifiers, Type type, List<Element> typeParameters, Element params, Block block) {
|
||||
myName = name;
|
||||
myModifiers = modifiers;
|
||||
myType = type;
|
||||
myTypeParameters = typeParameters;
|
||||
myParams = params;
|
||||
myBlock = block;
|
||||
}
|
||||
|
||||
public List<Element> getTypeParameters() {
|
||||
return myTypeParameters;
|
||||
}
|
||||
|
||||
public Element getParams() {
|
||||
return myParams;
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
return myBlock;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String typeParametersToKotlin() {
|
||||
return myTypeParameters.size() > 0 ? "<" + AstUtil.joinNodes(myTypeParameters, COMMA_WITH_SPACE) + ">" : EMPTY;
|
||||
}
|
||||
|
||||
private boolean hasWhere() {
|
||||
for (Element t : myTypeParameters)
|
||||
if (t instanceof TypeParameter && ((TypeParameter) t).hasWhere()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String typeParameterWhereToKotlin() {
|
||||
if (hasWhere()) {
|
||||
List<String> wheres = new LinkedList<String>();
|
||||
for (Element t : myTypeParameters)
|
||||
if (t instanceof TypeParameter) {
|
||||
wheres.add(((TypeParameter) t).getWhereToKotlin());
|
||||
}
|
||||
return SPACE + "where" + SPACE + AstUtil.join(wheres, COMMA_WITH_SPACE) + SPACE;
|
||||
}
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
String modifiersToKotlin() {
|
||||
List<String> modifierList = new LinkedList<String>();
|
||||
|
||||
String accessModifier = accessModifier();
|
||||
if (!accessModifier.isEmpty()) {
|
||||
modifierList.add(accessModifier);
|
||||
}
|
||||
|
||||
if (isAbstract()) {
|
||||
modifierList.add(Modifier.ABSTRACT);
|
||||
}
|
||||
|
||||
if (myModifiers.contains(Modifier.OVERRIDE)) {
|
||||
modifierList.add(Modifier.OVERRIDE);
|
||||
}
|
||||
|
||||
if (!myModifiers.contains(Modifier.ABSTRACT) && !myModifiers.contains(Modifier.OVERRIDE) && !myModifiers.contains(Modifier.FINAL)) {
|
||||
modifierList.add(Modifier.OPEN);
|
||||
}
|
||||
|
||||
if (myModifiers.contains(Modifier.NOT_OPEN)) {
|
||||
modifierList.remove(Modifier.OPEN);
|
||||
}
|
||||
|
||||
if (modifierList.size() > 0) {
|
||||
return AstUtil.join(modifierList, SPACE) + SPACE;
|
||||
}
|
||||
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return modifiersToKotlin() + "fun" + SPACE + myName.toKotlin() + typeParametersToKotlin() + "(" + myParams.toKotlin() + ")" + SPACE + COLON +
|
||||
SPACE + myType.toKotlin() + SPACE +
|
||||
typeParameterWhereToKotlin() +
|
||||
myBlock.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public interface IMember extends INode {
|
||||
boolean isStatic();
|
||||
|
||||
boolean isAbstract();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public interface INode {
|
||||
@NotNull
|
||||
String toKotlin();
|
||||
|
||||
@NotNull
|
||||
Kind getKind();
|
||||
|
||||
enum Kind {
|
||||
UNDEFINED, TYPE, CONSTRUCTOR, BREAK, CONTINUE, VARARG, TRAIT, ASSIGNMENT_EXPRESSION, CALL_CHAIN, LITERAL, ARRAY_TYPE,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public interface Identifier extends INode {
|
||||
@NotNull
|
||||
Identifier EMPTY_IDENTIFIER = new IdentifierImpl("");
|
||||
|
||||
boolean isEmpty();
|
||||
|
||||
String getName();
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class IdentifierImpl extends Expression implements Identifier {
|
||||
private final String myName;
|
||||
private boolean myIsNullable = true;
|
||||
private boolean myQuotingNeeded = true;
|
||||
|
||||
public IdentifierImpl(String name) {
|
||||
myName = name;
|
||||
}
|
||||
|
||||
public IdentifierImpl(String name, boolean isNullable) {
|
||||
myName = name;
|
||||
myIsNullable = isNullable;
|
||||
}
|
||||
|
||||
public IdentifierImpl(String name, boolean isNullable, boolean quotingNeeded) {
|
||||
myName = name;
|
||||
myIsNullable = isNullable;
|
||||
myQuotingNeeded = quotingNeeded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return myName.length() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String quote(String str) {
|
||||
return BACKTICK + str + BACKTICK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNullable() {
|
||||
return myIsNullable;
|
||||
}
|
||||
|
||||
private String ifNeedQuote() {
|
||||
if (myQuotingNeeded && (ONLY_KOTLIN_KEYWORDS.contains(myName) || myName.contains("$"))) {
|
||||
return quote(myName);
|
||||
}
|
||||
return myName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return ifNeedQuote();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class IfStatement extends Expression {
|
||||
private final Expression myCondition;
|
||||
private final Statement myThenStatement;
|
||||
private final Statement myElseStatement;
|
||||
|
||||
public IfStatement(Expression condition, Statement thenStatement, Statement elseStatement) {
|
||||
myCondition = condition;
|
||||
myThenStatement = thenStatement;
|
||||
myElseStatement = elseStatement;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
String result = "if" + SPACE + "(" + myCondition.toKotlin() + ")" + N + myThenStatement.toKotlin() + N;
|
||||
|
||||
if (myElseStatement != Statement.EMPTY_STATEMENT) {
|
||||
return result +
|
||||
"else" + N +
|
||||
myElseStatement.toKotlin();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class Import extends Node {
|
||||
private final String myName;
|
||||
|
||||
public String getName() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
public Import(String name) {
|
||||
myName = name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "import" + SPACE + myName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class InProjectionType extends Type {
|
||||
private final Type myBound;
|
||||
|
||||
public InProjectionType(Type bound) {
|
||||
myBound = bound;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "in" + SPACE + myBound.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class Initializer extends Member {
|
||||
private final Block myBlock;
|
||||
|
||||
public Initializer(Block block, Set<String> modifiers) {
|
||||
myBlock = block;
|
||||
myModifiers = modifiers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return myBlock.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class IsOperator extends Expression {
|
||||
private final Expression myExpression;
|
||||
private final Element myTypeElement;
|
||||
|
||||
public IsOperator(Expression expression, Element typeElement) {
|
||||
myExpression = expression;
|
||||
myTypeElement = typeElement;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "(" + myExpression.toKotlin() + SPACE + "is" + SPACE + myTypeElement.toKotlin() + ")";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class LabelStatement extends Statement {
|
||||
private final Identifier myName;
|
||||
private final Statement myStatement;
|
||||
|
||||
public LabelStatement(Identifier name, Statement statement) {
|
||||
myName = name;
|
||||
myStatement = statement;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return AT + myName.toKotlin() + SPACE + myStatement.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class LiteralExpression extends Expression {
|
||||
private final Identifier myIdentifier;
|
||||
|
||||
public LiteralExpression(Identifier identifier) {
|
||||
myIdentifier = identifier;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.LITERAL;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return myIdentifier.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class LocalVariable extends Expression {
|
||||
private final Identifier myIdentifier;
|
||||
private final Set<String> myModifiersSet;
|
||||
private final Type myType;
|
||||
private final Expression myInitializer;
|
||||
|
||||
public LocalVariable(Identifier identifier, Set<String> modifiersSet, Type type, Expression initializer) {
|
||||
myIdentifier = identifier;
|
||||
myModifiersSet = modifiersSet;
|
||||
myType = type;
|
||||
myInitializer = initializer;
|
||||
}
|
||||
|
||||
public boolean hasModifier(String modifier) {
|
||||
return myModifiersSet.contains(modifier);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
if (myInitializer.isEmpty()) {
|
||||
return myIdentifier.toKotlin() + SPACE + COLON + SPACE + myType.toKotlin();
|
||||
}
|
||||
|
||||
return myIdentifier.toKotlin() + SPACE + COLON + SPACE + myType.toKotlin() + SPACE +
|
||||
EQUAL + SPACE + myInitializer.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public abstract class Member extends Node implements IMember {
|
||||
Set<String> myModifiers;
|
||||
|
||||
@NotNull
|
||||
String accessModifier() {
|
||||
for (String m : myModifiers)
|
||||
if (m.equals(Modifier.PUBLIC) || m.equals(Modifier.PROTECTED) || m.equals(Modifier.PRIVATE)) {
|
||||
return m;
|
||||
}
|
||||
return EMPTY; // package local converted to internal, but we use internal by default
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbstract() {
|
||||
return myModifiers.contains(Modifier.ABSTRACT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStatic() {
|
||||
return myModifiers.contains(Modifier.STATIC);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class MethodCallExpression extends Expression {
|
||||
private final Expression myMethodCall;
|
||||
private final List<Expression> myArguments;
|
||||
private final List<String> myConversions;
|
||||
private final boolean myIsResultNullable;
|
||||
private final List<Type> myTypeParameters;
|
||||
|
||||
public MethodCallExpression(Expression methodCall, List<Expression> arguments, List<Type> typeParameters) {
|
||||
this(methodCall, arguments, AstUtil.createListWithEmptyString(arguments), false, typeParameters);
|
||||
}
|
||||
|
||||
public MethodCallExpression(Expression methodCall, List<Expression> arguments, List<String> conversions, boolean nullable, List<Type> typeParameters) {
|
||||
myMethodCall = methodCall;
|
||||
myArguments = arguments;
|
||||
myConversions = conversions;
|
||||
myIsResultNullable = nullable;
|
||||
myTypeParameters = typeParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNullable() {
|
||||
return myIsResultNullable;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
String typeParamsToKotlin = myTypeParameters.size() > 0
|
||||
? "<" + AstUtil.joinNodes(myTypeParameters, COMMA_WITH_SPACE) + ">"
|
||||
: EMPTY;
|
||||
List<String> applyConversions = AstUtil.applyConversions(AstUtil.nodesToKotlin(myArguments), myConversions);
|
||||
return myMethodCall.toKotlin() + typeParamsToKotlin + "(" + AstUtil.join(applyConversions, COMMA_WITH_SPACE) + ")";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public abstract class Modifier {
|
||||
@NotNull
|
||||
public static final String PUBLIC = "public";
|
||||
@NotNull
|
||||
public static final String PROTECTED = "protected";
|
||||
@NotNull
|
||||
public static final String PRIVATE = "private";
|
||||
@NotNull
|
||||
public static final String INTERNAL = "internal";
|
||||
@NotNull
|
||||
public static final String STATIC = "static";
|
||||
@NotNull
|
||||
public static final String ABSTRACT = "abstract";
|
||||
@NotNull
|
||||
public static final String FINAL = "final";
|
||||
@NotNull
|
||||
public static final String OPEN = "open";
|
||||
@NotNull
|
||||
public static final String NOT_OPEN = "not open";
|
||||
@NotNull
|
||||
public static final String OVERRIDE = "override";
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class NewClassExpression extends Expression {
|
||||
private final Element myName;
|
||||
private final List<Expression> myArguments;
|
||||
private Expression myQualifier;
|
||||
private List<String> myConversions;
|
||||
@Nullable
|
||||
private AnonymousClass myAnonymousClass = null;
|
||||
|
||||
private NewClassExpression(Element name, List<Expression> arguments) {
|
||||
myName = name;
|
||||
myQualifier = EMPTY_EXPRESSION;
|
||||
myArguments = arguments;
|
||||
myConversions = AstUtil.createListWithEmptyString(arguments);
|
||||
}
|
||||
|
||||
public NewClassExpression(@NotNull Expression qualifier, @NotNull Element name, @NotNull List<Expression> arguments,
|
||||
@NotNull List<String> conversions, @Nullable AnonymousClass anonymousClass) {
|
||||
this(name, arguments);
|
||||
myQualifier = qualifier;
|
||||
myConversions = conversions;
|
||||
myAnonymousClass = anonymousClass;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
final String callOperator = myQualifier.isNullable() ? QUESTDOT : DOT;
|
||||
final String qualifier = myQualifier.isEmpty() ? EMPTY : myQualifier.toKotlin() + callOperator;
|
||||
List<String> applyConversions = AstUtil.applyConversions(AstUtil.nodesToKotlin(myArguments), myConversions);
|
||||
String appliedArguments = AstUtil.join(applyConversions, COMMA_WITH_SPACE);
|
||||
return myAnonymousClass != null ?
|
||||
"object" + SPACE + ":" + SPACE + qualifier + myName.toKotlin() + "(" + appliedArguments + ")" + myAnonymousClass.toKotlin()
|
||||
:
|
||||
qualifier + myName.toKotlin() + "(" + appliedArguments + ")";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public abstract class Node implements INode {
|
||||
@NotNull
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.UNDEFINED;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
final static Set<String> ONLY_KOTLIN_KEYWORDS = new HashSet<String>(Arrays.asList(
|
||||
"package", "as", "type", "val", "var", "fun", "is", "in", "object", "when", "trait", "This"
|
||||
));
|
||||
|
||||
@NotNull
|
||||
public final static Set<String> PRIMITIVE_TYPES = new HashSet<String>(Arrays.asList(
|
||||
"double", "float", "long", "int", "short", "byte", "boolean", "char"
|
||||
));
|
||||
|
||||
static final String N = "\n";
|
||||
@NotNull
|
||||
static final String N2 = N + N;
|
||||
@NotNull
|
||||
static final String SPACE = " ";
|
||||
@NotNull
|
||||
static final String EQUAL = "=";
|
||||
@NotNull
|
||||
static final String EMPTY = "";
|
||||
@NotNull
|
||||
static final String DOT = ".";
|
||||
@NotNull
|
||||
static final String QUESTDOT = "?.";
|
||||
@NotNull
|
||||
static final String COLON = ":";
|
||||
@NotNull
|
||||
static final String IN = "in";
|
||||
@NotNull
|
||||
static final String AT = "@";
|
||||
@NotNull
|
||||
static final String BACKTICK = "`";
|
||||
@NotNull
|
||||
static final String QUEST = "?";
|
||||
@NotNull
|
||||
public static final String COMMA_WITH_SPACE = "," + SPACE;
|
||||
@NotNull
|
||||
static final String STAR = "*";
|
||||
@NotNull
|
||||
protected static final String ZERO = "0";
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class OutProjectionType extends Type {
|
||||
private final Type myBound;
|
||||
|
||||
public OutProjectionType(Type bound) {
|
||||
myBound = bound;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "out" + SPACE + myBound.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class Parameter extends Expression {
|
||||
private final Identifier myIdentifier;
|
||||
private final Type myType;
|
||||
private boolean myReadOnly;
|
||||
|
||||
public Parameter(Identifier identifier, Type type) {
|
||||
myIdentifier = identifier;
|
||||
myType = type;
|
||||
myReadOnly = true;
|
||||
}
|
||||
|
||||
public Parameter(IdentifierImpl identifier, Type type, boolean readOnly) {
|
||||
this(identifier, type);
|
||||
myReadOnly = readOnly;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
String vararg = myType.getKind() == Kind.VARARG ? "vararg" + SPACE : EMPTY;
|
||||
String var = myReadOnly ? EMPTY : "var" + SPACE;
|
||||
return vararg + var + myIdentifier.toKotlin() + SPACE + COLON + SPACE + myType.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ParameterList extends Expression {
|
||||
private final List<Parameter> myParameters;
|
||||
|
||||
public ParameterList(List<Parameter> parameters) {
|
||||
myParameters = parameters;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return AstUtil.joinNodes(myParameters, COMMA_WITH_SPACE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ParenthesizedExpression extends Expression {
|
||||
private final Expression myExpression;
|
||||
|
||||
public ParenthesizedExpression(Expression expression) {
|
||||
myExpression = expression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "(" + myExpression.toKotlin() + ")";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class PolyadicExpression extends Expression {
|
||||
private final List<Expression> myExpressions;
|
||||
private final String myToken;
|
||||
private final List<String> myConversions;
|
||||
|
||||
public PolyadicExpression(List<Expression> expressions, String token, List<String> conversions) {
|
||||
super();
|
||||
myExpressions = expressions;
|
||||
myToken = token;
|
||||
myConversions = conversions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
List<String> expressionsWithConversions = AstUtil.applyConversions(AstUtil.nodesToKotlin(myExpressions), myConversions);
|
||||
return AstUtil.join(expressionsWithConversions, SPACE + myToken + SPACE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class PostfixOperator extends Expression {
|
||||
private final String myOp;
|
||||
private final Expression myExpression;
|
||||
|
||||
public PostfixOperator(String op, Expression expression) {
|
||||
myOp = op;
|
||||
myExpression = expression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return myExpression.toKotlin() + myOp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class PrefixOperator extends Expression {
|
||||
private final String myOp;
|
||||
private final Expression myExpression;
|
||||
|
||||
public PrefixOperator(String op, Expression expression) {
|
||||
myOp = op;
|
||||
myExpression = expression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return myOp + myExpression.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class PrimitiveType extends Type {
|
||||
private final Identifier myType;
|
||||
|
||||
public PrimitiveType(Identifier type) {
|
||||
myType = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNullable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return myType.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ReferenceElement extends Element {
|
||||
@NotNull
|
||||
private final Identifier myReference;
|
||||
@NotNull
|
||||
private final List<Type> myTypes;
|
||||
|
||||
public ReferenceElement(@NotNull Identifier reference, @NotNull List<Type> types) {
|
||||
myReference = reference;
|
||||
myTypes = types;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
String typesIfNeeded = myTypes.size() > 0 ? "<" + AstUtil.joinNodes(myTypes, COMMA_WITH_SPACE) + ">" : EMPTY;
|
||||
return myReference.toKotlin() + typesIfNeeded;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ReturnStatement extends Statement {
|
||||
private final Expression myExpression;
|
||||
private String myConversion = EMPTY;
|
||||
|
||||
public ReturnStatement(Expression expression) {
|
||||
myExpression = expression;
|
||||
}
|
||||
|
||||
public ReturnStatement(final Expression expression, final String conversion) {
|
||||
this(expression);
|
||||
myConversion = conversion;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "return" + SPACE + AstUtil.applyConversionForOneItem(myExpression.toKotlin(), myConversion);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class StarProjectionType extends Type {
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
G g = new G("");
|
||||
G<String> g2 = new G<String>("");
|
||||
return STAR;
|
||||
}
|
||||
}
|
||||
|
||||
class G<T extends String> {
|
||||
public <T> G(T t) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public abstract class Statement extends Element {
|
||||
@NotNull
|
||||
public static final Statement EMPTY_STATEMENT = new EmptyStatement();
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
private static class EmptyStatement extends Statement {
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return EMPTY;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class SuperExpression extends Expression {
|
||||
private final Identifier myIdentifier;
|
||||
|
||||
public SuperExpression(Identifier identifier) {
|
||||
myIdentifier = identifier;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
if (myIdentifier.isEmpty()) {
|
||||
return "super";
|
||||
}
|
||||
return "super" + AT + myIdentifier.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class SureCallChainExpression extends Expression {
|
||||
private final Expression myExpression;
|
||||
private final String myConversion;
|
||||
|
||||
public SureCallChainExpression(Expression expression, String conversion) {
|
||||
myExpression = expression;
|
||||
myConversion = conversion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return myExpression.isEmpty();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return myExpression.toKotlin() + myConversion;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class SwitchContainer extends Statement {
|
||||
private final Expression myExpression;
|
||||
private final List<CaseContainer> myCaseContainers;
|
||||
|
||||
public SwitchContainer(final Expression expression, final List<CaseContainer> caseContainers) {
|
||||
myExpression = expression;
|
||||
myCaseContainers = caseContainers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "when" + SPACE + "(" + myExpression.toKotlin() + ")" + SPACE + "{" + N +
|
||||
AstUtil.joinNodes(myCaseContainers, N) + N +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class SwitchLabelStatement extends Statement {
|
||||
private final Expression myExpression;
|
||||
|
||||
public SwitchLabelStatement(final Expression expression) {
|
||||
myExpression = expression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return myExpression.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class SynchronizedStatement extends Statement {
|
||||
private final Expression myExpression;
|
||||
private final Block myBlock;
|
||||
|
||||
public SynchronizedStatement(Expression expression, Block block) {
|
||||
myExpression = expression;
|
||||
myBlock = block;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "synchronized" + SPACE + "(" + myExpression.toKotlin() + ")" + SPACE + myBlock.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ThisExpression extends Expression {
|
||||
private final Identifier myIdentifier;
|
||||
|
||||
public ThisExpression(Identifier identifier) {
|
||||
myIdentifier = identifier;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
if (myIdentifier.isEmpty()) {
|
||||
return "this";
|
||||
}
|
||||
return "this" + AT + myIdentifier.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ThrowStatement extends Expression {
|
||||
private final Expression myExpression;
|
||||
|
||||
public ThrowStatement(Expression expression) {
|
||||
myExpression = expression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "throw" + SPACE + myExpression.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.jet.j2k.Converter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class Trait extends Class {
|
||||
public Trait(Converter converter, Identifier name, Set<String> modifiers, List<Element> typeParameters, List<Type> extendsTypes,
|
||||
List<Expression> baseClassParams, List<Type> implementsTypes, List<Member> members) {
|
||||
super(converter, name, modifiers, typeParameters, extendsTypes, baseClassParams, implementsTypes, getMembers(members, converter));
|
||||
TYPE = "trait";
|
||||
}
|
||||
|
||||
@Override
|
||||
String primaryConstructorSignatureToKotlin() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
boolean needOpenModifier() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class TryStatement extends Statement {
|
||||
private final Block myBlock;
|
||||
private final List<CatchStatement> myCatches;
|
||||
private final Block myFinallyBlock;
|
||||
|
||||
public TryStatement(Block block, List<CatchStatement> catches, Block finallyBlock) {
|
||||
myBlock = block;
|
||||
myCatches = catches;
|
||||
myFinallyBlock = finallyBlock;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "try" + N +
|
||||
myBlock.toKotlin() + N +
|
||||
AstUtil.joinNodes(myCatches, N) + N +
|
||||
(myFinallyBlock.isEmpty() ? EMPTY : "finally" + N + myFinallyBlock.toKotlin());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public abstract class Type extends Element {
|
||||
@NotNull
|
||||
public static final Type EMPTY_TYPE = new EmptyType();
|
||||
boolean myNullable = true;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.TYPE;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Type convertedToNotNull() {
|
||||
myNullable = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isNullable() {
|
||||
return myNullable;
|
||||
}
|
||||
|
||||
String isNullableStr() {
|
||||
return isNullable() ? QUEST : EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
private static class EmptyType extends Type {
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "UNRESOLVED_TYPE";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNullable() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class TypeCastExpression extends Expression {
|
||||
private final Type myType;
|
||||
private final Expression myExpression;
|
||||
|
||||
public TypeCastExpression(Type type, Expression expression) {
|
||||
myType = type;
|
||||
myExpression = expression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "(" + myExpression.toKotlin() + SPACE + "as" + SPACE + myType.toKotlin() + ")";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class TypeElement extends Element {
|
||||
private final Type myType;
|
||||
|
||||
public TypeElement(Type type) {
|
||||
myType = type;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return myType.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class TypeParameter extends Element {
|
||||
private final Identifier myName;
|
||||
private final List<Type> myExtendsTypes;
|
||||
|
||||
public TypeParameter(Identifier name, List<Type> extendsTypes) {
|
||||
myName = name;
|
||||
myExtendsTypes = extendsTypes;
|
||||
}
|
||||
|
||||
public boolean hasWhere() {
|
||||
return myExtendsTypes.size() > 1;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getWhereToKotlin() {
|
||||
if (hasWhere()) {
|
||||
return myName.toKotlin() + SPACE + COLON + SPACE + myExtendsTypes.get(1).toKotlin();
|
||||
}
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
if (myExtendsTypes.size() > 0) {
|
||||
return myName.toKotlin() + SPACE + COLON + SPACE + myExtendsTypes.get(0).toKotlin();
|
||||
}
|
||||
return myName.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class VarArg extends Type {
|
||||
private final Type myType;
|
||||
|
||||
public VarArg(Type type) {
|
||||
myType = type;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.VARARG;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return myType.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class WhileStatement extends Statement {
|
||||
final Expression myCondition;
|
||||
final Statement myStatement;
|
||||
|
||||
public WhileStatement(Expression condition, Statement statement) {
|
||||
myCondition = condition;
|
||||
myStatement = statement;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "while" + SPACE + "(" + myCondition.toKotlin() + ")" + N +
|
||||
myStatement.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.j2k.ast.INode;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class AstUtil {
|
||||
private AstUtil() {
|
||||
}
|
||||
|
||||
private static String join(@NotNull final String[] array, @Nullable final String delimiter) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
boolean haveDelimiter = (delimiter != null);
|
||||
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
buffer.append(array[i]);
|
||||
|
||||
if (haveDelimiter && (i + 1) < array.length) {
|
||||
buffer.append(delimiter);
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static String joinNodes(@NotNull final List<? extends INode> nodes, final String delimiter) {
|
||||
return join(nodesToKotlin(nodes), delimiter);
|
||||
}
|
||||
|
||||
public static String join(@NotNull final List<String> array, final String delimiter) {
|
||||
return join(array.toArray(new String[array.size()]), delimiter);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<String> nodesToKotlin(@NotNull List<? extends INode> nodes) {
|
||||
List<String> result = new LinkedList<String>();
|
||||
for (INode n : nodes)
|
||||
result.add(n.toKotlin());
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String upperFirstCharacter(@NotNull String string) {
|
||||
return string.substring(0, 1).toUpperCase() + string.substring(1);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String lowerFirstCharacter(@NotNull String string) {
|
||||
return string.substring(0, 1).toLowerCase() + string.substring(1);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T> List<String> createListWithEmptyString(@NotNull final List<T> arguments) {
|
||||
final List<String> conversions = new LinkedList<String>();
|
||||
//noinspection UnusedDeclaration
|
||||
for (T argument : arguments) conversions.add("");
|
||||
return conversions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<String> applyConversions(@NotNull List<String> first, @NotNull List<String> second) {
|
||||
List<String> result = new LinkedList<String>();
|
||||
assert first.size() == second.size() : "Lists must have the same size.";
|
||||
for (int i = 0; i < first.size(); i++) {
|
||||
result.add(applyConversionForOneItem(first.get(i), second.get(i)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String applyConversionForOneItem(@NotNull String f, @NotNull String s) {
|
||||
if (s.isEmpty()) {
|
||||
return f;
|
||||
}
|
||||
else {
|
||||
return "(" + f + ")" + s;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T> T getOrElse(@NotNull Map<T, T> map, @NotNull T e, @NotNull T orElse) {
|
||||
if (map.containsKey(e)) {
|
||||
return map.get(e);
|
||||
}
|
||||
return orElse;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String replaceLastQuest(@NotNull String str) {
|
||||
if (str.endsWith("?")) {
|
||||
return str.substring(0, str.length() - 1);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.visitors;
|
||||
|
||||
import com.intellij.psi.JavaRecursiveElementVisitor;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ClassVisitor extends JavaRecursiveElementVisitor {
|
||||
private final Set<String> myClassIdentifiers;
|
||||
|
||||
public ClassVisitor() {
|
||||
myClassIdentifiers = new HashSet<String>();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<String> getClassIdentifiers() {
|
||||
return new HashSet<String>(myClassIdentifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitClass(@NotNull PsiClass aClass) {
|
||||
myClassIdentifiers.add(aClass.getQualifiedName());
|
||||
super.visitClass(aClass);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.visitors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.Converter;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class Dispatcher {
|
||||
private ExpressionVisitor myExpressionVisitor;
|
||||
|
||||
public void setExpressionVisitor(final ExpressionVisitor expressionVisitor) {
|
||||
this.myExpressionVisitor = expressionVisitor;
|
||||
}
|
||||
|
||||
public Dispatcher(@NotNull Converter converter) {
|
||||
myExpressionVisitor = new ExpressionVisitor(converter);
|
||||
}
|
||||
|
||||
public ExpressionVisitor getExpressionVisitor() {
|
||||
return myExpressionVisitor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.visitors;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.Converter;
|
||||
import org.jetbrains.jet.j2k.ast.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.j2k.Converter.modifiersListToModifiersSet;
|
||||
import static org.jetbrains.jet.j2k.ConverterUtil.isAnnotatedAsNotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ElementVisitor extends JavaElementVisitor implements J2KVisitor {
|
||||
|
||||
private final Converter myConverter;
|
||||
|
||||
@NotNull
|
||||
private Element myResult = Element.EMPTY_ELEMENT;
|
||||
|
||||
public ElementVisitor(@NotNull Converter converter) {
|
||||
this.myConverter = converter;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Converter getConverter() {
|
||||
return myConverter;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Element getResult() {
|
||||
return myResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLocalVariable(@NotNull PsiLocalVariable variable) {
|
||||
super.visitLocalVariable(variable);
|
||||
|
||||
myResult = new LocalVariable(
|
||||
new IdentifierImpl(variable.getName()), // TODO
|
||||
modifiersListToModifiersSet(variable.getModifierList()),
|
||||
getConverter().typeToType(variable.getType(), isAnnotatedAsNotNull(variable.getModifierList())),
|
||||
getConverter().createSureCallOnlyForChain(variable.getInitializer(), variable.getType())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitExpressionList(@NotNull PsiExpressionList list) {
|
||||
super.visitExpressionList(list);
|
||||
myResult = new ExpressionList(
|
||||
getConverter().expressionsToExpressionList(list.getExpressions()),
|
||||
getConverter().typesToTypeList(list.getExpressionTypes())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitReferenceElement(@NotNull PsiJavaCodeReferenceElement reference) {
|
||||
super.visitReferenceElement(reference);
|
||||
|
||||
final List<Type> types = getConverter().typesToTypeList(reference.getTypeParameters());
|
||||
if (!reference.isQualified()) {
|
||||
myResult = new ReferenceElement(
|
||||
new IdentifierImpl(reference.getReferenceName()),
|
||||
types
|
||||
);
|
||||
}
|
||||
else {
|
||||
String result = new IdentifierImpl(reference.getReferenceName()).toKotlin();
|
||||
PsiElement qualifier = reference.getQualifier();
|
||||
while (qualifier != null) {
|
||||
final PsiJavaCodeReferenceElement p = (PsiJavaCodeReferenceElement) qualifier;
|
||||
result = new IdentifierImpl(p.getReferenceName()).toKotlin() + "." + result; // TODO: maybe need to replace by safe call?
|
||||
qualifier = p.getQualifier();
|
||||
}
|
||||
myResult = new ReferenceElement(
|
||||
new IdentifierImpl(result),
|
||||
types
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTypeElement(@NotNull PsiTypeElement type) {
|
||||
super.visitTypeElement(type);
|
||||
myResult = new TypeElement(getConverter().typeToType(type.getType()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTypeParameter(@NotNull PsiTypeParameter classParameter) {
|
||||
super.visitTypeParameter(classParameter);
|
||||
myResult = new TypeParameter(
|
||||
new IdentifierImpl(classParameter.getName()), // TODO
|
||||
getConverter().typesToTypeList(classParameter.getExtendsListTypes())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitParameterList(@NotNull PsiParameterList list) {
|
||||
super.visitParameterList(list);
|
||||
myResult = new ParameterList(
|
||||
getConverter().parametersToParameterList(list.getParameters())
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,506 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.visitors;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.j2k.Converter;
|
||||
import org.jetbrains.jet.j2k.ast.*;
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.j2k.Converter.isConstructorPrimary;
|
||||
import static org.jetbrains.jet.j2k.visitors.TypeVisitor.*;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ExpressionVisitor extends StatementVisitor {
|
||||
@NotNull
|
||||
Expression myResult = Expression.EMPTY_EXPRESSION;
|
||||
|
||||
public ExpressionVisitor(@NotNull Converter converter) {
|
||||
super(converter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitExpression(final PsiExpression expression) {
|
||||
myResult = Expression.EMPTY_EXPRESSION;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Expression getResult() {
|
||||
return myResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitArrayAccessExpression(@NotNull PsiArrayAccessExpression expression) {
|
||||
super.visitArrayAccessExpression(expression);
|
||||
myResult = new ArrayAccessExpression(
|
||||
getConverter().expressionToExpression(expression.getArrayExpression()),
|
||||
getConverter().expressionToExpression(expression.getIndexExpression())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitArrayInitializerExpression(@NotNull PsiArrayInitializerExpression expression) {
|
||||
super.visitArrayInitializerExpression(expression);
|
||||
myResult = new ArrayInitializerExpression(
|
||||
getConverter().typeToType(expression.getType()),
|
||||
getConverter().expressionsToExpressionList(expression.getInitializers())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitAssignmentExpression(@NotNull PsiAssignmentExpression expression) {
|
||||
super.visitAssignmentExpression(expression);
|
||||
|
||||
// TODO: simplify
|
||||
|
||||
final IElementType tokenType = expression.getOperationSign().getTokenType();
|
||||
|
||||
String secondOp = "";
|
||||
if (tokenType == JavaTokenType.GTGTEQ) secondOp = "shr";
|
||||
if (tokenType == JavaTokenType.LTLTEQ) secondOp = "shl";
|
||||
if (tokenType == JavaTokenType.XOREQ) secondOp = "xor";
|
||||
if (tokenType == JavaTokenType.ANDEQ) secondOp = "and";
|
||||
if (tokenType == JavaTokenType.OREQ) secondOp = "or";
|
||||
if (tokenType == JavaTokenType.GTGTGTEQ) secondOp = "ushr";
|
||||
|
||||
if (!secondOp.isEmpty()) // if not Kotlin operators
|
||||
{
|
||||
myResult = new AssignmentExpression(
|
||||
getConverter().expressionToExpression(expression.getLExpression()),
|
||||
new BinaryExpression(
|
||||
getConverter().expressionToExpression(expression.getLExpression()),
|
||||
getConverter().expressionToExpression(expression.getRExpression()),
|
||||
secondOp
|
||||
),
|
||||
"="
|
||||
);
|
||||
}
|
||||
else {
|
||||
myResult = new AssignmentExpression(
|
||||
getConverter().expressionToExpression(expression.getLExpression()),
|
||||
getConverter().expressionToExpression(expression.getRExpression()),
|
||||
expression.getOperationSign().getText() // TODO
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getOperatorString(@NotNull IElementType tokenType) {
|
||||
if (tokenType == JavaTokenType.PLUS) return "+";
|
||||
if (tokenType == JavaTokenType.MINUS) return "-";
|
||||
if (tokenType == JavaTokenType.ASTERISK) return "*";
|
||||
if (tokenType == JavaTokenType.DIV) return "/";
|
||||
if (tokenType == JavaTokenType.PERC) return "%";
|
||||
if (tokenType == JavaTokenType.GTGT) return "shr";
|
||||
if (tokenType == JavaTokenType.LTLT) return "shl";
|
||||
if (tokenType == JavaTokenType.XOR) return "xor";
|
||||
if (tokenType == JavaTokenType.AND) return "and";
|
||||
if (tokenType == JavaTokenType.OR) return "or";
|
||||
if (tokenType == JavaTokenType.GTGTGT) return "ushr";
|
||||
if (tokenType == JavaTokenType.GT) return ">";
|
||||
if (tokenType == JavaTokenType.LT) return "<";
|
||||
if (tokenType == JavaTokenType.GE) return ">=";
|
||||
if (tokenType == JavaTokenType.LE) return "<=";
|
||||
if (tokenType == JavaTokenType.EQEQ) return "==";
|
||||
if (tokenType == JavaTokenType.NE) return "!=";
|
||||
if (tokenType == JavaTokenType.ANDAND) return "&&";
|
||||
if (tokenType == JavaTokenType.OROR) return "||";
|
||||
if (tokenType == JavaTokenType.PLUSPLUS) return "++";
|
||||
if (tokenType == JavaTokenType.MINUSMINUS) return "--";
|
||||
if (tokenType == JavaTokenType.EXCL) return "!";
|
||||
|
||||
System.out.println("UNSUPPORTED TOKEN TYPE: " + tokenType.toString());
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
|
||||
super.visitBinaryExpression(expression);
|
||||
|
||||
if (expression.getOperationSign().getTokenType() == JavaTokenType.GTGTGT) {
|
||||
myResult = new DummyMethodCallExpression(
|
||||
getConverter().expressionToExpression(expression.getLOperand()),
|
||||
"ushr",
|
||||
getConverter().expressionToExpression(expression.getROperand()));
|
||||
}
|
||||
else {
|
||||
myResult =
|
||||
new BinaryExpression(
|
||||
getConverter().expressionToExpression(expression.getLOperand()),
|
||||
getConverter().expressionToExpression(expression.getROperand()),
|
||||
getOperatorString(expression.getOperationSign().getTokenType()),
|
||||
getConverter().createConversions(expression, PsiType.BOOLEAN)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitClassObjectAccessExpression(@NotNull PsiClassObjectAccessExpression expression) {
|
||||
super.visitClassObjectAccessExpression(expression);
|
||||
myResult = new ClassObjectAccessExpression(getConverter().elementToElement(expression.getOperand()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitConditionalExpression(@NotNull PsiConditionalExpression expression) {
|
||||
super.visitConditionalExpression(expression);
|
||||
PsiExpression condition = expression.getCondition();
|
||||
PsiType type = condition.getType();
|
||||
Expression e = type != null ?
|
||||
getConverter().createSureCallOnlyForChain(condition, type) :
|
||||
getConverter().expressionToExpression(condition);
|
||||
myResult = new ParenthesizedExpression(
|
||||
new IfStatement(
|
||||
e,
|
||||
getConverter().expressionToExpression(expression.getThenExpression()),
|
||||
getConverter().expressionToExpression(expression.getElseExpression())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitExpressionList(@NotNull PsiExpressionList list) {
|
||||
super.visitExpressionList(list);
|
||||
myResult = new ExpressionList(getConverter().expressionsToExpressionList(list.getExpressions()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInstanceOfExpression(@NotNull PsiInstanceOfExpression expression) {
|
||||
super.visitInstanceOfExpression(expression);
|
||||
myResult = new IsOperator(
|
||||
getConverter().expressionToExpression(expression.getOperand()),
|
||||
getConverter().elementToElement(expression.getCheckType()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLiteralExpression(@NotNull PsiLiteralExpression expression) {
|
||||
super.visitLiteralExpression(expression);
|
||||
|
||||
final Object value = expression.getValue();
|
||||
String text = expression.getText();
|
||||
boolean isQuotingNeeded = true;
|
||||
|
||||
final PsiType type = expression.getType();
|
||||
if (type != null) {
|
||||
String canonicalTypeStr = type.getCanonicalText();
|
||||
if (canonicalTypeStr.equals("double") || canonicalTypeStr.equals(JAVA_LANG_DOUBLE)) {
|
||||
text = text.replace("D", "").replace("d", "");
|
||||
}
|
||||
if (canonicalTypeStr.equals("float") || canonicalTypeStr.equals(JAVA_LANG_FLOAT)) {
|
||||
text = text.replace("F", "").replace("f", "") + "." + OperatorConventions.FLOAT + "()";
|
||||
}
|
||||
if (canonicalTypeStr.equals("long") || canonicalTypeStr.equals(JAVA_LANG_LONG)) {
|
||||
text = text.replace("L", "").replace("l", "");
|
||||
}
|
||||
if (canonicalTypeStr.equals("int") || canonicalTypeStr.equals(JAVA_LANG_INTEGER)) // need for hex support
|
||||
{
|
||||
text = value != null ? value.toString() : text;
|
||||
}
|
||||
|
||||
if (canonicalTypeStr.equals(JAVA_LANG_STRING)) {
|
||||
isQuotingNeeded = false;
|
||||
}
|
||||
if (canonicalTypeStr.equals("char") || canonicalTypeStr.equals(JAVA_LANG_CHARACTER)) {
|
||||
isQuotingNeeded = false;
|
||||
}
|
||||
}
|
||||
myResult = new LiteralExpression(new IdentifierImpl(text, false, isQuotingNeeded));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) {
|
||||
super.visitMethodCallExpression(expression);
|
||||
if (!SuperVisitor.isSuper(expression.getMethodExpression()) || !isInsidePrimaryConstructor(expression)) {
|
||||
myResult = // TODO: not resolved
|
||||
new MethodCallExpression(
|
||||
getConverter().expressionToExpression(expression.getMethodExpression()),
|
||||
getConverter().expressionsToExpressionList(expression.getArgumentList().getExpressions()),
|
||||
getConverter().createConversions(expression),
|
||||
getConverter().typeToType(expression.getType()).isNullable(),
|
||||
getConverter().typesToTypeList(expression.getTypeArguments())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitCallExpression(PsiCallExpression callExpression) {
|
||||
super.visitCallExpression(callExpression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitNewExpression(@NotNull PsiNewExpression expression) {
|
||||
super.visitNewExpression(expression);
|
||||
if (expression.getArrayInitializer() != null) // new Foo[] {Foo(1), Foo(2)}
|
||||
{
|
||||
myResult = createNewEmptyArray(expression);
|
||||
}
|
||||
else if (expression.getArrayDimensions().length > 0) { // new Foo[5]
|
||||
myResult = createNewEmptyArrayWithoutInitialization(expression);
|
||||
}
|
||||
else { // new Class(): common case
|
||||
myResult = createNewClassExpression(expression);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Expression createNewClassExpression(@NotNull PsiNewExpression expression) {
|
||||
final PsiAnonymousClass anonymousClass = expression.getAnonymousClass();
|
||||
final PsiMethod constructor = expression.resolveMethod();
|
||||
PsiJavaCodeReferenceElement classReference = expression.getClassOrAnonymousClassReference();
|
||||
final boolean isNotConvertedClass = classReference != null && !getConverter().getClassIdentifiers().contains(classReference.getQualifiedName());
|
||||
PsiExpressionList argumentList = expression.getArgumentList();
|
||||
PsiExpression[] arguments = argumentList != null ? argumentList.getExpressions() : new PsiExpression[]{};
|
||||
if (constructor == null || isConstructorPrimary(constructor) || isNotConvertedClass) {
|
||||
return new NewClassExpression(
|
||||
getConverter().expressionToExpression(expression.getQualifier()),
|
||||
getConverter().elementToElement(classReference),
|
||||
getConverter().expressionsToExpressionList(arguments),
|
||||
getConverter().createConversions(expression),
|
||||
anonymousClass != null ? getConverter().anonymousClassToAnonymousClass(anonymousClass) : null
|
||||
);
|
||||
}
|
||||
// is constructor secondary
|
||||
final PsiJavaCodeReferenceElement reference = expression.getClassReference();
|
||||
final List<Type> typeParameters = reference != null
|
||||
? getConverter().typesToTypeList(reference.getTypeParameters())
|
||||
: Collections.<Type>emptyList();
|
||||
return new CallChainExpression(
|
||||
new IdentifierImpl(constructor.getName(), false),
|
||||
new MethodCallExpression(
|
||||
new IdentifierImpl("init"),
|
||||
getConverter().expressionsToExpressionList(arguments),
|
||||
typeParameters));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Expression createNewEmptyArrayWithoutInitialization(@NotNull PsiNewExpression expression) {
|
||||
return new ArrayWithoutInitializationExpression(
|
||||
getConverter().typeToType(expression.getType(), true),
|
||||
getConverter().expressionsToExpressionList(expression.getArrayDimensions())
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Expression createNewEmptyArray(@NotNull PsiNewExpression expression) {
|
||||
return getConverter().expressionToExpression(expression.getArrayInitializer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitParenthesizedExpression(@NotNull PsiParenthesizedExpression expression) {
|
||||
super.visitParenthesizedExpression(expression);
|
||||
myResult = new ParenthesizedExpression(
|
||||
getConverter().expressionToExpression(expression.getExpression())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPostfixExpression(@NotNull PsiPostfixExpression expression) {
|
||||
super.visitPostfixExpression(expression);
|
||||
myResult = new PostfixOperator(
|
||||
getOperatorString(expression.getOperationSign().getTokenType()),
|
||||
getConverter().expressionToExpression(expression.getOperand())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPrefixExpression(@NotNull PsiPrefixExpression expression) {
|
||||
super.visitPrefixExpression(expression);
|
||||
if (expression.getOperationTokenType() == JavaTokenType.TILDE) {
|
||||
myResult = new DummyMethodCallExpression(
|
||||
new ParenthesizedExpression(getConverter().expressionToExpression(expression.getOperand())), "inv", Expression.EMPTY_EXPRESSION
|
||||
);
|
||||
}
|
||||
else {
|
||||
myResult = new PrefixOperator(
|
||||
getOperatorString(expression.getOperationSign().getTokenType()),
|
||||
getConverter().expressionToExpression(expression.getOperand())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) {
|
||||
super.visitReferenceExpression(expression);
|
||||
|
||||
final boolean isFieldReference = isFieldReference(expression, getContainingClass(expression));
|
||||
final boolean insideSecondaryConstructor = isInsideSecondaryConstructor(expression);
|
||||
final boolean hasReceiver = isFieldReference && insideSecondaryConstructor;
|
||||
final boolean isThis = isThisExpression(expression);
|
||||
final boolean isNullable = getConverter().typeToType(expression.getType()).isNullable();
|
||||
final String className = getClassNameWithConstructor(expression);
|
||||
|
||||
Expression identifier = new IdentifierImpl(expression.getReferenceName(), isNullable);
|
||||
|
||||
final String __ = "__";
|
||||
if (hasReceiver) {
|
||||
identifier = new CallChainExpression(new IdentifierImpl(__, false), new IdentifierImpl(expression.getReferenceName(), isNullable));
|
||||
}
|
||||
else if (insideSecondaryConstructor && isThis) {
|
||||
identifier = new IdentifierImpl("val __ = " + className); // TODO: hack
|
||||
}
|
||||
|
||||
myResult = new CallChainExpression(
|
||||
getConverter().expressionToExpression(expression.getQualifierExpression()),
|
||||
identifier // TODO: if type exists so identifier is nullable
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getClassNameWithConstructor(@NotNull PsiReferenceExpression expression) {
|
||||
PsiElement context = expression.getContext();
|
||||
while (context != null) {
|
||||
if (context instanceof PsiMethod && ((PsiMethod) context).isConstructor()) {
|
||||
final PsiClass containingClass = ((PsiMethod) context).getContainingClass();
|
||||
if (containingClass != null) {
|
||||
final PsiIdentifier identifier = containingClass.getNameIdentifier();
|
||||
if (identifier != null) {
|
||||
return identifier.getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
context = context.getContext();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static String getClassName(@NotNull PsiExpression expression) {
|
||||
PsiElement context = expression.getContext();
|
||||
while (context != null) {
|
||||
if (context instanceof PsiClass) {
|
||||
final PsiClass containingClass = (PsiClass) context;
|
||||
final PsiIdentifier identifier = containingClass.getNameIdentifier();
|
||||
if (identifier != null) {
|
||||
return identifier.getText();
|
||||
}
|
||||
}
|
||||
context = context.getContext();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private static boolean isFieldReference(@NotNull PsiReferenceExpression expression, PsiClass currentClass) {
|
||||
final PsiReference reference = expression.getReference();
|
||||
if (reference != null) {
|
||||
final PsiElement resolvedReference = reference.resolve();
|
||||
if (resolvedReference != null) {
|
||||
if (resolvedReference instanceof PsiField) {
|
||||
return ((PsiField) resolvedReference).getContainingClass() == currentClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isInsideSecondaryConstructor(@NotNull PsiReferenceExpression expression) {
|
||||
PsiElement context = expression.getContext();
|
||||
while (context != null) {
|
||||
if (context instanceof PsiMethod && ((PsiMethod) context).isConstructor()) {
|
||||
return !isConstructorPrimary((PsiMethod) context);
|
||||
}
|
||||
context = context.getContext();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isInsidePrimaryConstructor(@NotNull PsiExpression expression) {
|
||||
PsiElement context = expression.getContext();
|
||||
while (context != null) {
|
||||
if (context instanceof PsiMethod && ((PsiMethod) context).isConstructor()) {
|
||||
return isConstructorPrimary((PsiMethod) context);
|
||||
}
|
||||
context = context.getContext();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiClass getContainingClass(@NotNull PsiExpression expression) {
|
||||
PsiElement context = expression.getContext();
|
||||
while (context != null) {
|
||||
if (context instanceof PsiMethod && ((PsiMethod) context).isConstructor()) {
|
||||
return ((PsiMethod) context).getContainingClass();
|
||||
}
|
||||
context = context.getContext();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isThisExpression(@NotNull PsiReferenceExpression expression) {
|
||||
for (PsiReference r : expression.getReferences())
|
||||
if (r.getCanonicalText().equals("this")) {
|
||||
final PsiElement res = r.resolve();
|
||||
if (res != null && res instanceof PsiMethod && ((PsiMethod) res).isConstructor()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSuperExpression(@NotNull PsiSuperExpression expression) {
|
||||
super.visitSuperExpression(expression);
|
||||
final PsiJavaCodeReferenceElement qualifier = expression.getQualifier();
|
||||
myResult = new SuperExpression(
|
||||
qualifier != null ?
|
||||
new IdentifierImpl(qualifier.getQualifiedName()) :
|
||||
Identifier.EMPTY_IDENTIFIER
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitThisExpression(@NotNull PsiThisExpression expression) {
|
||||
super.visitThisExpression(expression);
|
||||
final PsiJavaCodeReferenceElement qualifier = expression.getQualifier();
|
||||
myResult = new ThisExpression(
|
||||
qualifier != null ?
|
||||
new IdentifierImpl(qualifier.getQualifiedName()) :
|
||||
Identifier.EMPTY_IDENTIFIER
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTypeCastExpression(@NotNull PsiTypeCastExpression expression) {
|
||||
super.visitTypeCastExpression(expression);
|
||||
|
||||
final PsiTypeElement castType = expression.getCastType();
|
||||
if (castType != null) {
|
||||
myResult = new TypeCastExpression(
|
||||
getConverter().typeToType(castType.getType()),
|
||||
getConverter().expressionToExpression(expression.getOperand())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPolyadicExpression(@NotNull PsiPolyadicExpression expression) {
|
||||
super.visitPolyadicExpression(expression);
|
||||
myResult = new PolyadicExpression(
|
||||
getConverter().expressionsToExpressionList(expression.getOperands()),
|
||||
getOperatorString(expression.getOperationTokenType()),
|
||||
getConverter().createConversions(expression, PsiType.BOOLEAN)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.visitors;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.Converter;
|
||||
import org.jetbrains.jet.j2k.ast.DummyMethodCallExpression;
|
||||
import org.jetbrains.jet.j2k.ast.DummyStringExpression;
|
||||
import org.jetbrains.jet.j2k.ast.IdentifierImpl;
|
||||
|
||||
import static org.jetbrains.jet.j2k.visitors.TypeVisitor.JAVA_LANG_OBJECT;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ExpressionVisitorForDirectObjectInheritors extends ExpressionVisitor {
|
||||
public ExpressionVisitorForDirectObjectInheritors(@NotNull Converter converter) {
|
||||
super(converter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethodCallExpression(@NotNull final PsiMethodCallExpression expression) {
|
||||
if (superMethodInvocation(expression.getMethodExpression(), "hashCode")) {
|
||||
myResult = new DummyMethodCallExpression(new IdentifierImpl("System"), "identityHashCode", new IdentifierImpl("this"));
|
||||
}
|
||||
else if (superMethodInvocation(expression.getMethodExpression(), "equals")) {
|
||||
myResult = new DummyMethodCallExpression(new IdentifierImpl("this"), "identityEquals", getConverter().elementToElement(expression.getArgumentList()));
|
||||
}
|
||||
else if (superMethodInvocation(expression.getMethodExpression(), "toString")) {
|
||||
myResult = new DummyStringExpression(String.format("getJavaClass<%s>.getName() + '@' + Integer.toHexString(hashCode())", getClassName(expression.getMethodExpression())));
|
||||
}
|
||||
else {
|
||||
super.visitMethodCallExpression(expression);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitReferenceExpression(@NotNull final PsiReferenceExpression expression) {
|
||||
super.visitReferenceExpression(expression);
|
||||
}
|
||||
|
||||
private static boolean superMethodInvocation(@NotNull final PsiReferenceExpression expression, final String methodName) {
|
||||
String referenceName = expression.getReferenceName();
|
||||
PsiExpression qualifierExpression = expression.getQualifierExpression();
|
||||
if (referenceName != null && referenceName.equals(methodName)) {
|
||||
if (qualifierExpression instanceof PsiSuperExpression) {
|
||||
PsiType type = qualifierExpression.getType();
|
||||
if (type != null && type.getCanonicalText().equals(JAVA_LANG_OBJECT)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.visitors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.Converter;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public interface J2KVisitor {
|
||||
@NotNull
|
||||
Converter getConverter();
|
||||
}
|
||||
@@ -0,0 +1,396 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.visitors;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.j2k.Converter;
|
||||
import org.jetbrains.jet.j2k.ast.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.j2k.Converter.identifierToIdentifier;
|
||||
import static org.jetbrains.jet.j2k.ConverterUtil.countWritingAccesses;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class StatementVisitor extends ElementVisitor {
|
||||
private Statement myResult = Statement.EMPTY_STATEMENT;
|
||||
|
||||
public StatementVisitor(@NotNull Converter converter) {
|
||||
super(converter);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Statement getResult() {
|
||||
return myResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitAssertStatement(@NotNull PsiAssertStatement statement) {
|
||||
super.visitAssertStatement(statement);
|
||||
myResult = new AssertStatement(
|
||||
getConverter().expressionToExpression(statement.getAssertCondition()),
|
||||
getConverter().expressionToExpression(statement.getAssertDescription())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitBlockStatement(@NotNull PsiBlockStatement statement) {
|
||||
super.visitBlockStatement(statement);
|
||||
myResult = new Block(
|
||||
getConverter().statementsToStatementList(statement.getCodeBlock().getStatements()),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitBreakStatement(@NotNull PsiBreakStatement statement) {
|
||||
super.visitBreakStatement(statement);
|
||||
if (statement.getLabelIdentifier() == null) {
|
||||
myResult = new BreakStatement();
|
||||
}
|
||||
else {
|
||||
myResult = new BreakStatement(
|
||||
identifierToIdentifier(statement.getLabelIdentifier())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitContinueStatement(@NotNull PsiContinueStatement statement) {
|
||||
super.visitContinueStatement(statement);
|
||||
if (statement.getLabelIdentifier() == null) {
|
||||
myResult = new ContinueStatement();
|
||||
}
|
||||
else {
|
||||
myResult = new ContinueStatement(
|
||||
identifierToIdentifier(statement.getLabelIdentifier())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitDeclarationStatement(@NotNull PsiDeclarationStatement statement) {
|
||||
super.visitDeclarationStatement(statement);
|
||||
myResult = new DeclarationStatement(
|
||||
getConverter().elementsToElementList(statement.getDeclaredElements())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitDoWhileStatement(@NotNull PsiDoWhileStatement statement) {
|
||||
super.visitDoWhileStatement(statement);
|
||||
PsiExpression condition = statement.getCondition();
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
Expression expression = condition != null && condition.getType() != null ?
|
||||
getConverter().createSureCallOnlyForChain(condition, condition.getType()) :
|
||||
getConverter().expressionToExpression(condition);
|
||||
myResult = new DoWhileStatement(
|
||||
expression,
|
||||
getConverter().statementToStatement(statement.getBody())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitExpressionStatement(@NotNull PsiExpressionStatement statement) {
|
||||
super.visitExpressionStatement(statement);
|
||||
myResult = getConverter().expressionToExpression(statement.getExpression());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitExpressionListStatement(@NotNull PsiExpressionListStatement statement) {
|
||||
super.visitExpressionListStatement(statement);
|
||||
myResult =
|
||||
new ExpressionListStatement(getConverter().expressionsToExpressionList(statement.getExpressionList().getExpressions()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitForStatement(@NotNull PsiForStatement statement) {
|
||||
super.visitForStatement(statement);
|
||||
|
||||
final PsiStatement initialization = statement.getInitialization();
|
||||
final PsiStatement update = statement.getUpdate();
|
||||
final PsiExpression condition = statement.getCondition();
|
||||
final PsiStatement body = statement.getBody();
|
||||
|
||||
final PsiLocalVariable firstChild = initialization != null && initialization.getFirstChild() instanceof PsiLocalVariable
|
||||
?
|
||||
(PsiLocalVariable) initialization.getFirstChild()
|
||||
: null;
|
||||
|
||||
int bodyWriteCount = countWritingAccesses(firstChild, body);
|
||||
int conditionWriteCount = countWritingAccesses(firstChild, condition);
|
||||
int updateWriteCount = countWritingAccesses(firstChild, update);
|
||||
boolean onceWritableIterator = updateWriteCount == 1 && bodyWriteCount + conditionWriteCount == 0;
|
||||
|
||||
final IElementType operationTokenType = condition != null && condition instanceof PsiBinaryExpression ?
|
||||
((PsiBinaryExpression) condition).getOperationTokenType() : null;
|
||||
if (
|
||||
initialization != null &&
|
||||
initialization instanceof PsiDeclarationStatement
|
||||
&& initialization.getFirstChild() == initialization.getLastChild()
|
||||
&& condition != null
|
||||
&& update != null
|
||||
&& update.getChildren().length == 1
|
||||
&& isPlusPlusExpression(update.getChildren()[0])
|
||||
&& operationTokenType != null
|
||||
&& (operationTokenType == JavaTokenType.LT || operationTokenType == JavaTokenType.LE)
|
||||
&& initialization.getFirstChild() != null
|
||||
&& initialization.getFirstChild() instanceof PsiLocalVariable
|
||||
&& firstChild != null
|
||||
&& firstChild.getNameIdentifier() != null
|
||||
&& onceWritableIterator
|
||||
) {
|
||||
final Expression end = getConverter().expressionToExpression(((PsiBinaryExpression) condition).getROperand());
|
||||
final Expression endExpression = operationTokenType == JavaTokenType.LT ?
|
||||
new BinaryExpression(end, new IdentifierImpl("1"), "-") :
|
||||
end;
|
||||
myResult = new ForeachWithRangeStatement(
|
||||
new IdentifierImpl(firstChild.getName()),
|
||||
getConverter().expressionToExpression(firstChild.getInitializer()),
|
||||
endExpression,
|
||||
getConverter().statementToStatement(body)
|
||||
);
|
||||
}
|
||||
else { // common case: while loop instead of for loop
|
||||
List<Statement> forStatements = new LinkedList<Statement>();
|
||||
forStatements.add(getConverter().statementToStatement(initialization));
|
||||
forStatements.add(new WhileStatement(
|
||||
getConverter().expressionToExpression(condition),
|
||||
new Block(
|
||||
Arrays.asList(getConverter().statementToStatement(body),
|
||||
new Block(Arrays.asList(getConverter().statementToStatement(update)))))));
|
||||
myResult = new Block(forStatements);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isPlusPlusExpression(@NotNull PsiElement psiElement) {
|
||||
return (psiElement instanceof PsiPostfixExpression && ((PsiPostfixExpression) psiElement).getOperationTokenType() == JavaTokenType.PLUSPLUS)
|
||||
|| (psiElement instanceof PsiPrefixExpression && ((PsiPrefixExpression) psiElement).getOperationTokenType() == JavaTokenType.PLUSPLUS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitForeachStatement(@NotNull PsiForeachStatement statement) {
|
||||
super.visitForeachStatement(statement);
|
||||
myResult = new ForeachStatement(
|
||||
getConverter().parameterToParameter(statement.getIterationParameter()),
|
||||
getConverter().expressionToExpression(statement.getIteratedValue()),
|
||||
getConverter().statementToStatement(statement.getBody())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitIfStatement(@NotNull PsiIfStatement statement) {
|
||||
super.visitIfStatement(statement);
|
||||
PsiExpression condition = statement.getCondition();
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
Expression expression = condition != null && condition.getType() != null ?
|
||||
getConverter().createSureCallOnlyForChain(condition, condition.getType()) :
|
||||
getConverter().expressionToExpression(condition);
|
||||
myResult = new IfStatement(
|
||||
expression,
|
||||
getConverter().statementToStatement(statement.getThenBranch()),
|
||||
getConverter().statementToStatement(statement.getElseBranch())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLabeledStatement(@NotNull PsiLabeledStatement statement) {
|
||||
super.visitLabeledStatement(statement);
|
||||
myResult = new LabelStatement(
|
||||
identifierToIdentifier(statement.getLabelIdentifier()),
|
||||
getConverter().statementToStatement(statement.getStatement())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSwitchLabelStatement(@NotNull PsiSwitchLabelStatement statement) {
|
||||
super.visitSwitchLabelStatement(statement);
|
||||
myResult = statement.isDefaultCase() ?
|
||||
new DefaultSwitchLabelStatement() :
|
||||
new SwitchLabelStatement(getConverter().expressionToExpression(statement.getCaseValue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSwitchStatement(@NotNull PsiSwitchStatement statement) {
|
||||
super.visitSwitchStatement(statement);
|
||||
myResult = new SwitchContainer(
|
||||
getConverter().expressionToExpression(statement.getExpression()),
|
||||
switchBodyToCases(statement.getBody())
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<CaseContainer> switchBodyToCases(@Nullable final PsiCodeBlock body) {
|
||||
final List<List<PsiStatement>> cases = splitToCases(body);
|
||||
final List<PsiStatement> allSwitchStatements = body != null
|
||||
? Arrays.asList(body.getStatements())
|
||||
: Collections.<PsiStatement>emptyList();
|
||||
|
||||
List<CaseContainer> result = new LinkedList<CaseContainer>();
|
||||
List<Statement> pendingLabels = new LinkedList<Statement>();
|
||||
int i = 0;
|
||||
for (List<PsiStatement> ls : cases) {
|
||||
assert ls.size() > 0;
|
||||
PsiStatement label = ls.get(0);
|
||||
assert label instanceof PsiSwitchLabelStatement;
|
||||
|
||||
assert allSwitchStatements.get(i) == label : "not a right index";
|
||||
|
||||
if (ls.size() > 1) {
|
||||
pendingLabels.add(getConverter().statementToStatement(label));
|
||||
List<PsiStatement> slice = ls.subList(1, ls.size());
|
||||
|
||||
if (!containsBreak(slice)) {
|
||||
List<Statement> statements = getConverter().statementsToStatementList(slice);
|
||||
statements.addAll(
|
||||
getConverter().statementsToStatementList(getAllToNextBreak(allSwitchStatements, i + ls.size()))
|
||||
);
|
||||
result.add(new CaseContainer(pendingLabels, statements));
|
||||
pendingLabels = new LinkedList<Statement>();
|
||||
}
|
||||
else {
|
||||
result.add(new CaseContainer(pendingLabels, getConverter().statementsToStatementList(slice)));
|
||||
pendingLabels = new LinkedList<Statement>();
|
||||
}
|
||||
}
|
||||
else // ls.size() == 1
|
||||
{
|
||||
pendingLabels.add(getConverter().statementToStatement(label));
|
||||
}
|
||||
i += ls.size();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean containsBreak(@NotNull final List<PsiStatement> slice) {
|
||||
for (PsiStatement s : slice)
|
||||
if (s instanceof PsiBreakStatement) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<PsiStatement> getAllToNextBreak(@NotNull final List<PsiStatement> allStatements, final int start) {
|
||||
List<PsiStatement> result = new LinkedList<PsiStatement>();
|
||||
for (int i = start; i < allStatements.size(); i++) {
|
||||
PsiStatement s = allStatements.get(i);
|
||||
if (s instanceof PsiBreakStatement || s instanceof PsiReturnStatement) {
|
||||
return result;
|
||||
}
|
||||
if (!(s instanceof PsiSwitchLabelStatement)) {
|
||||
result.add(s);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<List<PsiStatement>> splitToCases(@Nullable final PsiCodeBlock body) {
|
||||
List<List<PsiStatement>> cases = new LinkedList<List<PsiStatement>>();
|
||||
List<PsiStatement> currentCaseStatements = new LinkedList<PsiStatement>();
|
||||
boolean isFirst = true;
|
||||
if (body != null) {
|
||||
for (PsiStatement s : body.getStatements()) {
|
||||
if (s instanceof PsiSwitchLabelStatement) {
|
||||
if (isFirst) {
|
||||
isFirst = false;
|
||||
}
|
||||
else {
|
||||
cases.add(currentCaseStatements);
|
||||
currentCaseStatements = new LinkedList<PsiStatement>();
|
||||
}
|
||||
}
|
||||
currentCaseStatements.add(s);
|
||||
}
|
||||
cases.add(currentCaseStatements);
|
||||
}
|
||||
return cases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSynchronizedStatement(@NotNull PsiSynchronizedStatement statement) {
|
||||
super.visitSynchronizedStatement(statement);
|
||||
myResult = new SynchronizedStatement(
|
||||
getConverter().expressionToExpression(statement.getLockExpression()),
|
||||
getConverter().blockToBlock(statement.getBody())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitThrowStatement(@NotNull PsiThrowStatement statement) {
|
||||
super.visitThrowStatement(statement);
|
||||
myResult = new ThrowStatement(
|
||||
getConverter().expressionToExpression(statement.getException())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTryStatement(@NotNull PsiTryStatement statement) {
|
||||
super.visitTryStatement(statement);
|
||||
|
||||
List<CatchStatement> catches = new LinkedList<CatchStatement>();
|
||||
for (int i = 0; i < statement.getCatchBlocks().length; i++) {
|
||||
catches.add(new CatchStatement(
|
||||
getConverter().parameterToParameter(statement.getCatchBlockParameters()[i]),
|
||||
getConverter().blockToBlock(statement.getCatchBlocks()[i], true)
|
||||
));
|
||||
}
|
||||
|
||||
myResult = new TryStatement(
|
||||
getConverter().blockToBlock(statement.getTryBlock(), true),
|
||||
catches,
|
||||
getConverter().blockToBlock(statement.getFinallyBlock(), true)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitWhileStatement(@NotNull PsiWhileStatement statement) {
|
||||
super.visitWhileStatement(statement);
|
||||
PsiExpression condition = statement.getCondition();
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
Expression expression = condition != null && condition.getType() != null ?
|
||||
getConverter().createSureCallOnlyForChain(condition, condition.getType()) :
|
||||
getConverter().expressionToExpression(condition);
|
||||
myResult = new WhileStatement(
|
||||
expression,
|
||||
getConverter().statementToStatement(statement.getBody())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitReturnStatement(@NotNull PsiReturnStatement statement) {
|
||||
super.visitReturnStatement(statement);
|
||||
PsiExpression returnValue = statement.getReturnValue();
|
||||
PsiType methodReturnType = getConverter().getMethodReturnType();
|
||||
Expression expression = returnValue != null && methodReturnType != null ?
|
||||
getConverter().createSureCallOnlyForChain(returnValue, methodReturnType) :
|
||||
getConverter().expressionToExpression(returnValue);
|
||||
myResult = new ReturnStatement(
|
||||
expression
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.visitors;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class SuperVisitor extends JavaRecursiveElementVisitor {
|
||||
@NotNull
|
||||
private final HashSet<PsiExpressionList> myResolvedSuperCallParameters;
|
||||
|
||||
public SuperVisitor() {
|
||||
myResolvedSuperCallParameters = new HashSet<PsiExpressionList>();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public HashSet<PsiExpressionList> getResolvedSuperCallParameters() {
|
||||
return myResolvedSuperCallParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) {
|
||||
super.visitMethodCallExpression(expression);
|
||||
if (isSuper(expression.getMethodExpression())) {
|
||||
myResolvedSuperCallParameters.add(expression.getArgumentList());
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isSuper(@NotNull PsiReference r) {
|
||||
if (r.getCanonicalText().equals("super")) {
|
||||
final PsiElement baseConstructor = r.resolve();
|
||||
if (baseConstructor != null && baseConstructor instanceof PsiMethod && ((PsiMethod) baseConstructor).isConstructor()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.visitors;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ThisVisitor extends JavaRecursiveElementVisitor {
|
||||
@NotNull
|
||||
private final Set<PsiMethod> myResolvedConstructors = Sets.newLinkedHashSet();
|
||||
|
||||
@Override
|
||||
public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) {
|
||||
for (PsiReference r : expression.getReferences())
|
||||
if (r.getCanonicalText().equals("this")) {
|
||||
final PsiElement res = r.resolve();
|
||||
if (res != null && res instanceof PsiMethod && ((PsiMethod) res).isConstructor()) {
|
||||
myResolvedConstructors.add((PsiMethod) res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PsiMethod getPrimaryConstructor() {
|
||||
if (myResolvedConstructors.size() > 0) {
|
||||
PsiMethod first = myResolvedConstructors.toArray(new PsiMethod[myResolvedConstructors.size()])[0];
|
||||
for (PsiMethod m : myResolvedConstructors)
|
||||
if (m.hashCode() != first.hashCode()) {
|
||||
return null;
|
||||
}
|
||||
return first;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k.visitors;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.PsiClassReferenceType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.Converter;
|
||||
import org.jetbrains.jet.j2k.J2KConverterFlags;
|
||||
import org.jetbrains.jet.j2k.ast.*;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class TypeVisitor extends PsiTypeVisitor<Type> implements J2KVisitor {
|
||||
public static final String JAVA_LANG_BYTE = "java.lang.Byte";
|
||||
public static final String JAVA_LANG_CHARACTER = "java.lang.Character";
|
||||
public static final String JAVA_LANG_DOUBLE = "java.lang.Double";
|
||||
public static final String JAVA_LANG_FLOAT = "java.lang.Float";
|
||||
public static final String JAVA_LANG_INTEGER = "java.lang.Integer";
|
||||
public static final String JAVA_LANG_LONG = "java.lang.Long";
|
||||
public static final String JAVA_LANG_SHORT = "java.lang.Short";
|
||||
private static final String JAVA_LANG_BOOLEAN = "java.lang.Boolean";
|
||||
public static final String JAVA_LANG_OBJECT = "java.lang.Object";
|
||||
public static final String JAVA_LANG_STRING = "java.lang.String";
|
||||
private static final String JAVA_LANG_ITERABLE = "java.lang.Iterable";
|
||||
private static final String JAVA_UTIL_ITERATOR = "java.util.Iterator";
|
||||
private final Converter myConverter;
|
||||
private Type myResult = Type.EMPTY_TYPE;
|
||||
|
||||
public TypeVisitor(@NotNull Converter myConverter) {
|
||||
this.myConverter = myConverter;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Type getResult() {
|
||||
return myResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type visitPrimitiveType(@NotNull PsiPrimitiveType primitiveType) {
|
||||
final String name = primitiveType.getCanonicalText();
|
||||
final IdentifierImpl identifier = new IdentifierImpl(name);
|
||||
|
||||
if (name.equals("void")) {
|
||||
myResult = new PrimitiveType(new IdentifierImpl(JetStandardClasses.UNIT_ALIAS));
|
||||
}
|
||||
else if (Node.PRIMITIVE_TYPES.contains(name)) {
|
||||
myResult = new PrimitiveType(new IdentifierImpl(AstUtil.upperFirstCharacter(name)));
|
||||
}
|
||||
else {
|
||||
myResult = new PrimitiveType(identifier);
|
||||
}
|
||||
return super.visitPrimitiveType(primitiveType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type visitArrayType(@NotNull PsiArrayType arrayType) {
|
||||
if (myResult == Type.EMPTY_TYPE) {
|
||||
myResult = new ArrayType(getConverter().typeToType(arrayType.getComponentType()));
|
||||
}
|
||||
return super.visitArrayType(arrayType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type visitClassType(@NotNull PsiClassType classType) {
|
||||
final IdentifierImpl identifier = constructClassTypeIdentifier(classType);
|
||||
final List<Type> resolvedClassTypeParams = createRawTypesForResolvedReference(classType);
|
||||
|
||||
if (classType.getParameterCount() == 0 && resolvedClassTypeParams.size() > 0) {
|
||||
myResult = new ClassType(identifier, resolvedClassTypeParams);
|
||||
}
|
||||
else {
|
||||
myResult = new ClassType(identifier, getConverter().typesToTypeList(classType.getParameters()));
|
||||
}
|
||||
return super.visitClassType(classType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private IdentifierImpl constructClassTypeIdentifier(@NotNull PsiClassType classType) {
|
||||
final PsiClass psiClass = classType.resolve();
|
||||
if (psiClass != null) {
|
||||
String qualifiedName = psiClass.getQualifiedName();
|
||||
if (qualifiedName != null) {
|
||||
if (!qualifiedName.equals("java.lang.Object") && getConverter().hasFlag(J2KConverterFlags.FULLY_QUALIFIED_TYPE_NAMES)) {
|
||||
return new IdentifierImpl(qualifiedName);
|
||||
}
|
||||
if (qualifiedName.equals(JAVA_LANG_ITERABLE)) {
|
||||
return new IdentifierImpl(JAVA_LANG_ITERABLE);
|
||||
}
|
||||
if (qualifiedName.equals(JAVA_UTIL_ITERATOR)) {
|
||||
return new IdentifierImpl(JAVA_UTIL_ITERATOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
final String classTypeName = createQualifiedName(classType);
|
||||
|
||||
if (classTypeName.isEmpty()) {
|
||||
return new IdentifierImpl(getClassTypeName(classType));
|
||||
}
|
||||
|
||||
return new IdentifierImpl(classTypeName);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String createQualifiedName(@NotNull PsiClassType classType) {
|
||||
String classTypeName = "";
|
||||
if (classType instanceof PsiClassReferenceType) {
|
||||
final PsiJavaCodeReferenceElement reference = ((PsiClassReferenceType) classType).getReference();
|
||||
if (reference.isQualified()) {
|
||||
String result = new IdentifierImpl(reference.getReferenceName()).toKotlin();
|
||||
PsiElement qualifier = reference.getQualifier();
|
||||
while (qualifier != null) {
|
||||
final PsiJavaCodeReferenceElement p = (PsiJavaCodeReferenceElement) qualifier;
|
||||
result = new IdentifierImpl(p.getReferenceName()).toKotlin() + "." + result; // TODO: maybe need to replace by safe call?
|
||||
qualifier = p.getQualifier();
|
||||
}
|
||||
classTypeName = result;
|
||||
}
|
||||
}
|
||||
return classTypeName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<Type> createRawTypesForResolvedReference(@NotNull PsiClassType classType) {
|
||||
final List<Type> typeParams = new LinkedList<Type>();
|
||||
if (classType instanceof PsiClassReferenceType) {
|
||||
final PsiJavaCodeReferenceElement reference = ((PsiClassReferenceType) classType).getReference();
|
||||
final PsiElement resolve = reference.resolve();
|
||||
if (resolve != null) {
|
||||
if (resolve instanceof PsiClass)
|
||||
//noinspection UnusedDeclaration
|
||||
{
|
||||
for (PsiTypeParameter p : ((PsiClass) resolve).getTypeParameters()) {
|
||||
Type boundType = p.getSuperTypes().length > 0 ?
|
||||
new ClassType(new IdentifierImpl(getClassTypeName(p.getSuperTypes()[0])), getConverter().typesToTypeList(p.getSuperTypes()[0].getParameters()), true)
|
||||
:
|
||||
new StarProjectionType();
|
||||
|
||||
typeParams.add(boundType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return typeParams;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getClassTypeName(@NotNull PsiClassType classType) {
|
||||
String canonicalTypeStr = classType.getCanonicalText();
|
||||
if (canonicalTypeStr.equals(JAVA_LANG_OBJECT)) return "Any";
|
||||
if (canonicalTypeStr.equals(JAVA_LANG_BYTE)) return "Byte";
|
||||
if (canonicalTypeStr.equals(JAVA_LANG_CHARACTER)) return "Char";
|
||||
if (canonicalTypeStr.equals(JAVA_LANG_DOUBLE)) return "Double";
|
||||
if (canonicalTypeStr.equals(JAVA_LANG_FLOAT)) return "Float";
|
||||
if (canonicalTypeStr.equals(JAVA_LANG_INTEGER)) return "Int";
|
||||
if (canonicalTypeStr.equals(JAVA_LANG_LONG)) return "Long";
|
||||
if (canonicalTypeStr.equals(JAVA_LANG_SHORT)) return "Short";
|
||||
if (canonicalTypeStr.equals(JAVA_LANG_BOOLEAN)) return "Boolean";
|
||||
return classType.getClassName() != null ? classType.getClassName() : classType.getCanonicalText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type visitWildcardType(@NotNull PsiWildcardType wildcardType) {
|
||||
if (wildcardType.isExtends()) {
|
||||
myResult = new OutProjectionType(getConverter().typeToType(wildcardType.getExtendsBound()));
|
||||
}
|
||||
else if (wildcardType.isSuper()) {
|
||||
myResult = new InProjectionType(getConverter().typeToType(wildcardType.getSuperBound()));
|
||||
}
|
||||
else {
|
||||
myResult = new StarProjectionType();
|
||||
}
|
||||
return super.visitWildcardType(wildcardType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type visitEllipsisType(@NotNull PsiEllipsisType ellipsisType) {
|
||||
myResult = new VarArg(getConverter().typeToType(ellipsisType.getComponentType()));
|
||||
return super.visitEllipsisType(ellipsisType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type visitCapturedWildcardType(PsiCapturedWildcardType capturedWildcardType) {
|
||||
return super.visitCapturedWildcardType(capturedWildcardType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type visitDisjunctionType(PsiDisjunctionType disjunctionType) {
|
||||
return super.visitDisjunctionType(disjunctionType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Converter getConverter() {
|
||||
return myConverter;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k;
|
||||
|
||||
import com.intellij.core.JavaCoreEnvironment;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiJavaFile;
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class StandaloneJavaToKotlinConverterTest extends TestCase {
|
||||
private final String myDataPath;
|
||||
private final String myName;
|
||||
@NotNull
|
||||
private final static JavaCoreEnvironment myJavaCoreEnvironment = JavaToKotlinTranslator.setUpJavaCoreEnvironment();
|
||||
|
||||
public StandaloneJavaToKotlinConverterTest(String dataPath, String name) {
|
||||
myDataPath = dataPath;
|
||||
myName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
Converter converter = new Converter();
|
||||
String javaPath = "tests/testData/" + getTestFilePath();
|
||||
String kotlinPath = javaPath.replace(".jav", ".kt");
|
||||
|
||||
final File kotlinFile = new File(kotlinPath);
|
||||
if (!kotlinFile.exists()) {
|
||||
FileUtil.writeToFile(kotlinFile, "");
|
||||
}
|
||||
final String expected = FileUtil.loadFile(kotlinFile);
|
||||
final File javaFile = new File(javaPath);
|
||||
final String javaCode = FileUtil.loadFile(javaFile);
|
||||
|
||||
String actual = "";
|
||||
String parentFileName = javaFile.getParentFile().getName();
|
||||
if (parentFileName.equals("expression")) {
|
||||
actual = expressionToKotlin(converter, javaCode);
|
||||
}
|
||||
else if (parentFileName.equals("statement")) {
|
||||
actual = statementToKotlin(converter, javaCode);
|
||||
}
|
||||
else if (parentFileName.equals("method")) {
|
||||
actual = methodToKotlin(converter, javaCode);
|
||||
}
|
||||
else if (parentFileName.equals("class")) {
|
||||
actual = fileToKotlin(converter, javaCode);
|
||||
}
|
||||
else if (parentFileName.equals("file")) {
|
||||
actual = fileToKotlin(converter, javaCode);
|
||||
}
|
||||
else if (parentFileName.equals("comp")) actual = fileToFileWithCompatibilityImport(javaCode);
|
||||
|
||||
assert !actual.isEmpty() : "Specify what is it: file, class, method, statement or expression: " + javaPath + " parent: " + parentFileName;
|
||||
|
||||
final File tmp = new File(kotlinPath + ".tmp");
|
||||
if (!expected.equals(actual)) FileUtil.writeToFile(tmp, actual);
|
||||
if (expected.equals(actual) && tmp.exists()) //noinspection ResultOfMethodCallIgnored
|
||||
{
|
||||
tmp.delete();
|
||||
}
|
||||
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
String getTestFilePath() {
|
||||
return myDataPath + "/" + myName + ".jav";
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return "test_" + myName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite();
|
||||
// suite.addTest(new StandaloneJavaToKotlinConverterTest("ast/class/file", "kt-639"));
|
||||
suite.addTest(TestCaseBuilder.suiteForDirectory("tests/testData", "/ast", new TestCaseBuilder.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String dataPath, @NotNull String name) {
|
||||
return new StandaloneJavaToKotlinConverterTest(dataPath, name);
|
||||
}
|
||||
}));
|
||||
return suite;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String fileToFileWithCompatibilityImport(@NotNull String text) {
|
||||
return JavaToKotlinTranslator.generateKotlinCodeWithCompatibilityImport(text);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String fileToKotlin(Converter converter, @NotNull String text) {
|
||||
return generateKotlinCode(converter, JavaToKotlinTranslator.createFile(myJavaCoreEnvironment, text));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String generateKotlinCode(@NotNull Converter converter, @Nullable PsiFile file) {
|
||||
if (file != null && file instanceof PsiJavaFile) {
|
||||
JavaToKotlinTranslator.setClassIdentifiers(converter, file);
|
||||
return prettify(converter.elementToKotlin(file));
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String methodToKotlin(Converter converter, String text) throws IOException {
|
||||
String result = fileToKotlin(converter, "final class C {" + text + "}")
|
||||
.replaceAll("class C\\(\\) \\{", "");
|
||||
result = result.substring(0, result.lastIndexOf("}"));
|
||||
return prettify(result);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String statementToKotlin(Converter converter, String text) throws Exception {
|
||||
String result = methodToKotlin(converter, "void main() {" + text + "}");
|
||||
int pos = result.lastIndexOf("}");
|
||||
result = result.substring(0, pos).replaceFirst("fun main\\(\\) : Unit \\{", "");
|
||||
return prettify(result);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String expressionToKotlin(Converter converter, String code) throws Exception {
|
||||
String result = statementToKotlin(converter, "Object o =" + code + "}");
|
||||
result = result.replaceFirst("var o : Any\\? =", "");
|
||||
return prettify(result);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String prettify(@Nullable String code) {
|
||||
if (code == null) {
|
||||
return "";
|
||||
}
|
||||
return code
|
||||
.trim()
|
||||
.replaceAll("\r\n", "\n")
|
||||
.replaceAll(" \n", "\n")
|
||||
.replaceAll("\n ", "\n")
|
||||
.replaceAll("\n+", "\n")
|
||||
.replaceAll(" +", " ")
|
||||
.trim()
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.jetbrains.jet.j2k;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
abstract class TestCaseBuilder {
|
||||
@NotNull
|
||||
private static final FilenameFilter emptyFilter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File file, String name) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull
|
||||
public static String getTestDataPathBase() {
|
||||
return "testData";
|
||||
}
|
||||
|
||||
public static String getHomeDirectory() {
|
||||
return new File(PathManager.getResourceRoot(TestCaseBuilder.class, "/org/jetbrains/jet/TestCaseBuilder.class")).getParentFile().getParentFile().getParent();
|
||||
}
|
||||
|
||||
public interface NamedTestFactory {
|
||||
@NotNull
|
||||
Test createTest(@NotNull String dataPath, @NotNull String name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static TestSuite suiteForDirectory(String baseDataDir, @NotNull final String dataPath, @NotNull NamedTestFactory factory) {
|
||||
return suiteForDirectory(baseDataDir, dataPath, true, emptyFilter, factory);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static TestSuite suiteForDirectory(String baseDataDir, @NotNull final String dataPath, boolean recursive, @NotNull final FilenameFilter filter, @NotNull NamedTestFactory factory) {
|
||||
TestSuite suite = new TestSuite(dataPath);
|
||||
final String extensionJava = ".jav";
|
||||
|
||||
final FilenameFilter extensionFilter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, @NotNull String name) {
|
||||
return name.endsWith(extensionJava);
|
||||
}
|
||||
};
|
||||
FilenameFilter resultFilter;
|
||||
if (filter != emptyFilter) {
|
||||
resultFilter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File file, String s) {
|
||||
return extensionFilter.accept(file, s) && filter.accept(file, s);
|
||||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
resultFilter = extensionFilter;
|
||||
}
|
||||
File dir = new File(baseDataDir + dataPath);
|
||||
FileFilter dirFilter = new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(@NotNull File pathname) {
|
||||
return pathname.isDirectory();
|
||||
}
|
||||
};
|
||||
if (recursive) {
|
||||
File[] files = dir.listFiles(dirFilter);
|
||||
assert files != null : dir;
|
||||
List<File> subdirs = Arrays.asList(files);
|
||||
Collections.sort(subdirs);
|
||||
for (File subdir : subdirs) {
|
||||
suite.addTest(suiteForDirectory(baseDataDir, dataPath + "/" + subdir.getName(), recursive, filter, factory));
|
||||
}
|
||||
}
|
||||
List<File> files = Arrays.asList(dir.listFiles(resultFilter));
|
||||
Collections.sort(files);
|
||||
for (File file : files) {
|
||||
String fileName = file.getName();
|
||||
assert fileName != null;
|
||||
suite.addTest(factory.createTest(dataPath, fileName.substring(0, fileName.length() - extensionJava.length())));
|
||||
}
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package test;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Test {
|
||||
@NotNull String myStr = "String2";
|
||||
|
||||
public Test(@NotNull String str) {
|
||||
myStr = str;
|
||||
}
|
||||
|
||||
public void sout(@NotNull String str) {
|
||||
System.out.println(str);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String dummy(@NotNull String str) {
|
||||
return str;
|
||||
}
|
||||
|
||||
public void test() {
|
||||
sout("String");
|
||||
@NotNull String test = "String2";
|
||||
sout(test);
|
||||
sout(dummy(test));
|
||||
|
||||
new Test(test);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user