public String getAllModifierProperties( LightModifierList modifierList ) { final StringBuilder builder = StringBuilderSpinAllocator.alloc(); try { for( String modifier : modifierList.getModifiers() ) { if( !PsiModifier.PACKAGE_LOCAL.equals( modifier ) ) { builder.append( modifier ).append( ' ' ); } } return builder.toString(); } finally { StringBuilderSpinAllocator.dispose( builder ); } }
private static void validate(@NotNull PsiElement reference, @Nullable PsiMember member, ProblemsHolder h) { if (member == null || !isAnnotatedAsTestOnly(member)) return; if (isInsideTestOnlyMethod(reference)) return; if (isInsideTestClass(reference)) return; if (isUnderTestSources(reference)) return; PsiAnnotation anno = findVisibleForTestingAnnotation(member); if (anno != null) { String modifier = getAccessModifierWithoutTesting(anno); if (modifier == null) { modifier = member.hasModifierProperty(PsiModifier.PUBLIC) ? PsiModifier.PROTECTED : member.hasModifierProperty(PsiModifier.PROTECTED) ? PsiModifier.PACKAGE_LOCAL : PsiModifier.PRIVATE; } LightModifierList modList = new LightModifierList(member.getManager(), JavaLanguage.INSTANCE, modifier); if (JavaResolveUtil.isAccessible(member, member.getContainingClass(), modList, reference, null, null)) { return; } } reportProblem(reference, member, h); }
public AndroidLightField(@NotNull String name, @NotNull PsiClass context, @NotNull PsiType type, boolean isFinal, @Nullable Object constantValue) { super(context.getManager(), JavaLanguage.INSTANCE); myName = name; myType = type; myContext = context; myConstantValue = constantValue; final List<String> modifiers = new ArrayList<String>(); modifiers.add(PsiModifier.PUBLIC); modifiers.add(PsiModifier.STATIC); if (isFinal) { modifiers.add(PsiModifier.FINAL); } myModifierList = new LightModifierList(getManager(), getLanguage(), ArrayUtil.toStringArray(modifiers)); }
private PsiMethod rebuildMethodFromString() { final StringBuilder builder = StringBuilderSpinAllocator.alloc(); try { builder.append(getAllModifierProperties((LightModifierList) getModifierList())); PsiType returnType = getReturnType(); if (null != returnType) { builder.append(returnType.getCanonicalText()).append(' '); } builder.append(getName()); builder.append('('); if (getParameterList().getParametersCount() > 0) { for (PsiParameter parameter : getParameterList().getParameters()) { builder.append(parameter.getType().getCanonicalText()).append(' ').append(parameter.getName()).append(','); } builder.deleteCharAt(builder.length() - 1); } builder.append(')'); builder.append('{').append(" ").append('}'); PsiElementFactory elementFactory = JavaPsiFacade.getInstance(getManager().getProject()).getElementFactory(); return elementFactory.createMethodFromText(builder.toString(), getContainingClass()); } finally { StringBuilderSpinAllocator.dispose(builder); } }
private static void validate(PsiCallExpression e, ProblemsHolder h) { PsiMethod method = e.resolveMethod(); if (method == null || !isAnnotatedAsTestOnly(method)) return; if (isInsideTestOnlyMethod(e)) return; if (isInsideTestClass(e)) return; if (isUnderTestSources(e)) return; PsiAnnotation anno = findVisibleForTestingAnnotation(method); if (anno != null) { LightModifierList modList = new LightModifierList(method.getManager(), JavaLanguage.INSTANCE, getAccessModifierWithoutTesting(anno)); if (JavaResolveUtil.isAccessible(method, method.getContainingClass(), modList, e, null, null)) { return; } } reportProblem(e, h); }
private PsiMethod rebuildMethodFromString() { final StringBuilder methodTextDeclaration = new StringBuilder(); methodTextDeclaration.append(getAllModifierProperties((LightModifierList) getModifierList())); PsiType returnType = getReturnType(); if (null != returnType) { methodTextDeclaration.append(returnType.getCanonicalText()).append(' '); } methodTextDeclaration.append(getName()); methodTextDeclaration.append('('); if (getParameterList().getParametersCount() > 0) { for (PsiParameter parameter : getParameterList().getParameters()) { methodTextDeclaration.append(parameter.getType().getCanonicalText()).append(' ').append(parameter.getName()).append(','); } methodTextDeclaration.deleteCharAt(methodTextDeclaration.length() - 1); } methodTextDeclaration.append(')'); methodTextDeclaration.append('{').append(" ").append('}'); final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(getManager().getProject()); final PsiMethod methodFromText = elementFactory.createMethodFromText(methodTextDeclaration.toString(), getContainingClass()); if (null != getBody()) { methodFromText.getBody().replace(getBody()); } return methodFromText; }
public ManLightParameterImpl( String name, PsiType type, PsiElement declarationScope, Language language ) { super( name, type, declarationScope, language ); PsiManager manager = declarationScope.getManager(); myNameIdentifier = new LightIdentifier( manager, name ); ReflectionUtil.setFinalFieldPerReflection( LightVariableBuilder.class, this, LightModifierList.class, new ManLightModifierListImpl( manager, language ) ); }
private PsiMethod rebuildMethodFromString() { final StringBuilder builder = StringBuilderSpinAllocator.alloc(); try { builder.append( getAllModifierProperties( (LightModifierList)getModifierList() ) ); PsiType returnType = getReturnType(); if( null != returnType ) { builder.append( returnType.getCanonicalText() ).append( ' ' ); } builder.append( getName() ); builder.append( '(' ); if( getParameterList().getParametersCount() > 0 ) { for( PsiParameter parameter : getParameterList().getParameters() ) { builder.append( parameter.getType().getCanonicalText() ).append( ' ' ).append( parameter.getName() ).append( ',' ); } builder.deleteCharAt( builder.length() - 1 ); } builder.append( ')' ); builder.append( '{' ).append( " " ).append( '}' ); PsiElementFactory elementFactory = JavaPsiFacade.getInstance( getManager().getProject() ).getElementFactory(); return elementFactory.createMethodFromText( builder.toString(), getContainingClass() ); } finally { StringBuilderSpinAllocator.dispose( builder ); } }
private static boolean isInsideMethodSignature(PsiElement element, @NotNull PsiMethod method) { final PsiCodeBlock body = method.getBody(); final TextRange textRange = element.getTextRange(); final PsiModifierList psiModifierList = method.getModifierList(); if (psiModifierList instanceof LightModifierList) return false; if (body != null) { return textRange.getEndOffset() <= body.getTextOffset() && textRange.getStartOffset() >= psiModifierList.getTextRange().getEndOffset(); } return textRange.getStartOffset() >= psiModifierList.getTextRange().getEndOffset() && textRange.getEndOffset() <= method.getTextRange().getEndOffset(); }
public String getAllModifierProperties(LightModifierList modifierList) { final StringBuilder builder = StringBuilderSpinAllocator.alloc(); try { for (String modifier : modifierList.getModifiers()) { if (!PsiModifier.PACKAGE_LOCAL.equals(modifier)) { builder.append(modifier).append(' '); } } return builder.toString(); } finally { StringBuilderSpinAllocator.dispose(builder); } }
public SqliteMagicLightParameter(@NotNull String name, @NotNull PsiType type, PsiElement declarationScope, Language language) { super(name, type, declarationScope, language); myName = name; PsiManager manager = declarationScope.getManager(); myNameIdentifier = new SqliteMagicLightIdentifier(manager, name); ReflectionUtil.setFinalFieldPerReflection(LightVariableBuilder.class, this, LightModifierList.class, new SqliteMagicLightModifierList(manager, language)); }
public HoldrLightField(@NotNull String name, @NotNull final PsiClass context, @NotNull PsiType type, final boolean isNullable, @Nullable final Object constantValue) { super(context.getManager(), JavaLanguage.INSTANCE); myName = name; myType = type; myContext = context; myConstantValue = constantValue; final List<String> modifiers = new ArrayList<String>(); modifiers.add(PsiModifier.PUBLIC); myModifierList = new LightModifierList(getManager(), getLanguage(), ArrayUtil.toStringArray(modifiers)) { @NotNull @Override public PsiAnnotation[] getAnnotations() { if (isNullable) { PsiAnnotation[] annotations = new PsiAnnotation[1]; annotations[0] = new PsiElementFactoryImpl((PsiManagerEx) PsiManagerEx.getInstance(context.getProject())).createAnnotationFromText("@android.support.annotation.Nullable", HoldrLightField.this); return annotations; } else { return super.getAnnotations(); } } }; }
private String getAllModifierProperties(LightModifierList modifierList) { final StringBuilder builder = new StringBuilder(); for (String modifier : modifierList.getModifiers()) { if (!PsiModifier.PACKAGE_LOCAL.equals(modifier)) { builder.append(modifier).append(' '); } } return builder.toString(); }
public LombokLightParameter(@NotNull String name, @NotNull PsiType type, PsiElement declarationScope, Language language) { super(name, type, declarationScope, language); myName = name; PsiManager manager = declarationScope.getManager(); myNameIdentifier = new LombokLightIdentifier(manager, name); ReflectionUtil.setFinalFieldPerReflection(LightVariableBuilder.class, this, LightModifierList.class, new LombokLightModifierList(manager, language)); }
public ManLightParameterImpl setModifiers( String... modifiers ) { ManLightModifierListImpl modifierList = new ManLightModifierListImpl( getManager(), getLanguage(), modifiers ); ReflectionUtil.setFinalFieldPerReflection( LightVariableBuilder.class, this, LightModifierList.class, modifierList ); return this; }
@Override public ManLightFieldBuilder withModifier( @PsiModifier.ModifierConstant String modifier ) { ((LightModifierList)getModifierList()).addModifier( modifier ); return this; }
@Override public PsiModifierList getModifierList() { return new LightModifierList(myManager, getLanguage(), PsiModifier.PUBLIC, PsiModifier.STATIC, PsiModifier.FINAL); }
public GroovyScriptClass(GroovyFile file) { super(file.getManager(), file.getLanguage()); myFile = file; myModifierList = new LightModifierList(myManager, GroovyLanguage.INSTANCE, PsiModifier.PUBLIC); }
public GrAccessorMethodImpl(@NotNull GrField property, boolean isSetter, String name) { super(property.getManager(), GroovyLanguage.INSTANCE, name, new LightParameterListBuilder(property.getManager(), GroovyLanguage.INSTANCE), new LightModifierList(property.getManager()) { @Override public String getText() { final String[] modifiers = getModifiers(); if (modifiers.length == 0) return ""; if (modifiers.length == 1) return modifiers[0]; return StringUtil.join(modifiers, " "); } }); myProperty = property; myIsSetter = isSetter; if (myIsSetter) { PsiType type = myProperty.getDeclaredType(); if (type == null) { type = TypesUtil.getJavaLangObject(myProperty); } addParameter(myProperty.getName(), type); } setMethodReturnType(myIsSetter ? PsiType.VOID : myProperty.getType()); addModifier(PsiModifier.PUBLIC); if (myProperty.hasModifierProperty(PsiModifier.STATIC)) { addModifier(PsiModifier.STATIC); } else if (myProperty.hasModifierProperty(PsiModifier.FINAL)) { //don't add final modifier to static method addModifier(PsiModifier.FINAL); } if (GrTraitUtil.isTrait(property.getContainingClass())) { addModifier(PsiModifier.ABSTRACT); } setNavigationElement(property); setBaseIcon(JetgroovyIcons.Groovy.Property); setContainingClass(myProperty.getContainingClass()); setMethodKind("AccessorMethod"); setOriginInfo("synthetic accessor for '"+myProperty.getName()+"'"); }
public SqliteMagicLightFieldBuilder withModifier(@PsiModifier.ModifierConstant @NotNull @NonNls String modifier) { ((LightModifierList) getModifierList()).addModifier(modifier); return this; }
public SqliteMagicLightParameter setModifiers(String... modifiers) { SqliteMagicLightModifierList modifierList = new SqliteMagicLightModifierList(getManager(), getLanguage(), modifiers); ReflectionUtil.setFinalFieldPerReflection(LightVariableBuilder.class, this, LightModifierList.class, modifierList); return this; }
public GroovyScriptClass(GroovyFile file) { super(file.getManager(), file.getLanguage()); myFile = file; myModifierList = new LightModifierList(myManager, GroovyFileType.GROOVY_LANGUAGE, PsiModifier.PUBLIC); }
public GrAccessorMethodImpl(@NotNull GrField property, boolean isSetter, String name) { super(property.getManager(), GroovyFileType.GROOVY_LANGUAGE, name, new LightParameterListBuilder(property.getManager(), GroovyFileType.GROOVY_LANGUAGE), new LightModifierList(property.getManager()) { @Override public String getText() { final String[] modifiers = getModifiers(); if (modifiers.length == 0) return ""; if (modifiers.length == 1) return modifiers[0]; return StringUtil.join(modifiers, " "); } }); myProperty = property; myIsSetter = isSetter; if (myIsSetter) { PsiType type = myProperty.getDeclaredType(); if (type == null) { type = TypesUtil.getJavaLangObject(myProperty); } addParameter(myProperty.getName(), type); } setMethodReturnType(myIsSetter ? PsiType.VOID : myProperty.getType()); addModifier(PsiModifier.PUBLIC); if (myProperty.hasModifierProperty(PsiModifier.STATIC)) { addModifier(PsiModifier.STATIC); } else if (myProperty.hasModifierProperty(PsiModifier.FINAL)) { //don't add final modifier to static method addModifier(PsiModifier.FINAL); } setNavigationElement(property); setBaseIcon(JetgroovyIcons.Groovy.Property); setContainingClass(myProperty.getContainingClass()); setMethodKind("AccessorMethod"); setOriginInfo("synthetic accessor for '"+myProperty.getName()+"'"); }
public void withModifiers(@NotNull String... modifiers) { myModifierList = new LightModifierList(getManager(), JavaLanguage.INSTANCE, modifiers); }
public LombokLightFieldBuilder withModifier(@PsiModifier.ModifierConstant @NotNull @NonNls String modifier) { ((LightModifierList) getModifierList()).addModifier(modifier); return this; }
public LombokLightParameter setModifiers(String... modifiers) { LombokLightModifierList modifierList = new LombokLightModifierList(getManager(), getLanguage(), modifiers); ReflectionUtil.setFinalFieldPerReflection(LightVariableBuilder.class, this, LightModifierList.class, modifierList); return this; }
@NotNull @Override public PsiModifierList getModifierList() { return new LightModifierList(getManager()); }