当前位置: 首页>>代码示例>>Java>>正文


Java PropertyUtil类代码示例

本文整理汇总了Java中com.intellij.psi.util.PropertyUtil的典型用法代码示例。如果您正苦于以下问题:Java PropertyUtil类的具体用法?Java PropertyUtil怎么用?Java PropertyUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PropertyUtil类属于com.intellij.psi.util包,在下文中一共展示了PropertyUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getWritablePropertyType

import com.intellij.psi.util.PropertyUtil; //导入依赖的package包/类
@Nullable
public static PsiType getWritablePropertyType(@Nullable PsiClass containingClass,
    @Nullable PsiElement declaration) {
  if (declaration instanceof PsiField) {
    return getWrappedPropertyType((PsiField) declaration, JavaFxCommonNames.ourWritableMap);
  }
  if (declaration instanceof PsiMethod) {
    final PsiMethod method = (PsiMethod) declaration;
    if (method.getParameterList().getParametersCount() != 0) {
      return getSetterArgumentType(method);
    }
    final String propertyName = PropertyUtil.getPropertyName(method);
    final PsiClass psiClass =
        containingClass != null ? containingClass : method.getContainingClass();
    if (propertyName != null && containingClass != null) {
      final PsiMethod setter = findInstancePropertySetter(psiClass, propertyName);
      if (setter != null) {
        final PsiType setterArgumentType = getSetterArgumentType(setter);
        if (setterArgumentType != null)
          return setterArgumentType;
      }
    }
    return getGetterReturnType(method);
  }
  return null;
}
 
开发者ID:1tontech,项目名称:intellij-spring-assistant,代码行数:27,代码来源:PsiUtil.java

示例2: getExpressionAccess

import com.intellij.psi.util.PropertyUtil; //导入依赖的package包/类
@Override
public Access getExpressionAccess(final PsiElement expression) {
  if (!(expression instanceof PsiExpression)) return Access.Read;
  PsiExpression expr = (PsiExpression) expression;
  boolean readAccess = PsiUtil.isAccessedForReading(expr);
  boolean writeAccess = PsiUtil.isAccessedForWriting(expr);
  if (!writeAccess && expr instanceof PsiReferenceExpression) {
    //when searching usages of fields, should show all found setters as a "only write usage"
    PsiElement actualReferee = ((PsiReferenceExpression) expr).resolve();
    if (actualReferee instanceof PsiMethod && PropertyUtil.isSimplePropertySetter((PsiMethod)actualReferee)) {
      writeAccess = true;
      readAccess = false;
    }
  }
  if (writeAccess && readAccess) return Access.ReadWrite;
  return writeAccess ? Access.Write : Access.Read;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:JavaReadWriteAccessDetector.java

示例3: fromString

import com.intellij.psi.util.PropertyUtil; //导入依赖的package包/类
public PsiMember fromString(final String s, final ConvertContext context) {
  if (s == null) return null;
  final PsiClass psiClass = getTargetClass(context);
  if (psiClass == null) return null;
  for (PropertyMemberType type : getMemberTypes(context)) {
    switch (type) {
      case FIELD:
        final PsiField field = psiClass.findFieldByName(s, isLookDeep());
        if (field != null) return field;
        break;
      case GETTER:
        final PsiMethod getter = PropertyUtil.findPropertyGetter(psiClass, getPropertyName(s, context), false, isLookDeep());
        if (getter != null) return getter;
        break;
      case SETTER:
        final PsiMethod setter = PropertyUtil.findPropertySetter(psiClass, getPropertyName(s, context), false, isLookDeep());
        if (setter != null) return setter;
        break;
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:AbstractMemberResolveConverter.java

示例4: getAccessedVariableOrGetter

import com.intellij.psi.util.PropertyUtil; //导入依赖的package包/类
@Nullable
private static PsiModifierListOwner getAccessedVariableOrGetter(final PsiElement target) {
  if (target instanceof PsiVariable) {
    return (PsiVariable)target;
  }
  if (target instanceof PsiMethod) {
    PsiMethod method = (PsiMethod)target;
    if (PropertyUtil.isSimplePropertyGetter(method) && !(method.getReturnType() instanceof PsiPrimitiveType)) {
      String qName = PsiUtil.getMemberQualifiedName(method);
      if (qName == null || !FALSE_GETTERS.value(qName)) {
        return method;
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:DfaExpressionFactory.java

示例5: inferPurity

import com.intellij.psi.util.PropertyUtil; //导入依赖的package包/类
public static boolean inferPurity(@NotNull final PsiMethod method) {
  if (!InferenceFromSourceUtil.shouldInferFromSource(method) ||
      method.getReturnType() == PsiType.VOID ||
      method.getBody() == null ||
      method.isConstructor() || 
      PropertyUtil.isSimpleGetter(method)) {
    return false;
  }

  return CachedValuesManager.getCachedValue(method, new CachedValueProvider<Boolean>() {
    @Nullable
    @Override
    public Result<Boolean> compute() {
      boolean pure = RecursionManager.doPreventingRecursion(method, true, new Computable<Boolean>() {
        @Override
        public Boolean compute() {
          return doInferPurity(method);
        }
      }) == Boolean.TRUE;
      return Result.create(pure, method);
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:PurityInference.java

示例6: isAvailable

import com.intellij.psi.util.PropertyUtil; //导入依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
  if (!myField.isValid()) return false;

  final PsiClass aClass = myField.getContainingClass();
  if (aClass == null) {
    return false;
  }

  if (myCreateGetter){
    if (isStaticFinal(myField) || PropertyUtil.findPropertyGetter(aClass, myPropertyName, isStatic(myField), false) != null){
      return false;
    }
  }

  if (myCreateSetter){
    if(isFinal(myField) || PropertyUtil.findPropertySetter(aClass, myPropertyName, isStatic(myField), false) != null){
      return false;
    }
  }

  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:CreateGetterOrSetterFix.java

示例7: visitMethodReturnType

import com.intellij.psi.util.PropertyUtil; //导入依赖的package包/类
private void visitMethodReturnType(final PsiMethod scopeMethod, PsiType type, boolean tailTypeSemicolon) {
  if (type != null) {
    NullableComputable<String> expectedName;
    if (PropertyUtil.isSimplePropertyAccessor(scopeMethod)) {
      expectedName = new NullableComputable<String>() {
        @Override
        public String compute() {
          return PropertyUtil.getPropertyName(scopeMethod);
        }
      };
    }
    else {
      expectedName = ExpectedTypeInfoImpl.NULL;
    }

    myResult.add(createInfoImpl(type, ExpectedTypeInfo.TYPE_OR_SUBTYPE, type,
                                               tailTypeSemicolon ? TailType.SEMICOLON : TailType.NONE, null, expectedName));
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:ExpectedTypesProvider.java

示例8: createGetter

import com.intellij.psi.util.PropertyUtil; //导入依赖的package包/类
protected PsiElement createGetter(final boolean createField) throws IncorrectOperationException {
  final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(myPsiClass.getProject()).getElementFactory();
  final String methodName = PropertyUtil.suggestGetterName(myPropertyName, myType);
  final String typeName = myType.getCanonicalText();
  @NonNls final String text;
  boolean isInterface = myPsiClass.isInterface();
  if (createField) {
    final String fieldName = getFieldName();
    text = "public " + typeName + " " + methodName + "() { return " + fieldName + "; }";
  } else {
    if (isInterface) {
      text = typeName + " " + methodName + "();";
    }
    else {
      text = "public " + typeName + " " + methodName + "() { return null; }";
    }
  }
  final PsiMethod method = elementFactory.createMethodFromText(text, null);
  final PsiMethod psiElement = (PsiMethod)myPsiClass.add(method);
  if (!createField && !isInterface) {
    CreateFromUsageUtils.setupMethodBody(psiElement);
  }
  return psiElement;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:CreateBeanPropertyFix.java

示例9: applyNewSetterPrefix

import com.intellij.psi.util.PropertyUtil; //导入依赖的package包/类
private void applyNewSetterPrefix() {
  final String setterPrefix = Messages.showInputDialog(myTable, "New setter prefix:", "Rename Setters Prefix", null,
                                                       mySetterPrefix, new MySetterPrefixInputValidator());
  if (setterPrefix != null) {
    mySetterPrefix = setterPrefix;
    PropertiesComponent.getInstance(myProject).setValue(SETTER_PREFIX_KEY, setterPrefix);
    final JavaCodeStyleManager javaCodeStyleManager = JavaCodeStyleManager.getInstance(myProject);
    for (String paramName : myParametersMap.keySet()) {
      final ParameterData data = myParametersMap.get(paramName);
      paramName = data.getParamName();
      final String propertyName = javaCodeStyleManager.variableNameToPropertyName(paramName, VariableKind.PARAMETER);
      data.setSetterName(PropertyUtil.suggestSetterName(propertyName, setterPrefix));
    }
    myTable.revalidate();
    myTable.repaint();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:ReplaceConstructorWithBuilderDialog.java

示例10: addSettersAndListeners

import com.intellij.psi.util.PropertyUtil; //导入依赖的package包/类
private static void addSettersAndListeners(CompletionResultSet result, PsiClass containingClass) {
  // see PyJavaType.init() in Jython source code for matching logic
  for (PsiMethod method : containingClass.getAllMethods()) {
    final Project project = containingClass.getProject();
    if (PropertyUtil.isSimplePropertySetter(method)) {
      final String propName = PropertyUtil.getPropertyName(method);
      result.addElement(PyUtil.createNamedParameterLookup(propName, project));
    }
    else if (method.getName().startsWith("add") && method.getName().endsWith("Listener") && PsiType.VOID.equals(method.getReturnType())) {
      final PsiParameter[] parameters = method.getParameterList().getParameters();
      if (parameters.length == 1) {
        final PsiType type = parameters[0].getType();
        if (type instanceof PsiClassType) {
          final PsiClass parameterClass = ((PsiClassType)type).resolve();
          if (parameterClass != null) {
            result.addElement(PyUtil.createNamedParameterLookup(StringUtil.decapitalize(parameterClass.getName()), project));
            for (PsiMethod parameterMethod : parameterClass.getMethods()) {
              result.addElement(PyUtil.createNamedParameterLookup(parameterMethod.getName(), project));
            }
          }
        }
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:PyConstructorArgumentCompletionContributor.java

示例11: findProperties

import com.intellij.psi.util.PropertyUtil; //导入依赖的package包/类
@SuppressWarnings("UnusedDeclaration")
public static List<String> findProperties(@Nullable PsiClass input) {
  if (input == null) {
    return Collections.emptyList();
  }
  final List<String> result = new ArrayList<String>();
  input.accept(new JavaRecursiveElementVisitor() {
    @Override
    public void visitMethod(PsiMethod method) {
      super.visitMethod(method);
      if (method.getName().startsWith("get")) {
        result.add(PropertyUtil.getPropertyName(method));
      }
    }
  });
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:Analyser.java

示例12: checkComponentProperties

import com.intellij.psi.util.PropertyUtil; //导入依赖的package包/类
protected void checkComponentProperties(Module module, final IComponent component, final FormErrorCollector collector) {
  final GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
  final PsiManager psiManager = PsiManager.getInstance(module.getProject());
  final PsiClass aClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(component.getComponentClassName(), scope);
  if (aClass == null) {
    return;
  }

  for(final IProperty prop: component.getModifiedProperties()) {
    final PsiMethod getter = PropertyUtil.findPropertyGetter(aClass, prop.getName(), false, true);
    if (getter == null) continue;
    final LanguageLevel languageLevel = LanguageLevelUtil.getEffectiveLanguageLevel(module);
    if (Java15APIUsageInspection.isForbiddenApiUsage(getter, languageLevel)) {
      registerError(component, collector, prop, "@since " + Java15APIUsageInspection.getShortName(languageLevel));
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:Java15FormInspection.java

示例13: isPropertyDeprecated

import com.intellij.psi.util.PropertyUtil; //导入依赖的package包/类
public boolean isPropertyDeprecated(final Module module, final Class aClass, final String propertyName) {
  // TODO[yole]: correct module-dependent caching
  Set<String> deprecated = myClass2DeprecatedProperties.get(aClass.getName());
  if (deprecated == null) {
    deprecated = new HashSet<String>();
    PsiClass componentClass =
      JavaPsiFacade.getInstance(module.getProject()).findClass(aClass.getName(), module.getModuleWithDependenciesAndLibrariesScope(true));
    if (componentClass != null) {
      PsiMethod[] methods = componentClass.getAllMethods();
      for(PsiMethod method: methods) {
        if (method.isDeprecated() && PropertyUtil.isSimplePropertySetter(method)) {
          deprecated.add(PropertyUtil.getPropertyNameBySetter(method));
        }
      }
    }
    myClass2DeprecatedProperties.put(aClass.getName(), deprecated);
  }

  return deprecated.contains(propertyName);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:Properties.java

示例14: isSetterNonNls

import com.intellij.psi.util.PropertyUtil; //导入依赖的package包/类
private static boolean isSetterNonNls(final Project project, final GlobalSearchScope searchScope,
                                      final String componentClassName, final String propertyName) {
  PsiClass componentClass = JavaPsiFacade.getInstance(project).findClass(componentClassName, searchScope);
  if (componentClass == null) {
    return false;
  }
  PsiMethod setter = PropertyUtil.findPropertySetter(componentClass, propertyName, false, true);
  if (setter != null) {
    PsiParameter[] parameters = setter.getParameterList().getParameters();
    if (parameters.length == 1 &&
        "java.lang.String".equals(parameters[0].getType().getCanonicalText()) &&
        AnnotationUtil.isAnnotated(parameters [0], AnnotationUtil.NON_NLS, false, true)) {
      return true;
    }
  }

  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:I18nFormInspection.java

示例15: visitMethod

import com.intellij.psi.util.PropertyUtil; //导入依赖的package包/类
@Override
public void visitMethod(@NotNull PsiMethod method) {
  //no drilldown
  if (method.getNameIdentifier() == null) {
    return;
  }
  if (!method.hasModifierProperty(PsiModifier.PUBLIC)) {
    return;
  }
  final PsiCodeBlock body = method.getBody();
  if (body == null) {
    return;
  }
  if (method.isConstructor()) {
    return;
  }
  if (PropertyUtil.isSimpleGetter(method) || PropertyUtil.isSimpleSetter(method)) {
    return;
  }
  if (containsLoggingCall(body)) {
    return;
  }
  registerMethodError(method);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:PublicMethodWithoutLoggingInspectionBase.java


注:本文中的com.intellij.psi.util.PropertyUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。