本文整理汇总了Java中org.eclipse.gmt.modisco.java.CompilationUnit类的典型用法代码示例。如果您正苦于以下问题:Java CompilationUnit类的具体用法?Java CompilationUnit怎么用?Java CompilationUnit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompilationUnit类属于org.eclipse.gmt.modisco.java包,在下文中一共展示了CompilationUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAnnotation
import org.eclipse.gmt.modisco.java.CompilationUnit; //导入依赖的package包/类
/**
* Create an annotation and add it to the current parameter
*
* @param packageName
* the name of the package of the current parameter.
* @param annotationName
* the annotation name.
* @return the created java annotation.
*/
public JavaAnnotation createAnnotation(String packageName, String annotationName) {
CompilationUnit compilationUnit = this.getDelegate() == null ? null : this.getDelegate()
.getOriginalCompilationUnit();
TypeAccess annotationType = compilationUnit != null ? TypeAccessHelper.createAnnotationTypeAccess(this,
packageName, annotationName) : TypeAccessHelper.createOrphanAnnotationTypeAccess(this, packageName
+ "." + annotationName);
Annotation annotation = AnnotationBuilder.builder().setCompilationUnit(compilationUnit).setType(annotationType)
.build();
this.getDelegate().getAnnotations().add(annotation);
if (compilationUnit != null) {
MissingImportAdder.addMissingImport(compilationUnit, annotationType.getType());
}
return new JavaAnnotation(annotation);
}
示例2: createAnnotation
import org.eclipse.gmt.modisco.java.CompilationUnit; //导入依赖的package包/类
/**
* Create an annotation and add it to the current array initializer
* instruction
*
* @param packageName
* the name of the package of the current array initializer
* instruction.
* @param annotationName
* the annotation name.
* @return the created java annotation.
*/
public JavaAnnotation createAnnotation(String packageName, String annotationName) {
CompilationUnit compilationUnit = this.getDelegate() == null ? null : this.getDelegate()
.getOriginalCompilationUnit();
TypeAccess annotationType = compilationUnit != null ? TypeAccessHelper.createAnnotationTypeAccess(this,
packageName, annotationName) : TypeAccessHelper.createOrphanAnnotationTypeAccess(this, packageName
+ "." + annotationName);
Annotation annotation = AnnotationBuilder.builder().setCompilationUnit(compilationUnit).setType(annotationType)
.build();
((ArrayInitializer) this.getDelegate()).getExpressions().add(annotation);
if (compilationUnit != null) {
MissingImportAdder.addMissingImport(compilationUnit, annotationType.getType());
}
return new JavaAnnotation(annotation);
}
示例3: addMissingImport
import org.eclipse.gmt.modisco.java.CompilationUnit; //导入依赖的package包/类
/**
* Adds import if missing in the compilation unit for the provided type
*
* @param compilationUnit
* the compilation unit.
* @param type
* the type.
*/
public static void addMissingImport(CompilationUnit compilationUnit, Type type) {
if (type instanceof UnresolvedAnnotationDeclaration || compilationUnit == null) {
return;
}
boolean hasMatchingImport = false;
Iterator<ImportDeclaration> importIterator = compilationUnit.getImports().iterator();
while (importIterator.hasNext() && hasMatchingImport == false) {
hasMatchingImport = importIterator.next().getImportedElement().equals(type);
}
if (!hasMatchingImport) {
ImportDeclaration declaration = ImportDeclarationBuilder.builder().setImportedElement(type).build();
compilationUnit.getImports().add(declaration);
}
}
示例4: createAnnotation
import org.eclipse.gmt.modisco.java.CompilationUnit; //导入依赖的package包/类
/**
* Create an annotation and add it to the current array initializer
* instruction
*
* @param packageName
* the name of the package of the current array initializer
* instruction.
* @param annotationName
* the annotation name.
* @return the created java annotation.
*/
public JavaAnnotation createAnnotation(String packageName, String annotationName, String propertyName) {
Annotation annotation = this.getDelegate();
CompilationUnit compilationUnit = this.getDelegate() == null ? null : this.getDelegate()
.getOriginalCompilationUnit();
AnnotationMemberValuePair pair = null;
if (annotation.getValues().size() == 0) {
pair = JavaFactory.eINSTANCE.createAnnotationMemberValuePair();
if (propertyName != null) {
AnnotationTypeMemberDeclaration annotationTypeMemberDeclaration = AnnotationTypeMemberDeclarationHelper
.createTypeMemberDeclaration(annotation, propertyName);
pair.setMember(annotationTypeMemberDeclaration);
}
annotation.getValues().add(pair);
} else
pair = annotation.getValues().get(0);
ArrayInitializer initializer = null;
if (pair.getValue() == null || !(pair.getValue() instanceof ArrayInitializer)) {
initializer = JavaFactory.eINSTANCE.createArrayInitializer();
pair.setValue(initializer);
initializer.setOriginalCompilationUnit(compilationUnit);
} else
initializer = (ArrayInitializer) pair.getValue();
return new ArrayInitializerInstruction(initializer).createAnnotation(packageName, annotationName);
}
示例5: queryCommentsTagContent
import org.eclipse.gmt.modisco.java.CompilationUnit; //导入依赖的package包/类
public static Query<Integer> queryCommentsTagContent(Resource resource) {
return () -> {
Set<TextElement> result = new HashSet<>();
try {
Model model = (Model) resource.getContents().get(0);
if (model.getName().equals("org.eclipse.gmt.modisco.java.neoemf") || model.getName().equals("org.eclipse.jdt.core")) {
for (CompilationUnit cu : model.getCompilationUnits()) {
for (Comment comment : cu.getCommentList()) {
if (comment instanceof Javadoc) {
Javadoc javadoc = (Javadoc) comment;
for (TagElement te : javadoc.getTags()) {
for (ASTNode node : te.getFragments()) {
if (node instanceof TextElement) {
result.add((TextElement) node);
}
}
}
}
}
}
}
}
catch (NullPointerException e) {
log.error("Null pointer", e);
}
return result.size();
};
}
示例6: chunkPackage
import org.eclipse.gmt.modisco.java.CompilationUnit; //导入依赖的package包/类
/**
* Update the processed package
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private static void chunkPackage(final Package pack) {
final String name = pack.getName();
final String[] nameChunks = name.split("\\.");
if (nameChunks.length > 1) {
final Package[] packages = new Package[nameChunks.length];
packages[0] = pack;
pack.setName(nameChunks[0]);
for (int i = 1; i < nameChunks.length; i++) {
final Package packageChunk = JavaFactory.eINSTANCE.createPackage();
packageChunk.setName(nameChunks[i]);
packages[i] = packageChunk;
packageChunk.setPackage(packages[i - 1]);
}
final Package lastPackage = packages[nameChunks.length - 1];
final Collection<EObject> contentsToProcess = new ArrayList<EObject>();
contentsToProcess.addAll(pack.eContents());
for (final EObject eObject : contentsToProcess)
if (!(eObject instanceof Package)) {
final EReference eReference = eObject.eContainmentFeature();
if (eReference.isMany())
((EList) lastPackage.eGet(eReference)).add(eObject);
else
lastPackage.eSet(eReference, eObject);
}
for (final CompilationUnit compilationUnit : pack.getModel().getCompilationUnits())
if (compilationUnit.getPackage() == pack)
compilationUnit.setPackage(lastPackage);
}
}
示例7: createAnnotation
import org.eclipse.gmt.modisco.java.CompilationUnit; //导入依赖的package包/类
/**
* Create an annotation and add it to the current abstract declaration
*
* @param packageName
* the name of the package of the annotation.
* @param annotationName
* the annotation name.
* @return the created java annotation.
*/
public JavaAnnotation createAnnotation(String packageName, String annotationName) {
CompilationUnit compilationUnit = this.getDelegate() == null ? null : this.getDelegate()
.getOriginalCompilationUnit();
TypeAccess annotationType = compilationUnit != null ? TypeAccessHelper.createAnnotationTypeAccess(this,
packageName, annotationName) : TypeAccessHelper.createOrphanAnnotationTypeAccess(this, packageName
+ "." + annotationName);
Annotation annotation = AnnotationBuilder.builder().setCompilationUnit(compilationUnit).setType(annotationType)
.build();
if (this.getDelegate() != null) {
this.getDelegate().getAnnotations().add(annotation);
MissingImportAdder.addMissingImport(this.getDelegate(), annotationType.getType());
}
return new JavaAnnotation(annotation);
}
示例8: InterfaceHelper
import org.eclipse.gmt.modisco.java.CompilationUnit; //导入依赖的package包/类
/**
* Private constructor : a new interface (public, proxy state set to false,
* no interface and abstract state set to false by default)
*
* @param javaPackage
* the package a the interface under construction.
* @param interfaceName
* the name of the interface under construction.
*/
private InterfaceHelper(JavaPackage javaPackage, String interfaceName) {
org.eclipse.gmt.modisco.java.Package internalPackage = javaPackage.getDelegate();
CompilationUnit compilationUnit = CompilationUnitBuilder.builder().setName(interfaceName + ".java")
.setPackage(internalPackage).build();
Modifier modifier = ModifierBuilder.builder().setVisibility(VisibilityKind.PUBLIC)
.setInheritance(InheritanceKind.NONE).setCompilationUnit(compilationUnit).build();
this.buildInterface = InterfaceDeclarationBuilder.builder().setName(interfaceName).setPackage(internalPackage)
.setProxy(false).setModifier(modifier).setCompilationUnit(compilationUnit).build();
TypeParameterHelper.addTypeParametersToTypeDeclaration(this.buildInterface);
compilationUnit.getTypes().add(this.buildInterface);
ASTElementFinder.findModel(internalPackage).getCompilationUnits().add(compilationUnit);
}
示例9: ClassHelper
import org.eclipse.gmt.modisco.java.CompilationUnit; //导入依赖的package包/类
/**
* Private constructor : a new class (public, proxy state set to false, no
* super class, no interface and inheritance state set to none by default)
*
* @param javaPackage
* the package a the class under construction.
* @param className
* the name of the class under construction.
*/
private ClassHelper(JavaPackage javaPackage, String className) {
org.eclipse.gmt.modisco.java.Package internalPackage = javaPackage.getDelegate();
CompilationUnit compilationUnit = CompilationUnitBuilder.builder().setName(className + ".java")
.setPackage(internalPackage).build();
Modifier modifier = ModifierBuilder.builder().setVisibility(VisibilityKind.PUBLIC)
.setInheritance(InheritanceKind.NONE).setCompilationUnit(compilationUnit).build();
this.buildClass = ClassDeclarationBuilder.builder().setName(className).setPackage(internalPackage)
.setProxy(false).setModifier(modifier).setCompilationUnit(compilationUnit).build();
compilationUnit.getTypes().add(this.buildClass);
TypeParameterHelper.addTypeParametersToTypeDeclaration(this.buildClass);
ASTElementFinder.findModel(internalPackage).getCompilationUnits().add(compilationUnit);
}
示例10: EnumHelper
import org.eclipse.gmt.modisco.java.CompilationUnit; //导入依赖的package包/类
/**
* Private constructor : a new enumeration (public, proxy state set to false
* and no interface by default)
*
* @param javaPackage
* the package a the enumeration under construction.
* @param enumName
* the name of the enumeration under construction.
*/
private EnumHelper(JavaPackage javaPackage, String enumName) {
org.eclipse.gmt.modisco.java.Package internalPackage = javaPackage.getDelegate();
CompilationUnit compilationUnit = CompilationUnitBuilder.builder().setName(enumName + ".java")
.setPackage(internalPackage).build();
Modifier modifier = ModifierBuilder.builder().setVisibility(VisibilityKind.PUBLIC)
.setInheritance(InheritanceKind.NONE).setCompilationUnit(compilationUnit).build();
this.buildEnum = EnumDeclarationBuilder.builder().setName(enumName).setPackage(internalPackage).setProxy(false)
.setModifier(modifier).setCompilationUnit(compilationUnit).build();
compilationUnit.getTypes().add(this.buildEnum);
ASTElementFinder.findModel(internalPackage).getCompilationUnits().add(compilationUnit);
}
示例11: getOriginalCompilationUnit
import org.eclipse.gmt.modisco.java.CompilationUnit; //导入依赖的package包/类
public CompilationUnit getOriginalCompilationUnit() {
return null;
}
示例12: setOriginalCompilationUnit
import org.eclipse.gmt.modisco.java.CompilationUnit; //导入依赖的package包/类
public void setOriginalCompilationUnit(final CompilationUnit value) {
return;
}
示例13: getCompilationUnit
import org.eclipse.gmt.modisco.java.CompilationUnit; //导入依赖的package包/类
public CompilationUnit getCompilationUnit() {
return this.getDelegate().getOriginalCompilationUnit();
}
示例14: getOriginalCompilationUnit
import org.eclipse.gmt.modisco.java.CompilationUnit; //导入依赖的package包/类
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public CompilationUnit getOriginalCompilationUnit() {
return (CompilationUnit)eGet(JavaPackage.eINSTANCE.getASTNode_OriginalCompilationUnit(), true);
}
示例15: setOriginalCompilationUnit
import org.eclipse.gmt.modisco.java.CompilationUnit; //导入依赖的package包/类
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setOriginalCompilationUnit(CompilationUnit newOriginalCompilationUnit) {
eSet(JavaPackage.eINSTANCE.getASTNode_OriginalCompilationUnit(), newOriginalCompilationUnit);
}