blob: 79b621d8b594054a256e7db0ea892af28525b61a (
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*******************************************************************************
* Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are 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.
*
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.common.core.internal.resource.java;
import org.eclipse.core.resources.IFile;
import org.eclipse.jpt.common.core.AnnotationProvider;
import org.eclipse.jpt.common.core.resource.java.JavaResourceNode;
import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
import org.eclipse.jpt.common.utility.internal.model.AspectChangeSupport;
import org.eclipse.jpt.common.utility.internal.model.ChangeSupport;
/**
* Java resource containment hierarchy
*/
public abstract class AbstractJavaResourceNode
extends AbstractModel
implements JavaResourceNode
{
protected final JavaResourceNode parent;
// ********** constructor **********
protected AbstractJavaResourceNode(JavaResourceNode parent) {
super();
this.checkParent(parent);
this.parent = parent;
}
public JavaResourceNode getParent() {
return this.parent;
}
// ********** parent **********
protected void checkParent(JavaResourceNode p) {
if (p == null) {
if (this.requiresParent()) {
throw new IllegalArgumentException("'parent' cannot be null"); //$NON-NLS-1$
}
} else {
if (this.forbidsParent()) {
throw new IllegalArgumentException("'parent' must be null"); //$NON-NLS-1$
}
}
}
protected boolean requiresParent() {
return true;
}
protected boolean forbidsParent() {
return ! this.requiresParent(); // assume 'parent' is not optional
}
// ********** change support callback hook **********
@Override
protected final ChangeSupport buildChangeSupport() {
return new AspectChangeSupport(this, this.buildChangeSupportListener());
}
private AspectChangeSupport.Listener buildChangeSupportListener() {
return new AspectChangeSupport.Listener() {
public void aspectChanged(String aspectName) {
AbstractJavaResourceNode.this.aspectChanged(aspectName);
}
};
}
/**
* ignore the aspect name, we notify listeners of *every* change
*/
protected void aspectChanged(@SuppressWarnings("unused") String aspectName) {
this.getRoot().resourceModelChanged();
}
// ********** JavaResourceNode implementation **********
/**
* @see org.eclipse.jpt.common.core.internal.resource.java.binary.RootBinaryNode#getRoot()
* @see org.eclipse.jpt.common.core.internal.resource.java.source.SourceCompilationUnit#getRoot()
*/
public Root getRoot() {
return this.parent.getRoot();
}
public IFile getFile() {
return this.getRoot().getFile();
}
// ********** convenience methods **********
protected AnnotationProvider getAnnotationProvider() {
return this.getRoot().getAnnotationProvider();
}
}
|