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


Java PsiNameValuePair类代码示例

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


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

示例1: isJavaElementForType

import com.intellij.psi.PsiNameValuePair; //导入依赖的package包/类
private static boolean isJavaElementForType( PsiModifierListOwner modifierListOwner, PsiClass psiClass )
{
  PsiAnnotation annotation = modifierListOwner.getModifierList().findAnnotation( TypeReference.class.getName() );
  if( annotation != null )
  {
    PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
    for( PsiNameValuePair pair : attributes )
    {
      String fqn = pair.getLiteralValue();
      if( psiClass.getQualifiedName().contains( fqn ) )
      {
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:18,代码来源:ResourceToManifoldUtil.java

示例2: toStringImpl

import com.intellij.psi.PsiNameValuePair; //导入依赖的package包/类
/**
 * Implementation of dynamicProxy.toString()
 */
private String toStringImpl() {
  StringBuilder result = new StringBuilder(128);
  result.append('@');
  result.append(type.getName());
  result.append('(');
  boolean firstMember = true;
  PsiNameValuePair[] attributes = myAnnotation.getParameterList().getAttributes();
  for (PsiNameValuePair e : attributes) {
    if (firstMember) {
      firstMember = false;
    }
    else {
      result.append(", ");
    }

    result.append(e.getName());
    result.append('=');
    PsiAnnotationMemberValue value = e.getValue();
    result.append(value == null ? "null" : value.getText());
  }
  result.append(')');
  return result.toString();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:AnnotationInvocationHandler.java

示例3: isOnXParameterAnnotation

import com.intellij.psi.PsiNameValuePair; //导入依赖的package包/类
public static boolean isOnXParameterAnnotation(HighlightInfo highlightInfo, PsiFile file) {
  if (!(ANNOTATION_TYPE_EXPECTED.equals(highlightInfo.getDescription())
    || CANNOT_RESOLVE_UNDERSCORES_MESSAGE.matcher(StringUtil.notNullize(highlightInfo.getDescription())).matches())) {
    return false;
  }

  PsiElement highlightedElement = file.findElementAt(highlightInfo.getStartOffset());

  PsiNameValuePair nameValuePair = findContainingNameValuePair(highlightedElement);
  if (nameValuePair == null || !(nameValuePair.getContext() instanceof PsiAnnotationParameterList)) {
    return false;
  }

  String parameterName = nameValuePair.getName();
  if (!ONX_PARAMETERS.contains(parameterName)) {
    return false;
  }

  PsiElement containingAnnotation = nameValuePair.getContext().getContext();
  return containingAnnotation instanceof PsiAnnotation && ONXABLE_ANNOTATIONS.contains(((PsiAnnotation) containingAnnotation).getQualifiedName());
}
 
开发者ID:mplushnikov,项目名称:lombok-intellij-plugin,代码行数:22,代码来源:OnXAnnotationHandler.java

示例4: removeDefaultAnnotation

import com.intellij.psi.PsiNameValuePair; //导入依赖的package包/类
protected void removeDefaultAnnotation(@NotNull PsiModifierListOwner targetElement, @NotNull Class<? extends Annotation> annotationClass) {
  final PsiAnnotation psiAnnotation = PsiAnnotationSearchUtil.findAnnotation(targetElement, annotationClass);
  if (null != psiAnnotation) {
    boolean hasOnlyDefaultValues = true;

    final PsiAnnotationParameterList psiAnnotationParameterList = psiAnnotation.getParameterList();
    for (PsiNameValuePair nameValuePair : psiAnnotationParameterList.getAttributes()) {
      if (null != psiAnnotation.findDeclaredAttributeValue(nameValuePair.getName())) {
        hasOnlyDefaultValues = false;
        break;
      }
    }

    if (hasOnlyDefaultValues) {
      psiAnnotation.delete();
    }
  }
}
 
开发者ID:mplushnikov,项目名称:lombok-intellij-plugin,代码行数:19,代码来源:BaseLombokHandler.java

示例5: getDescription

import com.intellij.psi.PsiNameValuePair; //导入依赖的package包/类
@NotNull
public String getDescription(boolean full) {
    if ( !element.equals(resolve(element.getNameReferenceElement())) ) {
        return element.getText();
    }
    StringBuilder buf = new StringBuilder();
    buf.append('@');
    buf.append(element.getQualifiedName());
    if ( full && element.getParameterList().getAttributes().length > 0 ) {
        buf.append('(');
        boolean first = true;
        for( PsiNameValuePair value : element.getParameterList().getAttributes() ) {
            if ( first ) {
                first = false;
            }
            else {
                buf.append(", ");
            }
            buf.append(value.getName()).append("=");
            buf.append(value.getValue() == null ? "?" : value.getValue().getText());
        }
        buf.append(')');
    }
    return buf.toString();
}
 
开发者ID:Abnaxos,项目名称:guards,代码行数:26,代码来源:PsiGuard.java

示例6: accepts

import com.intellij.psi.PsiNameValuePair; //导入依赖的package包/类
@Override
public boolean accepts(@Nullable Object o, ProcessingContext context) {
  if (o instanceof PsiLiteralExpression) {
    final PsiAnnotation parentOfType = PsiTreeUtil.getParentOfType((PsiLiteralExpression) o, PsiAnnotation.class);

    if (parentOfType != null && type.equals(parentOfType.getQualifiedName())) {
      if (attributeName != null) {
        final PsiNameValuePair nvp = PsiTreeUtil.getParentOfType((PsiLiteralExpression) o, PsiNameValuePair.class);
        return nvp != null && attributeName.equals(nvp.getName());
      }
      else {
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:errai,项目名称:errai-intellij-idea-plugin,代码行数:18,代码来源:AnnotationMatchingPattern.java

示例7: getValueStringFromAnnotationWithDefault

import com.intellij.psi.PsiNameValuePair; //导入依赖的package包/类
public static AnnotationValueElement getValueStringFromAnnotationWithDefault(PsiAnnotation annotation) {
  final PsiAnnotationParameterList parameterList = annotation.getParameterList();
  final PsiNameValuePair[] attributes = parameterList.getAttributes();
  final PsiElement logicalElement = getImmediateOwnerElement(annotation);

  if (logicalElement == null) {
    return null;
  }

  final String value;
  final PsiElement errorElement;

  if (attributes.length == 0) {
    value = getNameOfElement(logicalElement);
    errorElement = annotation;
  }
  else {
    final String text = attributes[0].getText();
    value = text.substring(1, text.length() - 1);
    errorElement = attributes[0];
  }

  return new AnnotationValueElement(value, errorElement);
}
 
开发者ID:errai,项目名称:errai-intellij-idea-plugin,代码行数:25,代码来源:Util.java

示例8: buildBlocks

import com.intellij.psi.PsiNameValuePair; //导入依赖的package包/类
public List<Block> buildBlocks()
{
	final Wrap wrap = Wrap.createWrap(getWrapType(myJavaSettings.ANNOTATION_PARAMETER_WRAP), false);
	final Alignment alignment = myJavaSettings.ALIGN_MULTILINE_ANNOTATION_PARAMETERS ? Alignment.createAlignment() : null;

	ChildrenBlocksBuilder.Config config = new ChildrenBlocksBuilder.Config().setDefaultIndent(Indent.getContinuationWithoutFirstIndent()).setIndent(JavaTokenType.RPARENTH, Indent.getNoneIndent()
	).setIndent(JavaTokenType.LPARENTH, Indent.getNoneIndent())

			.setDefaultWrap(wrap).setNoWrap(JavaTokenType.COMMA).setNoWrap(JavaTokenType.RPARENTH).setNoWrap(JavaTokenType.LPARENTH)

			.setDefaultAlignment(alignment).setNoAlignment(JavaTokenType.COMMA).setNoAlignment(JavaTokenType.LPARENTH).setNoAlignmentIf(JavaTokenType.RPARENTH, node -> {
				PsiElement prev = PsiTreeUtil.skipSiblingsBackward(node.getPsi(), PsiWhiteSpace.class);
				if(prev == null)
				{
					return false;
				}
				return prev instanceof PsiNameValuePair && !PsiTreeUtil.hasErrorElements(prev);
			});

	return config.createBuilder().buildNodeChildBlocks(myNode, myFactory);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:22,代码来源:AnnotationInitializerBlocksBuilder.java

示例9: getAnnotationValue

import com.intellij.psi.PsiNameValuePair; //导入依赖的package包/类
@Nullable
PsiExpression getAnnotationValue(PsiAnnotation annotation, String annotationKey) {
    PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
    return Arrays.stream(attributes)
            .filter(a -> annotationKey.equalsIgnoreCase(a.getName()))
            .map(PsiNameValuePair::getValue)
            .filter(v -> v instanceof PsiExpression)
            .map(v -> (PsiExpression) v)
            .findFirst().orElse(null);
}
 
开发者ID:TNG,项目名称:jgiven-intellij-plugin,代码行数:11,代码来源:AnnotationValueProvider.java

示例10: isJavaElementFor

import com.intellij.psi.PsiNameValuePair; //导入依赖的package包/类
private static boolean isJavaElementFor( PsiModifierListOwner modifierListOwner, PsiElement element )
{
  PsiAnnotation annotation = modifierListOwner.getModifierList().findAnnotation( SourcePosition.class.getName() );
  if( annotation != null )
  {
    int textOffset = element.getTextOffset();
    int textLength = element instanceof PsiNamedElement ? ((PsiNamedElement)element).getName().length() : element.getTextLength();
    PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
    int offset = -1;
    for( PsiNameValuePair pair : attributes )
    {
      if( pair.getNameIdentifier().getText().equals( SourcePosition.OFFSET ) )
      {
        String literalValue = pair.getLiteralValue();
        if( literalValue == null )
        {
          return false;
        }
        offset = Integer.parseInt( literalValue );
        break;
      }
    }
    if( offset >= textOffset && offset <= textOffset + textLength )
    {
      return true;
    }
  }
  return false;
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:30,代码来源:ResourceToManifoldUtil.java

示例11: addAnnotations

import com.intellij.psi.PsiNameValuePair; //导入依赖的package包/类
private void addAnnotations( SrcAnnotated<?> srcAnnotated, PsiModifierListOwner annotated )
{
  for( PsiAnnotation psiAnno : annotated.getModifierList().getAnnotations() )
  {
    SrcAnnotationExpression annoExpr = new SrcAnnotationExpression( psiAnno.getQualifiedName() );
    for( PsiNameValuePair value : psiAnno.getParameterList().getAttributes() )
    {
      SrcArgument srcArg = new SrcArgument( new SrcRawExpression( value.getLiteralValue() ) );
      annoExpr.addArgument( srcArg ).name( value.getName() );
    }
    srcAnnotated.addAnnotation( annoExpr );
  }
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:14,代码来源:StubBuilder.java

示例12: withName

import com.intellij.psi.PsiNameValuePair; //导入依赖的package包/类
public PsiNameValuePairPattern withName(@NotNull @NonNls final String requiredName) {
  return with(new PatternCondition<PsiNameValuePair>("withName") {
    public boolean accepts(@NotNull final PsiNameValuePair psiNameValuePair, final ProcessingContext context) {
      String actualName = psiNameValuePair.getName();
      return requiredName.equals(actualName) || actualName == null && "value".equals(requiredName);
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:PsiNameValuePairPattern.java

示例13: annotateMethod

import com.intellij.psi.PsiNameValuePair; //导入依赖的package包/类
private void annotateMethod(@NotNull PsiMethod method) {
  try {
    AddAnnotationPsiFix fix = new AddAnnotationPsiFix(myAnnotation, method, PsiNameValuePair.EMPTY_ARRAY, myAnnotationsToRemove);
    fix.invoke(method.getProject(), method.getContainingFile(), method, method);
  }
  catch (IncorrectOperationException e) {
    LOG.error(e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:AnnotateMethodFix.java

示例14: buildBlocks

import com.intellij.psi.PsiNameValuePair; //导入依赖的package包/类
public List<Block> buildBlocks() {
  final Wrap wrap = Wrap.createWrap(getWrapType(myJavaSettings.ANNOTATION_PARAMETER_WRAP), false);
  final Alignment alignment = myJavaSettings.ALIGN_MULTILINE_ANNOTATION_PARAMETERS ? Alignment.createAlignment() : null;

  ChildrenBlocksBuilder.Config config = new ChildrenBlocksBuilder.Config()
    .setDefaultIndent(Indent.getContinuationWithoutFirstIndent())
    .setIndent(JavaTokenType.RPARENTH, Indent.getNoneIndent())
    .setIndent(JavaTokenType.LPARENTH, Indent.getNoneIndent())

    .setDefaultWrap(wrap)
    .setNoWrap(JavaTokenType.COMMA)
    .setNoWrap(JavaTokenType.RPARENTH)
    .setNoWrap(JavaTokenType.LPARENTH)

    .setDefaultAlignment(alignment)
    .setNoAlignment(JavaTokenType.COMMA)
    .setNoAlignment(JavaTokenType.LPARENTH)
    .setNoAlignmentIf(JavaTokenType.RPARENTH, new Condition<ASTNode>() {
      @Override
      public boolean value(ASTNode node) {
        PsiElement prev = PsiTreeUtil.skipSiblingsBackward(node.getPsi(), PsiWhiteSpace.class);
        if (prev == null) return false;
        return prev instanceof PsiNameValuePair && !PsiTreeUtil.hasErrorElements(prev);
      }
    });

  return config.createBuilder().buildNodeChildBlocks(myNode, myFactory);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:AnnotationInitializerBlocksBuilder.java

示例15: addInternal

import com.intellij.psi.PsiNameValuePair; //导入依赖的package包/类
@Override
public ASTNode addInternal(ASTNode first, ASTNode last, ASTNode anchor, Boolean before) {
  if (first.getElementType() == GroovyElementTypes.ANNOTATION_MEMBER_VALUE_PAIR && last.getElementType() ==
                                                                                   GroovyElementTypes.ANNOTATION_MEMBER_VALUE_PAIR) {
    ASTNode lparenth = getNode().getFirstChildNode();
    ASTNode rparenth = getNode().getLastChildNode();
    if (lparenth == null) {
      getNode().addLeaf(GroovyTokenTypes.mLPAREN, "(", null);
    }
    if (rparenth == null) {
      getNode().addLeaf(GroovyTokenTypes.mRPAREN, ")", null);
    }

    final PsiNameValuePair[] nodes = getAttributes();
    if (nodes.length == 1) {
      final PsiNameValuePair pair = nodes[0];
      if (pair.getName() == null) {
        final String text = pair.getValue().getText();
        try {
          final PsiAnnotation annotation = GroovyPsiElementFactory.getInstance(getProject()).createAnnotationFromText("@AAA(value = " + text + ")");
          getNode().replaceChild(pair.getNode(), annotation.getParameterList().getAttributes()[0].getNode());
        }
        catch (IncorrectOperationException e) {
          LOG.error(e);
        }
      }
    }

    if (anchor == null && before != null) {
      anchor = before.booleanValue() ? getNode().getLastChildNode() : getNode().getFirstChildNode();
    }
  }

  return super.addInternal(first, last, anchor, before);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:GrAnnotationArgumentListImpl.java


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