本文整理汇总了Java中org.eclipse.gmt.modisco.java.AbstractTypeDeclaration类的典型用法代码示例。如果您正苦于以下问题:Java AbstractTypeDeclaration类的具体用法?Java AbstractTypeDeclaration怎么用?Java AbstractTypeDeclaration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AbstractTypeDeclaration类属于org.eclipse.gmt.modisco.java包,在下文中一共展示了AbstractTypeDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: queryThrownExceptionsPerPackage
import org.eclipse.gmt.modisco.java.AbstractTypeDeclaration; //导入依赖的package包/类
public static Query<Integer> queryThrownExceptionsPerPackage(Resource resource) {
return () -> {
HashMap<String, Iterable<TypeAccess>> resultMap = new HashMap<>();
Iterable<Package> packages = getAllInstances(resource, JavaPackage.eINSTANCE.getPackage());
for (Package pack : packages) {
List<TypeAccess> thrownExceptions = new BasicEList<>();
Iterable<AbstractTypeDeclaration> elements = pack.getOwnedElements();
for (AbstractTypeDeclaration element : elements) {
if (element instanceof ClassDeclaration) {
appendThrownExceptions((ClassDeclaration) element, thrownExceptions);
}
}
resultMap.put(pack.getName(), thrownExceptions);
}
return resultMap.size();
};
}
示例2: getAnnotationTypeMemberDeclaration
import org.eclipse.gmt.modisco.java.AbstractTypeDeclaration; //导入依赖的package包/类
private AnnotationTypeMemberDeclaration getAnnotationTypeMemberDeclaration(
final MethodBinding binding, final Model model1) {
AnnotationTypeMemberDeclaration result = (AnnotationTypeMemberDeclaration) this
.getTarget(binding);
if (result == null) {
result = this.factory.createAnnotationTypeMemberDeclaration();
result.setProxy(true);
result.setName(binding.getName());
if (binding.getDeclaringClass() != null) {
AbstractTypeDeclaration declaring = (AbstractTypeDeclaration) getTypeDeclaration(
binding.getDeclaringClass(), model1);
if (declaring != null) {
declaring.getBodyDeclarations().add(result);
}
}
this.addTarget(binding, result);
}
return result;
}
示例3: createAnnotationTypeAccess
import org.eclipse.gmt.modisco.java.AbstractTypeDeclaration; //导入依赖的package包/类
/**
* Create a type access associated to an annotation
*
* @param element
* the element which we associate the annotation.
* @param packageName
* the name of the package of the element.
* @param annotationName
* the name of the annotation.
* @return the created type access associated to the specified annotation
* name.
*/
public static TypeAccess createAnnotationTypeAccess(Element<?> element, String packageName, String annotationName) {
Model model = ASTElementFinder.findModel(element.getDelegate());
JavaPackage javaPackage = PackageHelper.createPackage(model, packageName);
AnnotationTypeDeclaration generatedAnnotation = null;
Iterator<AbstractTypeDeclaration> declarationIterator = javaPackage.getDelegate().getOwnedElements().iterator();
while (declarationIterator.hasNext() && generatedAnnotation == null) {
AbstractTypeDeclaration next = declarationIterator.next();
if (next instanceof AnnotationTypeDeclaration && annotationName.equals(next.getName())) {
generatedAnnotation = (AnnotationTypeDeclaration) next;
}
}
if (generatedAnnotation == null) {
return TypeAccessBuilder
.builder()
.setType(
AnnotationTypeDeclarationBuilder.builder().setName(annotationName)
.setPackage(javaPackage.getDelegate()).setProxy(true).build()).build();
}
return TypeAccessBuilder.builder().setType(generatedAnnotation).build();
}
示例4: appendAccessedTypes
import org.eclipse.gmt.modisco.java.AbstractTypeDeclaration; //导入依赖的package包/类
private static void appendAccessedTypes(org.eclipse.gmt.modisco.java.Package pack, List<Statement> result) {
for (AbstractTypeDeclaration el : pack.getOwnedElements()) {
if (JavaPackage.eINSTANCE.getClassDeclaration().isInstance(el)) {
appendAccessedTypes((ClassDeclaration) el, result);
}
}
for (org.eclipse.gmt.modisco.java.Package subPack : pack.getOwnedPackages()) {
appendAccessedTypes(subPack, result);
}
}
示例5: appendInvisibleMethods
import org.eclipse.gmt.modisco.java.AbstractTypeDeclaration; //导入依赖的package包/类
private static void appendInvisibleMethods(org.eclipse.gmt.modisco.java.Package pack, List<MethodDeclaration> result) {
for (AbstractTypeDeclaration el : pack.getOwnedElements()) {
if (JavaPackage.eINSTANCE.getClassDeclaration().isInstance(el)) {
appendInvisibleMethodsInClassDeclaration((ClassDeclaration) el, result);
}
}
for (org.eclipse.gmt.modisco.java.Package subPack : pack.getOwnedPackages()) {
appendInvisibleMethods(subPack, result);
}
}
示例6: getFieldDeclaration
import org.eclipse.gmt.modisco.java.AbstractTypeDeclaration; //导入依赖的package包/类
private VariableDeclarationFragment getFieldDeclaration(final FieldBinding binding,
final Model model1) {
VariableDeclarationFragment result = (VariableDeclarationFragment) this.getTarget(binding);
if (result == null) {
FieldDeclaration field = this.factory.createFieldDeclaration();
field.setProxy(true);
result = this.factory.createVariableDeclarationFragment();
result.setProxy(true);
result.setName(binding.getName());
field.getFragments().add(result);
if (binding.getDeclaringClass() != null) {
AbstractTypeDeclaration declaring = (AbstractTypeDeclaration) getTypeDeclaration(
binding.getDeclaringClass(), model1);
if (declaring != null) {
declaring.getBodyDeclarations().add(field);
}
} else {
// To be sure that result object is owned by a resource.
model1.eResource().getContents().add(field);
}
this.addTarget(binding, result);
}
return result;
}
示例7: getRawSignature
import org.eclipse.gmt.modisco.java.AbstractTypeDeclaration; //导入依赖的package包/类
private static String getRawSignature(final TypeAccess typeRef) {
String signature;
if (typeRef.getType() instanceof AbstractTypeDeclaration) {
signature = JavaUtil.getQualifiedName(typeRef.getType(), true);
} else {
signature = typeRef.getType().getName();
}
return signature;
}
示例8: ConstructorHelper
import org.eclipse.gmt.modisco.java.AbstractTypeDeclaration; //导入依赖的package包/类
/**
* Private constructor : a new constructor (public, with no body and no
* parameter by default)
*
* @param abstractClass
* the abstract class associated to the constructor under
* construction.
*/
private ConstructorHelper(AbstractClass<? extends AbstractTypeDeclaration> abstractClass) {
AbstractTypeDeclaration internalClass = abstractClass.getDelegate();
Modifier modifier = ModifierBuilder.builder().setVisibility(VisibilityKind.PUBLIC)
.setCompilationUnit(internalClass.getOriginalCompilationUnit()).build();
this.buildConstructor = ConstructorDeclarationBuilder.builder().setModifier(modifier)
.setName(abstractClass.getName()).setAbstractTypeDeclaration(internalClass)
.setCompilationUnit(internalClass.getOriginalCompilationUnit()).build();
}
示例9: MethodHelper
import org.eclipse.gmt.modisco.java.AbstractTypeDeclaration; //导入依赖的package包/类
/**
* Private constructor : a new method (void, public, not static, inheritance
* set to none with no parameter, no exceptions and no body by default)
*
* @param abstractClassDeclaration
* the class, the interface or the enumeration where is the
* method under construction.
* @param methodName
* the name of the created method under construction.
*/
private MethodHelper(AbstractClassDeclaration<?> abstractClassDeclaration, String methodName) {
AbstractTypeDeclaration abstractType = abstractClassDeclaration.getDelegate();
Modifier modifier = ModifierBuilder.builder().setVisibility(VisibilityKind.PUBLIC).setStatic(false)
.setInheritance(InheritanceKind.NONE).setCompilationUnit(abstractType.getOriginalCompilationUnit())
.build();
this.buildMethod = MethodDeclarationBuilder.builder().setModifier(modifier)
.setReturnType(TypeAccessHelper.createTypeAccess(MethodHelper.VOID_TYPE)).setName(methodName)
.setAbstractTypeDeclaration(abstractType).setCompilationUnit(abstractType.getOriginalCompilationUnit())
.build();
}
示例10: SetterHelper
import org.eclipse.gmt.modisco.java.AbstractTypeDeclaration; //导入依赖的package包/类
/**
* Private constructor : a new setter method (public, not final, with
* generated name and generated parameter name)
*
* @param abstractClass
* the abstract class where is the setter method under
* construction.
* @param field
* the field associated to the setter method under construction.
*/
private SetterHelper(AbstractClass<? extends AbstractTypeDeclaration> abstractClass, Field field) {
String parameterName = NameGenerator.generateNameWithTypeName(field.getTypeName());
this.buildSetterMethod = MethodHelper
.builder(abstractClass, NameGenerator.generateSetterName(field.getName()))
.setVisibility(VisibilityKind.PUBLIC)
.setInheritance(InheritanceKind.NONE)
.addParameter(field.getTypeName(), parameterName)
.addInstructions(
AssignmentInstructionHelper.builder().setOperator(AssignmentKind.ASSIGN)
.setLeftFieldOperand(field.getName()).setRightVariableOperand(parameterName).build())
.build();
this.field = field;
}
示例11: FieldHelper
import org.eclipse.gmt.modisco.java.AbstractTypeDeclaration; //导入依赖的package包/类
/**
* Private constructor : a new field (private, not static, nor abstract,
* with generated name)
*
* @param abstractClass
* the abstract class where is the field under construction.
* @param fieldTypeName
* the type name of the field under construction.
* @return a new helper.
*/
private FieldHelper(AbstractClass<? extends AbstractTypeDeclaration> abstractClass, String fieldTypeName) {
AbstractTypeDeclaration internalClass = abstractClass.getDelegate();
String fieldName = NameGenerator.generateNameWithTypeName(fieldTypeName);
Modifier modifier = ModifierBuilder.builder().setVisibility(VisibilityKind.PRIVATE).setStatic(false)
.setInheritance(InheritanceKind.NONE).setCompilationUnit(internalClass.getOriginalCompilationUnit())
.build();
VariableDeclarationFragment variableDeclarationFragment = VariableDeclarationFragmentBuilder.builder()
.setName(fieldName).build();
this.buildField = FieldDeclarationBuilder.builder().setModifier(modifier)
.setType(TypeAccessHelper.createTypeAccess(fieldTypeName)).addFragment(variableDeclarationFragment)
.setAbstractTypeDeclaration(internalClass)
.setCompilationUnit(internalClass.getOriginalCompilationUnit()).build();
}
示例12: getMethodDeclaration
import org.eclipse.gmt.modisco.java.AbstractTypeDeclaration; //导入依赖的package包/类
private AbstractMethodDeclaration getMethodDeclaration(final MethodBinding binding,
final Model model1) {
AbstractMethodDeclaration result = (AbstractMethodDeclaration) this.getTarget(binding);
if (result == null) {
if (binding.isConstructor()) {
result = this.factory.createConstructorDeclaration();
} else {
result = this.factory.createMethodDeclaration();
}
result.setProxy(true);
result.setName(binding.getName());
for (int i = 0; i < binding.getParameters().size(); i++) {
ParameterBinding param = binding.getParameters().get(i);
SingleVariableDeclaration paramDecl = this.factory
.createSingleVariableDeclaration();
paramDecl.setProxy(true);
paramDecl.setName("arg" + i); //$NON-NLS-1$
result.getParameters().add(paramDecl);
TypeAccess typAcc = this.factory.createTypeAccess();
if (param.isArray()) {
typAcc.setType(getArrayTypeDeclaration(param, model1));
} else {
typAcc.setType((Type) getTypeDeclaration(param.getElementType(), model1));
}
paramDecl.setType(typAcc);
}
// Placed at the end of the method to avoid to connect
// a type body declaration which is not finished to construct
// This avoid null pointer exception while searching into the model.
if (binding.getDeclaringClass() != null) {
AbstractTypeDeclaration declaring = (AbstractTypeDeclaration) getTypeDeclaration(
binding.getDeclaringClass(), model1);
if (declaring != null) {
declaring.getBodyDeclarations().add(result);
}
}
this.addTarget(binding, result);
}
return result;
}
示例13: resolveMethodRedefinitions
import org.eclipse.gmt.modisco.java.AbstractTypeDeclaration; //导入依赖的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.AbstractTypeDeclaration; //导入依赖的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: visitType
import org.eclipse.gmt.modisco.java.AbstractTypeDeclaration; //导入依赖的package包/类
/**
* Visit the properties of an {@code IType}.
*
* @param type
* the {@code IType}
* @return the {@link AbstractTypeDeclaration} object corresponding to the
* {@code IType}
* @throws JavaModelException
*/
protected AbstractTypeDeclaration visitType(final IType type) throws JavaModelException {
AbstractTypeDeclaration element = null;
if (type.isEnum()) {
element = getFactory().createEnumDeclaration();
} else if (type.isAnnotation()) {
element = getFactory().createAnnotationTypeDeclaration();
} else if (type.isInterface()) {
element = getFactory().createInterfaceDeclaration();
} else {
element = getFactory().createClassDeclaration();
}
this.currentlyVisitedJavaElement = type;
initializeNode(element);
element.setName(type.getElementName());
element.setPackage(this.currentPackage);
this.currentPackage.getOwnedElements().add(element);
// superClass
// enums are classes but can't have explicit superclass
String superClass = type.getSuperclassTypeSignature();
if (type.isClass() && superClass != null
&& !ClassFileParserUtils.isJavaLangObject(superClass)) {
((ClassDeclaration) element).setSuperClass(getRefOnType(superClass));
}
// superInterfaces
// annotations can't have explicit annotations
if (!type.isAnnotation()) {
for (String superInterface : type.getSuperInterfaceTypeSignatures()) {
if (!ClassFileParserUtils.isJavaLangObject(superInterface)) {
element.getSuperInterfaces().add(getRefOnType(superInterface));
}
}
}
// type parameters
ITypeParameter[] parameters = type.getTypeParameters();
for (ITypeParameter parameter : parameters) {
TypeParameter t = getFactory().createTypeParameter();
((TypeDeclaration) element).getTypeParameters().add(t);
visitTypeParameter(parameter, t);
}
// annotations
for (IAnnotation annotation : type.getAnnotations()) {
Annotation anno = getFactory().createAnnotation();
element.getAnnotations().add(anno);
visitAnnotation(annotation, anno);
}
// visibility modifier
Modifier m = getFactory().createModifier();
element.setModifier(m);
m.setBodyDeclaration(element);
manageModifier(m, type.getFlags(), type);
ClassFileParserUtils.manageBindingDeclaration(element, type, this);
return element;
}