use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.
the class DependsOnMethodInspection method checkClass.
@Override
@Nullable
public ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
PsiAnnotation[] annotations = TestNGUtil.getTestNGAnnotations(psiClass);
if (annotations.length == 0)
return ProblemDescriptor.EMPTY_ARRAY;
List<ProblemDescriptor> problemDescriptors = new ArrayList<>();
for (PsiAnnotation annotation : annotations) {
final PsiAnnotationMemberValue value = annotation.findDeclaredAttributeValue("dependsOnMethods");
if (value != null && !TestNGUtil.isDisabled(annotation)) {
String text = value.getText();
if (value instanceof PsiReferenceExpression) {
final PsiElement resolve = ((PsiReferenceExpression) value).resolve();
if (resolve instanceof PsiField && ((PsiField) resolve).hasModifierProperty(PsiModifier.STATIC) && ((PsiField) resolve).hasModifierProperty(PsiModifier.FINAL)) {
final PsiExpression initializer = ((PsiField) resolve).getInitializer();
if (initializer != null) {
text = initializer.getText();
}
}
}
final Set<String> names = new HashSet<>();
final Matcher matcher = PATTERN.matcher(text);
int idx = 0;
while (matcher.find()) {
String methodName = matcher.group(1);
if (!names.add(methodName)) {
PsiAnnotationMemberValue element2Highlight = value;
if (value instanceof PsiArrayInitializerMemberValue) {
final PsiAnnotationMemberValue[] initializers = ((PsiArrayInitializerMemberValue) value).getInitializers();
if (idx < initializers.length) {
element2Highlight = initializers[idx];
}
}
problemDescriptors.add(manager.createProblemDescriptor(element2Highlight, "Duplicated method name: " + methodName, (LocalQuickFix) null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly));
}
checkMethodNameDependency(manager, psiClass, methodName, value, problemDescriptors, isOnTheFly);
idx++;
}
}
}
return problemDescriptors.toArray(new ProblemDescriptor[problemDescriptors.size()]);
}
use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.
the class ResourceBundleFileStructureViewElement method getChildren.
@NotNull
public synchronized StructureViewTreeElement[] getChildren() {
final MultiMap<String, IProperty> propertyNames = getPropertiesMap(myResourceBundle, myShowOnlyIncomplete);
final HashSet<String> remains = new HashSet<>(myElements.keySet());
for (Map.Entry<String, Collection<IProperty>> entry : propertyNames.entrySet()) {
final String propKey = entry.getKey();
Collection<IProperty> properties = entry.getValue();
final ResourceBundlePropertyStructureViewElement oldPropertyNode = myElements.get(propKey);
if (oldPropertyNode != null && properties.contains(oldPropertyNode.getProperty())) {
remains.remove(propKey);
continue;
}
final IProperty representative = properties.iterator().next();
myElements.put(propKey, new ResourceBundlePropertyStructureViewElement(representative));
}
for (String remain : remains) {
myElements.remove(remain);
}
return myElements.values().toArray(StructureViewTreeElement.EMPTY_ARRAY);
}
use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.
the class CommandLineSuggestionTest method ensureSuggestions.
/**
* @param initialPositionText place to move cusor to
* @param expectedSuggestions expected suggestions
*/
private void ensureSuggestions(@NotNull final String initialPositionText, @NotNull final String... expectedSuggestions) {
moveByText(initialPositionText);
final Set<String> completions = new HashSet<>();
for (final LookupElement element : myFixture.completeBasic()) {
completions.add(element.getLookupString());
}
Assert.assertThat("Bad suggestions", completions, Matchers.containsInAnyOrder(expectedSuggestions));
}
use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.
the class GrRefactoringConflictsUtil method checkUsedElements.
public static void checkUsedElements(PsiMember member, PsiElement scope, @NotNull Set<GrMember> membersToMove, @Nullable Set<PsiMethod> abstractMethods, @Nullable PsiClass targetClass, @NotNull PsiElement context, MultiMap<PsiElement, String> conflicts) {
final Set<PsiMember> moving = new HashSet<>(membersToMove);
if (abstractMethods != null) {
moving.addAll(abstractMethods);
}
if (scope instanceof GrReferenceExpression) {
GrReferenceExpression refExpr = (GrReferenceExpression) scope;
PsiElement refElement = refExpr.resolve();
if (refElement instanceof PsiMember) {
if (!RefactoringHierarchyUtil.willBeInTargetClass(refElement, moving, targetClass, false)) {
GrExpression qualifier = refExpr.getQualifierExpression();
PsiClass accessClass = (PsiClass) (qualifier != null ? PsiUtil.getAccessObjectClass(qualifier).getElement() : null);
RefactoringConflictsUtil.checkAccessibility((PsiMember) refElement, context, accessClass, member, conflicts);
}
}
} else if (scope instanceof GrNewExpression) {
final GrNewExpression newExpression = (GrNewExpression) scope;
final GrAnonymousClassDefinition anonymousClass = newExpression.getAnonymousClassDefinition();
if (anonymousClass != null) {
if (!RefactoringHierarchyUtil.willBeInTargetClass(anonymousClass, moving, targetClass, false)) {
RefactoringConflictsUtil.checkAccessibility(anonymousClass, context, anonymousClass, member, conflicts);
}
} else {
final PsiMethod refElement = newExpression.resolveMethod();
if (refElement != null) {
if (!RefactoringHierarchyUtil.willBeInTargetClass(refElement, moving, targetClass, false)) {
RefactoringConflictsUtil.checkAccessibility(refElement, context, null, member, conflicts);
}
}
}
} else if (scope instanceof GrCodeReferenceElement) {
GrCodeReferenceElement refExpr = (GrCodeReferenceElement) scope;
PsiElement refElement = refExpr.resolve();
if (refElement instanceof PsiMember) {
if (!RefactoringHierarchyUtil.willBeInTargetClass(refElement, moving, targetClass, false)) {
RefactoringConflictsUtil.checkAccessibility((PsiMember) refElement, context, null, member, conflicts);
}
}
}
for (PsiElement child : scope.getChildren()) {
if (child instanceof PsiWhiteSpace || child instanceof PsiComment)
continue;
checkUsedElements(member, child, membersToMove, abstractMethods, targetClass, context, conflicts);
}
}
use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.
the class HgTestChangeListManager method checkFilesAreInList.
/**
* Updates the change list manager and checks that the given files are in the default change list.
* @param only Set this to true if you want ONLY the specified files to be in the change list.
* If set to false, the change list may contain some other files apart from the given ones.
* @param files Files to be checked.
*/
public void checkFilesAreInList(boolean only, VirtualFile... files) {
ensureUpToDate();
final Collection<Change> changes = peer.getDefaultChangeList().getChanges();
if (only) {
Assert.assertEquals(changes.size(), files.length);
}
final Collection<VirtualFile> filesInChangeList = new HashSet<>();
for (Change c : changes) {
filesInChangeList.add(c.getVirtualFile());
}
for (VirtualFile f : files) {
Assert.assertTrue(filesInChangeList.contains(f));
}
}
Aggregations