use of com.intellij.psi.PsiCompiledElement in project android by JetBrains.
the class ActionBarHandler method getMenuIdNames.
@Override
public List<String> getMenuIdNames() {
if (myMenus != null) {
return myMenus;
}
boolean token = RenderSecurityManager.enterSafeRegion(myCredential);
try {
final XmlFile xmlFile = myRenderTask.getPsiFile();
String commaSeparatedMenus = xmlFile == null ? null : AndroidPsiUtils.getRootTagAttributeSafely(xmlFile, ATTR_MENU, TOOLS_URI);
if (commaSeparatedMenus != null) {
myMenus = new ArrayList<String>();
Iterables.addAll(myMenus, Splitter.on(',').trimResults().omitEmptyStrings().split(commaSeparatedMenus));
} else {
final String fqn = xmlFile == null ? null : AndroidPsiUtils.getDeclaredContextFqcn(myRenderTask.getModule(), xmlFile);
if (fqn != null) {
final Project project = xmlFile.getProject();
DumbService.getInstance(project).smartInvokeLater(new Runnable() {
@Override
public void run() {
// Glance at the onCreateOptionsMenu of the associated context and use any menus found there.
// This is just a simple textual search; we need to replace this with a proper model lookup.
PsiClass clz = JavaPsiFacade.getInstance(project).findClass(fqn, GlobalSearchScope.allScope(project));
if (clz != null) {
for (PsiMethod method : clz.findMethodsByName(ON_CREATE_OPTIONS_MENU, true)) {
if (method instanceof PsiCompiledElement) {
continue;
}
// TODO: This should instead try to use the GotoRelated implementation's notion
// of associated activities; see what is done in
// AndroidMissingOnClickHandlerInspection. However, the AndroidGotoRelatedProvider
// will first need to properly handle menus.
String matchText = method.getText();
Matcher matcher = MENU_FIELD_PATTERN.matcher(matchText);
Set<String> menus = Sets.newTreeSet();
int index = 0;
while (true) {
if (matcher.find(index)) {
menus.add(matcher.group(1));
index = matcher.end();
} else {
break;
}
}
if (!menus.isEmpty()) {
myMenus = new ArrayList<String>(menus);
}
}
}
}
});
}
}
if (myMenus == null) {
myMenus = Collections.emptyList();
}
} finally {
RenderSecurityManager.exitSafeRegion(token);
}
return myMenus;
}
use of com.intellij.psi.PsiCompiledElement in project intellij-community by JetBrains.
the class FindUsagesHelper method processUsagesInText.
protected static boolean processUsagesInText(@NotNull final PsiElement element, @NotNull Collection<String> stringToSearch, @NotNull GlobalSearchScope searchScope, @NotNull Processor<UsageInfo> processor) {
final TextRange elementTextRange = ApplicationManager.getApplication().runReadAction(new NullableComputable<TextRange>() {
@Override
public TextRange compute() {
if (!element.isValid() || element instanceof PsiCompiledElement)
return null;
return element.getTextRange();
}
});
UsageInfoFactory factory = new UsageInfoFactory() {
@Override
public UsageInfo createUsageInfo(@NotNull PsiElement usage, int startOffset, int endOffset) {
if (!element.isValid())
return new UsageInfo(usage, startOffset, endOffset, true);
if (elementTextRange != null && usage.getContainingFile() == element.getContainingFile() && elementTextRange.contains(startOffset) && elementTextRange.contains(endOffset)) {
return null;
}
PsiReference someReference = usage.findReferenceAt(startOffset);
if (someReference != null) {
PsiElement refElement = someReference.getElement();
for (PsiReference ref : PsiReferenceService.getService().getReferences(refElement, new PsiReferenceService.Hints(element, null))) {
if (element.getManager().areElementsEquivalent(ref.resolve(), element)) {
TextRange range = ref.getRangeInElement().shiftRight(refElement.getTextRange().getStartOffset() - usage.getTextRange().getStartOffset());
return new UsageInfo(usage, range.getStartOffset(), range.getEndOffset(), true);
}
}
}
return new UsageInfo(usage, startOffset, endOffset, true);
}
};
for (String s : stringToSearch) {
if (!PsiSearchHelperImpl.processTextOccurrences(element, s, searchScope, processor, factory))
return false;
}
return true;
}
use of com.intellij.psi.PsiCompiledElement in project intellij-community by JetBrains.
the class MethodInheritanceUtils method findAvailableSuperClasses.
private static void findAvailableSuperClasses(PsiMethod method, List<PsiClass> sourceClasses) {
final PsiMethod[] superMethods = method.findSuperMethods(true);
for (PsiMethod superMethod : superMethods) {
final PsiClass containingClass = superMethod.getContainingClass();
if (!(containingClass instanceof PsiCompiledElement)) {
sourceClasses.add(containingClass);
findAvailableSuperClasses(superMethod, sourceClasses);
}
}
}
use of com.intellij.psi.PsiCompiledElement in project intellij-community by JetBrains.
the class DebuggerContextUtil method findNearest.
public static SourcePosition findNearest(@NotNull DebuggerContextImpl context, @NotNull PsiElement psi, @NotNull PsiFile file) {
if (psi instanceof PsiCompiledElement) {
// it makes no sense to compute text range of compiled element
return null;
}
final DebuggerSession session = context.getDebuggerSession();
if (session != null) {
try {
final XDebugSession debugSession = session.getXDebugSession();
if (debugSession != null) {
final XSourcePosition position = debugSession.getCurrentPosition();
Editor editor = ((FileEditorManagerImpl) FileEditorManager.getInstance(file.getProject())).getSelectedTextEditor(true);
//final Editor editor = fileEditor instanceof TextEditorImpl ? ((TextEditorImpl)fileEditor).getEditor() : null;
if (editor != null && position != null && position.getFile().equals(file.getOriginalFile().getVirtualFile())) {
PsiMethod method = PsiTreeUtil.getParentOfType(PositionUtil.getContextElement(context), PsiMethod.class, false);
final Collection<TextRange> ranges = IdentifierHighlighterPass.getUsages(psi, method != null ? method : file, false);
final int breakPointLine = position.getLine();
int bestLine = -1;
int bestOffset = -1;
for (TextRange range : ranges) {
final int line = editor.offsetToLogicalPosition(range.getStartOffset()).line;
if (line > bestLine && line < breakPointLine) {
bestLine = line;
bestOffset = range.getStartOffset();
} else if (line == breakPointLine) {
bestOffset = range.getStartOffset();
break;
}
}
if (bestOffset > -1) {
return SourcePosition.createFromOffset(file, bestOffset);
}
}
}
} catch (Exception ignore) {
}
}
return null;
}
Aggregations