Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
24,100
boolean (PsiLanguageInjectionHost host) { return host instanceof PsiLiteralExpression; }
isApplicableTo
24,101
BaseInjection (@NotNull PsiElement host, @Nullable Ref<? super PsiElement> commentRef) { PsiFile containingFile = host.getContainingFile(); boolean compiled = containingFile != null && containingFile.getOriginalFile() instanceof PsiCompiledFile; return compiled ? null : super.findCommentInjection(host, commentRef); }
findCommentInjection
24,102
boolean (final Language language, final PsiLanguageInjectionHost psiElement) { if (!isMine(psiElement)) return false; return doInjectInJava(psiElement.getProject(), psiElement, psiElement, language.getID()); }
addInjectionInPlace
24,103
boolean (final PsiLanguageInjectionHost psiElement) { if (!isMine(psiElement)) return false; final HashMap<BaseInjection, Pair<PsiMethod, Integer>> injectionsMap = new HashMap<>(); final ArrayList<PsiElement> annotations = new ArrayList<>(); final PsiLiteralExpression host = (PsiLiteralExpression)psiElement; final Project project = host.getProject(); final Configuration configuration = Configuration.getProjectInstance(project); collectInjections(host, configuration, this, injectionsMap, annotations); if (injectionsMap.isEmpty() && annotations.isEmpty()) return false; final ArrayList<BaseInjection> originalInjections = new ArrayList<>(injectionsMap.keySet()); final List<BaseInjection> newInjections = ContainerUtil.mapNotNull(originalInjections, (NullableFunction<BaseInjection, BaseInjection>)injection -> { final Pair<PsiMethod, Integer> pair = injectionsMap.get(injection); final String placeText = getPatternStringForJavaPlace(pair.first, pair.second); final BaseInjection newInjection = injection.copy(); newInjection.setPlaceEnabled(placeText, false); return InjectorUtils.canBeRemoved(newInjection)? null : newInjection; }); configuration.replaceInjectionsWithUndo(project, host.getContainingFile(), newInjections, originalInjections, annotations); return true; }
removeInjectionInPlace
24,104
boolean (final PsiLanguageInjectionHost psiElement) { if (!isMine(psiElement)) return false; final HashMap<BaseInjection, Pair<PsiMethod, Integer>> injectionsMap = new HashMap<>(); final ArrayList<PsiElement> annotations = new ArrayList<>(); final PsiLiteralExpression host = (PsiLiteralExpression)psiElement; final Project project = host.getProject(); final Configuration configuration = Configuration.getProjectInstance(project); collectInjections(host, configuration, this, injectionsMap, annotations); if (injectionsMap.isEmpty() || !annotations.isEmpty()) return false; final BaseInjection originalInjection = injectionsMap.keySet().iterator().next(); final MethodParameterInjection methodParameterInjection = createFrom(psiElement.getProject(), originalInjection, injectionsMap.get(originalInjection).first, false); final MethodParameterInjection copy = methodParameterInjection.copy(); final BaseInjection newInjection = showInjectionUI(project, methodParameterInjection); if (newInjection != null) { newInjection.mergeOriginalPlacesFrom(copy, false); newInjection.mergeOriginalPlacesFrom(originalInjection, true); configuration.replaceInjectionsWithUndo( project, psiElement.getContainingFile(), Collections.singletonList(newInjection), Collections.singletonList(originalInjection), Collections.<PsiAnnotation>emptyList()); } return true; }
editInjectionInPlace
24,105
BaseInjection (final Project project, final MethodParameterInjection methodParameterInjection) { final MethodParameterPanel panel = new MethodParameterPanel(methodParameterInjection, project); panel.reset(); String helpID = "reference.settings.injection.language.injection.settings.java.parameter"; return showEditInjectionDialog(project, panel, null, helpID) ? new BaseInjection(methodParameterInjection.getSupportId()).copyFrom(methodParameterInjection) : null; }
showInjectionUI
24,106
BaseInjection (final Element element) { return new BaseInjection(JAVA_SUPPORT_ID); }
createInjection
24,107
boolean (final Project project, @NotNull final PsiElement psiElement, PsiLanguageInjectionHost host, final String languageId) { final PsiElement target = ContextComputationProcessor.getTopLevelInjectionTarget(psiElement); final PsiElement parent = target.getParent(); if (parent instanceof PsiReturnStatement || parent instanceof PsiMethod || parent instanceof PsiNameValuePair) { return doInjectInJavaMethod(project, findPsiMethod(parent), -1, host, languageId); } else if (parent instanceof PsiExpressionList && parent.getParent() instanceof PsiCall) { return doInjectInJavaMethod(project, findPsiMethod(parent), findParameterIndex(target, (PsiExpressionList)parent), host, languageId); } else if (parent instanceof PsiAssignmentExpression) { final PsiExpression psiExpression = ((PsiAssignmentExpression)parent).getLExpression(); if (psiExpression instanceof PsiReferenceExpression) { final PsiElement element = ((PsiReferenceExpression)psiExpression).resolve(); if (element != null) { return doInjectInJava(project, element, host, languageId); } } } else if (parent instanceof PsiVariable) { return doAddLanguageAnnotation(project, (PsiModifierListOwner)parent, host, languageId); } else if (target instanceof PsiVariable) { return doAddLanguageAnnotation(project, (PsiModifierListOwner)target, host, languageId); } return false; }
doInjectInJava
24,108
boolean (final Project project, final PsiModifierListOwner modifierListOwner, @NotNull PsiLanguageInjectionHost host, final String languageId) { return doAddLanguageAnnotation(project, modifierListOwner, host, languageId, host1 -> { final Configuration.AdvancedConfiguration configuration = Configuration.getProjectInstance(project).getAdvancedConfiguration(); boolean allowed = configuration.isSourceModificationAllowed(); configuration.setSourceModificationAllowed(true); try { return doInjectInJava(project, host1, host1, languageId); } finally { configuration.setSourceModificationAllowed(allowed); } }); }
doAddLanguageAnnotation
24,109
boolean (Module module) { if (module == null) return false; return JavaPsiFacade.getInstance(module.getProject()) .findClass(AnnotationUtil.LANGUAGE, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module)) != null; }
isAnnotationsJarInPath
24,110
boolean (@NotNull Project project, @Nullable final PsiModifierListOwner modifierListOwner, @NotNull final PsiLanguageInjectionHost host, final String languageId, Processor<? super PsiLanguageInjectionHost> annotationFixer) { if (modifierListOwner == null) return false; final Task.WithResult<Boolean, RuntimeException> task = new Task.WithResult<>(project, IntelliLangBundle.message("progress.looking.for", AnnotationUtil.LANGUAGE), true) { @Override protected Boolean compute(@NotNull ProgressIndicator indicator) { return ReadAction.nonBlocking(() -> isAnnotationsJarInPath(ModuleUtilCore.findModuleForPsiElement(modifierListOwner))) .executeSynchronously(); } }; final boolean addAnnotation = ProgressManager.getInstance().run(task) && PsiUtil.isLanguageLevel5OrHigher(modifierListOwner) && modifierListOwner.getModifierList() != null; final PsiElement statement = PsiTreeUtil.getParentOfType(host, PsiStatement.class, PsiField.class); if (!addAnnotation && statement == null) return false; Configuration.AdvancedConfiguration configuration = Configuration.getProjectInstance(project).getAdvancedConfiguration(); if (!configuration.isSourceModificationAllowed()) { String fixText = addAnnotation ? IntelliLangBundle.message("intelliLang.suggest.insert.annotation") : IntelliLangBundle.message("intelliLang.suggest.insert.comment"); InjectLanguageAction.addFixer(host, annotationFixer, fixText); return false; } WriteCommandAction.writeCommandAction(project, modifierListOwner.getContainingFile()).run(() -> { PsiElementFactory javaFacade = JavaPsiFacade.getElementFactory(project); if (addAnnotation) { JVMElementFactory factory = ObjectUtils.chooseNotNull(JVMElementFactories.getFactory(modifierListOwner.getLanguage(), project), javaFacade); PsiAnnotation annotation = factory.createAnnotationFromText("@" + AnnotationUtil.LANGUAGE + "(\"" + languageId + "\")", modifierListOwner); PsiModifierList list = Objects.requireNonNull(modifierListOwner.getModifierList()); final PsiAnnotation existingAnnotation = list.findAnnotation(AnnotationUtil.LANGUAGE); if (existingAnnotation != null) { existingAnnotation.replace(annotation); } else { list.addAfter(annotation, null); } JavaCodeStyleManager.getInstance(project).shortenClassReferences(list); } else { statement.getParent().addBefore(javaFacade.createCommentFromText("//language=" + languageId, host), statement); } }); return true; }
doAddLanguageAnnotation
24,111
Boolean (@NotNull ProgressIndicator indicator) { return ReadAction.nonBlocking(() -> isAnnotationsJarInPath(ModuleUtilCore.findModuleForPsiElement(modifierListOwner))) .executeSynchronously(); }
compute
24,112
boolean (@NotNull final Project project, @Nullable final PsiMethod psiMethod, final int parameterIndex, @NotNull PsiLanguageInjectionHost host, @NotNull final String languageId) { if (psiMethod == null) return false; if (parameterIndex < -1) return false; if (parameterIndex >= psiMethod.getParameterList().getParametersCount()) return false; final PsiModifierList methodModifiers = psiMethod.getModifierList(); if (methodModifiers.hasModifierProperty(PsiModifier.PRIVATE) || methodModifiers.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) { return doAddLanguageAnnotation(project, parameterIndex >= 0? psiMethod.getParameterList().getParameters()[parameterIndex] : psiMethod, host, languageId); } final PsiClass containingClass = psiMethod.getContainingClass(); assert containingClass != null; final PsiModifierList classModifiers = containingClass.getModifierList(); if (classModifiers != null && (classModifiers.hasModifierProperty(PsiModifier.PRIVATE) || classModifiers.hasModifierProperty(PsiModifier.PACKAGE_LOCAL))) { return doAddLanguageAnnotation(project, parameterIndex >= 0 ? psiMethod.getParameterList().getParameters()[parameterIndex] : psiMethod, host, languageId); } final MethodParameterInjection injection = makeParameterInjection(psiMethod, parameterIndex, languageId); doEditInjection(project, injection, host.getContainingFile(), psiMethod); return true; }
doInjectInJavaMethod
24,113
MethodParameterInjection (@NotNull PsiMethod psiMethod, int parameterIndex, @NotNull String languageId) { final PsiClass containingClass = psiMethod.getContainingClass(); assert containingClass != null; final String className = containingClass.getQualifiedName(); assert className != null; final MethodParameterInjection injection = new MethodParameterInjection(); injection.setInjectedLanguageId(languageId); injection.setClassName(className); final MethodInfo info = createMethodInfo(psiMethod); if (parameterIndex < 0) { info.setReturnFlag(true); } else { info.getParamFlags()[parameterIndex] = true; } injection.setMethodInfos(Collections.singletonList(info)); injection.generatePlaces(); return injection; }
makeParameterInjection
24,114
int (final PsiElement target, final PsiExpressionList parent) { final int idx = Arrays.<PsiElement>asList(parent.getExpressions()).indexOf(target); return idx < 0? -2 : idx; }
findParameterIndex
24,115
PsiMethod (final PsiElement parent) { if (parent instanceof PsiNameValuePair) { final PsiAnnotation annotation = PsiTreeUtil.getParentOfType(parent, PsiAnnotation.class); if (annotation != null) { final PsiJavaCodeReferenceElement referenceElement = annotation.getNameReferenceElement(); if (referenceElement != null) { PsiElement resolved = referenceElement.resolve(); if (resolved != null) { final String name = ((PsiNameValuePair)parent).getName(); PsiMethod[] methods = ((PsiClass)resolved).findMethodsByName(name == null? PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME : name, false); if (methods.length == 1) { return methods[0]; } } } } } final PsiMethod first; if (parent.getParent() instanceof PsiCall) { first = ((PsiCall)parent.getParent()).resolveMethod(); } else { first = PsiTreeUtil.getParentOfType(parent, PsiMethod.class, false); } if (first == null || first.getContainingClass() == null) return null; final LinkedList<PsiMethod> methods = new LinkedList<>(); methods.add(first); while (!methods.isEmpty()) { final PsiMethod method = methods.removeFirst(); final PsiClass psiClass = method.getContainingClass(); if (psiClass != null && psiClass.getQualifiedName() != null) { return method; } else { ContainerUtil.addAll(methods, method.findSuperMethods()); } } return null; }
findPsiMethod
24,116
void (final Project project, final MethodParameterInjection template, PsiFile psiFile, final PsiMethod contextMethod) { final Configuration configuration = InjectorUtils.getEditableInstance(project); final BaseInjection baseTemplate = new BaseInjection(template.getSupportId()).copyFrom(template); final MethodParameterInjection allMethodParameterInjection = createFrom(project, baseTemplate, contextMethod, true); // find existing injection for this class. final BaseInjection originalInjection = configuration.findExistingInjection(allMethodParameterInjection); final MethodParameterInjection methodParameterInjection; if (originalInjection == null) { methodParameterInjection = template; } else { final BaseInjection originalCopy = originalInjection.copy(); final InjectionPlace currentPlace = template.getInjectionPlaces()[0]; originalCopy.mergeOriginalPlacesFrom(template, true); originalCopy.setPlaceEnabled(currentPlace.getText(), true); methodParameterInjection = createFrom(project, originalCopy, contextMethod, false); } mergePlacesAndAddToConfiguration(project, psiFile, configuration, methodParameterInjection, originalInjection); }
doEditInjection
24,117
void (@NotNull Project project, @Nullable PsiFile psiFile, @NotNull Configuration configuration, @NotNull MethodParameterInjection injection, @Nullable BaseInjection originalInjection) { BaseInjection newInjection = new BaseInjection(injection.getSupportId()).copyFrom(injection); if (originalInjection != null) { newInjection.mergeOriginalPlacesFrom(originalInjection, true); } configuration.replaceInjectionsWithUndo( project, psiFile, Collections.singletonList(newInjection), ContainerUtil.createMaybeSingletonList(originalInjection), Collections.emptyList()); }
mergePlacesAndAddToConfiguration
24,118
void (PsiLiteralExpression host, Configuration configuration, JavaLanguageInjectionSupport support, final HashMap<BaseInjection, Pair<PsiMethod, Integer>> injectionsMap, final ArrayList<? super PsiElement> annotations) { new ConcatenationInjector.InjectionProcessor(configuration, support, host) { @Override protected boolean processCommentInjectionInner(PsiElement comment, BaseInjection injection) { ContainerUtil.addAll(annotations, comment); return true; } @Override protected boolean processAnnotationInjectionInner(PsiModifierListOwner owner, PsiAnnotation[] annos) { ContainerUtil.addAll(annotations, annos); return true; } @Override protected boolean processXmlInjections(BaseInjection injection, PsiModifierListOwner owner, PsiMethod method, int paramIndex) { injectionsMap.put(injection, Pair.create(method, paramIndex)); return true; } }.processInjections(); }
collectInjections
24,119
boolean (PsiElement comment, BaseInjection injection) { ContainerUtil.addAll(annotations, comment); return true; }
processCommentInjectionInner
24,120
boolean (PsiModifierListOwner owner, PsiAnnotation[] annos) { ContainerUtil.addAll(annotations, annos); return true; }
processAnnotationInjectionInner
24,121
boolean (BaseInjection injection, PsiModifierListOwner owner, PsiMethod method, int paramIndex) { injectionsMap.put(injection, Pair.create(method, paramIndex)); return true; }
processXmlInjections
24,122
MethodParameterInjection (final Project project, final BaseInjection injection, final PsiMethod contextMethod, final boolean includeAllPlaces) { final PsiClass[] classes; final String className; if (contextMethod != null) { final PsiClass psiClass = contextMethod.getContainingClass(); className = psiClass == null ? "" : StringUtil.notNullize(psiClass.getQualifiedName()); classes = psiClass == null? PsiClass.EMPTY_ARRAY : new PsiClass[] {psiClass}; } else { String found = null; final Pattern pattern = Pattern.compile(".*definedInClass\\(\"([^\"]*)\"\\)+"); for (InjectionPlace place : injection.getInjectionPlaces()) { final Matcher matcher = pattern.matcher(place.getText()); if (matcher.matches()) { found = matcher.group(1); } } if (found == null) { // hack to guess at least the class name final Matcher matcher = ourPresentationPattern.matcher(injection.getDisplayName()); if (matcher.matches()) { final String pkg = matcher.group(2); found = pkg.substring(1, pkg.length()-1)+"." + matcher.group(1); } } classes = found != null && project.isInitialized()? JavaPsiFacade.getInstance(project).findClasses(found, GlobalSearchScope .allScope(project)) : PsiClass.EMPTY_ARRAY; className = StringUtil.notNullize(classes.length == 0 ? found : classes[0].getQualifiedName()); } final MethodParameterInjection result = new MethodParameterInjection(); result.copyFrom(injection); result.setInjectionPlaces(InjectionPlace.EMPTY_ARRAY); result.setClassName(className); final ArrayList<MethodInfo> infos = new ArrayList<>(); if (classes.length > 0) { final Set<String> visitedSignatures = new HashSet<>(); final PatternCompiler<PsiElement> compiler = injection.getCompiler(); for (PsiClass psiClass : classes) { for (PsiMethod method : psiClass.getMethods()) { final PsiModifierList modifiers = method.getModifierList(); if (modifiers.hasModifierProperty(PsiModifier.PRIVATE) || modifiers.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) continue; boolean add = false; final MethodInfo methodInfo = createMethodInfo(method); if (!visitedSignatures.add(methodInfo.getMethodSignature())) continue; if (isInjectable(method.getReturnType(), method.getProject())) { final int parameterIndex = -1; int index = ArrayUtilRt.find(injection.getInjectionPlaces(), new InjectionPlace( compiler.compileElementPattern(getPatternStringForJavaPlace(method, parameterIndex)), true)); final InjectionPlace place = index > -1 ? injection.getInjectionPlaces()[index] : null; methodInfo.setReturnFlag(place != null && place.isEnabled() || includeAllPlaces); add = true; } final PsiParameter[] parameters = method.getParameterList().getParameters(); for (int i = 0; i < parameters.length; i++) { final PsiParameter p = parameters[i]; if (isInjectable(p.getType(), p.getProject())) { int index = ArrayUtilRt.find(injection.getInjectionPlaces(), new InjectionPlace(compiler.compileElementPattern(getPatternStringForJavaPlace(method, i)), true)); final InjectionPlace place = index > -1 ? injection.getInjectionPlaces()[index] : null; methodInfo.getParamFlags()[i] = place != null && place.isEnabled() || includeAllPlaces; add = true; } } if (add) { infos.add(methodInfo); } } } } // else { // todo tbd //for (InjectionPlace place : injection.getInjectionPlaces()) { // final Matcher matcher = pattern.matcher(place.getText()); // if (matcher.matches()) { // // } //} // } result.setMethodInfos(infos); result.generatePlaces(); return result; }
createFrom
24,123
String (final PsiMethod method, final int parameterIndex) { final PsiClass psiClass = method.getContainingClass(); final String className = psiClass == null ? "" : StringUtil.notNullize(psiClass.getQualifiedName()); final String signature = createMethodInfo(method).getMethodSignature(); return MethodParameterInjection.getPatternStringForJavaPlace(method.getName(), getParameterTypesString(signature), parameterIndex, className); }
getPatternStringForJavaPlace
24,124
AnAction[] (final Project project, final Consumer<? super BaseInjection> consumer) { return new AnAction[] { new AnAction(IntelliLangBundle.message("java.parameter"), null, IconManager.getInstance().getPlatformIcon(com.intellij.ui.PlatformIcons.Parameter)) { @Override public void actionPerformed(@NotNull final AnActionEvent e) { final BaseInjection injection = showInjectionUI(project, new MethodParameterInjection()); if (injection != null) consumer.consume(injection); } } }; }
createAddActions
24,125
void (@NotNull final AnActionEvent e) { final BaseInjection injection = showInjectionUI(project, new MethodParameterInjection()); if (injection != null) consumer.consume(injection); }
actionPerformed
24,126
AnAction (final Project project, final Factory<? extends BaseInjection> producer) { return new AnAction() { @Override public void actionPerformed(@NotNull final AnActionEvent e) { final BaseInjection originalInjection = producer.create(); final MethodParameterInjection injection = createFrom(project, originalInjection, null, false); final boolean mergeEnabled = !project.isInitialized() || JavaPsiFacade.getInstance(project).findClass(injection.getClassName(), GlobalSearchScope.allScope(project)) == null; final BaseInjection newInjection = showInjectionUI(project, injection); if (newInjection != null) { newInjection.mergeOriginalPlacesFrom(originalInjection, mergeEnabled); originalInjection.copyFrom(newInjection); } } }; }
createEditAction
24,127
void (@NotNull final AnActionEvent e) { final BaseInjection originalInjection = producer.create(); final MethodParameterInjection injection = createFrom(project, originalInjection, null, false); final boolean mergeEnabled = !project.isInitialized() || JavaPsiFacade.getInstance(project).findClass(injection.getClassName(), GlobalSearchScope.allScope(project)) == null; final BaseInjection newInjection = showInjectionUI(project, injection); if (newInjection != null) { newInjection.mergeOriginalPlacesFrom(originalInjection, mergeEnabled); originalInjection.copyFrom(newInjection); } }
actionPerformed
24,128
void (final BaseInjection injection, final SimpleColoredText presentation, final boolean isSelected) { final Matcher matcher = ourPresentationPattern.matcher(injection.getDisplayName()); if (matcher.matches()) { presentation.append(matcher.group(1), SimpleTextAttributes.REGULAR_ATTRIBUTES); presentation.append(matcher.group(2), isSelected ? SimpleTextAttributes.REGULAR_ATTRIBUTES : SimpleTextAttributes.GRAYED_ATTRIBUTES); } else { super.setupPresentation(injection, presentation, isSelected); } }
setupPresentation
24,129
String () { return "reference.settings.injection.language.injection.settings.java.parameter"; }
getHelpId
24,130
void (@NotNull PsiReferenceRegistrar registrar) { final Configuration configuration = Configuration.getInstance(); registerUastReferenceProvider(registrar, injectionHostUExpression().annotationParam(StandardPatterns.string().with( new PatternCondition<>( "isLanguageAnnotation") { @Override public boolean accepts(@NotNull final String s, final ProcessingContext context) { return Objects.equals(configuration.getAdvancedConfiguration().getLanguageAnnotationClass(), s); } }), "value"), new UastInjectionHostReferenceProvider() { @Override public boolean acceptsTarget(@NotNull PsiElement target) { return false; } @Override public PsiReference @NotNull [] getReferencesForInjectionHost(@NotNull UExpression uExpression, @NotNull PsiLanguageInjectionHost host, @NotNull ProcessingContext context) { return new PsiReference[]{new ULiteralLanguageReference(uExpression, host)}; } }, PsiReferenceRegistrar.DEFAULT_PRIORITY); registrar.registerReferenceProvider(literalExpression().with(new PatternCondition<>("isStringLiteral") { @Override public boolean accepts(@NotNull final PsiLiteralExpression expression, final ProcessingContext context) { return PsiUtilEx.isStringOrCharacterLiteral(expression); } }), new PsiReferenceProvider() { @Override public boolean acceptsTarget(@NotNull PsiElement target) { return target instanceof PsiLiteral; } @Override public PsiReference @NotNull [] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext context) { final PsiLiteralExpression expression = (PsiLiteralExpression)psiElement; final PsiModifierListOwner owner = AnnotationUtilEx.getAnnotatedElementFor(expression, AnnotationUtilEx.LookupType.PREFER_DECLARATION); if (owner != null && PsiUtilEx.isLanguageAnnotationTarget(owner)) { final PsiAnnotation[] annotations = AnnotationUtilEx.getAnnotationFrom(owner, configuration.getAdvancedConfiguration().getPatternAnnotationPair(), true); if (annotations.length > 0) { final String pattern = AnnotationUtilEx.calcAnnotationValue(annotations, "value"); if (pattern != null) { return new PsiReference[]{new RegExpEnumReference(expression, pattern)}; } } } return PsiReference.EMPTY_ARRAY; } }); }
registerReferenceProviders
24,131
boolean (@NotNull final String s, final ProcessingContext context) { return Objects.equals(configuration.getAdvancedConfiguration().getLanguageAnnotationClass(), s); }
accepts
24,132
boolean (@NotNull PsiElement target) { return false; }
acceptsTarget
24,133
boolean (@NotNull final PsiLiteralExpression expression, final ProcessingContext context) { return PsiUtilEx.isStringOrCharacterLiteral(expression); }
accepts
24,134
boolean (@NotNull PsiElement target) { return target instanceof PsiLiteral; }
acceptsTarget
24,135
boolean () { return true; }
isSoft
24,136
PsiElement () { final Set<String> values = getEnumValues(); return values != null ? values.contains(getValue()) ? myValue : null : null; }
resolve
24,137
Set<String> () { return RegExpUtil.getEnumValues(myValue.getProject(), myPattern); }
getEnumValues
24,138
Set<String> (String annotationClassName) { GlobalSearchScope allScope = GlobalSearchScope.allScope(myProject); // todo use allScope once Kotlin support becomes fast enough (https://youtrack.jetbrains.com/issue/KT-13734) GlobalSearchScope usageScope = GlobalSearchScope.getScopeRestrictedByFileTypes(allScope, JavaFileType.INSTANCE); Set<String> result = new HashSet<>(); List<PsiClass> annoClasses = new ArrayList<>(List.of(JavaPsiFacade.getInstance(myProject).findClasses(annotationClassName, allScope))); for (int cursor = 0; cursor < annoClasses.size(); cursor++) { Parameters parameters = new Parameters(annoClasses.get(cursor), usageScope, true, PsiClass.class, PsiParameter.class, PsiMethod.class, PsiRecordComponent.class); AnnotatedElementsSearch.searchElements(parameters).forEach(element -> { if (element instanceof PsiParameter psiParameter) { final PsiElement scope = psiParameter.getDeclarationScope(); if (scope instanceof PsiMethod psiMethod) { ContainerUtil.addIfNotNull(result, psiMethod.getName()); } } else if (element instanceof PsiClass psiClass && psiClass.isAnnotationType() && !annoClasses.contains(psiClass)) { annoClasses.add(psiClass); } else if (element instanceof PsiMethod psiMethod) { ContainerUtil.addIfNotNull(result, psiMethod.getName()); } else if (element instanceof PsiRecordComponent psiRecordComponent) { final PsiClass psiClass = psiRecordComponent.getContainingClass(); if (psiClass != null) { ContainerUtil.addIfNotNull(result, psiClass.getName()); } } return true; }); } return result; }
collectMethodNamesWithLanguage
24,139
InjectionCache (Project project) { return project.getService(InjectionCache.class); }
getInstance
24,140
Set<String> () { return myAnnoIndex.getValue(); }
getAnnoIndex
24,141
Collection<String> () { return myXmlIndex.getValue(); }
getXmlIndex
24,142
void (@NotNull MultiHostRegistrar registrar, PsiElement @NotNull ... operands) { if (operands.length == 0) return; boolean hasLiteral = false; InjectedLanguage tempInjectedLanguage = null; PsiFile containingFile = null; TemporaryPlacesRegistry temporaryPlaceRegistry = TemporaryPlacesRegistry.getInstance(myProject); for (PsiElement operand : operands) { if (PsiUtilEx.isStringOrCharacterLiteral(operand)) { hasLiteral = true; if (containingFile == null) { containingFile = operands[0].getContainingFile(); } tempInjectedLanguage = temporaryPlaceRegistry.getLanguageFor((PsiLanguageInjectionHost)operand, containingFile); if (tempInjectedLanguage != null) break; } } if (!hasLiteral) return; processOperandsInjection(registrar, containingFile, tempInjectedLanguage, operands); }
getLanguagesToInject
24,143
void (@NotNull MultiHostRegistrar registrar, @NotNull PsiFile containingFile, @Nullable InjectedLanguage tempInjectedLanguage, PsiElement @NotNull [] operands) { Language tempLanguage = tempInjectedLanguage == null ? null : tempInjectedLanguage.getLanguage(); LanguageInjectionSupport injectionSupport = tempLanguage == null ? InjectorUtils.findNotNullInjectionSupport(JavaLanguageInjectionSupport.JAVA_SUPPORT_ID) : TemporaryPlacesRegistry.getInstance(myProject).getLanguageInjectionSupport(); InjectionProcessor injectionProcessor = new InjectionProcessor(Configuration.getProjectInstance(myProject), injectionSupport, operands) { @Override protected Pair<PsiLanguageInjectionHost, Language> processInjection(Language language, List<InjectionInfo> list, boolean settingsAvailable, boolean unparsable) { InjectorUtils.registerInjection(language, containingFile, list, registrar); InjectorUtils.registerSupport(getLanguageInjectionSupport(), settingsAvailable, list.get(0).host(), language); PsiLanguageInjectionHost host = list.get(0).host(); if (tempLanguage != null) { InjectorUtils .putInjectedFileUserData(host, language, LanguageInjectionSupport.TEMPORARY_INJECTED_LANGUAGE, tempInjectedLanguage); } InjectorUtils .putInjectedFileUserData(host, language, InjectedLanguageUtil.FRANKENSTEIN_INJECTION, unparsable ? Boolean.TRUE : null); return Pair.create(host, language); } @Override protected boolean areThereInjectionsWithName(String methodName, boolean annoOnly) { if (methodName == null) return false; if (getAnnotatedElementsValue().contains(methodName)) { return true; } return !annoOnly && getXmlAnnotatedElementsValue().contains(methodName); } }; if (tempLanguage != null) { BaseInjection baseInjection = new BaseInjection(JavaLanguageInjectionSupport.JAVA_SUPPORT_ID); baseInjection.setInjectedLanguageId(tempInjectedLanguage.getID()); List<Pair<PsiLanguageInjectionHost, Language>> list = injectionProcessor.processInjectionWithContext(baseInjection, false); for (Pair<PsiLanguageInjectionHost, Language> pair : list) { PsiLanguageInjectionHost host = pair.getFirst(); Language language = pair.getSecond(); InjectorUtils.putInjectedFileUserData(host, language, LanguageInjectionSupport.TEMPORARY_INJECTED_LANGUAGE, tempInjectedLanguage); } } else { injectionProcessor.processInjections(); } }
processOperandsInjection
24,144
boolean (String methodName, boolean annoOnly) { if (methodName == null) return false; if (getAnnotatedElementsValue().contains(methodName)) { return true; } return !annoOnly && getXmlAnnotatedElementsValue().contains(methodName); }
areThereInjectionsWithName
24,145
void () { PsiElement firstOperand = myOperands[0]; PsiElement topBlock = PsiUtil.getTopLevelEnclosingCodeBlock(firstOperand, null); LocalSearchScope searchScope = new LocalSearchScope(new PsiElement[]{topBlock instanceof PsiCodeBlock ? topBlock : firstOperand.getContainingFile()}, "", true); List<PsiElement> places = new ArrayList<>(5); places.add(firstOperand); Set<PsiModifierListOwner> visitedVars = new HashSet<>(); class MyAnnoVisitor implements AnnotationUtilEx.AnnotatedElementVisitor { @Override public boolean visitMethodParameter(@NotNull PsiExpression expression, @NotNull PsiCall psiCallExpression) { PsiExpressionList list = psiCallExpression.getArgumentList(); assert list != null; int index = ArrayUtil.indexOf(list.getExpressions(), expression); String methodName; if (psiCallExpression instanceof PsiMethodCallExpression) { String referenceName = ((PsiMethodCallExpression)psiCallExpression).getMethodExpression().getReferenceName(); if ("super".equals(referenceName) || "this".equals(referenceName)) { // constructor call PsiClass psiClass = PsiTreeUtil.getParentOfType(psiCallExpression, PsiClass.class, true); PsiClass psiTargetClass = "super".equals(referenceName)? psiClass == null ? null : psiClass.getSuperClass() : psiClass; methodName = psiTargetClass == null? null : psiTargetClass.getName(); } else { methodName = referenceName; } } else if (psiCallExpression instanceof PsiNewExpression) { PsiJavaCodeReferenceElement classRef = ((PsiNewExpression)psiCallExpression).getClassOrAnonymousClassReference(); methodName = classRef == null ? null : classRef.getReferenceName(); } else if (psiCallExpression instanceof PsiEnumConstant) { PsiMethod method = psiCallExpression.resolveMethod(); methodName = method != null ? method.getName() : null; } else { methodName = null; } if (methodName != null && index >= 0 && areThereInjectionsWithName(methodName, false)) { PsiMethod method = psiCallExpression.resolveMethod(); if (method != null) { PsiParameter[] parameters = method.getParameterList().getParameters(); if (index < parameters.length) { process(parameters[index], method, index); } else if (method.isVarArgs()) { process(parameters[parameters.length - 1], method, parameters.length - 1); } } } return false; } @Override public boolean visitMethodReturnStatement(@NotNull PsiElement source, @NotNull PsiMethod method) { if (areThereInjectionsWithName(method.getName(), false)) { process(method, method, -1); } return false; } private void visitVariableUsages(PsiVariable variable) { if (variable == null) return; if (myConfiguration.getAdvancedConfiguration().getDfaOption() != Configuration.DfaOption.OFF) { ReferencesSearch.search(variable, searchScope).forEach(psiReference -> { PsiElement element = psiReference.getElement(); if (element instanceof PsiExpression refExpression) { places.add(refExpression); if (!myUnparsable) { myUnparsable = checkUnparsableReference(refExpression); } } return true; }); } } @Override public boolean visitVariable(@NotNull PsiVariable variable) { if (!visitedVars.add(variable)) return false; visitVariableUsages(variable); PsiElement anchor = !(variable.getFirstChild() instanceof PsiComment) ? variable : variable.getModifierList() != null ? variable.getModifierList() : variable.getTypeElement(); if (anchor != null && !processCommentInjection(anchor)) { myShouldStop = true; } else { process(variable, null, -1); } return false; } @Override public boolean visitAnnotationParameter(@NotNull PsiNameValuePair nameValuePair, @NotNull PsiAnnotation psiAnnotation) { String paramName = nameValuePair.getName(); String methodName = paramName != null ? paramName : PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME; if (areThereInjectionsWithName(methodName, false)) { PsiReference reference = nameValuePair.getReference(); PsiElement element = reference == null ? null : reference.resolve(); if (element instanceof PsiMethod) { process((PsiMethod)element, (PsiMethod)element, -1); } } return false; } @Override public boolean visitReference(@NotNull PsiReferenceExpression expression) { if (myConfiguration.getAdvancedConfiguration().getDfaOption() == Configuration.DfaOption.OFF) return true; PsiElement e = expression.resolve(); if (e instanceof PsiVariable) { if (e instanceof PsiParameter p) { PsiElement declarationScope = p.getDeclarationScope(); PsiMethod method = declarationScope instanceof PsiMethod ? (PsiMethod)declarationScope : null; PsiParameterList parameterList = method == null ? null : method.getParameterList(); // don't check catchblock parameters & etc. if (!(parameterList == null || parameterList != e.getParent()) && areThereInjectionsWithName(method.getName(), false)) { int parameterIndex = parameterList.getParameterIndex((PsiParameter)e); process((PsiModifierListOwner)e, method, parameterIndex); } } visitVariable((PsiVariable)e); } return !myShouldStop; } private boolean processCommentInjection(@NotNull PsiElement anchor) { Ref<PsiElement> causeRef = Ref.create(); BaseInjection injection = mySupport.findCommentInjection(anchor, causeRef); if (injection != null) { PsiVariable variable = PsiTreeUtil.getParentOfType(anchor, PsiVariable.class); visitVariableUsages(variable); return processCommentInjectionInner(causeRef.get(), injection); } return true; } } MyAnnoVisitor visitor = new MyAnnoVisitor(); if (!visitor.processCommentInjection(firstOperand)) { return; } while (!places.isEmpty() && !myShouldStop) { PsiElement curPlace = places.remove(0); AnnotationUtilEx.visitAnnotatedElements(curPlace, visitor); } }
processInjections
24,146
boolean (@NotNull PsiExpression expression, @NotNull PsiCall psiCallExpression) { PsiExpressionList list = psiCallExpression.getArgumentList(); assert list != null; int index = ArrayUtil.indexOf(list.getExpressions(), expression); String methodName; if (psiCallExpression instanceof PsiMethodCallExpression) { String referenceName = ((PsiMethodCallExpression)psiCallExpression).getMethodExpression().getReferenceName(); if ("super".equals(referenceName) || "this".equals(referenceName)) { // constructor call PsiClass psiClass = PsiTreeUtil.getParentOfType(psiCallExpression, PsiClass.class, true); PsiClass psiTargetClass = "super".equals(referenceName)? psiClass == null ? null : psiClass.getSuperClass() : psiClass; methodName = psiTargetClass == null? null : psiTargetClass.getName(); } else { methodName = referenceName; } } else if (psiCallExpression instanceof PsiNewExpression) { PsiJavaCodeReferenceElement classRef = ((PsiNewExpression)psiCallExpression).getClassOrAnonymousClassReference(); methodName = classRef == null ? null : classRef.getReferenceName(); } else if (psiCallExpression instanceof PsiEnumConstant) { PsiMethod method = psiCallExpression.resolveMethod(); methodName = method != null ? method.getName() : null; } else { methodName = null; } if (methodName != null && index >= 0 && areThereInjectionsWithName(methodName, false)) { PsiMethod method = psiCallExpression.resolveMethod(); if (method != null) { PsiParameter[] parameters = method.getParameterList().getParameters(); if (index < parameters.length) { process(parameters[index], method, index); } else if (method.isVarArgs()) { process(parameters[parameters.length - 1], method, parameters.length - 1); } } } return false; }
visitMethodParameter
24,147
boolean (@NotNull PsiElement source, @NotNull PsiMethod method) { if (areThereInjectionsWithName(method.getName(), false)) { process(method, method, -1); } return false; }
visitMethodReturnStatement
24,148
void (PsiVariable variable) { if (variable == null) return; if (myConfiguration.getAdvancedConfiguration().getDfaOption() != Configuration.DfaOption.OFF) { ReferencesSearch.search(variable, searchScope).forEach(psiReference -> { PsiElement element = psiReference.getElement(); if (element instanceof PsiExpression refExpression) { places.add(refExpression); if (!myUnparsable) { myUnparsable = checkUnparsableReference(refExpression); } } return true; }); } }
visitVariableUsages
24,149
boolean (@NotNull PsiVariable variable) { if (!visitedVars.add(variable)) return false; visitVariableUsages(variable); PsiElement anchor = !(variable.getFirstChild() instanceof PsiComment) ? variable : variable.getModifierList() != null ? variable.getModifierList() : variable.getTypeElement(); if (anchor != null && !processCommentInjection(anchor)) { myShouldStop = true; } else { process(variable, null, -1); } return false; }
visitVariable
24,150
boolean (@NotNull PsiNameValuePair nameValuePair, @NotNull PsiAnnotation psiAnnotation) { String paramName = nameValuePair.getName(); String methodName = paramName != null ? paramName : PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME; if (areThereInjectionsWithName(methodName, false)) { PsiReference reference = nameValuePair.getReference(); PsiElement element = reference == null ? null : reference.resolve(); if (element instanceof PsiMethod) { process((PsiMethod)element, (PsiMethod)element, -1); } } return false; }
visitAnnotationParameter
24,151
boolean (@NotNull PsiReferenceExpression expression) { if (myConfiguration.getAdvancedConfiguration().getDfaOption() == Configuration.DfaOption.OFF) return true; PsiElement e = expression.resolve(); if (e instanceof PsiVariable) { if (e instanceof PsiParameter p) { PsiElement declarationScope = p.getDeclarationScope(); PsiMethod method = declarationScope instanceof PsiMethod ? (PsiMethod)declarationScope : null; PsiParameterList parameterList = method == null ? null : method.getParameterList(); // don't check catchblock parameters & etc. if (!(parameterList == null || parameterList != e.getParent()) && areThereInjectionsWithName(method.getName(), false)) { int parameterIndex = parameterList.getParameterIndex((PsiParameter)e); process((PsiModifierListOwner)e, method, parameterIndex); } } visitVariable((PsiVariable)e); } return !myShouldStop; }
visitReference
24,152
boolean (@NotNull PsiElement anchor) { Ref<PsiElement> causeRef = Ref.create(); BaseInjection injection = mySupport.findCommentInjection(anchor, causeRef); if (injection != null) { PsiVariable variable = PsiTreeUtil.getParentOfType(anchor, PsiVariable.class); visitVariableUsages(variable); return processCommentInjectionInner(causeRef.get(), injection); } return true; }
processCommentInjection
24,153
boolean (PsiElement comment, BaseInjection injection) { processInjectionWithContext(injection, false); return false; }
processCommentInjectionInner
24,154
void (PsiModifierListOwner owner, PsiMethod method, int paramIndex) { if (!processAnnotationInjections(owner)) { myShouldStop = true; } for (BaseInjection injection : myConfiguration.getInjections(JavaLanguageInjectionSupport.JAVA_SUPPORT_ID)) { if (injection.acceptsPsiElement(owner)) { if (!processXmlInjections(injection, owner, method, paramIndex)) { myShouldStop = true; break; } } } }
process
24,155
boolean (PsiModifierListOwner annoElement) { if (annoElement instanceof PsiParameter) { PsiElement scope = ((PsiParameter)annoElement).getDeclarationScope(); if (scope instanceof PsiMethod && !areThereInjectionsWithName(((PsiNamedElement)scope).getName(), true)) { return true; } } PsiAnnotation[] annotations = AnnotationUtilEx.getAnnotationFrom(annoElement, myConfiguration.getAdvancedConfiguration().getLanguageAnnotationPair(), true); if (annotations.length > 0) { return processAnnotationInjectionInner(annoElement, annotations); } return true; }
processAnnotationInjections
24,156
boolean (PsiModifierListOwner owner, PsiAnnotation[] annotations) { String id = AnnotationUtilEx.calcAnnotationValue(annotations, "value"); String prefix = AnnotationUtilEx.calcAnnotationValue(annotations, "prefix"); String suffix = AnnotationUtilEx.calcAnnotationValue(annotations, "suffix"); BaseInjection injection = new BaseInjection(JavaLanguageInjectionSupport.JAVA_SUPPORT_ID); if (prefix != null) injection.setPrefix(prefix); if (suffix != null) injection.setSuffix(suffix); if (id != null) injection.setInjectedLanguageId(id); processInjectionWithContext(injection, false); return false; }
processAnnotationInjectionInner
24,157
boolean (BaseInjection injection, PsiModifierListOwner owner, PsiMethod method, int paramIndex) { processInjectionWithContext(injection, true); return !injection.isTerminal(); }
processXmlInjections
24,158
List<TextRange> (PsiLanguageInjectionHost host) { if (!(host instanceof PsiLiteralExpression literalExpression)) { return null; } if (!literalExpression.isTextBlock()) { return null; } final TextRange textRange = ElementManipulators.getValueTextRange(host); final int indent = PsiLiteralUtil.getTextBlockIndent(literalExpression); if (indent <= 0) { return Collections.singletonList(textRange); } final String text = literalExpression.getText(); int startOffset = textRange.getStartOffset() + indent; int endOffset = text.indexOf('\n', startOffset); final List<TextRange> result = new SmartList<>(); while (endOffset > 0) { endOffset++; result.add(new TextRange(startOffset, endOffset)); startOffset = endOffset + indent; endOffset = text.indexOf('\n', startOffset); } endOffset = textRange.getEndOffset(); if (startOffset <= endOffset) { result.add(new TextRange(startOffset, endOffset)); } return result; }
getTextBlockInjectedArea
24,159
boolean (Language language) { return LanguageParserDefinitions.INSTANCE.forLanguage(language) == null && ReferenceInjector.findById(language.getID()) != null; }
isReferenceInject
24,160
boolean (String methodName, boolean annoOnly) { return true; }
areThereInjectionsWithName
24,161
LanguageInjectionSupport () { return mySupport; }
getLanguageInjectionSupport
24,162
boolean (PsiExpression refExpression) { PsiElement parent = refExpression.getParent(); if (parent instanceof PsiAssignmentExpression assignmentExpression) { IElementType operation = assignmentExpression.getOperationTokenType(); if (assignmentExpression.getLExpression() == refExpression && JavaTokenType.PLUSEQ.equals(operation)) { return true; } } else if (parent instanceof PsiPolyadicExpression || parent instanceof PsiParenthesizedExpression || parent instanceof PsiConditionalExpression) { return true; } return false; }
checkUnparsableReference
24,163
Collection<String> () { // note: external annotations not supported return InjectionCache.getInstance(myProject).getAnnoIndex(); }
getAnnotatedElementsValue
24,164
Collection<String> () { return InjectionCache.getInstance(myProject).getXmlIndex(); }
getXmlAnnotatedElementsValue
24,165
String (Project project) { return Configuration.getProjectInstance(project).getAdvancedConfiguration().getLanguageAnnotationClass(); }
getAnnotationName
24,166
boolean (PsiType type) { return type == null || !PsiUtilEx.isStringOrStringArray(type); }
isTypeApplicable
24,167
String () { return IntelliLangBundle.message("inspection.message.language.injection.only.applicable.to.elements.type.string"); }
getDescriptionTemplate
24,168
PsiElementVisitor (@NotNull final ProblemsHolder holder, boolean isOnTheFly) { return new JavaElementVisitor() { final String annotationName = Configuration.getProjectInstance(holder.getProject()).getAdvancedConfiguration().getLanguageAnnotationClass(); @Override public void visitNameValuePair(@NotNull PsiNameValuePair valuePair) { final PsiAnnotation annotation = PsiTreeUtil.getParentOfType(valuePair, PsiAnnotation.class); if (annotation != null) { final String qualifiedName = annotation.getQualifiedName(); if (annotationName.equals(qualifiedName)) { final String name = valuePair.getName(); if (name == null || "value".equals(name)) { final PsiAnnotationMemberValue value = valuePair.getValue(); if (value instanceof PsiExpression expression) { final Object id = JavaPsiFacade.getInstance(expression.getProject()). getConstantEvaluationHelper().computeConstantExpression(expression); if (id instanceof String) { Language language = InjectorUtils.getLanguageByString((String)id); if (language == null) { holder.registerProblem(expression, IntelliLangBundle.message("inspection.unknown.language.ID.description", id), ProblemHighlightType.LIKE_UNKNOWN_SYMBOL); } } } } } } } }; }
buildVisitor
24,169
void (@NotNull PsiNameValuePair valuePair) { final PsiAnnotation annotation = PsiTreeUtil.getParentOfType(valuePair, PsiAnnotation.class); if (annotation != null) { final String qualifiedName = annotation.getQualifiedName(); if (annotationName.equals(qualifiedName)) { final String name = valuePair.getName(); if (name == null || "value".equals(name)) { final PsiAnnotationMemberValue value = valuePair.getValue(); if (value instanceof PsiExpression expression) { final Object id = JavaPsiFacade.getInstance(expression.getProject()). getConstantEvaluationHelper().computeConstantExpression(expression); if (id instanceof String) { Language language = InjectorUtils.getLanguageByString((String)id); if (language == null) { holder.registerProblem(expression, IntelliLangBundle.message("inspection.unknown.language.ID.description", id), ProblemHighlightType.LIKE_UNKNOWN_SYMBOL); } } } } } } }
visitNameValuePair
24,170
OptPane () { return pane( checkbox("CHECK_NON_ANNOTATED_REFERENCES", IntelliLangBundle.message("flag.usages.of.non.annotated.elements")) .description(HtmlChunk.text(IntelliLangBundle.message("flag.usages.of.non.annotated.elements.description"))) ); }
getOptionsPane
24,171
PsiElementVisitor (@NotNull final ProblemsHolder holder, boolean isOnTheFly) { return new JavaElementVisitor() { final Pair<String, ? extends Set<String>> annotationName = Configuration.getProjectInstance(holder.getProject()).getAdvancedConfiguration().getLanguageAnnotationPair(); @Override public void visitExpression(@NotNull PsiExpression expression) { checkExpression(expression, holder, annotationName); } @Override public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) { if (expression.getParent() instanceof PsiMethodCallExpression) return; final PsiElement element = expression.resolve(); if (!(element instanceof PsiModifierListOwner)) { return; } checkExpression(expression, holder, annotationName); } }; }
buildVisitor
24,172
void (@NotNull PsiExpression expression) { checkExpression(expression, holder, annotationName); }
visitExpression
24,173
void (@NotNull PsiReferenceExpression expression) { if (expression.getParent() instanceof PsiMethodCallExpression) return; final PsiElement element = expression.resolve(); if (!(element instanceof PsiModifierListOwner)) { return; } checkExpression(expression, holder, annotationName); }
visitReferenceExpression
24,174
String () { return myClassName; }
getClassName
24,175
void (@NotNull String className) { myClassName = className; }
setClassName
24,176
void (final Collection<? extends MethodInfo> newInfos) { myParameterMap.clear(); for (MethodInfo methodInfo : newInfos) { myParameterMap.put(methodInfo.getMethodSignature(), methodInfo); } }
setMethodInfos
24,177
Collection<MethodInfo> () { return myParameterMap.values(); }
getMethodInfos
24,178
MethodParameterInjection (@NotNull BaseInjection o) { super.copyFrom(o); if (o instanceof MethodParameterInjection other) { myClassName = other.getClassName(); myParameterMap.clear(); for (MethodInfo info : other.myParameterMap.values()) { myParameterMap.put(info.methodSignature, info.copy()); } } return this; }
copyFrom
24,179
void (Element e) { if (e.getAttribute("injector-id") == null) { setClassName(JDOMExternalizer.readString(e, "CLASS")); //setApplyInHierarchy(JDOMExternalizer.readBoolean(e, "APPLY_IN_HIERARCHY")); readOldFormat(e); final Map<String, String> map = new HashMap<>(); JDOMExternalizer.readMap(e, map, null, "SIGNATURES"); for (String s : map.keySet()) { final String fixedSignature = fixSignature(s, false); myParameterMap.put(fixedSignature, new MethodInfo(fixedSignature, map.get(s))); } } }
readExternalImpl
24,180
void (final Element e) { final JDOMExternalizableStringList list = new JDOMExternalizableStringList(); try { list.readExternal(e); } catch (IllegalDataException ignored) { } if (list.isEmpty()) return; final boolean[] selection = new boolean[list.size()]; for (int i = 0; i < list.size(); i++) { selection[i] = Boolean.parseBoolean(list.get(i)); } final String methodSignature = fixSignature(JDOMExternalizer.readString(e, "METHOD"), false); myParameterMap.put(methodSignature, new MethodInfo(methodSignature, selection, false)); }
readOldFormat
24,181
MethodParameterInjection () { return new MethodParameterInjection().copyFrom(this); }
copy
24,182
void () { final PatternCompiler<PsiElement> compiler = getCompiler(); List<String> patternString = getPatternString(this); InjectionPlace[] places = InjectionPlace.ARRAY_FACTORY.create(patternString.size()); for (int i = 0, patternStringSize = patternString.size(); i < patternStringSize; i++) { String text = patternString.get(i); places[i] = new InjectionPlace(compiler.createElementPattern(text, getDisplayName()), true); } setInjectionPlaces(places); }
generatePlaces
24,183
boolean (Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; final MethodParameterInjection that = (MethodParameterInjection)o; if (!myClassName.equals(that.myClassName)) return false; if (!myParameterMap.equals(that.myParameterMap)) return false; return true; }
equals
24,184
int () { int result = super.hashCode(); result = 31 * result + myClassName.hashCode(); result = 31 * result + myParameterMap.hashCode(); return result; }
hashCode
24,185
String () { final String className = getClassName(); if (StringUtil.isEmpty(className)) return IntelliLangBundle.message("method.param.injection.unnamed.placeholder"); MethodInfo singleInfo = null; for (MethodInfo info : myParameterMap.values()) { if (info.isEnabled()) { if (singleInfo == null) { singleInfo = info; } else { singleInfo = null; break; } } } final String name = singleInfo != null ? StringUtil.getShortName(className) + "." + singleInfo.methodName : StringUtil.getShortName(className); return /*"["+getInjectedLanguageId()+"] " +*/ name + " ("+StringUtil.getPackageName(className)+")"; }
getDisplayName
24,186
String (final String signature, final boolean parameterNames) { @NonNls final StringBuilder sb = new StringBuilder(); final StringTokenizer st = new StringTokenizer(signature, "(,)"); for (int i = 0; st.hasMoreTokens(); i++) { final String token = st.nextToken().trim(); if (i > 1) sb.append(", "); final int idx; if (i == 0) { sb.append(token).append("("); } else if ((idx = token.indexOf(' ')) > -1) { if (parameterNames) { sb.append(token); } else { sb.append(token, 0, idx); } } else { sb.append(token); if (parameterNames) { sb.append(' ').append('p').append(i); } } } sb.append(")"); return sb.toString(); }
fixSignature
24,187
String (@NotNull PsiMethod method) { return PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS, PsiFormatUtil.SHOW_TYPE | PsiFormatUtil.SHOW_FQ_CLASS_NAMES | PsiFormatUtil.SHOW_RAW_TYPE); }
buildSignature
24,188
MethodInfo (final PsiMethod method) { final String signature = buildSignature(method); return new MethodInfo(signature, new boolean[method.getParameterList().getParametersCount()], false); }
createMethodInfo
24,189
boolean (@Nullable final PsiType type, final Project project) { if (type == null) return false; if (type instanceof PsiPrimitiveType) return false; if (project.isDefault()) { @NonNls final String text = type.getPresentableText(); return text.equals("java.lang.String") || text.equals("java.lang.String...") || text.equals("java.lang.String[]"); } else { return type.equalsToText("java.lang.String") || type.equalsToText("java.lang.String...") || type.equalsToText("java.lang.String[]"); } }
isInjectable
24,190
PsiMethod (final Project project, final String signature) { if (StringUtil.isEmpty(signature)) return null; try { return JavaPsiFacade.getInstance(project).getElementFactory(). createMethodFromText("void " + fixSignature(signature, true) + "{}", null); } catch (IncorrectOperationException e) { // something wrong } return null; }
makeMethod
24,191
String (final String signature) { @NonNls final StringBuilder sb = new StringBuilder(); final StringTokenizer st = new StringTokenizer(signature, "(,)"); for (int i = 0; st.hasMoreTokens(); i++) { final String token = st.nextToken().trim(); if (i > 1) sb.append(", "); final int idx; if (i == 0) { // nothing } else { sb.append('\"'); if ((idx = token.indexOf(' ')) > -1) { sb.append(token, 0, idx); } else { sb.append(token); } sb.append('\"'); } } return sb.toString(); }
getParameterTypesString
24,192
String (final String methodName, final String parametersStrings, final int parameterIndex, final String className) { final StringBuilder sb = new StringBuilder(); if (parameterIndex >= 0) { sb.append("psiParameter().ofMethod(").append(parameterIndex).append(", "); } sb.append("psiMethod().withName(\"").append(methodName) .append("\").withParameters(").append(parametersStrings) .append(").definedInClass(\"").append(className).append("\")"); if (parameterIndex >= 0) { sb.append(")"); } return sb.toString(); }
getPatternStringForJavaPlace
24,193
String () { return methodSignature; }
getMethodSignature
24,194
String () { return methodName; }
getMethodName
24,195
boolean () { return returnFlag; }
isReturnFlag
24,196
void (final boolean returnFlag) { this.returnFlag = returnFlag; }
setReturnFlag
24,197
boolean () { if (returnFlag) return true; for (boolean b : paramFlags) { if (b) return true; } return false; }
isEnabled
24,198
String (final String methodSignature) { final String s = StringUtil.split(methodSignature, "(").get(0); return s.length() == 0 ? "<none>" : s; }
calcMethodName
24,199
String () { final StringBuilder result = new StringBuilder(); result.append(returnFlag).append(':'); boolean first = true; for (boolean b : paramFlags) { if (first) first = false; else result.append(','); result.append(b); } return result.toString(); }
getFlagsString