use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.
the class CustomAnnotationChecker method checkAnnotationArguments.
public static void checkAnnotationArguments(@NotNull AnnotationHolder holder, @NotNull PsiClass annotation, @NotNull GrCodeReferenceElement refToHighlight, @NotNull GrAnnotationNameValuePair[] attributes, boolean checkMissedAttributes) {
Set<String> usedAttrs = new HashSet<>();
if (attributes.length > 0) {
final PsiElement identifier = attributes[0].getNameIdentifierGroovy();
if (attributes.length == 1 && identifier == null) {
checkAnnotationValue(annotation, attributes[0], "value", usedAttrs, attributes[0].getValue(), holder);
} else {
for (GrAnnotationNameValuePair attribute : attributes) {
final String name = attribute.getName();
if (name != null) {
final PsiElement toHighlight = attribute.getNameIdentifierGroovy();
assert toHighlight != null;
checkAnnotationValue(annotation, toHighlight, name, usedAttrs, attribute.getValue(), holder);
}
}
}
}
List<String> missedAttrs = new ArrayList<>();
final PsiMethod[] methods = annotation.getMethods();
for (PsiMethod method : methods) {
final String name = method.getName();
if (usedAttrs.contains(name) || method instanceof PsiAnnotationMethod && ((PsiAnnotationMethod) method).getDefaultValue() != null) {
continue;
}
missedAttrs.add(name);
}
if (checkMissedAttributes && !missedAttrs.isEmpty()) {
holder.createErrorAnnotation(refToHighlight, GroovyBundle.message("missed.attributes", StringUtil.join(missedAttrs, ", ")));
}
}
use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.
the class GroovyAnnotator method checkRecursiveConstructors.
private static void checkRecursiveConstructors(AnnotationHolder holder, PsiMethod[] constructors) {
Map<PsiMethod, PsiMethod> nodes = new HashMap<>(constructors.length);
Set<PsiMethod> set = ContainerUtil.set(constructors);
for (PsiMethod constructor : constructors) {
if (!(constructor instanceof GrMethod))
continue;
final GrOpenBlock block = ((GrMethod) constructor).getBlock();
if (block == null)
continue;
final GrStatement[] statements = block.getStatements();
if (statements.length <= 0 || !(statements[0] instanceof GrConstructorInvocation))
continue;
final PsiMethod resolved = ((GrConstructorInvocation) statements[0]).resolveMethod();
if (!set.contains(resolved))
continue;
nodes.put(constructor, resolved);
}
Set<PsiMethod> checked = new HashSet<>();
Set<PsiMethod> current;
for (PsiMethod constructor : constructors) {
if (!checked.add(constructor))
continue;
current = new HashSet<>();
current.add(constructor);
for (constructor = nodes.get(constructor); constructor != null && current.add(constructor); constructor = nodes.get(constructor)) {
checked.add(constructor);
}
if (constructor != null) {
PsiMethod circleStart = constructor;
do {
holder.createErrorAnnotation(GrHighlightUtil.getMethodHeaderTextRange(constructor), GroovyBundle.message("recursive.constructor.invocation"));
constructor = nodes.get(constructor);
} while (constructor != circleStart);
}
}
}
use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.
the class GroovyDslFileIndex method getBundledScriptFolders.
@NotNull
private static Set<File> getBundledScriptFolders() {
final GdslScriptProvider[] extensions = GdslScriptProvider.EP_NAME.getExtensions();
final Set<Class> classes = new HashSet<>(ContainerUtil.map(extensions, GdslScriptProvider::getClass));
// for default extension
classes.add(GdslScriptProvider.class);
Set<File> scriptFolders = new LinkedHashSet<>();
for (Class aClass : classes) {
File jarPath = new File(PathUtil.getJarPathForClass(aClass));
if (jarPath.isFile()) {
jarPath = jarPath.getParentFile();
}
scriptFolders.add(new File(jarPath, "standardDsls"));
}
return scriptFolders;
}
use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.
the class PsiUtil method iterateSupers.
public static Iterable<PsiClass> iterateSupers(@NotNull final PsiClass psiClass, final boolean includeSelf) {
return new Iterable<PsiClass>() {
@Override
public Iterator<PsiClass> iterator() {
return new Iterator<PsiClass>() {
TIntStack indices = new TIntStack();
Stack<PsiClassType[]> superTypesStack = new Stack<>();
PsiClass current;
boolean nextObtained;
Set<PsiClass> visited = new HashSet<>();
{
if (includeSelf) {
current = psiClass;
nextObtained = true;
} else {
current = null;
nextObtained = false;
}
pushSuper(psiClass);
}
@Override
public boolean hasNext() {
nextElement();
return current != null;
}
private void nextElement() {
if (nextObtained)
return;
nextObtained = true;
while (!superTypesStack.empty()) {
assert indices.size() > 0;
int i = indices.pop();
PsiClassType[] superTypes = superTypesStack.peek();
while (i < superTypes.length) {
PsiClass clazz = superTypes[i].resolve();
if (clazz != null && !visited.contains(clazz)) {
current = clazz;
visited.add(clazz);
indices.push(i + 1);
pushSuper(clazz);
return;
}
i++;
}
superTypesStack.pop();
}
current = null;
}
private void pushSuper(PsiClass clazz) {
superTypesStack.push(clazz.getSuperTypes());
indices.push(0);
}
@Override
@NotNull
public PsiClass next() {
nextElement();
nextObtained = false;
if (current == null)
throw new NoSuchElementException();
return current;
}
@Override
public void remove() {
throw new IllegalStateException("should not be called");
}
};
}
};
}
use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.
the class OfflineInspectionRVContentProvider method excludeProblem.
private static void excludeProblem(final String externalName, final Map<String, Set<OfflineProblemDescriptor>> content) {
for (Iterator<String> iter = content.keySet().iterator(); iter.hasNext(); ) {
final String packageName = iter.next();
final Set<OfflineProblemDescriptor> excluded = new HashSet<>(content.get(packageName));
for (Iterator<OfflineProblemDescriptor> it = excluded.iterator(); it.hasNext(); ) {
final OfflineProblemDescriptor ex = it.next();
if (Comparing.strEqual(ex.getFQName(), externalName)) {
it.remove();
}
}
if (excluded.isEmpty()) {
iter.remove();
} else {
content.put(packageName, excluded);
}
}
}
Aggregations