Java 类com.intellij.openapi.editor.colors.TextAttributesScheme 实例源码

项目:intellij-ce-playground    文件:HighlightNamesUtil.java   
@Nullable
static HighlightInfo highlightVariableName(final PsiVariable variable,
                                           final PsiElement elementToHighlight,
                                           @NotNull TextAttributesScheme colorsScheme) {
  HighlightInfoType varType = getVariableNameHighlightType(variable);
  if (varType != null) {
    if (variable instanceof PsiField) {
      TextAttributes attributes = mergeWithScopeAttributes(variable, varType, colorsScheme);
      HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(varType).range(elementToHighlight.getTextRange());
      if (attributes != null) {
        builder.textAttributes(attributes);
      }
      return builder.createUnconditionally();
    }
    return HighlightInfo.newHighlightInfo(varType).range(elementToHighlight).create();
  }
  return null;
}
项目:intellij-ce-playground    文件:HighlightNamesUtil.java   
private static TextAttributes getScopeAttributes(@NotNull PsiElement element, @NotNull TextAttributesScheme colorsScheme) {
  PsiFile file = element.getContainingFile();
  if (file == null) return null;
  TextAttributes result = null;
  DependencyValidationManagerImpl validationManager = (DependencyValidationManagerImpl)DependencyValidationManager.getInstance(file.getProject());
  List<Pair<NamedScope,NamedScopesHolder>> scopes = validationManager.getScopeBasedHighlightingCachedScopes();
  for (Pair<NamedScope, NamedScopesHolder> scope : scopes) {
    final NamedScope namedScope = scope.getFirst();
    final TextAttributesKey scopeKey = ScopeAttributesUtil.getScopeTextAttributeKey(namedScope.getName());
    final TextAttributes attributes = colorsScheme.getAttributes(scopeKey);
    if (attributes == null || attributes.isEmpty()) {
      continue;
    }
    final PackageSet packageSet = namedScope.getValue();
    if (packageSet != null && packageSet.contains(file, scope.getSecond())) {
      result = TextAttributes.merge(attributes, result);
    }
  }
  return result;
}
项目:tools-idea    文件:HighlightNamesUtil.java   
@Nullable
public static HighlightInfo highlightMethodName(@NotNull PsiMethod method,
                                                final PsiElement elementToHighlight,
                                                TextRange range, @NotNull TextAttributesScheme colorsScheme, final boolean isDeclaration) {
  boolean isInherited = false;

  if (!isDeclaration) {
    if (isCalledOnThis(elementToHighlight)) {
      PsiClass enclosingClass = PsiTreeUtil.getParentOfType(elementToHighlight, PsiClass.class);
      isInherited = enclosingClass != null && enclosingClass.isInheritor(method.getContainingClass(), true);
    }
  }

  HighlightInfoType type = getMethodNameHighlightType(method, isDeclaration, isInherited);
  if (type != null && elementToHighlight != null) {
    TextAttributes attributes = mergeWithScopeAttributes(method, type, colorsScheme);
    HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(type).range(range);
    if (attributes != null) {
      builder.textAttributes(attributes);
    }
    return builder.createUnconditionally();
  }
  return null;
}
项目:tools-idea    文件:HighlightNamesUtil.java   
@Nullable
public static HighlightInfo highlightVariableName(final PsiVariable variable,
                                                  final PsiElement elementToHighlight,
                                                  @NotNull TextAttributesScheme colorsScheme) {
  HighlightInfoType varType = getVariableNameHighlightType(variable);
  if (varType != null) {
    if (variable instanceof PsiField) {
      TextAttributes attributes = mergeWithScopeAttributes(variable, varType, colorsScheme);
      HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(varType).range(elementToHighlight.getTextRange());
      if (attributes != null) {
        builder.textAttributes(attributes);
      }
      return builder.createUnconditionally();
    }
    return HighlightInfo.newHighlightInfo(varType).range(elementToHighlight).create();
  }
  return null;
}
项目:tools-idea    文件:HighlightNamesUtil.java   
private static TextAttributes getScopeAttributes(@NotNull PsiElement element, @NotNull TextAttributesScheme colorsScheme) {
  PsiFile file = element.getContainingFile();
  if (file == null) return null;
  TextAttributes result = null;
  final DaemonCodeAnalyzerImpl daemonCodeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(file.getProject());
  List<Pair<NamedScope,NamedScopesHolder>> scopes = daemonCodeAnalyzer.getScopeBasedHighlightingCachedScopes();
  for (Pair<NamedScope, NamedScopesHolder> scope : scopes) {
    NamedScope namedScope = scope.getFirst();
    NamedScopesHolder scopesHolder = scope.getSecond();
    PackageSet packageSet = namedScope.getValue();
    if (packageSet != null && packageSet.contains(file, scopesHolder)) {
      TextAttributesKey scopeKey = ColorAndFontOptions.getScopeTextAttributeKey(namedScope.getName());
      TextAttributes attributes = colorsScheme.getAttributes(scopeKey);
      if (attributes == null || attributes.isEmpty()) {
        continue;
      }
      result = TextAttributes.merge(attributes, result);
    }
  }
  return result;
}
项目:consulo-java    文件:HighlightVisitorImpl.java   
@Override
public void visitDocTagValue(PsiDocTagValue value)
{
    PsiReference reference = value.getReference();
    if(reference != null)
    {
        PsiElement element = reference.resolve();
        final TextAttributesScheme colorsScheme = myHolder.getColorsScheme();
        if(element instanceof PsiMethod)
        {
            PsiElement nameElement = ((PsiDocMethodOrFieldRef) value).getNameElement();
            if(nameElement != null)
            {
                myHolder.add(HighlightNamesUtil.highlightMethodName((PsiMethod) element, nameElement, false, colorsScheme));
            }
        }
        else if(element instanceof PsiParameter)
        {
            myHolder.add(HighlightNamesUtil.highlightVariableName((PsiVariable) element, value.getNavigationElement(), colorsScheme));
        }
    }
}
项目:intellij-ce-playground    文件:HighlightNamesUtil.java   
@Nullable
static HighlightInfo highlightMethodName(@NotNull PsiMethod method,
                                         final PsiElement elementToHighlight,
                                         final boolean isDeclaration,
                                         @NotNull TextAttributesScheme colorsScheme) {
  return highlightMethodName(method, elementToHighlight, elementToHighlight.getTextRange(), colorsScheme, isDeclaration);
}
项目:intellij-ce-playground    文件:HighlightNamesUtil.java   
@Nullable
static HighlightInfo highlightMethodName(@NotNull PsiMethod method,
                                         final PsiElement elementToHighlight,
                                         TextRange range, @NotNull TextAttributesScheme colorsScheme, final boolean isDeclaration) {
  boolean isInherited = false;

  if (!isDeclaration) {
    if (isCalledOnThis(elementToHighlight)) {
      final PsiClass containingClass = method.getContainingClass();
      PsiClass enclosingClass = containingClass == null ? null : PsiTreeUtil.getParentOfType(elementToHighlight, PsiClass.class);
      while (enclosingClass != null) {
        isInherited = enclosingClass.isInheritor(containingClass, true);
        if (isInherited) break;
        enclosingClass = PsiTreeUtil.getParentOfType(enclosingClass, PsiClass.class, true);
      }
    }
  }

  HighlightInfoType type = getMethodNameHighlightType(method, isDeclaration, isInherited);
  if (type != null && elementToHighlight != null) {
    TextAttributes attributes = mergeWithScopeAttributes(method, type, colorsScheme);
    HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(type).range(range);
    if (attributes != null) {
      builder.textAttributes(attributes);
    }
    return builder.createUnconditionally();
  }
  return null;
}
项目:intellij-ce-playground    文件:HighlightNamesUtil.java   
private static TextAttributes mergeWithScopeAttributes(final PsiElement element,
                                                       @NotNull HighlightInfoType type,
                                                       @NotNull TextAttributesScheme colorsScheme) {
  TextAttributes regularAttributes = HighlightInfo.getAttributesByType(element, type, colorsScheme);
  if (element == null) return regularAttributes;
  TextAttributes scopeAttributes = getScopeAttributes(element, colorsScheme);
  return TextAttributes.merge(scopeAttributes, regularAttributes);
}
项目:intellij-ce-playground    文件:HighlightNamesUtil.java   
@Nullable
static HighlightInfo highlightClassName(PsiClass aClass, PsiElement elementToHighlight, @NotNull TextAttributesScheme colorsScheme) {
  HighlightInfoType type = getClassNameHighlightType(aClass, elementToHighlight);
  if (elementToHighlight != null) {
    TextAttributes attributes = mergeWithScopeAttributes(aClass, type, colorsScheme);
    TextRange range = elementToHighlight.getTextRange();
    if (elementToHighlight instanceof PsiJavaCodeReferenceElement) {
      final PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)elementToHighlight;
      PsiReferenceParameterList parameterList = referenceElement.getParameterList();
      if (parameterList != null) {
        final TextRange paramListRange = parameterList.getTextRange();
        if (paramListRange.getEndOffset() > paramListRange.getStartOffset()) {
          range = new TextRange(range.getStartOffset(), paramListRange.getStartOffset());
        }
      }
    }

    // This will highlight @ sign in annotation as well.
    final PsiElement parent = elementToHighlight.getParent();
    if (parent instanceof PsiAnnotation) {
      final PsiAnnotation psiAnnotation = (PsiAnnotation)parent;
      range = new TextRange(psiAnnotation.getTextRange().getStartOffset(), range.getEndOffset());
    }

    HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(type).range(range);
    if (attributes != null) {
      builder.textAttributes(attributes);
    }
    return builder.createUnconditionally();
  }
  return null;
}
项目:intellij-ce-playground    文件:HighlightNamesUtil.java   
@Nullable
static HighlightInfo highlightClassNameInQualifier(final PsiJavaCodeReferenceElement element,
                                                   @NotNull TextAttributesScheme colorsScheme) {
  PsiElement qualifierExpression = element.getQualifier();
  if (qualifierExpression instanceof PsiJavaCodeReferenceElement) {
    PsiElement resolved = ((PsiJavaCodeReferenceElement)qualifierExpression).resolve();
    if (resolved instanceof PsiClass) {
      return highlightClassName((PsiClass)resolved, qualifierExpression, colorsScheme);
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:HighlightVisitorImpl.java   
@Override
public void visitDocTagValue(PsiDocTagValue value) {
  PsiReference reference = value.getReference();
  if (reference != null) {
    PsiElement element = reference.resolve();
    final TextAttributesScheme colorsScheme = myHolder.getColorsScheme();
    if (element instanceof PsiMethod) {
      myHolder.add(HighlightNamesUtil.highlightMethodName((PsiMethod)element, ((PsiDocMethodOrFieldRef)value).getNameElement(), false,
                                                          colorsScheme));
    }
    else if (element instanceof PsiParameter) {
      myHolder.add(HighlightNamesUtil.highlightVariableName((PsiVariable)element, value.getNavigationElement(), colorsScheme));
    }
  }
}
项目:intellij-ce-playground    文件:HighlightVisitorImpl.java   
@Override
public void visitMethod(PsiMethod method) {
  super.visitMethod(method);
  if (!myHolder.hasErrorResults()) myHolder.add(HighlightControlFlowUtil.checkUnreachableStatement(method.getBody()));
  if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkConstructorHandleSuperClassExceptions(method));
  if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkRecursiveConstructorInvocation(method));
  if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkSafeVarargsAnnotation(method, myLanguageLevel));

  PsiClass aClass = method.getContainingClass();
  if (!myHolder.hasErrorResults() && method.isConstructor()) {
    myHolder.add(HighlightClassUtil.checkThingNotAllowedInInterface(method, aClass));
  }
  if (!myHolder.hasErrorResults() && method.hasModifierProperty(PsiModifier.DEFAULT)) {
    myHolder.add(checkFeature(method, Feature.EXTENSION_METHODS));
  }
  if (!myHolder.hasErrorResults() && aClass != null && aClass.isInterface() && method.hasModifierProperty(PsiModifier.STATIC)) {
    myHolder.add(checkFeature(method, Feature.EXTENSION_METHODS));
  }
  if (!myHolder.hasErrorResults() && aClass != null) {
    myHolder.add(HighlightMethodUtil.checkDuplicateMethod(aClass, method, getDuplicateMethods(aClass)));
  }

  // method params are highlighted in visitMethod since we should make sure the method body was visited before
  PsiParameter[] parameters = method.getParameterList().getParameters();
  final TextAttributesScheme colorsScheme = myHolder.getColorsScheme();

  for (PsiParameter parameter : parameters) {
    int info = myReassignedParameters.get(parameter);
    if (info == 0) continue; // out of this file
    if (info == 2) {// reassigned
      myHolder.add(HighlightNamesUtil.highlightReassignedVariable(parameter, parameter.getNameIdentifier()));
    }
    else {
      myHolder.add(HighlightNamesUtil.highlightVariableName(parameter, parameter.getNameIdentifier(), colorsScheme));
    }
  }
}
项目:intellij-ce-playground    文件:HighlightInfoHolder.java   
@NotNull
public TextAttributesScheme getColorsScheme() {
  return new TextAttributesScheme() {
    @Override
    public TextAttributes getAttributes(TextAttributesKey key) {
      return key.getDefaultAttributes();
    }
  };
}
项目:intellij-ce-playground    文件:CustomHighlightInfoHolder.java   
@Override
@NotNull
public TextAttributesScheme getColorsScheme() {
  if (myCustomColorsScheme != null) {
    return myCustomColorsScheme;
  }
  return EditorColorsManager.getInstance().getGlobalScheme();
}
项目:tools-idea    文件:HighlightNamesUtil.java   
@Nullable
public static HighlightInfo highlightMethodName(@NotNull PsiMethod method,
                                                final PsiElement elementToHighlight,
                                                final boolean isDeclaration,
                                                @NotNull TextAttributesScheme colorsScheme) {
  return highlightMethodName(method, elementToHighlight, elementToHighlight.getTextRange(), colorsScheme, isDeclaration);
}
项目:tools-idea    文件:HighlightNamesUtil.java   
private static TextAttributes mergeWithScopeAttributes(final PsiElement element,
                                                       @NotNull HighlightInfoType type,
                                                       @NotNull TextAttributesScheme colorsScheme) {
  TextAttributes regularAttributes = HighlightInfo.getAttributesByType(element, type, colorsScheme);
  if (element == null) return regularAttributes;
  TextAttributes scopeAttributes = getScopeAttributes(element, colorsScheme);
  return TextAttributes.merge(scopeAttributes, regularAttributes);
}
项目:tools-idea    文件:HighlightNamesUtil.java   
@Nullable
public static HighlightInfo highlightClassName(PsiClass aClass, PsiElement elementToHighlight, @NotNull TextAttributesScheme colorsScheme) {
  HighlightInfoType type = getClassNameHighlightType(aClass, elementToHighlight);
  if (elementToHighlight != null) {
    TextAttributes attributes = mergeWithScopeAttributes(aClass, type, colorsScheme);
    TextRange range = elementToHighlight.getTextRange();
    if (elementToHighlight instanceof PsiJavaCodeReferenceElement) {
      final PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)elementToHighlight;
      PsiReferenceParameterList parameterList = referenceElement.getParameterList();
      if (parameterList != null) {
        final TextRange paramListRange = parameterList.getTextRange();
        if (paramListRange.getEndOffset() > paramListRange.getStartOffset()) {
          range = new TextRange(range.getStartOffset(), paramListRange.getStartOffset());
        }
      }
    }

    // This will highlight @ sign in annotation as well.
    final PsiElement parent = elementToHighlight.getParent();
    if (parent instanceof PsiAnnotation) {
      final PsiAnnotation psiAnnotation = (PsiAnnotation)parent;
      range = new TextRange(psiAnnotation.getTextRange().getStartOffset(), range.getEndOffset());
    }

    HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(type).range(range);
    if (attributes != null) {
      builder.textAttributes(attributes);
    }
    return builder.createUnconditionally();
  }
  return null;
}
项目:tools-idea    文件:HighlightNamesUtil.java   
@Nullable
public static HighlightInfo highlightClassNameInQualifier(final PsiJavaCodeReferenceElement element,
                                                          @NotNull TextAttributesScheme colorsScheme) {
  PsiExpression qualifierExpression = null;
  if (element instanceof PsiReferenceExpression) {
    qualifierExpression = ((PsiReferenceExpression)element).getQualifierExpression();
  }
  if (qualifierExpression instanceof PsiJavaCodeReferenceElement) {
    PsiElement resolved = ((PsiJavaCodeReferenceElement)qualifierExpression).resolve();
    if (resolved instanceof PsiClass) {
      return highlightClassName((PsiClass)resolved, qualifierExpression, colorsScheme);
    }
  }
  return null;
}
项目:tools-idea    文件:HighlightVisitorImpl.java   
@Override
public void visitDocTagValue(PsiDocTagValue value) {
  PsiReference reference = value.getReference();
  if (reference != null) {
    PsiElement element = reference.resolve();
    final TextAttributesScheme colorsScheme = myHolder.getColorsScheme();
    if (element instanceof PsiMethod) {
      myHolder.add(HighlightNamesUtil.highlightMethodName((PsiMethod)element, ((PsiDocMethodOrFieldRef)value).getNameElement(), false,
                                                          colorsScheme));
    }
    else if (element instanceof PsiParameter) {
      myHolder.add(HighlightNamesUtil.highlightVariableName((PsiVariable)element, value.getNavigationElement(), colorsScheme));
    }
  }
}
项目:tools-idea    文件:HighlightVisitorImpl.java   
@Override
public void visitMethod(PsiMethod method) {
  super.visitMethod(method);
  if (!myHolder.hasErrorResults()) myHolder.add(HighlightControlFlowUtil.checkUnreachableStatement(method.getBody()));
  if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkConstructorHandleSuperClassExceptions(method));
  if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkRecursiveConstructorInvocation(method));
  if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkOverrideAnnotation(method, myLanguageLevel));
  if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkSafeVarargsAnnotation(method));
  if (!myHolder.hasErrorResults() && method.isConstructor()) {
    myHolder.add(HighlightClassUtil.checkThingNotAllowedInInterface(method, method.getContainingClass()));
  }

  // method params are highlighted in visitMethod since we should make sure the method body was visited before
  PsiParameter[] parameters = method.getParameterList().getParameters();
  final TextAttributesScheme colorsScheme = myHolder.getColorsScheme();

  for (PsiParameter parameter : parameters) {
    int info = myReassignedParameters.get(parameter);
    if (info == 0) continue; // out of this file
    if (info == 2) {// reassigned
      myHolder.add(HighlightNamesUtil.highlightReassignedVariable(parameter, parameter.getNameIdentifier()));
    }
    else {
      myHolder.add(HighlightNamesUtil.highlightVariableName(parameter, parameter.getNameIdentifier(), colorsScheme));
    }
  }
}
项目:tools-idea    文件:HighlightInfoHolder.java   
@NotNull
public TextAttributesScheme getColorsScheme() {
  return new TextAttributesScheme() {
    @Override
    public TextAttributes getAttributes(TextAttributesKey key) {
      return key.getDefaultAttributes();
    }
  };
}
项目:tools-idea    文件:CustomHighlightInfoHolder.java   
@Override
@NotNull
public TextAttributesScheme getColorsScheme() {
  if (myCustomColorsScheme != null) {
    return myCustomColorsScheme;
  }
  return EditorColorsManager.getInstance().getGlobalScheme();
}
项目:consulo    文件:HighlightInfoHolder.java   
@Nonnull
public TextAttributesScheme getColorsScheme() {
  return new TextAttributesScheme() {
    @Override
    public TextAttributes getAttributes(TextAttributesKey key) {
      return key.getDefaultAttributes();
    }
  };
}
项目:consulo    文件:CustomHighlightInfoHolder.java   
@Override
@Nonnull
public TextAttributesScheme getColorsScheme() {
  if (myCustomColorsScheme != null) {
    return myCustomColorsScheme;
  }
  return EditorColorsManager.getInstance().getGlobalScheme();
}
项目:consulo    文件:RainbowHighlighter.java   
@Nullable
@Contract("_, null -> !null")
public static Boolean isRainbowEnabled(@Nullable TextAttributesScheme colorsScheme, @Nullable Language language) {
  if (colorsScheme instanceof SchemeMetaInfo) {
    String value = ((SchemeMetaInfo)colorsScheme).getMetaProperties().getProperty(getKey(language), INHERITED);
    if (String.valueOf(true).equals(value)) return Boolean.TRUE;
    if (String.valueOf(false).equals(value)) return Boolean.FALSE;
    return language == null ? DEFAULT_RAINBOW_ON : null;
  }
  return false;
}
项目:consulo    文件:RainbowHighlighter.java   
@Nonnull
private static Color[] generateColorSequence(@Nonnull TextAttributesScheme colorsScheme) {
  String colorDump = ApplicationManager.getApplication().isUnitTestMode()
                     ? UNIT_TEST_COLORS
                     : Registry.get("rainbow.highlighter.colors").asString();

  final List<String> registryColors = StringUtil.split(colorDump, ",");
  if (!registryColors.isEmpty()) {
    return registryColors.stream().map(s -> ColorUtil.fromHex(s.trim())).toArray(Color[]::new);
  }

  List<Color> stopColors = ContainerUtil.map(RAINBOW_COLOR_KEYS, key -> colorsScheme.getAttributes(key).getForegroundColor());
  List<Color> colors = ColorGenerator.generateLinearColorSequence(stopColors, RAINBOW_COLORS_BETWEEN);
  return colors.toArray(new Color[colors.size()]);
}
项目:consulo-java    文件:HighlightNamesUtil.java   
private static TextAttributes mergeWithScopeAttributes(@Nullable PsiElement element, @NotNull HighlightInfoType type, @NotNull TextAttributesScheme colorsScheme)
{
    TextAttributes regularAttributes = HighlightInfo.getAttributesByType(element, type, colorsScheme);
    if(element == null)
    {
        return regularAttributes;
    }
    TextAttributes scopeAttributes = getScopeAttributes(element, colorsScheme);
    return TextAttributes.merge(scopeAttributes, regularAttributes);
}
项目:consulo-java    文件:HighlightNamesUtil.java   
@NotNull
static HighlightInfo highlightClassName(@Nullable PsiClass aClass, @NotNull PsiElement elementToHighlight, @NotNull TextAttributesScheme colorsScheme)
{
    TextRange range = elementToHighlight.getTextRange();
    if(elementToHighlight instanceof PsiJavaCodeReferenceElement)
    {
        final PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement) elementToHighlight;
        PsiElement identifier = referenceElement.getReferenceNameElement();
        if(identifier != null)
        {
            range = identifier.getTextRange();
        }
    }

    // This will highlight @ sign in annotation as well.
    final PsiElement parent = elementToHighlight.getParent();
    if(parent instanceof PsiAnnotation)
    {
        final PsiAnnotation psiAnnotation = (PsiAnnotation) parent;
        range = new TextRange(psiAnnotation.getTextRange().getStartOffset(), range.getEndOffset());
    }

    HighlightInfoType type = getClassNameHighlightType(aClass, elementToHighlight);
    TextAttributes attributes = mergeWithScopeAttributes(aClass, type, colorsScheme);
    HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(type).range(range);
    if(attributes != null)
    {
        builder.textAttributes(attributes);
    }
    return builder.createUnconditionally();
}
项目:consulo-java    文件:HighlightNamesUtil.java   
@Nullable
static HighlightInfo highlightClassNameInQualifier(@NotNull PsiJavaCodeReferenceElement element, @NotNull TextAttributesScheme colorsScheme)
{
    PsiElement qualifierExpression = element.getQualifier();
    if(qualifierExpression instanceof PsiJavaCodeReferenceElement)
    {
        PsiElement resolved = ((PsiJavaCodeReferenceElement) qualifierExpression).resolve();
        if(resolved instanceof PsiClass)
        {
            return highlightClassName((PsiClass) resolved, qualifierExpression, colorsScheme);
        }
    }
    return null;
}
项目:consulo-java    文件:HighlightNamesUtil.java   
private static TextAttributes getScopeAttributes(@NotNull PsiElement element, @NotNull TextAttributesScheme colorsScheme)
{
    PsiFile file = element.getContainingFile();
    if(file == null)
    {
        return null;
    }
    TextAttributes result = null;
    DependencyValidationManagerImpl validationManager = (DependencyValidationManagerImpl) DependencyValidationManager.getInstance(file.getProject());
    List<Pair<NamedScope, NamedScopesHolder>> scopes = validationManager.getScopeBasedHighlightingCachedScopes();
    for(Pair<NamedScope, NamedScopesHolder> scope : scopes)
    {
        final NamedScope namedScope = scope.getFirst();
        final TextAttributesKey scopeKey = ScopeAttributesUtil.getScopeTextAttributeKey(namedScope.getName());
        final TextAttributes attributes = colorsScheme.getAttributes(scopeKey);
        if(attributes == null || attributes.isEmpty())
        {
            continue;
        }
        final PackageSet packageSet = namedScope.getValue();
        if(packageSet != null && packageSet.contains(file, scope.getSecond()))
        {
            result = TextAttributes.merge(attributes, result);
        }
    }
    return result;
}
项目:consulo-java    文件:HighlightNamesUtil.java   
static HighlightInfo highlightPackage(@NotNull PsiElement resolved, @NotNull PsiJavaCodeReferenceElement elementToHighlight, @NotNull TextAttributesScheme scheme)
{
    PsiElement referenceNameElement = elementToHighlight.getReferenceNameElement();
    TextRange range;
    if(referenceNameElement == null)
    {
        range = elementToHighlight.getTextRange();
    }
    else
    {
        PsiElement nextSibling = PsiTreeUtil.nextLeaf(referenceNameElement);
        if(nextSibling != null && nextSibling.getTextRange().isEmpty())
        {
            // empty PsiReferenceParameterList
            nextSibling = PsiTreeUtil.nextLeaf(nextSibling);
        }
        if(nextSibling instanceof PsiJavaToken && ((PsiJavaToken) nextSibling).getTokenType() == JavaTokenType.DOT)
        {
            range = new TextRange(referenceNameElement.getTextRange().getStartOffset(), nextSibling.getTextRange().getEndOffset());
        }
        else
        {
            range = referenceNameElement.getTextRange();
        }
    }
    HighlightInfoType type = JavaHighlightInfoTypes.PACKAGE_NAME;
    TextAttributes attributes = mergeWithScopeAttributes(resolved, type, scheme);
    HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(type).range(range);
    if(attributes != null)
    {
        builder.textAttributes(attributes);
    }
    return builder.createUnconditionally();
}
项目:intellij-ce-playground    文件:CheckLevelHighlightInfoHolder.java   
@NotNull
@Override
public TextAttributesScheme getColorsScheme() {
  return myHolder.getColorsScheme();
}
项目:tools-idea    文件:HighlightVisitorImpl.java   
@Override
public void visitIdentifier(final PsiIdentifier identifier) {
  TextAttributesScheme colorsScheme = myHolder.getColorsScheme();

  PsiElement parent = identifier.getParent();
  if (parent instanceof PsiVariable) {
    PsiVariable variable = (PsiVariable)parent;
    myHolder.add(HighlightUtil.checkVariableAlreadyDefined(variable));

    if (variable.getInitializer() == null) {
      final PsiElement child = variable.getLastChild();
      if (child instanceof PsiErrorElement && child.getPrevSibling() == identifier) return;
    }

    boolean isMethodParameter = variable instanceof PsiParameter && ((PsiParameter)variable).getDeclarationScope() instanceof PsiMethod;
    if (!isMethodParameter) { // method params are highlighted in visitMethod since we should make sure the method body was visited before
      if (HighlightControlFlowUtil.isReassigned(variable, myFinalVarProblems)) {
        myHolder.add(HighlightNamesUtil.highlightReassignedVariable(variable, identifier));
      }
      else {
        myHolder.add(HighlightNamesUtil.highlightVariableName(variable, identifier, colorsScheme));
      }
    }
    else {
      myReassignedParameters.put((PsiParameter)variable, 1); // mark param as present in current file
    }

    myHolder.add(HighlightUtil.checkUnderscore(identifier, variable));
  }
  else if (parent instanceof PsiClass) {
    PsiClass aClass = (PsiClass)parent;
    if (aClass.isAnnotationType()) {
      myHolder.add(HighlightUtil.checkAnnotationFeature(identifier, myLanguageLevel, myFile));
    }

    myHolder.add(HighlightClassUtil.checkClassAlreadyImported(aClass, identifier));
    if (!(parent instanceof PsiAnonymousClass) && aClass.getNameIdentifier() == identifier) {
      myHolder.add(HighlightNamesUtil.highlightClassName(aClass, identifier, colorsScheme));
    }
  }
  else if (parent instanceof PsiMethod) {
    PsiMethod method = (PsiMethod)parent;
    if (method.isConstructor()) {
      myHolder.add(HighlightMethodUtil.checkConstructorName(method));
    }
    myHolder.add(HighlightNamesUtil.highlightMethodName(method, identifier, true, colorsScheme));
  }
  else {
    visitParentReference(parent);
  }

  super.visitIdentifier(identifier);
}
项目:consulo    文件:CheckLevelHighlightInfoHolder.java   
@Nonnull
@Override
public TextAttributesScheme getColorsScheme() {
  return myHolder.getColorsScheme();
}
项目:consulo    文件:RainbowHighlighter.java   
public RainbowHighlighter(@Nullable TextAttributesScheme colorsScheme) {
  myColorsScheme = colorsScheme != null ? colorsScheme : EditorColorsManager.getInstance().getGlobalScheme();
  myRainbowColors = generateColorSequence(myColorsScheme);
}
项目:consulo    文件:RainbowHighlighter.java   
public static boolean isRainbowEnabledWithInheritance(@Nullable TextAttributesScheme colorsScheme, @Nullable Language language) {
  Boolean rainbowEnabled = isRainbowEnabled(colorsScheme, language);
  return rainbowEnabled != null ? rainbowEnabled : isRainbowEnabled(colorsScheme, null);
}
项目:consulo-java    文件:HighlightNamesUtil.java   
@Nullable
static HighlightInfo highlightMethodName(@NotNull PsiMethod method, @NotNull PsiElement elementToHighlight, final boolean isDeclaration, @NotNull TextAttributesScheme colorsScheme)
{
    return highlightMethodName(method, elementToHighlight, elementToHighlight.getTextRange(), colorsScheme, isDeclaration);
}
项目:consulo-java    文件:HighlightNamesUtil.java   
/**
 * @param methodOrClass method to highlight; class is passed instead of implicit constructor
 */
@Nullable
static HighlightInfo highlightMethodName(@NotNull PsiMember methodOrClass,
        @NotNull PsiElement elementToHighlight,
        @NotNull TextRange range,
        @NotNull TextAttributesScheme colorsScheme,
        final boolean isDeclaration)
{
    boolean isInherited = false;

    if(!isDeclaration)
    {
        if(isCalledOnThis(elementToHighlight))
        {
            final PsiClass containingClass = methodOrClass instanceof PsiMethod ? methodOrClass.getContainingClass() : null;
            PsiClass enclosingClass = containingClass == null ? null : PsiTreeUtil.getParentOfType(elementToHighlight, PsiClass.class);
            while(enclosingClass != null)
            {
                isInherited = enclosingClass.isInheritor(containingClass, true);
                if(isInherited)
                {
                    break;
                }
                enclosingClass = PsiTreeUtil.getParentOfType(enclosingClass, PsiClass.class, true);
            }
        }
    }

    LOG.assertTrue(methodOrClass instanceof PsiMethod || !isDeclaration);
    HighlightInfoType type = methodOrClass instanceof PsiMethod ? getMethodNameHighlightType((PsiMethod) methodOrClass, isDeclaration, isInherited) : JavaHighlightInfoTypes.CONSTRUCTOR_CALL;
    if(type != null)
    {
        TextAttributes attributes = mergeWithScopeAttributes(methodOrClass, type, colorsScheme);
        HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(type).range(range);
        if(attributes != null)
        {
            builder.textAttributes(attributes);
        }
        return builder.createUnconditionally();
    }
    return null;
}
项目:consulo-java    文件:HighlightVisitorImpl.java   
@Override
public void visitMethod(PsiMethod method)
{
    super.visitMethod(method);
    if(!myHolder.hasErrorResults())
    {
        myHolder.add(HighlightControlFlowUtil.checkUnreachableStatement(method.getBody()));
    }
    if(!myHolder.hasErrorResults())
    {
        myHolder.add(HighlightMethodUtil.checkConstructorHandleSuperClassExceptions(method));
    }
    if(!myHolder.hasErrorResults())
    {
        myHolder.add(HighlightMethodUtil.checkRecursiveConstructorInvocation(method));
    }
    if(!myHolder.hasErrorResults())
    {
        myHolder.add(GenericsHighlightUtil.checkSafeVarargsAnnotation(method, myLanguageLevel));
    }

    PsiClass aClass = method.getContainingClass();
    if(!myHolder.hasErrorResults() && method.isConstructor())
    {
        myHolder.add(HighlightClassUtil.checkThingNotAllowedInInterface(method, aClass));
    }
    if(!myHolder.hasErrorResults() && method.hasModifierProperty(PsiModifier.DEFAULT))
    {
        myHolder.add(checkFeature(method, Feature.EXTENSION_METHODS));
    }
    if(!myHolder.hasErrorResults() && aClass != null && aClass.isInterface() && method.hasModifierProperty(PsiModifier.STATIC))
    {
        myHolder.add(checkFeature(method, Feature.EXTENSION_METHODS));
    }
    if(!myHolder.hasErrorResults() && aClass != null)
    {
        myHolder.add(HighlightMethodUtil.checkDuplicateMethod(aClass, method, getDuplicateMethods(aClass)));
    }

    // method params are highlighted in visitMethod since we should make sure the method body was visited before
    PsiParameter[] parameters = method.getParameterList().getParameters();
    final TextAttributesScheme colorsScheme = myHolder.getColorsScheme();

    for(PsiParameter parameter : parameters)
    {
        int info = myReassignedParameters.get(parameter);
        if(info == 0)
        {
            continue; // out of this file
        }

        PsiIdentifier nameIdentifier = parameter.getNameIdentifier();
        if(nameIdentifier != null)
        {
            if(info == 2)
            { // reassigned
                myHolder.add(HighlightNamesUtil.highlightReassignedVariable(parameter, nameIdentifier));
            }
            else
            {
                myHolder.add(HighlightNamesUtil.highlightVariableName(parameter, nameIdentifier, colorsScheme));
            }
        }
    }
}