类org.eclipse.jdt.core.dom.SingleMemberAnnotation源码实例Demo

下面列出了怎么用org.eclipse.jdt.core.dom.SingleMemberAnnotation的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: xtext-xtend   文件: ASTFlattenerUtils.java
public boolean canConvertToRichText(final InfixExpression node) {
  final FieldDeclaration parentFieldDecl = this.<FieldDeclaration>findParentOfType(node, FieldDeclaration.class);
  if ((parentFieldDecl != null)) {
    final TypeDeclaration typeDeclr = this.<TypeDeclaration>findParentOfType(parentFieldDecl, TypeDeclaration.class);
    if ((typeDeclr.isInterface() || (this.isFinal(parentFieldDecl.modifiers()) && this.isStatic(parentFieldDecl.modifiers())))) {
      return false;
    }
  }
  final SingleMemberAnnotation parentSingleMemberAnnotation = this.<SingleMemberAnnotation>findParentOfType(node, SingleMemberAnnotation.class);
  if ((parentSingleMemberAnnotation != null)) {
    return false;
  }
  final Iterable<StringLiteral> nodes = this.collectCompatibleNodes(node);
  return ((!IterableExtensions.isEmpty(nodes)) && IterableExtensions.<StringLiteral>forall(nodes, ((Function1<StringLiteral, Boolean>) (StringLiteral it) -> {
    return Boolean.valueOf(this.canTranslate(it));
  })));
}
 
@SuppressWarnings("unchecked")
private void validateUiHandlerFieldExistenceInUiXml(
    MethodDeclaration uiHandlerDecl) {
  Annotation annotation = JavaASTUtils.findAnnotation(uiHandlerDecl,
      UiBinderConstants.UI_HANDLER_TYPE_NAME);

  if (annotation instanceof SingleMemberAnnotation) {
    SingleMemberAnnotation uiHandlerAnnotation = (SingleMemberAnnotation) annotation;
    Expression exp = uiHandlerAnnotation.getValue();
    if (exp instanceof StringLiteral) {
      validateFieldExistenceInUiXml(
          (TypeDeclaration) uiHandlerDecl.getParent(), exp,
          ((StringLiteral) exp).getLiteralValue());
    } else if (exp instanceof ArrayInitializer) {
      for (Expression element : (List<Expression>) ((ArrayInitializer) exp).expressions()) {
        if (element instanceof StringLiteral) {
          validateFieldExistenceInUiXml(
              (TypeDeclaration) uiHandlerDecl.getParent(), element,
              ((StringLiteral) element).getLiteralValue());
        }
      }
    }
  }
}
 
源代码3 项目: RefactoringMiner   文件: UMLAnnotation.java
public UMLAnnotation(CompilationUnit cu, String filePath, Annotation annotation) {
	this.typeName = annotation.getTypeName().getFullyQualifiedName();
	this.locationInfo = new LocationInfo(cu, filePath, annotation, CodeElementType.ANNOTATION);
	if(annotation instanceof SingleMemberAnnotation) {
		SingleMemberAnnotation singleMemberAnnotation = (SingleMemberAnnotation)annotation;
		this.value = new AbstractExpression(cu, filePath, singleMemberAnnotation.getValue(), CodeElementType.SINGLE_MEMBER_ANNOTATION_VALUE);
	}
	else if(annotation instanceof NormalAnnotation) {
		NormalAnnotation normalAnnotation = (NormalAnnotation)annotation;
		List<MemberValuePair> pairs = normalAnnotation.values();
		for(MemberValuePair pair : pairs) {
			AbstractExpression value = new AbstractExpression(cu, filePath, pair.getValue(), CodeElementType.NORMAL_ANNOTATION_MEMBER_VALUE_PAIR);
			memberValuePairs.put(pair.getName().getIdentifier(), value);
		}
	}
}
 
源代码4 项目: txtUML   文件: PlantUmlPreCompiler.java
@Override
public boolean visit(FieldDeclaration decl) {
	boolean isLifeline = SharedUtils.typeIsAssignableFrom(decl.getType().resolveBinding(), Proxy.class)
			|| SharedUtils.typeIsAssignableFrom(decl.getType().resolveBinding(),
					hu.elte.txtuml.api.model.seqdiag.Lifeline.class);

	if (isLifeline) {
		List<?> modifiers = decl.modifiers();
		Optional<Integer> position = modifiers.stream().filter(modifier -> modifier instanceof Annotation)
				.map(modifier -> (Annotation) modifier)
				.filter(annot -> annot.getTypeName().getFullyQualifiedName().equals("Position"))
				.map(annot -> (int) ((SingleMemberAnnotation) annot).getValue().resolveConstantExpressionValue())
				.findFirst();

		if (position.isPresent()) {
			addLifeline(position.get(), decl);
		} else {
			addLifeline(-1, decl);
		}
	}
	return true;
}
 
private static Annotation findExistingAnnotation(List<? extends ASTNode> modifiers) {
	for (int i= 0, len= modifiers.size(); i < len; i++) {
		Object curr= modifiers.get(i);
		if (curr instanceof NormalAnnotation || curr instanceof SingleMemberAnnotation) {
			Annotation annotation= (Annotation) curr;
			ITypeBinding typeBinding= annotation.resolveTypeBinding();
			if (typeBinding != null) {
				if ("java.lang.SuppressWarnings".equals(typeBinding.getQualifiedName())) { //$NON-NLS-1$
					return annotation;
				}
			} else {
				String fullyQualifiedName= annotation.getTypeName().getFullyQualifiedName();
				if ("SuppressWarnings".equals(fullyQualifiedName) || "java.lang.SuppressWarnings".equals(fullyQualifiedName)) { //$NON-NLS-1$ //$NON-NLS-2$
					return annotation;
				}
			}
		}
	}
	return null;
}
 
private SingleMemberAnnotation createGeneratedAnnotation(AST ast) {
    SingleMemberAnnotation generatedAnnotation = ast.newSingleMemberAnnotation();
    generatedAnnotation.setTypeName(ast.newSimpleName("Generated"));
    StringLiteral annotationValue = ast.newStringLiteral();
    annotationValue.setLiteralValue(StaticPreferences.PLUGIN_GENERATED_ANNOTATION_NAME);
    generatedAnnotation.setValue(annotationValue);
    return generatedAnnotation;
}
 
@Override
public boolean test(BodyDeclaration bodyDeclaration) {
    return ((List<IExtendedModifier>) bodyDeclaration.modifiers())
            .stream()
            .filter(modifier -> modifier instanceof SingleMemberAnnotation)
            .map(modifier -> (SingleMemberAnnotation) modifier)
            .filter(modifier -> isGeneratedAnnotation(modifier))
            .filter(modifier -> modifier.getValue() instanceof StringLiteral)
            .filter(annotation -> ((StringLiteral) annotation.getValue()).getLiteralValue().equals(PLUGIN_GENERATED_ANNOTATION_NAME))
            .findFirst()
            .isPresent();
}
 
源代码8 项目: eclipse.jdt.ls   文件: FlowAnalyzer.java
@Override
public void endVisit(SingleMemberAnnotation node) {
	if (skipNode(node)) {
		return;
	}
	assignFlowInfo(node, node.getValue());
}
 
源代码9 项目: xtext-xtend   文件: JavaASTFlattener.java
@Override
public boolean visit(final SingleMemberAnnotation node) {
  this.appendToBuffer("@");
  node.getTypeName().accept(this);
  this.appendToBuffer("(");
  node.getValue().accept(this);
  this.appendToBuffer(")");
  return false;
}
 
源代码10 项目: gwt-eclipse-plugin   文件: JavaASTUtils.java
/**
 * Returns an annotation's value. If the annotation not a single-member
 * annotation, this is the value corresponding to the key named "value".
 */
@SuppressWarnings("unchecked")
public static Expression getAnnotationValue(Annotation annotation) {
  if (annotation instanceof SingleMemberAnnotation) {
    return ((SingleMemberAnnotation) annotation).getValue();
  } else if (annotation instanceof NormalAnnotation) {
    NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;
    for (MemberValuePair pair : (List<MemberValuePair>) normalAnnotation.values()) {
      if (pair.getName().getIdentifier().equals("value")) {
        return pair.getValue();
      }
    }
  }
  return null;
}
 
@Override
public boolean visit(SingleMemberAnnotation node) {
  IAnnotationBinding resolvedAnnotationBinding = node.resolveAnnotationBinding();
  processAnnotationBinding(resolvedAnnotationBinding);
  
  // Don't visit this node's children; they don't impact the result    
  return false;
}
 
源代码12 项目: gwt-eclipse-plugin   文件: ClientBundleResource.java
public MethodDeclaration createMethodDeclaration(IType clientBundle, ASTRewrite astRewrite,
    ImportRewrite importRewrite, boolean addComments) throws CoreException {
  AST ast = astRewrite.getAST();
  MethodDeclaration methodDecl = ast.newMethodDeclaration();

  // Method is named after the resource it accesses
  methodDecl.setName(ast.newSimpleName(getMethodName()));

  // Method return type is a ResourcePrototype subtype
  ITypeBinding resourceTypeBinding = JavaASTUtils.resolveType(clientBundle.getJavaProject(), getReturnTypeName());
  Type resourceType = importRewrite.addImport(resourceTypeBinding, ast);
  methodDecl.setReturnType2(resourceType);

  // Add @Source annotation if necessary
  String sourceAnnotationValue = getSourceAnnotationValue(clientBundle);
  if (sourceAnnotationValue != null) {
    // Build the annotation
    SingleMemberAnnotation sourceAnnotation = ast.newSingleMemberAnnotation();
    sourceAnnotation.setTypeName(ast.newName("Source"));
    StringLiteral annotationValue = ast.newStringLiteral();
    annotationValue.setLiteralValue(sourceAnnotationValue);
    sourceAnnotation.setValue(annotationValue);

    // Add the annotation to the method
    ChildListPropertyDescriptor modifiers = methodDecl.getModifiersProperty();
    ListRewrite modifiersRewriter = astRewrite.getListRewrite(methodDecl, modifiers);
    modifiersRewriter.insertFirst(sourceAnnotation, null);
  }

  return methodDecl;
}
 
源代码13 项目: txtUML   文件: SharedUtils.java
public static Expression obtainSingleMemberAnnotationValue(BodyDeclaration declaration, Class<?> annotationClass) {
	Annotation annotation = obtainAnnotation(declaration, annotationClass);
	if (annotation != null && annotation.isSingleMemberAnnotation()) {
		SingleMemberAnnotation singleMemberAnnot = (SingleMemberAnnotation) annotation;
		return singleMemberAnnot.getValue();
	}
	return null;
}
 
public static void addRemoveUnusedSuppressWarningProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	ASTNode coveringNode= problem.getCoveringNode(context.getASTRoot());
	if (!(coveringNode instanceof StringLiteral))
		return;

	StringLiteral literal= (StringLiteral) coveringNode;

	if (coveringNode.getParent() instanceof MemberValuePair) {
		coveringNode= coveringNode.getParent();
	}

	ASTNode parent= coveringNode.getParent();

	ASTRewrite rewrite= ASTRewrite.create(coveringNode.getAST());
	if (parent instanceof SingleMemberAnnotation) {
		rewrite.remove(parent, null);
	} else if (parent instanceof NormalAnnotation) {
		NormalAnnotation annot= (NormalAnnotation) parent;
		if (annot.values().size() == 1) {
			rewrite.remove(annot, null);
		} else {
			rewrite.remove(coveringNode, null);
		}
	} else if (parent instanceof ArrayInitializer) {
		rewrite.remove(coveringNode, null);
	} else {
		return;
	}
	String label= Messages.format(CorrectionMessages.SuppressWarningsSubProcessor_remove_annotation_label, literal.getLiteralValue());
	Image image= JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE);
	ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REMOVE_ANNOTATION, image);
	proposals.add(proposal);
}
 
源代码15 项目: JDeodorant   文件: StyledStringVisitor.java
public boolean visit(SingleMemberAnnotation annotation) {
	/*
	 * SingleMemberAnnotation: @ TypeName ( Expression  )
	 */
	activateDiffStyle(annotation);
	appendAtSign();
	handleExpression(annotation.getTypeName());
	appendOpenParenthesis();
	handleExpression(annotation.getValue());
	appendClosedParenthesis();
	deactivateDiffStyle(annotation);
	return false;
}
 
源代码16 项目: JDeodorant   文件: StyledStringVisitor.java
private void handleModifier(IExtendedModifier extendedModifier) {
	if(extendedModifier instanceof Modifier) {
		visit((Modifier) extendedModifier);
	}
	else if(extendedModifier instanceof MarkerAnnotation) {
		visit((MarkerAnnotation) extendedModifier);
	}
	else if(extendedModifier instanceof NormalAnnotation) {
		visit((NormalAnnotation) extendedModifier);
	}
	else if(extendedModifier instanceof SingleMemberAnnotation) {
		visit((SingleMemberAnnotation) extendedModifier);
	}
}
 
@Override
public boolean visit(SingleMemberAnnotation node) {
  return visitAnnotation(node);
}
 
public void addGeneratedAnnotation(AST ast, TypeDeclaration builderType) {
    SingleMemberAnnotation generatedAnnotation = createGeneratedAnnotation(ast);
    builderType.modifiers().add(0, generatedAnnotation);
}
 
public void addGeneratedAnnotation(AST ast, MethodDeclaration methodDeclaration) {
    SingleMemberAnnotation generatedAnnotation = createGeneratedAnnotation(ast);
    methodDeclaration.modifiers().add(0, generatedAnnotation);
}
 
private boolean isGeneratedAnnotation(SingleMemberAnnotation modifier) {
    String fqn = modifier.getTypeName().getFullyQualifiedName();
    return fqn.equals("javax.annotation.Generated") || fqn.equals("Generated");
}
 
源代码21 项目: jdt2famix   文件: AstVisitor.java
/**
 * handles: @ TypeName ( Expression ) see comment from
 * {@link #visit(MarkerAnnotation)}
 */
@Override
public boolean visit(SingleMemberAnnotation node) {
	addTypeAnnotationSourceAnchor(node);
	return true;
}
 
@Override
public void endVisit(SingleMemberAnnotation node) {
	if (skipNode(node))
		return;
	assignFlowInfo(node, node.getValue());
}
 
@Override
public boolean visit(SingleMemberAnnotation node) {
	if (node.subtreeMatch(fMatcher, fNodeToMatch))
		return matches(node);
	return super.visit(node);
}
 
@Override
public boolean visit(SingleMemberAnnotation node) {
	return false;
}
 
@Override
public void endVisit(SingleMemberAnnotation node) {
	endVisitNode(node);
}
 
@Override
public boolean visit(SingleMemberAnnotation node) {
	return visitNode(node);
}
 
@Override
public boolean visit(SingleMemberAnnotation node) {
	typeRefFound(node.getTypeName());
	doVisitNode(node.getValue());
	return false;
}
 
public boolean visit(SingleMemberAnnotation node) {
	if (found(node, node) && this.resolveBinding)
		this.foundBinding = node.resolveAnnotationBinding();
	return true;
}
 
 类所在包
 类方法
 同包方法