private SingleMemberAnnotation getTypeAnnotationDomainAssumes(ASTRewrite rewrite, TypeDeclaration typeDeclaration, String annotation, String domainName) { ArrayInitializer initializer = rewrite.getAST().newArrayInitializer(); if (domainName != null) { ListRewrite listRewrite = rewrite.getListRewrite(initializer, ArrayInitializer.EXPRESSIONS_PROPERTY); StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral(); newStringLiteral.setLiteralValue(domainName); listRewrite.insertFirst(newStringLiteral, null); declareOtherDomains(rewrite, listRewrite, typeDeclaration); } SingleMemberAnnotation newParamAnnotation = typeDeclaration.getAST().newSingleMemberAnnotation(); newParamAnnotation.setTypeName(rewrite.getAST().newSimpleName(annotation)); newParamAnnotation.setValue(initializer); return newParamAnnotation; }
private SingleMemberAnnotation getTypeAnnotationParams(ASTRewrite rewrite, TypeDeclaration typeDeclaration, String annotation) { ArrayInitializer initializer = rewrite.getAST().newArrayInitializer(); if (!typeDeclaration.resolveBinding().getQualifiedName().equals(Config.MAINCLASS)) { StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral(); newStringLiteral.setLiteralValue("p"); ListRewrite listRewrite = rewrite.getListRewrite(initializer, ArrayInitializer.EXPRESSIONS_PROPERTY); listRewrite.insertFirst(newStringLiteral, null); } SingleMemberAnnotation newParamAnnotation = typeDeclaration.getAST().newSingleMemberAnnotation(); newParamAnnotation.setTypeName(rewrite.getAST().newSimpleName(annotation)); newParamAnnotation.setValue(initializer); return newParamAnnotation; }
@Override public ITypeConstraint[] create(ArrayInitializer arrayInitializer) { ITypeBinding arrayBinding = arrayInitializer.resolveTypeBinding(); Assert.isTrue(arrayBinding.isArray()); List<Expression> expressions = arrayInitializer.expressions(); List<ITypeConstraint> constraints = new ArrayList<ITypeConstraint>(); Type type = getTypeParent(arrayInitializer); ConstraintVariable typeVariable = fConstraintVariableFactory.makeTypeVariable(type); for (int i = 0; i < expressions.size(); i++) { Expression each = expressions.get(i); ITypeConstraint[] c = fTypeConstraintFactory.createSubtypeConstraint( fConstraintVariableFactory.makeExpressionOrTypeVariable(each, getContext()), typeVariable); constraints.addAll(Arrays.asList(c)); } return constraints.toArray(new ITypeConstraint[constraints.size()]); }
private static boolean addSuppressArgument( ASTRewrite rewrite, Expression value, StringLiteral newStringLiteral) { if (value instanceof ArrayInitializer) { ListRewrite listRewrite = rewrite.getListRewrite(value, ArrayInitializer.EXPRESSIONS_PROPERTY); listRewrite.insertLast(newStringLiteral, null); } else if (value instanceof StringLiteral) { ArrayInitializer newArr = rewrite.getAST().newArrayInitializer(); newArr.expressions().add(rewrite.createMoveTarget(value)); newArr.expressions().add(newStringLiteral); rewrite.replace(value, newArr, null); } else { return false; } return true; }
private Expression newDefaultExpression( AST ast, ITypeBinding type, ImportRewriteContext context) { if (type.isPrimitive()) { String name = type.getName(); if ("boolean".equals(name)) { // $NON-NLS-1$ return ast.newBooleanLiteral(false); } else { return ast.newNumberLiteral("0"); // $NON-NLS-1$ } } if (type == ast.resolveWellKnownType("java.lang.String")) { // $NON-NLS-1$ return ast.newStringLiteral(); } if (type.isArray()) { ArrayInitializer initializer = ast.newArrayInitializer(); initializer.expressions().add(newDefaultExpression(ast, type.getElementType(), context)); return initializer; } if (type.isAnnotation()) { MarkerAnnotation annotation = ast.newMarkerAnnotation(); annotation.setTypeName(ast.newName(getImportRewrite().addImport(type, context))); return annotation; } return ast.newNullLiteral(); }
@SuppressWarnings("unchecked") private static boolean containsAnnotationValue(Expression annotationValue, String value) { if (annotationValue.getNodeType() == ASTNode.STRING_LITERAL) { String valueString = ((StringLiteral) annotationValue).getLiteralValue(); return value.equals(valueString); } else if (annotationValue.getNodeType() == ASTNode.ARRAY_INITIALIZER) { // If the annotation value is actually an array, check each element List<Expression> warningTypes = ((ArrayInitializer) annotationValue).expressions(); for (Expression warningType : warningTypes) { if (containsAnnotationValue(warningType, value)) { return true; } } } return false; }
@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()); } } } } }
@SuppressWarnings("unchecked") private void validateSourceAnnotationValues(Annotation annotation) throws JavaModelException { Expression exp = JavaASTUtils.getAnnotationValue(annotation); if (exp == null) { return; } // There will usually just be one string value if (exp instanceof StringLiteral) { validateSourceAnnotationValue((StringLiteral) exp); } // But there could be multiple values; if so, check each one. if (exp instanceof ArrayInitializer) { ArrayInitializer array = (ArrayInitializer) exp; for (Expression item : (List<Expression>) array.expressions()) { if (item instanceof StringLiteral) { validateSourceAnnotationValue((StringLiteral) item); } } } }
private RefactoringStatus checkExpression() throws JavaModelException { Expression selectedExpression= getSelectedExpression().getAssociatedExpression(); if (selectedExpression != null) { final ASTNode parent= selectedExpression.getParent(); if (selectedExpression instanceof NullLiteral) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_null_literals); } else if (selectedExpression instanceof ArrayInitializer) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_array_initializer); } else if (selectedExpression instanceof Assignment) { if (parent instanceof Expression && !(parent instanceof ParenthesizedExpression)) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_assignment); else return null; } else if (selectedExpression instanceof SimpleName) { if ((((SimpleName) selectedExpression)).isDeclaration()) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_names_in_declarations); if (parent instanceof QualifiedName && selectedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY || parent instanceof FieldAccess && selectedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_select_expression); } else if (selectedExpression instanceof VariableDeclarationExpression && parent instanceof TryStatement) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_resource_in_try_with_resources); } } return null; }
@Override public ITypeConstraint[] create(ArrayInitializer arrayInitializer){ ITypeBinding arrayBinding= arrayInitializer.resolveTypeBinding(); Assert.isTrue(arrayBinding.isArray()); List<Expression> expressions= arrayInitializer.expressions(); List<ITypeConstraint> constraints= new ArrayList<ITypeConstraint>(); Type type= getTypeParent(arrayInitializer); ConstraintVariable typeVariable= fConstraintVariableFactory.makeTypeVariable(type); for (int i= 0; i < expressions.size(); i++) { Expression each= expressions.get(i); ITypeConstraint[] c= fTypeConstraintFactory.createSubtypeConstraint( fConstraintVariableFactory.makeExpressionOrTypeVariable(each, getContext()), typeVariable); constraints.addAll(Arrays.asList(c)); } return constraints.toArray(new ITypeConstraint[constraints.size()]); }
@Override protected void complete() throws CoreException { super.complete(); ReturnStatement rStatement= fAst.newReturnStatement(); String formatClass; if (getContext().is50orHigher()) formatClass= "java.lang.String"; //$NON-NLS-1$ else formatClass= "java.text.MessageFormat"; //$NON-NLS-1$ MethodInvocation formatInvocation= createMethodInvocation(addImport(formatClass), "format", null); //$NON-NLS-1$ StringLiteral literal= fAst.newStringLiteral(); literal.setLiteralValue(buffer.toString()); formatInvocation.arguments().add(literal); if (getContext().is50orHigher()) { formatInvocation.arguments().addAll(arguments); } else { ArrayCreation arrayCreation= fAst.newArrayCreation(); arrayCreation.setType(fAst.newArrayType(fAst.newSimpleType(addImport("java.lang.Object")))); //$NON-NLS-1$ ArrayInitializer initializer= fAst.newArrayInitializer(); arrayCreation.setInitializer(initializer); initializer.expressions().addAll(arguments); formatInvocation.arguments().add(arrayCreation); } rStatement.setExpression(formatInvocation); toStringMethod.getBody().statements().add(rStatement); }
private Expression newDefaultExpression(AST ast, ITypeBinding type, ImportRewriteContext context) { if (type.isPrimitive()) { String name= type.getName(); if ("boolean".equals(name)) { //$NON-NLS-1$ return ast.newBooleanLiteral(false); } else { return ast.newNumberLiteral("0"); //$NON-NLS-1$ } } if (type == ast.resolveWellKnownType("java.lang.String")) { //$NON-NLS-1$ return ast.newStringLiteral(); } if (type.isArray()) { ArrayInitializer initializer= ast.newArrayInitializer(); initializer.expressions().add(newDefaultExpression(ast, type.getElementType(), context)); return initializer; } if (type.isAnnotation()) { MarkerAnnotation annotation= ast.newMarkerAnnotation(); annotation.setTypeName(ast.newName(getImportRewrite().addImport(type, context))); return annotation; } return ast.newNullLiteral(); }
@SuppressWarnings("unchecked") private Expression expressionAt(Expression value, int offset) { if (value == null) return null; if (value.getNodeType() == Expression.ARRAY_INITIALIZER) { ArrayInitializer arrayInitializer = (ArrayInitializer)value; for (Expression expression : (List<Expression>)arrayInitializer.expressions()) { if (isInRange(expression, offset)) { return expression; } } } else if (value.getNodeType() == Expression.STRING_LITERAL) { return value; } return null; }
@SuppressWarnings("unchecked") private String stringAt(Expression value, int offset) { if (value == null) return null; if (value.getNodeType() == Expression.ARRAY_INITIALIZER) { ArrayInitializer arrayInitializer = (ArrayInitializer)value; for (Expression expression : (List<Expression>)arrayInitializer.expressions()) { if (isInRange(expression, offset)) { return (String)expression.resolveConstantExpressionValue(); } } } else if (value.getNodeType() == Expression.STRING_LITERAL) { return (String)value.resolveConstantExpressionValue(); } return null; }
private static ITypeBinding getTargetTypeForArrayInitializer(ArrayInitializer arrayInitializer) { ASTNode initializerParent= arrayInitializer.getParent(); while (initializerParent instanceof ArrayInitializer) { initializerParent= initializerParent.getParent(); } if (initializerParent instanceof ArrayCreation) { return ((ArrayCreation) initializerParent).getType().getElementType().resolveBinding(); } else if (initializerParent instanceof VariableDeclaration) { ITypeBinding typeBinding= ((VariableDeclaration) initializerParent).getName().resolveTypeBinding(); if (typeBinding != null) { return typeBinding.getElementType(); } } return null; }
@Override public void endVisit(ArrayInitializer node) { if (skipNode(node)) { return; } processSequential(node, node.expressions()); }
@Override protected final void checkSelectedNodes() { super.checkSelectedNodes(); RefactoringStatus status = getStatus(); if (status.hasFatalError()) { return; } ASTNode node = getFirstSelectedNode(); if (node instanceof ArrayInitializer) { status.addFatalError(RefactoringCoreMessages.CodeAnalyzer_array_initializer, JavaStatusContext.create(fCUnit, node)); } }
public List<String> getAnnotationList(List<IExtendedModifier> paramModifiers, String annotation) { List<String> found = new ArrayList<String>(); for (IExtendedModifier o:paramModifiers){ if (o instanceof SingleMemberAnnotation) { SingleMemberAnnotation annot = (SingleMemberAnnotation) o; if (annot.getTypeName().toString().equals(annotation)) { Expression value = annot.getValue(); if (value instanceof ArrayInitializer) { //@Domains( {"D", "U"}) ArrayInitializer annotValueArray = (ArrayInitializer)value; found = new ArrayList<String>(); for (Object s:annotValueArray.expressions()){ if (s instanceof StringLiteral) { StringLiteral sLiteral = (StringLiteral)s; found.add(sLiteral.getLiteralValue()); } } return found; } if (value instanceof StringLiteral) { //@Domains ("D") StringLiteral annotValue = (StringLiteral)value; String parserInput = annotValue.getLiteralValue(); found = new ArrayList<String>(); found.add(parserInput); return found; } } } } return found; }
private SingleMemberAnnotation getTypeAnnotationDomain(ASTRewrite rewrite, TypeDeclaration typeDeclaration, String annotation, String domainName) { ArrayInitializer initializer = rewrite.getAST().newArrayInitializer(); if (domainName != null) { ListRewrite listRewrite = rewrite.getListRewrite(initializer, ArrayInitializer.EXPRESSIONS_PROPERTY); StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral(); newStringLiteral.setLiteralValue(domainName); listRewrite.insertFirst(newStringLiteral, null); // XXX. HACK: Add hard-coded public domain, PD StringLiteral newStringLiteralPD = rewrite.getAST().newStringLiteral(); newStringLiteralPD.setLiteralValue("PD"); listRewrite.insertLast(newStringLiteralPD, null); // Add other domains that are created using other refinements declareOtherDomains(rewrite, listRewrite, typeDeclaration); // XXX. HACK: Add another hard-coded domain, PARAM. NO. // StringLiteral newStringLiteralPARAM = rewrite.getAST().newStringLiteral(); // newStringLiteralPARAM.setLiteralValue("PARAM"); // listRewrite.insertLast(newStringLiteralPARAM, null); } SingleMemberAnnotation newParamAnnotation = typeDeclaration.getAST().newSingleMemberAnnotation(); newParamAnnotation.setTypeName(rewrite.getAST().newSimpleName(annotation)); newParamAnnotation.setValue(initializer); return newParamAnnotation; }
private SingleMemberAnnotation getTypeAnnotationInherits(ASTRewrite rewrite, TypeDeclaration typeDeclaration, String annotation, String domainName) { boolean display = false; ArrayInitializer initializer = rewrite.getAST().newArrayInitializer(); ListRewrite listRewrite = rewrite.getListRewrite(initializer, ArrayInitializer.EXPRESSIONS_PROPERTY); List localSuperClasses = getAllSuperTypes(typeDeclaration); if (!localSuperClasses.isEmpty()) { int i = 0; for (Iterator iterSuperClass = localSuperClasses.iterator(); iterSuperClass.hasNext();) { Type tt = (Type) iterSuperClass.next(); if (tt != null) { StringBuilder builder = new StringBuilder(); // Use simple name rather than fully qualified type name. Typechecker does not expect qualified name. builder.append(Signature.getSimpleName(tt.toString())); builder.append("<"); builder.append(domainName); builder.append(">"); StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral(); newStringLiteral.setLiteralValue(builder.toString()); listRewrite.insertAt(newStringLiteral, i, null); i++; display = true; } } } SingleMemberAnnotation newParamAnnotation = typeDeclaration.getAST().newSingleMemberAnnotation(); newParamAnnotation.setTypeName(rewrite.getAST().newSimpleName(annotation)); newParamAnnotation.setValue(initializer); if (display) { return newParamAnnotation; } return null; }
private Expression getTempInitializerCopy(ASTRewrite rewrite) { final Expression initializer = (Expression) rewrite.createCopyTarget(getTempInitializer()); if (initializer instanceof ArrayInitializer && ASTNodes.getDimensions(fTempDeclarationNode) > 0) { ArrayCreation arrayCreation = rewrite.getAST().newArrayCreation(); arrayCreation.setType( (ArrayType) ASTNodeFactory.newType(rewrite.getAST(), fTempDeclarationNode)); arrayCreation.setInitializer((ArrayInitializer) initializer); return arrayCreation; } return initializer; }
private RefactoringStatus checkExpression() throws JavaModelException { Expression selectedExpression = getSelectedExpression().getAssociatedExpression(); if (selectedExpression != null) { final ASTNode parent = selectedExpression.getParent(); if (selectedExpression instanceof NullLiteral) { return RefactoringStatus.createFatalErrorStatus( RefactoringCoreMessages.ExtractTempRefactoring_null_literals); } else if (selectedExpression instanceof ArrayInitializer) { return RefactoringStatus.createFatalErrorStatus( RefactoringCoreMessages.ExtractTempRefactoring_array_initializer); } else if (selectedExpression instanceof Assignment) { if (parent instanceof Expression && !(parent instanceof ParenthesizedExpression)) return RefactoringStatus.createFatalErrorStatus( RefactoringCoreMessages.ExtractTempRefactoring_assignment); else return null; } else if (selectedExpression instanceof SimpleName) { if ((((SimpleName) selectedExpression)).isDeclaration()) return RefactoringStatus.createFatalErrorStatus( RefactoringCoreMessages.ExtractTempRefactoring_names_in_declarations); if (parent instanceof QualifiedName && selectedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY || parent instanceof FieldAccess && selectedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY) return RefactoringStatus.createFatalErrorStatus( RefactoringCoreMessages.ExtractTempRefactoring_select_expression); } else if (selectedExpression instanceof VariableDeclarationExpression && parent instanceof TryStatement) { return RefactoringStatus.createFatalErrorStatus( RefactoringCoreMessages.ExtractTempRefactoring_resource_in_try_with_resources); } } return null; }
@Override protected final void checkSelectedNodes() { super.checkSelectedNodes(); RefactoringStatus status = getStatus(); if (status.hasFatalError()) return; ASTNode node = getFirstSelectedNode(); if (node instanceof ArrayInitializer) { status.addFatalError( RefactoringCoreMessages.CodeAnalyzer_array_initializer, JavaStatusContext.create(fCUnit, node)); } }
@Override public final void endVisit(final ArrayCreation node) { final ConstraintVariable2 ancestor= (ConstraintVariable2) node.getType().getProperty(PROPERTY_CONSTRAINT_VARIABLE); node.setProperty(PROPERTY_CONSTRAINT_VARIABLE, ancestor); final ArrayInitializer initializer= node.getInitializer(); if (initializer != null) { final ConstraintVariable2 descendant= (ConstraintVariable2) initializer.getProperty(PROPERTY_CONSTRAINT_VARIABLE); if (descendant != null) fModel.createSubtypeConstraint(descendant, ancestor); } }
private Expression getTempInitializerCopy(ASTRewrite rewrite) { final Expression initializer= (Expression) rewrite.createCopyTarget(getTempInitializer()); if (initializer instanceof ArrayInitializer && ASTNodes.getDimensions(fTempDeclarationNode) > 0) { ArrayCreation arrayCreation= rewrite.getAST().newArrayCreation(); arrayCreation.setType((ArrayType) ASTNodeFactory.newType(rewrite.getAST(), fTempDeclarationNode)); arrayCreation.setInitializer((ArrayInitializer) initializer); return arrayCreation; } return initializer; }
private RefactoringStatus checkExpression() { //TODO: adjust error messages (or generalize for all refactorings on expression-selections?) Expression selectedExpression= fSelectedExpression; if (selectedExpression instanceof Name && selectedExpression.getParent() instanceof ClassInstanceCreation) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_name_in_new); //TODO: let's just take the CIC automatically (no ambiguity -> no problem -> no dialog ;-) if (selectedExpression instanceof NullLiteral) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_null_literals); } else if (selectedExpression instanceof ArrayInitializer) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_array_initializer); } else if (selectedExpression instanceof Assignment) { if (selectedExpression.getParent() instanceof Expression) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_assignment); else return null; } else if (selectedExpression instanceof SimpleName){ if ((((SimpleName)selectedExpression)).isDeclaration()) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_names_in_declarations); if (selectedExpression.getParent() instanceof QualifiedName && selectedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY || selectedExpression.getParent() instanceof FieldAccess && selectedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_select_expression); } return null; }
@Override protected final void checkSelectedNodes() { super.checkSelectedNodes(); RefactoringStatus status= getStatus(); if (status.hasFatalError()) return; ASTNode node= getFirstSelectedNode(); if (node instanceof ArrayInitializer) { status.addFatalError(RefactoringCoreMessages.CodeAnalyzer_array_initializer, JavaStatusContext.create(fCUnit, node)); } }
private static boolean addSuppressArgument(ASTRewrite rewrite, Expression value, StringLiteral newStringLiteral) { if (value instanceof ArrayInitializer) { ListRewrite listRewrite= rewrite.getListRewrite(value, ArrayInitializer.EXPRESSIONS_PROPERTY); listRewrite.insertLast(newStringLiteral, null); } else if (value instanceof StringLiteral) { ArrayInitializer newArr= rewrite.getAST().newArrayInitializer(); newArr.expressions().add(rewrite.createMoveTarget(value)); newArr.expressions().add(newStringLiteral); rewrite.replace(value, newArr, null); } else { return false; } return true; }
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); }
@SuppressWarnings("unchecked") private void parseAnnotation(Annotation anno) { String name = anno.getTypeName().getFullyQualifiedName(); if ("ResultMap".equals(name)) { createHyperlink("resultMap", expressionAt(annotationValueAt(anno, "value", offset), offset)); } else if ("Results".equals(name)) { Expression expr = annotationValueAt(anno, "value", offset); if (expr == null) return; List<Expression> resultAnnos; if (expr.getNodeType() == Expression.ARRAY_INITIALIZER) { resultAnnos = ((ArrayInitializer)expr).expressions(); } else { resultAnnos = Arrays.asList((Expression)expr); } for (Expression resultAnno : resultAnnos) { if (isInRange(resultAnno, offset)) { createHyperlink("select", expressionAt( annotationValueAt((Annotation)annotationValueAt((Annotation)resultAnno, Arrays.asList("one", "many"), offset), "select", offset), offset)); break; } } } }
private String parseStringValue(Expression value, String separator) { int valueType = value.getNodeType(); if (valueType == ASTNode.STRING_LITERAL) { return ((StringLiteral)value).getLiteralValue(); } else if (valueType == ASTNode.ARRAY_INITIALIZER) { StringBuilder buffer = new StringBuilder(); @SuppressWarnings("unchecked") List<Expression> expressions = (List<Expression>)((ArrayInitializer)value) .expressions(); for (Expression expression : expressions) { int expressionType = expression.getNodeType(); if (expressionType == ASTNode.STRING_LITERAL) { if (buffer.length() > 0) buffer.append(separator); buffer.append(((StringLiteral)expression).getLiteralValue()); } else if (expressionType == ASTNode.INFIX_EXPRESSION) { buffer.append(parseInfixExpression((InfixExpression)expression)); } } return buffer.toString(); } else if (valueType == ASTNode.INFIX_EXPRESSION) { return parseInfixExpression((InfixExpression)value); } Activator.log(Status.ERROR, "Unsupported node type " + valueType); return null; }