本文整理汇总了Java中org.eclipse.gmt.modisco.java.BodyDeclaration类的典型用法代码示例。如果您正苦于以下问题:Java BodyDeclaration类的具体用法?Java BodyDeclaration怎么用?Java BodyDeclaration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BodyDeclaration类属于org.eclipse.gmt.modisco.java包,在下文中一共展示了BodyDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getProtectedMethodDeclarations
import org.eclipse.gmt.modisco.java.BodyDeclaration; //导入依赖的package包/类
private static EList<MethodDeclaration> getProtectedMethodDeclarations(Resource resource) {
EList<MethodDeclaration> methodDeclarations = new BasicEList<>();
List<? extends EObject> allClasses = getAllInstances(resource, JavaPackage.eINSTANCE.getClassDeclaration());
for (EObject cls : allClasses) {
for (BodyDeclaration method : ((ClassDeclaration) cls).getBodyDeclarations()) {
if (!(method instanceof MethodDeclaration)) {
continue;
}
if (method.getModifier() == null) {
continue;
}
if (method.getModifier().getVisibility() == VisibilityKind.PROTECTED) {
methodDeclarations.add((MethodDeclaration) method);
}
}
}
return methodDeclarations;
}
示例2: queryGrabats
import org.eclipse.gmt.modisco.java.BodyDeclaration; //导入依赖的package包/类
public static Query<Integer> queryGrabats(Resource resource) {
return () -> {
List<ClassDeclaration> listResult = new BasicEList<>();
Iterable<TypeDeclaration> typeDeclarations = getAllInstances(resource, JavaPackage.eINSTANCE.getTypeDeclaration());
for (TypeDeclaration type : typeDeclarations) {
for (BodyDeclaration body : type.getBodyDeclarations()) {
if ((body instanceof MethodDeclaration)) {
MethodDeclaration method = (MethodDeclaration) body;
if (nonNull(method.getModifier()) && method.getModifier().isStatic() && nonNull(method.getReturnType()) && method.getReturnType().getType() == type) {
listResult.add((ClassDeclaration) type);
}
}
}
}
return listResult.size();
};
}
示例3: queryGrabats
import org.eclipse.gmt.modisco.java.BodyDeclaration; //导入依赖的package包/类
public static Query<Integer> queryGrabats(Resource resource) {
return () -> {
List<ClassDeclaration> listResult = new BasicEList<>();
Iterable<TypeDeclaration> typeDeclarations = getAllInstances(resource, JavaPackage.eINSTANCE.getTypeDeclaration());
for (TypeDeclaration owner : typeDeclarations) {
for (BodyDeclaration method : owner.getBodyDeclarations()) {
if (method instanceof MethodDeclaration) {
MethodDeclaration methDecl = (MethodDeclaration) method;
if (nonNull(methDecl.getModifier()) && methDecl.getModifier().isStatic() && methDecl.getReturnType() == owner) {
listResult.add((ClassDeclaration) owner);
}
}
}
}
return listResult.size();
};
}
示例4: queryInvisibleMethodDeclarations
import org.eclipse.gmt.modisco.java.BodyDeclaration; //导入依赖的package包/类
public static Query<Integer> queryInvisibleMethodDeclarations(Resource resource) {
return () -> {
List<MethodDeclaration> methodDeclarations = new BasicEList<>();
Iterable<ClassDeclaration> classDeclarations = getAllInstances(resource, JavaPackage.eINSTANCE.getClassDeclaration());
for (ClassDeclaration clazz : classDeclarations) {
for (BodyDeclaration method : clazz.getBodyDeclarations()) {
if (method instanceof MethodDeclaration && nonNull(method.getModifier())) {
if (method.getModifier().getVisibility() == VisibilityKind.PRIVATE) {
methodDeclarations.add((MethodDeclaration) method);
}
else if (method.getModifier().getVisibility() == VisibilityKind.PROTECTED) {
if (hasNoChildTypes(classDeclarations, clazz)) {
methodDeclarations.add((MethodDeclaration) method);
}
}
}
}
}
return methodDeclarations.size();
};
}
示例5: separateFields
import org.eclipse.gmt.modisco.java.BodyDeclaration; //导入依赖的package包/类
private static Iterable<NamedElement> separateFields(Iterable<BodyDeclaration> bodyDeclarations) {
List<NamedElement> fields = new BasicEList<>();
for (BodyDeclaration declaration : bodyDeclarations) {
if (nonNull(declaration) && declaration instanceof FieldDeclaration) {
FieldDeclaration field = (FieldDeclaration) declaration;
if (field.getFragments().isEmpty()) {
fields.add(declaration);
}
else {
fields.addAll(field.getFragments());
}
}
}
return fields;
}
示例6: getTypeMemberDeclaration
import org.eclipse.gmt.modisco.java.BodyDeclaration; //导入依赖的package包/类
/**
* Adds a new property definition of the annotation declaration
*
* @param annotationDeclaration
* @param propertyName
* @return
*/
private static AnnotationTypeMemberDeclaration getTypeMemberDeclaration(
AnnotationTypeDeclaration annotationDeclaration, String propertyName) {
if (annotationDeclaration != null) {
EList<BodyDeclaration> bodyDeclarations = annotationDeclaration.getBodyDeclarations();
for (BodyDeclaration bodyDeclaration : bodyDeclarations)
if (bodyDeclaration instanceof AnnotationTypeMemberDeclaration) {
AnnotationTypeMemberDeclaration atmd = (AnnotationTypeMemberDeclaration) bodyDeclaration;
if (propertyName.equals(atmd.getName()))
return atmd;
}
}
AnnotationTypeMemberDeclaration typeMemberDeclaration = JavaFactory.eINSTANCE
.createAnnotationTypeMemberDeclaration();
typeMemberDeclaration.setName(propertyName);
if (annotationDeclaration != null)
typeMemberDeclaration.setAbstractTypeDeclaration(annotationDeclaration);
return typeMemberDeclaration;
}
示例7: createTypeMemberDeclaration
import org.eclipse.gmt.modisco.java.BodyDeclaration; //导入依赖的package包/类
/**
* Create an annotation type member declaration associated to an annotation
* and a property name
*
* @param annotation
* the annotation.
* @param propertyName
* the property name.
* @return the created annotation type member associated to specified
* annotation and property name.
*/
public static AnnotationTypeMemberDeclaration createTypeMemberDeclaration(Annotation annotation, String propertyName) {
AnnotationTypeDeclaration annotationDeclaration = (AnnotationTypeDeclaration) annotation.getType().getType();
if (annotationDeclaration != null) {
for (BodyDeclaration bodyDeclaration : annotationDeclaration.getBodyDeclarations()) {
if (bodyDeclaration instanceof AnnotationTypeMemberDeclaration) {
AnnotationTypeMemberDeclaration atmd = (AnnotationTypeMemberDeclaration) bodyDeclaration;
if (propertyName.equals(atmd.getName())) {
return atmd;
}
}
}
}
return AnnotationTypeMemberDeclarationBuilder.builder().setName(propertyName)
.setAbstractTypeDeclaration(annotationDeclaration).build();
}
示例8: appendAccessedTypes
import org.eclipse.gmt.modisco.java.BodyDeclaration; //导入依赖的package包/类
private static void appendAccessedTypes(ClassDeclaration cd, List<Statement> result) {
for (BodyDeclaration method : cd.getBodyDeclarations()) {
if ((method instanceof MethodDeclaration)) {
MethodDeclaration meth = (MethodDeclaration) method;
if (nonNull(meth.getBody())) {
appendAccessedTypesFromBody(meth.getBody().getStatements(), result);
}
}
}
}
示例9: appendInvisibleMethodsInClassDeclaration
import org.eclipse.gmt.modisco.java.BodyDeclaration; //导入依赖的package包/类
private static void appendInvisibleMethodsInClassDeclaration(ClassDeclaration cd, List<MethodDeclaration> result) {
for (BodyDeclaration method : cd.getBodyDeclarations()) {
if ((method instanceof MethodDeclaration) && nonNull(method.getModifier())) {
if (method.getModifier().getVisibility() == VisibilityKind.PRIVATE) {
result.add((MethodDeclaration) method);
}
else if (method.getModifier().getVisibility() == VisibilityKind.PROTECTED) {
result.add((MethodDeclaration) method);
}
}
}
}
示例10: appendThrownExceptions
import org.eclipse.gmt.modisco.java.BodyDeclaration; //导入依赖的package包/类
protected static void appendThrownExceptions(ClassDeclaration cd, List<TypeAccess> thrownExceptions) {
for (BodyDeclaration declaration : cd.getBodyDeclarations()) {
if (declaration instanceof MethodDeclaration) {
for (TypeAccess type : ((MethodDeclaration) declaration).getThrownExceptions()) {
if (!thrownExceptions.contains(type)) {
thrownExceptions.add(type);
}
}
}
}
}
示例11: addGenerated
import org.eclipse.gmt.modisco.java.BodyDeclaration; //导入依赖的package包/类
public static void addGenerated(BodyDeclaration bodyDeclaration, String value, boolean withComments,
boolean withDate) {
Annotation addedAnnotation = JavaAnnotationHelper.addAnnotation(bodyDeclaration, JAVAX_ANNOTATION, GENERATED);
JavaAnnotationHelper.addAnnotationParameter(addedAnnotation, VALUE2, value, true);
if (withComments)
JavaAnnotationHelper.addAnnotationParameter(addedAnnotation, COMMENTS, TO_BE_CALCULATED, true);
if (withDate) {
String formattedDate = DATEFORMAT.format(new Date());
JavaAnnotationHelper.addAnnotationParameter(addedAnnotation, DATE, formattedDate, true);
}
}
示例12: addAnnotation
import org.eclipse.gmt.modisco.java.BodyDeclaration; //导入依赖的package包/类
/**
* Adds an annotation to a body declaration
*
* @param bodyDeclaration
* @param packageName
* @param annotationName
* @return
* @deprecated use the add annotation method in AbstractDeclaration in the
* net.atos.optimus.m2m.javaxmi.operation package.
*/
@Deprecated
public static Annotation addAnnotation(BodyDeclaration bodyDeclaration, String packageName, String annotationName) {
return (new AbstractDeclaration<BodyDeclaration>(bodyDeclaration))
.createAnnotation(packageName, annotationName).getDelegate();
// CompilationUnit compilationUnit = bodyDeclaration == null ? null :
// bodyDeclaration.getOriginalCompilationUnit();
//
// AnnotationTypeDeclaration annotationDeclaration = compilationUnit !=
// null ? getAnnotation(bodyDeclaration,
// packageName, annotationName) : getOrphanAnnotation(bodyDeclaration,
// packageName + "." + annotationName);
//
// // Now, we create a new annotation instance and set it on the body
// // declaration.
// Annotation annotation = JavaFactory.eINSTANCE.createAnnotation();
// annotation.setOriginalCompilationUnit(compilationUnit);
// TypeAccess typeAccess = JavaFactory.eINSTANCE.createTypeAccess();
// typeAccess.setType(annotationDeclaration);
// annotation.setType(typeAccess);
//
// if (bodyDeclaration != null) {
// bodyDeclaration.getAnnotations().add(annotation);
// addMissingImport(annotationDeclaration, bodyDeclaration);
// }
//
// return annotation;
}
示例13: resolveMethodRedefinitions
import org.eclipse.gmt.modisco.java.BodyDeclaration; //导入依赖的package包/类
/**
* consolidates the model with redefinitions links between methods
*
* @param model
* @param facto
*/
public static void resolveMethodRedefinitions(final Model model, final JavaFactory facto) {
Object item;
for (Iterator<?> i = model.eAllContents(); i.hasNext();) {
item = i.next();
if (item instanceof MethodDeclaration) {
MethodDeclaration aMethod = (MethodDeclaration) item;
if (!aMethod.isProxy()) {
String signature = getRawSignature(aMethod);
TypeAccess superClassRef = null;
AbstractTypeDeclaration declaringType = aMethod.getAbstractTypeDeclaration();
if (declaringType != null && declaringType instanceof ClassDeclaration) {
superClassRef = ((ClassDeclaration) declaringType).getSuperClass();
}
if (declaringType == null
&& aMethod.getAnonymousClassDeclarationOwner() != null) {
ClassInstanceCreation cic = aMethod.getAnonymousClassDeclarationOwner()
.getClassInstanceCreation();
if (cic != null) {
superClassRef = cic.getType();
}
}
boolean bFound = false;
// Look for similar method signature in super classes
while (!bFound && superClassRef != null
&& superClassRef.getType() instanceof ClassDeclaration) {
ClassDeclaration superClass = (ClassDeclaration) superClassRef.getType();
for (BodyDeclaration bodyDecl : superClass.getBodyDeclarations()) {
if (bodyDecl instanceof MethodDeclaration
&& signature
.equals(getRawSignature((MethodDeclaration) bodyDecl))) {
bFound = true;
aMethod.setRedefinedMethodDeclaration((MethodDeclaration) bodyDecl);
}
}
superClassRef = superClass.getSuperClass();
}
}
}
}
}
示例14: parse2
import org.eclipse.gmt.modisco.java.BodyDeclaration; //导入依赖的package包/类
/**
* Visit the members (fields, methods and types) of the {@code type}.
*
* @param type
* the java model {@code IType}
* @param enclosingType
* the MoDisco enclosing type of the {@code IType}
* @return the {@link AbstractTypeDeclaration} object corresponding to the
* {@code IType}, {@code null} if type does not exist.
* @throws JavaModelException
*/
protected AbstractTypeDeclaration parse2(final IType type,
final AbstractTypeDeclaration enclosingType) throws JavaModelException {
AbstractTypeDeclaration typeDeclaration = visitType(type);
if (enclosingType == null) {
// the class file object registers the top level type
this.cuNode.setType(typeDeclaration);
} else {
// type is an member type
enclosingType.getBodyDeclarations().add(typeDeclaration);
}
// fields
for (IField f : type.getFields()) {
if (type.isEnum() && f.isEnumConstant()) {
EnumConstantDeclaration constant = visitEnumConstantDeclaration(f);
if (constant != null) {
((EnumDeclaration) typeDeclaration).getEnumConstants().add(constant);
}
} else {
// declaring type is an annotation, interface or type
FieldDeclaration field = visitField(f);
if (field != null) {
typeDeclaration.getBodyDeclarations().add(field);
}
}
}
// methods
for (IMethod m : type.getMethods()) {
BodyDeclaration method = null;
if (type.isAnnotation()) {
method = visitAnnotationTypeMemberDeclaration(m);
} else {
method = visitMethod(m);
}
if (method != null) {
typeDeclaration.getBodyDeclarations().add(method);
}
}
// member types
for (IType subType : type.getTypes()) {
if (subType.exists()) {
parse2(subType, typeDeclaration);
}
}
return typeDeclaration;
}
示例15: resolveMethodRedefinitions
import org.eclipse.gmt.modisco.java.BodyDeclaration; //导入依赖的package包/类
/**
* consolidates the model with redefinitions links between methods
*
* @param model
* @param facto
*/
public static void resolveMethodRedefinitions(final EObject model, final JavaFactory facto) {
Object item;
for (Iterator<?> i = model.eAllContents(); i.hasNext();) {
item = i.next();
if (item instanceof MethodDeclaration) {
MethodDeclaration aMethod = (MethodDeclaration) item;
if (!aMethod.isProxy()) {
String signature = getRawSignature(aMethod);
TypeAccess superClassRef = null;
AbstractTypeDeclaration declaringType = aMethod.getAbstractTypeDeclaration();
if (declaringType != null && declaringType instanceof ClassDeclaration) {
superClassRef = ((ClassDeclaration) declaringType).getSuperClass();
}
if (declaringType == null
&& aMethod.getAnonymousClassDeclarationOwner() != null) {
ClassInstanceCreation cic = aMethod.getAnonymousClassDeclarationOwner()
.getClassInstanceCreation();
if (cic != null) {
superClassRef = cic.getType();
}
}
boolean bFound = false;
// Look for similar method signature in super classes
while (!bFound && superClassRef != null
&& superClassRef.getType() instanceof ClassDeclaration) {
ClassDeclaration superClass = (ClassDeclaration) superClassRef.getType();
for (BodyDeclaration bodyDecl : superClass.getBodyDeclarations()) {
if (bodyDecl instanceof MethodDeclaration
&& signature
.equals(getRawSignature((MethodDeclaration) bodyDecl))) {
bFound = true;
aMethod.setRedefinedMethodDeclaration((MethodDeclaration) bodyDecl);
}
}
superClassRef = superClass.getSuperClass();
}
}
}
}
}