本文整理汇总了Java中org.eclipse.jdt.core.dom.NormalAnnotation类的典型用法代码示例。如果您正苦于以下问题:Java NormalAnnotation类的具体用法?Java NormalAnnotation怎么用?Java NormalAnnotation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NormalAnnotation类属于org.eclipse.jdt.core.dom包,在下文中一共展示了NormalAnnotation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getGraphWalkerClassAnnotation
import org.eclipse.jdt.core.dom.NormalAnnotation; //导入依赖的package包/类
/**
* @return
*/
public NormalAnnotation getGraphWalkerClassAnnotation() {
String source = getSource ();
if(source==null) return null;
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setSource(source.toCharArray());
parser.setKind(ASTParser.K_COMPILATION_UNIT);
final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
cu.accept(new ASTVisitor() {
public boolean visit(NormalAnnotation node) {
annotation = node;
return true;
}
});
if (this.generateAnnotation) return annotation;
return null;
}
示例2: getGeneratedClassAnnotation
import org.eclipse.jdt.core.dom.NormalAnnotation; //导入依赖的package包/类
public NormalAnnotation getGeneratedClassAnnotation() {
String source = getGeneratedAnnotationSource ();
if(source==null) return null;
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setSource(source.toCharArray());
parser.setKind(ASTParser.K_COMPILATION_UNIT);
final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
cu.accept(new ASTVisitor() {
public boolean visit(NormalAnnotation node) {
annotation = node;
return true;
}
});
return annotation;
}
示例3: findPathGeneratorInGraphWalkerAnnotation
import org.eclipse.jdt.core.dom.NormalAnnotation; //导入依赖的package包/类
/**
* @param cu
* @return
*/
public static String findPathGeneratorInGraphWalkerAnnotation(ICompilationUnit cu) {
CompilationUnit ast = parse(cu);
Map<String, String> ret = new HashMap<String, String>();
ast.accept(new ASTVisitor() {
public boolean visit(MemberValuePair node) {
String name = node.getName().getFullyQualifiedName();
if ("value".equals(name) && node.getParent() != null && node.getParent() instanceof NormalAnnotation) {
IAnnotationBinding annoBinding = ((NormalAnnotation) node.getParent()).resolveAnnotationBinding();
String qname = annoBinding.getAnnotationType().getQualifiedName();
if (GraphWalker.class.getName().equals(qname)) {
StringLiteral sl = (StringLiteral) node.getValue();
ret.put("ret", sl.getLiteralValue());
}
}
return true;
}
});
return ret.get("ret");
}
示例4: findExistingAnnotation
import org.eclipse.jdt.core.dom.NormalAnnotation; //导入依赖的package包/类
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;
}
示例5: getRewrite
import org.eclipse.jdt.core.dom.NormalAnnotation; //导入依赖的package包/类
@Override
protected ASTRewrite getRewrite() throws CoreException {
AST ast = fAnnotation.getAST();
ASTRewrite rewrite = ASTRewrite.create(ast);
createImportRewrite((CompilationUnit) fAnnotation.getRoot());
ListRewrite listRewrite;
if (fAnnotation instanceof NormalAnnotation) {
listRewrite = rewrite.getListRewrite(fAnnotation, NormalAnnotation.VALUES_PROPERTY);
} else {
NormalAnnotation newAnnotation = ast.newNormalAnnotation();
newAnnotation.setTypeName((Name) rewrite.createMoveTarget(fAnnotation.getTypeName()));
rewrite.replace(fAnnotation, newAnnotation, null);
listRewrite = rewrite.getListRewrite(newAnnotation, NormalAnnotation.VALUES_PROPERTY);
}
addMissingAtributes(fAnnotation.resolveTypeBinding(), listRewrite);
return rewrite;
}
示例6: findExistingAnnotation
import org.eclipse.jdt.core.dom.NormalAnnotation; //导入依赖的package包/类
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;
}
示例7: getRewrite
import org.eclipse.jdt.core.dom.NormalAnnotation; //导入依赖的package包/类
@Override
protected ASTRewrite getRewrite() throws CoreException {
AST ast= fAnnotation.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
createImportRewrite((CompilationUnit) fAnnotation.getRoot());
ListRewrite listRewrite;
if (fAnnotation instanceof NormalAnnotation) {
listRewrite= rewrite.getListRewrite(fAnnotation, NormalAnnotation.VALUES_PROPERTY);
} else {
NormalAnnotation newAnnotation= ast.newNormalAnnotation();
newAnnotation.setTypeName((Name) rewrite.createMoveTarget(fAnnotation.getTypeName()));
rewrite.replace(fAnnotation, newAnnotation, null);
listRewrite= rewrite.getListRewrite(newAnnotation, NormalAnnotation.VALUES_PROPERTY);
}
addMissingAtributes(fAnnotation.resolveTypeBinding(), listRewrite);
return rewrite;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:MissingAnnotationAttributesProposal.java
示例8: annotations
import org.eclipse.jdt.core.dom.NormalAnnotation; //导入依赖的package包/类
/**
* Returns the annotations for a given <code>modifierList</code>.
*
* @param modifierList the modifier list to be processed
* @return An ArraySet with all annotations
*/
@OperationMeta(returnGenerics = JavaAnnotation.class)
public Set<JavaAnnotation> annotations(List<IExtendedModifier> modifierList) {
List<JavaAnnotation> list = new ArrayList<JavaAnnotation>();
for (Object modifier : modifierList) {
if (modifier instanceof org.eclipse.jdt.core.dom.Annotation) {
org.eclipse.jdt.core.dom.Annotation annot = (org.eclipse.jdt.core.dom.Annotation) modifier;
// Get annotation name and value
Map<String, String> fields = new HashMap<String, String>();
// possibly the unqualified name as not resolved unless not given as qualified name!
String name = annot.getTypeName().getFullyQualifiedName();
if (annot instanceof SingleMemberAnnotation) {
fields.put(JavaAnnotation.DEFAULT_FIELD,
toString(((SingleMemberAnnotation) modifier).getValue()));
} else if (annot instanceof NormalAnnotation) {
@SuppressWarnings("unchecked")
List<MemberValuePair> values = ((NormalAnnotation) annot).values();
for (MemberValuePair pair : values) {
fields.put(pair.getName().getIdentifier(), toString(pair.getValue()));
}
}
list.add(new JavaAnnotation(name, fields, this));
}
}
return new ArraySet<JavaAnnotation>(list.toArray(new JavaAnnotation[list.size()]), JavaAnnotation.class);
}
示例9: writeSuppressWarning
import org.eclipse.jdt.core.dom.NormalAnnotation; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void writeSuppressWarning(BodyDeclaration target) {
AST ast = target.getAST();
NormalAnnotation annotation = ast.newNormalAnnotation();
annotation.setTypeName(ast.newSimpleName(SuppressWarnings.class.getSimpleName()));
MemberValuePair memberValuePair = ast.newMemberValuePair();
memberValuePair.setName(ast.newSimpleName("value"));
StringLiteral stringLiteral = ast.newStringLiteral();
stringLiteral.setLiteralValue("static-access");
memberValuePair.setValue(stringLiteral);
annotation.values().add(memberValuePair);
target.modifiers().add(annotation);
}
示例10: writeEnumField
import org.eclipse.jdt.core.dom.NormalAnnotation; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void writeEnumField(EnumConstantDeclaration enumField, QSpecialElement elem) {
AST ast = enumField.getAST();
NormalAnnotation normalAnnotation = ast.newNormalAnnotation();
String name = new String("*" + enumField.getName());
if (elem.getValue() != null && !name.equals(elem.getValue())) {
normalAnnotation.setTypeName(ast.newSimpleName(Special.class.getSimpleName()));
MemberValuePair memberValuePair = ast.newMemberValuePair();
memberValuePair.setName(ast.newSimpleName("value"));
StringLiteral stringLiteral = ast.newStringLiteral();
stringLiteral.setLiteralValue(elem.getValue());
memberValuePair.setValue(stringLiteral);
normalAnnotation.values().add(memberValuePair);
enumField.modifiers().add(normalAnnotation);
}
}
示例11: checkAnnotationContent
import org.eclipse.jdt.core.dom.NormalAnnotation; //导入依赖的package包/类
/**
* Return true if the annotation content matches the input map (@Foo(f1 = v1
* , f2 = v2)
*
* @param annotation
* input annotation to check
* @param content
* a Map object containing as key the expected member name and as
* value the expected member value
* @return true if the annotation is a normal annotation and if the content
* matches the content parameter, false otherwise
*/
@SuppressWarnings("unchecked")
public static boolean checkAnnotationContent(Annotation annotation, Map<String, Object> content) {
boolean correct = false;
// Test if this annotation is a Normal Member Annotation
if (annotation != null && annotation.isNormalAnnotation()) {
List<MemberValuePair> values = ((NormalAnnotation) annotation).values();
correct = true;
for (int inc = 0; inc < values.size() && correct; inc++) {
MemberValuePair mvp = values.get(inc);
String memberName = mvp.getName().getFullyQualifiedName();
Object contentValue = content.get(memberName);
correct = contentValue != null;
Expression memberValue = mvp.getValue();
correct = checkSingleAnnotationValue(memberValue, contentValue);
}
}
return correct;
}
示例12: setGeneratedAnnotationPart
import org.eclipse.jdt.core.dom.NormalAnnotation; //导入依赖的package包/类
private static boolean setGeneratedAnnotationPart(CompilationUnit cu, NormalAnnotation annotation, String newPartValue, int rankInComment) {
StringLiteral oldCommentLiteral = getGeneratedAnnotationComment(annotation);
if (oldCommentLiteral != null) {
String[] oldCommentParts = oldCommentLiteral.getLiteralValue().split(COMMENT_SEPARATOR);
StringBuilder newCommentSB = new StringBuilder(25).append("");
for(int i = 0; i<oldCommentParts.length; i++) {
if(i == rankInComment) {
newCommentSB.append(newPartValue);
}
else {
newCommentSB.append(oldCommentParts[i]);
}
if(i<(oldCommentParts.length-1)) {
newCommentSB.append(COMMENT_SEPARATOR);
}
}
oldCommentLiteral.setLiteralValue(newCommentSB.toString());
return true;
}
return false;
}
示例13: getGeneratedAnnotationComment
import org.eclipse.jdt.core.dom.NormalAnnotation; //导入依赖的package包/类
private static StringLiteral getGeneratedAnnotationComment(NormalAnnotation annotation) {
MemberValuePair mvp = null;
for (Object o : annotation.values()) {
if (o instanceof MemberValuePair) {
MemberValuePair tempMVP = (MemberValuePair) o;
if (COMMENTS_PARAM.equals(tempMVP.getName().toString())) {
mvp = tempMVP;
break;
}
}
}
if (mvp != null && mvp.getValue() != null && mvp.getValue() instanceof StringLiteral) {
StringLiteral literal = (StringLiteral) mvp.getValue();
return literal;
}
else{
return null;
}
}
示例14: getHashCodeFromGeneratedAnnotation
import org.eclipse.jdt.core.dom.NormalAnnotation; //导入依赖的package包/类
/**
* Return the hashCode of a Body Declaration (from @Generated annotation)
*/
public static int getHashCodeFromGeneratedAnnotation(BodyDeclaration bodyDeclaration) {
Annotation generatedAnnotation = ASTHelper.getAnnotation(JavaCodeHelper.GENERATED_SIMPLECLASSNAME, bodyDeclaration);
if (generatedAnnotation == null) {
// @Generated not found, the BodyDeclaration must not be merged
throw new UnsupportedOperationException();
}
if (generatedAnnotation.isNormalAnnotation()) {
String stringHashcode = GeneratedAnnotationHelper.getGeneratedAnnotationHashcode((NormalAnnotation) generatedAnnotation);
if(stringHashcode != null) {
try {
return Integer.parseInt(stringHashcode);
}
catch (NumberFormatException e) {
Activator.getDefault().logError("Hashcode can't be parsed to int in: \n" + bodyDeclaration.toString(), e);
return -1;
}
}
}
// If the hashCode cannot be found, throw an IllegalArgumentException
throw new IllegalArgumentException();
}
示例15: addThrownSupport
import org.eclipse.jdt.core.dom.NormalAnnotation; //导入依赖的package包/类
private void addThrownSupport(MethodDeclaration methodDeclaration) {
Optional<Annotation> testAnnotation = annotatedWith(methodDeclaration, "Test");
Optional<Expression> expected = testAnnotation
.filter(annotation -> annotation instanceof NormalAnnotation)
.flatMap(this::expectedException);
expected.ifPresent(expression -> body()
.add(astNodeFactory().methodInvocation(THROWN,
singletonList(astNodeFactory().simpleName(((TypeLiteral) expression).getType().toString())))));
}