Fix ADT to use the new sdklib API
ManifestConstants got renamed AndroidManifest but I forgot to update ADT. Change-Id: I60d40c63a67968c31789e91f14020c61114907ca
This commit is contained in:
@@ -27,7 +27,7 @@ import com.android.ide.eclipse.adt.internal.sdk.Sdk;
|
|||||||
import com.android.sdklib.AndroidVersion;
|
import com.android.sdklib.AndroidVersion;
|
||||||
import com.android.sdklib.IAndroidTarget;
|
import com.android.sdklib.IAndroidTarget;
|
||||||
import com.android.sdklib.SdkConstants;
|
import com.android.sdklib.SdkConstants;
|
||||||
import com.android.sdklib.xml.ManifestConstants;
|
import com.android.sdklib.xml.AndroidManifest;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IContainer;
|
import org.eclipse.core.resources.IContainer;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
@@ -336,7 +336,7 @@ public class PreCompilerBuilder extends BaseBuilder {
|
|||||||
// integer minSdk when the target is a preview => fatal error
|
// integer minSdk when the target is a preview => fatal error
|
||||||
String msg = String.format(
|
String msg = String.format(
|
||||||
"Platform %1$s is a preview and requires appication manifest to set %2$s to '%1$s'",
|
"Platform %1$s is a preview and requires appication manifest to set %2$s to '%1$s'",
|
||||||
codename, ManifestConstants.ATTRIBUTE_MIN_SDK_VERSION);
|
codename, AndroidManifest.ATTRIBUTE_MIN_SDK_VERSION);
|
||||||
AdtPlugin.printErrorToConsole(project, msg);
|
AdtPlugin.printErrorToConsole(project, msg);
|
||||||
BaseProjectHelper.addMarker(manifest, AdtConstants.MARKER_ADT, msg,
|
BaseProjectHelper.addMarker(manifest, AdtConstants.MARKER_ADT, msg,
|
||||||
IMarker.SEVERITY_ERROR);
|
IMarker.SEVERITY_ERROR);
|
||||||
@@ -345,7 +345,7 @@ public class PreCompilerBuilder extends BaseBuilder {
|
|||||||
// integer minSdk is not high enough for the target => warning
|
// integer minSdk is not high enough for the target => warning
|
||||||
String msg = String.format(
|
String msg = String.format(
|
||||||
"Attribute %1$s (%2$d) is lower than the project target API level (%3$d)",
|
"Attribute %1$s (%2$d) is lower than the project target API level (%3$d)",
|
||||||
ManifestConstants.ATTRIBUTE_MIN_SDK_VERSION,
|
AndroidManifest.ATTRIBUTE_MIN_SDK_VERSION,
|
||||||
minSdkValue, projectVersion.getApiLevel());
|
minSdkValue, projectVersion.getApiLevel());
|
||||||
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project, msg);
|
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project, msg);
|
||||||
BaseProjectHelper.addMarker(manifest, AdtConstants.MARKER_ADT, msg,
|
BaseProjectHelper.addMarker(manifest, AdtConstants.MARKER_ADT, msg,
|
||||||
@@ -354,7 +354,7 @@ public class PreCompilerBuilder extends BaseBuilder {
|
|||||||
// integer minSdk is too high for the target => warning
|
// integer minSdk is too high for the target => warning
|
||||||
String msg = String.format(
|
String msg = String.format(
|
||||||
"Attribute %1$s (%2$d) is higher than the project target API level (%3$d)",
|
"Attribute %1$s (%2$d) is higher than the project target API level (%3$d)",
|
||||||
ManifestConstants.ATTRIBUTE_MIN_SDK_VERSION,
|
AndroidManifest.ATTRIBUTE_MIN_SDK_VERSION,
|
||||||
minSdkValue, projectVersion.getApiLevel());
|
minSdkValue, projectVersion.getApiLevel());
|
||||||
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project, msg);
|
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project, msg);
|
||||||
BaseProjectHelper.addMarker(manifest, AdtConstants.MARKER_ADT, msg,
|
BaseProjectHelper.addMarker(manifest, AdtConstants.MARKER_ADT, msg,
|
||||||
@@ -368,7 +368,7 @@ public class PreCompilerBuilder extends BaseBuilder {
|
|||||||
// platform is not a preview => fatal error
|
// platform is not a preview => fatal error
|
||||||
String msg = String.format(
|
String msg = String.format(
|
||||||
"Manifest attribute '%1$s' is set to '%2$s'. Integer is expected.",
|
"Manifest attribute '%1$s' is set to '%2$s'. Integer is expected.",
|
||||||
ManifestConstants.ATTRIBUTE_MIN_SDK_VERSION, minSdkVersion);
|
AndroidManifest.ATTRIBUTE_MIN_SDK_VERSION, minSdkVersion);
|
||||||
AdtPlugin.printErrorToConsole(project, msg);
|
AdtPlugin.printErrorToConsole(project, msg);
|
||||||
BaseProjectHelper.addMarker(manifest, AdtConstants.MARKER_ADT, msg,
|
BaseProjectHelper.addMarker(manifest, AdtConstants.MARKER_ADT, msg,
|
||||||
IMarker.SEVERITY_ERROR);
|
IMarker.SEVERITY_ERROR);
|
||||||
@@ -377,7 +377,7 @@ public class PreCompilerBuilder extends BaseBuilder {
|
|||||||
// platform and manifest codenames don't match => fatal error.
|
// platform and manifest codenames don't match => fatal error.
|
||||||
String msg = String.format(
|
String msg = String.format(
|
||||||
"Value of manifest attribute '%1$s' does not match platform codename '%2$s'",
|
"Value of manifest attribute '%1$s' does not match platform codename '%2$s'",
|
||||||
ManifestConstants.ATTRIBUTE_MIN_SDK_VERSION, codename);
|
AndroidManifest.ATTRIBUTE_MIN_SDK_VERSION, codename);
|
||||||
AdtPlugin.printErrorToConsole(project, msg);
|
AdtPlugin.printErrorToConsole(project, msg);
|
||||||
BaseProjectHelper.addMarker(manifest, AdtConstants.MARKER_ADT, msg,
|
BaseProjectHelper.addMarker(manifest, AdtConstants.MARKER_ADT, msg,
|
||||||
IMarker.SEVERITY_ERROR);
|
IMarker.SEVERITY_ERROR);
|
||||||
@@ -390,7 +390,7 @@ public class PreCompilerBuilder extends BaseBuilder {
|
|||||||
String codename = projectTarget.getVersion().getCodename();
|
String codename = projectTarget.getVersion().getCodename();
|
||||||
String msg = String.format(
|
String msg = String.format(
|
||||||
"Platform %1$s is a preview and requires appication manifests to set %2$s to '%1$s'",
|
"Platform %1$s is a preview and requires appication manifests to set %2$s to '%1$s'",
|
||||||
codename, ManifestConstants.ATTRIBUTE_MIN_SDK_VERSION);
|
codename, AndroidManifest.ATTRIBUTE_MIN_SDK_VERSION);
|
||||||
AdtPlugin.printErrorToConsole(project, msg);
|
AdtPlugin.printErrorToConsole(project, msg);
|
||||||
BaseProjectHelper.addMarker(manifest, AdtConstants.MARKER_ADT, msg,
|
BaseProjectHelper.addMarker(manifest, AdtConstants.MARKER_ADT, msg,
|
||||||
IMarker.SEVERITY_ERROR);
|
IMarker.SEVERITY_ERROR);
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ import com.android.ide.eclipse.adt.internal.editors.manifest.descriptors.Android
|
|||||||
import com.android.ide.eclipse.adt.internal.editors.ui.SectionHelper;
|
import com.android.ide.eclipse.adt.internal.editors.ui.SectionHelper;
|
||||||
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
|
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
|
||||||
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiTextAttributeNode;
|
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiTextAttributeNode;
|
||||||
import com.android.ide.eclipse.adt.internal.project.AndroidManifestParser;
|
|
||||||
import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper;
|
import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper;
|
||||||
|
import com.android.sdklib.xml.AndroidManifest;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
@@ -94,9 +94,9 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
private IPostTypeCreationAction mPostCreationAction;
|
private IPostTypeCreationAction mPostCreationAction;
|
||||||
private boolean mMandatory;
|
private boolean mMandatory;
|
||||||
private final boolean mDefaultToProjectOnly;
|
private final boolean mDefaultToProjectOnly;
|
||||||
|
|
||||||
private class HierarchyTypeSelection extends TypeSelectionExtension {
|
private class HierarchyTypeSelection extends TypeSelectionExtension {
|
||||||
|
|
||||||
private IJavaProject mJavaProject;
|
private IJavaProject mJavaProject;
|
||||||
private IType mReferenceType;
|
private IType mReferenceType;
|
||||||
private Button mProjectOnly;
|
private Button mProjectOnly;
|
||||||
@@ -112,13 +112,13 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
public ITypeInfoFilterExtension getFilterExtension() {
|
public ITypeInfoFilterExtension getFilterExtension() {
|
||||||
return new ITypeInfoFilterExtension() {
|
return new ITypeInfoFilterExtension() {
|
||||||
public boolean select(ITypeInfoRequestor typeInfoRequestor) {
|
public boolean select(ITypeInfoRequestor typeInfoRequestor) {
|
||||||
|
|
||||||
boolean projectOnly = mUseProjectOnly;
|
boolean projectOnly = mUseProjectOnly;
|
||||||
|
|
||||||
String packageName = typeInfoRequestor.getPackageName();
|
String packageName = typeInfoRequestor.getPackageName();
|
||||||
String typeName = typeInfoRequestor.getTypeName();
|
String typeName = typeInfoRequestor.getTypeName();
|
||||||
String enclosingType = typeInfoRequestor.getEnclosingName();
|
String enclosingType = typeInfoRequestor.getEnclosingName();
|
||||||
|
|
||||||
// build the full class name.
|
// build the full class name.
|
||||||
StringBuilder sb = new StringBuilder(packageName);
|
StringBuilder sb = new StringBuilder(packageName);
|
||||||
sb.append('.');
|
sb.append('.');
|
||||||
@@ -127,9 +127,9 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
sb.append('.');
|
sb.append('.');
|
||||||
}
|
}
|
||||||
sb.append(typeName);
|
sb.append(typeName);
|
||||||
|
|
||||||
String className = sb.toString();
|
String className = sb.toString();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IType type = mJavaProject.findType(className);
|
IType type = mJavaProject.findType(className);
|
||||||
|
|
||||||
@@ -150,11 +150,11 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the type hierarchy and reference type is one of the super classes.
|
// get the type hierarchy and reference type is one of the super classes.
|
||||||
ITypeHierarchy hierarchy = type.newSupertypeHierarchy(
|
ITypeHierarchy hierarchy = type.newSupertypeHierarchy(
|
||||||
new NullProgressMonitor());
|
new NullProgressMonitor());
|
||||||
|
|
||||||
IType[] supertypes = hierarchy.getAllSupertypes(type);
|
IType[] supertypes = hierarchy.getAllSupertypes(type);
|
||||||
int n = supertypes.length;
|
int n = supertypes.length;
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
@@ -165,12 +165,12 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
}
|
}
|
||||||
} catch (JavaModelException e) {
|
} catch (JavaModelException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Control createContentArea(Composite parent) {
|
public Control createContentArea(Composite parent) {
|
||||||
|
|
||||||
@@ -178,10 +178,10 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
mProjectOnly.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
mProjectOnly.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||||
mProjectOnly.setText(String.format("Display classes from sources of project '%s' only",
|
mProjectOnly.setText(String.format("Display classes from sources of project '%s' only",
|
||||||
mJavaProject.getProject().getName()));
|
mJavaProject.getProject().getName()));
|
||||||
|
|
||||||
mUseProjectOnly = mDefaultToProjectOnly;
|
mUseProjectOnly = mDefaultToProjectOnly;
|
||||||
mProjectOnly.setSelection(mUseProjectOnly);
|
mProjectOnly.setSelection(mUseProjectOnly);
|
||||||
|
|
||||||
mProjectOnly.addSelectionListener(new SelectionAdapter() {
|
mProjectOnly.addSelectionListener(new SelectionAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void widgetSelected(SelectionEvent e) {
|
public void widgetSelected(SelectionEvent e) {
|
||||||
@@ -190,7 +190,7 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
getTypeSelectionComponent().triggerSearch();
|
getTypeSelectionComponent().triggerSearch();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return super.createContentArea(parent);
|
return super.createContentArea(parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,13 +216,13 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
* @param mandatory indicates if the class value is mandatory
|
* @param mandatory indicates if the class value is mandatory
|
||||||
* @param attributeDescriptor the {@link AttributeDescriptor} object linked to the Ui Node.
|
* @param attributeDescriptor the {@link AttributeDescriptor} object linked to the Ui Node.
|
||||||
* @param defaultToProjectOnly When true display classes of this project only by default.
|
* @param defaultToProjectOnly When true display classes of this project only by default.
|
||||||
* When false any class path will be considered. The user can always toggle this.
|
* When false any class path will be considered. The user can always toggle this.
|
||||||
*/
|
*/
|
||||||
public UiClassAttributeNode(String referenceClass, IPostTypeCreationAction postCreationAction,
|
public UiClassAttributeNode(String referenceClass, IPostTypeCreationAction postCreationAction,
|
||||||
boolean mandatory, AttributeDescriptor attributeDescriptor, UiElementNode uiParent,
|
boolean mandatory, AttributeDescriptor attributeDescriptor, UiElementNode uiParent,
|
||||||
boolean defaultToProjectOnly) {
|
boolean defaultToProjectOnly) {
|
||||||
super(attributeDescriptor, uiParent);
|
super(attributeDescriptor, uiParent);
|
||||||
|
|
||||||
mReferenceClass = referenceClass;
|
mReferenceClass = referenceClass;
|
||||||
mPostCreationAction = postCreationAction;
|
mPostCreationAction = postCreationAction;
|
||||||
mMandatory = mandatory;
|
mMandatory = mandatory;
|
||||||
@@ -256,7 +256,7 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
});
|
});
|
||||||
formText.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.MIDDLE));
|
formText.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.MIDDLE));
|
||||||
SectionHelper.addControlTooltip(formText, desc.getTooltip());
|
SectionHelper.addControlTooltip(formText, desc.getTooltip());
|
||||||
|
|
||||||
Composite composite = toolkit.createComposite(parent);
|
Composite composite = toolkit.createComposite(parent);
|
||||||
composite.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.MIDDLE));
|
composite.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.MIDDLE));
|
||||||
GridLayout gl = new GridLayout(2, false);
|
GridLayout gl = new GridLayout(2, false);
|
||||||
@@ -265,13 +265,13 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
// Fixes missing text borders under GTK... also requires adding a 1-pixel margin
|
// Fixes missing text borders under GTK... also requires adding a 1-pixel margin
|
||||||
// for the text field below
|
// for the text field below
|
||||||
toolkit.paintBordersFor(composite);
|
toolkit.paintBordersFor(composite);
|
||||||
|
|
||||||
final Text text = toolkit.createText(composite, getCurrentValue());
|
final Text text = toolkit.createText(composite, getCurrentValue());
|
||||||
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
|
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
|
||||||
gd.horizontalIndent = 1; // Needed by the fixed composite borders under GTK
|
gd.horizontalIndent = 1; // Needed by the fixed composite borders under GTK
|
||||||
text.setLayoutData(gd);
|
text.setLayoutData(gd);
|
||||||
Button browseButton = toolkit.createButton(composite, "Browse...", SWT.PUSH);
|
Button browseButton = toolkit.createButton(composite, "Browse...", SWT.PUSH);
|
||||||
|
|
||||||
setTextWidget(text);
|
setTextWidget(text);
|
||||||
|
|
||||||
browseButton.addSelectionListener(new SelectionAdapter() {
|
browseButton.addSelectionListener(new SelectionAdapter() {
|
||||||
@@ -282,9 +282,9 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-java doc)
|
/* (non-java doc)
|
||||||
*
|
*
|
||||||
* Add a modify listener that will check the validity of the class
|
* Add a modify listener that will check the validity of the class
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -305,12 +305,12 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
String javaPackage = getManifestPackage();
|
String javaPackage = getManifestPackage();
|
||||||
|
|
||||||
// build the fully qualified name of the class
|
// build the fully qualified name of the class
|
||||||
String className = AndroidManifestParser.combinePackageAndClassName(
|
String className = AndroidManifest.combinePackageAndClassName(
|
||||||
javaPackage, textValue);
|
javaPackage, textValue);
|
||||||
|
|
||||||
// only test the vilibility for activities.
|
// only test the vilibility for activities.
|
||||||
boolean testVisibility = AndroidConstants.CLASS_ACTIVITY.equals(
|
boolean testVisibility = AndroidConstants.CLASS_ACTIVITY.equals(
|
||||||
mReferenceClass);
|
mReferenceClass);
|
||||||
|
|
||||||
// test the class
|
// test the class
|
||||||
setErrorMessage(BaseProjectHelper.testClassForManifest(
|
setErrorMessage(BaseProjectHelper.testClassForManifest(
|
||||||
@@ -339,11 +339,11 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
|
|
||||||
private void handleBrowseClick() {
|
private void handleBrowseClick() {
|
||||||
Text text = getTextWidget();
|
Text text = getTextWidget();
|
||||||
|
|
||||||
// we need to get the project of the manifest.
|
// we need to get the project of the manifest.
|
||||||
IProject project = getProject();
|
IProject project = getProject();
|
||||||
if (project != null) {
|
if (project != null) {
|
||||||
|
|
||||||
// Create a search scope including only the source folder of the current
|
// Create a search scope including only the source folder of the current
|
||||||
// project.
|
// project.
|
||||||
IPackageFragmentRoot[] packageFragmentRoots = getPackageFragmentRoots(project,
|
IPackageFragmentRoot[] packageFragmentRoots = getPackageFragmentRoots(project,
|
||||||
@@ -365,7 +365,7 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
if (dlg instanceof ITypeSelectionComponent) {
|
if (dlg instanceof ITypeSelectionComponent) {
|
||||||
((ITypeSelectionComponent)dlg).triggerSearch();
|
((ITypeSelectionComponent)dlg).triggerSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dlg.open() == Window.OK) {
|
if (dlg.open() == Window.OK) {
|
||||||
Object[] results = dlg.getResult();
|
Object[] results = dlg.getResult();
|
||||||
if (results.length == 1) {
|
if (results.length == 1) {
|
||||||
@@ -384,7 +384,7 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
|
|
||||||
// get the package name from the manifest.
|
// get the package name from the manifest.
|
||||||
String packageName = getManifestPackage();
|
String packageName = getManifestPackage();
|
||||||
|
|
||||||
if (className.length() == 0) {
|
if (className.length() == 0) {
|
||||||
createNewClass(packageName, null /* className */);
|
createNewClass(packageName, null /* className */);
|
||||||
} else {
|
} else {
|
||||||
@@ -398,10 +398,10 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
fullClassName = packageName + "." + className; //$NON-NLS-1$
|
fullClassName = packageName + "." + className; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// in case the type is enclosed, we need to replace the $ with .
|
// in case the type is enclosed, we need to replace the $ with .
|
||||||
fullClassName = fullClassName.replaceAll("\\$", "\\."); //$NON-NLS-1$ //$NON-NLS2$
|
fullClassName = fullClassName.replaceAll("\\$", "\\."); //$NON-NLS-1$ //$NON-NLS2$
|
||||||
|
|
||||||
// now we try to find the file that contains this class and we open it in the editor.
|
// now we try to find the file that contains this class and we open it in the editor.
|
||||||
IProject project = getProject();
|
IProject project = getProject();
|
||||||
IJavaProject javaProject = JavaCore.create(project);
|
IJavaProject javaProject = JavaCore.create(project);
|
||||||
@@ -427,7 +427,7 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IProject getProject() {
|
private IProject getProject() {
|
||||||
UiElementNode uiNode = getUiParent();
|
UiElementNode uiNode = getUiParent();
|
||||||
AndroidEditor editor = uiNode.getEditor();
|
AndroidEditor editor = uiNode.getEditor();
|
||||||
@@ -437,7 +437,7 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
IFile file = ((IFileEditorInput)input).getFile();
|
IFile file = ((IFileEditorInput)input).getFile();
|
||||||
return file.getProject();
|
return file.getProject();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,7 +449,7 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
private String getManifestPackage() {
|
private String getManifestPackage() {
|
||||||
// get the root uiNode to get the 'package' attribute value.
|
// get the root uiNode to get the 'package' attribute value.
|
||||||
UiElementNode rootNode = getUiParent().getUiRoot();
|
UiElementNode rootNode = getUiParent().getUiRoot();
|
||||||
|
|
||||||
Element xmlElement = (Element) rootNode.getXmlNode();
|
Element xmlElement = (Element) rootNode.getXmlNode();
|
||||||
|
|
||||||
if (xmlElement != null) {
|
if (xmlElement != null) {
|
||||||
@@ -485,20 +485,20 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
|
|
||||||
return result.toArray(new IPackageFragmentRoot[result.size()]);
|
return result.toArray(new IPackageFragmentRoot[result.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleNewType(IType type) {
|
private void handleNewType(IType type) {
|
||||||
Text text = getTextWidget();
|
Text text = getTextWidget();
|
||||||
|
|
||||||
// get the fully qualified name with $ to properly detect the enclosing types.
|
// get the fully qualified name with $ to properly detect the enclosing types.
|
||||||
String name = type.getFullyQualifiedName('$');
|
String name = type.getFullyQualifiedName('$');
|
||||||
|
|
||||||
String packageValue = getManifestPackage();
|
String packageValue = getManifestPackage();
|
||||||
|
|
||||||
// check if the class doesn't start with the package.
|
// check if the class doesn't start with the package.
|
||||||
if (packageValue.length() > 0 && name.startsWith(packageValue)) {
|
if (packageValue.length() > 0 && name.startsWith(packageValue)) {
|
||||||
// if it does, we remove the package and the first dot.
|
// if it does, we remove the package and the first dot.
|
||||||
name = name.substring(packageValue.length() + 1);
|
name = name.substring(packageValue.length() + 1);
|
||||||
|
|
||||||
// look for how many segments we have left.
|
// look for how many segments we have left.
|
||||||
// if one, just write it that way.
|
// if one, just write it that way.
|
||||||
// if more than one, write it with a leading dot.
|
// if more than one, write it with a leading dot.
|
||||||
@@ -512,14 +512,14 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
text.setText(name);
|
text.setText(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createNewClass(String packageName, String className) {
|
private void createNewClass(String packageName, String className) {
|
||||||
// create the wizard page for the class creation, and configure it
|
// create the wizard page for the class creation, and configure it
|
||||||
NewClassWizardPage page = new NewClassWizardPage();
|
NewClassWizardPage page = new NewClassWizardPage();
|
||||||
|
|
||||||
// set the parent class
|
// set the parent class
|
||||||
page.setSuperClass(mReferenceClass, true /* canBeModified */);
|
page.setSuperClass(mReferenceClass, true /* canBeModified */);
|
||||||
|
|
||||||
// get the source folders as java elements.
|
// get the source folders as java elements.
|
||||||
IPackageFragmentRoot[] roots = getPackageFragmentRoots(getProject(),
|
IPackageFragmentRoot[] roots = getPackageFragmentRoots(getProject(),
|
||||||
true /*include_containers*/);
|
true /*include_containers*/);
|
||||||
@@ -527,7 +527,7 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
IPackageFragmentRoot currentRoot = null;
|
IPackageFragmentRoot currentRoot = null;
|
||||||
IPackageFragment currentFragment = null;
|
IPackageFragment currentFragment = null;
|
||||||
int packageMatchCount = -1;
|
int packageMatchCount = -1;
|
||||||
|
|
||||||
for (IPackageFragmentRoot root : roots) {
|
for (IPackageFragmentRoot root : roots) {
|
||||||
// Get the java element for the package.
|
// Get the java element for the package.
|
||||||
// This method is said to always return a IPackageFragment even if the
|
// This method is said to always return a IPackageFragment even if the
|
||||||
@@ -564,7 +564,7 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<IPackageFragment> createdFragments = null;
|
ArrayList<IPackageFragment> createdFragments = null;
|
||||||
|
|
||||||
if (currentRoot != null) {
|
if (currentRoot != null) {
|
||||||
@@ -578,7 +578,7 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
// know what to delete in case of a cancel.
|
// know what to delete in case of a cancel.
|
||||||
try {
|
try {
|
||||||
createdFragments = new ArrayList<IPackageFragment>();
|
createdFragments = new ArrayList<IPackageFragment>();
|
||||||
|
|
||||||
int totalCount = packageName.split("\\.").length; //$NON-NLS-1$
|
int totalCount = packageName.split("\\.").length; //$NON-NLS-1$
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int index = -1;
|
int index = -1;
|
||||||
@@ -587,7 +587,7 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
index = packageName.indexOf('.', index+1);
|
index = packageName.indexOf('.', index+1);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the rest of the segments, except for the last one as indexOf will
|
// create the rest of the segments, except for the last one as indexOf will
|
||||||
// return -1;
|
// return -1;
|
||||||
while (count < totalCount - 1) {
|
while (count < totalCount - 1) {
|
||||||
@@ -597,11 +597,11 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
packageName.substring(0, index),
|
packageName.substring(0, index),
|
||||||
true /* force*/, new NullProgressMonitor()));
|
true /* force*/, new NullProgressMonitor()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the last package
|
// create the last package
|
||||||
createdFragments.add(currentRoot.createPackageFragment(
|
createdFragments.add(currentRoot.createPackageFragment(
|
||||||
packageName, true /* force*/, new NullProgressMonitor()));
|
packageName, true /* force*/, new NullProgressMonitor()));
|
||||||
|
|
||||||
// set the root and fragment in the Wizard page
|
// set the root and fragment in the Wizard page
|
||||||
page.setPackageFragmentRoot(currentRoot, true /* canBeModified*/);
|
page.setPackageFragmentRoot(currentRoot, true /* canBeModified*/);
|
||||||
page.setPackageFragment(createdFragments.get(createdFragments.size()-1),
|
page.setPackageFragment(createdFragments.get(createdFragments.size()-1),
|
||||||
@@ -626,27 +626,27 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
// if we haven't found a valid fragment, we set the root to the first source folder.
|
// if we haven't found a valid fragment, we set the root to the first source folder.
|
||||||
page.setPackageFragmentRoot(roots[0], true /* canBeModified*/);
|
page.setPackageFragmentRoot(roots[0], true /* canBeModified*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we have a starting class name we use it
|
// if we have a starting class name we use it
|
||||||
if (className != null) {
|
if (className != null) {
|
||||||
page.setTypeName(className, true /* canBeModified*/);
|
page.setTypeName(className, true /* canBeModified*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the action that will open it the wizard.
|
// create the action that will open it the wizard.
|
||||||
OpenNewClassWizardAction action = new OpenNewClassWizardAction();
|
OpenNewClassWizardAction action = new OpenNewClassWizardAction();
|
||||||
action.setConfiguredWizardPage(page);
|
action.setConfiguredWizardPage(page);
|
||||||
action.run();
|
action.run();
|
||||||
IJavaElement element = action.getCreatedElement();
|
IJavaElement element = action.getCreatedElement();
|
||||||
|
|
||||||
if (element != null) {
|
if (element != null) {
|
||||||
if (element.getElementType() == IJavaElement.TYPE) {
|
if (element.getElementType() == IJavaElement.TYPE) {
|
||||||
|
|
||||||
IType type = (IType)element;
|
IType type = (IType)element;
|
||||||
|
|
||||||
if (mPostCreationAction != null) {
|
if (mPostCreationAction != null) {
|
||||||
mPostCreationAction.processNewType(type);
|
mPostCreationAction.processNewType(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleNewType(type);
|
handleNewType(type);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -663,7 +663,7 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the error messages. If message is <code>null</code>, the message is removed.
|
* Sets the error messages. If message is <code>null</code>, the message is removed.
|
||||||
* @param message the message to set, or <code>null</code> to remove the current message
|
* @param message the message to set, or <code>null</code> to remove the current message
|
||||||
@@ -679,7 +679,7 @@ public class UiClassAttributeNode extends UiTextAttributeNode {
|
|||||||
getManagedForm().getMessageManager().removeMessage(textWidget, textWidget);
|
getManagedForm().getMessageManager().removeMessage(textWidget, textWidget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getPossibleValues(String prefix) {
|
public String[] getPossibleValues(String prefix) {
|
||||||
// TODO: compute a list of existing classes for content assist completion
|
// TODO: compute a list of existing classes for content assist completion
|
||||||
|
|||||||
Reference in New Issue
Block a user