Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
34,400
String () { return "Groovy script"; }
toString
34,401
boolean (@NotNull PsiClass aClass) { return addImportForClass(aClass) != null; }
importClass
34,402
void (GrVariable variable) { PsiImplUtil.removeVariable(variable); }
removeVariable
34,403
void (@NotNull GroovyElementVisitor visitor) { visitor.visitFile(this); }
accept
34,404
void (@NotNull GroovyElementVisitor visitor) { PsiElement child = getFirstChild(); while (child != null) { if (child instanceof GroovyPsiElement) { ((GroovyPsiElement) child).accept(visitor); } child = child.getNextSibling(); } }
acceptChildren
34,405
void () { super.clearCaches(); myControlFlow = null; }
clearCaches
34,406
Instruction[] () { return getGroovyControlFlow().getFlow(); }
getControlFlow
34,407
GroovyControlFlow () { assert isValid(); GroovyControlFlow result = dereference(myControlFlow); if (result == null) { result = ControlFlowBuilder.buildControlFlow(this); myControlFlow = new SoftReference<>(result); } return result; }
getGroovyControlFlow
34,408
boolean () { return false; }
isTopControlFlowOwner
34,409
boolean (@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) { for (PsiScopeProcessor each : MultiProcessor.allProcessors(processor)) { if (!shouldProcessMembers(each)) continue; if (!getAppropriateHolder(getAnnotationHint(processor)).processDeclarations(each, state, place)) return false; } return true; }
processDeclarations
34,410
DeclarationHolder (@Nullable AnnotationHint hint) { boolean mayUseCache = useCache(); if (hint == null) { if (mayUseCache || myAnnotationsCache.hasUpToDateValue() && myDeclarationsCache.hasUpToDateValue()) { return myAllCachedDeclarations; } } else if (hint.isAnnotationResolve()) { if (mayUseCache || myAnnotationsCache.hasUpToDateValue()) { return myAnnotationsCache.getValue(); } } else { if (mayUseCache || myDeclarationsCache.hasUpToDateValue()) { return myDeclarationsCache.getValue(); } } return this::processDeclarationsNoCache; }
getAppropriateHolder
34,411
boolean () { if (!isPhysical()) return false; if (ApplicationManager.getApplication().isDispatchThread()) return false; return getUserData(PsiFileEx.BATCH_REFERENCE_PROCESSING) == Boolean.TRUE; }
useCache
34,412
DeclarationHolder (boolean annotationCache) { FileCacheBuilderProcessor processor = new FileCacheBuilderProcessor(annotationCache); processDeclarationsNoCache(processor, ResolveState.initial(), this); return processor.buildCache(); }
buildCache
34,413
boolean (@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @NotNull PsiElement place) { if (!processClassesInFile(this, processor, state)) return false; final GroovyFileImports imports = getImports(); if (!imports.processAllNamedImports(processor, state, place)) return false; if (!processClassesInPackage(this, processor, state, place)) return false; if (!areImportsIgnored(state)) { return processComplexImports(processor, state, place); } return true; }
processDeclarationsNoCache
34,414
boolean (@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @NotNull PsiElement place) { final GroovyFileImports imports = getImports(); if (!imports.processAllStarImports(processor, state, place)) return false; return imports.processDefaultImports(processor, state, place); }
processComplexImports
34,415
PsiType (String key) { return myStringEntries.get(key); }
getTypeByStringKey
34,416
Set<String> () { return myStringEntries.keySet(); }
getStringKeys
34,417
List<Couple<PsiType>> () { return myOtherEntries; }
getOtherEntries
34,418
boolean () { for (PsiType type : myStringEntries.values()) { if (type != null && !type.isValid()) { return false; } } for (Couple<PsiType> entry : myOtherEntries) { if (entry.first != null && !entry.first.isValid()) { return false; } if (entry.second != null && !entry.second.isValid()) { return false; } } return true; }
isValid
34,419
boolean () { return myStringEntries.isEmpty() && myOtherEntries.isEmpty(); }
isEmpty
34,420
boolean (Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; GrMapTypeImpl type = (GrMapTypeImpl)o; if (!myStringEntries.equals(type.myStringEntries)) return false; if (!myOtherEntries.equals(type.myOtherEntries)) return false; return true; }
equals
34,421
int () { int result = super.hashCode(); result = 31 * result + myStringEntries.hashCode(); result = 31 * result + myOtherEntries.hashCode(); return result; }
hashCode
34,422
PsiElement (@NotNull PsiReference ref, int flags) { PsiElement sourceElement = ref.getElement(); if (sourceElement instanceof GrCodeReferenceElement) { GrNewExpression newExpr; PsiElement parent = sourceElement.getParent(); if (parent instanceof GrNewExpression) { newExpr = (GrNewExpression)parent; } else if (parent instanceof GrAnonymousClassDefinition) { PsiElement grandParent = parent.getParent(); if (grandParent instanceof GrNewExpression) { newExpr = (GrNewExpression)grandParent; } else { return null; } } else { return null; } final PsiMethod constructor = newExpr.resolveMethod(); if (constructor instanceof DefaultConstructor) return constructor.getContainingClass(); final GrArgumentList argumentList = newExpr.getArgumentList(); if (constructor != null && argumentList != null && PsiImplUtil.hasNamedArguments(argumentList) && !PsiImplUtil.hasExpressionArguments(argumentList)) { if (constructor.getParameterList().isEmpty()) return constructor.getContainingClass(); } return constructor; } if (sourceElement instanceof GrReferenceExpression) { PsiElement resolved = ((GrReferenceExpression)sourceElement).resolve(); if (resolved instanceof GrGdkMethod || !(resolved instanceof GrRenameableLightElement)) { return correctSearchTargets(resolved); } return resolved; } return null; }
getElementByReference
34,423
PsiElement (@Nullable PsiElement target) { if (target instanceof ClsMethodImpl) { PsiElement mirror = ((ClsMethodImpl)target).getSourceMirrorMethod(); if (mirror != null) { return mirror.getNavigationElement(); } } if (target != null && !(target instanceof GrAccessorMethod) && target.getUserData(NAVIGATION_ELEMENT_IS_NOT_TARGET) == null) { if (target instanceof PsiMirrorElement) { return ((PsiMirrorElement)target).getPrototype(); } else { return target.getNavigationElement(); } } return target; }
correctSearchTargets
34,424
Collection<PsiElement> (@NotNull PsiReference reference) { if (reference instanceof GrReferenceExpression referenceExpression) { if (referenceExpression.hasMemberPointer()) { GroovyResolveResult[] results = referenceExpression.multiResolve(false); if (results.length > 0) { return collapseReflectedMethods(mapNotNull(results, it -> it.getElement())); } } } return super.getTargetCandidates(reference); }
getTargetCandidates
34,425
PsiElement (Editor editor, int offset, int flags, @NotNull PsiElement targetElement) { if (targetElement instanceof GrPropertyForCompletion) { return ((GrPropertyForCompletion)targetElement).getOriginalAccessor(); } return super.adjustTargetElement(editor, offset, flags, targetElement); }
adjustTargetElement
34,426
PsiType (@NotNull GrReferenceExpression refExpr, boolean honorCompileStatic) { if (honorCompileStatic && !CompileStaticUtil.isCompileStatic(refExpr) || refExpr.getQualifier() != null) { return null; } final PsiElement resolved = refExpr.resolve(); if (!PsiUtil.isLocalVariable(resolved)) { return null; } assert resolved instanceof GrVariable; return TypeInferenceHelper.getCurrentContext().getExpressionType(((GrVariable)resolved), variable -> getLeastUpperBoundByVar(variable)); }
getReassignedVarType
34,427
PsiType (@NotNull final GrVariable var) { return RecursionManager.doPreventingRecursion(var, false, (NullableComputable<PsiType>)() -> { final Collection<PsiReference> all = ReferencesSearch.search(var, var.getUseScope()).findAll(); final GrExpression initializer = var.getInitializerGroovy(); if (initializer == null && all.isEmpty()) { return var.getDeclaredType(); } PsiType result = initializer != null ? initializer.getType() : null; final PsiManager manager = var.getManager(); for (PsiReference reference : all) { final PsiElement ref = reference.getElement(); if (ref instanceof GrReferenceExpression && PsiUtil.isLValue(((GrReferenceExpression)ref))) { result = TypesUtil.getLeastUpperBoundNullable(result, TypeInferenceHelper.getInitializerTypeFor(ref), manager); } } return result; }); }
getLeastUpperBoundByVar
34,428
boolean (PsiElement element, String expectedName, GroovyFile file) { if (!(element instanceof PsiClass psiClass)) return false; if (!expectedName.equals(psiClass.getName())) return false; final String qname = psiClass.getQualifiedName(); if (qname == null) return false; if (ArrayUtil.contains(qname, GroovyFileBase.IMPLICITLY_IMPORTED_CLASSES)) { return true; } for (String pkg : getImplicitlyImportedPackages(file)) { if (qname.equals(pkg + "." + expectedName) || pkg.isEmpty() && qname.equals(expectedName)) { return true; } } return false; }
isImplicitlyImported
34,429
LinkedHashSet<String> (@NotNull GroovyFile file) { final LinkedHashSet<String> result = new LinkedHashSet<>(); ContainerUtil.addAll(result, GroovyFileBase.IMPLICITLY_IMPORTED_PACKAGES); final GroovyFileImports fileImports = file.getImports(); for (StarImport starImport : fileImports.getStarImports()) { if (!fileImports.isImplicit(starImport)) continue; result.add(starImport.getPackageFqn()); } result.add(file.getPackageName()); return result; }
getImplicitlyImportedPackages
34,430
String () { return CommonClassNames.JAVA_UTIL_LIST; }
getJavaClassName
34,431
String () { List<PsiType> types = getComponentTypes(); StringBuilder builder = new StringBuilder(); builder.append("["); for (int i = 0; i < types.size(); i++) { if (i >= 2) { builder.append(",..."); break; } if (i > 0) builder.append(", "); builder.append(getInternalCanonicalText(types.get(i))); } builder.append("]"); return builder.toString(); }
getInternalCanonicalText
34,432
boolean (Object obj) { if (obj instanceof GrTupleType) { List<PsiType> componentTypes = getComponentTypes(); List<PsiType> otherComponents = ((GrTupleType)obj).getComponentTypes(); return componentTypes.size() == otherComponents.size() && componentTypes.equals(otherComponents); } return super.equals(obj); }
equals
34,433
boolean (@NotNull PsiType type) { if (type instanceof GrTupleType) { List<PsiType> otherComponents = ((GrTupleType)type).getComponentTypes(); List<PsiType> componentTypes = getComponentTypes(); for (int i = 0; i < Math.min(componentTypes.size(), otherComponents.size()); i++) { PsiType componentType = componentTypes.get(i); PsiType otherComponent = otherComponents.get(i); if (otherComponent == null) { if (componentType != null && !TypesUtil.isClassType(componentType, CommonClassNames.JAVA_LANG_OBJECT)) return false; } else if (componentType != null && !componentType.isAssignableFrom(otherComponent)) return false; } return true; } return super.isAssignableFrom(type); }
isAssignableFrom
34,434
List<PsiType> () { return myComponents.getValue(); }
getComponentTypes
34,435
PsiClassType (@NotNull LanguageLevel languageLevel) { return new GrImmediateTupleType(getComponentTypes(), myFacade, getResolveScope()); }
setLanguageLevel
34,436
String (@NotNull PsiAnnotation annotation, @NlsSafe @NotNull String attributeName) { final PsiAnnotationMemberValue targetValue = annotation.findAttributeValue(attributeName); return getString(targetValue); }
inferStringAttribute
34,437
GrClosableBlock (@NotNull PsiAnnotation annotation, @NlsSafe @NotNull String attributeName) { PsiAnnotationMemberValue targetValue = annotation.findAttributeValue(attributeName); if (targetValue instanceof GrClosableBlock) { return (GrClosableBlock)targetValue; } return null; }
inferClosureAttribute
34,438
String (@Nullable PsiAnnotationMemberValue targetValue) { if (targetValue instanceof PsiLiteral) { final Object value = ((PsiLiteral)targetValue).getValue(); if (value instanceof String) return (String)value; } return null; }
getString
34,439
Integer (@NotNull PsiAnnotation annotation, @NlsSafe @NotNull String attributeName) { final PsiAnnotationMemberValue targetValue = annotation.findAttributeValue(attributeName); if (targetValue instanceof PsiLiteral) { final Object value = ((PsiLiteral)targetValue).getValue(); if (value instanceof Integer) return (Integer)value; } return null; }
inferIntegerAttribute
34,440
Boolean (@NotNull PsiAnnotation annotation, @NlsSafe @NotNull String attributeName) { final PsiAnnotationMemberValue targetValue = annotation.findAttributeValue(attributeName); if (targetValue instanceof PsiLiteral) { final Object value = ((PsiLiteral)targetValue).getValue(); if (value instanceof Boolean) return (Boolean)value; } return null; }
inferBooleanAttribute
34,441
boolean (@NotNull PsiAnnotation annotation, @NlsSafe @NotNull String attributeName) { Boolean result = inferBooleanAttribute(annotation, attributeName); return result != null && result; }
inferBooleanAttributeNotNull
34,442
PsiClass (@NotNull PsiAnnotation annotation, @NlsSafe @NotNull String attributeName) { final PsiAnnotationMemberValue targetValue = annotation.findAttributeValue(attributeName); return getPsiClass(targetValue); }
inferClassAttribute
34,443
PsiClass (@Nullable PsiAnnotationMemberValue targetValue) { if (targetValue instanceof PsiClassObjectAccessExpression) { PsiType type = ((PsiClassObjectAccessExpression)targetValue).getOperand().getType(); if (type instanceof PsiClassType) { return ((PsiClassType)type).resolve(); } } else if (targetValue instanceof GrReferenceExpression) { if ("class".equals(((GrReferenceExpression)targetValue).getReferenceName())) { GrExpression qualifier = ((GrReferenceExpression)targetValue).getQualifier(); if (qualifier instanceof GrReferenceExpression) { PsiElement resolved = ((GrReferenceExpression)qualifier).resolve(); if (resolved instanceof PsiClass) { return (PsiClass)resolved; } } } PsiElement resolved = ((GrReferenceExpression)targetValue).resolve(); if (resolved instanceof PsiClass) return (PsiClass)resolved; } return null; }
getPsiClass
34,444
PsiType (PsiAnnotationMemberValue targetValue) { if (targetValue instanceof PsiClassObjectAccessExpression) { return ((PsiClassObjectAccessExpression)targetValue).getOperand().getType(); } else if (targetValue instanceof GrReferenceExpression) { if ("class".equals(((GrReferenceExpression)targetValue).getReferenceName())) { GrExpression qualifier = ((GrReferenceExpression)targetValue).getQualifier(); if (qualifier instanceof GrReferenceExpression) { PsiElement resolved = ((GrReferenceExpression)qualifier).resolve(); if (resolved instanceof PsiClass) { return qualifier.getType(); } } } PsiElement resolved = ((GrReferenceExpression)targetValue).resolve(); if (resolved instanceof PsiClass) { return ((GrReferenceExpression)targetValue).getType(); } } return null; }
extractClassTypeFromClassAttributeValue
34,445
PsiElement (GrAnnotation annotation) { PsiAnnotationOwner owner = annotation.getOwner(); if (owner instanceof PsiModifierList) return ((PsiModifierList)owner).getParent(); return (PsiElement)owner; }
getActualOwner
34,446
List<PsiClass> (@NotNull PsiAnnotation annotation, @NlsSafe @NotNull String attributeName, boolean declared) { PsiAnnotationMemberValue value = declared ? annotation.findDeclaredAttributeValue(attributeName) : annotation.findAttributeValue(attributeName); return ContainerUtil.mapNotNull(AnnotationUtil.arrayAttributeValues(value), GrAnnotationUtil::getPsiClass); }
getClassArrayValue
34,447
List<String> (@NotNull PsiAnnotation annotation, @NlsSafe @NotNull String attributeName, boolean declared) { PsiAnnotationMemberValue value = findDetachedAttributeValue(annotation, attributeName, declared); if (value == null) return Collections.emptyList(); return getArrayValue(value, AnnotationUtil::getStringAttributeValue); }
getStringArrayValue
34,448
PsiAnnotationMemberValue (@NotNull PsiAnnotation annotation, @NlsSafe @Nullable String attributeName, boolean declared) { PsiAnnotationMemberValue declaredValue = findDeclaredDetachedValue(annotation, attributeName); if (declaredValue != null) return declaredValue; if (declared) return null; return annotation.findAttributeValue(attributeName); }
findDetachedAttributeValue
34,449
PsiElement (@NotNull String refName) { GroovyFileBase file = createGroovyFileChecked("a." + refName); GrTopStatement statement = file.getTopStatements()[0]; if (!(statement instanceof GrReferenceExpression)) { throw new IncorrectOperationException("Incorrect reference name: " + refName); } final PsiElement element = ((GrReferenceExpression)statement).getReferenceNameElement(); if (element == null) { throw new IncorrectOperationException("Incorrect reference name: " + refName); } return element; }
createReferenceNameFromText
34,450
PsiElement (@NotNull String idText) { GrDocMemberReference reference = createDocMemberReferenceFromText("Foo", idText); LOG.assertTrue(reference != null, idText); return reference.getReferenceNameElement(); }
createDocMemberReferenceNameFromText
34,451
GrDocMemberReference (@NotNull String className, @NotNull String text) { PsiFile file = createGroovyFileChecked("/** @see " + className + "#" + text + " */"); PsiElement element = file.getFirstChild(); assert element instanceof GrDocComment; GrDocTag tag = PsiTreeUtil.getChildOfType(element, GrDocTag.class); assert tag != null : "Doc tag points to null"; return PsiTreeUtil.getChildOfType(tag, GrDocMemberReference.class); }
createDocMemberReferenceFromText
34,452
GrDocReferenceElement (@NotNull String qName) { PsiFile file = createGroovyFileChecked("/** @see " + qName + " */"); PsiElement element = file.getFirstChild(); assert element instanceof GrDocComment; GrDocTag tag = PsiTreeUtil.getChildOfType(element, GrDocTag.class); assert tag != null : "Doc tag points to null"; return PsiTreeUtil.getChildOfType(tag, GrDocReferenceElement.class); }
createDocReferenceElementFromFQN
34,453
GrCodeReferenceElement (@NotNull String text, @Nullable PsiElement context) { return createElementFromText(text, context, CODE_REFERENCE, GrCodeReferenceElement.class); }
createCodeReference
34,454
GrReferenceExpression (@NotNull String idText) { GroovyFileBase file = createGroovyFileChecked(idText); final GrTopStatement[] statements = file.getTopStatements(); if (!(statements.length == 1 && statements[0] instanceof GrReferenceExpression)) throw new IncorrectOperationException(idText); return (GrReferenceExpression) statements[0]; }
createReferenceExpressionFromText
34,455
GrReferenceExpression (@NotNull String idText, PsiElement context) { GroovyFile file = createGroovyFileChecked(idText, false, context); GrTopStatement[] statements = file.getTopStatements(); if (statements.length != 1) throw new IncorrectOperationException("refText: " + idText); if (!(statements[0] instanceof GrReferenceExpression)) throw new IncorrectOperationException("refText: " + idText); return (GrReferenceExpression)statements[0]; }
createReferenceExpressionFromText
34,456
GrReferenceExpression (@NotNull PsiClass aClass) { final String text; if (aClass instanceof PsiAnonymousClass) { text = ((PsiAnonymousClass)aClass).getBaseClassType().getPresentableText(); } else { text = aClass.getName(); } return createReferenceExpressionFromText(text); }
createReferenceElementForClass
34,457
GrExpression (@NotNull String text, PsiElement context) { GroovyFile file = createGroovyFile(text, false, context); GrTopStatement[] topStatements = file.getTopStatements(); if (topStatements.length == 0 || !(topStatements[0] instanceof GrExpression)) { throw new IncorrectOperationException("incorrect expression = '" + text + "'"); } return (GrExpression) topStatements[0]; }
createExpressionFromText
34,458
GrCodeReferenceElement (PsiClassType type) { if (type instanceof GrClassReferenceType) { return ((GrClassReferenceType)type).getReference(); } final PsiClassType.ClassResolveResult resolveResult = type.resolveGenerics(); final PsiClass refClass = resolveResult.getElement(); assert refClass != null : type; return createCodeReference(type.getCanonicalText()); }
createReferenceElementByType
34,459
PsiTypeParameterList () { return createMethodFromText("def <> void foo(){}").getTypeParameterList(); }
createTypeParameterList
34,460
PsiTypeParameter (@NotNull String name, PsiClassType @NotNull [] superTypes) { @NlsSafe StringBuilder builder = new StringBuilder(); builder.append("def <").append(name); if (superTypes.length > 1 || superTypes.length == 1 && !superTypes[0].equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) { builder.append(" extends "); for (PsiClassType type : superTypes) { if (type.equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) continue; builder.append(type.getCanonicalText()).append(','); } builder.delete(builder.length() - 1, builder.length()); } builder.append("> void foo(){}"); try { return createMethodFromText(builder).getTypeParameters()[0]; } catch (RuntimeException e) { throw new IncorrectOperationException("type parameter text: " + builder); } }
createTypeParameter
34,461
GrVariableDeclaration (String @Nullable [] modifiers, @Nullable GrExpression initializer, @Nullable PsiType type, String... identifiers) { String initializerText; if (initializer != null) { if (initializer instanceof GrApplicationStatement && !GroovyConfigUtils.getInstance().isVersionAtLeast(initializer, GroovyConfigUtils.GROOVY1_8, false)) { initializer = createMethodCallByAppCall((GrApplicationStatement)initializer); } assert initializer != null; initializerText = initializer.getText(); } else { initializerText = null; } return createVariableDeclaration(modifiers, initializerText, type, identifiers); }
createVariableDeclaration
34,462
GrVariableDeclaration (String @Nullable [] modifiers, @Nullable String initializer, @Nullable PsiType type, String... identifiers) { @NlsSafe StringBuilder text = writeModifiers(modifiers); if (type != null && type != PsiTypes.nullType()) { final PsiType unboxed = TypesUtil.unboxPrimitiveTypeWrapper(type); final String typeText = getTypeText(unboxed); text.append(typeText).append(" "); } else if (text.length() == 0) { text.insert(0, "def "); } if (identifiers.length > 1 && initializer != null) { text.append('('); } text.append(String.join(", ", identifiers)); if (identifiers.length > 1 && initializer != null) { text.append(')'); } if (!StringUtil.isEmptyOrSpaces(initializer)) { text.append(" = ").append(initializer); } GrTopStatement[] topStatements = createGroovyFileChecked(text).getTopStatements(); if (topStatements.length == 0 || !(topStatements[0] instanceof GrVariableDeclaration)) { topStatements = createGroovyFileChecked("def " + text).getTopStatements(); } if (topStatements.length == 0 || !(topStatements[0] instanceof GrVariableDeclaration statement)) { throw new RuntimeException("Invalid arguments, text = " + text); } //todo switch-case formatting should work without this hack CodeEditUtil.markToReformatBefore(statement.getNode().findLeafElementAt(0), true); return statement; }
createVariableDeclaration
34,463
GrEnumConstant (@NotNull String text) { GroovyFile file = createGroovyFileChecked("enum E{" + text + "}"); final GrEnumTypeDefinition enumClass = (GrEnumTypeDefinition)file.getClasses()[0]; return enumClass.getEnumConstants()[0]; }
createEnumConstantFromText
34,464
GrVariableDeclaration (String @NotNull [] modifiers, @NotNull String identifier, @Nullable GrExpression initializer, @Nullable PsiType type) { final String varDeclaration = createVariableDeclaration(modifiers, initializer, type, identifier).getText(); final GroovyFileBase file = createGroovyFileChecked("class A { " + varDeclaration + "}"); final GrTypeDefinitionBody body = file.getTypeDefinitions()[0].getBody(); LOG.assertTrue(body.getMemberDeclarations().length == 1 && body.getMemberDeclarations()[0] instanceof GrVariableDeclaration, "ident = <" + identifier + "> initializer = " + (initializer == null ? "_null_" : ("<" + initializer.getText()) + ">")); return (GrVariableDeclaration) body.getMemberDeclarations()[0]; }
createFieldDeclaration
34,465
GrVariableDeclaration (@NotNull String text) { final GroovyFile file = createGroovyFileChecked("class X{\n" + text + "\n}"); final PsiClass psiClass = file.getClasses()[0]; return (GrVariableDeclaration)psiClass.getFields()[0].getParent(); }
createFieldDeclarationFromText
34,466
StringBuilder (String[] modifiers) { StringBuilder text = new StringBuilder(); if (!(modifiers == null || modifiers.length == 0)) { for (String modifier : modifiers) { text.append(modifier); text.append(" "); } } return text; }
writeModifiers
34,467
String (PsiType type) { if (!(type instanceof PsiArrayType)) { final String canonical = type.getCanonicalText(); final String text = canonical != null ? canonical : type.getPresentableText(); if (PsiKeyword.NULL.equals(text)) { return ""; } else { return text; } } else { return getTypeText(((PsiArrayType)type).getComponentType()) + "[]"; } }
getTypeText
34,468
GrTopStatement (@NotNull String text) { GroovyFile dummyFile = createGroovyFileChecked(text); final GrTopStatement[] topStatements = dummyFile.getTopStatements(); if (topStatements.length != 1) throw new IncorrectOperationException("text = '" + text + "'"); return topStatements[0]; }
createTopElementFromText
34,469
GroovyFileImpl (@NotNull CharSequence text, boolean physical) { final String fileName = DUMMY_FILE_NAME + '.' + GroovyFileType.GROOVY_FILE_TYPE.getDefaultExtension(); final long stamp = System.currentTimeMillis(); final PsiFileFactory factory = PsiFileFactory.getInstance(myProject); return (GroovyFileImpl) factory.createFileFromText(fileName, GroovyFileType.GROOVY_FILE_TYPE, text, stamp, physical); }
createDummyFile
34,470
PsiClassType (@NotNull PsiClass aClass) { return JavaPsiFacade.getElementFactory(myProject).createType(aClass); }
createType
34,471
GrParenthesizedExpression (@NotNull GrExpression expression, @Nullable PsiElement context) { return ((GrParenthesizedExpression)createExpressionFromText("(" + expression.getText() + ")", context)); }
createParenthesizedExpr
34,472
PsiElement (@NotNull String text) { return createLiteralFromValue(text).getFirstChild(); }
createStringLiteralForReference
34,473
PsiElement (@NotNull String name) { final GroovyFileBase file = createGroovyFileChecked(name + " foo() {}"); final GrTopStatement[] definitions = file.getTopStatements(); if (definitions.length != 1) throw new IncorrectOperationException(name); return definitions[0].getFirstChild().getFirstChild(); }
createModifierFromText
34,474
GrCodeBlock (@NotNull String text) { final GroovyFileBase file = createGroovyFileChecked("def foo () {" + text + "}"); final GrMethod method = (GrMethod) file.getTopStatements()[0]; return method.getBlock(); }
createMethodBodyFromText
34,475
GrVariableDeclaration (@NotNull String name, @NotNull String typeText) { String classText; if (Character.isLowerCase(typeText.charAt(0))) { classText = "class A { def " + typeText + " " + name + "}"; } else { classText = "class A { " + typeText + " " + name + "}"; } GroovyFileBase file = createGroovyFileChecked(classText); final GrTypeDefinitionBody body = file.getTypeDefinitions()[0].getBody(); return (GrVariableDeclaration) body.getMemberDeclarations()[0]; }
createSimpleVariableDeclaration
34,476
PsiElement (@NotNull String newDot) { return createReferenceExpressionFromText("a" + newDot + "b").getDotToken(); }
createDotToken
34,477
GrMethod (@NotNull String constructorName, String @Nullable [] paramTypes, String @NotNull [] paramNames, @Nullable String body, @Nullable PsiElement context) { final CharSequence text = generateMethodText(null, constructorName, null, paramTypes, paramNames, body, true); return createConstructorFromText(constructorName, text, context); }
createConstructorFromText
34,478
GrMethod (String constructorName, CharSequence constructorText, @Nullable PsiElement context) { GroovyFile file = createGroovyFileChecked("class " + constructorName + "{" + constructorText + "}", false, context); GrTypeDefinition definition = file.getTypeDefinitions()[0]; if (definition == null) { throw new IncorrectOperationException("constructorName: " + constructorName + ", text: " + constructorText); } GrMethod[] methods = definition.getCodeMethods(); if (methods.length != 1) { throw new IncorrectOperationException("constructorName: " + constructorName + ", text: " + constructorText); } return methods[0]; }
createConstructorFromText
34,479
GrMethod (String methodText, @Nullable PsiElement context) { if (methodText == null) throw new IncorrectOperationException("Method text not provided"); GroovyFile file = createGroovyFile(methodText, false, context); GrTopStatement[] definitions = file.getTopStatements(); if (definitions.length != 1) { throw new IncorrectOperationException("Can't create method from text: '" + file.getText() + "'"); } GrTopStatement definition = definitions[0]; if (!(definition instanceof GrMethod)) { throw new IncorrectOperationException("Can't create method from text: '" + file.getText() + "'"); } return ((GrMethod)definition); }
createMethodFromText
34,480
GrAnnotation (@NotNull @NonNls String annotationText, @Nullable PsiElement context) { return createElementFromText(annotationText, context, ANNOTATION, GrAnnotation.class); }
createAnnotationFromText
34,481
GrAnnotationNameValuePair (@NotNull String text, @Nullable PsiElement context) { return createElementFromText(text, context, ANNOTATION_MEMBER_VALUE_PAIR, GrAnnotationNameValuePair.class); }
createAnnotationAttribute
34,482
GrMethod (@NotNull String name, @NotNull GrSignature signature) { StringBuilder builder = new StringBuilder(PsiKeyword.PUBLIC); final PsiType returnType = signature.getReturnType(); if (returnType != null && returnType != PsiTypes.nullType()) { builder.append(' '); builder.append(returnType.getCanonicalText()); } builder.append(' ').append(name).append('('); int i = 0; for (GrClosureParameter parameter : signature.getParameters()) { final PsiType type = parameter.getType(); if (type != null) { builder.append(type.getCanonicalText()); builder.append(' '); } builder.append('p').append(++i); final GrExpression initializer = parameter.getDefaultInitializer(); if (initializer != null) { builder.append(" = ").append(initializer.getText()); builder.append(", "); } } if (signature.getParameterCount() > 0) { builder.delete(builder.length() - 2, builder.length()); } builder.append("){}"); return createMethodFromText(builder); }
createMethodFromSignature
34,483
GrAnnotation (@NotNull String annoText) { return createAnnotationFromText(annoText, null); }
createAnnotationFromText
34,484
GroovyFile (@NlsSafe @NotNull CharSequence idText) { return createGroovyFileChecked(idText, false, null); }
createGroovyFileChecked
34,485
GroovyFile (@NlsSafe @NotNull CharSequence idText, boolean isPhysical, @Nullable PsiElement context) { final GroovyFileImpl file = createDummyFile(idText, isPhysical); if (ErrorUtil.containsError(file)) { throw new IncorrectOperationException("cannot create file from text: " + idText); } file.setContext(context); return file; }
createGroovyFileChecked
34,486
GroovyFile (@NotNull CharSequence idText, boolean isPhysical, @Nullable PsiElement context) { GroovyFileImpl file = createDummyFile(idText, isPhysical); file.setContext(context); return file; }
createGroovyFile
34,487
PsiElement () { PsiFile dummyFile = createDummyFile(" ", false); return dummyFile.getFirstChild(); }
createWhiteSpace
34,488
PsiElement (int length) { String text = length <= 1 ? "\n" : ""; if (length > 1) { text = StringUtil.repeatSymbol('\n', length); } return createLineTerminator(text); }
createLineTerminator
34,489
PsiElement (@NotNull String text) { PsiFile dummyFile = createGroovyFileChecked(text); PsiElement child = dummyFile.getFirstChild(); assert child != null; return child; }
createLineTerminator
34,490
GrArgumentList (GrExpression... expressions) { @NonNls StringBuilder text = new StringBuilder(); text.append("ven ("); for (GrExpression expression : expressions) { text.append(expression.getText()).append(", "); } if (expressions.length > 0) { text.delete(text.length() - 2, text.length()); } text.append(')'); PsiFile file = createGroovyFileChecked(text); assert file.getChildren()[0] != null && (file.getChildren()[0] instanceof GrMethodCallExpression); return (((GrMethodCallExpression) file.getChildren()[0])).getArgumentList(); }
createExpressionArgumentList
34,491
GrNamedArgument (@NotNull final String name, @NotNull final GrExpression expression) { PsiFile file = createGroovyFileChecked("foo (" + name + ":" + expression.getText() + ")"); assert file.getChildren()[0] != null; GrCall call = (GrCall)file.getChildren()[0]; return call.getArgumentList().getNamedArguments()[0]; }
createNamedArgument
34,492
GrStatement (@NotNull CharSequence text) { return createStatementFromText(text, null); }
createStatementFromText
34,493
GrStatement (@NotNull CharSequence text, @Nullable PsiElement context) { GroovyFile file = createGroovyFileChecked(text, false, context); GrTopStatement[] statements = file.getTopStatements(); if (statements.length != 1) { throw new IncorrectOperationException("count = " + statements.length + ", " + text); } if (!(statements[0] instanceof GrStatement)) { throw new IncorrectOperationException("type = " + statements[0].getClass().getName() + ", " + text); } return (GrStatement)statements[0]; }
createStatementFromText
34,494
GrMethodCallExpression (@NotNull GrApplicationStatement callExpr) { StringBuilder text = new StringBuilder(); text.append(callExpr.getInvokedExpression().getText()); text.append("("); final GrCommandArgumentList argumentList = callExpr.getArgumentList(); if (argumentList != null) text.append(argumentList.getText()); text.append(")"); PsiFile file = createGroovyFileChecked(text); assert file.getChildren()[0] != null && (file.getChildren()[0] instanceof GrMethodCallExpression); return ((GrMethodCallExpression)file.getChildren()[0]); }
createMethodCallByAppCall
34,495
GrCodeReferenceElement (@NotNull PsiClass aClass) { String qualifiedName = aClass.getQualifiedName(); if (qualifiedName == null) { throw new IncorrectOperationException("cannot create code reference element for class " + aClass.getText()); } return createCodeReference(qualifiedName); }
createCodeReferenceElementFromClass
34,496
GrReferenceExpression (@Nullable PsiClass psiClass) { final String text; if (psiClass == null) { text = "this"; } else { final String qname = psiClass.getQualifiedName(); if (StringUtil.isEmpty(qname)) { text = "this"; } else { text = qname + ".this"; } } return createReferenceExpressionFromText(text, psiClass); }
createThisExpression
34,497
GrBlockStatement (@NotNull String text, @Nullable PsiElement context) { return createElementFromText(text, context, BLOCK_STATEMENT, GrBlockStatement.class); }
createBlockStatementFromText
34,498
GrModifierList (@NotNull CharSequence text) { final GrMethod method = createMethodFromText(text + " void foo()"); return method.getModifierList(); }
createModifierList
34,499
GrCaseSection (@NotNull String text) { final GrStatement statement = createStatementFromText("switch (a) {\n" + text + "\n}"); if (!(statement instanceof GrSwitchElement)) { throw new IncorrectOperationException("Cannot create switch section from text: " + text); } final GrCaseSection[] sections = ((GrSwitchElement)statement).getCaseSections(); if (sections.length != 1) throw new IncorrectOperationException("Cannot create switch section from text: " + text); return sections[0]; }
createSwitchSection