Skip to content
This repository has been archived by the owner on Jul 13, 2020. It is now read-only.

Generator of ActionBars' properties #53

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .idea/libraries/jmustache.xml

This file was deleted.

20 changes: 0 additions & 20 deletions anko.iml

This file was deleted.

105 changes: 104 additions & 1 deletion dsl/props/excluded_methods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,107 @@ android.widget.AutoCompleteTextView#setAdapter
android.widget.ImageView#getDrawable
android.widget.TextView#isTextSelectable
android.widget.EditText#getText
android.view.View#getBackground
android.view.View#getBackground
android.app.Activity#getIntent
android.app.Activity#getApplication
android.app.Activity#isChild
android.app.Activity#getParent
android.app.Activity#getWindowManager
android.app.Activity#getWindow
android.app.Activity#getLoaderManager
android.app.Activity#getCurrentFocus
android.app.Activity#getChangingConfigurations
android.app.Activity#getLastNonConfigurationInstance
android.app.Activity#getLayoutInflater
android.app.Activity#getCallingPackage
android.app.Activity#getCallingActivity
android.app.Activity#isFinishing
android.app.Activity#isChangingConfigurations
android.app.Activity#getRequestedOrientation
android.app.Activity#getTaskId
android.app.Activity#isTaskRoot
android.app.Activity#getLocalClassName
android.app.Activity#getComponentName
android.app.Activity#getTitle
android.app.Activity#getTitleColor
android.app.Activity#getVolumeControlStream
android.app.ActivityGroup#getCurrentActivity
android.app.ActivityGroup#getLocalActivityManager
android.app.Activity#getContentScene
android.app.Activity#getContentTransitionManager
android.app.Activity#setContentTransitionManager
android.app.Activity#getMediaController
android.app.Activity#setMediaController
android.app.Activity#getParentActivityIntent
android.app.Activity#isDestroyed
android.app.Activity#isImmersive
android.app.Activity#setImmersive
android.app.ExpandableListActivity#getExpandableListView
android.app.ExpandableListActivity#getExpandableListAdapter
android.app.ExpandableListActivity#getSelectedId
android.app.ExpandableListActivity#getSelectedPosition
android.app.ListActivity#getSelectedItemPosition
android.app.ListActivity#getSelectedItemId
android.app.ListActivity#getListView
android.app.ListActivity#getListAdapter
android.app.TabActivity#getTabHost
android.app.TabActivity#getTabWidget
android.preference.PreferenceActivity#isMultiPane
android.preference.PreferenceActivity#getPreferenceManager
android.preference.PreferenceActivity#getPreferenceScreen
android.app.Activity#setIntent
android.app.Activity#setContentView
android.app.Activity#setFinishOnTouchOutside
android.app.Activity#setDefaultKeyMode
android.app.Activity#setResult
android.app.Activity#setVisible
android.app.Activity#setRequestedOrientation
android.app.Activity#setTitle
android.app.Activity#setTitleColor
android.app.Activity#setProgressBarVisibility
android.app.Activity#setProgressBarIndeterminateVisibility
android.app.Activity#setProgressBarIndeterminate
android.app.Activity#setProgress
android.app.Activity#setSecondaryProgress
android.app.Activity#setVolumeControlStream
android.app.Activity#setActionBar
android.accounts.AccountAuthenticatorActivity#setAccountAuthenticatorResult
android.app.ExpandableListActivity#setListAdapter
android.app.ExpandableListActivity#setSelectedGroup
android.app.ListActivity#setListAdapter
android.app.ListActivity#setSelection
android.app.TabActivity#setDefaultTab
android.preference.PreferenceActivity#setListFooter
android.preference.PreferenceActivity#setPreferenceScreen
android.app.LauncherActivity#setTitle
android.support.v4.app.FragmentActivity#getLastCustomNonConfigurationInstance
android.support.v4.app.FragmentActivity#getSupportLoaderManager
android.support.v4.app.FragmentActivity#setEnterSharedElementCallback
android.support.v4.app.FragmentActivity#setExitSharedElementCallback
android.support.v7.app.AppCompatActivity#getSupportParentActivityIntent
android.support.v7.app.AppCompatActivity#getDrawerToggleDelegate
android.support.v7.app.AppCompatActivity#getDelegate
android.support.v7.app.AppCompatActivity#setContentView
android.support.v7.app.AppCompatActivity#setSupportProgressBarVisibility
android.support.v7.app.AppCompatActivity#setSupportProgressBarIndeterminateVisibility
android.support.v7.app.AppCompatActivity#setSupportProgressBarIndeterminate
android.support.v7.app.AppCompatActivity#setSupportProgress
android.support.v7.app.AppCompatActivity#setSupportActionBar
android.app.ActionBar#isShowing
android.app.ActionBar#getThemedContext
android.app.ActionBar#getElevation
android.app.ActionBar#setElevation
android.app.ActionBar#getHideOffset
android.app.ActionBar#setHideOffset
android.app.ActionBar#isHideOnContentScrollEnabled
android.app.ActionBar#setHideOnContentScrollEnabled
android.support.v7.app.ActionBar#isShowing
android.support.v7.app.ActionBar#getThemedContext
android.support.v7.app.ActionBar#isTitleTruncated
android.support.v7.app.ActionBar#isHideOnContentScrollEnabled
android.support.v7.app.ActionBar#getHideOffset
android.support.v7.app.ActionBar#getElevation
android.support.v7.app.ActionBar#setHideOnContentScrollEnabled
android.support.v7.app.ActionBar#setHideOffset
android.support.v7.app.ActionBar#setElevation
android.support.v7.app.ActionBar#setWindowTitle
2 changes: 2 additions & 0 deletions dsl/props/excluded_properties.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ android.widget.AbsListView#getCheckedItemPositions
android.widget.AbsListView#getSolidColor
android.widget.AbsListView#getTextFilter
android.widget.AbsListView#getVerticalScrollbarWidth
android.support.v7.internal.app.WindowDecorActionBar#*
android.support.v7.internal.app.ToolbarActionBar#*
28 changes: 27 additions & 1 deletion dsl/props/properties_without_getters.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,30 @@ android.widget.RelativeLayout.gravity
android.widget.LinearLayout.gravity
android.widget.Gallery.gravity
android.widget.Spinner.gravity
android.widget.GridView.gravity
android.widget.GridView.gravity
android.app.ActionBar.icon
android.app.ActionBar.logo
android.app.ActionBar.selectedNavigationItem
android.app.ActionBar.displayUseLogoEnabled
android.app.ActionBar.displayShowHomeEnabled
android.app.ActionBar.displayHomeAsUpEnabled
android.app.ActionBar.displayShowTitleEnabled
android.app.ActionBar.displayShowCustomEnabled
android.app.ActionBar.backgroundDrawable
android.app.ActionBar.stackedBackgroundDrawable
android.app.ActionBar.splitBackgroundDrawable
android.app.ActionBar.homeButtonEnabled
android.app.ActionBar.homeAsUpIndicator
android.support.v7.app.ActionBar.displayHomeAsUpEnabled
android.support.v7.app.ActionBar.selectedNavigationItem
android.support.v7.app.ActionBar.displayUseLogoEnabled
android.support.v7.app.ActionBar.logo
android.support.v7.app.ActionBar.displayShowTitleEnabled
android.support.v7.app.ActionBar.displayShowHomeEnabled
android.support.v7.app.ActionBar.icon
android.support.v7.app.ActionBar.displayShowCustomEnabled
android.support.v7.app.ActionBar.backgroundDrawable
android.support.v7.app.ActionBar.stackedBackgroundDrawable
android.support.v7.app.ActionBar.splitBackgroundDrawable
android.support.v7.app.ActionBar.homeButtonEnabled
android.support.v7.app.ActionBar.homeAsUpIndicator
6 changes: 4 additions & 2 deletions dsl/src/org/jetbrains/android/anko/DSLGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ class DSLGenerator(
}

override fun run() {
if (fVersion.contains("s"))
val isSupport = fVersion.contains("s")

if (isSupport)
config.files.add(AnkoFile.SUPPORT)
else
config.files.remove(AnkoFile.SUPPORT)

val classTree = this.classTree ?: ClassProcessor(jars).genClassTree()
val generator = Generator(classTree, config)
val generator = Generator(classTree, config, isSupport)
val renderer = RenderFacade(generator)
Writer(renderer).write()

Expand Down
27 changes: 23 additions & 4 deletions dsl/src/org/jetbrains/android/anko/Generator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import org.objectweb.asm.tree.FieldNode

class Generator(
public override val classTree: ClassTree,
config: AnkoConfiguration
config: AnkoConfiguration,
isSupport: Boolean
) : Configurable(config), ClassTreeUtils {

private val availableClasses = findAvailableClasses()
Expand All @@ -55,7 +56,7 @@ class Generator(
.map { makeListener(it) }
.sortBy { it.setter.identifier }

private val propertyGetters = generateList(PROPERTIES) {
private val viewPropertyGetters = generateList(PROPERTIES) {
availableMethods
.filter {
it.clazz.isView &&
Expand All @@ -66,11 +67,11 @@ class Generator(
.sortBy { it.identifier }
}

private val propertySetters = availableMethods
private val viewPropertySetters = availableMethods
.filter { it.clazz.isView && it.method.isNonListenerSetter() && !it.method.isOverridden }
.groupBy { it.identifier }

val properties = genProperties(propertyGetters, propertySetters)
val viewProperties = genProperties(viewPropertyGetters, viewPropertySetters)

// Find all ancestors of ViewGroup.LayoutParams in classes that extends ViewGroup.
val layoutParams = viewGroupClasses
Expand All @@ -90,6 +91,24 @@ class Generator(
?: listOf()
}

// Generate actionbar properties
private val actionbarPropertyGetters = generateList(PROPERTIES) {
availableMethods
.filter { ((isSupport && it.clazz.isSupportActionBar) || (!isSupport && it.clazz.isActionBar)) &&
it.method.isGetter() && !it.method.isOverridden && !it.method.isListenerGetter &&
!config.excludedProperties.contains(it.clazz.fqName + "#" + it.method.name) &&
!config.excludedProperties.contains(it.clazz.fqName + "#*")
}
.sortBy { it.identifier }
}

private val actionbarPropertySetters = availableMethods
.filter { ((isSupport && it.clazz.isSupportActionBar) || (!isSupport && it.clazz.isActionBar)) && it.method.isNonListenerSetter() && !it.method.isOverridden }
.groupBy { it.identifier }

val actionbarProperties = genProperties(actionbarPropertyGetters, actionbarPropertySetters)
// ~~~

val interfaceWorkarounds = generateList(INTERFACE_WORKAROUNDS) {
availableClasses.filter {
it.isPublic && it.innerClasses != null && it.fields != null && it.fields.notEmpty &&
Expand Down
7 changes: 6 additions & 1 deletion dsl/src/org/jetbrains/android/anko/render/RenderFacade.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ class RenderFacade(private val generator: Generator) : Configurable(generator.co
genHelperConstructors()
}

val properties = PropertyRenderer(config).process(generator.properties)
// Generate View and ActionBar extension properties (with "best" setter)
val properties: String
get() {
val propertyRender = PropertyRenderer(config)
return propertyRender.process(generator.viewProperties) + propertyRender.process(generator.actionbarProperties)
}

val listeners = ListenerRenderer(config).process(generator.listeners)

Expand Down
2 changes: 1 addition & 1 deletion dsl/src/org/jetbrains/android/anko/utils/ClassInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ val InnerClassNode.isInterface: Boolean

fun ClassNode.getConstructors(): List<MethodNode> {
return (methods as List<MethodNode>).filter { it.isConstructor }
}
}
19 changes: 15 additions & 4 deletions dsl/src/org/jetbrains/android/anko/utils/ClassTreeUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

package org.jetbrains.android.anko.utils

import org.jetbrains.android.anko.ClassTree
import org.jetbrains.android.anko.MethodNodeWithClass
import org.jetbrains.android.anko.isAbstract
import org.jetbrains.android.anko.isInner
import org.jetbrains.android.anko.*
import org.objectweb.asm.tree.ClassNode

public interface ClassTreeUtils {
Expand Down Expand Up @@ -56,4 +53,18 @@ public interface ClassTreeUtils {
return !isInner && (classTree.isSuccessorOf(this, "android/view/ViewGroup") || this.name == "android/view/ViewGroup")
}

protected val ClassNode.isActionBar: Boolean
get() {
val isSuccessor = ((classTree.isSuccessorOf(this, "android/app/Activity") || this.name == "android/app/Activity") ||
(classTree.isSuccessorOf(this, "android/app/ActionBar") || this.name == "android/app/ActionBar"))
return isSuccessor && !isInner
}

protected val ClassNode.isSupportActionBar: Boolean
get() {
val isSuccessor = ((classTree.isSuccessorOf(this, "android/support/v4/app/FragmentActivity") || this.name == "android/support/v4/app/FragmentActivity") ||
((classTree.isSuccessorOf(this, "android/support/v7/app/ActionBar") || this.name == "android/support/v7/app/ActionBar")))
return isSuccessor && !isInner
}

}
15 changes: 12 additions & 3 deletions dsl/static/src/ContextUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@

package org.jetbrains.anko

import android.app.*
import android.content.Intent
import android.content.Context
import android.content.SharedPreferences
import android.content.ActivityNotFoundException
import android.preference.PreferenceManager
import android.app.Activity
import android.app.Fragment
import android.app.Service
import android.os.Bundle
import android.net.Uri
import java.io.Serializable
Expand Down Expand Up @@ -306,3 +304,14 @@ public fun Intent.newTask(): Intent = setFlag(Intent.FLAG_ACTIVITY_NEW_TASK)
public fun Intent.noAnimation(): Intent = setFlag(Intent.FLAG_ACTIVITY_NO_ANIMATION)
public fun Intent.noHistory(): Intent = setFlag(Intent.FLAG_ACTIVITY_NO_HISTORY)
public fun Intent.singleTop(): Intent = setFlag(Intent.FLAG_ACTIVITY_SINGLE_TOP)

[suppress("NOTHING_TO_INLINE")]
public inline fun FragmentManager.transactions(init: FragmentTransaction.() -> FragmentTransaction): FragmentTransaction {
return beginTransaction().init()
}

[suppress("NOTHING_TO_INLINE")]
public inline fun <reified T: Fragment> FragmentManager.find(id: Int): T? = findFragmentById(id) as? T

[suppress("NOTHING_TO_INLINE")]
public inline fun <reified T: Fragment> FragmentManager.find(tag: String): T? = findFragmentByTag(tag) as? T
14 changes: 13 additions & 1 deletion dsl/static/src/Support.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.app.Activity
import android.app.ProgressDialog
import android.app.Service
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.view.View
import android.widget.LinearLayout
import android.content.Context
Expand All @@ -28,6 +29,7 @@ import android.preference.PreferenceManager
import java.util.concurrent.ExecutorService
import java.util.concurrent.Future
import android.content.Intent
import android.support.v4.app.FragmentTransaction
import org.jetbrains.anko.custom.addView
import org.jetbrains.anko.internals.AnkoInternals

Expand Down Expand Up @@ -206,4 +208,14 @@ public fun Fragment.indeterminateProgressDialog(message: Int? = null, title: Int
return getActivity().progressDialog(true, message?.let { getActivity().getString(it) }, title?.let { getActivity().getString(it) }, init)
}

/* END SECTION */
public inline fun FragmentManager.transactions(init: FragmentTransaction.() -> FragmentTransaction): FragmentTransaction {
return beginTransaction().init()
}

[suppress("NOTHING_TO_INLINE")]
public inline fun <reified T: Fragment> FragmentManager.find(id: Int): T? = findFragmentById(id) as? T

[suppress("NOTHING_TO_INLINE")]
public inline fun <reified T: Fragment> FragmentManager.find(tag: String): T? = findFragmentByTag(tag) as? T

/* END SECTION */
10 changes: 9 additions & 1 deletion dsl/stubs/src/SupportStubs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ public open class Fragment {
public fun setArguments(args: Bundle) {

}
}
}

public abstract class FragmentManager {
public abstract fun beginTransaction(): FragmentTransaction
public abstract fun findFragmentById(id: Int): Fragment
public abstract fun findFragmentByTag(tag: String): Fragment
}

public abstract class FragmentTransaction
Loading