com.github.javaparser.ast.type.ReferenceType Java Examples
The following examples show how to use
com.github.javaparser.ast.type.ReferenceType.
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: Sources.java From sundrio with Apache License 2.0 | 6 votes |
public TypeRef apply(Type type) { if (type instanceof VoidType) { return new VoidRef(); } else if (type instanceof WildcardType) { return new WildcardRef(); } else if (type instanceof ReferenceType) { ReferenceType referenceType = (ReferenceType) type; int dimensions = referenceType.getArrayCount(); TypeRef typeRef = TYPEREF.apply(referenceType.getType()); if (dimensions == 0) { return typeRef; } else if (typeRef instanceof ClassRef) { return new ClassRefBuilder((ClassRef)typeRef).withDimensions(dimensions).build(); } else if (typeRef instanceof PrimitiveRef) { return new PrimitiveRefBuilder((PrimitiveRef)typeRef).withDimensions(dimensions).build(); } else if (typeRef instanceof TypeParamRef) { return new TypeParamRefBuilder((TypeParamRef)typeRef).withDimensions(dimensions).build(); } } else if (type instanceof PrimitiveType) { PrimitiveType primitiveType = (PrimitiveType) type; return new PrimitiveRefBuilder().withName(primitiveType.getType().name()).build(); } else if (type instanceof ClassOrInterfaceType) { return CLASS_OR_TYPEPARAM_REF.apply((ClassOrInterfaceType) type); } throw new IllegalArgumentException("Can't handle type:[" + type + "]."); }
Example #2
Source File: PrettyPrintVisitor.java From stategen with GNU Affero General Public License v3.0 | 5 votes |
@Override public void visit(final IntersectionType n, final Void arg) { printJavaComment(n.getComment(), arg); printAnnotations(n.getAnnotations(), false, arg); boolean isFirst = true; for (ReferenceType element : n.getElements()) { if (isFirst) { isFirst = false; } else { printer.print(" & "); } element.accept(this, arg); } }
Example #3
Source File: PrettyPrintVisitor.java From stategen with GNU Affero General Public License v3.0 | 5 votes |
@Override public void visit(final UnionType n, final Void arg) { printJavaComment(n.getComment(), arg); printAnnotations(n.getAnnotations(), true, arg); boolean isFirst = true; for (ReferenceType element : n.getElements()) { if (isFirst) { isFirst = false; } else { printer.print(" | "); } element.accept(this, arg); } }
Example #4
Source File: PrettyPrintVisitor.java From stategen with GNU Affero General Public License v3.0 | 5 votes |
@Override public void visit(final ConstructorDeclaration n, final Void arg) { printJavaComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); printTypeParameters(n.getTypeParameters(), arg); if (n.isGeneric()) { printer.print(" "); } n.getName().accept(this, arg); printer.print("("); if (!n.getParameters().isEmpty()) { for (final Iterator<Parameter> i = n.getParameters().iterator(); i.hasNext(); ) { final Parameter p = i.next(); p.accept(this, arg); if (i.hasNext()) { printer.print(", "); } } } printer.print(")"); if (!isNullOrEmpty(n.getThrownExceptions())) { printer.print(" throws "); for (final Iterator<ReferenceType<?>> i = n.getThrownExceptions().iterator(); i.hasNext(); ) { final ReferenceType name = i.next(); name.accept(this, arg); if (i.hasNext()) { printer.print(", "); } } } printer.print(" "); n.getBody().accept(this, arg); }
Example #5
Source File: AppendRoutingVisitor.java From enkan with Eclipse Public License 1.0 | 5 votes |
public void visit(final BlockStmt n, final RoutingDefineContext arg) { if (arg.isInRoutingDefine()) { MethodCallExpr call = new MethodCallExpr( ASTHelper.createNameExpr(arg.getRoutingParameter().getId().getName()), "resource"); ReferenceType rt = ASTHelper.createReferenceType(controllerClassName, 0); ASTHelper.addArgument(call, new ClassExpr(rt.getType())); ASTHelper.addStmt(n, call); } else { super.visit(n, arg); } }
Example #6
Source File: ReferenceTypeMerger.java From dolphin with Apache License 2.0 | 5 votes |
@Override public ReferenceType doMerge(ReferenceType first, ReferenceType second) { ReferenceType rf = new ReferenceType(); rf.setArrayCount(first.getArrayCount()); rf.setType(first.getType()); rf.setAnnotations(mergeCollections(first.getAnnotations(), second.getAnnotations())); List<List<AnnotationExpr>> lists = null; if (first.getArraysAnnotations() == null) lists = second.getArraysAnnotations(); if (second.getArraysAnnotations() == null) lists = first.getArraysAnnotations(); if (lists == null && (first.getArraysAnnotations() != null && second.getArraysAnnotations() != null)) { lists = new ArrayList<>(); List<List<AnnotationExpr>> faas = first.getArraysAnnotations(); List<List<AnnotationExpr>> saas = second.getArraysAnnotations(); int size = faas.size() > saas.size() ? faas.size() : saas.size(); for (int i = 0; i < size; i++) { List<AnnotationExpr> faa = i < faas.size() ? faas.get(i) : null; List<AnnotationExpr> saa = i < saas.size() ? saas.get(i) : null; if (isAllNotNull(faa, saa)) { lists.add(mergeCollections(faa, saa)); } else { lists.add(faa == null ? saa : faa); } } } rf.setArraysAnnotations(lists); return rf; }
Example #7
Source File: AttributeSyncHandler.java From jeddict with Apache License 2.0 | 5 votes |
private void syncThrows(MethodDeclaration method, boolean getterMethod, Map<String, ImportDeclaration> imports) { if (attribute.getSnippets(getterMethod ? GETTER_THROWS : SETTER_THROWS).isEmpty()) { for (ReferenceType thrownException : method.getThrownExceptions()) { String value = thrownException.toString(); AttributeSnippet attributeSnippet = new AttributeSnippet(value, getterMethod ? GETTER_THROWS : SETTER_THROWS); attribute.addRuntimeSnippet(attributeSnippet); addImportSnippet(value, imports); } } }
Example #8
Source File: CodeValidator.java From CodeDefenders with GNU Lesser General Public License v3.0 | 5 votes |
/** * Check if the mutation introduce a change to an instanceof condition * * @param word_changes * @return */ private static boolean containsInstanceOfChanges(CompilationUnit originalCU, CompilationUnit mutatedCU) { final List<ReferenceType> instanceOfInsideOriginal = new ArrayList<>(); final List<ReferenceType> instanceOfInsideMutated = new ArrayList<>(); final AtomicBoolean analyzingMutant = new AtomicBoolean(false); ModifierVisitor<Void> visitor = new ModifierVisitor<Void>() { @Override public Visitable visit(IfStmt n, Void arg) { // Extract elements from the condition if (n.getCondition() instanceof InstanceOfExpr) { InstanceOfExpr expr = (InstanceOfExpr) n.getCondition(); ReferenceType type = expr.getType(); // Accumulate instanceOF if (analyzingMutant.get()) { instanceOfInsideMutated.add(type); } else { instanceOfInsideOriginal.add(type); } } return super.visit(n, arg); } }; visitor.visit(originalCU,null); if( ! instanceOfInsideOriginal.isEmpty() ){ analyzingMutant.set( true ); visitor.visit(mutatedCU, null); } return ! instanceOfInsideMutated.equals( instanceOfInsideOriginal ); }
Example #9
Source File: PrettyPrintVisitor.java From stategen with GNU Affero General Public License v3.0 | 4 votes |
@Override public void visit(final MethodDeclaration n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); printJavaComment(n.getComment(), arg); printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); printTypeParameters(n.getTypeParameters(), arg); if (!isNullOrEmpty(n.getTypeParameters())) { printer.print(" "); } n.getType().accept(this, arg); printer.print(" "); n.getName().accept(this, arg); printer.print("("); if (!isNullOrEmpty(n.getParameters())) { for (final Iterator<Parameter> i = n.getParameters().iterator(); i.hasNext(); ) { final Parameter p = i.next(); p.accept(this, arg); if (i.hasNext()) { printer.print(", "); } } } printer.print(")"); if (!isNullOrEmpty(n.getThrownExceptions())) { printer.print(" throws "); for (final Iterator<ReferenceType<?>> i = n.getThrownExceptions().iterator(); i.hasNext(); ) { final ReferenceType name = i.next(); name.accept(this, arg); if (i.hasNext()) { printer.print(", "); } } } if (!n.getBody().isPresent()) { printer.print(";"); } else { printer.print(" "); n.getBody().get().accept(this, arg); } }
Example #10
Source File: ReferenceTypeMerger.java From dolphin with Apache License 2.0 | 3 votes |
@SuppressWarnings("unchecked") @Override public boolean doIsEquals(ReferenceType first, ReferenceType second) { if (first.getArrayCount() != second.getArrayCount()) return false; if (!isEqualsUseMerger(first.getType(),second.getType())) return false; return true; }