Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8c30dc0b8f2e9b2997a8b8f06eed42dd6f8f2fa2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*******************************************************************************
  * Copyright (c) 2010 Red Hat, Inc.
  * Distributed under license by Red Hat, Inc. All rights reserved.
  * This program is made available under the terms of the
  * Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  *
  * Contributor:
  *     Red Hat, Inc. - initial API and implementation
  ******************************************************************************/
package org.eclipse.jpt.core.internal.utility.jdt;

import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.IPackageBinding;
import org.eclipse.jdt.core.dom.PackageDeclaration;
import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.jpt.core.utility.jdt.AnnotationEditFormatter;
import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration;
import org.eclipse.jpt.core.utility.jdt.Package;
import org.eclipse.jpt.utility.CommandExecutor;

/**
 * @author Dmitry Geraskov
 *
 */

public class JDTPackage extends JDTAnnotatedElement implements Package {
	
	
	protected JDTPackage(PackageDeclaration declaringPackage,
			ICompilationUnit compilationUnit,
			CommandExecutor modifySharedDocumentCommandExecutor) {
		super(declaringPackage.getName().getFullyQualifiedName(), 
				compilationUnit,
				modifySharedDocumentCommandExecutor);
	}

	public JDTPackage(
			PackageDeclaration declaringPackage,
			ICompilationUnit compilationUnit,
			CommandExecutor modifySharedDocumentCommandExecutor,
			AnnotationEditFormatter annotationEditFormatter) {
		super(declaringPackage.getName().getFullyQualifiedName(),
				compilationUnit, modifySharedDocumentCommandExecutor, annotationEditFormatter);
	}

	@Override
	public ModifiedDeclaration getModifiedDeclaration(CompilationUnit astRoot) {
		return new JDTModifiedDeclaration(this.getBodyDeclaration(astRoot));
	}

	public IPackageBinding getBinding(CompilationUnit astRoot) {
		PackageDeclaration pd = this.getBodyDeclaration(astRoot);
		return (pd == null) ? null : pd.resolveBinding();
	}

	public PackageDeclaration getBodyDeclaration(CompilationUnit astRoot) {
		return astRoot.getPackage();
	}

	public TextRange getNameTextRange(CompilationUnit astRoot) {
		return new ASTNodeTextRange(this.getBodyDeclaration(astRoot).getName());
	}
}

Back to the top