use of com.intellij.psi.JavaPsiFacade in project android by JetBrains.
the class OnClickEnumSupport method getAllValues.
@Override
@NotNull
public List<ValueWithDisplayString> getAllValues() {
Module module = myProperty.getModel().getModule();
Configuration configuration = myProperty.getModel().getConfiguration();
String activityClassName = configuration.getActivity();
JavaPsiFacade facade = JavaPsiFacade.getInstance(module.getProject());
Collection<PsiClass> classes;
if (activityClassName != null) {
if (activityClassName.startsWith(".")) {
MergedManifest manifest = MergedManifest.get(module);
String pkg = StringUtil.notNullize(manifest.getPackage());
activityClassName = pkg + activityClassName;
}
PsiClass activityClass = facade.findClass(activityClassName, module.getModuleScope());
if (activityClass != null) {
classes = Collections.singletonList(activityClass);
} else {
classes = Collections.emptyList();
}
} else {
GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, false);
PsiClass activityClass = facade.findClass(CLASS_ACTIVITY, scope);
if (activityClass != null) {
classes = ClassInheritorsSearch.search(activityClass, scope, true).findAll();
} else {
classes = Collections.emptyList();
}
}
List<ValueWithDisplayString> values = new ArrayList<>();
Set<String> found = new HashSet<>();
for (PsiClass psiClass : classes) {
for (PsiMethod method : psiClass.getAllMethods()) {
if (OnClickConverter.CONVERTER_FOR_LAYOUT.checkSignature(method) && found.add(method.getName()) && method instanceof PsiMethodImpl) {
values.add(new ValueWithDisplayString(method.getName(), method.getName(), psiClass.getName()));
}
}
}
return values;
}
use of com.intellij.psi.JavaPsiFacade in project oxy-template-support-plugin by mutant-industries.
the class JavaContext method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
Module module;
PsiElement element = parameters.getOriginalFile().getViewProvider().findElementAt(parameters.getOffset() - 1, OxyTemplateInnerJs.INSTANCE);
if (element == null || element.getNode().getElementType() != JSTokenTypes.DOT && (element = element.getPrevSibling()) == null) {
return;
}
if (element.getNode().getElementType() == TokenType.WHITE_SPACE) {
element = element.getPrevSibling();
}
while (element != null && element.getNode().getElementType() != JSTokenTypes.DOT) {
element = element.getLastChild();
if (element instanceof PsiErrorElement) {
element = element.getPrevSibling();
}
}
if (element == null || element.getNode().getElementType() != JSTokenTypes.DOT || (element = element.getPrevSibling()) == null) {
return;
}
if (element.getNode().getElementType() == TokenType.WHITE_SPACE) {
element = element.getPrevSibling();
}
if (!(element instanceof JSExpression) || (module = ModuleUtilCore.findModuleForPsiElement(parameters.getOriginalFile())) == null) {
return;
}
JSSimpleTypeProcessor typeProcessor = new JSSimpleTypeProcessor();
JSTypeEvaluator.evaluateTypes((JSExpression) element, parameters.getOriginalFile().getViewProvider().getPsi(OxyTemplateInnerJs.INSTANCE), typeProcessor);
JSType type = typeProcessor.getType();
List<String> possibleJavaTypes = new LinkedList<>();
if (type != null) {
if (type instanceof JSCompositeTypeImpl) {
possibleJavaTypes.addAll(((JSCompositeTypeImpl) type).getTypes().stream().filter(jsType -> jsType instanceof JSTypeImpl).map(JSType::getTypeText).collect(Collectors.toList()));
} else if (type instanceof JSTypeImpl) {
possibleJavaTypes.add(type.getTypeText());
}
}
JavaPsiFacade facade = JavaPsiFacade.getInstance(parameters.getOriginalFile().getProject());
GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
List<PsiClass> possibleInstancesOf = new LinkedList<>();
boolean suggestionsFound = false;
PsiClass aClass;
for (String possibleType : possibleJavaTypes) {
if ((aClass = facade.findClass(possibleType, scope)) != null) {
possibleInstancesOf.add(aClass);
possibleInstancesOf.addAll(ExtenderProvider.getExtenders(aClass));
}
}
for (PsiClass psiClass : possibleInstancesOf) {
List<String> alreadySuggested = new LinkedList<>();
for (PsiMethod method : psiClass.getAllMethods()) {
if (method.getContainingClass() == null || Object.class.getName().equals(method.getContainingClass().getQualifiedName()) || method.getReturnType() == null || shippedBaseExtenderMethods.contains(method.getName()) || !method.getModifierList().hasModifierProperty(PsiModifier.PUBLIC) || InheritanceUtil.isInheritor(method.getContainingClass(), EXTENDER_INTERFACE_FQN) && !InheritanceUtil.isInheritor(method.getContainingClass(), EXTENDER_BASE_CLASS_FQN)) {
continue;
}
String insertText = method.getName();
String presentableText = method.getName();
if (insertText.matches("((^is)|(^get)|(^set))[A-Z].*")) {
insertText = presentableText = StringUtils.decapitalize(insertText.replaceFirst("(^is)|(^get)|(^set)", ""));
} else {
presentableText = method.getPresentation() == null ? presentableText + "()" : method.getPresentation().getPresentableText();
insertText += "()";
}
if (alreadySuggested.contains(insertText)) {
continue;
}
result.consume(LookupElementBuilder.create(method, insertText).withIcon(method.getIcon(0)).withTypeText(method.getReturnType().getPresentableText(), true).withTailText(" (" + psiClass.getContainingFile().getName() + ")", true).withPresentableText(presentableText).withInsertHandler(new TrailingPatternConsumer(INSERT_CONSUME)).withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE));
alreadySuggested.add(insertText);
suggestionsFound = true;
}
}
if (suggestionsFound) {
result.stopHere();
}
}
use of com.intellij.psi.JavaPsiFacade in project moe-ide-integration by multi-os-engine.
the class MOEJUnitUtil method checkConfiguration.
public static void checkConfiguration(Module module, int TESTING_TYPE, String PACKAGE_NAME, String CLASS_NAME) throws RuntimeConfigurationException {
JavaPsiFacade facade = JavaPsiFacade.getInstance(module.getProject());
switch(TESTING_TYPE) {
case TEST_ALL_IN_PACKAGE:
if (PACKAGE_NAME == null || PACKAGE_NAME.isEmpty()) {
throw new RuntimeConfigurationWarning("No test package specified");
}
final PsiPackage testPackage = facade.findPackage(PACKAGE_NAME);
if (testPackage == null) {
throw new RuntimeConfigurationWarning(ExecutionBundle.message("package.does.not.exist.error.message", PACKAGE_NAME));
}
Vector<PsiClass> packageTestClasses = MOEJUnitUtil.getTestClasses(module, PACKAGE_NAME);
if (packageTestClasses == null || packageTestClasses.size() == 0) {
throw new RuntimeConfigurationWarning("Not found test class in package: " + PACKAGE_NAME);
}
break;
case TEST_CLASS:
JavaRunConfigurationModule configurationModule = new JavaRunConfigurationModule(module.getProject(), false);
configurationModule.setModule(module);
final PsiClass testClass = configurationModule.checkModuleAndClassName(CLASS_NAME, ExecutionBundle.message("no.test.class.specified.error.text"));
if (!JUnitUtil.isTestClass(testClass)) {
throw new RuntimeConfigurationWarning(ExecutionBundle.message("class.isnt.test.class.error.message", CLASS_NAME));
}
break;
case TEST_METHOD:
// Already not used
break;
}
}
use of com.intellij.psi.JavaPsiFacade in project moe-ide-integration by multi-os-engine.
the class MOETestClassBrowser method showDialog.
@Override
protected String showDialog() {
Project project = getProject();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
if (module == null) {
Messages.showErrorDialog(project, ExecutionBundle.message("module.not.specified.error.text"), CommonBundle.getErrorTitle());
return null;
}
GlobalSearchScope scope = myIncludeLibraryClasses ? module.getModuleWithDependenciesAndLibrariesScope(true) : module.getModuleWithDependenciesScope();
PsiClass initialSelection = facade.findClass(getText(), scope);
TreeClassChooser chooser = createTreeClassChooser(project, scope, initialSelection, new ClassFilter() {
@Override
public boolean isAccepted(PsiClass aClass) {
if (aClass.isInterface())
return false;
final PsiModifierList modifierList = aClass.getModifierList();
return modifierList == null || !modifierList.hasModifierProperty(PsiModifier.ABSTRACT);
}
});
if (chooser == null)
return null;
chooser.showDialog();
PsiClass selClass = chooser.getSelected();
return selClass != null ? selClass.getQualifiedName() : null;
}
use of com.intellij.psi.JavaPsiFacade in project component-runtime by Talend.
the class SuggestionServiceImpl method computeKeySuggestions.
@Override
public List<LookupElement> computeKeySuggestions(final Project project, final Module module, final String packageName, final List<String> containerElements, final String query) {
final JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
final PsiPackage pkg = javaPsiFacade.findPackage(packageName);
if (pkg == null) {
return Collections.emptyList();
}
final String defaultFamily = getFamilyFromPackageInfo(pkg, module);
return Stream.concat(of(pkg.getClasses()).flatMap(this::unwrapInnerClasses).filter(c -> AnnotationUtil.findAnnotation(c, PARTITION_MAPPER, PROCESSOR, EMITTER) != null).flatMap(clazz -> fromComponent(clazz, defaultFamily)), of(pkg.getClasses()).flatMap(this::unwrapInnerClasses).filter(c -> of(c.getAllFields()).anyMatch(f -> AnnotationUtil.findAnnotation(f, OPTION) != null)).flatMap(c -> fromConfiguration(defaultFamily, c.getName(), c))).filter(s -> containerElements.isEmpty() || !containerElements.contains(s.getKey())).filter(s -> query == null || query.isEmpty() || s.getKey().startsWith(query)).map(s -> s.newLookupElement(withPriority(s.getType()))).collect(toList());
}
Aggregations