blob: 0f66a80c2d0bb41e8adb542079e2bce5e3ac620d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/*******************************************************************************
* Copyright (c) 2009 Shane Clarke.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Shane Clarke - initial API and implementation
*******************************************************************************/
package org.eclipse.jst.ws.internal.jaxws.core.annotations.validation;
import java.util.Collection;
import javax.jws.WebService;
import org.eclipse.jst.ws.annotations.core.processor.AbstractAnnotationProcessor;
import org.eclipse.jst.ws.internal.jaxws.core.JAXWSCoreMessages;
import com.sun.mirror.declaration.AnnotationMirror;
import com.sun.mirror.declaration.AnnotationTypeDeclaration;
import com.sun.mirror.declaration.ClassDeclaration;
import com.sun.mirror.declaration.ConstructorDeclaration;
import com.sun.mirror.declaration.Declaration;
import com.sun.mirror.declaration.EnumDeclaration;
import com.sun.mirror.declaration.Modifier;
public class WebServiceDefaultPublicConstructorRule extends AbstractAnnotationProcessor {
@Override
public void process() {
AnnotationTypeDeclaration annotationDeclaration = (AnnotationTypeDeclaration) environment
.getTypeDeclaration(WebService.class.getName());
Collection<Declaration> annotatedTypes = environment
.getDeclarationsAnnotatedWith(annotationDeclaration);
for (Declaration declaration : annotatedTypes) {
if (declaration instanceof ClassDeclaration && !(declaration instanceof EnumDeclaration)) {
boolean hasDefaultConstructor = false;
ClassDeclaration classDeclaration = (ClassDeclaration) declaration;
Collection<ConstructorDeclaration> constructors = classDeclaration.getConstructors();
if (constructors.size() == 0) {
hasDefaultConstructor = true;
} else {
for (ConstructorDeclaration constructorDeclaration : constructors) {
if (constructorDeclaration.getModifiers().contains(Modifier.PUBLIC) &&
constructorDeclaration.getParameters().size() == 0) {
hasDefaultConstructor = true;
break;
}
}
}
if (!hasDefaultConstructor) {
Collection<AnnotationMirror> annotationMirrors = declaration.getAnnotationMirrors();
for (AnnotationMirror mirror : annotationMirrors) {
if ( mirror.getAnnotationType().toString().equals(annotationDeclaration
.getQualifiedName())) {
printFixableError(declaration.getPosition(),
JAXWSCoreMessages.WEBSERVICE_DEFAULT_PUBLIC_CONSTRUCTOR);
}
}
}
}
}
}
}
|