org.eclipse.jdt.core.dom.SingleMemberAnnotation Java Examples

The following examples show how to use org.eclipse.jdt.core.dom.SingleMemberAnnotation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SuppressWarningsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: PlantUmlPreCompiler.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
@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;
}
 
Example #3
Source File: UMLAnnotation.java    From RefactoringMiner with MIT License 6 votes vote down vote up
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);
		}
	}
}
 
Example #4
Source File: ASTFlattenerUtils.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
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));
  })));
}
 
Example #5
Source File: UiBinderJavaValidator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@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());
        }
      }
    }
  }
}
 
Example #6
Source File: SharedUtils.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example #7
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
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);
	}
}
 
Example #8
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
public boolean visit(SingleMemberAnnotation annotation) {
	/*
	 * SingleMemberAnnotation: @ TypeName ( Expression  )
	 */
	activateDiffStyle(annotation);
	appendAtSign();
	handleExpression(annotation.getTypeName());
	appendOpenParenthesis();
	handleExpression(annotation.getValue());
	appendClosedParenthesis();
	deactivateDiffStyle(annotation);
	return false;
}
 
Example #9
Source File: SuppressWarningsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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);
}
 
Example #10
Source File: ClientBundleResource.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example #11
Source File: ValidationSuppressionVisitor.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@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;
}
 
Example #12
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final SingleMemberAnnotation node) {
  this.appendToBuffer("@");
  node.getTypeName().accept(this);
  this.appendToBuffer("(");
  node.getValue().accept(this);
  this.appendToBuffer(")");
  return false;
}
 
Example #13
Source File: FlowAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void endVisit(SingleMemberAnnotation node) {
	if (skipNode(node)) {
		return;
	}
	assignFlowInfo(node, node.getValue());
}
 
Example #14
Source File: JavaASTUtils.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #15
Source File: GeneratedAnnotationPopulator.java    From SparkBuilderGenerator with MIT License 5 votes vote down vote up
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;
}
 
Example #16
Source File: GeneratedAnnotationPredicate.java    From SparkBuilderGenerator with MIT License 5 votes vote down vote up
@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();
}
 
Example #17
Source File: GeneratedAnnotationPopulator.java    From SparkBuilderGenerator with MIT License 4 votes vote down vote up
public void addGeneratedAnnotation(AST ast, TypeDeclaration builderType) {
    SingleMemberAnnotation generatedAnnotation = createGeneratedAnnotation(ast);
    builderType.modifiers().add(0, generatedAnnotation);
}
 
Example #18
Source File: GeneratedAnnotationPopulator.java    From SparkBuilderGenerator with MIT License 4 votes vote down vote up
public void addGeneratedAnnotation(AST ast, MethodDeclaration methodDeclaration) {
    SingleMemberAnnotation generatedAnnotation = createGeneratedAnnotation(ast);
    methodDeclaration.modifiers().add(0, generatedAnnotation);
}
 
Example #19
Source File: DOMFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public boolean visit(SingleMemberAnnotation node) {
	if (found(node, node) && this.resolveBinding)
		this.foundBinding = node.resolveAnnotationBinding();
	return true;
}
 
Example #20
Source File: ImportReferencesCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(SingleMemberAnnotation node) {
	typeRefFound(node.getTypeName());
	doVisitNode(node.getValue());
	return false;
}
 
Example #21
Source File: GenericVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(SingleMemberAnnotation node) {
	return visitNode(node);
}
 
Example #22
Source File: GenericVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void endVisit(SingleMemberAnnotation node) {
	endVisitNode(node);
}
 
Example #23
Source File: ConstraintCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(SingleMemberAnnotation node) {
	return false;
}
 
Example #24
Source File: AstMatchingNodeFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(SingleMemberAnnotation node) {
	if (node.subtreeMatch(fMatcher, fNodeToMatch))
		return matches(node);
	return super.visit(node);
}
 
Example #25
Source File: FlowAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void endVisit(SingleMemberAnnotation node) {
	if (skipNode(node))
		return;
	assignFlowInfo(node, node.getValue());
}
 
Example #26
Source File: AstVisitor.java    From jdt2famix with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * handles: @ TypeName ( Expression ) see comment from
 * {@link #visit(MarkerAnnotation)}
 */
@Override
public boolean visit(SingleMemberAnnotation node) {
	addTypeAnnotationSourceAnchor(node);
	return true;
}
 
Example #27
Source File: GeneratedAnnotationPredicate.java    From SparkBuilderGenerator with MIT License 4 votes vote down vote up
private boolean isGeneratedAnnotation(SingleMemberAnnotation modifier) {
    String fqn = modifier.getTypeName().getFullyQualifiedName();
    return fqn.equals("javax.annotation.Generated") || fqn.equals("Generated");
}
 
Example #28
Source File: ReferencedClassesParser.java    From BUILD_file_generator with Apache License 2.0 4 votes vote down vote up
@Override
public boolean visit(SingleMemberAnnotation node) {
  return visitAnnotation(node);
}