当前位置: 首页>>代码示例>>Java>>正文


Java PackageDeclaration类代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.PackageDeclaration的典型用法代码示例。如果您正苦于以下问题:Java PackageDeclaration类的具体用法?Java PackageDeclaration怎么用?Java PackageDeclaration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PackageDeclaration类属于org.eclipse.jdt.core.dom包,在下文中一共展示了PackageDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ClassModel

import org.eclipse.jdt.core.dom.PackageDeclaration; //导入依赖的package包/类
ClassModel(ASTNodeFactory astNodeFactory, String className, Type superClassType, PackageDeclaration packageDeclaration,
           List<FieldDeclaration> fields, List<MethodModel> methods, List<ImportDeclaration> imports,
           List<TypeModel> innerTypes, List<ASTNode> modifiers) {
    groovism = provide();

    this.className = className;
    this.packageDeclaration = packageDeclaration;
    this.fields = fieldDeclarations(fields);
    this.methods = unmodifiableList(new LinkedList<>(methods));
    this.modifiers = unmodifiableList(new LinkedList<>(modifiers));
    this.imports = imports;
    this.innerTypes = unmodifiableList(new LinkedList<>(innerTypes));
    if (isTestClass(methods)) {
        this.superClassType = Optional.of(astNodeFactory.simpleType(Specification.class.getSimpleName()));
        imports.add(0, astNodeFactory.importDeclaration(Specification.class));
    } else {
        this.superClassType = Optional.ofNullable(superClassType);
    }
}
 
开发者ID:opaluchlukasz,项目名称:junit2spock,代码行数:20,代码来源:ClassModel.java

示例2: InterfaceModel

import org.eclipse.jdt.core.dom.PackageDeclaration; //导入依赖的package包/类
InterfaceModel(String typeName, Type superClassType, PackageDeclaration packageDeclaration,
               List<FieldDeclaration> fields, List<MethodModel> methods, List<ImportDeclaration> imports,
               List<ASTNode> modifiers) {
    groovism = provide();

    LinkedList<ImportDeclaration> importDeclarations = new LinkedList<>(imports);

    this.superClassType = Optional.ofNullable(superClassType).map(Object::toString);

    this.typeName = typeName;
    this.packageDeclaration = packageDeclaration;
    this.fields = unmodifiableList(new LinkedList<>(fields));
    this.methods = unmodifiableList(new LinkedList<>(methods));
    this.imports = unmodifiableList(importDeclarations);
    this.modifiers = unmodifiableList(modifiers);
}
 
开发者ID:opaluchlukasz,项目名称:junit2spock,代码行数:17,代码来源:InterfaceModel.java

示例3: visit

import org.eclipse.jdt.core.dom.PackageDeclaration; //导入依赖的package包/类
@Override
public boolean visit(FieldDeclaration node) {
	List fragments = node.fragments();
	for(Object o : fragments) {
		VariableDeclarationFragment frag = (VariableDeclarationFragment) o;
		String varName = frag.getName().getIdentifier();
		int line = cunit.getLineNumber(frag.getStartPosition());
		ASTNode parent = node.getParent();
		Scope scope = new Scope(cunit.getLineNumber(parent.getStartPosition()), getEndLine(parent, cunit));
		TypeDeclaration dec = (TypeDeclaration) node.getParent();
		String qName = dec.getName().getFullyQualifiedName();
		PackageDeclaration packageDec = cunit.getPackage();
		if(packageDec != null)
			qName = packageDec.getName().getFullyQualifiedName() + "." + qName;
		String type = !Modifier.isStatic(node.getModifiers()) ? qName : null; 
		VariableTags tags = new VariableTags(varName, type, line, scope, true);
		variables.add(tags);
	}
	return false;
}
 
开发者ID:andre-santos-pt,项目名称:pandionj,代码行数:21,代码来源:TagParser.java

示例4: getFullName

import org.eclipse.jdt.core.dom.PackageDeclaration; //导入依赖的package包/类
/**
 * Evaluates fully qualified name of the TypeDeclaration object.
 */
public static String getFullName(TypeDeclaration decl) {
    String name = decl.getName().getIdentifier();
    ASTNode parent = decl.getParent();
    // resolve full name e.g.: A.B
    while (parent != null && parent.getClass() == TypeDeclaration.class) {
        name = ((TypeDeclaration) parent).getName().getIdentifier() + "." + name;
        parent = parent.getParent();
    }
    // resolve fully qualified name e.g.: some.package.A.B
    if (decl.getRoot().getClass() == CompilationUnit.class) {
        CompilationUnit root = (CompilationUnit) decl.getRoot();
        if (root.getPackage() != null) {
            PackageDeclaration pack = root.getPackage();
            name = pack.getName().getFullyQualifiedName() + "." + name;
        }
    }
    return name;
}
 
开发者ID:linzeqipku,项目名称:SnowGraph,代码行数:22,代码来源:NameResolver.java

示例5: createStubTypeContext

import org.eclipse.jdt.core.dom.PackageDeclaration; //导入依赖的package包/类
public static StubTypeContext createStubTypeContext(
    ICompilationUnit cu, CompilationUnit root, int focalPosition) throws CoreException {
  StringBuffer bufBefore = new StringBuffer();
  StringBuffer bufAfter = new StringBuffer();

  int introEnd = 0;
  PackageDeclaration pack = root.getPackage();
  if (pack != null) introEnd = pack.getStartPosition() + pack.getLength();
  List<ImportDeclaration> imports = root.imports();
  if (imports.size() > 0) {
    ImportDeclaration lastImport = imports.get(imports.size() - 1);
    introEnd = lastImport.getStartPosition() + lastImport.getLength();
  }
  bufBefore.append(cu.getBuffer().getText(0, introEnd));

  fillWithTypeStubs(bufBefore, bufAfter, focalPosition, root.types());
  bufBefore.append(' ');
  bufAfter.insert(0, ' ');
  return new StubTypeContext(cu, bufBefore.toString(), bufAfter.toString());
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:TypeContextChecker.java

示例6: getNodeStartPosition

import org.eclipse.jdt.core.dom.PackageDeclaration; //导入依赖的package包/类
private static int getNodeStartPosition(final ASTNode node) {
    if (node instanceof MethodDeclaration) {
        MethodDeclaration decl = (MethodDeclaration) node;
        return decl.isConstructor() ? decl.getName().getStartPosition() : decl.getReturnType2().getStartPosition();
    } else if (node instanceof FieldDeclaration) {
        return ((FieldDeclaration) node).getType().getStartPosition();
    } else if (node instanceof AbstractTypeDeclaration) {
        return ((AbstractTypeDeclaration) node).getName().getStartPosition();
    } else if (node instanceof AnnotationTypeMemberDeclaration) {
        return ((AnnotationTypeMemberDeclaration) node).getName().getStartPosition();
    } else if (node instanceof EnumConstantDeclaration) {
        return ((EnumConstantDeclaration) node).getName().getStartPosition();
    } else if (node instanceof PackageDeclaration) {
        return ((PackageDeclaration) node).getName().getStartPosition();
    }
    /* TODO: Initializer */

    return node.getStartPosition();
}
 
开发者ID:boalang,项目名称:compiler,代码行数:20,代码来源:UglyMathCommentsExtractor.java

示例7: getFullyQualifiedName

import org.eclipse.jdt.core.dom.PackageDeclaration; //导入依赖的package包/类
/**
 * Queries the fully qualified name of type defined by the source code file this
 * bridge was created for.
 *
 * @return The fully qualified name of the type defined by the source code file this
 *         bridge was created for. {@code null} if there is nothing in the file this
 *         desription applies to.
 */
String getFullyQualifiedName() {
	Validate.validState(this.compilationUnit != null, "getFullyQualifiedName may only be called after getAst was!");

	// Compilation Units that don’t have exactly one type declaration at the root
	// level are not supported. The author knows of no compilable example of such a
	// compilation unit.
	final TypeDeclaration rootType = (TypeDeclaration) this.compilationUnit.types().get(0);
	if (rootType == null) {
		return null;
	}

	final PackageDeclaration cuPackage = this.compilationUnit.getPackage();
	final String packageName;
	if (cuPackage == null) {
		packageName = "";
	} else {
		packageName = cuPackage.getName() + ".";
	}

	return packageName + rootType.getName();
}
 
开发者ID:Beagle-PSE,项目名称:Beagle,代码行数:30,代码来源:EclipseAstBridge.java

示例8: qualifiedName

import org.eclipse.jdt.core.dom.PackageDeclaration; //导入依赖的package包/类
public static String qualifiedName(TypeDeclaration decl) {
	String name = decl.getName().getIdentifier();
	ASTNode parent = decl.getParent();
	// resolve full name e.g.: A.B
	while (parent != null && parent.getClass() == TypeDeclaration.class) {
		name = ((TypeDeclaration) parent).getName().getIdentifier() + "." + name;
		parent = parent.getParent();
	}
	// resolve fully qualified name e.g.: some.package.A.B
	if (decl.getRoot().getClass() == CompilationUnit.class) {
		CompilationUnit root = (CompilationUnit) decl.getRoot();
		if (root.getPackage() != null) {
			PackageDeclaration pack = root.getPackage();
			name = pack.getName().getFullyQualifiedName() + "." + name;
		}
	}
	return name;
}
 
开发者ID:ELTE-Soft,项目名称:txtUML,代码行数:19,代码来源:SharedUtils.java

示例9: createStubTypeContext

import org.eclipse.jdt.core.dom.PackageDeclaration; //导入依赖的package包/类
public static StubTypeContext createStubTypeContext(ICompilationUnit cu, CompilationUnit root, int focalPosition) throws CoreException {
	StringBuffer bufBefore= new StringBuffer();
	StringBuffer bufAfter= new StringBuffer();

	int introEnd= 0;
	PackageDeclaration pack= root.getPackage();
	if (pack != null)
		introEnd= pack.getStartPosition() + pack.getLength();
	List<ImportDeclaration> imports= root.imports();
	if (imports.size() > 0) {
		ImportDeclaration lastImport= imports.get(imports.size() - 1);
		introEnd= lastImport.getStartPosition() + lastImport.getLength();
	}
	bufBefore.append(cu.getBuffer().getText(0, introEnd));

	fillWithTypeStubs(bufBefore, bufAfter, focalPosition, root.types());
	bufBefore.append(' ');
	bufAfter.insert(0, ' ');
	return new StubTypeContext(cu, bufBefore.toString(), bufAfter.toString());
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:TypeContextChecker.java

示例10: visitCompilationUnit

import org.eclipse.jdt.core.dom.PackageDeclaration; //导入依赖的package包/类
private void visitCompilationUnit(IFile file) {
	ICompilationUnit cu= JavaCore.createCompilationUnitFrom(file);
	if (cu != null) {
		ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
		parser.setSource(cu);
		parser.setFocalPosition(0);
		CompilationUnit root= (CompilationUnit)parser.createAST(null);
		PackageDeclaration packDecl= root.getPackage();
		
		IPath packPath= file.getParent().getFullPath();
		String cuName= file.getName();
		if (packDecl == null) {
			addToMap(fSourceFolders, packPath, new Path(cuName));
		} else {
			IPath relPath= new Path(packDecl.getName().getFullyQualifiedName().replace('.', '/'));
			IPath folderPath= getFolderPath(packPath, relPath);
			if (folderPath != null) {
				addToMap(fSourceFolders, folderPath, relPath.append(cuName));
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:23,代码来源:ClassPathDetector.java

示例11: generateElementAST

import org.eclipse.jdt.core.dom.PackageDeclaration; //导入依赖的package包/类
protected ASTNode generateElementAST(ASTRewrite rewriter, ICompilationUnit cu) throws JavaModelException {
	//look for an existing package declaration
	IJavaElement[] children = getCompilationUnit().getChildren();
	for (int i = 0; i < children.length; i++) {
		if (children[i].getElementType() ==  IJavaElement.PACKAGE_DECLARATION && this.name.equals(children[i].getElementName())) {
			//equivalent package declaration already exists
			this.creationOccurred = false;
			return null;
		}
	}
	AST ast = this.cuAST.getAST();
	PackageDeclaration pkgDeclaration = ast.newPackageDeclaration();
	Name astName = ast.newName(this.name);
	pkgDeclaration.setName(astName);
	return pkgDeclaration;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:CreatePackageDeclarationOperation.java

示例12: extractPackage

import org.eclipse.jdt.core.dom.PackageDeclaration; //导入依赖的package包/类
private void extractPackage(Repository _repo) throws MissingObjectException, IOException{
	ObjectLoader newFile = _repo.open(this.newObjId);
	String newData = readStream(newFile.openStream());

	
	ASTParser parser = ASTParser.newParser(AST.JLS3);
	parser.setSource(newData.toCharArray());
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	Hashtable<String, String> options = JavaCore.getOptions();
	options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.DISABLED);
	parser.setCompilerOptions(options);
	
	final CompilationUnit cu = (CompilationUnit) parser.createAST(null);

	cu.accept(new ASTVisitor() {
		
		public boolean visit(PackageDeclaration _package){
			packageName = _package.getName().getFullyQualifiedName();
			return false;
		}
	});
}
 
开发者ID:gems-uff,项目名称:dominoes,代码行数:23,代码来源:FileNode.java

示例13: visit

import org.eclipse.jdt.core.dom.PackageDeclaration; //导入依赖的package包/类
@Override
public boolean visit(PackageDeclaration node) {
	if (node.getAST().apiLevel() >= JLS3) {
		if (node.getJavadoc() != null) {
			node.getJavadoc().accept(this);
		}
		for (Iterator<Annotation> it= node.annotations().iterator(); it.hasNext();) {
			Annotation p= it.next();
			p.accept(this);
			this.fBuffer.append(" ");//$NON-NLS-1$
		}
	}
	this.fBuffer.append("package ");//$NON-NLS-1$
	node.getName().accept(this);
	this.fBuffer.append(";");//$NON-NLS-1$
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:18,代码来源:ASTFlattener.java

示例14: visit

import org.eclipse.jdt.core.dom.PackageDeclaration; //导入依赖的package包/类
public boolean visit(PackageDeclaration node) {
	if (node.getAST().apiLevel() >= JLS3) {
		if (node.getJavadoc() != null) {
			node.getJavadoc().accept(this);
		}
		for (Iterator it = node.annotations().iterator(); it.hasNext(); ) {
			Annotation p = (Annotation) it.next();
			p.accept(this);
			this.buffer.append(" ");//$NON-NLS-1$
		}
	}
	printIndent();
	this.buffer.append("package ");//$NON-NLS-1$
	node.getName().accept(this);
	this.buffer.append(";\n");//$NON-NLS-1$
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:18,代码来源:NaiveASTFlattener.java

示例15: getFullyQualifiedTypeName

import org.eclipse.jdt.core.dom.PackageDeclaration; //导入依赖的package包/类
private String getFullyQualifiedTypeName(AbstractTypeDeclaration node) {
  LinkedList<String> nameParts = Lists.newLinkedList();
  nameParts.add(node.getName().toString());
  ASTNode parent = node.getParent();
  while (!(parent instanceof CompilationUnit)) {
    nameParts.addFirst(((AbstractTypeDeclaration) parent).getName().toString());
    parent = parent.getParent();
  }

  // A Java file might not have a package. Hopefully all of ours do though...
  PackageDeclaration packageDecl = ((CompilationUnit) parent).getPackage();
  if (packageDecl != null) {
    nameParts.addFirst(packageDecl.getName().toString());
  }

  return Joiner.on(".").join(nameParts);
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:18,代码来源:JavaFileParser.java


注:本文中的org.eclipse.jdt.core.dom.PackageDeclaration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。