Java 类com.intellij.psi.impl.light.LightModifierList 实例源码

项目:manifold-ij    文件:ManLightMethodBuilderImpl.java   
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 );
  }
}
项目:intellij-ce-playground    文件:TestOnlyInspection.java   
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);
}
项目:intellij-ce-playground    文件:AndroidLightField.java   
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));
}
项目:sqlitemagic    文件:SqliteMagicLightMethodBuilder.java   
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);
  }
}
项目:holdr    文件:HoldrLightMethodBuilder.java   
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);
    }
}
项目:tools-idea    文件:TestOnlyInspection.java   
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);
}
项目:lombok-intellij-plugin    文件:LombokLightMethodBuilder.java   
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;
}
项目:manifold-ij    文件:ManLightParameterImpl.java   
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 ) );
}
项目:manifold-ij    文件:ManLightMethodBuilderImpl.java   
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 );
  }
}
项目:intellij-ce-playground    文件:JavaChangeSignatureDetector.java   
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();
}
项目:sqlitemagic    文件:SqliteMagicLightMethodBuilder.java   
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);
  }
}
项目:sqlitemagic    文件:SqliteMagicLightParameter.java   
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));
}
项目:holdr    文件:HoldrLightField.java   
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();
            }
        }
    };
}
项目:holdr    文件:HoldrLightMethodBuilder.java   
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);
    }
}
项目:tools-idea    文件:JavaChangeSignatureDetector.java   
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();
}
项目:lombok-intellij-plugin    文件:LombokLightMethodBuilder.java   
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();
}
项目:lombok-intellij-plugin    文件:LombokLightParameter.java   
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));
}
项目:manifold-ij    文件:ManLightParameterImpl.java   
public ManLightParameterImpl setModifiers( String... modifiers )
{
  ManLightModifierListImpl modifierList = new ManLightModifierListImpl( getManager(), getLanguage(), modifiers );
  ReflectionUtil.setFinalFieldPerReflection( LightVariableBuilder.class, this, LightModifierList.class, modifierList );
  return this;
}
项目:manifold-ij    文件:ManLightFieldBuilderImpl.java   
@Override
public ManLightFieldBuilder withModifier( @PsiModifier.ModifierConstant String modifier )
{
  ((LightModifierList)getModifierList()).addModifier( modifier );
  return this;
}
项目:intellij-ce-playground    文件:AndroidLightClassBase.java   
@Override
public PsiModifierList getModifierList() {
  return new LightModifierList(myManager, getLanguage(), PsiModifier.PUBLIC, PsiModifier.STATIC, PsiModifier.FINAL);
}
项目:intellij-ce-playground    文件:GroovyScriptClass.java   
public GroovyScriptClass(GroovyFile file) {
  super(file.getManager(), file.getLanguage());
  myFile = file;

  myModifierList = new LightModifierList(myManager, GroovyLanguage.INSTANCE, PsiModifier.PUBLIC);
}
项目:intellij-ce-playground    文件:GrAccessorMethodImpl.java   
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()+"'");
}
项目:sqlitemagic    文件:SqliteMagicLightFieldBuilder.java   
public SqliteMagicLightFieldBuilder withModifier(@PsiModifier.ModifierConstant @NotNull @NonNls String modifier) {
  ((LightModifierList) getModifierList()).addModifier(modifier);
  return this;
}
项目:sqlitemagic    文件:SqliteMagicLightParameter.java   
public SqliteMagicLightParameter setModifiers(String... modifiers) {
  SqliteMagicLightModifierList modifierList = new SqliteMagicLightModifierList(getManager(), getLanguage(), modifiers);
  ReflectionUtil.setFinalFieldPerReflection(LightVariableBuilder.class, this, LightModifierList.class, modifierList);
  return this;
}
项目:tools-idea    文件:GroovyScriptClass.java   
public GroovyScriptClass(GroovyFile file) {
  super(file.getManager(), file.getLanguage());
  myFile = file;

  myModifierList = new LightModifierList(myManager, GroovyFileType.GROOVY_LANGUAGE, PsiModifier.PUBLIC);
}
项目:tools-idea    文件:GrAccessorMethodImpl.java   
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()+"'");
}
项目:consulo-ikvm    文件:DotNetTypeToJavaClass.java   
public void withModifiers(@NotNull String... modifiers)
{
    myModifierList = new LightModifierList(getManager(), JavaLanguage.INSTANCE, modifiers);
}
项目:lombok-intellij-plugin    文件:LombokLightFieldBuilder.java   
public LombokLightFieldBuilder withModifier(@PsiModifier.ModifierConstant @NotNull @NonNls String modifier) {
  ((LightModifierList) getModifierList()).addModifier(modifier);
  return this;
}
项目:lombok-intellij-plugin    文件:LombokLightParameter.java   
public LombokLightParameter setModifiers(String... modifiers) {
  LombokLightModifierList modifierList = new LombokLightModifierList(getManager(), getLanguage(), modifiers);
  ReflectionUtil.setFinalFieldPerReflection(LightVariableBuilder.class, this, LightModifierList.class, modifierList);
  return this;
}
项目:consulo-javaee    文件:JspHolderMethodImpl.java   
@NotNull
@Override
public PsiModifierList getModifierList()
{
    return new LightModifierList(getManager());
}