Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
24,200
MethodInfo () { return new MethodInfo(methodSignature, paramFlags.clone(), returnFlag); }
copy
24,201
boolean (final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final MethodInfo that = (MethodInfo)o; if (returnFlag != that.returnFlag) return false; if (!methodName.equals(that.methodName)) return false; if (!methodSignature.equals(that.methodSignature)) return false; if (!Arrays.equals(paramFlags, that.paramFlags)) return false; return true; }
equals
24,202
int () { int result; result = methodSignature.hashCode(); result = 31 * result + methodName.hashCode(); result = 31 * result + Arrays.hashCode(paramFlags); result = 31 * result + (returnFlag ? 1 : 0); return result; }
hashCode
24,203
List<String> (final MethodParameterInjection injection) { final ArrayList<String> list = new ArrayList<>(); final String className = injection.getClassName(); for (MethodParameterInjection.MethodInfo info : injection.getMethodInfos()) { final boolean[] paramFlags = info.getParamFlags(); final int paramFlagsLength = paramFlags.length; final String methodName = info.getMethodName(); final String typesString = getParameterTypesString(info.getMethodSignature()); if (info.isReturnFlag()) { list.add(getPatternStringForJavaPlace(methodName, typesString, -1, className)); } for (int i = 0; i < paramFlagsLength; i++) { if (paramFlags[i]) { list.add(getPatternStringForJavaPlace(methodName, typesString, i, className)); } } } return list; }
getPatternString
24,204
void (@NotNull final DocumentEvent e) { updateParamTree(); updateInjectionPanelTree(); }
documentChanged
24,205
void (@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { final Object o = ((DefaultMutableTreeNode)value).getUserObject(); setIcon(o instanceof PsiMethod ? IconManager.getInstance().getPlatformIcon(com.intellij.ui.PlatformIcons.Method) : o instanceof PsiParameter ? IconManager.getInstance().getPlatformIcon(com.intellij.ui.PlatformIcons.Parameter) : null); final String name; if (o instanceof PsiMethod) { name = PsiFormatUtil.formatMethod((PsiMethod)o, PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE); } else if (o instanceof PsiParameter) { name = PsiFormatUtil.formatVariable((PsiParameter)o, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE, PsiSubstitutor.EMPTY); } else name = null; final boolean missing = o instanceof PsiElement && !((PsiElement)o).isPhysical(); if (name != null) { append(name, missing? SimpleTextAttributes.ERROR_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES); } }
customizeCellRenderer
24,206
void (@NotNull final AnActionEvent e) { performToggleAction(); }
actionPerformed
24,207
void () { updateTree(); }
updateInjectionPanelTree
24,208
void () { final Collection<DefaultMutableTreeNode> selectedInjections = myParamsTable.getSelection(); boolean enabledExists = false; boolean disabledExists = false; for (DefaultMutableTreeNode node : selectedInjections) { final Boolean nodeSelected = isNodeSelected(node); if (Boolean.TRUE == nodeSelected) enabledExists = true; else if (Boolean.FALSE == nodeSelected) disabledExists = true; if (enabledExists && disabledExists) break; } boolean allEnabled = !enabledExists && disabledExists; for (DefaultMutableTreeNode node : selectedInjections) { setNodeSelected(node, allEnabled); } myParamsTable.updateUI(); }
performToggleAction
24,209
PsiType () { final Document document = myClassField.getEditorTextField().getDocument(); final PsiDocumentManager dm = PsiDocumentManager.getInstance(myProject); dm.commitDocument(document); final PsiFile psiFile = dm.getPsiFile(document); if (psiFile == null) return null; try { return ((PsiTypeCodeFragment)psiFile).getType(); } catch (PsiTypeCodeFragment.TypeSyntaxException | PsiTypeCodeFragment.NoTypeException e1) { return null; } }
getClassType
24,210
void (String name) { myClassField.setText(name); }
setPsiClass
24,211
void () { rebuildTreeModel(); refreshTreeStructure(); }
updateParamTree
24,212
void () { myData.clear(); ApplicationManager.getApplication().runReadAction(() -> { final PsiType classType = getClassType(); final PsiClass[] classes = classType instanceof PsiClassType? JavaPsiFacade.getInstance(myProject). findClasses(classType.getCanonicalText(), GlobalSearchScope.allScope(myProject)) : PsiClass.EMPTY_ARRAY; if (classes.length == 0) return; final Set<String> visitedSignatures = new HashSet<>(); 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; if (MethodParameterInjection.isInjectable(method.getReturnType(), method.getProject()) || ContainerUtil.find(method.getParameterList().getParameters(), p -> MethodParameterInjection.isInjectable(p.getType(), p.getProject())) != null) { final MethodParameterInjection.MethodInfo info = MethodParameterInjection.createMethodInfo(method); if (!visitedSignatures.add(info.getMethodSignature())) continue; myData.put(method, info); } } } }); }
rebuildTreeModel
24,213
void () { myRootNode.removeAllChildren(); final ArrayList<PsiMethod> methods = new ArrayList<>(myData.keySet()); methods.sort(Comparator.comparing(PsiMethod::getName).thenComparingInt(o -> o.getParameterList().getParametersCount())); for (PsiMethod method : methods) { final PsiParameter[] params = method.getParameterList().getParameters(); final DefaultMutableTreeNode methodNode = new DefaultMutableTreeNode(method, true); myRootNode.add(methodNode); for (final PsiParameter parameter : params) { methodNode.add(new DefaultMutableTreeNode(parameter, false)); } } final ListTreeTableModelOnColumns tableModel = (ListTreeTableModelOnColumns)myParamsTable.getTableModel(); tableModel.reload(); TreeUtil.expandAll(myParamsTable.getTree()); myParamsTable.revalidate(); }
refreshTreeStructure
24,214
String () { final PsiType type = getClassType(); if (type == null) { return myClassField.getText(); } return type.getCanonicalText(); }
getClassName
24,215
void (final MethodParameterInjection other) { final boolean applyMethods = ReadAction.compute(() -> { other.setClassName(getClassName()); return getClassType() != null; }).booleanValue(); if (applyMethods) { other.setMethodInfos(ContainerUtil.findAll(myData.values(), methodInfo -> methodInfo.isEnabled())); } }
apply
24,216
void () { setPsiClass(myOrigInjection.getClassName()); rebuildTreeModel(); final Map<String, MethodParameterInjection.MethodInfo> map = new HashMap<>(); for (PsiMethod method : myData.keySet()) { final MethodParameterInjection.MethodInfo methodInfo = myData.get(method); map.put(methodInfo.getMethodSignature(), methodInfo); } for (MethodParameterInjection.MethodInfo info : myOrigInjection.getMethodInfos()) { final MethodParameterInjection.MethodInfo curInfo = map.get(info.getMethodSignature()); if (curInfo != null) { System.arraycopy(info.getParamFlags(), 0, curInfo.getParamFlags(), 0, Math.min(info.getParamFlags().length, curInfo.getParamFlags().length)); curInfo.setReturnFlag(info.isReturnFlag()); } else { final PsiMethod missingMethod = MethodParameterInjection.makeMethod(myProject, info.getMethodSignature()); myData.put(missingMethod, info.copy()); } } refreshTreeStructure(); final Enumeration enumeration = myRootNode.children(); while (enumeration.hasMoreElements()) { PsiMethod method = (PsiMethod)((DefaultMutableTreeNode)enumeration.nextElement()).getUserObject(); assert myData.containsKey(method); } }
resetImpl
24,217
JPanel () { return myRoot; }
getComponent
24,218
void () { myLanguagePanel = new LanguagePanel(myProject, myOrigInjection); myRootNode = new DefaultMutableTreeNode(null, true); myParamsTable = new MyView(new ListTreeTableModelOnColumns(myRootNode, createColumnInfos())); myAdvancedPanel = new AdvancedPanel(myProject, myOrigInjection); }
createUIComponents
24,219
Boolean (final DefaultMutableTreeNode o) { final Object userObject = o.getUserObject(); if (userObject instanceof PsiMethod) { final PsiMethod method = (PsiMethod)userObject; return MethodParameterInjection.isInjectable(method.getReturnType(), method.getProject()) ? myData.get(method).isReturnFlag() : null; } else if (userObject instanceof PsiParameter parameter) { final PsiMethod method = getMethodByNode(o); final int index = method.getParameterList().getParameterIndex(parameter); return MethodParameterInjection.isInjectable(parameter.getType(), method.getProject()) ? myData.get(method).getParamFlags()[index] : null; } return null; }
isNodeSelected
24,220
void (final DefaultMutableTreeNode o, final boolean value) { final Object userObject = o.getUserObject(); if (userObject instanceof PsiMethod) { myData.get((PsiMethod)userObject).setReturnFlag(value); } else if (userObject instanceof PsiParameter) { final PsiMethod method = getMethodByNode(o); final int index = method.getParameterList().getParameterIndex((PsiParameter)userObject); myData.get(method).getParamFlags()[index] = value; } }
setNodeSelected
24,221
PsiMethod (final DefaultMutableTreeNode o) { final Object userObject = o.getUserObject(); if (userObject instanceof PsiMethod) return (PsiMethod)userObject; return (PsiMethod)((DefaultMutableTreeNode)o.getParent()).getUserObject(); }
getMethodByNode
24,222
ColumnInfo[] () { return new ColumnInfo[]{ new ColumnInfo<DefaultMutableTreeNode, Boolean>(" ") { // "" for the first column's name isn't a good idea final BooleanTableCellRenderer myRenderer = new BooleanTableCellRenderer(); @Override public Boolean valueOf(DefaultMutableTreeNode o) { return isNodeSelected(o); } @Override public int getWidth(JTable table) { return myRenderer.getPreferredSize().width; } @Override public TableCellEditor getEditor(DefaultMutableTreeNode o) { return new DefaultCellEditor(new JCheckBox()); } @Override public TableCellRenderer getRenderer(DefaultMutableTreeNode o) { myRenderer.setEnabled(isCellEditable(o)); return myRenderer; } @Override public void setValue(DefaultMutableTreeNode o, Boolean value) { setNodeSelected(o, Boolean.TRUE.equals(value)); } @Override public Class<Boolean> getColumnClass() { return Boolean.class; } @Override public boolean isCellEditable(DefaultMutableTreeNode o) { return valueOf(o) != null; } }, new TreeColumnInfo(" ") }; }
createColumnInfos
24,223
Boolean (DefaultMutableTreeNode o) { return isNodeSelected(o); }
valueOf
24,224
int (JTable table) { return myRenderer.getPreferredSize().width; }
getWidth
24,225
TableCellEditor (DefaultMutableTreeNode o) { return new DefaultCellEditor(new JCheckBox()); }
getEditor
24,226
TableCellRenderer (DefaultMutableTreeNode o) { myRenderer.setEnabled(isCellEditable(o)); return myRenderer; }
getRenderer
24,227
void (DefaultMutableTreeNode o, Boolean value) { setNodeSelected(o, Boolean.TRUE.equals(value)); }
setValue
24,228
Class<Boolean> () { return Boolean.class; }
getColumnClass
24,229
boolean (DefaultMutableTreeNode o) { return valueOf(o) != null; }
isCellEditable
24,230
void (ActionEvent e) { final TreeClassChooserFactory factory = TreeClassChooserFactory.getInstance(myProject); final TreeClassChooser chooser = factory.createAllProjectScopeChooser(IntelliLangBundle.message("dialog.title.select.class")); chooser.showDialog(); final PsiClass psiClass = chooser.getSelected(); if (psiClass != null) { setPsiClass(psiClass.getQualifiedName()); updateParamTree(); updateInjectionPanelTree(); } }
actionPerformed
24,231
Object (@NotNull String dataId) { if (CommonDataKeys.PSI_ELEMENT.is(dataId)) { Object userObject = TreeUtil.getUserObject(ContainerUtil.getFirstItem(getSelection())); return userObject instanceof PsiElement ? userObject : null; } return null; }
getData
24,232
String (Project project) { return Configuration.getProjectInstance(project).getAdvancedConfiguration().getPatternAnnotationClass(); }
getAnnotationName
24,233
boolean (PsiType type) { return type != null && !PsiUtilEx.isString(type); }
isTypeApplicable
24,234
String () { return IntelliLangBundle.message("inspection.message.pattern.annotation.only.applicable.to.elements.type.string"); }
getDescriptionTemplate
24,235
String () { return "PatternNotApplicable"; }
getShortName
24,236
OptPane () { return OptPane.pane( OptPane.checkbox("CHECK_NON_CONSTANT_VALUES", IntelliLangBundle.message("flag.non.compile.time.constant.expressions")) ); }
getOptionsPane
24,237
PsiElementVisitor (@NotNull final ProblemsHolder holder, boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) { visitExpression(expression); } @Override public void visitExpression(@NotNull PsiExpression expression) { final PsiElement element = expression.getParent(); if (element instanceof PsiExpressionList) { // this checks method arguments check(expression, holder, false); } else if (element instanceof PsiNameValuePair valuePair) { final String name = valuePair.getName(); if (name == null || name.equals(PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME)) { // check whether @Subst complies with pattern check(expression, holder, true); } check(expression, holder, false); } } @Override public void visitReturnStatement(@NotNull PsiReturnStatement statement) { final PsiExpression returnValue = statement.getReturnValue(); if (returnValue != null) { check(returnValue, holder, false); } } @Override public void visitVariable(@NotNull PsiVariable var) { final PsiExpression initializer = var.getInitializer(); if (initializer != null) { // variable/field initializer check(initializer, holder, false); } } @Override public void visitAssignmentExpression(@NotNull PsiAssignmentExpression expression) { final PsiExpression e = expression.getRExpression(); if (e != null) { check(e, holder, false); } visitExpression(expression); } private void check(@NotNull PsiExpression expression, ProblemsHolder holder, boolean isAnnotationValue) { if (expression instanceof PsiConditionalExpression expr) { PsiExpression e = expr.getThenExpression(); if (e != null) { check(e, holder, isAnnotationValue); } e = expr.getElseExpression(); if (e != null) { check(e, holder, isAnnotationValue); } } else { final PsiType type = expression.getType(); // optimiziation: only check expressions of type String if (type != null && PsiUtilEx.isString(type)) { final PsiModifierListOwner element; if (isAnnotationValue) { final PsiAnnotation psiAnnotation = PsiTreeUtil.getParentOfType(expression, PsiAnnotation.class); if (psiAnnotation != null && Configuration.getInstance() .getAdvancedConfiguration().getSubstAnnotationClass().equals(psiAnnotation.getQualifiedName())) { element = PsiTreeUtil.getParentOfType(expression, PsiModifierListOwner.class); } else { return; } } else { element = AnnotationUtilEx.getAnnotatedElementFor(expression, AnnotationUtilEx.LookupType.PREFER_CONTEXT); } if (element != null && PsiUtilEx.isLanguageAnnotationTarget(element)) { PsiAnnotation[] annotations = AnnotationUtilEx.getAnnotationFrom(element, Configuration.getInstance().getAdvancedConfiguration() .getPatternAnnotationPair(), true); checkExpression(expression, annotations, holder); } } } } }; }
buildVisitor
24,238
void (@NotNull PsiReferenceExpression expression) { visitExpression(expression); }
visitReferenceExpression
24,239
void (@NotNull PsiExpression expression) { final PsiElement element = expression.getParent(); if (element instanceof PsiExpressionList) { // this checks method arguments check(expression, holder, false); } else if (element instanceof PsiNameValuePair valuePair) { final String name = valuePair.getName(); if (name == null || name.equals(PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME)) { // check whether @Subst complies with pattern check(expression, holder, true); } check(expression, holder, false); } }
visitExpression
24,240
void (@NotNull PsiReturnStatement statement) { final PsiExpression returnValue = statement.getReturnValue(); if (returnValue != null) { check(returnValue, holder, false); } }
visitReturnStatement
24,241
void (@NotNull PsiVariable var) { final PsiExpression initializer = var.getInitializer(); if (initializer != null) { // variable/field initializer check(initializer, holder, false); } }
visitVariable
24,242
void (@NotNull PsiAssignmentExpression expression) { final PsiExpression e = expression.getRExpression(); if (e != null) { check(e, holder, false); } visitExpression(expression); }
visitAssignmentExpression
24,243
void (@NotNull PsiExpression expression, ProblemsHolder holder, boolean isAnnotationValue) { if (expression instanceof PsiConditionalExpression expr) { PsiExpression e = expr.getThenExpression(); if (e != null) { check(e, holder, isAnnotationValue); } e = expr.getElseExpression(); if (e != null) { check(e, holder, isAnnotationValue); } } else { final PsiType type = expression.getType(); // optimiziation: only check expressions of type String if (type != null && PsiUtilEx.isString(type)) { final PsiModifierListOwner element; if (isAnnotationValue) { final PsiAnnotation psiAnnotation = PsiTreeUtil.getParentOfType(expression, PsiAnnotation.class); if (psiAnnotation != null && Configuration.getInstance() .getAdvancedConfiguration().getSubstAnnotationClass().equals(psiAnnotation.getQualifiedName())) { element = PsiTreeUtil.getParentOfType(expression, PsiModifierListOwner.class); } else { return; } } else { element = AnnotationUtilEx.getAnnotatedElementFor(expression, AnnotationUtilEx.LookupType.PREFER_CONTEXT); } if (element != null && PsiUtilEx.isLanguageAnnotationTarget(element)) { PsiAnnotation[] annotations = AnnotationUtilEx.getAnnotationFrom(element, Configuration.getInstance().getAdvancedConfiguration() .getPatternAnnotationPair(), true); checkExpression(expression, annotations, holder); } } } }
check
24,244
void (PsiExpression expression, final PsiAnnotation[] annotations, ProblemsHolder holder) { if (annotations.length == 0) return; final PsiAnnotation psiAnnotation = annotations[0]; // cache compiled pattern with annotation CachedValue<Pattern> p = psiAnnotation.getUserData(COMPLIED_PATTERN); if (p == null) { final CachedValueProvider<Pattern> provider = () -> { final String pattern = AnnotationUtilEx.calcAnnotationValue(psiAnnotation, "value"); Pattern p1 = null; if (pattern != null) { try { p1 = Pattern.compile(pattern); } catch (PatternSyntaxException e) { // pattern stays null } } return CachedValueProvider.Result.create(p1, (Object[])annotations); }; p = CachedValuesManager.getManager(expression.getProject()).createCachedValue(provider, false); psiAnnotation.putUserData(COMPLIED_PATTERN, p); } final Pattern pattern = p.getValue(); if (pattern == null) return; List<PsiExpression> nonConstantElements = new SmartList<>(); Configuration configuration = Configuration.getInstance(); final Object result = new SubstitutedExpressionEvaluationHelper(expression.getProject()).computeExpression( expression, configuration.getAdvancedConfiguration().getDfaOption(), false, nonConstantElements); final String o = result == null ? null : String.valueOf(result); if (o != null) { if (!pattern.matcher(o).matches()) { if (annotations.length > 1) { // the last element contains the element's actual annotation final String fqn = annotations[annotations.length - 1].getQualifiedName(); assert fqn != null; final String name = StringUtil.getShortName(fqn); holder.registerProblem(expression, IntelliLangBundle.message("inspection.message.expression.does.not.match.pattern", o, name, pattern.pattern())); } else { holder.registerProblem(expression, IntelliLangBundle.message("inspection.message.expression.does.not.match.pattern2", o, pattern.pattern())); } } } else if (CHECK_NON_CONSTANT_VALUES) { for (PsiExpression expr : nonConstantElements) { final PsiElement e; if (expr instanceof PsiReferenceExpression) { e = ((PsiReferenceExpression)expr).resolve(); } else if (expr instanceof PsiMethodCallExpression) { e = ((PsiMethodCallExpression)expr).getMethodExpression().resolve(); } else { e = expr; } final PsiModifierListOwner owner = ObjectUtils.tryCast(e, PsiModifierListOwner.class); List<LocalQuickFix> fixes = new SmartList<>(); if (owner != null && PsiUtilEx.isLanguageAnnotationTarget(owner)) { PsiAnnotation[] resolvedAnnos = AnnotationUtilEx.getAnnotationFrom(owner, configuration.getAdvancedConfiguration().getPatternAnnotationPair(), true); if (resolvedAnnos.length == 2 && annotations.length == 2 && Comparing.strEqual(resolvedAnnos[1].getQualifiedName(), annotations[1].getQualifiedName())) { // both target and source annotated indirectly with the same anno return; } } if (holder.isOnTheFly()) { final String classname = configuration.getAdvancedConfiguration().getSubstAnnotationPair().first; if (owner != null && AddAnnotationFixWithoutArgFix.isApplicable(owner, classname)) { fixes.add(new AddAnnotationFixWithoutArgFix(classname, owner)); } else { fixes.add(new IntroduceVariableFix(false)); } } else { fixes.add(new IntroduceVariableFix(false)); } holder.registerProblem(expr, IntelliLangBundle.message("inspection.pattern.validator.description"), fixes.toArray(LocalQuickFix.EMPTY_ARRAY)); } } }
checkExpression
24,245
PsiElementVisitor (@NotNull final ProblemsHolder holder, boolean isOnTheFly) { return new JavaElementVisitor() { final Pair<String, ? extends Set<String>> annotationName = Configuration.getProjectInstance(holder.getProject()).getAdvancedConfiguration().getPatternAnnotationPair(); @Override public void visitMethod(@NotNull PsiMethod method) { PsiIdentifier psiIdentifier = method.getNameIdentifier(); if (psiIdentifier == null || !PsiUtilEx.isLanguageAnnotationTarget(method)) { return; } PsiAnnotation[] annotationFrom = AnnotationUtilEx.getAnnotationFrom(method, annotationName, true, false); if (annotationFrom.length == 0) { PsiAnnotation[] annotationFromHierarchy = AnnotationUtilEx.getAnnotationFrom(method, annotationName, true, true); if (annotationFromHierarchy.length > 0) { PsiAnnotation annotation = annotationFromHierarchy[annotationFromHierarchy.length - 1]; String annotationClassname = annotation.getQualifiedName(); PsiNameValuePair[] argList = annotation.getParameterList().getAttributes(); holder.registerProblem(psiIdentifier, IntelliLangBundle.message("inspection.pattern.overridden.by.non.annotated.method.description"), new AddAnnotationFix(Objects.requireNonNull(annotationClassname), method, argList)); } } } }; }
buildVisitor
24,246
void (@NotNull PsiMethod method) { PsiIdentifier psiIdentifier = method.getNameIdentifier(); if (psiIdentifier == null || !PsiUtilEx.isLanguageAnnotationTarget(method)) { return; } PsiAnnotation[] annotationFrom = AnnotationUtilEx.getAnnotationFrom(method, annotationName, true, false); if (annotationFrom.length == 0) { PsiAnnotation[] annotationFromHierarchy = AnnotationUtilEx.getAnnotationFrom(method, annotationName, true, true); if (annotationFromHierarchy.length > 0) { PsiAnnotation annotation = annotationFromHierarchy[annotationFromHierarchy.length - 1]; String annotationClassname = annotation.getQualifiedName(); PsiNameValuePair[] argList = annotation.getParameterList().getAttributes(); holder.registerProblem(psiIdentifier, IntelliLangBundle.message("inspection.pattern.overridden.by.non.annotated.method.description"), new AddAnnotationFix(Objects.requireNonNull(annotationClassname), method, argList)); } } }
visitMethod
24,247
void (@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) { result.addElement(LookupElementBuilder.create("*").bold()); for (Map.Entry<String, String> function : STANDARD_FUNCTIONS.entrySet()) { result.addElement(LookupElementBuilder.create(function.getKey() + "()") .withPresentableText(function.getKey()) .withIcon(AllIcons.Nodes.Method) .withTailText("()") .withTypeText(function.getValue())); } }
addCompletions
24,248
void (@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) { for (String keyword : KEYWORDS) { result.addElement(LookupElementBuilder.create(keyword).bold()); } }
addCompletions
24,249
void (@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) { for (String keyword : STANDARD_NAMED_OPERATORS) { result.addElement(LookupElementBuilder.create(keyword).bold()); } }
addCompletions
24,250
void (@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) { PsiFile file = parameters.getOriginalFile(); InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(file.getProject()); PsiLanguageInjectionHost injectionHost = injectedLanguageManager.getInjectionHost(file); if (injectionHost != null) { PsiFile hostFile = injectionHost.getContainingFile(); if (hostFile != null) { visitJsonPathLiteralsInFile(injectedLanguageManager, hostFile, propertyName -> { addCompletionElement(result, propertyName); }); } } Supplier<JsonFile> targetFileGetter = file.getUserData(JsonPathEvaluateManager.JSON_PATH_EVALUATE_SOURCE_KEY); if (targetFileGetter != null) { JsonFile targetFile = targetFileGetter.get(); if (targetFile == null) return; // it could be already removed targetFile.accept(new JsonRecursiveElementVisitor() { @Override public void visitProperty(@NotNull JsonProperty o) { super.visitProperty(o); String propertyName = o.getName(); if (!propertyName.isBlank()) { addCompletionElement(result, propertyName); } } }); } }
addCompletions
24,251
void (@NotNull JsonProperty o) { super.visitProperty(o); String propertyName = o.getName(); if (!propertyName.isBlank()) { addCompletionElement(result, propertyName); } }
visitProperty
24,252
void (@NotNull CompletionResultSet result, String propertyName) { if (!validIdentifiersOnly || VALID_IDENTIFIER_PATTERN.matcher(propertyName).matches()) { result.addElement(PrioritizedLookupElement.withPriority( LookupElementBuilder.create(propertyName) .withIcon(AllIcons.Nodes.Field) .withTypeText(JsonPathBundle.message("jsonpath.completion.key")), 100)); } }
addCompletionElement
24,253
void (InjectedLanguageManager injectedLanguageManager, PsiFile hostFile, Consumer<String> pathNameConsumer) { hostFile.accept(new PsiRecursiveElementVisitor() { @Override public void visitElement(@NotNull PsiElement element) { super.visitElement(element); if (element instanceof PsiLanguageInjectionHost) { List<Pair<PsiElement, TextRange>> files = injectedLanguageManager.getInjectedPsiFiles(element); if (files == null) return; for (Pair<PsiElement, TextRange> rangePair : files) { if (rangePair.getFirst() instanceof JsonPathFile jsonPathFile) { visitJsonPathLiterals(jsonPathFile); } } } } private void visitJsonPathLiterals(JsonPathFile jsonPathFile) { jsonPathFile.accept(new JsonPathRecursiveElementVisitor() { @Override public void visitIdSegment(@NotNull JsonPathIdSegment o) { super.visitIdSegment(o); JsonPathId id = o.getId(); if (!id.getTextRange().isEmpty()) { String literalText = getElementTextWithoutHostEscaping(id); if (!StringUtil.isEmptyOrSpaces(literalText)) { pathNameConsumer.accept(literalText); } } } @Override public void visitExpressionSegment(@NotNull JsonPathExpressionSegment o) { super.visitExpressionSegment(o); JsonPathQuotedPathsList quotedPathsList = o.getQuotedPathsList(); if (quotedPathsList == null) return; for (JsonPathStringLiteral stringLiteral : quotedPathsList.getStringLiteralList()) { String literalText = getElementTextWithoutHostEscaping(stringLiteral); if (literalText != null) { String literalValue = StringUtil.unquoteString(literalText); if (!StringUtil.isEmptyOrSpaces(literalValue)) { pathNameConsumer.accept(literalValue); } } } } private String getElementTextWithoutHostEscaping(@NotNull PsiElement element) { if (injectedLanguageManager.isInjectedFragment(element.getContainingFile())) { return injectedLanguageManager.getUnescapedText(element); } else { return element.getText(); } } }); } }); }
visitJsonPathLiteralsInFile
24,254
void (@NotNull PsiElement element) { super.visitElement(element); if (element instanceof PsiLanguageInjectionHost) { List<Pair<PsiElement, TextRange>> files = injectedLanguageManager.getInjectedPsiFiles(element); if (files == null) return; for (Pair<PsiElement, TextRange> rangePair : files) { if (rangePair.getFirst() instanceof JsonPathFile jsonPathFile) { visitJsonPathLiterals(jsonPathFile); } } } }
visitElement
24,255
void (JsonPathFile jsonPathFile) { jsonPathFile.accept(new JsonPathRecursiveElementVisitor() { @Override public void visitIdSegment(@NotNull JsonPathIdSegment o) { super.visitIdSegment(o); JsonPathId id = o.getId(); if (!id.getTextRange().isEmpty()) { String literalText = getElementTextWithoutHostEscaping(id); if (!StringUtil.isEmptyOrSpaces(literalText)) { pathNameConsumer.accept(literalText); } } } @Override public void visitExpressionSegment(@NotNull JsonPathExpressionSegment o) { super.visitExpressionSegment(o); JsonPathQuotedPathsList quotedPathsList = o.getQuotedPathsList(); if (quotedPathsList == null) return; for (JsonPathStringLiteral stringLiteral : quotedPathsList.getStringLiteralList()) { String literalText = getElementTextWithoutHostEscaping(stringLiteral); if (literalText != null) { String literalValue = StringUtil.unquoteString(literalText); if (!StringUtil.isEmptyOrSpaces(literalValue)) { pathNameConsumer.accept(literalValue); } } } } private String getElementTextWithoutHostEscaping(@NotNull PsiElement element) { if (injectedLanguageManager.isInjectedFragment(element.getContainingFile())) { return injectedLanguageManager.getUnescapedText(element); } else { return element.getText(); } } }); }
visitJsonPathLiterals
24,256
void (@NotNull JsonPathIdSegment o) { super.visitIdSegment(o); JsonPathId id = o.getId(); if (!id.getTextRange().isEmpty()) { String literalText = getElementTextWithoutHostEscaping(id); if (!StringUtil.isEmptyOrSpaces(literalText)) { pathNameConsumer.accept(literalText); } } }
visitIdSegment
24,257
void (@NotNull JsonPathExpressionSegment o) { super.visitExpressionSegment(o); JsonPathQuotedPathsList quotedPathsList = o.getQuotedPathsList(); if (quotedPathsList == null) return; for (JsonPathStringLiteral stringLiteral : quotedPathsList.getStringLiteralList()) { String literalText = getElementTextWithoutHostEscaping(stringLiteral); if (literalText != null) { String literalValue = StringUtil.unquoteString(literalText); if (!StringUtil.isEmptyOrSpaces(literalValue)) { pathNameConsumer.accept(literalValue); } } } }
visitExpressionSegment
24,258
String (@NotNull PsiElement element) { if (injectedLanguageManager.isInjectedFragment(element.getContainingFile())) { return injectedLanguageManager.getUnescapedText(element); } else { return element.getText(); } }
getElementTextWithoutHostEscaping
24,259
Lexer () { return new JsonPathLexer(); }
getHighlightingLexer
24,260
boolean () { return true; }
isCaseSensitive
24,261
LanguageFileType () { return JsonPathFileType.INSTANCE; }
getAssociatedFileType
24,262
SyntaxHighlighter (Project project, VirtualFile virtualFile) { return new JsonPathSyntaxHighlighter(); }
getSyntaxHighlighter
24,263
String () { return "JSONPath"; }
getName
24,264
String () { return JsonPathBundle.message("filetype.jsonpath.description"); }
getDescription
24,265
String () { return "jsonpath"; }
getDefaultExtension
24,266
Icon () { return AllIcons.FileTypes.Json; }
getIcon
24,267
void (@NotNull PsiElement element, @NotNull AnnotationHolder holder) { if (element instanceof JsonPathId && element.getParent() instanceof JsonPathFunctionCall) { holder.newSilentAnnotation(HighlightSeverity.INFORMATION) .range(element.getTextRange()) .textAttributes(JsonPathSyntaxHighlighter.JSONPATH_FUNCTION_CALL) .create(); } }
annotate
24,268
Icon () { return AllIcons.FileTypes.Json; }
getIcon
24,269
SyntaxHighlighter () { return new JsonPathSyntaxHighlighter(); }
getHighlighter
24,270
boolean (@NotNull IElementType lbraceType, @Nullable IElementType contextType) { return true; }
isPairedBracesAllowedBeforeType
24,271
int (PsiFile file, int openingBraceOffset) { return openingBraceOffset; }
getCodeConstructStart
24,272
void (@NotNull JsonPathStringLiteral element, @NotNull TokenConsumer consumer) { PlainTextSplitter textSplitter = PlainTextSplitter.getInstance(); if (element.textContains('\\')) { List<Pair<TextRange, String>> fragments = element.getTextFragments(); for (Pair<TextRange, String> fragment : fragments) { TextRange fragmentRange = fragment.getFirst(); String escaped = fragment.getSecond(); // Fragment without escaping, also not a broken escape sequence or a unicode code point if (escaped.length() == fragmentRange.getLength() && !escaped.startsWith("\\")) { consumer.consumeToken(element, escaped, false, fragmentRange.getStartOffset(), TextRange.allOf(escaped), textSplitter); } } } else { consumer.consumeToken(element, textSplitter); } }
tokenize
24,273
void (@NotNull JsonPathId element, @NotNull TokenConsumer consumer) { PlainTextSplitter textSplitter = PlainTextSplitter.getInstance(); consumer.consumeToken(element, textSplitter); }
tokenize
24,274
Tokenizer (PsiElement element) { if (element instanceof JsonPathStringLiteral) { return ourStringLiteralTokenizer; } if (element instanceof JsonPathId && element.getParent() instanceof JsonPathIdSegment) { return idLiteralTokenizer; } return super.getTokenizer(element); }
getTokenizer
24,275
void () { putUserData(JsonPathPsiUtils.STRING_FRAGMENTS, null); }
subtreeChanged
24,276
void (@NotNull final PsiElement element) { element.acceptChildren(this); }
visitElement
24,277
Lexer (Project project) { return new JsonPathLexer(); }
createLexer
24,278
PsiParser (Project project) { return new JsonPathParser(); }
createParser
24,279
PsiFile (@NotNull FileViewProvider viewProvider) { return new JsonPathFile(viewProvider); }
createFile
24,280
IFileElementType () { return FILE; }
getFileNodeType
24,281
TokenSet () { return TokenSet.EMPTY; }
getCommentTokens
24,282
TokenSet () { return JSONPATH_STRINGS_SET; }
getStringLiteralElements
24,283
PsiElement (ASTNode node) { return JsonPathTypes.Factory.createElement(node); }
createElement
24,284
FileType () { return JsonPathFileType.INSTANCE; }
getFileType
24,285
String () { return "JsonPathFile"; }
toString
24,286
PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { Supplier<JsonFile> jsonFileSupplier = holder.getFile().getUserData(JsonPathEvaluateManager.JSON_PATH_EVALUATE_SOURCE_KEY); JsonFile sourceFile = jsonFileSupplier != null ? jsonFileSupplier.get() : null; if (sourceFile == null) return PsiElementVisitor.EMPTY_VISITOR; NotNullLazyValue<Set<String>> allKeys = NotNullLazyValue.lazy(() -> collectAllKeysFromFile(sourceFile)); return new JsonPathVisitor() { @Override public void visitIdSegment(@NotNull JsonPathIdSegment segment) { super.visitIdSegment(segment); JsonPathId identifier = segment.getId(); String idString = identifier.getText(); if (StringUtil.isNotEmpty(idString) && !allKeys.getValue().contains(idString)) { holder.registerProblem(identifier, null, JsonPathBundle.message("inspection.message.jsonpath.unknown.key", idString)); } } }; }
buildVisitor
24,287
void (@NotNull JsonPathIdSegment segment) { super.visitIdSegment(segment); JsonPathId identifier = segment.getId(); String idString = identifier.getText(); if (StringUtil.isNotEmpty(idString) && !allKeys.getValue().contains(idString)) { holder.registerProblem(identifier, null, JsonPathBundle.message("inspection.message.jsonpath.unknown.key", idString)); } }
visitIdSegment
24,288
Set<String> (JsonFile file) { Set<String> propertyNames = new HashSet<>(); file.accept(new JsonRecursiveElementVisitor() { @Override public void visitProperty(@NotNull JsonProperty o) { super.visitProperty(o); propertyNames.add(o.getName()); } }); return propertyNames; }
collectAllKeysFromFile
24,289
void (@NotNull JsonProperty o) { super.visitProperty(o); propertyNames.add(o.getName()); }
visitProperty
24,290
PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { return new JsonPathVisitor() { @Override public void visitFunctionCall(@NotNull JsonPathFunctionCall call) { super.visitFunctionCall(call); JsonPathId functionId = call.getId(); String functionName = functionId.getText(); if (!JsonPathConstants.STANDARD_FUNCTIONS.containsKey(functionName)) { boolean isEvaluateExpr = Boolean.TRUE.equals(holder.getFile().getUserData(JSON_PATH_EVALUATE_EXPRESSION_KEY)); if (isEvaluateExpr) { holder.registerProblem(functionId, JsonPathBundle.message("inspection.message.jsonpath.unsupported.jayway.function", functionName), ProblemHighlightType.ERROR); } else { holder.registerProblem(functionId, null, JsonPathBundle.message("inspection.message.jsonpath.unknown.function.name", functionName)); // todo Suppress for name quick fix } } } }; }
buildVisitor
24,291
void (@NotNull JsonPathFunctionCall call) { super.visitFunctionCall(call); JsonPathId functionId = call.getId(); String functionName = functionId.getText(); if (!JsonPathConstants.STANDARD_FUNCTIONS.containsKey(functionName)) { boolean isEvaluateExpr = Boolean.TRUE.equals(holder.getFile().getUserData(JSON_PATH_EVALUATE_EXPRESSION_KEY)); if (isEvaluateExpr) { holder.registerProblem(functionId, JsonPathBundle.message("inspection.message.jsonpath.unsupported.jayway.function", functionName), ProblemHighlightType.ERROR); } else { holder.registerProblem(functionId, null, JsonPathBundle.message("inspection.message.jsonpath.unknown.function.name", functionName)); // todo Suppress for name quick fix } } }
visitFunctionCall
24,292
PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { return new JsonPathVisitor() { @Override public void visitBinaryConditionalOperator(@NotNull JsonPathBinaryConditionalOperator operator) { super.visitBinaryConditionalOperator(operator); ASTNode namedOp = operator.getNode().findChildByType(JsonPathTypes.NAMED_OP); if (namedOp == null) return; String operatorName = namedOp.getText(); if (!JsonPathConstants.STANDARD_NAMED_OPERATORS.contains(operatorName)) { boolean isEvaluateExpr = Boolean.TRUE.equals(holder.getFile().getUserData(JSON_PATH_EVALUATE_EXPRESSION_KEY)); if (isEvaluateExpr) { holder.registerProblem(operator, JsonPathBundle.message("inspection.message.jsonpath.unsupported.jayway.operator", operatorName), ProblemHighlightType.ERROR); } else { holder.registerProblem(operator, null, JsonPathBundle.message("inspection.message.jsonpath.unknown.operator.name", operatorName)); } } } }; }
buildVisitor
24,293
void (@NotNull JsonPathBinaryConditionalOperator operator) { super.visitBinaryConditionalOperator(operator); ASTNode namedOp = operator.getNode().findChildByType(JsonPathTypes.NAMED_OP); if (namedOp == null) return; String operatorName = namedOp.getText(); if (!JsonPathConstants.STANDARD_NAMED_OPERATORS.contains(operatorName)) { boolean isEvaluateExpr = Boolean.TRUE.equals(holder.getFile().getUserData(JSON_PATH_EVALUATE_EXPRESSION_KEY)); if (isEvaluateExpr) { holder.registerProblem(operator, JsonPathBundle.message("inspection.message.jsonpath.unsupported.jayway.operator", operatorName), ProblemHighlightType.ERROR); } else { holder.registerProblem(operator, null, JsonPathBundle.message("inspection.message.jsonpath.unknown.operator.name", operatorName)); } } }
visitBinaryConditionalOperator
24,294
ASTNode (IElementType t, PsiBuilder b) { parseLight(t, b); return b.getTreeBuilt(); }
parse
24,295
void (IElementType t, PsiBuilder b) { boolean r; b = adapt_builder_(t, b, this, EXTENDS_SETS_); Marker m = enter_section_(b, 0, _COLLAPSE_, null); r = parse_root_(t, b); exit_section_(b, 0, m, t, r, true, TRUE_CONDITION); }
parseLight
24,296
boolean (IElementType t, PsiBuilder b) { return parse_root_(t, b, 0); }
parse_root_
24,297
boolean (IElementType t, PsiBuilder b, int l) { boolean r; if (t == EXPRESSION) { r = expression(b, l + 1, -1); } else { r = root(b, l + 1); } return r; }
parse_root_
24,298
boolean (PsiBuilder b, int l) { if (!recursion_guard_(b, l, "arrayElement_")) return false; boolean r, p; Marker m = enter_section_(b, l, _NONE_); r = value(b, l + 1); p = r; // pin = 1 r = r && arrayElement__1(b, l + 1); exit_section_(b, l, m, r, p, JsonPathParser::notBracketOrNextValue); return r || p; }
arrayElement_
24,299
boolean (PsiBuilder b, int l) { if (!recursion_guard_(b, l, "arrayElement__1")) return false; boolean r; Marker m = enter_section_(b); r = consumeToken(b, COMMA); if (!r) r = arrayElement__1_1(b, l + 1); exit_section_(b, m, null, r); return r; }
arrayElement__1