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

项目:intellij-ce-playground    文件:AutoExternalizeContributor.java   
@Override
public void collectMethods(@NotNull GrTypeDefinition clazz, @NotNull Collection<PsiMethod> collector) {
  if (!hasGeneratedImplementations(clazz)) return;

  final LightMethodBuilder write = new LightMethodBuilder(clazz.getManager(), "writeExternal");
  write.setContainingClass(clazz);
  write.addParameter("out", ObjectOutput.class.getName());
  write.addException(IOException.class.getName());
  write.setOriginInfo("created by @AutoExternalize");
  collector.add(write);

  final LightMethodBuilder read = new LightMethodBuilder(clazz.getManager(), "readExternal");
  read.setContainingClass(clazz);
  read.addParameter("oin", ObjectInput.class.getName());
  read.setOriginInfo("created by @AutoExternalize");
  collector.add(read);
}
项目:intellij-ce-playground    文件:DefaultBuilderStrategySupport.java   
@NotNull
private LightPsiClassBuilder createBuilderClass(@NotNull final PsiAnnotation annotation,
                                                @NotNull GrVariable[] setters,
                                                @Nullable PsiType builtType) {
  final LightPsiClassBuilder builderClass = new BuilderHelperLightPsiClass(
    myContainingClass, getBuilderClassName(annotation, myContainingClass)
  );

  for (GrVariable field : setters) {
    builderClass.addMethod(createFieldSetter(builderClass, field, annotation));
  }

  final LightMethodBuilder buildMethod = createBuildMethod(
    annotation, builtType == null ? myElementFactory.createType(myContainingClass) : builtType, builderClass
  );
  return builderClass.addMethod(buildMethod);
}
项目:intellij-ce-playground    文件:InitializerBuilderStrategySupport.java   
@NotNull
private LightMethodBuilder createFieldSetter(@NotNull LightPsiClassBuilder builderClass,
                                             @NotNull GrVariable field,
                                             @NotNull PsiAnnotation annotation,
                                             int currentField) {
  final String name = field.getName();
  final LightMethodBuilder fieldSetter = new LightMethodBuilder(builderClass.getManager(), getFieldMethodName(annotation, name));
  final PsiSubstitutor substitutor = PsiSubstitutor.EMPTY.put(
    builderClass.getTypeParameters()[currentField],
    myElementFactory.createTypeByFQClassName(SET_FQN, annotation.getResolveScope())
  );
  fieldSetter.addModifier(PsiModifier.PUBLIC);
  fieldSetter.addParameter(name, field.getType());
  fieldSetter.setContainingClass(builderClass);
  fieldSetter.setMethodReturnType(myElementFactory.createType(builderClass, substitutor));
  fieldSetter.setNavigationElement(field);
  fieldSetter.setOriginInfo(ORIGIN_INFO);
  return fieldSetter;
}
项目:intellij-ce-playground    文件:AntTasksProvider.java   
public static Set<LightMethodBuilder> getAntTasks(PsiElement place) {
  final PsiFile file = place.getContainingFile();
  if (!(file instanceof GroovyFile)) {
    return Collections.emptySet();
  }

  return CachedValuesManager.getManager(file.getProject()).getCachedValue(file, GANT_METHODS, new CachedValueProvider<Set<LightMethodBuilder>>() {
    @Override
    public Result<Set<LightMethodBuilder>> compute() {
      Map<String, Class> antObjects = getAntObjects((GroovyFile)file);

      final Set<LightMethodBuilder> methods = new HashSet<LightMethodBuilder>();

      final Project project = file.getProject();
      final PsiType closureType = TypesUtil.createType(GroovyCommonClassNames.GROOVY_LANG_CLOSURE, file);
      final PsiClassType stringType = TypesUtil.createType(CommonClassNames.JAVA_LANG_STRING, file);

      for (String name : antObjects.keySet()) {
        methods.add(new AntBuilderMethod(file, name, closureType, antObjects.get(name), stringType));
      }
      return Result.create(methods, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT, ProjectRootManager.getInstance(project));
    }
  }, false);
}
项目:intellij-ce-playground    文件:StubGenerator.java   
private static LightMethodBuilder mirrorMethod(PsiClass typeDefinition,
                                               PsiMethod method,
                                               PsiClass baseClass,
                                               PsiSubstitutor substitutor) {
  final LightMethodBuilder builder = new LightMethodBuilder(method.getManager(), method.getName());
  substitutor = substitutor.putAll(TypeConversionUtil.getSuperClassSubstitutor(baseClass, typeDefinition, PsiSubstitutor.EMPTY));
  for (PsiParameter parameter : method.getParameterList().getParameters()) {
    builder.addParameter(StringUtil.notNullize(parameter.getName()), substitutor.substitute(parameter.getType()));
  }
  builder.setMethodReturnType(substitutor.substitute(method.getReturnType()));
  for (String modifier : STUB_MODIFIERS) {
    if (method.hasModifierProperty(modifier)) {
      builder.addModifier(modifier);
    }
  }
  return builder;
}
项目:tools-idea    文件:AutoExternalizeContributor.java   
@Override
public void collectMethods(@NotNull GrTypeDefinition clazz, @NotNull Collection<PsiMethod> collector) {
  if (!hasGeneratedImplementations(clazz)) return;

  final LightMethodBuilder write = new LightMethodBuilder(clazz.getManager(), "writeExternal");
  write.setContainingClass(clazz);
  write.addParameter("out", ObjectOutput.class.getName());
  write.addException(IOException.class.getName());
  write.setOriginInfo("created by @AutoExternalize");
  collector.add(write);

  final LightMethodBuilder read = new LightMethodBuilder(clazz.getManager(), "readExternal");
  read.setContainingClass(clazz);
  read.addParameter("oin", ObjectInput.class.getName());
  read.setOriginInfo("created by @AutoExternalize");
  collector.add(read);
}
项目:tools-idea    文件:AntTasksProvider.java   
public static Set<LightMethodBuilder> getAntTasks(PsiElement place) {
  final PsiFile file = place.getContainingFile();
  if (!(file instanceof GroovyFile)) {
    return Collections.emptySet();
  }

  return CachedValuesManager.getManager(file.getProject()).getCachedValue(file, GANT_METHODS, new CachedValueProvider<Set<LightMethodBuilder>>() {
    @Override
    public Result<Set<LightMethodBuilder>> compute() {
      Map<String, Class> antObjects = getAntObjects((GroovyFile)file);

      final Set<LightMethodBuilder> methods = new HashSet<LightMethodBuilder>();

      final Project project = file.getProject();
      final PsiType closureType = TypesUtil.createType(GroovyCommonClassNames.GROOVY_LANG_CLOSURE, file);
      final PsiClassType stringType = TypesUtil.createType(CommonClassNames.JAVA_LANG_STRING, file);

      for (String name : antObjects.keySet()) {
        methods.add(new AntBuilderMethod(file, name, closureType, antObjects.get(name), stringType));
      }
      return Result.create(methods, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT, ProjectRootManager.getInstance(project));
    }
  }, false);
}
项目:tools-idea    文件:StubGenerator.java   
private static LightMethodBuilder mirrorMethod(PsiClass typeDefinition,
                                               PsiMethod method,
                                               PsiClass baseClass,
                                               PsiSubstitutor substitutor) {
  final LightMethodBuilder builder = new LightMethodBuilder(method.getManager(), method.getName());
  substitutor = substitutor.putAll(TypeConversionUtil.getSuperClassSubstitutor(baseClass, typeDefinition, PsiSubstitutor.EMPTY));
  for (PsiParameter parameter : method.getParameterList().getParameters()) {
    builder.addParameter(StringUtil.notNullize(parameter.getName()), substitutor.substitute(parameter.getType()));
  }
  builder.setMethodReturnType(substitutor.substitute(method.getReturnType()));
  for (String modifier : STUB_MODIFIERS) {
    if (method.hasModifierProperty(modifier)) {
      builder.addModifier(modifier);
    }
  }
  return builder;
}
项目:consulo-ikvm    文件:JavaMethodStubBuilder.java   
@NotNull
@Override
public PsiMethod buildToPsi(@Nullable PsiElement parent)
{
    PsiManager psiManager = PsiManager.getInstance(myNavTarget.getProject());
    LightMethodBuilder builder = new LightMethodBuilder(psiManager, myName);
    builder.setConstructor(myConstructor);
    builder.setModifiers(ArrayUtil.toStringArray(myModifiers));
    builder.setContainingClass((PsiClass) parent);
    builder.setMethodReturnType(normalizeType(myReturnType));
    builder.setNavigationElement(myNavTarget);
    for(JavaParameterStubBuilder parameter : myParameters)
    {
        builder.addParameter(parameter.buildToPsi(builder));
    }

    return builder;
}
项目:consulo-java    文件:JavaEnumAugmentProvider.java   
@NotNull
@Override
@SuppressWarnings("unchecked")
public <Psi extends PsiElement> List<Psi> getAugments(@NotNull PsiElement element, @NotNull Class<Psi> type)
{
    if(type == PsiMethod.class && element instanceof PsiClass && element.getUserData(FLAG) == Boolean.TRUE && ((PsiClass) element).isEnum())
    {
        List<Psi> list = new ArrayList<Psi>(2);

        LightMethodBuilder valuesMethod = new LightMethodBuilder(element.getManager(), JavaLanguage.INSTANCE, VALUES_METHOD_NAME);
        valuesMethod.setContainingClass((PsiClass) element);
        valuesMethod.setMethodReturnType(new PsiArrayType(new PsiImmediateClassType((PsiClass)element, PsiSubstitutor.EMPTY)));
        valuesMethod.addModifiers(PsiModifier.PUBLIC, PsiModifier.STATIC);
        list.add((Psi) valuesMethod);

        LightMethodBuilder valueOfMethod = new LightMethodBuilder(element.getManager(), JavaLanguage.INSTANCE, VALUE_OF_METHOD_NAME);
        valueOfMethod.setContainingClass((PsiClass) element);
        valueOfMethod.setMethodReturnType(new PsiImmediateClassType((PsiClass) element, PsiSubstitutor.EMPTY));
        valueOfMethod.addModifiers(PsiModifier.PUBLIC, PsiModifier.STATIC);
        valueOfMethod.addParameter("name", JavaClassNames.JAVA_LANG_STRING);
        valueOfMethod.addException(JavaClassNames.JAVA_LANG_ILLEGAL_ARGUMENT_EXCEPTION);
        list.add((Psi) valueOfMethod);
        return list;
    }
    return Collections.emptyList();
}
项目:intellij-ce-playground    文件:AutoCloneContributor.java   
@Override
public void collectMethods(@NotNull GrTypeDefinition clazz, @NotNull Collection<PsiMethod> collector) {
  if (PsiImplUtil.getAnnotation(clazz, GroovyCommonClassNames.GROOVY_TRANSFORM_AUTO_CLONE) == null) return;

  final LightMethodBuilder clone = new LightMethodBuilder(clazz.getManager(), "clone");
  clone.addModifier(PsiModifier.PUBLIC);
  clone.setContainingClass(clazz);
  clone.addException(CloneNotSupportedException.class.getName());
  clone.setOriginInfo("created by @AutoClone");
  collector.add(clone);
}
项目:intellij-ce-playground    文件:DefaultBuilderStrategySupport.java   
@NotNull
private LightMethodBuilder createBuilderMethod(@NotNull PsiClass builderClass, @NotNull PsiAnnotation annotation) {
  final LightMethodBuilder builderMethod = new LightMethodBuilder(getManager(), getBuilderMethodName(annotation));
  builderMethod.addModifier(PsiModifier.STATIC);
  builderMethod.setContainingClass(myContainingClass);
  builderMethod.setOriginInfo(ORIGIN_INFO);
  builderMethod.setNavigationElement(annotation);
  builderMethod.setMethodReturnType(myElementFactory.createType(builderClass));
  return builderMethod;
}
项目:intellij-ce-playground    文件:DefaultBuilderStrategySupport.java   
@NotNull
public static LightMethodBuilder createBuildMethod(@NotNull PsiAnnotation annotation, @NotNull PsiType builtType, PsiClass builderClass) {
  final LightMethodBuilder buildMethod = new LightMethodBuilder(annotation.getManager(), getBuildMethodName(annotation));
  buildMethod.setContainingClass(builderClass);
  buildMethod.setOriginInfo(ORIGIN_INFO);
  buildMethod.setMethodReturnType(builtType);
  return buildMethod;
}
项目:intellij-ce-playground    文件:DefaultBuilderStrategySupport.java   
@NotNull
public static LightMethodBuilder createFieldSetter(@NotNull PsiClass builderClass, @NotNull GrVariable field, @NotNull PsiAnnotation annotation) {
  final String name = field.getName();
  final LightMethodBuilder fieldSetter = new LightMethodBuilder(builderClass.getManager(), getFieldMethodName(annotation, name));
  fieldSetter.addModifier(PsiModifier.PUBLIC);
  fieldSetter.addParameter(name, field.getType());
  fieldSetter.setContainingClass(builderClass);
  fieldSetter.setMethodReturnType(JavaPsiFacade.getElementFactory(builderClass.getProject()).createType(builderClass));
  fieldSetter.setNavigationElement(field);
  fieldSetter.setOriginInfo(ORIGIN_INFO);
  return fieldSetter;
}
项目:intellij-ce-playground    文件:SimpleBuilderStrategySupport.java   
@NotNull
public static LightMethodBuilder createFieldSetter(@NotNull PsiClass builderClass, @NotNull GrVariable field, @NotNull PsiAnnotation annotation) {
  final String name = field.getName();
  final LightMethodBuilder fieldSetter = new LightMethodBuilder(builderClass.getManager(), getFieldMethodName(annotation, name));
  fieldSetter.addModifier(PsiModifier.PUBLIC);
  fieldSetter.addParameter(name, field.getType(), false);
  fieldSetter.setContainingClass(builderClass);
  fieldSetter.setMethodReturnType(createType(builderClass));
  fieldSetter.setNavigationElement(field);
  fieldSetter.setOriginInfo(ORIGIN_INFO);
  return fieldSetter;
}
项目:intellij-ce-playground    文件:InitializerBuilderStrategySupport.java   
private LightMethodBuilder createBuildMethod(@NotNull PsiAnnotation annotation, @NotNull PsiClass builderClass) {
  LightMethodBuilder buildMethod = new LightMethodBuilder(annotation.getManager(), builderClass.getLanguage(), getBuildMethodName(annotation));
  buildMethod.addModifier(PsiModifier.STATIC);
  buildMethod.setContainingClass(builderClass);
  buildMethod.setOriginInfo(ORIGIN_INFO);
  buildMethod.setNavigationElement(annotation);
  buildMethod.setMethodReturnType(createAllSetUnsetType(builderClass, false));
  return buildMethod;
}
项目:intellij-ce-playground    文件:InitializerBuilderStrategySupport.java   
@NotNull
private LightMethodBuilder createBuilderMethod(@NotNull PsiClass builderClass, @NotNull PsiAnnotation annotation) {
  final LightMethodBuilder builderMethod = new LightMethodBuilder(getManager(), getBuilderMethodName(annotation));
  builderMethod.addModifier(PsiModifier.STATIC);
  builderMethod.setContainingClass(myContainingClass);
  builderMethod.setOriginInfo(ORIGIN_INFO);
  builderMethod.setNavigationElement(annotation);
  builderMethod.setMethodReturnType(createAllSetUnsetType(builderClass, false));
  return builderMethod;
}
项目:intellij-ce-playground    文件:InitializerBuilderStrategySupport.java   
@NotNull
private LightMethodBuilder createBuilderConstructor(@NotNull PsiClass constructedClass, @NotNull PsiClass builderClass, PsiAnnotation annotation) {
  final LightMethodBuilder constructor = new LightMethodBuilder(constructedClass, constructedClass.getLanguage()).addParameter(
    "builder", createAllSetUnsetType(builderClass, true)
  ).setConstructor(true);
  constructor.setNavigationElement(annotation);
  constructor.setOriginInfo(ORIGIN_INFO);
  return constructor;
}
项目:intellij-ce-playground    文件:GroovyScriptClass.java   
private synchronized void initMethods() {
  if (myInitialized) return;
  myMainMethod = new LightMethodBuilder(getManager(), GroovyLanguage.INSTANCE, "main").
    setContainingClass(this).
    setMethodReturnType(PsiType.VOID).
    addParameter("args", new PsiArrayType(PsiType.getJavaLangString(getManager(), getResolveScope()))).
    addModifiers(PsiModifier.PUBLIC, PsiModifier.STATIC);
  myRunMethod = new LightMethodBuilder(getManager(), GroovyLanguage.INSTANCE, "run").
    setContainingClass(this).
    setMethodReturnType(TypesUtil.getJavaLangObject(this)).
    addModifier(PsiModifier.PUBLIC);

  myInitialized = true;
}
项目:intellij-ce-playground    文件:GrEnumTypeDefinitionImpl.java   
private PsiMethod[] getDefEnumMethods() {
  return CachedValuesManager.getCachedValue(this, new CachedValueProvider<PsiMethod[]>() {
    @Override
    public Result<PsiMethod[]> compute() {
      PsiMethod[] defMethods = new PsiMethod[4];
      final PsiManagerEx manager = getManager();
      final PsiElementFactory factory = JavaPsiFacade.getElementFactory(getProject());
      defMethods[0] = new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "values")
        .setMethodReturnType(factory.createTypeFromText(CommonClassNames.JAVA_UTIL_COLLECTION + "<" + getName() + ">", GrEnumTypeDefinitionImpl.this))
        .setContainingClass(GrEnumTypeDefinitionImpl.this)
        .addModifier(PsiModifier.PUBLIC)
        .addModifier(PsiModifier.STATIC);

      defMethods[1] = new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "next")
        .setMethodReturnType(factory.createType(GrEnumTypeDefinitionImpl.this))
        .setContainingClass(GrEnumTypeDefinitionImpl.this)
        .addModifier(PsiModifier.PUBLIC);

      defMethods[2] = new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "previous")
        .setMethodReturnType(factory.createType(GrEnumTypeDefinitionImpl.this))
        .setContainingClass(GrEnumTypeDefinitionImpl.this)
        .addModifier(PsiModifier.PUBLIC);

      defMethods[3] = new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "valueOf")
        .setMethodReturnType(factory.createType(GrEnumTypeDefinitionImpl.this))
        .setContainingClass(GrEnumTypeDefinitionImpl.this)
        .addParameter("name", CommonClassNames.JAVA_LANG_STRING)
        .addModifier(PsiModifier.PUBLIC)
        .addModifier(PsiModifier.STATIC);

      return Result.create(defMethods, GrEnumTypeDefinitionImpl.this);
    }
  });
}
项目:intellij-ce-playground    文件:GantMemberContributor.java   
private static boolean processAntTasks(PsiScopeProcessor processor, PsiElement place, ResolveState state) {
  if (!AntTasksProvider.antAvailable) {
    return true;
  }

  for (LightMethodBuilder task : AntTasksProvider.getAntTasks(place)) {
    if (!ResolveUtil.processElement(processor, task, state)) {
      return false;
    }
  }
  return true;
}
项目:tools-idea    文件:AutoCloneContributor.java   
@Override
public void collectMethods(@NotNull GrTypeDefinition clazz, @NotNull Collection<PsiMethod> collector) {
  if (PsiImplUtil.getAnnotation(clazz, GroovyCommonClassNames.GROOVY_TRANSFORM_AUTO_CLONE) == null) return;

  final LightMethodBuilder clone = new LightMethodBuilder(clazz.getManager(), "clone");
  clone.addModifier(PsiModifier.PUBLIC);
  clone.setContainingClass(clazz);
  clone.addException(CloneNotSupportedException.class.getName());
  clone.setOriginInfo("created by @AutoClone");
  collector.add(clone);
}
项目:tools-idea    文件:GroovyScriptClass.java   
private synchronized void initMethods() {
  if (myInitialized) return;
  myMainMethod = new LightMethodBuilder(getManager(), GroovyFileType.GROOVY_LANGUAGE, "main").
    setContainingClass(this).
    setMethodReturnType(PsiType.VOID).
    addParameter("args", new PsiArrayType(PsiType.getJavaLangString(getManager(), getResolveScope()))).
    addModifiers(PsiModifier.PUBLIC, PsiModifier.STATIC);
  myRunMethod = new LightMethodBuilder(getManager(), GroovyFileType.GROOVY_LANGUAGE, "run").
    setContainingClass(this).
    setMethodReturnType(PsiType.getJavaLangObject(getManager(), getResolveScope())).
    addModifier(PsiModifier.PUBLIC);

  myInitialized = true;
}
项目:tools-idea    文件:GrEnumTypeDefinitionImpl.java   
private PsiMethod[] getDefEnumMethods() {
  CachedValue<PsiMethod[]> cached = getUserData(ENUM_METHODS);
  if (cached == null) {
    cached = CachedValuesManager.getManager(getProject()).createCachedValue(new CachedValueProvider<PsiMethod[]>() {
      @Override
      public Result<PsiMethod[]> compute() {
        PsiMethod[] defMethods = new PsiMethod[3];
        final PsiManagerEx manager = getManager();
        final PsiElementFactory factory = JavaPsiFacade.getElementFactory(getProject());
        defMethods[0] = new LightMethodBuilder(manager, GROOVY_LANGUAGE, "values")
          .setMethodReturnType(factory.createTypeFromText(JAVA_UTIL_COLLECTION + "<" + getName() + ">", GrEnumTypeDefinitionImpl.this))
          .setContainingClass(GrEnumTypeDefinitionImpl.this)
          .addModifier(PsiModifier.PUBLIC)
          .addModifier(PsiModifier.STATIC);

        defMethods[1] = new LightMethodBuilder(manager, GROOVY_LANGUAGE, "next")
          .setMethodReturnType(factory.createType(GrEnumTypeDefinitionImpl.this))
          .setContainingClass(GrEnumTypeDefinitionImpl.this)
          .addModifier(PsiModifier.PUBLIC);

        defMethods[2] = new LightMethodBuilder(manager, GROOVY_LANGUAGE, "previous")
          .setMethodReturnType(factory.createType(GrEnumTypeDefinitionImpl.this))
          .setContainingClass(GrEnumTypeDefinitionImpl.this)
          .addModifier(PsiModifier.PUBLIC);
        return Result.create(defMethods);
      }
    }, false);
    putUserDataIfAbsent(ENUM_METHODS, cached);
  }
  return cached.getValue();
}
项目:tools-idea    文件:GantMemberContributor.java   
private static boolean processAntTasks(PsiScopeProcessor processor, PsiElement place, ResolveState state) {
  if (!AntTasksProvider.antAvailable) {
    return true;
  }

  for (LightMethodBuilder task : AntTasksProvider.getAntTasks(place)) {
    if (!ResolveUtil.processElement(processor, task, state)) {
      return false;
    }
  }
  return true;
}
项目:consulo-java    文件:JavaRefactoringSupportProvider.java   
public static boolean isDisableRefactoringForLightElement(@Nullable PsiElement element)
{
    if(element instanceof LightMethodBuilder)
    {
        return true;
    }
    return false;
}
项目:intellij-ce-playground    文件:JavaCompletionProcessor.java   
@Override
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
  //noinspection SuspiciousMethodCalls
  if (myNonInitializedFields.contains(element)) {
    return true;
  }

  if (element instanceof PsiPackage && !isQualifiedContext()) {
    if (myScope instanceof PsiClass) {
      return true;
    }
    if (((PsiPackage)element).getQualifiedName().contains(".") &&
        PsiTreeUtil.getParentOfType(myElement, PsiImportStatementBase.class) != null) {
      return true;
    }
  }

  if (element instanceof PsiMethod) {
    PsiMethod method = (PsiMethod)element;
    if (PsiTypesUtil.isGetClass(method) && PsiUtil.isLanguageLevel5OrHigher(myElement)) {
      PsiType patchedType = PsiTypesUtil.createJavaLangClassType(myElement, myQualifierType, false);
      if (patchedType != null) {
        element = new LightMethodBuilder(element.getManager(), method.getName()).
          addModifier(PsiModifier.PUBLIC).
          setMethodReturnType(patchedType).
          setContainingClass(method.getContainingClass());
      }
    }
  }

  if (satisfies(element, state) && isAccessible(element)) {
    CompletionElement element1 = new CompletionElement(element, state.get(PsiSubstitutor.KEY));
    if (myResultNames.add(element1.getUniqueId())) {
      StaticProblem sp = myElement.getParent() instanceof PsiMethodReferenceExpression ? StaticProblem.none : getStaticProblem(element);
      if (sp != StaticProblem.instanceAfterStatic) {
        (sp == StaticProblem.staticAfterInstance ? myFilteredResults : myResults).add(element1);
      }
    }
  } else if (element instanceof PsiLocalVariable || element instanceof PsiParameter) {
    myResultNames.add(CompletionElement.getVariableUniqueId((PsiVariable)element));
  }

  return true;
}
项目:intellij-ce-playground    文件:DelegatedMethodsContributor.java   
private static PsiMethod generateDelegateMethod(PsiMethod method,
                                                PsiClass superClass,
                                                PsiSubstitutor substitutor,
                                                boolean keepParameterAnnotations) {
  final LightMethodBuilder builder = new LightMethodBuilder(superClass.getManager(), GroovyLanguage.INSTANCE, method.getName());
  builder.setContainingClass(superClass);
  builder.setMethodReturnType(substitutor.substitute(method.getReturnType()));
  builder.setNavigationElement(method);
  builder.addModifier(PsiModifier.PUBLIC);

  final PsiTypeParameter[] typeParameters = method.getTypeParameters();

  final PsiClass containingClass = method.getContainingClass();
  boolean isRaw = containingClass != null && PsiUtil.isRawSubstitutor(containingClass, substitutor);
  if (isRaw) {
    substitutor = JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createRawSubstitutor(substitutor, typeParameters);
  }

  if (!isRaw) {
    for (PsiTypeParameter typeParameter : typeParameters) {
      builder.addTypeParameter(typeParameter);
    }
  }

  final PsiParameter[] originalParameters = method.getParameterList().getParameters();

  for (int i = 0; i < originalParameters.length; i++) {
    PsiParameter originalParameter = originalParameters[i];
    PsiType type;
    if (isRaw) {
      type = TypeConversionUtil.erasure(substitutor.substitute(originalParameter.getType()));
    }
    else {
      type = substitutor.substitute(originalParameter.getType());
    }
    if (type == null) {
      type = TypesUtil.getJavaLangObject(superClass);
    }
    final LightParameter lightParameter = new LightParameter(StringUtil.notNullize(originalParameter.getName(), "p" + i), type, builder, JavaLanguage.INSTANCE);
    if (keepParameterAnnotations) {
      final PsiCompositeModifierList delegatingModifierList = new PsiCompositeModifierList(method.getManager(), Collections.singletonList(originalParameter.getModifierList()));
      lightParameter.setModifierList(delegatingModifierList);
    }
    builder.addParameter(lightParameter);
  }
  builder.setBaseIcon(JetgroovyIcons.Groovy.Method);

  return new DelegatedMethod(builder, method);
}
项目:intellij-ce-playground    文件:ClassItemGeneratorImpl.java   
@Override
public void writeMethod(StringBuilder builder, PsiMethod method) {
  if (method == null) return;

  GenerationUtil.writeDocComment(builder, method, true);

  String name = method.getName();

  boolean isAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT);

  PsiModifierList modifierList = method.getModifierList();

  final PsiClass containingClass = method.getContainingClass();
  if (method.isConstructor() && containingClass != null && containingClass.isEnum()) {
    ModifierListGenerator.writeModifiers(builder, modifierList, ModifierListGenerator.ENUM_CONSTRUCTOR_MODIFIERS);
  }
  else {
    ModifierListGenerator.writeModifiers(builder, modifierList);
  }


  if (method.hasTypeParameters()) {
    GenerationUtil.writeTypeParameters(builder, method, classNameProvider);
    builder.append(' ');
  }

  //append return type
  if (!method.isConstructor()) {
    PsiType retType = context.typeProvider.getReturnType(method);
    TypeWriter.writeType(builder, retType, method, classNameProvider);
    builder.append(' ');
  }
  builder.append(name);

  if (method instanceof GroovyPsiElement) {
    context.searchForLocalVarsToWrap((GroovyPsiElement)method);
  }
  GenerationUtil.writeParameterList(builder, method.getParameterList().getParameters(), classNameProvider, context);

  if (method instanceof GrAnnotationMethod) {
    GrAnnotationMemberValue defaultValue = ((GrAnnotationMethod)method).getDefaultValue();
    if (defaultValue != null) {
      builder.append("default ");
      defaultValue.accept(new AnnotationGenerator(builder, context));
    }
  }


  GenerationUtil.writeThrowsList(builder, method.getThrowsList(), getMethodExceptions(method), classNameProvider);

  if (!isAbstract) {
    /************* body **********/
    if (method instanceof GrMethod) {
      if (method instanceof GrReflectedMethod && ((GrReflectedMethod)method).getSkippedParameters().length > 0) {
        builder.append("{\n").append(generateDelegateCall((GrReflectedMethod)method)).append("\n}\n");
      }
      else {
        new CodeBlockGenerator(builder, context.extend()).generateMethodBody((GrMethod)method);
      }
    }
    else if (method instanceof GrAccessorMethod) {
      writeAccessorBody(builder, method);
    }
    else if (method instanceof LightMethodBuilder && containingClass instanceof GroovyScriptClass) {
      if ("main".equals(method.getName())) {
        writeMainScriptMethodBody(builder, method);
      }
      else if ("run".equals(method.getName())) {
        writeRunScriptMethodBody(builder, method);
      }
    }
    else {
      builder.append("{//todo\n}");
    }
  }
  else {
    builder.append(';');
  }
}
项目:sqlitemagic    文件:SqliteMagicLightMethodBuilder.java   
public LightMethodBuilder addException(PsiClassType type) {
  myThrowsList.addReference(type);
  return this;
}
项目:sqlitemagic    文件:SqliteMagicLightMethodBuilder.java   
public LightMethodBuilder addException(String fqName) {
  myThrowsList.addReference(fqName);
  return this;
}
项目:sqlitemagic    文件:SqliteMagicLightMethodBuilder.java   
@Override
public PsiElement setName(@NotNull String name) throws IncorrectOperationException {
  ReflectionUtil.setFinalFieldPerReflection(LightMethodBuilder.class, this, String.class, name);
  return this;
}
项目:holdr    文件:HoldrLightMethodBuilder.java   
@Override
public LightMethodBuilder addParameter(@NotNull String name, @NotNull PsiType type) {
    return super.addParameter(new HoldrLightParameter(name, type, this, JavaLanguage.INSTANCE));
}
项目:tools-idea    文件:DelegatedMethodsContributor.java   
private static PsiMethod generateDelegateMethod(PsiMethod method, PsiClass superClass, PsiSubstitutor substitutor) {
  final LightMethodBuilder builder = new LightMethodBuilder(superClass.getManager(), GroovyFileType.GROOVY_LANGUAGE, method.getName());
  builder.setContainingClass(superClass);
  builder.setMethodReturnType(substitutor.substitute(method.getReturnType()));
  builder.setNavigationElement(method);
  builder.addModifier(PsiModifier.PUBLIC);

  final PsiTypeParameter[] typeParameters = method.getTypeParameters();

  final PsiClass containingClass = method.getContainingClass();
  boolean isRaw = containingClass != null && PsiUtil.isRawSubstitutor(containingClass, substitutor);
  if (isRaw) {
    substitutor = JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createRawSubstitutor(substitutor, typeParameters);
  }

  if (!isRaw) {
    for (PsiTypeParameter typeParameter : typeParameters) {
      builder.addTypeParameter(typeParameter);
    }
  }

  final PsiParameter[] originalParameters = method.getParameterList().getParameters();

  for (int i = 0; i < originalParameters.length; i++) {
    PsiParameter originalParameter = originalParameters[i];
    PsiType type;
    if (isRaw) {
      type = TypeConversionUtil.erasure(substitutor.substitute(originalParameter.getType()));
    }
    else {
      type = substitutor.substitute(originalParameter.getType());
    }
    if (type == null) {
      type = PsiType.getJavaLangObject(superClass.getManager(), superClass.getResolveScope());
    }
    builder.addParameter(StringUtil.notNullize(originalParameter.getName(), "p" + i), type);
  }
  builder.setBaseIcon(JetgroovyIcons.Groovy.Method);

  return new DelegatedMethod(builder, method);
}
项目:lombok-intellij-plugin    文件:LombokLightMethodBuilder.java   
@Override
public LightMethodBuilder setMethodReturnType(PsiType returnType) {
  myReturnTypeCanonicalText = returnType.getCanonicalText();
  return super.setMethodReturnType(returnType);
}
项目:lombok-intellij-plugin    文件:LombokLightMethodBuilder.java   
public LightMethodBuilder addTypeParameter(PsiTypeParameter parameter) {
  ((LightTypeParameterListBuilder) getTypeParameterList()).addParameter(parameter);
  return this;
}
项目:lombok-intellij-plugin    文件:LombokLightMethodBuilder.java   
@Override
public PsiElement setName(@NotNull String name) throws IncorrectOperationException {
  ReflectionUtil.setFinalFieldPerReflection(LightMethodBuilder.class, this, String.class, name);
  return this;
}
项目:consulo-javaee    文件:JspClassImpl.java   
@NotNull
@Override
public PsiMethod[] getConstructors()
{
    return new PsiMethod[]{new LightMethodBuilder(this, JavaLanguage.INSTANCE).setConstructor(true)};
}
项目:consulo-java    文件:JavaCompletionProcessor.java   
@Override
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state)
{
    if(element instanceof PsiPackage && !isQualifiedContext())
    {
        if(myScope instanceof PsiClass)
        {
            return true;
        }
        if(((PsiPackage) element).getQualifiedName().contains(".") && PsiTreeUtil.getParentOfType(myElement, PsiImportStatementBase.class) != null)
        {
            return true;
        }
    }

    if(element instanceof PsiMethod)
    {
        PsiMethod method = (PsiMethod) element;
        if(PsiTypesUtil.isGetClass(method) && PsiUtil.isLanguageLevel5OrHigher(myElement))
        {
            PsiType patchedType = PsiTypesUtil.createJavaLangClassType(myElement, myQualifierType, false);
            if(patchedType != null)
            {
                element = new LightMethodBuilder(element.getManager(), method.getName()).
                        addModifier(PsiModifier.PUBLIC).
                        setMethodReturnType(patchedType).
                        setContainingClass(method.getContainingClass());
            }
        }
    }

    if(element instanceof PsiVariable)
    {
        String name = ((PsiVariable) element).getName();
        if(myShadowedNames.contains(name))
        {
            return true;
        }
        if(element instanceof PsiLocalVariable || element instanceof PsiParameter)
        {
            myShadowedNames.add(name);
        }
    }

    if(element instanceof PsiMethod)
    {
        myCurrentScopeMethodNames.add(((PsiMethod) element).getName());
    }

    if(!satisfies(element, state) || !isAccessible(element))
    {
        return true;
    }

    StaticProblem sp = myElement.getParent() instanceof PsiMethodReferenceExpression ? StaticProblem.none : getStaticProblem(element);
    if(sp == StaticProblem.instanceAfterStatic)
    {
        return true;
    }

    CompletionElement completion = new CompletionElement(element, state.get(PsiSubstitutor.KEY), getCallQualifierText(element));
    CompletionElement prev = myResults.get(completion);
    if(prev == null || completion.isMoreSpecificThan(prev))
    {
        myResults.put(completion, completion);
        if(sp == StaticProblem.staticAfterInstance)
        {
            mySecondRateResults.add(completion);
        }
    }

    return true;
}