Java Code Examples for org.eclipse.jdt.core.dom.PackageDeclaration#getStartPosition()

The following examples show how to use org.eclipse.jdt.core.dom.PackageDeclaration#getStartPosition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeContextChecker.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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());
}
 
Example 2
Source File: CopyrightManager.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Checks whether {@link CompilationUnit} has copyright header
 *
 * @param compilationUnit
 *            checked compilation unit
 * @return true if {@link CompilationUnit} has copyright header
 */
public boolean hasCopyrightsComment(final CompilationUnit compilationUnit) {
	final List<Comment> comments = getCommentList(compilationUnit);
	boolean hasCopyrights = false;
	if (!comments.isEmpty()) {
		final PackageDeclaration packageNode = compilationUnit.getPackage();
		final boolean commentBeforePackage = comments.get(0).getStartPosition() <= packageNode.getStartPosition();
		final boolean hasJavaDoc = packageNode.getJavadoc() != null;
		hasCopyrights = commentBeforePackage || hasJavaDoc;
	}
	return hasCopyrights;
}
 
Example 3
Source File: ImportRewriteAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private int getPackageStatementEndPos(CompilationUnit root) {
	PackageDeclaration packDecl= root.getPackage();
	if (packDecl != null) {
		int afterPackageStatementPos= -1;
		int lineNumber= root.getLineNumber(packDecl.getStartPosition() + packDecl.getLength());
		if (lineNumber >= 0) {
			int lineAfterPackage= lineNumber + 1;
			afterPackageStatementPos= root.getPosition(lineAfterPackage, 0);
		}
		if (afterPackageStatementPos < 0) {
			this.flags|= F_NEEDS_LEADING_DELIM;
			return packDecl.getStartPosition() + packDecl.getLength();
		}
		int firstTypePos= getFirstTypeBeginPos(root);
		if (firstTypePos != -1 && firstTypePos <= afterPackageStatementPos) {
			this.flags|= F_NEEDS_TRAILING_DELIM;
			if (firstTypePos == afterPackageStatementPos) {
				this.flags|= F_NEEDS_LEADING_DELIM;
			}
			return firstTypePos;
		}
		this.flags|= F_NEEDS_LEADING_DELIM;
		return afterPackageStatementPos; // insert a line after after package statement
	}
	this.flags |= F_NEEDS_TRAILING_DELIM;
	return 0;
}
 
Example 4
Source File: JavaParseTreeBuilder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(PackageDeclaration node) {
       new JavaNode(getCurrentContainer(), JavaNode.PACKAGE, null, node.getStartPosition(), node.getLength());
       return false;
   }