Unnamed: 0
int64 0
305k
| body
stringlengths 7
52.9k
| name
stringlengths 1
185
|
|---|---|---|
17,500
|
boolean () { return false; }
|
isSearchInLibraries
|
17,501
|
PsiElementVisitor (final @NotNull ProblemsHolder holder, final boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitAnnotation(@NotNull PsiAnnotation annotation) { if (TestNGUtil.TEST_ANNOTATION_FQN.equals(annotation.getQualifiedName())) { final PsiAnnotationMemberValue provider = annotation.findDeclaredAttributeValue("dataProvider"); if (provider != null && !TestNGUtil.isDisabled(annotation)) { for (PsiReference reference : provider.getReferences()) { if (reference instanceof DataProviderReference) { final PsiElement dataProviderMethod = reference.resolve(); final PsiElement element = reference.getElement(); final PsiClass topLevelClass = PsiUtil.getTopLevelClass(element); final PsiClass providerClass = TestNGUtil.getProviderClass(element, topLevelClass); if (!(dataProviderMethod instanceof PsiMethod providerMethod)) { final LocalQuickFix[] fixes; if (isOnTheFly && providerClass != null) { fixes = new LocalQuickFix[] {createMethodFix(provider, providerClass, topLevelClass)}; } else { fixes = LocalQuickFix.EMPTY_ARRAY; } holder.registerProblem(provider, TestngBundle.message("inspection.testng.data.provider.does.not.exist.problem"), fixes); } else { if (TestNGUtil.isVersionOrGreaterThan(holder.getProject(), ModuleUtilCore.findModuleForPsiElement(providerClass), 6, 9, 13)) { break; } if (providerClass != topLevelClass && !providerMethod.hasModifierProperty(PsiModifier.STATIC)) { holder.registerProblem(provider, TestngBundle.message("inspection.testng.data.provider.need.to.be.static")); } } break; } } } } } }; }
|
buildVisitor
|
17,502
|
void (@NotNull PsiAnnotation annotation) { if (TestNGUtil.TEST_ANNOTATION_FQN.equals(annotation.getQualifiedName())) { final PsiAnnotationMemberValue provider = annotation.findDeclaredAttributeValue("dataProvider"); if (provider != null && !TestNGUtil.isDisabled(annotation)) { for (PsiReference reference : provider.getReferences()) { if (reference instanceof DataProviderReference) { final PsiElement dataProviderMethod = reference.resolve(); final PsiElement element = reference.getElement(); final PsiClass topLevelClass = PsiUtil.getTopLevelClass(element); final PsiClass providerClass = TestNGUtil.getProviderClass(element, topLevelClass); if (!(dataProviderMethod instanceof PsiMethod providerMethod)) { final LocalQuickFix[] fixes; if (isOnTheFly && providerClass != null) { fixes = new LocalQuickFix[] {createMethodFix(provider, providerClass, topLevelClass)}; } else { fixes = LocalQuickFix.EMPTY_ARRAY; } holder.registerProblem(provider, TestngBundle.message("inspection.testng.data.provider.does.not.exist.problem"), fixes); } else { if (TestNGUtil.isVersionOrGreaterThan(holder.getProject(), ModuleUtilCore.findModuleForPsiElement(providerClass), 6, 9, 13)) { break; } if (providerClass != topLevelClass && !providerMethod.hasModifierProperty(PsiModifier.STATIC)) { holder.registerProblem(provider, TestngBundle.message("inspection.testng.data.provider.need.to.be.static")); } } break; } } } } }
|
visitAnnotation
|
17,503
|
CreateMethodQuickFix (PsiAnnotationMemberValue provider, @NotNull PsiClass providerClass, PsiClass topLevelClass) { final String name = StringUtil.unquoteString(provider.getText()); FileTemplateDescriptor templateDesc = new TestNGFramework().getParametersMethodFileTemplateDescriptor(); assert templateDesc != null; final FileTemplate fileTemplate = FileTemplateManager.getInstance(provider.getProject()).getCodeTemplate(templateDesc.getFileName()); String body = ""; try { final Properties attributes = FileTemplateManager.getInstance(provider.getProject()).getDefaultProperties(); attributes.setProperty(FileTemplate.ATTRIBUTE_NAME, name); body = fileTemplate.getText(attributes); body = body.replace("${BODY}\n", ""); final PsiMethod methodFromTemplate = JavaPsiFacade.getElementFactory(providerClass.getProject()).createMethodFromText(body, providerClass); final PsiCodeBlock methodBody = methodFromTemplate.getBody(); if (methodBody != null) { body = StringUtil.trimEnd(StringUtil.trimStart(methodBody.getText(), "{"), "}"); } else { body = ""; } } catch (Exception ignored) {} if (StringUtil.isEmptyOrSpaces(body)) { body = "return new Object[][]{};"; } String signature = "@" + DataProvider.class.getName() + " public "; if (providerClass == topLevelClass) { signature += "static "; } signature += "Object[][] " + name + "()"; return CreateMethodQuickFix.createFix(providerClass, signature, body); }
|
createMethodFix
|
17,504
|
String () { return TestNGUtil.TESTNG_GROUP_NAME; }
|
getGroupDisplayName
|
17,505
|
String () { return "JUnitTestNG"; }
|
getShortName
|
17,506
|
String () { return TestngBundle.message("intention.family.name.convert.testcase.to.testng"); }
|
getFamilyName
|
17,507
|
boolean () { return false; }
|
startInWriteAction
|
17,508
|
IntentionPreviewInfo (@NotNull Project project, @NotNull ProblemDescriptor previewDescriptor) { final PsiClass psiClass = PsiTreeUtil.getParentOfType(previewDescriptor.getPsiElement(), PsiClass.class); if (psiClass == null) return IntentionPreviewInfo.EMPTY; doFix(project, psiClass); return IntentionPreviewInfo.DIFF; }
|
generatePreview
|
17,509
|
void (@NotNull Project project, @NotNull ProblemDescriptor descriptor) { final PsiClass psiClass = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiClass.class); if (psiClass == null || !TestNGUtil.checkTestNGInClasspath(psiClass)) return; if (!FileModificationService.getInstance().preparePsiElementsForWrite(psiClass)) return; WriteAction.run(() -> doFix(project, psiClass)); }
|
applyFix
|
17,510
|
void (@NotNull Project project, PsiClass psiClass) { try { final PsiManager manager = PsiManager.getInstance(project); final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(); final PsiJavaFile javaFile = (PsiJavaFile)psiClass.getContainingFile(); for (PsiMethod method : psiClass.getMethods()) { final PsiMethodCallExpression[] methodCalls = getTestCaseCalls(method); if (method.isConstructor()) { convertJUnitConstructor(method); } else { if (!javaFile.getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_5)) { addMethodJavadoc(factory, method); } else { if (TestNGUtil.containsJunitAnnotations(method)) { convertJunitAnnotations(factory, method); } else { addMethodAnnotations(factory, method); } } } for (PsiMethodCallExpression methodCall : methodCalls) { PsiMethod assertMethod = methodCall.resolveMethod(); if (assertMethod == null) { continue; } @NonNls String methodName = assertMethod.getName(); PsiExpression[] expressions = methodCall.getArgumentList().getExpressions(); final PsiStatement methodCallStatement = PsiTreeUtil.getParentOfType(methodCall, PsiStatement.class); LOG.assertTrue(methodCallStatement != null); final String qualifierTemplate = methodCall.getMethodExpression().getQualifierExpression() != null ? "$qualifier$." : ""; final String searchTemplate; final String replaceTemplate; if ("assertNull".equals(methodName) || "assertNotNull".equals(methodName) || "assertTrue".equals(methodName) || "assertFalse".equals(methodName)) { boolean hasMessage = expressions.length == 2; searchTemplate = qualifierTemplate + "$method$($object$ " + (hasMessage ? ",$msg$" : "") + ")"; replaceTemplate = "org.testng.Assert.$method$(" + (hasMessage ? "$msg$," : "") + "$object$)"; } else if ("fail".equals(methodName)) { boolean hasMessage = expressions.length == 1; searchTemplate = qualifierTemplate + "$method$(" + (hasMessage ? "$msg$" : "") + ")"; replaceTemplate = "org.testng.Assert.$method$(" + (hasMessage ? "$msg$" : "") + ")"; } else if ("assertThat".equals(methodName)) { String paramTemplate = (expressions.length == 3 ? "$msg$," : "") + "$actual$, $matcher$"; searchTemplate = qualifierTemplate + "assertThat(" + paramTemplate + ")"; replaceTemplate = "org.hamcrest.MatcherAssert.assertThat(" + paramTemplate +")"; } else { boolean hasMessage = hasMessage(methodCall); if ((hasMessage && expressions.length == 4) || (!hasMessage && expressions.length == 3)) { searchTemplate = qualifierTemplate + "$method$"; replaceTemplate = "org.testng.AssertJUnit.$method$"; } else { String replaceMethodWildCard = "$method$"; if (methodName.equals("assertArrayEquals")) { replaceMethodWildCard = "assertEquals"; } searchTemplate = qualifierTemplate + "$method$(" + (hasMessage ? "$msg$, " : "") + "$expected$, $actual$" + ")"; replaceTemplate = "org.testng.Assert." + replaceMethodWildCard + "($actual$, $expected$ " + (hasMessage ? ", $msg$" : "") + ")"; } } TypeConversionDescriptor.replaceExpression(methodCall, searchTemplate, replaceTemplate); } } final PsiClass superClass = psiClass.getSuperClass(); if (superClass != null && "junit.framework.TestCase".equals(superClass.getQualifiedName())) { final PsiReferenceList extendsList = psiClass.getExtendsList(); LOG.assertTrue(extendsList != null); for (PsiJavaCodeReferenceElement element : extendsList.getReferenceElements()) { element.delete(); } } final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project); codeStyleManager.optimizeImports(javaFile);//delete unused imports codeStyleManager.shortenClassReferences(javaFile); } catch (IncorrectOperationException e) { LOG.error("Error converting testcase", e); } }
|
doFix
|
17,511
|
boolean (PsiMethodCallExpression expression) { final PsiExpression[] expressions = expression.getArgumentList().getExpressions(); if (expressions.length == 4) { return true; } final PsiMethod method = expression.resolveMethod(); LOG.assertTrue(method != null); for (PsiParameter parameter : method.getParameterList().getParameters()) { final PsiType type = parameter.getType(); if (type instanceof PsiClassType) { final PsiClass resolvedClass = ((PsiClassType)type).resolve(); if (resolvedClass != null && CommonClassNames.JAVA_LANG_STRING.equals(resolvedClass.getQualifiedName())) { return true; } } } return false; }
|
hasMessage
|
17,512
|
void (PsiMethod method) { method.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitExpressionStatement(@NotNull PsiExpressionStatement statement) { PsiExpression expression = statement.getExpression(); if (expression instanceof PsiMethodCallExpression methodCall) { if (methodCall.getArgumentList().getExpressionCount() == 1) { PsiMethod resolved = methodCall.resolveMethod(); if (resolved != null && "junit.framework.TestCase".equals(resolved.getContainingClass().getQualifiedName()) && "TestCase".equals(resolved.getName())) { try { statement.delete(); } catch (IncorrectOperationException e) { LOG.error(e); } } } } } }); }
|
convertJUnitConstructor
|
17,513
|
void (@NotNull PsiExpressionStatement statement) { PsiExpression expression = statement.getExpression(); if (expression instanceof PsiMethodCallExpression methodCall) { if (methodCall.getArgumentList().getExpressionCount() == 1) { PsiMethod resolved = methodCall.resolveMethod(); if (resolved != null && "junit.framework.TestCase".equals(resolved.getContainingClass().getQualifiedName()) && "TestCase".equals(resolved.getName())) { try { statement.delete(); } catch (IncorrectOperationException e) { LOG.error(e); } } } } }
|
visitExpressionStatement
|
17,514
|
PsiMethodCallExpression[] (PsiMethod method) { return SyntaxTraverser.psiTraverser(method).filter(PsiMethodCallExpression.class) .filter(methodCall -> { final PsiMethod method1 = methodCall.resolveMethod(); if (method1 != null) { final PsiClass containingClass = method1.getContainingClass(); if (containingClass != null) { final String qualifiedName = containingClass.getQualifiedName(); return "junit.framework.Assert".equals(qualifiedName) || "org.junit.Assert".equals(qualifiedName) || "junit.framework.TestCase".equals(qualifiedName); } } return false; }).toArray(new PsiMethodCallExpression[0]); }
|
getTestCaseCalls
|
17,515
|
String () { return TestNGUtil.TESTNG_GROUP_NAME; }
|
getGroupDisplayName
|
17,516
|
String () { return "ConvertOldAnnotations"; }
|
getShortName
|
17,517
|
PsiElementVisitor (@NotNull final ProblemsHolder holder, final boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitAnnotation(final @NotNull PsiAnnotation annotation) { final String qualifiedName = annotation.getQualifiedName(); if (Comparing.strEqual(qualifiedName, "org.testng.annotations.Configuration")) { holder.registerProblem(annotation, TestngBundle.message("inspection.message.old.testng.annotation.configuration.used"), new ConvertOldAnnotationsQuickfix()); } } }; }
|
buildVisitor
|
17,518
|
String () { return TestngBundle.message("intention.family.name.convert.old.configuration.testng.annotations"); }
|
getFamilyName
|
17,519
|
boolean () { return false; }
|
startInWriteAction
|
17,520
|
IntentionPreviewInfo (@NotNull Project project, @NotNull ProblemDescriptor previewDescriptor) { final PsiAnnotation annotation = (PsiAnnotation)previewDescriptor.getPsiElement(); doFix(annotation); return IntentionPreviewInfo.DIFF; }
|
generatePreview
|
17,521
|
void (@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) { final PsiAnnotation annotation = (PsiAnnotation)descriptor.getPsiElement(); if (!TestNGUtil.checkTestNGInClasspath(annotation)) return; if (!FileModificationService.getInstance().preparePsiElementsForWrite(annotation)) return; WriteAction.run(() -> doFix(annotation)); }
|
applyFix
|
17,522
|
void (PsiAnnotation annotation) { final PsiModifierList modifierList = PsiTreeUtil.getParentOfType(annotation, PsiModifierList.class); LOG.assertTrue(modifierList != null); try { convertOldAnnotationAttributeToAnnotation(modifierList, annotation, "beforeTest", "@org.testng.annotations.BeforeTest"); convertOldAnnotationAttributeToAnnotation(modifierList, annotation, "beforeTestClass", "@org.testng.annotations.BeforeTest"); convertOldAnnotationAttributeToAnnotation(modifierList, annotation, "beforeTestMethod", "@org.testng.annotations.BeforeMethod"); convertOldAnnotationAttributeToAnnotation(modifierList, annotation, "beforeSuite", "@org.testng.annotations.BeforeSuite"); convertOldAnnotationAttributeToAnnotation(modifierList, annotation, "beforeGroups", "@org.testng.annotations.BeforeGroups"); convertOldAnnotationAttributeToAnnotation(modifierList, annotation, "afterTest", "@org.testng.annotations.AfterTest"); convertOldAnnotationAttributeToAnnotation(modifierList, annotation, "afterTestClass", "@org.testng.annotations.AfterTest"); convertOldAnnotationAttributeToAnnotation(modifierList, annotation, "afterTestMethod", "@org.testng.annotations.AfterMethod"); convertOldAnnotationAttributeToAnnotation(modifierList, annotation, "afterSuite", "@org.testng.annotations.AfterSuite"); convertOldAnnotationAttributeToAnnotation(modifierList, annotation, "afterGroups", "@org.testng.annotations.AfterGroups"); annotation.delete(); } catch (IncorrectOperationException e) { LOG.error(e); } }
|
doFix
|
17,523
|
String () { return TestNGUtil.TESTNG_GROUP_NAME; }
|
getGroupDisplayName
|
17,524
|
String () { return "ConvertJavadoc"; }
|
getShortName
|
17,525
|
PsiElementVisitor (@NotNull final ProblemsHolder holder, final boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitDocTag(final @NotNull PsiDocTag tag) { if (tag.getName().startsWith(TESTNG_PREFIX)) { holder.registerProblem(tag, TestngBundle.message("inspection.message.testng.javadoc.can.be.converted.to.annotations"), new ConvertJavadocQuickfix()); } } }; }
|
buildVisitor
|
17,526
|
String () { return TestngBundle.message("intention.family.name.convert.testng.javadoc.to.annotations"); }
|
getFamilyName
|
17,527
|
boolean () { return false; }
|
startInWriteAction
|
17,528
|
IntentionPreviewInfo (@NotNull Project project, @NotNull ProblemDescriptor previewDescriptor) { final PsiDocTag tag = (PsiDocTag)previewDescriptor.getPsiElement(); doFix(project, tag); return IntentionPreviewInfo.DIFF; }
|
generatePreview
|
17,529
|
void (@NotNull Project project, @NotNull ProblemDescriptor descriptor) { final PsiDocTag tag = (PsiDocTag)descriptor.getPsiElement(); if (!TestNGUtil.checkTestNGInClasspath(tag)) return; if (!FileModificationService.getInstance().preparePsiElementsForWrite(tag)) return; WriteAction.run(() -> doFix(project, tag)); }
|
applyFix
|
17,530
|
void (@NotNull Project project, PsiDocTag tag) { final PsiMember member = PsiTreeUtil.getParentOfType(tag, PsiMember.class); LOG.assertTrue(member != null); @NonNls String annotationName = getFQAnnotationName(tag); final StringBuilder annotationText = new StringBuilder("@"); annotationText.append(annotationName); final PsiClass annotationClass = DumbService.getInstance(project) .computeWithAlternativeResolveEnabled(() -> JavaPsiFacade.getInstance(member.getProject()) .findClass(annotationName, member.getResolveScope())); PsiElement[] dataElements = tag.getDataElements(); if (dataElements.length > 1) { annotationText.append('('); } if (annotationClass != null) { for (PsiMethod attribute : annotationClass.getMethods()) { boolean stripQuotes = false; PsiType returnType = attribute.getReturnType(); if (returnType instanceof PsiPrimitiveType) { stripQuotes = true; } for (int i = 0; i < dataElements.length; i++) { String text = dataElements[i].getText(); int equals = text.indexOf('='); String value; final String key = equals == -1 ? text : text.substring(0, equals).trim(); if (!key.equals(attribute.getName())) continue; annotationText.append(key).append(" = "); if (equals == -1) { //no equals, so we look in the next token String next = dataElements[++i].getText().trim(); //it's an equals by itself if (next.length() == 1) { value = dataElements[++i].getText().trim(); } else { //otherwise, it's foo =bar, so we strip equals value = next.substring(1).trim(); } } else { //check if the value is in the first bit too if (equals < text.length() - 1) { //we have stuff after equals, great value = text.substring(equals + 1).trim(); } else { //nothing after equals, so we just get the next element value = dataElements[++i].getText().trim(); } } if (stripQuotes && value.charAt(0) == '\"') { value = value.substring(1, value.length() - 1); } annotationText.append(value); } } } if (dataElements.length > 1) { annotationText.append(')'); } try { PsiModifierList modifierList = member.getModifierList(); PsiAnnotation annotation = JavaPsiFacade.getElementFactory(tag.getProject()).createAnnotationFromText(annotationText.toString(), member); final PsiElement inserted = modifierList.addBefore(annotation, modifierList.getFirstChild()); JavaCodeStyleManager.getInstance(project).shortenClassReferences(inserted); final PsiDocComment docComment = PsiTreeUtil.getParentOfType(tag, PsiDocComment.class); LOG.assertTrue(docComment != null); //cleanup tag.delete(); for (PsiElement element : docComment.getChildren()) { //if it's anything other than a doc token, then it must stay if (element instanceof PsiWhiteSpace) continue; if (!(element instanceof PsiDocToken docToken)) return; if (docToken.getTokenType() == JavaDocTokenType.DOC_COMMENT_DATA && !docToken.getText().trim().isEmpty()) { return; } } //at this point, our doc don't have non-empty comments, nor any tags, so we can delete it. docComment.delete(); } catch (IncorrectOperationException e) { LOG.error(e); } }
|
doFix
|
17,531
|
String (PsiDocTag tag) { @NonNls String annotationName = StringUtil.capitalize(tag.getName().substring(TESTNG_PREFIX.length())); int dash = annotationName.indexOf('-'); if (dash > -1) { annotationName = annotationName.substring(0, dash) + Character.toUpperCase(annotationName.charAt(dash + 1)) + annotationName.substring(dash + 2); } annotationName = "org.testng.annotations." + annotationName; return annotationName; }
|
getFQAnnotationName
|
17,532
|
PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { return new ExpectedExceptionNeverThrownVisitor(holder); }
|
buildVisitor
|
17,533
|
void (@NotNull PsiMethod method) { super.visitMethod(method); final PsiAnnotation annotation = AnnotationUtil.findAnnotation(method, "org.testng.annotations.Test"); if (annotation == null) { return; } final PsiAnnotationMemberValue value = annotation.findDeclaredAttributeValue("expectedExceptions"); if (value == null) { return; } final PsiCodeBlock body = method.getBody(); if (body == null) { return; } final List<PsiClassType> exceptionsThrown = ExceptionUtil.getThrownExceptions(body); if (value instanceof PsiClassObjectAccessExpression) { checkAnnotationMemberValue(value, method, exceptionsThrown); } else if (value instanceof PsiArrayInitializerMemberValue arrayInitializerMemberValue) { for (PsiAnnotationMemberValue memberValue : arrayInitializerMemberValue.getInitializers()) { checkAnnotationMemberValue(memberValue, method, exceptionsThrown); } } }
|
visitMethod
|
17,534
|
void (PsiAnnotationMemberValue annotationMemberValue, PsiMethod method, List<PsiClassType> exceptionsThrown) { if (!(annotationMemberValue instanceof PsiClassObjectAccessExpression classObjectAccessExpression)) { return; } final PsiTypeElement operand = classObjectAccessExpression.getOperand(); final PsiType type = operand.getType(); if (!(type instanceof PsiClassType expectedType)) { return; } if (InheritanceUtil.isInheritor(expectedType, CommonClassNames.JAVA_LANG_RUNTIME_EXCEPTION)) { return; } for (PsiClassType exceptionType : exceptionsThrown) { if (exceptionType.isAssignableFrom(expectedType)) { return; } } myProblemsHolder.registerProblem(operand, TestngBundle.message("inspection.testng.expected.exception.never.thrown.problem", method.getName())); }
|
checkAnnotationMemberValue
|
17,535
|
String () { return TestngBundle.message("checkbox.testng.test"); }
|
getElementDescription
|
17,536
|
String () { return "TestNGMethodNamingConvention"; }
|
getShortName
|
17,537
|
NamingConventionBean () { return new NamingConventionBean("[a-z][A-Za-z_\\d]*", 4, 64); }
|
createDefaultBean
|
17,538
|
boolean (PsiMethod member) { return TestNGUtil.hasTest(member); }
|
isApplicable
|
17,539
|
String () { return TestNGUtil.TESTNG_GROUP_NAME; }
|
getGroupDisplayName
|
17,540
|
String () { return "dependsOnMethodTestNG"; }
|
getShortName
|
17,541
|
boolean () { return true; }
|
isEnabledByDefault
|
17,542
|
void (InspectionManager manager, PsiClass psiClass, String methodName, PsiAnnotationMemberValue value, List<ProblemDescriptor> problemDescriptors, boolean onTheFly) { LOGGER.debug("Found dependsOnMethods with text: " + methodName); if (!methodName.isEmpty() && methodName.charAt(methodName.length() - 1) == ')') { LOGGER.debug("dependsOnMethods contains ()" + psiClass.getName()); // TODO Add quick fix for removing brackets on annotation String template = TestngBundle.message("inspection.depends.on.method.check", methodName); problemDescriptors.add(manager.createProblemDescriptor( value, template, (LocalQuickFix)null, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, onTheFly)); } else { final String configAnnotation = TestNGUtil.getConfigAnnotation(PsiTreeUtil.getParentOfType(value, PsiMethod.class)); final PsiMethod[] foundMethods; if (methodName.endsWith("*")) { final String methodNameMask = StringUtil.trimEnd(methodName, "*"); final List<PsiMethod> methods = ContainerUtil.filter(psiClass.getMethods(), method -> method.getName().startsWith(methodNameMask)); foundMethods = methods.toArray(PsiMethod.EMPTY_ARRAY); } else { foundMethods = psiClass.findMethodsByName(methodName, true); } if (foundMethods.length == 0) { LOGGER.debug("dependsOnMethods method doesn't exist:" + methodName); problemDescriptors.add(manager.createProblemDescriptor( value, TestngBundle.message("inspection.depends.on.method.unknown.method.problem", methodName), (LocalQuickFix)null, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, onTheFly)); } else { boolean hasTestsOrConfigs = false; for (PsiMethod foundMethod : foundMethods) { if (configAnnotation != null) { hasTestsOrConfigs |= AnnotationUtil.isAnnotated(foundMethod, configAnnotation, AnnotationUtil.CHECK_HIERARCHY); } else { hasTestsOrConfigs |= TestNGUtil.hasTest(foundMethod); } } if (!hasTestsOrConfigs) { String template = configAnnotation == null ? TestngBundle.message("inspection.depends.on.method.is.not.test", methodName) : TestngBundle.message("inspection.depends.on.method.is.not.annotated", methodName, configAnnotation); problemDescriptors.add(manager.createProblemDescriptor( value, template, (LocalQuickFix)null, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, onTheFly)); } } } }
|
checkMethodNameDependency
|
17,543
|
String () { return TestNGUtil.TESTNG_GROUP_NAME; }
|
getGroupDisplayName
|
17,544
|
String () { return SHORT_NAME; }
|
getShortName
|
17,545
|
boolean () { return true; }
|
isEnabledByDefault
|
17,546
|
OptPane () { return OptPane.pane( OptPane.string("groups", TestngBundle.message("inspection.depends.on.groups.defined.groups.panel.title"), 30) ); }
|
getOptionsPane
|
17,547
|
OptionController () { return super.getOptionController().onValue( "groups", () -> StringUtil.join(ArrayUtilRt.toStringArray(groups), ","), value -> { groups.clear(); if (!StringUtil.isEmptyOrSpaces(value)) { ContainerUtil.addAll(groups, value.split("[, ]")); } }); }
|
getOptionController
|
17,548
|
String () { return TestngBundle.message("inspection.depends.on.groups.add.as.defined.test.group.fix", myGroupName); }
|
getName
|
17,549
|
String () { return TestngBundle.message("inspection.depends.on.groups.family.name"); }
|
getFamilyName
|
17,550
|
void (@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) { groups.add(myGroupName); //correct save settings ProjectInspectionProfileManager.getInstance(project).fireProfileChanged(); //TODO lesya /* try { inspectionProfile.save(); } catch (IOException e) { Messages.showErrorDialog(project, e.getMessage(), CommonBundle.getErrorTitle()); } */ }
|
applyFix
|
17,551
|
boolean () { return false; }
|
startInWriteAction
|
17,552
|
boolean (@NotNull PsiType type, @NotNull PsiAnnotation annotation) { if (type instanceof PsiArrayType) { return isSuitableInnerType(((PsiArrayType)type).getComponentType(), annotation); } if (type instanceof PsiClassType) { final PsiClassType.ClassResolveResult resolveResult = ((PsiClassType)type).resolveGenerics(); final PsiClass resolvedClass = resolveResult.getElement(); if (resolvedClass == null || !CommonClassNames.JAVA_UTIL_ITERATOR.equals(resolvedClass.getQualifiedName())) return false; final Map<PsiTypeParameter, PsiType> substitutionMap = resolveResult.getSubstitutor().getSubstitutionMap(); if (substitutionMap.size() != 1) return false; final PsiType genericType = ContainerUtil.getFirstItem(substitutionMap.values()); if (genericType == null) return false; return isSuitableInnerType(genericType, annotation); } return false; }
|
isSuitableReturnType
|
17,553
|
boolean (@NotNull PsiType type, @NotNull PsiAnnotation annotation) { if (!(type instanceof PsiArrayType)) { Module module = ModuleUtilCore.findModuleForPsiElement(annotation); if (module == null) return false; return supportOneDimensional(module); } final PsiType componentType = type.getDeepComponentType(); if (!(componentType instanceof PsiClassType)) return false; final PsiClass resolvedClass = ((PsiClassType)componentType).resolve(); if (resolvedClass == null) return false; return true; }
|
isSuitableInnerType
|
17,554
|
boolean (@NotNull Module module) { return TestNGUtil.isVersionOrGreaterThan(module.getProject(), module, 6, 10, 0); }
|
supportOneDimensional
|
17,555
|
boolean (PsiElement member) { if (member instanceof PsiMethod method) { return TestNGUtil.hasTest(method, false) || TestNGUtil.hasConfig(method); } return false; }
|
value
|
17,556
|
String () { return TestNGUtil.TESTNG_GROUP_NAME; }
|
getGroupDisplayName
|
17,557
|
String () { return "UndeclaredTests"; }
|
getShortName
|
17,558
|
String () { return TestngBundle.message("inspection.undeclared.test.register", myClassName); }
|
getName
|
17,559
|
String () { return TestngBundle.message("inspection.undeclared.test.register.test"); }
|
getFamilyName
|
17,560
|
void (@NotNull final Project project, @NotNull ProblemDescriptor descriptor) { final PsiClass psiClass = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiClass.class); LOG.assertTrue(psiClass != null); final String testngXmlPath = new SuiteBrowser(project).showDialog(); if (testngXmlPath == null) return; final VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(testngXmlPath); LOG.assertTrue(virtualFile != null); final PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile); LOG.assertTrue(psiFile instanceof XmlFile); final XmlFile testngXML = (XmlFile)psiFile; WriteCommandAction.writeCommandAction(project, testngXML).withName(getName()).run(() -> patchTestngXml(testngXML, psiClass)); }
|
applyFix
|
17,561
|
boolean () { return false; }
|
startInWriteAction
|
17,562
|
void (final XmlFile testngXML, final PsiClass psiClass) { final XmlTag rootTag = testngXML.getDocument().getRootTag(); if (rootTag != null && rootTag.getName().equals("suite")) { try { XmlTag testTag = rootTag.findFirstSubTag("test"); if (testTag == null) { testTag = (XmlTag)rootTag.add(rootTag.createChildTag("test", rootTag.getNamespace(), null, false)); testTag.setAttribute("name", psiClass.getName()); } XmlTag classesTag = testTag.findFirstSubTag("classes"); if (classesTag == null) { classesTag = (XmlTag)testTag.add(testTag.createChildTag("classes", testTag.getNamespace(), null, false)); } final XmlTag classTag = (XmlTag)classesTag.add(classesTag.createChildTag("class", classesTag.getNamespace(), null, false)); final String qualifiedName = psiClass.getQualifiedName(); LOG.assertTrue(qualifiedName != null); classTag.setAttribute("name", qualifiedName); } catch (IncorrectOperationException e) { LOG.error(e); } } }
|
patchTestngXml
|
17,563
|
String () { return TestngBundle.message("inspection.undeclared.test.create.suite.fix"); }
|
getFamilyName
|
17,564
|
void (@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) { final PsiClass psiClass = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiClass.class); final VirtualFile file = FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFolderDescriptor(), project, null); if (file != null) { final PsiManager psiManager = PsiManager.getInstance(project); final PsiDirectory directory = psiManager.findDirectory(file); LOG.assertTrue(directory != null); WriteCommandAction.writeCommandAction(project, PsiFile.EMPTY_ARRAY).withName(getName()).run(() -> { XmlFile testngXml = (XmlFile)PsiFileFactory.getInstance(psiManager.getProject()) .createFileFromText("testng.xml", "<!DOCTYPE suite SYSTEM \"http://testng.org/testng-1.0.dtd\">\n<suite></suite>"); try { testngXml = (XmlFile)directory.add(testngXml); } catch (IncorrectOperationException e) { //todo suggest new name return; } patchTestngXml(testngXml, psiClass); }); } }
|
applyFix
|
17,565
|
boolean () { return false; }
|
startInWriteAction
|
17,566
|
boolean () { return ADD_TESTNG_TO_ENTRIES; }
|
isSelected
|
17,567
|
void (boolean selected) { ADD_TESTNG_TO_ENTRIES = selected; }
|
setSelected
|
17,568
|
String () { return TestngBundle.message("testng.entry.point.test.cases"); }
|
getDisplayName
|
17,569
|
boolean (@NotNull RefElement refElement, @NotNull PsiElement psiElement) { return isEntryPoint(psiElement); }
|
isEntryPoint
|
17,570
|
boolean (@NotNull PsiElement psiElement) { if (psiElement instanceof PsiModifierListOwner) { if (TestNGUtil.hasTest((PsiModifierListOwner)psiElement, true, false, TestNGUtil.hasDocTagsSupport)) return true; return TestNGUtil.hasConfig((PsiModifierListOwner)psiElement); } return false; }
|
isEntryPoint
|
17,571
|
MyRunProfile (@NotNull ExecutionEnvironment environment) { final TestNGConfiguration configuration = (TestNGConfiguration)myConsoleProperties.getConfiguration(); final List<AbstractTestProxy> failedTests = getFailedTests(configuration.getProject()); return new MyRunProfile(configuration) { @Override public Module @NotNull [] getModules() { return configuration.getModules(); } @Override public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) { return new TestNGRunnableState(env, configuration) { @Override public SearchForTestsTask createSearchingForTestsTask() { return createSearchingForTestsTask(new LocalTargetEnvironment(new LocalTargetEnvironmentRequest())); } @Override public SearchForTestsTask createSearchingForTestsTask(@NotNull TargetEnvironment targetEnvironment) { return new SearchingForTestsTask(getServerSocket(), getConfiguration(), myTempFile) { @Override protected void fillTestObjects(final Map<PsiClass, Map<PsiMethod, List<String>>> classes) throws CantRunException { final HashMap<PsiClass, Map<PsiMethod, List<String>>> fullClassList = new HashMap<>(); super.fillTestObjects(fullClassList); for (final PsiClass aClass : fullClassList.keySet()) { if (!ReadAction.compute(() -> TestNGUtil.hasTest(aClass))) { classes.put(aClass, fullClassList.get(aClass)); } } final GlobalSearchScope scope = getConfiguration().getConfigurationModule().getSearchScope(); final Project project = getConfiguration().getProject(); for (final AbstractTestProxy proxy : failedTests) { ApplicationManager.getApplication().runReadAction(() -> includeFailedTestWithDependencies(classes, scope, project, proxy)); } } }; } }; } }; }
|
getRunProfile
|
17,572
|
RunProfileState (@NotNull Executor executor, @NotNull ExecutionEnvironment env) { return new TestNGRunnableState(env, configuration) { @Override public SearchForTestsTask createSearchingForTestsTask() { return createSearchingForTestsTask(new LocalTargetEnvironment(new LocalTargetEnvironmentRequest())); } @Override public SearchForTestsTask createSearchingForTestsTask(@NotNull TargetEnvironment targetEnvironment) { return new SearchingForTestsTask(getServerSocket(), getConfiguration(), myTempFile) { @Override protected void fillTestObjects(final Map<PsiClass, Map<PsiMethod, List<String>>> classes) throws CantRunException { final HashMap<PsiClass, Map<PsiMethod, List<String>>> fullClassList = new HashMap<>(); super.fillTestObjects(fullClassList); for (final PsiClass aClass : fullClassList.keySet()) { if (!ReadAction.compute(() -> TestNGUtil.hasTest(aClass))) { classes.put(aClass, fullClassList.get(aClass)); } } final GlobalSearchScope scope = getConfiguration().getConfigurationModule().getSearchScope(); final Project project = getConfiguration().getProject(); for (final AbstractTestProxy proxy : failedTests) { ApplicationManager.getApplication().runReadAction(() -> includeFailedTestWithDependencies(classes, scope, project, proxy)); } } }; } }; }
|
getState
|
17,573
|
SearchForTestsTask () { return createSearchingForTestsTask(new LocalTargetEnvironment(new LocalTargetEnvironmentRequest())); }
|
createSearchingForTestsTask
|
17,574
|
SearchForTestsTask (@NotNull TargetEnvironment targetEnvironment) { return new SearchingForTestsTask(getServerSocket(), getConfiguration(), myTempFile) { @Override protected void fillTestObjects(final Map<PsiClass, Map<PsiMethod, List<String>>> classes) throws CantRunException { final HashMap<PsiClass, Map<PsiMethod, List<String>>> fullClassList = new HashMap<>(); super.fillTestObjects(fullClassList); for (final PsiClass aClass : fullClassList.keySet()) { if (!ReadAction.compute(() -> TestNGUtil.hasTest(aClass))) { classes.put(aClass, fullClassList.get(aClass)); } } final GlobalSearchScope scope = getConfiguration().getConfigurationModule().getSearchScope(); final Project project = getConfiguration().getProject(); for (final AbstractTestProxy proxy : failedTests) { ApplicationManager.getApplication().runReadAction(() -> includeFailedTestWithDependencies(classes, scope, project, proxy)); } } }; }
|
createSearchingForTestsTask
|
17,575
|
void (Map<PsiClass, Map<PsiMethod, List<String>>> classes, GlobalSearchScope scope, Project project, AbstractTestProxy proxy) { final Location location = proxy.getLocation(project, scope); if (location != null) { final PsiElement element = location.getPsiElement(); if (element instanceof PsiMethod psiMethod && element.isValid()) { PsiClass psiClass = psiMethod.getContainingClass(); if (psiClass != null && psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) { final AbstractTestProxy parent = proxy.getParent(); final PsiElement elt = parent != null ? parent.getLocation(project, scope).getPsiElement() : null; if (elt instanceof PsiClass) { psiClass = (PsiClass)elt; } } TestNGTestObject.collectTestMethods(classes, psiClass, psiMethod.getName(), scope); Map<PsiMethod, List<String>> psiMethods = classes.get(psiClass); if (psiMethods == null) { psiMethods = new LinkedHashMap<>(); classes.put(psiClass, psiMethods); } List<String> strings = psiMethods.get(psiMethod); if (strings == null || strings.isEmpty()) { strings = new ArrayList<>(); } setupParameterName(location, strings); psiMethods.put(psiMethod, strings); } } }
|
includeFailedTestWithDependencies
|
17,576
|
void (Location location, List<String> strings) { if (location instanceof PsiMemberParameterizedLocation) { final String paramSetName = ((PsiMemberParameterizedLocation)location).getParamSetName(); if (paramSetName != null) { strings.add(TestNGConfigurationProducer.getInvocationNumber(paramSetName)); } } }
|
setupParameterName
|
17,577
|
Set<String> (TestNGConfiguration configuration) { return configuration.getPersistantData().getPatterns(); }
|
getPattern
|
17,578
|
boolean (RunConfiguration configuration) { return configuration instanceof TestNGConfiguration && TestType.PATTERN.getType().equals(((TestNGConfiguration)configuration).getPersistantData().TEST_OBJECT); }
|
isPatternBasedConfiguration
|
17,579
|
AbstractTestNGPatternConfigurationProducer () { return RunConfigurationProducer.getInstance(TestNGPatternConfigurationProducer.class); }
|
getPatternBasedProducer
|
17,580
|
ConfigurationType () { return TestNGConfigurationType.getInstance(); }
|
getConfigurationType
|
17,581
|
boolean (TestNGConfiguration configuration) { return TestType.PATTERN.getType().equals(configuration.getPersistantData().TEST_OBJECT); }
|
isPatternBasedConfiguration
|
17,582
|
Set<String> (TestNGConfiguration configuration) { return configuration.getPersistantData().getPatterns(); }
|
getPatterns
|
17,583
|
ExternalClassResolveResult (@NotNull String shortClassName, @NotNull ThreeState isAnnotation, @NotNull Module contextModule) { if (TEST_NG_ANNOTATIONS.contains(shortClassName)) { return new ExternalClassResolveResult("org.testng.annotations." + shortClassName, TESTNG_DESCRIPTOR); } return null; }
|
resolveClass
|
17,584
|
String[] (@NotNull PsiFile file) { return TestNGUtil.CONFIG_ANNOTATIONS_FQN; }
|
getAnnotations
|
17,585
|
int () { return listenerList.size(); }
|
getSize
|
17,586
|
Object (int i) { return listenerList.get(i); }
|
getElementAt
|
17,587
|
void (List<String> listenerList) { this.listenerList.clear(); this.listenerList.addAll(listenerList); fireContentsChanged(this, 0, 0); }
|
setListenerList
|
17,588
|
List<String> () { return listenerList; }
|
getListenerList
|
17,589
|
void (String listener) { listenerList.add(listener); fireContentsChanged(this, 0, 0); }
|
addListener
|
17,590
|
void (int rowIndex) { listenerList.remove(rowIndex); fireContentsChanged(this, 0, 0); }
|
removeListener
|
17,591
|
String () { return type; }
|
getType
|
17,592
|
int () { return value; }
|
getValue
|
17,593
|
String () { return myConfig.getPersistantData().getSuiteName(); }
|
getGeneratedName
|
17,594
|
String () { String suiteName = myConfig.getPersistantData().getSuiteName(); if (!suiteName.isEmpty()) { VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(suiteName); if (virtualFile != null) { return ProjectUtilCore.displayUrlRelativeToProject(virtualFile, virtualFile.getPresentableUrl(), myConfig.getProject(), true, false); } } return suiteName; }
|
getActionName
|
17,595
|
boolean (PsiElement element) { final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element); return virtualFile != null && Comparing.strEqual(myConfig.getPersistantData().getSuiteName(), virtualFile.getPath()); }
|
isConfiguredByElement
|
17,596
|
TestSearchScope () { return TEST_SEARCH_SCOPE.getScope(); }
|
getScope
|
17,597
|
void (TestSearchScope testseachscope) { TEST_SEARCH_SCOPE.setScope(testseachscope); }
|
setScope
|
17,598
|
String () { return PROPERTIES_FILE == null ? "" : PROPERTIES_FILE; }
|
getPropertiesFile
|
17,599
|
String () { return OUTPUT_DIRECTORY == null ? "" : OUTPUT_DIRECTORY; }
|
getOutputDirectory
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.