Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
33,000
boolean (@NotNull PsiElement place, @Nullable PsiElement lastParent, @NotNull PsiScopeProcessor processor, @NotNull PsiElement scope, @NotNull ResolveState state) { //state = ResolveState.initial(); if (scope instanceof GrTypeDefinition) { if (!processNonCodeMembers(createPsiType((GrTypeDefinition)scope), processor, place, state)) return false; //@Category(CategoryType) //class Scope {...} PsiClassType categoryType = GdkMethodUtil.getCategoryType((PsiClass)scope); if (categoryType != null) { if (!processNonCodeMembers(categoryType, processor, place, state)) return false; if (!GdkMethodUtil.processCategoryMethods(place, processor, state, (PsiClass)scope)) return false; } } if (scope instanceof GroovyFileBase && ((GroovyFileBase)scope).isScript()) { final PsiClass psiClass = ((GroovyFileBase)scope).getScriptClass(); if (psiClass != null) { if (!processNonCodeMembers(createPsiType(psiClass), processor, place, state)) return false; } } if (scope instanceof GrFunctionalExpression) { ResolveState _state = state.put(ClassHint.RESOLVE_CONTEXT, scope); if (!processNonCodeMembers(TypesUtil.createType(GROOVY_LANG_CLOSURE, scope), processor, place, _state)) return false; } if (scope instanceof GrStatementOwner) { if (!GdkMethodUtil.processMixinToMetaclass((GrStatementOwner)scope, processor, state, lastParent, place)) return false; GroovyInlineASTTransformationPerformer performer = GroovyInlineTransformationUtilKt.getHierarchicalInlineTransformationPerformer(scope); if (performer != null && !performer.processResolve(processor, state, place)) return false; } return true; }
processScopeNonCodeMembers
33,001
PsiClassType (@NotNull PsiClass psiClass) { PsiElementFactory factory = JavaPsiFacade.getElementFactory(psiClass.getProject()); return factory.createType(psiClass); }
createPsiType
33,002
boolean (@NotNull PsiScopeProcessor processor, @NotNull PsiNamedElement namedElement, @NotNull ResolveState state) { NameHint nameHint = processor.getHint(NameHint.KEY); String name = nameHint == null ? null : nameHint.getName(state); if (name == null || name.equals(namedElement.getName())) { return processor.execute(namedElement, state); } return true; }
processElement
33,003
boolean (@NotNull PsiType type, @NotNull PsiScopeProcessor processor, boolean processNonCodeMembers, @NotNull PsiElement place) { return processAllDeclarations(type, processor, initialState(processNonCodeMembers), place); }
processAllDeclarations
33,004
boolean (@NotNull PsiType type, @NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @NotNull PsiElement place) { return processReceiverType(type, processor, state, place); }
processAllDeclarations
33,005
boolean (@NotNull PsiType type, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) { if (type instanceof PsiEllipsisType) { type = ((PsiEllipsisType)type).toArrayType(); } return NonCodeMembersContributor.runContributors(type, processor, place, state); }
processNonCodeMembers
33,006
void (PsiType type, Set<? super String> visited, Project project) { String qName = rawCanonicalText(type); if (!(type instanceof PsiClassType && ((PsiClassType)type).resolve() instanceof PsiTypeParameter)) { if (!visited.add(qName)) { return; } } final PsiType[] superTypes = type.getSuperTypes(); for (PsiType superType : superTypes) { collectSuperTypes(TypeConversionUtil.erasure(superType), visited, project); } if (type instanceof PsiArrayType && superTypes.length == 0) { PsiType comparable = createTypeFromText(project, COMPARABLE, CommonClassNames.JAVA_LANG_COMPARABLE); PsiType serializable = createTypeFromText(project, SERIALIZABLE, CommonClassNames.JAVA_IO_SERIALIZABLE); collectSuperTypes(comparable, visited, project); collectSuperTypes(serializable, visited, project); } if (GroovyCommonClassNames.GROOVY_LANG_GSTRING.equals(qName)) { collectSuperTypes(createTypeFromText(project, STRING, CommonClassNames.JAVA_LANG_STRING), visited, project); } }
collectSuperTypes
33,007
PsiType (Project project, Key<PsiType> key, String text) { final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); PsiType type = project.getUserData(key); if (type == null) { type = factory.createTypeFromText(text, null); project.putUserData(key, type); } return type; }
createTypeFromText
33,008
Set<String> (@NotNull PsiType base, final Project project) { final Map<String, Set<String>> cache = CachedValuesManager.getManager(project).getCachedValue(project, () -> { final Map<String, Set<String>> result = new ConcurrentHashMap<>(); return CachedValueProvider.Result.create(result, PsiModificationTracker.MODIFICATION_COUNT); }); final PsiClass cls = PsiUtil.resolveClassInType(base); String key; if (cls instanceof PsiTypeParameter) { final PsiClass superClass = cls.getSuperClass(); key = cls.getName() + (superClass == null ? CommonClassNames.JAVA_LANG_OBJECT : superClass.getName()); } else if (base instanceof PsiClassType) { key = TypesUtil.getQualifiedName(base); } else { key = base.getCanonicalText(); } Set<String> result = key == null ? null : cache.get(key); if (result == null) { result = new HashSet<>(); collectSuperTypes(base, result, project); if (key != null) { cache.put(key, result); } } return result; }
getAllSuperTypes
33,009
String (@NotNull PsiType type) { if (type instanceof PsiClassType) { String qname = TypesUtil.getQualifiedName(type); if (qname != null) { return qname; } } return TypeConversionUtil.erasure(type).getCanonicalText(); }
rawCanonicalText
33,010
GroovyPsiElement (GroovyPsiElement place, String name) { PropertyResolverProcessor processor = new PropertyResolverProcessor(name, place); return resolveExistingElement(place, processor, GrVariable.class, GrReferenceExpression.class); }
resolveProperty
33,011
boolean (PsiElement element, String labelName) { return ((element instanceof GrLabeledStatement && labelName.equals(((GrLabeledStatement)element).getName()))); }
isApplicableLabelStatement
33,012
boolean (@NotNull PsiElement place, @NotNull PsiScopeProcessor processor, @NotNull ResolveState state) { PsiElement run = place; PsiElement lastParent = null; while (run != null) { ProgressManager.checkCanceled(); if (run instanceof GrStatementOwner) { if (!GdkMethodUtil.processMixinToMetaclass((GrStatementOwner)run, processor, state, lastParent, place)) return false; } lastParent = run; run = run.getContext(); } return true; }
processCategoryMembers
33,013
PsiElement[] (GroovyResolveResult[] candidates) { return PsiUtil.mapElements(candidates); }
mapToElements
33,014
GroovyResolveResult[] (Collection<? extends GroovyResolveResult> candidates) { if (candidates.size() == 0) return GroovyResolveResult.EMPTY_ARRAY; if (candidates.size() == 1) return candidates.toArray(GroovyResolveResult.EMPTY_ARRAY); final List<GroovyResolveResult> result = new ArrayList<>(); final Iterator<? extends GroovyResolveResult> allIterator = candidates.iterator(); Map<String, List<GroovyResolveResult>> cache = new HashMap<>(candidates.size()); while (allIterator.hasNext()) { final GroovyResolveResult currentResult = allIterator.next(); final PsiMethod currentMethod; final PsiSubstitutor currentSubstitutor; if (currentResult instanceof GroovyMethodResult currentMethodResult) { currentMethod = currentMethodResult.getElement(); currentSubstitutor = currentMethodResult.getContextSubstitutor(); } else if (currentResult.getElement() instanceof PsiMethod) { currentMethod = (PsiMethod)currentResult.getElement(); currentSubstitutor = currentResult.getSubstitutor(); } else { result.add(currentResult); continue; } boolean isDominated = false; List<GroovyResolveResult> existingCandidates = cache.computeIfAbsent(getKey(currentMethod), (__) -> new SmartList<>()); for (Iterator<GroovyResolveResult> iterator = existingCandidates.listIterator(); iterator.hasNext();) { GroovyResolveResult candidateResult = iterator.next(); final PsiMethod otherMethod; final PsiSubstitutor otherSubstitutor; if (candidateResult instanceof GroovyMethodResult otherMethodResult) { otherMethod = otherMethodResult.getElement(); otherSubstitutor = otherMethodResult.getContextSubstitutor(); } else if (candidateResult.getElement() instanceof PsiMethod) { otherMethod = (PsiMethod)candidateResult.getElement(); otherSubstitutor = candidateResult.getSubstitutor(); } else { continue; } if (dominated(currentMethod, currentSubstitutor, otherMethod, otherSubstitutor)) { // if current method is dominated by other method // then do not add current method to result and skip rest other methods isDominated = true; break; } else if (dominated(otherMethod, otherSubstitutor, currentMethod, currentSubstitutor)) { // if other method is dominated by current method // then remove other from result iterator.remove(); } } if (!isDominated) { existingCandidates.add(currentResult); } } for (List<GroovyResolveResult> resultsByName : cache.values()) { result.addAll(resultsByName); } return result.toArray(GroovyResolveResult.EMPTY_ARRAY); }
filterSameSignatureCandidates
33,015
String (PsiMethod method) { int parameters = method.getParameters().length; String name = method.getName(); return parameters + "_" + name; }
getKey
33,016
boolean (PsiMethod method1, PsiSubstitutor substitutor1, PsiMethod method2, PsiSubstitutor substitutor2) { //method1 has more general parameter types then method2 if (!method1.getName().equals(method2.getName())) return false; PsiParameter[] params1 = method1.getParameterList().getParameters(); PsiParameter[] params2 = method2.getParameterList().getParameters(); if (params1.length != params2.length) return false; for (int i = 0; i < params2.length; i++) { PsiType pType1 = params1[i].getType(); if (pType1 instanceof PsiEllipsisType) { pType1 = ((PsiEllipsisType)pType1).getComponentType().createArrayType(); } PsiType pType2 = params2[i].getType(); if (pType2 instanceof PsiEllipsisType) { pType2 = ((PsiEllipsisType)pType2).getComponentType().createArrayType(); } PsiType type1 = TypeConversionUtil.erasure(substitutor1.substitute(pType1)); PsiType type2 = TypeConversionUtil.erasure(substitutor2.substitute(pType2)); if (!type1.equals(type2)) return false; } if (method1 instanceof GrGdkMethod && method2 instanceof GrGdkMethod) { PsiType t1 = substitutor1.substitute(((GrGdkMethod)method1).getReceiverType()); PsiType t2 = substitutor2.substitute(((GrGdkMethod)method2).getReceiverType()); if (!t1.equals(t2)) { if (t1 instanceof PsiClassType) t1 = TypeConversionUtil.erasure(t1); if (t2 instanceof PsiClassType) t2 = TypeConversionUtil.erasure(t2); //method1 is more general than method2 return t1.isAssignableFrom(t2); } } if (GdkMethodUtil.isMacro(method1)) { // macro expansion happens during compilation, so macros always win overload resolution return false; } return true; }
dominated
33,017
GroovyResolveResult[] (GroovyPsiElement place) { final PsiElement parent = place.getParent(); GroovyResolveResult[] variants = GroovyResolveResult.EMPTY_ARRAY; if (parent instanceof GrCallExpression) { variants = ((GrCallExpression)parent).getCallVariants(place instanceof GrExpression ? (GrExpression)place : null); } else if (parent instanceof GrConstructorInvocation) { final PsiClass clazz = ((GrConstructorInvocation)parent).getDelegatedClass(); if (clazz != null) { final PsiMethod[] constructors = clazz.getConstructors(); variants = getConstructorResolveResult(constructors, place); } } else if (parent instanceof GrAnonymousClassDefinition) { final PsiElement element = ((GrAnonymousClassDefinition)parent).getBaseClassReferenceGroovy().resolve(); if (element instanceof PsiClass) { final PsiMethod[] constructors = ((PsiClass)element).getConstructors(); variants = getConstructorResolveResult(constructors, place); } } else if (place instanceof GrReferenceExpression) { variants = ((GrReferenceExpression)place).getSameNameVariants(); } return variants; }
getCallVariants
33,018
GroovyResolveResult[] (PsiMethod[] constructors, PsiElement place) { GroovyResolveResult[] variants = new GroovyResolveResult[constructors.length]; for (int i = 0; i < constructors.length; i++) { final boolean isAccessible = PsiUtil.isAccessible(constructors[i], place, null); variants[i] = new GroovyResolveResultImpl(constructors[i], isAccessible); } return variants; }
getConstructorResolveResult
33,019
boolean (GrReferenceExpression ref) { if (!(ref.getParent() instanceof GrIndexProperty) && org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isCall(ref)) return false; // TODO separate element for spread expression if (ref.getDotTokenType() == GroovyTokenTypes.mSPREAD_DOT) return false; return ref.resolve() instanceof GroovyMapProperty; }
isKeyOfMap
33,020
boolean (@Nullable PsiType type, PsiType @Nullable [] argTypes, @NotNull PsiElement place) { if (!(type instanceof GrClosureType)) { if (type instanceof GroovyClosureType) { throw new RuntimeException(); } return false; } if (argTypes == null) return true; final List<GrSignature> signature = ((GrClosureType)type).getSignatures(); return GrClosureSignatureUtil.isSignatureApplicable(signature, argTypes, place); }
isApplicableClosureType
33,021
boolean (PsiReference ref, String name, String qName) { PsiElement resolved = ref.resolve(); if (!(resolved instanceof PsiEnumConstant)) return false; if (!name.equals(((PsiEnumConstant)resolved).getName())) return false; PsiClass aClass = ((PsiEnumConstant)resolved).getContainingClass(); if (aClass == null) return false; return qName.equals(aClass.getQualifiedName()); }
isEnumConstant
33,022
boolean (GrVariable var) { PsiElement parent = var.getParent(); return parent instanceof GrVariableDeclaration && isScriptFieldDeclaration(((GrVariableDeclaration)parent)); }
isScriptField
33,023
boolean (@NotNull GrVariableDeclaration declaration) { PsiFile containingFile = declaration.getContainingFile(); if (!(containingFile instanceof GroovyFile) || !((GroovyFile)containingFile).isScript()) return false; GrMember member = PsiTreeUtil.getParentOfType(declaration, GrTypeDefinition.class, GrMethod.class); if (member != null) return false; return hasAnnotation(declaration.getModifierList(), GroovyCommonClassNames.GROOVY_TRANSFORM_FIELD); }
isScriptFieldDeclaration
33,024
boolean (@NotNull GrVariableDeclaration declaration) { return declaration.getParent() instanceof GrTypeDefinitionBody || isScriptFieldDeclaration(declaration); }
isFieldDeclaration
33,025
PsiNamedElement (@NotNull GrVariable variable) { if (isScriptField(variable)) { final String name = variable.getName(); final GroovyScriptClass script = (GroovyScriptClass)((GroovyFile)variable.getContainingFile()).getScriptClass(); assert script != null; List<GrField> duplicates = ContainerUtil.filter(script.getFields(), (GrField f) -> { if (!(f instanceof GrScriptField)) return false; if (!name.equals(f.getName())) return false; if (((GrScriptField)f).getOriginalVariable() == variable) return false; return true; }); return duplicates.size() > 0 ? duplicates.get(0) : null; } else { PsiNamedElement duplicate = treeWalkUpAndGetElement(variable, new DuplicateVariableProcessor(variable)); final PsiElement context1 = variable.getContext(); if (duplicate == null && variable instanceof GrParameter && context1 != null) { final PsiElement context = context1.getContext(); if (context instanceof GrClosableBlock || context instanceof GrMethod && !(context.getParent() instanceof GroovyFile) || context instanceof GrTryCatchStatement) { duplicate = treeWalkUpAndGetElement(context.getParent(), new DuplicateVariableProcessor(variable)); } } if (duplicate instanceof GrLightParameter && "args".equals(duplicate.getName())) { return null; } else { return duplicate; } } }
findDuplicate
33,026
boolean (final GrReferenceExpression ref) { GrExpression qualifier = ref.getQualifier(); if (qualifier instanceof GrReferenceExpression) { final PsiElement resolvedQualifier = ((GrReferenceExpression)qualifier).resolve(); return resolvedQualifier instanceof PsiClass || resolvedQualifier instanceof PsiPackage; } else { return qualifier == null; } }
canBeClassOrPackage
33,027
boolean (ElementClassHint classHint) { return classHint == null || classHint.shouldProcess(DeclarationKind.CLASS); }
shouldProcessClasses
33,028
boolean (ElementClassHint classHint) { return classHint == null || classHint.shouldProcess(DeclarationKind.METHOD); }
shouldProcessMethods
33,029
boolean (ElementClassHint classHint) { return classHint == null || classHint.shouldProcess(DeclarationKind.VARIABLE) || classHint.shouldProcess(DeclarationKind.FIELD) || classHint.shouldProcess(DeclarationKind.ENUM_CONST); }
shouldProcessProperties
33,030
boolean (@NotNull PsiScopeProcessor resolver, @NotNull PsiFile file, @NotNull ResolveState state, @NotNull PsiElement place) { if (!shouldProcessMethods(resolver.getHint(ElementClassHint.KEY))) return true; return file.processDeclarations(new GrDelegatingScopeProcessorWithHints(resolver, null, ClassHint.RESOLVE_KINDS_METHOD) { @Override public boolean execute(@NotNull PsiElement element, @NotNull ResolveState _state) { if (_state.get(ClassHint.RESOLVE_CONTEXT) instanceof GrImportStatement) { super.execute(element, _state); } return true; } }, state, null, place); }
processStaticImports
33,031
boolean (@NotNull PsiElement element, @NotNull ResolveState _state) { if (_state.get(ClassHint.RESOLVE_CONTEXT) instanceof GrImportStatement) { super.execute(element, _state); } return true; }
execute
33,032
boolean (@Nullable PsiElement expression) { if (!(expression instanceof GrQualifiedReference)) return false; return isClassReference(expression) || ((GrQualifiedReference<?>)expression).resolve() instanceof PsiClass; }
resolvesToClass
33,033
boolean (@NotNull PsiElement expression) { if (!(expression instanceof GrReferenceExpression ref)) return false; GrExpression qualifier = ref.getQualifier(); if (!"class".equals(ref.getReferenceName())) return false; return qualifier != null && getClassReferenceFromExpression(qualifier) != null; }
isClassReference
33,034
boolean (@NotNull PsiElement place, @NotNull PsiNamedElement namedElement) { if (namedElement instanceof GrField field) { if (org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isAccessible(place, field)) { return true; } for (GrAccessorMethod method : field.getGetters()) { if (org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isAccessible(place, method)) { return true; } } final GrAccessorMethod setter = field.getSetter(); if (setter != null && org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isAccessible(place, setter)) { return true; } return false; } return !(namedElement instanceof PsiMember) || org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isAccessible(place, ((PsiMember)namedElement)); }
isAccessible
33,035
boolean (@NotNull PsiElement place, @NotNull PsiNamedElement element, @Nullable PsiElement resolveContext, boolean filterStaticAfterInstanceQualifier) { if (resolveContext instanceof GrImportStatement) return true; if (element instanceof PsiModifierListOwner) { return GrStaticChecker.isStaticsOK((PsiModifierListOwner)element, place, resolveContext, filterStaticAfterInstanceQualifier); } return true; }
isStaticsOK
33,036
boolean (@NotNull GrReferenceExpression ref) { assert !ref.hasMemberPointer(); return ref.getParent() instanceof GrMethodCall; }
canResolveToMethod
33,037
boolean (@NotNull PsiClass scope, @NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) { for (PsiScopeProcessor each : MultiProcessor.allProcessors(processor)) { if (!scope.processDeclarations(each, state, lastParent, place)) return false; } return true; }
processClassDeclarations
33,038
String () { return GROOVY_LANG_CLOSURE; }
getParentClassName
33,039
void (@NotNull PsiType qualifierType, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) { final PsiElement context = state.get(ClassHint.RESOLVE_CONTEXT); if (!(context instanceof GrClosableBlock)) return; processMembers((GrClosableBlock)context, processor, place, state); }
processDynamicElements
33,040
PsiType () { List<GrStatement> returns = ControlFlowUtils.collectReturns(myBlock); if (returns.isEmpty()) return PsiTypes.voidType(); PsiType result = null; PsiManager manager = myBlock.getManager(); for (GrStatement returnStatement : returns) { GrExpression value = null; if (returnStatement instanceof GrReturnStatement) { value = ((GrReturnStatement)returnStatement).getReturnValue(); } else if (returnStatement instanceof GrExpression) { value = (GrExpression)returnStatement; } if (value != null) { result = TypesUtil.getLeastUpperBoundNullable(result, value.getType(), manager); } } return result; }
compute
33,041
void (@NotNull PsiReferenceRegistrar registrar) { registrar.registerReferenceProvider(GroovyPatterns.stringLiteral(), new MyProvider()); }
registerReferenceProviders
33,042
PsiReference[] (@NotNull PsiElement element, GrNamedArgument namedArgument, @NotNull ProcessingContext context) { String labelName = namedArgument.getLabelName(); if (labelName == null) return PsiReference.EMPTY_ARRAY; if (!GroovyMethodInfo.getAllSupportedNamedArguments().contains(labelName)) { // Optimization: avoid unnecessary resolve. return PsiReference.EMPTY_ARRAY; } PsiElement call = PsiUtil.getCallByNamedParameter(namedArgument); if (!(call instanceof GrMethodCall)) return PsiReference.EMPTY_ARRAY; GrExpression invokedExpression = ((GrMethodCall)call).getInvokedExpression(); if (!(invokedExpression instanceof GrReferenceExpression)) return PsiReference.EMPTY_ARRAY; for (GroovyResolveResult result : ((GrReferenceExpression)invokedExpression).multiResolve(false)) { PsiElement eMethod = result.getElement(); if (!(eMethod instanceof PsiMethod method)) continue; for (GroovyMethodInfo info : GroovyMethodInfo.getInfos(method)) { Object referenceProvider = info.getNamedArgReferenceProvider(labelName); if (referenceProvider != null) { PsiReference[] refs; if (referenceProvider instanceof GroovyNamedArgumentReferenceProvider) { refs = ((GroovyNamedArgumentReferenceProvider)referenceProvider).createRef(element, namedArgument, result, context); } else { refs = ((PsiReferenceProvider)referenceProvider).getReferencesByElement(element, context); } if (refs.length > 0) { return refs; } } } } return PsiReference.EMPTY_ARRAY; }
createReferencesForNamedArgument
33,043
TextRange (@NotNull final GrLiteralContainer element) { if (element instanceof GrStringContent) { return TextRange.from(0, element.getTextLength()); } final String text = element.getText(); if (!(element.getValue() instanceof String)) { return super.getRangeInElement(element); } return getLiteralRange(text); }
getRangeInElement
33,044
TextRange (String text) { int start = 1; int fin = text.length(); String begin = text.substring(0, 1); if (text.startsWith("$/")) { start = 2; if (text.endsWith("/$")) { return new TextRange(start, Math.max(1, fin - 2)); } else { return new TextRange(start, fin); } } if (text.startsWith("\"\"\"") || text.startsWith("'''")) { start = 3; begin = text.substring(0, 3); } if (text.length() >= begin.length() * 2 && text.endsWith(begin)) { fin -= begin.length(); } assert fin >= 1; return new TextRange(start, fin); }
getLiteralRange
33,045
boolean (@NotNull VirtualFile file) { return StringUtil.endsWith(file.getNameSequence(), HELPER_SUFFIX); }
acceptInput
33,046
Collection<TraitFieldDescriptor> (@NotNull FileContent inputData) { return index(inputData.getContent()); }
computeValue
33,047
SingleEntryIndexer<Collection<TraitFieldDescriptor>> () { return INDEXER; }
getIndexer
33,048
DataExternalizer<Collection<TraitFieldDescriptor>> () { return this; }
getValueExternalizer
33,049
InputFilter () { return FILTER; }
getInputFilter
33,050
int () { return 5; }
getVersion
33,051
Collection<TraitFieldDescriptor> (byte[] fileContents) { final Collection<TraitFieldDescriptor> values = new ArrayList<>(); new ClassReader(fileContents).accept(new ClassVisitor(Opcodes.API_VERSION) { @Override public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { return new FieldVisitor(Opcodes.API_VERSION) { private final List<String> annotations = new SmartList<>(); @Override public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { return StubBuildingVisitor.getAnnotationTextCollector(descriptor, annotations::add); } @Override public void visitEnd() { processField(access, name, desc, signature, annotations); } }; } private void processField(int access, String name, String desc, String signature, List<String> annotations) { if ((access & ACC_SYNTHETIC) == 0) return; final boolean isStatic; final boolean isPublic; Pair<Boolean, String> p; if ((p = parse(STATIC_PREFIX, INSTANCE_PREFIX, name)).first != null) { isStatic = p.first; name = p.second; } else { return; } if ((p = parse(PUBLIC_PREFIX, PRIVATE_PREFIX, name)).first != null) { isPublic = p.first; name = p.second; } else { return; } final String typeString = fieldType(desc, signature); if (typeString == null) return; final int delimiter = name.indexOf(DELIMITER); if (delimiter > -1) { name = name.substring(delimiter + DELIMITER.length()); } byte flags = (byte)((isPublic ? TraitFieldDescriptor.PUBLIC : 0) | (isStatic ? TraitFieldDescriptor.STATIC : 0)); values.add(new TraitFieldDescriptor(flags, typeString, name, annotations)); } private static Pair<Boolean, String> parse(String prefix, String prefix2, String input) { if (input.startsWith(prefix)) { return Pair.create(true, input.substring(prefix.length())); } else if (input.startsWith(prefix2)) { return Pair.create(false, input.substring(prefix2.length())); } else { return Pair.create(null, input); } } private static String fieldType(String desc, String signature) { if (signature != null) { try { return SignatureParsing.parseTypeStringToTypeInfo(new SignatureParsing.CharIterator(signature), StubBuildingVisitor.GUESSING_PROVIDER).text(); } catch (ClsFormatException ignored) { } } String raw = Type.getType(desc).getClassName(); return StubBuildingVisitor.GUESSING_MAPPER.fun(raw); } }, EMPTY_ATTRIBUTES, ClassReader.SKIP_CODE); return values; }
index
33,052
FieldVisitor (int access, String name, String desc, String signature, Object value) { return new FieldVisitor(Opcodes.API_VERSION) { private final List<String> annotations = new SmartList<>(); @Override public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { return StubBuildingVisitor.getAnnotationTextCollector(descriptor, annotations::add); } @Override public void visitEnd() { processField(access, name, desc, signature, annotations); } }; }
visitField
33,053
AnnotationVisitor (String descriptor, boolean visible) { return StubBuildingVisitor.getAnnotationTextCollector(descriptor, annotations::add); }
visitAnnotation
33,054
void () { processField(access, name, desc, signature, annotations); }
visitEnd
33,055
void (int access, String name, String desc, String signature, List<String> annotations) { if ((access & ACC_SYNTHETIC) == 0) return; final boolean isStatic; final boolean isPublic; Pair<Boolean, String> p; if ((p = parse(STATIC_PREFIX, INSTANCE_PREFIX, name)).first != null) { isStatic = p.first; name = p.second; } else { return; } if ((p = parse(PUBLIC_PREFIX, PRIVATE_PREFIX, name)).first != null) { isPublic = p.first; name = p.second; } else { return; } final String typeString = fieldType(desc, signature); if (typeString == null) return; final int delimiter = name.indexOf(DELIMITER); if (delimiter > -1) { name = name.substring(delimiter + DELIMITER.length()); } byte flags = (byte)((isPublic ? TraitFieldDescriptor.PUBLIC : 0) | (isStatic ? TraitFieldDescriptor.STATIC : 0)); values.add(new TraitFieldDescriptor(flags, typeString, name, annotations)); }
processField
33,056
String (String desc, String signature) { if (signature != null) { try { return SignatureParsing.parseTypeStringToTypeInfo(new SignatureParsing.CharIterator(signature), StubBuildingVisitor.GUESSING_PROVIDER).text(); } catch (ClsFormatException ignored) { } } String raw = Type.getType(desc).getClassName(); return StubBuildingVisitor.GUESSING_MAPPER.fun(raw); }
fieldType
33,057
boolean (Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; TraitFieldDescriptor that = (TraitFieldDescriptor)o; if (flags != that.flags) return false; if (!typeString.equals(that.typeString)) return false; if (!name.equals(that.name)) return false; return true; }
equals
33,058
int () { int result = flags; result = 31 * result + typeString.hashCode(); result = 31 * result + name.hashCode(); return result; }
hashCode
33,059
int () { return ClassFileStubBuilder.STUB_VERSION + 6; }
getVersion
33,060
InputFilter () { return new DefaultFileTypeSpecificInputFilter(JavaClassFileType.INSTANCE) { @Override public boolean acceptInput(@NotNull VirtualFile file) { return StringUtil.endsWith(file.getNameSequence(), HELPER_SUFFIX); } }; }
getInputFilter
33,061
boolean (@NotNull VirtualFile file) { return StringUtil.endsWith(file.getNameSequence(), HELPER_SUFFIX); }
acceptInput
33,062
SingleEntryIndexer<ByteArraySequence> () { return new SingleEntryIndexer<>(false) { @Override protected ByteArraySequence computeValue(@NotNull FileContent inputData) { @Nullable PsiJavaFileStub stub = index(inputData.getFile(), inputData.getContent()); if (stub == null) return null; BufferExposingByteArrayOutputStream buffer = new BufferExposingByteArrayOutputStream(); myStubTreeSerializer.serialize(stub, buffer); return buffer.toByteArraySequence(); } }; }
getIndexer
33,063
ByteArraySequence (@NotNull FileContent inputData) { @Nullable PsiJavaFileStub stub = index(inputData.getFile(), inputData.getContent()); if (stub == null) return null; BufferExposingByteArrayOutputStream buffer = new BufferExposingByteArrayOutputStream(); myStubTreeSerializer.serialize(stub, buffer); return buffer.toByteArraySequence(); }
computeValue
33,064
DataExternalizer<ByteArraySequence> () { return new DataExternalizer<>() { @Override public void save(@NotNull DataOutput out, ByteArraySequence value) throws IOException { int length = value.length(); DataInputOutputUtil.writeINT(out, length); out.write(value.getInternalBuffer(), value.getOffset(), length); } @Override public ByteArraySequence read(@NotNull DataInput in) throws IOException { int length = DataInputOutputUtil.readINT(in); byte[] buf = new byte[length]; in.readFully(buf); return ByteArraySequence.create(buf); } }; }
getValueExternalizer
33,065
PsiJavaFileStub (@NotNull VirtualFile file, byte @NotNull [] content) { try { PsiJavaFileStub root = new PsiJavaFileStubImpl("", true); new ClassReader(content).accept(new GrTraitMethodVisitor(file, root), EMPTY_ATTRIBUTES, ClassReader.SKIP_CODE); new StubTree(root); // to ensure stubs are stored in DFS order return root; } catch (OutOfOrderInnerClassException e) { if (LOG.isTraceEnabled()) LOG.trace(file.getPath()); return null; } catch (Exception e) { LOG.info(file.getPath(), e); return null; } }
index
33,066
void (int version, int access, String name, String signature, String superName, String[] interfaces) { super.visit(version, access, "gr_trait_helper", null, null, null); }
visit
33,067
void (String source, String debug) { }
visitSource
33,068
void (String owner, String name, String desc) { }
visitOuterClass
33,069
AnnotationVisitor (String desc, boolean visible) { return null; }
visitAnnotation
33,070
void (String name, String outerName, String innerName, int access) { }
visitInnerClass
33,071
FieldVisitor (int access, String name, String desc, String signature, Object value) { return null; }
visitField
33,072
MethodVisitor (int access, String name, String desc, String signature, String[] exceptions) { if ((access & ACC_SYNTHETIC) == 0 && (access & ACC_STATIC) != 0 && name != null) { Type[] args = Type.getArgumentTypes(desc); if (args.length > 0 && args[0].getSort() == Type.OBJECT && CommonClassNames.JAVA_LANG_CLASS.equals(args[0].getClassName())) { return super.visitMethod(access, name, desc, signature, exceptions); } } return null; }
visitMethod
33,073
Collection<PsiMethod> (@NotNull ClsClassImpl trait) { PsiFile psiFile = trait.getContainingFile(); if (!(psiFile instanceof PsiJavaFile)) return Collections.emptyList(); VirtualFile traitFile = psiFile.getVirtualFile(); if (traitFile == null) return Collections.emptyList(); VirtualFile helperFile = traitFile.getParent().findChild(trait.getName() + HELPER_SUFFIX); if (helperFile == null) return Collections.emptyList(); ByteArraySequence byteSequence = GrTraitUtil.GROOVY_TRAIT_METHODS_GIST.getFileData(trait.getProject(), helperFile); if (byteSequence == null) return Collections.emptyList(); StubTreeSerializer serializer = new ShareableStubTreeSerializer(); List<PsiMethod> result = new ArrayList<>(); Stub root; try { root = serializer.deserialize(byteSequence.toInputStream()); ((PsiJavaFileStubImpl)root).setPsi((PsiJavaFile)psiFile); } catch (SerializerNotFoundException e) { LOG.warn(e); return result; } for (Object childStub : root.getChildrenStubs().get(0).getChildrenStubs()) { if (childStub instanceof PsiMethodStub) { result.add(((PsiMethodStub)childStub).getPsi()); } } return result; }
getStaticTraitMethods
33,074
void (@NotNull NonCodeMembersContributor extension, @NotNull PluginDescriptor pluginDescriptor) { dropCache(); }
extensionAdded
33,075
void (@NotNull NonCodeMembersContributor extension, @NotNull PluginDescriptor pluginDescriptor) { dropCache(); }
extensionRemoved
33,076
void (@NotNull PsiType qualifierType, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) { throw new RuntimeException("One of two 'processDynamicElements()' methods must be implemented"); }
processDynamicElements
33,077
void (@NotNull PsiType qualifierType, @Nullable PsiClass aClass, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) { processDynamicElements(qualifierType, processor, place, state); }
processDynamicElements
33,078
boolean () { return true; }
unwrapMultiprocessor
33,079
String () { return null; }
getParentClassName
33,080
Collection<String> () { String className = getParentClassName(); return ContainerUtil.createMaybeSingletonList(className); }
getClassNames
33,081
void () { cache = null; PatternCompilerFactory.getFactory().dropCache(); }
dropCache
33,082
void () { if (cache != null) return; final Collection<NonCodeMembersContributor> allTypeContributors = new ArrayList<>(); final MultiMap<String, NonCodeMembersContributor> contributorMap = new MultiMap<>(); for (final NonCodeMembersContributor contributor : EP_NAME.getExtensions()) { Collection<String> fqns = contributor.getClassNames(); if (fqns.isEmpty()) { allTypeContributors.add(contributor); } else { for (String fqn : fqns) { contributorMap.putValue(fqn, contributor); } } } cache = new Cache(contributorMap, allTypeContributors.toArray(new NonCodeMembersContributor[0])); }
ensureInit
33,083
Iterable<NonCodeMembersContributor> (@Nullable PsiClass clazz) { final List<NonCodeMembersContributor> result = new ArrayList<>(); if (clazz != null) { for (String superClassName : ClassUtil.getSuperClassesWithCache(clazz).keySet()) { result.addAll(cache.classSpecifiedContributors.get(superClassName)); } } ContainerUtil.addAll(result, cache.allTypeContributors); return result; }
getApplicableContributors
33,084
boolean (@NotNull PsiType qualifierType, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) { ensureInit(); final PsiClass aClass = PsiTypesUtil.getPsiClass(qualifierType); final Iterable<? extends PsiScopeProcessor> unwrappedOriginals = MultiProcessor.allProcessors(processor); for (PsiScopeProcessor each : unwrappedOriginals) { if (!processClassMixins(qualifierType, each, place, state)) { return false; } if (!processCategoriesInScope(qualifierType, each, place, state)) { return false; } if (!processDgmMethods(qualifierType, each, place, state)) { return false; } } final List<MyDelegatingScopeProcessor> wrapped = Collections.singletonList(new MyDelegatingScopeProcessor(processor)); final List<MyDelegatingScopeProcessor> unwrapped = map(MultiProcessor.allProcessors(processor), MyDelegatingScopeProcessor::new); final Iterable<NonCodeMembersContributor> contributors = getApplicableContributors(aClass); for (NonCodeMembersContributor contributor : contributors) { ProgressManager.checkCanceled(); processor.handleEvent(CHANGE_LEVEL, null); final List<MyDelegatingScopeProcessor> delegates = contributor.unwrapMultiprocessor() ? unwrapped : wrapped; for (MyDelegatingScopeProcessor delegatingProcessor : delegates) { ProgressManager.checkCanceled(); contributor.processDynamicElements(qualifierType, aClass, delegatingProcessor, place, state); if (!delegatingProcessor.wantMore) { return false; } } } return true; }
runContributors
33,085
boolean (@NotNull PsiElement element, @NotNull ResolveState state) { if (!wantMore) { return false; } wantMore = super.execute(element, state); return wantMore; }
execute
33,086
void (@NotNull TransformationContext context) { GrTypeDefinition typeDefinition = context.getCodeClass(); if (typeDefinition.getName() == null) return; PsiModifierList modifierList = typeDefinition.getModifierList(); if (modifierList == null) return; final PsiAnnotation tupleConstructor = context.getAnnotation(GroovyCommonClassNames.GROOVY_TRANSFORM_TUPLE_CONSTRUCTOR); final PsiAnnotation mapConstructorAnno = context.getAnnotation(GroovyCommonClassNames.GROOVY_TRANSFORM_MAP_CONSTRUCTOR); final boolean immutable = GrImmutableUtils.hasImmutableAnnotation(typeDefinition); final boolean canonical = context.getAnnotation(GroovyCommonClassNames.GROOVY_TRANSFORM_CANONICAL) != null; if (!immutable && !canonical && tupleConstructor == null && mapConstructorAnno == null) { return; } if (tupleConstructor != null && typeDefinition.getCodeConstructors().length > 0 && !PsiUtil.getAnnoAttributeValue(tupleConstructor, TupleConstructorAttributes.FORCE, false)) { return; } String originInfo; if (immutable) { originInfo = "created by @Immutable"; } else if (canonical) { originInfo = "created by @Canonical"; } else if (tupleConstructor != null) { originInfo = "created by @TupleConstructor"; } else { originInfo = "created by @MapConstructor"; } if (canonical || immutable || tupleConstructor != null) { final GrLightMethodBuilder fieldsConstructor = generateFieldConstructor(context, tupleConstructor, immutable, canonical, originInfo); context.addMethod(fieldsConstructor); } List<GrLightMethodBuilder> mapConstructors = generateMapConstructor(typeDefinition, originInfo, context); for (GrLightMethodBuilder mapConstructor : mapConstructors) { context.addMethod(mapConstructor); } }
applyTransformation
33,087
List<GrLightMethodBuilder> (@NotNull GrTypeDefinition typeDefinition, String originInfo, @NotNull TransformationContext context) { if (GroovyConfigUtils.isAtLeastGroovy25(typeDefinition)) { PsiAnnotation mapConstructorAnno = typeDefinition.getAnnotation(GroovyCommonClassNames.GROOVY_TRANSFORM_MAP_CONSTRUCTOR); if (mapConstructorAnno == null) { return Collections.emptyList(); } GrLightMethodBuilder mapConstructor = new GrLightMethodBuilder(typeDefinition); checkContainingClass(context, mapConstructor); mapConstructor.setOriginInfo(originInfo); Visibility visibility = getVisibility(mapConstructorAnno, mapConstructor, Visibility.PUBLIC); mapConstructor.addModifier(visibility.toString()); var specialParamHandling = GrAnnotationUtil.inferBooleanAttribute(mapConstructorAnno, "specialNamedArgHandling"); String parameterRepresentation; if (Boolean.TRUE.equals(specialParamHandling)) { parameterRepresentation = computeMapParameterPresentation(typeDefinition); } else { parameterRepresentation = CommonClassNames.JAVA_UTIL_MAP; } mapConstructor.addParameter("args", parameterRepresentation); var noArg = GrAnnotationUtil.inferBooleanAttribute(mapConstructorAnno, "noArg"); if (Boolean.TRUE.equals(noArg)) { var noArgConstructor = new GrLightMethodBuilder(typeDefinition); checkContainingClass(context, noArgConstructor); noArgConstructor.setOriginInfo(originInfo); return List.of(mapConstructor, noArgConstructor); } else { return List.of(mapConstructor); } } else { final GrLightMethodBuilder mapConstructor = new GrLightMethodBuilder(typeDefinition); checkContainingClass(context, mapConstructor); mapConstructor.addParameter("args", CommonClassNames.JAVA_UTIL_HASH_MAP); mapConstructor.setOriginInfo(originInfo); return List.of(mapConstructor); } }
generateMapConstructor
33,088
GrLightMethodBuilder (@NotNull TransformationContext context, @Nullable PsiAnnotation tupleConstructor, boolean immutable, boolean canonical, @NotNull String originInfo) { final GrTypeDefinition typeDefinition = context.getCodeClass(); final GrLightMethodBuilder fieldsConstructor = new GrLightMethodBuilder(typeDefinition.getManager(), typeDefinition.getName()); fieldsConstructor.setConstructor(true); fieldsConstructor.setNavigationElement(typeDefinition); fieldsConstructor.setContainingClass(typeDefinition); if (canonical) { var modifierList = typeDefinition.getModifierList(); if (modifierList != null) { tupleConstructor = new GrLightAnnotation(modifierList, typeDefinition, GroovyCommonClassNames.GROOVY_TRANSFORM_TUPLE_CONSTRUCTOR, Map.of()); } } if (immutable) { var modifierList = typeDefinition.getModifierList(); if (modifierList != null) { tupleConstructor = new GrLightAnnotation(modifierList, typeDefinition, GroovyCommonClassNames.GROOVY_TRANSFORM_TUPLE_CONSTRUCTOR, Map.of(TupleConstructorAttributes.DEFAULTS, "false")); } } if (tupleConstructor != null) { boolean optional = !immutable && PsiUtil.getAnnoAttributeValue(tupleConstructor, TupleConstructorAttributes.DEFAULTS, true); Visibility visibility = getVisibility(tupleConstructor, fieldsConstructor, Visibility.PUBLIC); fieldsConstructor.addModifier(visibility.toString()); AffectedMembersCache cache = GrGeneratedConstructorUtils.getAffectedMembersCache(tupleConstructor); checkContainingClass(context, fieldsConstructor); for (PsiNamedElement element : cache.getAffectedMembers()) { GrLightParameter parameter; if (element instanceof PsiField) { String name = AffectedMembersCache.getExternalName(element); parameter = new GrLightParameter(name == null ? "arg" : name, ((PsiField)element).getType(), fieldsConstructor); } else if (element instanceof GrMethod) { String name = PropertyUtilBase.getPropertyName((PsiMember)element); PsiType type = PropertyUtilBase.getPropertyType((PsiMethod)element); parameter = new GrLightParameter(name == null ? "arg" : name, type, fieldsConstructor); } else { parameter = null; } if (parameter != null) { parameter.setOptional(optional); fieldsConstructor.addParameter(parameter); } } } fieldsConstructor.setOriginInfo(originInfo); return fieldsConstructor; }
generateFieldConstructor
33,089
void (@NotNull TransformationContext context,@NotNull GrLightMethodBuilder constructor) { GrTypeDefinition codeClass = context.getCodeClass(); var modifierList = codeClass.getModifierList(); if (modifierList == null || context.hasModifierProperty(modifierList, PsiModifier.STATIC)) { return; } PsiClass containingClass = codeClass.getContainingClass(); if (containingClass == null) { return; } var factory = GroovyPsiElementFactory.getInstance(context.getProject()); PsiClassType classType = factory.createType(containingClass); var justTypeParameter = new EnclosingClassParameter("_containingClass", classType, containingClass); constructor.addParameter(justTypeParameter); }
checkContainingClass
33,090
void (@NotNull TransformationContext context) { GrModifierList modifierList = context.getCodeClass().getModifierList(); if (modifierList == null) return; for (GrAnnotation annotation : modifierList.getAnnotations()) { String qname = annotation.getQualifiedName(); String logger = ourLoggers.get(qname); if (logger != null) { String fieldName = PsiUtil.getAnnoAttributeValue(annotation, "value", "log"); GrLightField field = new GrLightField(fieldName, logger, context.getCodeClass()); field.setNavigationElement(annotation); field.getModifierList().setModifiers(PsiModifier.PRIVATE, PsiModifier.FINAL, PsiModifier.STATIC); field.setOriginInfo("created by @" + annotation.getShortName()); context.addField(field); } } }
applyTransformation
33,091
Collection<PsiMethod> () { return Collections.emptyList(); }
getMethods
33,092
Collection<GrField> () { return Collections.emptyList(); }
getFields
33,093
Collection<PsiClass> () { return Collections.emptyList(); }
getClasses
33,094
Collection<PsiClassType> () { return Collections.emptyList(); }
getImplementsTypes
33,095
void (@NotNull Members other) { // do nothing }
addFrom
33,096
Members () { return new Members() { private final Collection<PsiMethod> methods = new ArrayList<>(); private final Collection<GrField> fields = new ArrayList<>(); private final Collection<PsiClass> classes = new ArrayList<>(); private final Collection<PsiClassType> implementsTypes = new ArrayList<>(); @NotNull @Override public Collection<PsiMethod> getMethods() { return methods; } @NotNull @Override public Collection<GrField> getFields() { return fields; } @NotNull @Override public Collection<PsiClass> getClasses() { return classes; } @NotNull @Override public Collection<PsiClassType> getImplementsTypes() { return implementsTypes; } @Override public void addFrom(@NotNull Members other) { methods.addAll(other.getMethods()); fields.addAll(other.getFields()); classes.addAll(other.getClasses()); implementsTypes.addAll(other.getImplementsTypes()); } }; }
create
33,097
Collection<PsiMethod> () { return methods; }
getMethods
33,098
Collection<GrField> () { return fields; }
getFields
33,099
Collection<PsiClass> () { return classes; }
getClasses