Skip to content

Commit

Permalink
Resolving wildcard aspect import with JdtSearchEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Degueule committed May 11, 2015
1 parent 292c1a6 commit 9dfad83
Showing 1 changed file with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import com.google.inject.Inject
import fr.inria.diverse.melange.ast.MetamodelExtensions
import fr.inria.diverse.melange.metamodel.melange.Metamodel
import fr.inria.diverse.melange.utils.AspectCopier
import java.util.List
import org.eclipse.jdt.core.IType
import org.eclipse.jdt.core.search.IJavaSearchConstants
import org.eclipse.jdt.core.search.SearchEngine
import org.eclipse.jdt.core.search.SearchMatch
import org.eclipse.jdt.core.search.SearchPattern
import org.eclipse.jdt.core.search.SearchRequestor
import org.eclipse.xtext.xbase.jvmmodel.JvmTypeReferenceBuilder

class AspectsCopier extends DispatchMelangeProcessor
Expand All @@ -24,6 +31,47 @@ class AspectsCopier extends DispatchMelangeProcessor
}
}
]
}
}
}

private def List<String> resolveWildcardImport(String wildcardImport) {
val matches = newArrayList
val engine = new SearchEngine

val requestor = new SearchRequestor() {
override acceptSearchMatch(SearchMatch match) {
if (match.element instanceof IType) {
val type = match.element as IType
val fqn = type.fullyQualifiedName
val name = type.elementName

// No Context/Properties classes generated from @Aspect
if (!(
(name.endsWith("Context")
&& name.substring(0, (name.length - 7) / 2) == name.substring((name.length - 7) / 2, name.length - 7))
|| (name.endsWith("Properties")
&& name.substring(0, (name.length - 10) / 2) == name.substring((name.length - 10) / 2, name.length - 10))
))
matches.add(type.fullyQualifiedName)
}
}
}

val pattern = SearchPattern.createPattern(
wildcardImport,
IJavaSearchConstants.CLASS,
IJavaSearchConstants.DECLARATIONS,
SearchPattern.R_PATTERN_MATCH
)

engine.search(
pattern,
#[SearchEngine.defaultSearchParticipant],
SearchEngine.createWorkspaceScope,
requestor,
null
)

return matches
}
}

0 comments on commit 9dfad83

Please sign in to comment.