-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #574 from alibaba/develop
Provide Android Studio plugin.
- Loading branch information
Showing
16 changed files
with
966 additions
and
759 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
plugins { | ||
id 'org.jetbrains.kotlin.jvm' | ||
id "org.jetbrains.intellij" version '0.3.12' | ||
} | ||
|
||
intellij { | ||
version support_idea_version | ||
updateSinceUntilBuild false | ||
plugins 'coverage' | ||
} | ||
|
||
patchPluginXml { | ||
changeNotes """ | ||
1.0.0 | ||
First Release | ||
""" | ||
} | ||
|
||
publishPlugin { | ||
username intellijPublishUsername | ||
password intellijPublishPassword | ||
channels "beta" | ||
} | ||
|
||
dependencies { | ||
compile 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' | ||
} | ||
|
||
compileKotlin { | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
} | ||
compileTestKotlin { | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
} |
127 changes: 127 additions & 0 deletions
127
...lugin/src/main/kotlin/com/alibaba/android/arouter/idea/extensions/NavigationLineMarker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package com.alibaba.android.arouter.idea.extensions | ||
|
||
import com.intellij.codeHighlighting.Pass | ||
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler | ||
import com.intellij.codeInsight.daemon.LineMarkerInfo | ||
import com.intellij.codeInsight.daemon.LineMarkerProviderDescriptor | ||
import com.intellij.navigation.NavigationItem | ||
import com.intellij.notification.Notification | ||
import com.intellij.notification.NotificationType | ||
import com.intellij.notification.Notifications | ||
import com.intellij.openapi.editor.markup.GutterIconRenderer | ||
import com.intellij.openapi.util.IconLoader | ||
import com.intellij.psi.* | ||
import com.intellij.psi.impl.source.tree.java.PsiMethodCallExpressionImpl | ||
import com.intellij.psi.search.GlobalSearchScope | ||
import com.intellij.psi.search.searches.AnnotatedMembersSearch | ||
import java.awt.event.MouseEvent | ||
|
||
/** | ||
* Mark navigation target. | ||
* | ||
* @author zhilong <a href="mailto:zhilong.liu@aliyun.com">Contact me.</a> | ||
* @version 1.0 | ||
* @since 2018/12/13 12:30 PM | ||
*/ | ||
class NavigationLineMarker : LineMarkerProviderDescriptor(), GutterIconNavigationHandler<PsiElement> { | ||
override fun getName(): String? { | ||
return "ARouter Location" | ||
} | ||
|
||
override fun getLineMarkerInfo(element: PsiElement): LineMarkerInfo<*>? { | ||
return if (isNavigationCall(element)) { | ||
LineMarkerInfo<PsiElement>(element, element.textRange, navigationOnIcon, | ||
Pass.UPDATE_ALL, null, this, | ||
GutterIconRenderer.Alignment.LEFT) | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
override fun navigate(e: MouseEvent?, psiElement: PsiElement?) { | ||
if (psiElement is PsiMethodCallExpression) { | ||
val psiExpressionList = (psiElement as PsiMethodCallExpressionImpl).argumentList | ||
if (psiExpressionList.expressions.size == 1) { | ||
// Support `build(path)` only now. | ||
|
||
val targetPath = psiExpressionList.expressions[0].text.replace("\"", "") | ||
val fullScope = GlobalSearchScope.allScope(psiElement.project) | ||
val routeAnnotationWrapper = AnnotatedMembersSearch.search(getAnnotationWrapper(psiElement, fullScope) | ||
?: return, fullScope).findAll() | ||
val target = routeAnnotationWrapper.find { | ||
it.modifierList?.annotations?.map { it.findAttributeValue("path")?.text?.replace("\"", "") }?.contains(targetPath) | ||
?: false | ||
} | ||
|
||
if (null != target) { | ||
// Redirect to target. | ||
NavigationItem::class.java.cast(target).navigate(true) | ||
return | ||
} | ||
} | ||
} | ||
|
||
notifyNotFound() | ||
} | ||
|
||
private fun notifyNotFound() { | ||
Notifications.Bus.notify(Notification(NOTIFY_SERVICE_NAME, NOTIFY_TITLE, NOTIFY_NO_TARGET_TIPS, NotificationType.WARNING)) | ||
} | ||
|
||
private fun getAnnotationWrapper(psiElement: PsiElement?, scope: GlobalSearchScope): PsiClass? { | ||
if (null == routeAnnotationWrapper) { | ||
routeAnnotationWrapper = JavaPsiFacade.getInstance(psiElement?.project).findClass(ROUTE_ANNOTATION_NAME, scope) | ||
} | ||
|
||
return routeAnnotationWrapper | ||
} | ||
|
||
override fun collectSlowLineMarkers(elements: MutableList<PsiElement>, result: MutableCollection<LineMarkerInfo<PsiElement>>) {} | ||
|
||
/** | ||
* Judge whether the code used for navigation. | ||
*/ | ||
private fun isNavigationCall(psiElement: PsiElement): Boolean { | ||
if (psiElement is PsiCallExpression) { | ||
val method = psiElement.resolveMethod() ?: return false | ||
val parent = method.parent | ||
|
||
if (method.name == "build" && parent is PsiClass) { | ||
if (isClassOfARouter(parent)) { | ||
return true | ||
} | ||
} | ||
} | ||
return false | ||
} | ||
|
||
/** | ||
* Judge whether the caller was ARouter | ||
*/ | ||
private fun isClassOfARouter(psiClass: PsiClass): Boolean { | ||
// It was ARouter | ||
if (psiClass.name.equals(SDK_NAME)) { | ||
return true | ||
} | ||
|
||
// It super class was ARouter | ||
psiClass.supers.find { it.name == SDK_NAME } ?: return false | ||
|
||
return true | ||
} | ||
|
||
companion object { | ||
const val ROUTE_ANNOTATION_NAME = "com.alibaba.android.arouter.facade.annotation.Route" | ||
const val SDK_NAME = "ARouter" | ||
|
||
// Notify | ||
const val NOTIFY_SERVICE_NAME = "ARouter Plugin Tips" | ||
const val NOTIFY_TITLE = "Road Sign" | ||
const val NOTIFY_NO_TARGET_TIPS = "No destination found or unsupported type." | ||
|
||
val navigationOnIcon = IconLoader.getIcon("/icon/outline_my_location_black_18dp.png") | ||
} | ||
|
||
// I'm 100% sure this point can not made memory leak. | ||
private var routeAnnotationWrapper: PsiClass? = null | ||
} |
16 changes: 16 additions & 0 deletions
16
arouter-idea-plugin/src/main/resources/META-INF/plugin.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<idea-plugin> | ||
<id>arouter-roadsign</id> | ||
<name>ARouter Helper</name> | ||
<version>1.0.0</version> | ||
<vendor email="zhilong.liu@aliyun.com" url="https://www.alibaba.com">Alibaba</vendor> | ||
<idea-version since-build="162.0"/> | ||
|
||
<description><![CDATA[ | ||
Support to track navigation target. | ||
]]></description> | ||
|
||
<extensions defaultExtensionNs="com.intellij"> | ||
<codeInsight.lineMarkerProvider language="JAVA" | ||
implementationClass="com.alibaba.android.arouter.idea.extensions.NavigationLineMarker"/> | ||
</extensions> | ||
</idea-plugin> |
Binary file added
BIN
+265 Bytes
arouter-idea-plugin/src/main/resources/icon/outline_my_location_black_18dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters