com.intellij.psi.PsiClass Java Examples

The following examples show how to use com.intellij.psi.PsiClass. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultActivityLocatorCompat.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
public static String getQualifiedName(@NotNull Activity activity) {
  ApplicationManager.getApplication().assertReadAccessAllowed();

  PsiClass psiClass = activity.getActivityClass().getValue();
  if (psiClass == null) {
    Module module = activity.getModule();
    if (module != null && ApkFacet.getInstance(module) != null) {
      // In APK project we doesn't necessarily have the source/class file of the activity.
      return activity.getActivityClass().getStringValue();
    }
    return null;
  }

  return getQualifiedActivityName(psiClass);
}
 
Example #2
Source File: JavaBinaryContextProvider.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
private static PsiClass getMainClass(ConfigurationContext context) {
  Location location = context.getLocation();
  if (location == null) {
    return null;
  }
  location = JavaExecutionUtil.stepIntoSingleClass(location);
  if (location == null) {
    return null;
  }
  PsiElement element = location.getPsiElement();
  if (!element.isPhysical()) {
    return null;
  }
  return ApplicationConfigurationType.getMainClass(element);
}
 
Example #3
Source File: BlazeJavaTestEventsHandlerTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Test
public void testMethodLocationResolves() {
  PsiFile javaFile =
      workspace.createPsiFile(
          new WorkspacePath("java/com/google/lib/JavaClass.java"),
          "package com.google.lib;",
          "public class JavaClass {",
          "  public void testMethod() {}",
          "}");
  PsiClass javaClass = ((PsiClassOwner) javaFile).getClasses()[0];
  PsiMethod method = javaClass.findMethodsByName("testMethod", false)[0];
  assertThat(method).isNotNull();

  String url =
      handler.testLocationUrl(
          Label.create("//java/com/google/lib:JavaClass"),
          null,
          null,
          "testMethod",
          "com.google.lib.JavaClass");
  Location<?> location = getLocation(url);
  assertThat(location.getPsiElement()).isEqualTo(method);
}
 
Example #4
Source File: RequiredPropAnnotator.java    From litho with Apache License 2.0 6 votes vote down vote up
/**
 * @param generatedCls class containing inner Builder class with methods annotated as {@link
 *     RequiredProp} marking which Props are required for this class.
 * @param methodNames methods from the given class.
 * @return names of the generatedCls required props, that were not set after all methodNames
 *     calls.
 */
private static Collection<String> collectMissingRequiredProps(
    PsiClass generatedCls, Collection<String> methodNames) {
  Map<String, Set<String>> propToMethods = getRequiredPropsToMethodNames(generatedCls);
  if (propToMethods.isEmpty()) {
    return Collections.emptySet();
  }
  Set<String> missingRequiredProps = new HashSet<>(propToMethods.keySet());
  Map<String, String> methodToProp = inverse(propToMethods);
  for (String methodName : methodNames) {
    if (methodToProp.containsKey(methodName)) {
      String prop = methodToProp.get(methodName);
      missingRequiredProps.remove(prop);
    }
  }
  return missingRequiredProps;
}
 
Example #5
Source File: FieldNameConstantsPredefinedInnerClassFieldProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@NotNull
@Override
public List<? super PsiElement> process(@NotNull PsiClass psiClass) {
  if (psiClass.getParent() instanceof PsiClass) {
    PsiClass parentClass = (PsiClass) psiClass.getParent();
    PsiAnnotation psiAnnotation = PsiAnnotationSearchUtil.findAnnotation(parentClass, getSupportedAnnotationClasses());
    if (null != psiAnnotation && supportAnnotationVariant(psiAnnotation)) {
      ProblemEmptyBuilder problemBuilder = ProblemEmptyBuilder.getInstance();
      if (super.validate(psiAnnotation, parentClass, problemBuilder)) {
        final String typeName = FieldNameConstantsHandler.getTypeName(parentClass, psiAnnotation);
        if (typeName.equals(psiClass.getName())) {
          if (validate(psiAnnotation, parentClass, problemBuilder)) {
            List<? super PsiElement> result = new ArrayList<>();
            generatePsiElements(parentClass, psiClass, psiAnnotation, result);
            return result;
          }
        }
      }
    }
  }
  return Collections.emptyList();
}
 
Example #6
Source File: JsonConfigAnnotationIssueDetector.java    From aircon with MIT License 6 votes vote down vote up
@Override
public final void visit(final UAnnotation node) {
	final PsiAnnotation nodePsi = node.getJavaPsi();
	if (nodePsi == null || !ConfigElementsUtils.isJsonConfigAnnotation(nodePsi)) {
		return;
	}

	final PsiClass jsonType = ConfigElementsUtils.getJsonTypeAttribute(nodePsi);
	if (jsonType == null) {
		return;
	}

	final int genericTypesCount = ConfigElementsUtils.getGenericTypesCount(nodePsi);

	visitJsonConfigAnnotation(node, jsonType, genericTypesCount);
}
 
Example #7
Source File: ResolveRedSymbolsAction.java    From litho with Apache License 2.0 6 votes vote down vote up
private static Map<String, PsiClass> addToCache(
    Collection<String> allRedSymbols, Project project, GlobalSearchScope symbolsScope) {
  Map<String, PsiClass> redSymbolToClass = new HashMap<>();
  ComponentsCacheService componentsCache = ComponentsCacheService.getInstance(project);
  for (String redSymbol : allRedSymbols) {
    Arrays.stream(
            PsiSearchUtils.findClassesByShortName(project, symbolsScope, redSymbol + "Spec"))
        .filter(LithoPluginUtils::isLayoutSpec)
        .forEach(
            specCls -> {
              final PsiClass resolved = componentsCache.maybeUpdate(specCls, false);
              redSymbolToClass.put(redSymbol, resolved);
            });
  }
  return redSymbolToClass;
}
 
Example #8
Source File: SpecMethodFindUsagesHandlerTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void getPrimaryElements() {
  testHelper.getPsiClass(
      psiClasses -> {
        final PsiClass targetCls = psiClasses.get(0);
        final PsiMethod[] methods = targetCls.getMethods();
        final PsiMethod staticMethod = methods[0];
        final PsiClass withMethodsClass = targetCls.getInnerClasses()[0];

        final PsiElement[] primaryElements =
            new SpecMethodFindUsagesHandler(staticMethod, cls -> withMethodsClass)
                .getPrimaryElements();
        assertThat(primaryElements.length).isEqualTo(2);
        assertThat(primaryElements[0].getParent()).isSameAs(withMethodsClass);
        assertThat(primaryElements[1].getParent()).isSameAs(targetCls);
        return true;
      },
      "WithMethods.java");
}
 
Example #9
Source File: PsiAnnotationProxyUtilsTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void proxyEquals_not_equal() {
  testHelper.getPsiClass(
      psiClasses -> {
        assertNotNull(psiClasses);
        PsiClass psiClass = psiClasses.get(0);
        PsiParameter[] parameters =
            PsiTreeUtil.findChildOfType(psiClass, PsiParameterList.class).getParameters();

        Prop prop1 = PsiAnnotationProxyUtils.findAnnotationInHierarchy(parameters[0], Prop.class);
        Prop prop2 = PsiAnnotationProxyUtils.findAnnotationInHierarchy(parameters[1], Prop.class);
        // Calls proxy
        assertNotEquals(prop1, prop2);

        return true;
      },
      "WithAnnotationClass.java");
}
 
Example #10
Source File: InvalidEnumClassDetector.java    From aircon with MIT License 6 votes vote down vote up
@Override
protected void visitEnumConfigAnnotation(final UAnnotation node, final PsiClass enumClass) {
	final PsiField[] fields = enumClass.getFields();

	if (fields.length == 0) {
		report(node);
		return;
	}

	for (PsiField psiField : fields) {
		if (ElementUtils.isEnumConst(psiField) && !ConfigElementsUtils.hasRemoteValueAnnotation(psiField)) {
			report(node);
			return;
		}
	}
}
 
Example #11
Source File: OnCodeAnalysisFinishedListenerTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void daemonFinished_settingsTrue_resolved() throws IOException {
  final PsiFile specPsiFile = testHelper.configure("LayoutSpec.java");
  testHelper.configure("ResolveRedSymbolsActionTest.java");
  final Project project = testHelper.getFixture().getProject();
  AppSettingsState.getInstance(project).getState().resolveRedSymbols = true;
  ApplicationManager.getApplication()
      .invokeAndWait(
          () -> {
            PsiSearchUtils.addMock(
                "LayoutSpec", PsiTreeUtil.findChildOfType(specPsiFile, PsiClass.class));
            new OnCodeAnalysisFinishedListener(project).daemonFinished();
          });
  final PsiClass cached = ComponentsCacheService.getInstance(project).getComponent("Layout");
  assertThat(cached).isNotNull();
}
 
Example #12
Source File: UtilityClassModifierTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void testUtilityClassModifiersInnerClass() {
  PsiFile file = myFixture.configureByFile(getTestName(false) + ".java");
  PsiClass innerClass = PsiTreeUtil.getParentOfType(file.findElementAt(myFixture.getCaretOffset()), PsiClass.class);

  assertNotNull(innerClass);
  assertNotNull(innerClass.getModifierList());

  PsiElement parent = innerClass.getParent();

  assertNotNull(parent);
  assertTrue(parent instanceof PsiClass);

  PsiClass parentClass = (PsiClass) parent;

  assertNotNull(parentClass.getModifierList());
  assertTrue("@UtilityClass should make parent class final", ((PsiClass) innerClass.getParent()).getModifierList().hasModifierProperty(PsiModifier.FINAL));
  assertTrue("@UtilityClass should make inner class static", innerClass.getModifierList().hasModifierProperty(PsiModifier.STATIC));
}
 
Example #13
Source File: ProducerUtils.java    From intellij with Apache License 2.0 6 votes vote down vote up
/** Same as {@link JUnitUtil#getTestClass}, but handles classes outside the project. */
@Nullable
public static PsiClass getTestClass(final Location<?> location) {
  for (Iterator<Location<PsiClass>> iterator = location.getAncestors(PsiClass.class, false);
      iterator.hasNext(); ) {
    final Location<PsiClass> classLocation = iterator.next();
    if (isTestClass(classLocation.getPsiElement())) {
      return classLocation.getPsiElement();
    }
  }
  PsiElement element = location.getPsiElement();
  if (element instanceof PsiClassOwner) {
    PsiClass[] classes = ((PsiClassOwner) element).getClasses();
    if (classes.length == 1 && isTestClass(classes[0])) {
      return classes[0];
    }
  }
  return null;
}
 
Example #14
Source File: CodeGenerator.java    From ParcelablePlease with Apache License 2.0 6 votes vote down vote up
/**
 * Make the class implementing Parcelable
 */
private void makeClassImplementParcelable(PsiElementFactory elementFactory, JavaCodeStyleManager styleManager) {
  final PsiClassType[] implementsListTypes = psiClass.getImplementsListTypes();
  final String implementsType = "android.os.Parcelable";

  for (PsiClassType implementsListType : implementsListTypes) {
    PsiClass resolved = implementsListType.resolve();

    // Already implements Parcelable, no need to add it
    if (resolved != null && implementsType.equals(resolved.getQualifiedName())) {
      return;
    }
  }

  PsiJavaCodeReferenceElement implementsReference =
      elementFactory.createReferenceFromText(implementsType, psiClass);
  PsiReferenceList implementsList = psiClass.getImplementsList();

  if (implementsList != null) {
    styleManager.shortenClassReferences(implementsList.add(implementsReference));
  }
}
 
Example #15
Source File: JavaBinaryContextProvider.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public BinaryRunContext getRunContext(ConfigurationContext context) {
  PsiClass mainClass = getMainClass(context);
  if (mainClass == null) {
    return null;
  }
  TargetIdeInfo target = getTarget(context.getProject(), mainClass);
  if (target == null) {
    return null;
  }
  // Try setting source element to a main method so ApplicationConfigurationProducer
  // can't override our configuration by producing a more specific one.
  PsiMethod mainMethod = PsiMethodUtil.findMainMethod(mainClass);
  return BinaryRunContext.create(
      /* sourceElement= */ mainMethod != null ? mainMethod : mainClass, target.toTargetInfo());
}
 
Example #16
Source File: OttoLineMarkerProvider.java    From otto-intellij-plugin with Apache License 2.0 6 votes vote down vote up
@Override public void navigate(final MouseEvent mouseEvent, final PsiElement psiElement) {
  PsiMethod subscribeMethod = (PsiMethod) psiElement;
  final PsiTypeElement parameterTypeElement = getMethodParameter(subscribeMethod);
  final SubscriberMetadata subscriberMetadata = SubscriberMetadata.getSubscriberMetadata(subscribeMethod);
  if ((parameterTypeElement.getType() instanceof PsiClassType) && (subscriberMetadata != null)) {
    final PsiClass eventClass = ((PsiClassType) parameterTypeElement.getType()).resolve();
    PickAction.startPicker(subscriberMetadata.displayedTypesOnSubscriberMethods(),
        new RelativePoint(mouseEvent), new PickAction.Callback() {

      @Override public void onTypeChose(PickAction.Type type) {
        if (type.equals(PickAction.Type.PRODUCER)) {
          new ShowUsagesAction(PRODUCERS).startFindUsages(eventClass,
              new RelativePoint(mouseEvent), PsiUtilBase.findEditor(psiElement),
              MAX_USAGES);
        } else if (type.equals(PickAction.Type.EVENT_POST)) {
          PsiMethod ottoBusMethod = subscriberMetadata.getBusPostMethod(psiElement.getProject());
          new ShowUsagesAction(new BusPostDecider(eventClass)).startFindUsages(
              ottoBusMethod, new RelativePoint(mouseEvent),
              PsiUtilBase.findEditor(psiElement), MAX_USAGES);
        }
      }
    });
  }
}
 
Example #17
Source File: JavaTestContextProvider.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
private static TestContext fromClass(PsiClass testClass) {
  String testFilter = getTestFilterForClass(testClass);
  if (testFilter == null) {
    return null;
  }
  TestSize testSize = TestSizeFinder.getTestSize(testClass);
  ListenableFuture<TargetInfo> target =
      TestTargetHeuristic.targetFutureForPsiElement(testClass, testSize);
  if (target == null) {
    return null;
  }
  return TestContext.builder(testClass, ExecutorType.FAST_DEBUG_SUPPORTED_TYPES)
      .setTarget(target)
      .setTestFilter(testFilter)
      .setDescription(testClass.getName())
      .build();
}
 
Example #18
Source File: QuarkusKubernetesProvider.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
private void collectProperties(String prefix, PsiClass configType, IPropertiesCollector collector, IPsiUtils utils,
		DocumentFormat documentFormat) {
	String sourceType = configType.getQualifiedName();
	PsiMethod[] methods = configType.getMethods();
	for (PsiMethod method : methods) {
		String resultTypeName = PsiTypeUtils.getResolvedResultTypeName(method);
		PsiClass resultTypeClass = PsiTypeUtils.findType(method.getManager(), resultTypeName);
		String methodName = method.getName();
		String propertyName = prefix + "." + StringUtil.hyphenate(methodName);
		boolean isArray = method.getReturnType().getArrayDimensions() > 0;
		if (isArray) {
			propertyName += "[*]";
		}
		if (isSimpleFieldType(resultTypeClass, resultTypeName)) {
			String type = getPropertyType(resultTypeClass, resultTypeName);
			String description = utils.getJavadoc(method, documentFormat);
			String sourceMethod = getSourceMethod(method);
			String defaultValue = PsiTypeUtils.getDefaultValue(method);
			String extensionName = null;
			super.updateHint(collector, resultTypeClass);

			super.addItemMetadata(collector, propertyName, type, description, sourceType, null, sourceMethod,
					defaultValue, extensionName, PsiTypeUtils.isBinary(method));
		} else {
			collectProperties(propertyName, resultTypeClass, collector, utils, documentFormat);
		}
	}
}
 
Example #19
Source File: PsiSearchUtils.java    From litho with Apache License 2.0 5 votes vote down vote up
public static PsiClass[] findClasses(Project project, String qualifiedName) {
  final PsiClass found = findClass(project, qualifiedName);
  if (found == null) {
    return PsiClass.EMPTY_ARRAY;
  }
  return new PsiClass[] {found};
}
 
Example #20
Source File: AbstractClassProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
@Override
public List<? super PsiElement> process(@NotNull PsiClass psiClass) {
  List<? super PsiElement> result = Collections.emptyList();

  PsiAnnotation psiAnnotation = PsiAnnotationSearchUtil.findAnnotation(psiClass, getSupportedAnnotationClasses());
  if (null != psiAnnotation) {
    if (supportAnnotationVariant(psiAnnotation) && validate(psiAnnotation, psiClass, ProblemEmptyBuilder.getInstance())) {
      result = new ArrayList<>();
      generatePsiElements(psiClass, psiAnnotation, result);
    }
  }
  return result;
}
 
Example #21
Source File: PsiEventDeclarationsExtractor.java    From litho with Apache License 2.0 5 votes vote down vote up
static EventDeclarationModel getEventDeclarationModel(
    PsiClassObjectAccessExpression psiExpression) {
  PsiType valueType = psiExpression.getOperand().getType();
  PsiClass valueClass = PsiTypesUtil.getPsiClass(valueType);

  return new EventDeclarationModel(
      PsiTypeUtils.guessClassName(valueType.getCanonicalText()),
      getReturnType(valueClass),
      getFields(valueClass),
      psiExpression);
}
 
Example #22
Source File: AbstractDelombokAction.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
  final Project project = event.getProject();
  if (project == null) {
    return;
  }

  PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
  if (psiDocumentManager.hasUncommitedDocuments()) {
    psiDocumentManager.commitAllDocuments();
  }

  final DataContext dataContext = event.getDataContext();
  final Editor editor = PlatformDataKeys.EDITOR.getData(dataContext);

  if (null != editor) {
    final PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project);
    if (null != psiFile) {
      final PsiClass targetClass = getTargetClass(editor, psiFile);
      if (null != targetClass) {
        process(project, psiFile, targetClass);
      }
    }
  } else {
    final VirtualFile[] files = PlatformDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
    if (null != files) {
      for (VirtualFile file : files) {
        if (file.isDirectory()) {
          processDirectory(project, file);
        } else {
          processFile(project, file);
        }
      }
    }
  }
}
 
Example #23
Source File: GetterFieldProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void generatePsiElements(@NotNull PsiField psiField, @NotNull PsiAnnotation psiAnnotation, @NotNull List<? super PsiElement> target) {
  final String methodVisibility = LombokProcessorUtil.getMethodModifier(psiAnnotation);
  final PsiClass psiClass = psiField.getContainingClass();
  if (null != methodVisibility && null != psiClass) {
    target.add(createGetterMethod(psiField, psiClass, methodVisibility));
  }
}
 
Example #24
Source File: InternalFolivoraApiDetector.java    From Folivora with Apache License 2.0 5 votes vote down vote up
@Override
public void visitMethod(@NotNull JavaContext context,
                        @NotNull UCallExpression call,
                        @NotNull PsiMethod method) {
  JavaEvaluator evaluator = context.getEvaluator();

  //check Folivora.applyDrawableToView() call
  String methodName = method.getName();
  if (!methodName.equals(APPLY_METHOD) || !evaluator.isMemberInClass(method, FOLIVORA_CLASS)) return;

  PsiClass viewClass = evaluator.findClass(VIEW_CLASS);
  PsiClass currentClass = UastUtils.getContainingClass(call);
  if(currentClass == null || viewClass == null) return;
  if (!currentClass.isInheritor(viewClass, true/*deep check*/)) {
    report(context, call);
    return;
  }

  UMethod uMethod = UastUtils.getParentOfType(call, UMethod.class, false);
  if(uMethod == null) return;

  //check it is a view's constructor
  if (!uMethod.isConstructor()) {
    report(context, call);
    return;
  }

  MethodSignature signature = uMethod.getSignature(PsiSubstitutor.EMPTY);
  PsiType[] types = signature.getParameterTypes();
  if (types.length != 2) {
    report(context, call);
    return;
  }

  if (!types[0].equalsToText(CONTEXT_CLASS)
    || !types[1].equalsToText(ATTRS_CLASS)) {
    report(context, call);
  }
}
 
Example #25
Source File: HaxeSubtypesHierarchyTreeStructure.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@NotNull
private final Object[] typeListToObjArray(@NotNull final HaxeTypeHierarchyNodeDescriptor descriptor, @NotNull final List<PsiClass> classes) {
  final int size = classes.size();
  if (size > 0) {
    final List<HaxeTypeHierarchyNodeDescriptor> descriptors = new ArrayList<HaxeTypeHierarchyNodeDescriptor>(size);
    for (PsiClass aClass : classes) {
      descriptors.add(new HaxeTypeHierarchyNodeDescriptor(myProject, descriptor, aClass, false));
    }
    return descriptors.toArray(new HaxeTypeHierarchyNodeDescriptor[descriptors.size()]);
  }
  return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
 
Example #26
Source File: LombokReferenceSearcher.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void processPsiField(final PsiField refPsiField, final SearchRequestCollector collector) {
  final PsiClass containingClass = refPsiField.getContainingClass();
  if (null != containingClass) {
    processClassMethods(refPsiField, collector, containingClass);

    final PsiClass[] innerClasses = containingClass.getInnerClasses();
    Arrays.stream(innerClasses)
      .forEach(psiClass -> processClassMethods(refPsiField, collector, psiClass));

    Arrays.stream(innerClasses)
      .forEach(psiClass -> processClassFields(refPsiField, collector, psiClass));
  }
}
 
Example #27
Source File: ConvertAction.java    From data-mediator with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    Project project = getEventProject(e);
    if(project == null){
        return;
    }
    PsiClass psiClass = getPsiClassFromContext(e);
    if(psiClass == null){
        Util.logError("psiClass == null");
        return;
    }
    PropertyProcessor processor = new PropertyProcessor(psiClass);
    processor.parse();
    processor.generate();
}
 
Example #28
Source File: RequiredPropAnnotator.java    From litho with Apache License 2.0 5 votes vote down vote up
private static void handleMethodCall(
    PsiMethodCallExpression currentMethodCall,
    Set<String> methodNamesCalled,
    BiConsumer<Collection<String>, PsiReferenceExpression> errorHandler,
    Function<PsiMethodCallExpression, PsiClass> generatedClassResolver) {
  PsiReferenceExpression methodExpression = currentMethodCall.getMethodExpression();
  methodNamesCalled.add(methodExpression.getReferenceName());

  // Assumption to find next method in a call chain
  PsiMethodCallExpression nextMethodCall =
      PsiTreeUtil.getChildOfType(methodExpression, PsiMethodCallExpression.class);
  if (nextMethodCall != null) {
    handleMethodCall(nextMethodCall, methodNamesCalled, errorHandler, generatedClassResolver);
  } else if ("create".equals(methodExpression.getReferenceName())) {
    // Finish call chain
    // TODO T47712852: allow setting required prop in another statement
    Optional.ofNullable(generatedClassResolver.apply(currentMethodCall))
        .map(generatedCls -> collectMissingRequiredProps(generatedCls, methodNamesCalled))
        .filter(result -> !result.isEmpty())
        .ifPresent(
            missingRequiredProps -> errorHandler.accept(missingRequiredProps, methodExpression));
  }

  PsiExpressionList argumentList = currentMethodCall.getArgumentList();
  for (PsiExpression argument : argumentList.getExpressions()) {
    handleIfMethodCall(argument, errorHandler, generatedClassResolver);
  }
}
 
Example #29
Source File: JavaMethodUtils.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Return all method names for the specific class and it's super classes, except
 * Object and Class
 */
public Collection<PsiMethod> getMethods(PsiClass psiClass) {
    return Stream.of(psiClass.getAllMethods())
        .filter(p -> !p.isConstructor())
        .filter(p -> !Object.class.getName().equals(p.getContainingClass().getQualifiedName()))
        .filter(p -> !Class.class.getName().equals(p.getContainingClass().getQualifiedName()))
        .collect(Collectors.toCollection(ArrayList::new));
}
 
Example #30
Source File: AllArgsConstructorProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public LombokPsiElementUsage checkFieldUsage(@NotNull PsiField psiField, @NotNull PsiAnnotation psiAnnotation) {
  final PsiClass containingClass = psiField.getContainingClass();
  if (null != containingClass) {
    if (PsiClassUtil.getNames(getAllNotInitializedAndNotStaticFields(containingClass)).contains(psiField.getName())) {
      return LombokPsiElementUsage.WRITE;
    }
  }
  return LombokPsiElementUsage.NONE;
}