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


Java VariableKind.STATIC_FINAL_FIELD属性代码示例

本文整理汇总了Java中com.intellij.psi.codeStyle.VariableKind.STATIC_FINAL_FIELD属性的典型用法代码示例。如果您正苦于以下问题:Java VariableKind.STATIC_FINAL_FIELD属性的具体用法?Java VariableKind.STATIC_FINAL_FIELD怎么用?Java VariableKind.STATIC_FINAL_FIELD使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.intellij.psi.codeStyle.VariableKind的用法示例。


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

示例1: getKind

@NotNull
private static VariableKind getKind(@NotNull JavaCodeStyleManager styleManager, @NotNull PsiReferenceExpression refExpr) {
  final String reference = refExpr.getText();

  if (reference.toUpperCase().equals(reference)){
    return VariableKind.STATIC_FINAL_FIELD;
  }

  for (VariableKind kind : VariableKind.values()) {
    final String prefix = styleManager.getPrefixByVariableKind(kind);
    final String suffix = styleManager.getSuffixByVariableKind(kind);

    if (prefix.isEmpty() && suffix.isEmpty()) {
      continue;
    }

    if (reference.startsWith(prefix) && reference.endsWith(suffix)) {
      return kind;
    }
  }

  return VariableKind.LOCAL_VARIABLE;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:23,代码来源:DefaultQuickFixProvider.java

示例2: getSuggestionsByName

@NotNull
private String[] getSuggestionsByName(@NotNull String name, @NotNull VariableKind variableKind, boolean isArray, boolean correctKeywords)
{
	boolean upperCaseStyle = variableKind == VariableKind.STATIC_FINAL_FIELD;
	boolean preferLongerNames = getSettings().PREFER_LONGER_NAMES;
	String prefix = getPrefixByVariableKind(variableKind);
	String suffix = getSuffixByVariableKind(variableKind);

	List<String> answer = new ArrayList<String>();
	for(String suggestion : NameUtil.getSuggestionsByName(name, prefix, suffix, upperCaseStyle, preferLongerNames, isArray))
	{
		answer.add(correctKeywords ? changeIfNotIdentifier(suggestion) : suggestion);
	}

	return ArrayUtil.toStringArray(answer);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:16,代码来源:JavaCodeStyleManagerImpl.java

示例3: completeFieldName

private static void completeFieldName(Set<LookupElement> set, PsiField var, final PrefixMatcher matcher, boolean includeOverlapped) {
  FeatureUsageTracker.getInstance().triggerFeatureUsed("editing.completion.variable.name");

  Project project = var.getProject();
  JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
  final VariableKind variableKind = JavaCodeStyleManager.getInstance(project).getVariableKind(var);

  final String prefix = matcher.getPrefix();
  if (PsiType.VOID.equals(var.getType()) || psiField().inClass(psiClass().isInterface().andNot(psiClass().isAnnotationType())).accepts(var)) {
    completeVariableNameForRefactoring(project, set, matcher, var.getType(), variableKind, includeOverlapped, true);
    return;
  }

  SuggestedNameInfo suggestedNameInfo = codeStyleManager.suggestVariableName(variableKind, null, null, var.getType());
  final String[] suggestedNames = suggestedNameInfo.names;
  addLookupItems(set, suggestedNameInfo, matcher, project, suggestedNames);

  if (!hasStartMatches(set, matcher) && includeOverlapped) {
    // use suggested names as suffixes
    final String requiredSuffix = codeStyleManager.getSuffixByVariableKind(variableKind);
    if(variableKind != VariableKind.STATIC_FINAL_FIELD){
      for (int i = 0; i < suggestedNames.length; i++)
        suggestedNames[i] = codeStyleManager.variableNameToPropertyName(suggestedNames[i], variableKind);
    }


    addLookupItems(set, null, matcher, project, getOverlappedNameVersions(prefix, suggestedNames, requiredSuffix));
  }

  addLookupItems(set, suggestedNameInfo, matcher, project, getUnresolvedReferences(var.getParent(), false));

  PsiExpression initializer = var.getInitializer();
  PsiClass containingClass = var.getContainingClass();
  if (initializer != null && containingClass != null) {
    SuggestedNameInfo initializerSuggestions = InplaceIntroduceFieldPopup.
      suggestFieldName(var.getType(), null, initializer, var.hasModifierProperty(PsiModifier.STATIC), containingClass);
    addLookupItems(set, initializerSuggestions, matcher, project, initializerSuggestions.names);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:JavaMemberNameCompletionContributor.java

示例4: completeVariableNameForRefactoring

public static String[] completeVariableNameForRefactoring(JavaCodeStyleManager codeStyleManager,
                                                          final PrefixMatcher matcher,
                                                          @Nullable final PsiType varType,
                                                          final VariableKind varKind,
                                                          SuggestedNameInfo suggestedNameInfo,
                                                          final boolean includeOverlapped, final boolean methodPrefix) {
  Set<String> result = new LinkedHashSet<String>();
  final String[] suggestedNames = suggestedNameInfo.names;
  for (final String suggestedName : suggestedNames) {
    if (matcher.prefixMatches(suggestedName)) {
      result.add(suggestedName);
    }
  }

  if (!hasStartMatches(matcher, result) && PsiType.VOID != varType && includeOverlapped) {
    // use suggested names as suffixes
    final String requiredSuffix = codeStyleManager.getSuffixByVariableKind(varKind);
    final String prefix = matcher.getPrefix();
    if (varKind != VariableKind.STATIC_FINAL_FIELD || methodPrefix) {
      for (int i = 0; i < suggestedNames.length; i++) {
        suggestedNames[i] = codeStyleManager.variableNameToPropertyName(suggestedNames[i], varKind);
      }
    }

    ContainerUtil.addAll(result, getOverlappedNameVersions(prefix, suggestedNames, requiredSuffix));


  }
  return ArrayUtil.toStringArray(result);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:JavaMemberNameCompletionContributor.java

示例5: getKind

@Nullable
private static VariableKind getKind(@NotNull JavaCodeStyleManager styleManager, @NotNull PsiReferenceExpression refExpr) {
  final String reference = refExpr.getText();

  if (reference.toUpperCase().equals(reference)){
    return VariableKind.STATIC_FINAL_FIELD;
  }

  for (VariableKind kind : VariableKind.values()) {
    final String prefix = styleManager.getPrefixByVariableKind(kind);
    final String suffix = styleManager.getSuffixByVariableKind(kind);

    if (prefix.isEmpty() && suffix.isEmpty()) {
      continue;
    }

    if (reference.startsWith(prefix) && reference.endsWith(suffix)) {
      return kind;
    }
  }

  if (StringUtil.isCapitalized(reference)) {
    return null;
  }

  return VariableKind.LOCAL_VARIABLE;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:DefaultQuickFixProvider.java

示例6: suggestProperlyCasedName

@Nullable
private static String[] suggestProperlyCasedName(PsiElement psiElement) {
  if (!(psiElement instanceof PsiNamedElement)) return null;
  if (psiElement instanceof PsiFile) return null;
  String name = ((PsiNamedElement)psiElement).getName();
  if (name == null) return null;
  String prefix = "";
  if (psiElement instanceof PsiVariable) {
    final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(psiElement.getProject());
    final VariableKind kind = codeStyleManager.getVariableKind((PsiVariable)psiElement);
    prefix = codeStyleManager.getPrefixByVariableKind(kind);
    if (kind == VariableKind.STATIC_FINAL_FIELD) {
      final String[] words = NameUtil.splitNameIntoWords(name);
      StringBuilder buffer = new StringBuilder();
      for (int i = 0; i < words.length; i++) {
        String word = words[i];
        if (i > 0) buffer.append('_');
        buffer.append(StringUtil.toUpperCase(word));
      }
      return new String[] {buffer.toString()};
    }
  }
  final List<String> result = new ArrayList<String>();
  result.add(suggestProperlyCasedName(prefix, NameUtil.splitNameIntoWords(name)));
  if (name.startsWith(prefix)) {
    name = name.substring(prefix.length());
    result.add(suggestProperlyCasedName(prefix, NameUtil.splitNameIntoWords(name)));
  }
  result.add(suggestProperlyCasedName(prefix, NameUtil.splitNameIntoWords(name.toLowerCase())));
  return ArrayUtil.toStringArray(result);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:JavaNameSuggestionProvider.java

示例7: suggestProperlyCasedName

@Nullable
private static String[] suggestProperlyCasedName(PsiElement psiElement) {
  if (!(psiElement instanceof PsiNamedElement)) return null;
  String name = ((PsiNamedElement)psiElement).getName();
  if (name == null) return null;
  if (psiElement instanceof PsiVariable) {
    final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(psiElement.getProject());
    final VariableKind kind = codeStyleManager.getVariableKind((PsiVariable)psiElement);
    final String prefix = codeStyleManager.getPrefixByVariableKind(kind);
    if (kind == VariableKind.STATIC_FINAL_FIELD) {
      final String[] words = NameUtil.splitNameIntoWords(name);
      StringBuilder buffer = new StringBuilder();
      for (int i = 0; i < words.length; i++) {
        String word = words[i];
        if (i > 0) buffer.append('_');
        buffer.append(StringUtil.toUpperCase(word));
      }
      return new String[] {buffer.toString()};
    }
    else {
      final List<String> result = new ArrayList<String>();
      result.add(suggestProperlyCasedName(prefix, NameUtil.splitNameIntoWords(name)));
      if (name.startsWith(prefix)) {
        name = name.substring(prefix.length());
        result.add(suggestProperlyCasedName(prefix, NameUtil.splitNameIntoWords(name)));
      }
      result.add(suggestProperlyCasedName(prefix, NameUtil.splitNameIntoWords(name.toLowerCase())));
      return ArrayUtil.toStringArray(result);
    }

  }
  return new String[]{name};
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:33,代码来源:JavaNameSuggestionProvider.java

示例8: completeVariableNameForRefactoring

public static String[] completeVariableNameForRefactoring(JavaCodeStyleManager codeStyleManager,
		final PrefixMatcher matcher,
		@Nullable final PsiType varType,
		final VariableKind varKind,
		SuggestedNameInfo suggestedNameInfo,
		final boolean includeOverlapped,
		final boolean methodPrefix)
{
	Set<String> result = new LinkedHashSet<>();
	final String[] suggestedNames = suggestedNameInfo.names;
	for(final String suggestedName : suggestedNames)
	{
		if(matcher.prefixMatches(suggestedName))
		{
			result.add(suggestedName);
		}
	}

	if(!hasStartMatches(matcher, result) && !PsiType.VOID.equals(varType) && includeOverlapped)
	{
		// use suggested names as suffixes
		final String requiredSuffix = codeStyleManager.getSuffixByVariableKind(varKind);
		final String prefix = matcher.getPrefix();
		if(varKind != VariableKind.STATIC_FINAL_FIELD || methodPrefix)
		{
			for(int i = 0; i < suggestedNames.length; i++)
			{
				suggestedNames[i] = codeStyleManager.variableNameToPropertyName(suggestedNames[i], varKind);
			}
		}

		ContainerUtil.addAll(result, getOverlappedNameVersions(prefix, suggestedNames, requiredSuffix));


	}
	return ArrayUtil.toStringArray(result);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:37,代码来源:JavaMemberNameCompletionContributor.java

示例9: variableNameToPropertyName

@NotNull
@Override
public String variableNameToPropertyName(@NotNull String name, @NotNull VariableKind variableKind)
{
	if(variableKind == VariableKind.STATIC_FINAL_FIELD || variableKind == VariableKind.STATIC_FIELD && name.contains("_"))
	{
		StringBuilder buffer = new StringBuilder();
		for(int i = 0; i < name.length(); i++)
		{
			char c = name.charAt(i);
			if(c != '_')
			{
				if(Character.isLowerCase(c))
				{
					return variableNameToPropertyNameInner(name, variableKind);
				}

				buffer.append(Character.toLowerCase(c));
				continue;
			}
			//noinspection AssignmentToForLoopParameter
			i++;
			if(i < name.length())
			{
				c = name.charAt(i);
				buffer.append(c);
			}
		}
		return buffer.toString();
	}

	return variableNameToPropertyNameInner(name, variableKind);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:33,代码来源:JavaCodeStyleManagerImpl.java

示例10: propertyNameToVariableName

@NotNull
@Override
public String propertyNameToVariableName(@NotNull String propertyName, @NotNull VariableKind variableKind)
{
	if(variableKind == VariableKind.STATIC_FINAL_FIELD)
	{
		String[] words = NameUtil.nameToWords(propertyName);
		StringBuilder buffer = new StringBuilder();
		for(int i = 0; i < words.length; i++)
		{
			String word = words[i];
			if(i > 0)
			{
				buffer.append("_");
			}
			buffer.append(StringUtil.toUpperCase(word));
		}
		return buffer.toString();
	}

	String prefix = getPrefixByVariableKind(variableKind);
	String name = propertyName;
	if(!name.isEmpty() && !prefix.isEmpty() && !StringUtil.endsWithChar(prefix, '_'))
	{
		name = Character.toUpperCase(name.charAt(0)) + name.substring(1);
	}
	name = prefix + name + getSuffixByVariableKind(variableKind);
	name = changeIfNotIdentifier(name);
	return name;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:30,代码来源:JavaCodeStyleManagerImpl.java

示例11: getVariableKind

@Override
protected VariableKind getVariableKind() {
  return VariableKind.STATIC_FINAL_FIELD;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:4,代码来源:InplaceIntroduceConstantPopup.java

示例12: completeFieldName

private static void completeFieldName(Set<LookupElement> set, PsiField var, final PrefixMatcher matcher, boolean includeOverlapped)
{
	FeatureUsageTracker.getInstance().triggerFeatureUsed("editing.completion.variable.name");

	Project project = var.getProject();
	JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
	final VariableKind variableKind = JavaCodeStyleManager.getInstance(project).getVariableKind(var);

	final String prefix = matcher.getPrefix();
	if(PsiType.VOID.equals(var.getType()) || psiField().inClass(psiClass().isInterface().andNot(psiClass().isAnnotationType())).accepts(var))
	{
		completeVariableNameForRefactoring(project, set, matcher, var.getType(), variableKind, includeOverlapped, true);
		return;
	}

	SuggestedNameInfo suggestedNameInfo = codeStyleManager.suggestVariableName(variableKind, null, null, var.getType());
	final String[] suggestedNames = suggestedNameInfo.names;
	addLookupItems(set, suggestedNameInfo, matcher, project, suggestedNames);

	if(!hasStartMatches(set, matcher) && includeOverlapped)
	{
		// use suggested names as suffixes
		final String requiredSuffix = codeStyleManager.getSuffixByVariableKind(variableKind);
		if(variableKind != VariableKind.STATIC_FINAL_FIELD)
		{
			for(int i = 0; i < suggestedNames.length; i++)
			{
				suggestedNames[i] = codeStyleManager.variableNameToPropertyName(suggestedNames[i], variableKind);
			}
		}


		addLookupItems(set, null, matcher, project, getOverlappedNameVersions(prefix, suggestedNames, requiredSuffix));
	}

	addLookupItems(set, suggestedNameInfo, matcher, project, getUnresolvedReferences(var.getParent(), false));

	PsiExpression initializer = var.getInitializer();
	PsiClass containingClass = var.getContainingClass();
	if(initializer != null && containingClass != null)
	{
		SuggestedNameInfo initializerSuggestions = InplaceIntroduceFieldPopup.
				suggestFieldName(var.getType(), null, initializer, var.hasModifierProperty(PsiModifier.STATIC), containingClass);
		addLookupItems(set, initializerSuggestions, matcher, project, initializerSuggestions.names);
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:46,代码来源:JavaMemberNameCompletionContributor.java

示例13: getKind

@Nullable
private static VariableKind getKind(@NotNull JavaCodeStyleManager styleManager, @NotNull PsiReferenceExpression refExpr)
{
	final String reference = refExpr.getText();

	boolean upperCase = true;
	for(int i = 0; i < reference.length(); i++)
	{
		if(!Character.isUpperCase(reference.charAt(i)))
		{
			upperCase = false;
			break;
		}
	}
	if(upperCase)
	{
		return VariableKind.STATIC_FINAL_FIELD;
	}

	for(VariableKind kind : VariableKind.values())
	{
		final String prefix = styleManager.getPrefixByVariableKind(kind);
		final String suffix = styleManager.getSuffixByVariableKind(kind);

		if(prefix.isEmpty() && suffix.isEmpty())
		{
			continue;
		}

		if(reference.startsWith(prefix) && reference.endsWith(suffix))
		{
			return kind;
		}
	}

	if(StringUtil.isCapitalized(reference))
	{
		return null;
	}

	return VariableKind.LOCAL_VARIABLE;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:42,代码来源:DefaultQuickFixProvider.java


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