0001: /*
0002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
0003: * notice. All rights reserved.
0004: */
0005: package org.terracotta.dso;
0006:
0007: import org.apache.commons.io.IOUtils;
0008: import org.apache.commons.lang.StringUtils;
0009: import org.apache.xmlbeans.XmlObject;
0010: import org.apache.xmlbeans.XmlString;
0011: import org.eclipse.core.resources.IContainer;
0012: import org.eclipse.core.resources.IFile;
0013: import org.eclipse.core.resources.IFolder;
0014: import org.eclipse.core.resources.IMarker;
0015: import org.eclipse.core.resources.IProject;
0016: import org.eclipse.core.resources.IResource;
0017: import org.eclipse.core.runtime.CoreException;
0018: import org.eclipse.jdt.core.Flags;
0019: import org.eclipse.jdt.core.IClassFile;
0020: import org.eclipse.jdt.core.ICompilationUnit;
0021: import org.eclipse.jdt.core.IField;
0022: import org.eclipse.jdt.core.IJavaElement;
0023: import org.eclipse.jdt.core.IJavaProject;
0024: import org.eclipse.jdt.core.IMethod;
0025: import org.eclipse.jdt.core.IPackageDeclaration;
0026: import org.eclipse.jdt.core.IPackageFragment;
0027: import org.eclipse.jdt.core.IPackageFragmentRoot;
0028: import org.eclipse.jdt.core.IType;
0029: import org.eclipse.jdt.core.JavaCore;
0030: import org.eclipse.jdt.core.JavaModelException;
0031: import org.eclipse.jdt.core.dom.IMethodBinding;
0032: import org.eclipse.jdt.core.dom.MethodDeclaration;
0033: import org.eclipse.jdt.core.search.IJavaSearchScope;
0034: import org.eclipse.jdt.core.search.SearchEngine;
0035: import org.eclipse.jface.text.Document;
0036: import org.eclipse.jface.text.FindReplaceDocumentAdapter;
0037: import org.eclipse.jface.text.IDocument;
0038: import org.eclipse.jface.text.IRegion;
0039: import org.eclipse.ui.texteditor.MarkerUtilities;
0040: import org.osgi.framework.BundleException;
0041: import org.terracotta.dso.editors.ConfigurationEditor;
0042:
0043: import com.tc.aspectwerkz.reflect.MemberInfo;
0044: import com.tc.aspectwerkz.reflect.MethodInfo;
0045: import com.terracottatech.config.AdditionalBootJarClasses;
0046: import com.terracottatech.config.Application;
0047: import com.terracottatech.config.Autolock;
0048: import com.terracottatech.config.ClassExpression;
0049: import com.terracottatech.config.Client;
0050: import com.terracottatech.config.DistributedMethods;
0051: import com.terracottatech.config.DsoApplication;
0052: import com.terracottatech.config.Include;
0053: import com.terracottatech.config.InstrumentedClasses;
0054: import com.terracottatech.config.LockLevel;
0055: import com.terracottatech.config.Locks;
0056: import com.terracottatech.config.Module;
0057: import com.terracottatech.config.Modules;
0058: import com.terracottatech.config.NamedLock;
0059: import com.terracottatech.config.Root;
0060: import com.terracottatech.config.Roots;
0061: import com.terracottatech.config.Servers;
0062: import com.terracottatech.config.TransientFields;
0063: import com.terracottatech.config.DistributedMethods.MethodExpression;
0064: import com.terracottatech.config.TcConfigDocument.TcConfig;
0065:
0066: import java.io.InputStream;
0067: import java.net.URL;
0068: import java.util.ArrayList;
0069: import java.util.Arrays;
0070: import java.util.HashMap;
0071:
0072: /**
0073: * Utility singleton for use by the various popup actions in org.terracotta.dso.popup.actions.
0074: *
0075: * @see org.terracotta.dso.actions.AdaptableAction
0076: * @see org.terracotta.dso.actions.AutolockAction
0077: * @see org.terracotta.dso.actions.BootJarTypeAction
0078: * @see org.terracotta.dso.actions.DistributedMethodAction
0079: * @see org.terracotta.dso.actions.ExcludedTypeAction
0080: * @see org.terracotta.dso.actions.NameLockedAction
0081: * @see org.terracotta.dso.actions.RootFieldAction
0082: * @see org.terracotta.dso.actions.TransientFieldAction
0083: */
0084:
0085: public class ConfigurationHelper {
0086: private TcPlugin m_plugin;
0087: private IProject m_project;
0088: private IJavaProject m_javaProject;
0089: private PatternHelper m_patternHelper;
0090:
0091: public ConfigurationHelper(IProject project) {
0092: m_plugin = TcPlugin.getDefault();
0093: m_project = project;
0094: m_javaProject = JavaCore.create(m_project);
0095: m_patternHelper = PatternHelper.getHelper();
0096: }
0097:
0098: public boolean isAdaptable(IJavaElement element) {
0099: if (element instanceof ICompilationUnit) {
0100: return isAdaptable((ICompilationUnit) element);
0101: } else if (element instanceof IClassFile) {
0102: return isAdaptable((IClassFile) element);
0103: } else if (element instanceof IType) {
0104: return isAdaptable((IType) element);
0105: } else if (element instanceof IPackageDeclaration) {
0106: return isAdaptable((IPackageDeclaration) element);
0107: } else if (element instanceof IPackageFragment) {
0108: return isAdaptable((IPackageFragment) element);
0109: } else if (element instanceof IJavaProject) {
0110: return isAdaptable((IJavaProject) element);
0111: }
0112:
0113: return false;
0114: }
0115:
0116: public boolean isAdaptable(ICompilationUnit module) {
0117: return isAdaptable(module.findPrimaryType());
0118: }
0119:
0120: public boolean isAdaptable(IClassFile classFile) {
0121: try {
0122: return isAdaptable(classFile.getType());
0123: } catch (Exception e) {
0124: return false;
0125: }
0126: }
0127:
0128: public boolean isAdaptable(IType type) {
0129: if (type != null) {
0130: return m_plugin.isBootClass(type) || isTypeAdaptable(type);
0131: }
0132: return false;
0133: }
0134:
0135: private Boolean isTypeAdaptable(IType type,
0136: InstrumentedClasses instrumentedClasses) {
0137: if (instrumentedClasses != null) {
0138: XmlObject[] objects = instrumentedClasses.selectPath("*");
0139:
0140: if (objects != null && objects.length > 0) {
0141: for (int i = objects.length - 1; i >= 0; i--) {
0142: XmlObject object = objects[i];
0143:
0144: if (object instanceof Include) {
0145: String expr = ((Include) object)
0146: .getClassExpression();
0147: if (m_patternHelper.matchesType(expr, type)) {
0148: return Boolean.TRUE;
0149: }
0150: } else if (object instanceof ClassExpression) {
0151: String expr = ((ClassExpression) object)
0152: .getStringValue();
0153: if (m_patternHelper.matchesType(expr, type)) {
0154: return Boolean.FALSE;
0155: }
0156: }
0157: }
0158: }
0159: }
0160: return null;
0161: }
0162:
0163: public boolean isTypeAdaptable(IType type) {
0164: TcConfig config = getConfig();
0165:
0166: if (config != null) {
0167: InstrumentedClasses instrumentedClasses = getInstrumentedClasses();
0168: if (instrumentedClasses != null) {
0169: Boolean adaptable = isTypeAdaptable(type,
0170: instrumentedClasses);
0171: if (adaptable != null) {
0172: return adaptable;
0173: }
0174: }
0175:
0176: ModulesConfiguration modulesConfig = m_plugin
0177: .getModulesConfiguration(m_project);
0178: if (modulesConfig != null) {
0179: instrumentedClasses = modulesConfig.getApplication()
0180: .getInstrumentedClasses();
0181: if (instrumentedClasses != null) {
0182: Boolean adaptable = isTypeAdaptable(type,
0183: instrumentedClasses);
0184: if (adaptable != null) {
0185: return adaptable;
0186: }
0187: }
0188: }
0189: }
0190:
0191: return false;
0192: }
0193:
0194: private Boolean isAdaptable(IPackageDeclaration packageDecl,
0195: InstrumentedClasses instrumentedClasses) {
0196: if (instrumentedClasses != null) {
0197: XmlObject[] objects = instrumentedClasses.selectPath("*");
0198:
0199: if (objects != null && objects.length > 0) {
0200: for (int i = objects.length - 1; i >= 0; i--) {
0201: XmlObject object = objects[i];
0202:
0203: if (object instanceof Include) {
0204: String expr = ((Include) object)
0205: .getClassExpression();
0206: if (m_patternHelper.matchesPackageDeclaration(
0207: expr, packageDecl)) {
0208: return Boolean.TRUE;
0209: }
0210: } else if (object instanceof ClassExpression) {
0211: String expr = ((ClassExpression) object)
0212: .getStringValue();
0213: if (m_patternHelper.matchesPackageDeclaration(
0214: expr, packageDecl)) {
0215: return Boolean.FALSE;
0216: }
0217: }
0218: }
0219: }
0220: }
0221: return null;
0222: }
0223:
0224: public boolean isAdaptable(IPackageDeclaration packageDecl) {
0225: TcConfig config = getConfig();
0226:
0227: if (config != null) {
0228: InstrumentedClasses instrumentedClasses = getInstrumentedClasses();
0229:
0230: if (instrumentedClasses != null) {
0231: Boolean adaptable = isAdaptable(packageDecl,
0232: instrumentedClasses);
0233: if (adaptable != null) {
0234: return adaptable;
0235: }
0236: }
0237:
0238: ModulesConfiguration modulesConfig = m_plugin
0239: .getModulesConfiguration(m_project);
0240: if (modulesConfig != null) {
0241: instrumentedClasses = modulesConfig.getApplication()
0242: .getInstrumentedClasses();
0243: if (instrumentedClasses != null) {
0244: Boolean adaptable = isAdaptable(packageDecl,
0245: instrumentedClasses);
0246: if (adaptable != null) {
0247: return adaptable;
0248: }
0249: }
0250: }
0251: }
0252:
0253: return false;
0254: }
0255:
0256: private Boolean isAdaptable(IPackageFragment fragment,
0257: InstrumentedClasses instrumentedClasses) {
0258: if (instrumentedClasses != null) {
0259: XmlObject[] objects = instrumentedClasses.selectPath("*");
0260:
0261: if (objects != null && objects.length > 0) {
0262: for (int i = objects.length - 1; i >= 0; i--) {
0263: XmlObject object = objects[i];
0264:
0265: if (object instanceof Include) {
0266: String expr = ((Include) object)
0267: .getClassExpression();
0268: if (m_patternHelper.matchesPackageFragment(
0269: expr, fragment)) {
0270: return Boolean.TRUE;
0271: }
0272: } else if (object instanceof ClassExpression) {
0273: String expr = ((ClassExpression) object)
0274: .getStringValue();
0275: if (m_patternHelper.matchesPackageFragment(
0276: expr, fragment)) {
0277: return Boolean.FALSE;
0278: }
0279: }
0280: }
0281: }
0282: }
0283: return null;
0284: }
0285:
0286: public boolean isAdaptable(IPackageFragment fragment) {
0287: TcConfig config = getConfig();
0288:
0289: if (config != null) {
0290: InstrumentedClasses instrumentedClasses = getInstrumentedClasses();
0291:
0292: if (instrumentedClasses != null) {
0293: Boolean adaptable = isAdaptable(fragment,
0294: instrumentedClasses);
0295: if (adaptable != null) {
0296: return adaptable;
0297: }
0298: }
0299:
0300: ModulesConfiguration modulesConfig = m_plugin
0301: .getModulesConfiguration(m_project);
0302: if (modulesConfig != null) {
0303: instrumentedClasses = modulesConfig.getApplication()
0304: .getInstrumentedClasses();
0305: if (instrumentedClasses != null) {
0306: Boolean adaptable = isAdaptable(fragment,
0307: instrumentedClasses);
0308: if (adaptable != null) {
0309: return adaptable;
0310: }
0311: }
0312: }
0313: }
0314:
0315: return false;
0316: }
0317:
0318: public boolean isAdaptable(final IJavaProject javaProject) {
0319: if (javaProject != null) {
0320: IPackageFragment[] fragments = getSourceFragments(javaProject);
0321:
0322: if (fragments.length > 0) {
0323: for (int i = 0; i < fragments.length; i++) {
0324: if (!isAdaptable(fragments[i])) {
0325: return false;
0326: }
0327: }
0328:
0329: return true;
0330: }
0331: }
0332:
0333: return false;
0334: }
0335:
0336: private Boolean isAdaptable(String classExpr,
0337: InstrumentedClasses instrumentedClasses) {
0338: if (instrumentedClasses != null) {
0339: XmlObject[] objects = instrumentedClasses.selectPath("*");
0340:
0341: if (objects != null && objects.length > 0) {
0342: for (int i = objects.length - 1; i >= 0; i--) {
0343: XmlObject object = objects[i];
0344:
0345: if (object instanceof Include) {
0346: String expr = ((Include) object)
0347: .getClassExpression();
0348: if (m_patternHelper.matchesClass(expr,
0349: classExpr)) {
0350: return Boolean.TRUE;
0351: }
0352: } else if (object instanceof ClassExpression) {
0353: String expr = ((ClassExpression) object)
0354: .getStringValue();
0355: if (m_patternHelper.matchesClass(expr,
0356: classExpr)) {
0357: return Boolean.FALSE;
0358: }
0359: }
0360: }
0361: }
0362: }
0363: return null;
0364: }
0365:
0366: public boolean isAdaptable(String classExpr) {
0367: TcConfig config = getConfig();
0368:
0369: if (config != null) {
0370: InstrumentedClasses instrumentedClasses = getInstrumentedClasses();
0371:
0372: if (instrumentedClasses != null) {
0373: Boolean adaptable = isAdaptable(classExpr,
0374: instrumentedClasses);
0375: if (adaptable != null) {
0376: return adaptable;
0377: }
0378: }
0379:
0380: ModulesConfiguration modulesConfig = m_plugin
0381: .getModulesConfiguration(m_project);
0382: if (modulesConfig != null) {
0383: instrumentedClasses = modulesConfig.getApplication()
0384: .getInstrumentedClasses();
0385: if (instrumentedClasses != null) {
0386: Boolean adaptable = isAdaptable(classExpr,
0387: instrumentedClasses);
0388: if (adaptable != null) {
0389: return adaptable;
0390: }
0391: }
0392: }
0393: }
0394:
0395: return m_plugin.isBootClass(classExpr);
0396: }
0397:
0398: public Include includeRuleFor(String classExpr) {
0399: TcConfig config = getConfig();
0400:
0401: if (config != null) {
0402: InstrumentedClasses classes = getInstrumentedClasses();
0403:
0404: if (classes != null) {
0405: XmlObject[] objects = classes.selectPath("*");
0406:
0407: if (objects != null && objects.length > 0) {
0408: for (int i = objects.length - 1; i >= 0; i--) {
0409: XmlObject object = objects[i];
0410:
0411: if (object instanceof Include) {
0412: String expr = ((Include) object)
0413: .getClassExpression();
0414: if (expr != null && expr.equals(classExpr)) {
0415: return (Include) object;
0416: }
0417: }
0418: }
0419: }
0420: }
0421: }
0422:
0423: return null;
0424: }
0425:
0426: public Include ensureIncludeRuleFor(String classExpr) {
0427: Include include = includeRuleFor(classExpr);
0428:
0429: if (include == null) {
0430: include = addIncludeRule(classExpr);
0431: m_plugin.fireExcludeRulesChanged(m_project);
0432: }
0433:
0434: return include;
0435: }
0436:
0437: public boolean declaresRoot(IType type) {
0438: return declaresRoot(type.getFullyQualifiedName());
0439: }
0440:
0441: public boolean declaresRoot(String typeName) {
0442: if (typeName == null)
0443: return false;
0444:
0445: Roots roots = getRoots();
0446: if (roots != null) {
0447: for (int i = 0; i < roots.sizeOfRootArray(); i++) {
0448: String rootFieldName = roots.getRootArray(i)
0449: .getFieldName();
0450:
0451: if (rootFieldName != null && rootFieldName.length() > 0) {
0452: int dotIndex = rootFieldName.lastIndexOf('.');
0453:
0454: if (dotIndex != -1) {
0455: String rootTypeName = rootFieldName.substring(
0456: 0, dotIndex);
0457: if (typeName.equals(rootTypeName)) {
0458: return true;
0459: }
0460: }
0461: }
0462: }
0463: }
0464:
0465: return false;
0466: }
0467:
0468: public void ensureAdaptable(IJavaElement element) {
0469: MultiChangeSignaller signaller = new MultiChangeSignaller();
0470: ensureAdaptable(element, signaller);
0471: signaller.signal(m_project);
0472: }
0473:
0474: public void ensureAdaptable(IJavaElement element,
0475: MultiChangeSignaller signaller) {
0476: if (element instanceof ICompilationUnit) {
0477: ensureAdaptable((ICompilationUnit) element, signaller);
0478: } else if (element instanceof IClassFile) {
0479: ensureAdaptable((IClassFile) element, signaller);
0480: } else if (element instanceof IType) {
0481: ensureAdaptable((IType) element, signaller);
0482: } else if (element instanceof IPackageDeclaration) {
0483: ensureAdaptable((IPackageDeclaration) element, signaller);
0484: } else if (element instanceof IPackageFragment) {
0485: ensureAdaptable((IPackageFragment) element, signaller);
0486: } else if (element instanceof IJavaProject) {
0487: ensureAdaptable((IJavaProject) element, signaller);
0488: }
0489: }
0490:
0491: public void ensureAdaptable(ICompilationUnit module) {
0492: MultiChangeSignaller signaller = new MultiChangeSignaller();
0493: ensureAdaptable(module, signaller);
0494: signaller.signal(m_project);
0495: }
0496:
0497: public void ensureAdaptable(ICompilationUnit module,
0498: MultiChangeSignaller signaller) {
0499: ensureAdaptable(module.findPrimaryType(), signaller);
0500: }
0501:
0502: public void ensureAdaptable(IClassFile classFile) {
0503: MultiChangeSignaller signaller = new MultiChangeSignaller();
0504: ensureAdaptable(classFile, signaller);
0505: signaller.signal(m_project);
0506: }
0507:
0508: public void ensureAdaptable(IClassFile classFile,
0509: MultiChangeSignaller signaller) {
0510: try {
0511: ensureAdaptable(classFile.getType(), signaller);
0512: } catch (Exception e) {
0513: openError("Error ensuring '" + classFile.getElementName()
0514: + "' instrumented", e);
0515: }
0516: }
0517:
0518: public void ensureAdaptable(IType type) {
0519: MultiChangeSignaller signaller = new MultiChangeSignaller();
0520: ensureAdaptable(type, signaller);
0521: signaller.signal(m_project);
0522: }
0523:
0524: public void ensureAdaptable(IType type,
0525: MultiChangeSignaller signaller) {
0526: if (isInterface(type)) {
0527: internalEnsureAdaptable(type, signaller);
0528: return;
0529: }
0530:
0531: while (type != null) {
0532: if (!isInterface(type)) {
0533: if (!isAdaptable(type)) {
0534: internalEnsureAdaptable(type, signaller);
0535: }
0536: } else {
0537: break;
0538: }
0539:
0540: IType parentType = type;
0541: while (parentType != null) {
0542: try {
0543: String super TypeSig = parentType
0544: .getSuperclassTypeSignature();
0545:
0546: if (super TypeSig == null) {
0547: break;
0548: }
0549:
0550: String super TypeName = JdtUtils
0551: .getResolvedTypeName(super TypeSig, type);
0552: if (super TypeName == null
0553: || super TypeName.equals("java.lang.Object")) {
0554: break;
0555: } else {
0556: IType super Type = JdtUtils.findType(
0557: m_javaProject, super TypeName);
0558:
0559: if (super Type == null) {
0560: break;
0561: } else if (!isInterface(super Type)) {
0562: if (!isAdaptable(super Type)) {
0563: internalEnsureAdaptable(super Type,
0564: signaller);
0565: } else {
0566: break;
0567: }
0568: }
0569: parentType = super Type;
0570: }
0571: } catch (JavaModelException jme) {
0572: break;
0573: }
0574: }
0575:
0576: type = type.getDeclaringType();
0577: }
0578: }
0579:
0580: public void internalEnsureAdaptable(IType type) {
0581: MultiChangeSignaller signaller = new MultiChangeSignaller();
0582: internalEnsureAdaptable(type, signaller);
0583: signaller.signal(m_project);
0584: }
0585:
0586: public void internalEnsureAdaptable(IType type,
0587: MultiChangeSignaller signaller) {
0588: String postscript = isInterface(type) ? "+" : "";
0589: internalEnsureAdaptable(PatternHelper
0590: .getFullyQualifiedName(type)
0591: + postscript, signaller);
0592:
0593: if (!isBootJarClass(type)) {
0594: int filter = IJavaSearchScope.SYSTEM_LIBRARIES;
0595: IJavaElement[] elements = new IJavaElement[] { m_javaProject };
0596: IJavaSearchScope scope = SearchEngine
0597: .createJavaSearchScope(elements, filter);
0598:
0599: if (scope.encloses(type)) {
0600: internalEnsureBootJarClass(type, signaller);
0601: }
0602: }
0603: }
0604:
0605: public void ensureAdaptable(IPackageDeclaration packageDecl) {
0606: MultiChangeSignaller signaller = new MultiChangeSignaller();
0607: ensureAdaptable(packageDecl, signaller);
0608: signaller.signal(m_project);
0609: }
0610:
0611: public void ensureAdaptable(IPackageDeclaration packageDecl,
0612: MultiChangeSignaller signaller) {
0613: if (packageDecl != null && !isAdaptable(packageDecl)) {
0614: internalEnsureAdaptable(packageDecl, signaller);
0615: }
0616: }
0617:
0618: public void internalEnsureAdaptable(IPackageDeclaration packageDecl) {
0619: MultiChangeSignaller signaller = new MultiChangeSignaller();
0620: internalEnsureAdaptable(packageDecl, signaller);
0621: signaller.signal(m_project);
0622: }
0623:
0624: public void internalEnsureAdaptable(
0625: IPackageDeclaration packageDecl,
0626: MultiChangeSignaller signaller) {
0627: internalEnsureAdaptable(PatternHelper
0628: .getWithinPattern(packageDecl), signaller);
0629: }
0630:
0631: public void ensureAdaptable(IPackageFragment fragment) {
0632: MultiChangeSignaller signaller = new MultiChangeSignaller();
0633: ensureAdaptable(fragment, signaller);
0634: signaller.signal(m_project);
0635: }
0636:
0637: public void ensureAdaptable(IPackageFragment fragment,
0638: MultiChangeSignaller signaller) {
0639: if (fragment != null && !isAdaptable(fragment)) {
0640: internalEnsureAdaptable(fragment, signaller);
0641: }
0642: }
0643:
0644: public void internalEnsureAdaptable(IPackageFragment fragment) {
0645: MultiChangeSignaller signaller = new MultiChangeSignaller();
0646: internalEnsureAdaptable(fragment, signaller);
0647: signaller.signal(m_project);
0648: }
0649:
0650: public void internalEnsureAdaptable(IPackageFragment fragment,
0651: MultiChangeSignaller signaller) {
0652: internalEnsureAdaptable(PatternHelper
0653: .getWithinPattern(fragment), signaller);
0654: }
0655:
0656: public void ensureAdaptable(IJavaProject javaProject) {
0657: MultiChangeSignaller signaller = new MultiChangeSignaller();
0658: ensureAdaptable(javaProject, signaller);
0659: signaller.signal(m_project);
0660: }
0661:
0662: public void ensureAdaptable(IJavaProject javaProject,
0663: MultiChangeSignaller signaller) {
0664: if (javaProject != null && !isAdaptable(javaProject)) {
0665: internalEnsureAdaptable(javaProject, signaller);
0666: }
0667: }
0668:
0669: public void internalEnsureAdaptable(IJavaProject javaProject,
0670: MultiChangeSignaller signaller) {
0671: IPackageFragment[] fragments = getSourceFragments(javaProject);
0672:
0673: for (int i = 0; i < fragments.length; i++) {
0674: if (!isAdaptable(fragments[i])) {
0675: internalEnsureAdaptable(fragments[i], signaller);
0676: }
0677: }
0678: }
0679:
0680: public void ensureAdaptable(String classExpr) {
0681: MultiChangeSignaller signaller = new MultiChangeSignaller();
0682: ensureAdaptable(classExpr, signaller);
0683: signaller.signal(m_project);
0684: }
0685:
0686: public void ensureAdaptable(String classExpr,
0687: MultiChangeSignaller signaller) {
0688: if (!isAdaptable(classExpr)) {
0689: internalEnsureAdaptable(classExpr, signaller);
0690: }
0691: }
0692:
0693: public Include addIncludeRule(String classExpr) {
0694: InstrumentedClasses classes = ensureInstrumentedClasses();
0695: Include include = classes.addNewInclude();
0696: include.setClassExpression(classExpr);
0697: return include;
0698: }
0699:
0700: public void internalEnsureAdaptable(String classExpr) {
0701: MultiChangeSignaller signaller = new MultiChangeSignaller();
0702: internalEnsureAdaptable(classExpr, signaller);
0703: signaller.signal(m_project);
0704: }
0705:
0706: public void internalEnsureAdaptable(String classExpr,
0707: MultiChangeSignaller signaller) {
0708: addIncludeRule(classExpr);
0709: signaller.includeRulesChanged = true;
0710: }
0711:
0712: public void ensureNotAdaptable(IJavaElement element) {
0713: MultiChangeSignaller signaller = new MultiChangeSignaller();
0714: ensureNotAdaptable(element, signaller);
0715: signaller.signal(m_project);
0716: }
0717:
0718: public void ensureNotAdaptable(IJavaElement element,
0719: MultiChangeSignaller signaller) {
0720: if (element instanceof ICompilationUnit) {
0721: ensureNotAdaptable((ICompilationUnit) element, signaller);
0722: } else if (element instanceof IType) {
0723: ensureNotAdaptable((IType) element, signaller);
0724: } else if (element instanceof IPackageDeclaration) {
0725: ensureNotAdaptable((IPackageDeclaration) element, signaller);
0726: } else if (element instanceof IPackageFragment) {
0727: ensureNotAdaptable((IPackageFragment) element, signaller);
0728: } else if (element instanceof IJavaProject) {
0729: ensureNotAdaptable((IJavaProject) element, signaller);
0730: }
0731: }
0732:
0733: public void ensureNotAdaptable(ICompilationUnit module) {
0734: MultiChangeSignaller signaller = new MultiChangeSignaller();
0735: ensureNotAdaptable(module, signaller);
0736: signaller.signal(m_project);
0737: }
0738:
0739: public void ensureNotAdaptable(ICompilationUnit module,
0740: MultiChangeSignaller signaller) {
0741: if (module != null) {
0742: internalEnsureNotAdaptable(module, signaller);
0743: }
0744: }
0745:
0746: public void internalEnsureNotAdaptable(ICompilationUnit module) {
0747: MultiChangeSignaller signaller = new MultiChangeSignaller();
0748: internalEnsureNotAdaptable(module, signaller);
0749: signaller.signal(m_project);
0750: }
0751:
0752: public void internalEnsureNotAdaptable(ICompilationUnit module,
0753: MultiChangeSignaller signaller) {
0754: IType primaryType = module.findPrimaryType();
0755:
0756: if (primaryType != null) {
0757: internalEnsureNotAdaptable(primaryType, signaller);
0758: }
0759: }
0760:
0761: public void ensureNotAdaptable(IType type) {
0762: MultiChangeSignaller signaller = new MultiChangeSignaller();
0763: ensureNotAdaptable(type, signaller);
0764: signaller.signal(m_project);
0765: }
0766:
0767: public void ensureNotAdaptable(IType type,
0768: MultiChangeSignaller signaller) {
0769: if (isAdaptable(type)) {
0770: baseEnsureNotAdaptable(type, signaller);
0771: }
0772: }
0773:
0774: public void baseEnsureNotAdaptable(IType type,
0775: MultiChangeSignaller signaller) {
0776: internalEnsureNotAdaptable(type, signaller);
0777: }
0778:
0779: public void internalEnsureNotAdaptable(IType type) {
0780: MultiChangeSignaller signaller = new MultiChangeSignaller();
0781: internalEnsureNotAdaptable(type, signaller);
0782: signaller.signal(m_project);
0783: }
0784:
0785: public void internalEnsureNotAdaptable(IType type,
0786: MultiChangeSignaller signaller) {
0787: internalEnsureNotLocked(type, signaller);
0788: internalEnsureNotBootJarClass(type, signaller);
0789: internalEnsureNotAdaptable(PatternHelper
0790: .getFullyQualifiedName(type), signaller);
0791:
0792: try {
0793: IField[] fields = type.getFields();
0794:
0795: if (fields != null) {
0796: for (int i = 0; i < fields.length; i++) {
0797: internalEnsureNotRoot(fields[i], signaller);
0798: }
0799: }
0800:
0801: IType[] childTypes = type.getTypes();
0802:
0803: if (childTypes != null) {
0804: for (int i = 0; i < childTypes.length; i++) {
0805: internalEnsureNotAdaptable(childTypes[i], signaller);
0806: internalEnsureNotBootJarClass(childTypes[i],
0807: signaller);
0808: }
0809: }
0810:
0811: IMethod[] methods = type.getMethods();
0812:
0813: if (methods != null) {
0814: for (int i = 0; i < methods.length; i++) {
0815: internalEnsureNotLocked(methods[i], signaller);
0816: internalEnsureLocalMethod(methods[i], signaller);
0817: }
0818: }
0819: } catch (JavaModelException jme) {/**/
0820: }
0821:
0822: testRemoveInstrumentedClasses();
0823: }
0824:
0825: public void ensureNotAdaptable(IPackageDeclaration packageDecl) {
0826: MultiChangeSignaller signaller = new MultiChangeSignaller();
0827: ensureNotAdaptable(packageDecl, signaller);
0828: signaller.signal(m_project);
0829: }
0830:
0831: public void ensureNotAdaptable(IPackageDeclaration packageDecl,
0832: MultiChangeSignaller signaller) {
0833: if (isAdaptable(packageDecl)) {
0834: internalEnsureNotAdaptable(packageDecl, signaller);
0835: }
0836: }
0837:
0838: public void internalEnsureNotAdaptable(
0839: IPackageDeclaration packageDecl) {
0840: MultiChangeSignaller signaller = new MultiChangeSignaller();
0841: internalEnsureNotAdaptable(packageDecl, signaller);
0842: signaller.signal(m_project);
0843: }
0844:
0845: public void internalEnsureNotAdaptable(
0846: IPackageDeclaration packageDecl,
0847: MultiChangeSignaller signaller) {
0848: internalEnsureNotLocked(packageDecl, signaller);
0849: internalEnsureNotAdaptable(PatternHelper
0850: .getWithinPattern(packageDecl), signaller);
0851: }
0852:
0853: public void ensureNotAdaptable(IPackageFragment fragment) {
0854: MultiChangeSignaller signaller = new MultiChangeSignaller();
0855: ensureNotAdaptable(fragment, signaller);
0856: signaller.signal(m_project);
0857: }
0858:
0859: public void ensureNotAdaptable(IPackageFragment fragment,
0860: MultiChangeSignaller signaller) {
0861: if (isAdaptable(fragment)) {
0862: internalEnsureNotAdaptable(fragment, signaller);
0863: }
0864: }
0865:
0866: public void internalEnsureNotAdaptable(IPackageFragment fragment) {
0867: MultiChangeSignaller signaller = new MultiChangeSignaller();
0868: internalEnsureNotAdaptable(fragment, signaller);
0869: signaller.signal(m_project);
0870: }
0871:
0872: public void internalEnsureNotAdaptable(IPackageFragment fragment,
0873: MultiChangeSignaller signaller) {
0874: internalEnsureNotLocked(fragment, signaller);
0875:
0876: try {
0877: ICompilationUnit[] cus = fragment.getCompilationUnits();
0878:
0879: if (cus != null) {
0880: for (int i = 0; i < cus.length; i++) {
0881: internalEnsureNotAdaptable(cus[i], signaller);
0882: }
0883: }
0884: } catch (JavaModelException jme) {
0885: internalEnsureNotAdaptable(PatternHelper
0886: .getWithinPattern(fragment), signaller);
0887: }
0888: }
0889:
0890: public void ensureNotAdaptable(IJavaProject javaProject) {
0891: MultiChangeSignaller signaller = new MultiChangeSignaller();
0892: ensureNotAdaptable(javaProject, signaller);
0893: signaller.signal(m_project);
0894: }
0895:
0896: public void ensureNotAdaptable(IJavaProject javaProject,
0897: MultiChangeSignaller signaller) {
0898: if (javaProject != null) {
0899: IPackageFragment[] fragments = getSourceFragments(javaProject);
0900: for (int i = 0; i < fragments.length; i++) {
0901: internalEnsureNotAdaptable(fragments[i], signaller);
0902: }
0903: }
0904: }
0905:
0906: public void ensureNotAdaptable(String classExpr) {
0907: MultiChangeSignaller signaller = new MultiChangeSignaller();
0908: ensureNotAdaptable(classExpr, signaller);
0909: signaller.signal(m_project);
0910: }
0911:
0912: public void ensureNotAdaptable(String classExpr,
0913: MultiChangeSignaller signaller) {
0914: if (isAdaptable(classExpr)) {
0915: internalEnsureNotAdaptable(classExpr, signaller);
0916: }
0917: }
0918:
0919: public void internalEnsureNotAdaptable(String classExpr,
0920: MultiChangeSignaller signaller) {
0921: InstrumentedClasses classes = getInstrumentedClasses();
0922:
0923: if (classes != null) {
0924: int size = classes.sizeOfIncludeArray();
0925:
0926: for (int i = size - 1; i >= 0; i--) {
0927: String expr = classes.getIncludeArray(i)
0928: .getClassExpression();
0929:
0930: if (m_patternHelper.matchesClass(expr, classExpr)) {
0931: classes.removeInclude(i);
0932: signaller.includeRulesChanged = true;
0933: }
0934: }
0935: }
0936: }
0937:
0938: public boolean isExcluded(IJavaElement element) {
0939: if (element instanceof ICompilationUnit) {
0940: return isExcluded((ICompilationUnit) element);
0941: } else if (element instanceof IType) {
0942: return isExcluded((IType) element);
0943: } else if (element instanceof IPackageDeclaration) {
0944: return isExcluded(element.getElementName());
0945: } else if (element instanceof IPackageFragment) {
0946: return isExcluded((IPackageFragment) element);
0947: } else if (element instanceof IJavaProject) {
0948: return isExcluded((IJavaProject) element);
0949: }
0950:
0951: return false;
0952: }
0953:
0954: public boolean isExcluded(ICompilationUnit module) {
0955: return isExcluded(module.findPrimaryType());
0956: }
0957:
0958: public boolean isExcluded(IType type) {
0959: return type != null
0960: && isExcluded(PatternHelper.getFullyQualifiedName(type));
0961: }
0962:
0963: private Boolean isExcluded(IPackageFragment fragment,
0964: InstrumentedClasses instrumentedClasses) {
0965: if (instrumentedClasses != null) {
0966: XmlObject[] objects = instrumentedClasses.selectPath("*");
0967:
0968: if (objects != null && objects.length > 0) {
0969: for (int i = objects.length - 1; i >= 0; i--) {
0970: XmlObject object = objects[i];
0971:
0972: if (object instanceof Include) {
0973: String expr = ((Include) object)
0974: .getClassExpression();
0975: if (m_patternHelper.matchesPackageFragment(
0976: expr, fragment)) {
0977: return Boolean.FALSE;
0978: }
0979: } else if (object instanceof ClassExpression) {
0980: String expr = ((ClassExpression) object)
0981: .getStringValue();
0982: if (m_patternHelper.matchesPackageFragment(
0983: expr, fragment)) {
0984: return Boolean.TRUE;
0985: }
0986: }
0987: }
0988: }
0989: }
0990: return null;
0991: }
0992:
0993: public boolean isExcluded(IPackageFragment fragment) {
0994: TcConfig config = getConfig();
0995:
0996: if (config != null) {
0997: InstrumentedClasses instrumentedClasses = getInstrumentedClasses();
0998:
0999: if (instrumentedClasses != null) {
1000: Boolean excluded = isExcluded(fragment,
1001: instrumentedClasses);
1002: if (excluded != null) {
1003: return excluded;
1004: }
1005: }
1006:
1007: ModulesConfiguration modulesConfig = m_plugin
1008: .getModulesConfiguration(m_project);
1009: if (modulesConfig != null) {
1010: instrumentedClasses = modulesConfig.getApplication()
1011: .getInstrumentedClasses();
1012: if (instrumentedClasses != null) {
1013: Boolean excluded = isExcluded(fragment,
1014: instrumentedClasses);
1015: if (excluded != null) {
1016: return excluded;
1017: }
1018: }
1019: }
1020: }
1021:
1022: return false;
1023: }
1024:
1025: public boolean isExcluded(IJavaProject javaProject) {
1026: if (javaProject != null) {
1027: IPackageFragment[] fragments = getSourceFragments(javaProject);
1028:
1029: if (fragments.length > 0) {
1030: for (int i = 0; i < fragments.length; i++) {
1031: if (!isExcluded(fragments[i])) {
1032: return false;
1033: }
1034: }
1035:
1036: return true;
1037: }
1038: }
1039:
1040: return false;
1041: }
1042:
1043: public Boolean isExcluded(String classExpr,
1044: InstrumentedClasses instrumentedClasses) {
1045: if (instrumentedClasses != null) {
1046: XmlObject[] objects = instrumentedClasses.selectPath("*");
1047:
1048: if (objects != null && objects.length > 0) {
1049: for (int i = objects.length - 1; i >= 0; i--) {
1050: XmlObject object = objects[i];
1051:
1052: if (object instanceof Include) {
1053: String expr = ((Include) object)
1054: .getClassExpression();
1055: if (m_patternHelper.matchesClass(expr,
1056: classExpr)) {
1057: return Boolean.FALSE;
1058: }
1059: } else if (object instanceof ClassExpression) {
1060: String expr = ((ClassExpression) object)
1061: .getStringValue();
1062: if (m_patternHelper.matchesClass(expr,
1063: classExpr)) {
1064: return Boolean.TRUE;
1065: }
1066: }
1067: }
1068: }
1069: }
1070: return null;
1071: }
1072:
1073: public boolean isExcluded(String classExpr) {
1074: TcConfig config = getConfig();
1075:
1076: if (config != null) {
1077: InstrumentedClasses instrumentedClasses = getInstrumentedClasses();
1078:
1079: if (instrumentedClasses != null) {
1080: Boolean excluded = isExcluded(classExpr,
1081: instrumentedClasses);
1082: if (excluded != null) {
1083: return excluded;
1084: }
1085: }
1086:
1087: ModulesConfiguration modulesConfig = m_plugin
1088: .getModulesConfiguration(m_project);
1089: if (modulesConfig != null) {
1090: instrumentedClasses = modulesConfig.getApplication()
1091: .getInstrumentedClasses();
1092: if (instrumentedClasses != null) {
1093: Boolean excluded = isExcluded(classExpr,
1094: instrumentedClasses);
1095: if (excluded != null) {
1096: return excluded;
1097: }
1098: }
1099: }
1100: }
1101:
1102: return false;
1103: }
1104:
1105: public void ensureExcluded(IJavaElement element) {
1106: MultiChangeSignaller signaller = new MultiChangeSignaller();
1107: ensureExcluded(element, signaller);
1108: signaller.signal(m_project);
1109: }
1110:
1111: public void ensureExcluded(IJavaElement element,
1112: MultiChangeSignaller signaller) {
1113: if (element instanceof ICompilationUnit) {
1114: ensureExcluded((ICompilationUnit) element, signaller);
1115: } else if (element instanceof IType) {
1116: ensureExcluded((IType) element, signaller);
1117: } else if (element instanceof IPackageDeclaration) {
1118: ensureExcluded(element.getElementName(), signaller);
1119: } else if (element instanceof IPackageFragment) {
1120: ensureExcluded((IPackageFragment) element, signaller);
1121: } else if (element instanceof IJavaProject) {
1122: ensureExcluded((IJavaProject) element, signaller);
1123: }
1124: }
1125:
1126: public void ensureExcluded(ICompilationUnit module) {
1127: MultiChangeSignaller signaller = new MultiChangeSignaller();
1128: ensureExcluded(module, signaller);
1129: signaller.signal(m_project);
1130: }
1131:
1132: public void ensureExcluded(ICompilationUnit module,
1133: MultiChangeSignaller signaller) {
1134: if (module != null) {
1135: internalEnsureExcluded(module, signaller);
1136: }
1137: }
1138:
1139: public void internalEnsureExcluded(ICompilationUnit module) {
1140: MultiChangeSignaller signaller = new MultiChangeSignaller();
1141: internalEnsureExcluded(module, signaller);
1142: signaller.signal(m_project);
1143: }
1144:
1145: public void internalEnsureExcluded(ICompilationUnit module,
1146: MultiChangeSignaller signaller) {
1147: internalEnsureExcluded(module.findPrimaryType(), signaller);
1148: }
1149:
1150: public void ensureExcluded(IType type) {
1151: MultiChangeSignaller signaller = new MultiChangeSignaller();
1152: ensureExcluded(type, signaller);
1153: signaller.signal(m_project);
1154: }
1155:
1156: public void ensureExcluded(IType type,
1157: MultiChangeSignaller signaller) {
1158: if (type != null && !isExcluded(type)) {
1159: internalEnsureExcluded(type, signaller);
1160: }
1161: }
1162:
1163: public void internalEnsureExcluded(IType type) {
1164: MultiChangeSignaller signaller = new MultiChangeSignaller();
1165: internalEnsureExcluded(type, signaller);
1166: signaller.signal(m_project);
1167: }
1168:
1169: public void internalEnsureExcluded(IType type,
1170: MultiChangeSignaller signaller) {
1171: internalEnsureExcluded(PatternHelper
1172: .getFullyQualifiedName(type), signaller);
1173: }
1174:
1175: public void ensureExcluded(IPackageFragment fragment) {
1176: MultiChangeSignaller signaller = new MultiChangeSignaller();
1177: ensureExcluded(fragment, signaller);
1178: signaller.signal(m_project);
1179: }
1180:
1181: public void ensureExcluded(IPackageFragment fragment,
1182: MultiChangeSignaller signaller) {
1183: if (fragment != null && !isExcluded(fragment)) {
1184: internalEnsureExcluded(fragment, signaller);
1185: }
1186: }
1187:
1188: public void internalEnsureExcluded(IPackageFragment fragment) {
1189: MultiChangeSignaller signaller = new MultiChangeSignaller();
1190: internalEnsureExcluded(fragment, signaller);
1191: signaller.signal(m_project);
1192: }
1193:
1194: public void internalEnsureExcluded(IPackageFragment fragment,
1195: MultiChangeSignaller signaller) {
1196: internalEnsureExcluded(
1197: PatternHelper.getWithinPattern(fragment), signaller);
1198: }
1199:
1200: public void ensureExcluded(IJavaProject javaProject) {
1201: MultiChangeSignaller signaller = new MultiChangeSignaller();
1202: ensureExcluded(javaProject, signaller);
1203: signaller.signal(m_project);
1204: }
1205:
1206: public void ensureExcluded(IJavaProject javaProject,
1207: MultiChangeSignaller signaller) {
1208: if (javaProject != null) {
1209: IPackageFragment[] fragments = getSourceFragments(javaProject);
1210: for (int i = 0; i < fragments.length; i++) {
1211: internalEnsureExcluded(fragments[i], signaller);
1212: }
1213: }
1214: }
1215:
1216: public void ensureExcluded(String className) {
1217: MultiChangeSignaller signaller = new MultiChangeSignaller();
1218: ensureExcluded(className, signaller);
1219: signaller.signal(m_project);
1220: }
1221:
1222: public void ensureExcluded(String className,
1223: MultiChangeSignaller signaller) {
1224: if (className != null && !isExcluded(className)) {
1225: internalEnsureExcluded(className, signaller);
1226: }
1227: }
1228:
1229: public void internalEnsureExcluded(String className,
1230: MultiChangeSignaller signaller) {
1231: ensureInstrumentedClasses().addExclude(className);
1232: signaller.excludeRulesChanged = true;
1233: }
1234:
1235: public void ensureNotExcluded(IJavaElement element) {
1236: MultiChangeSignaller signaller = new MultiChangeSignaller();
1237: ensureNotExcluded(element, signaller);
1238: signaller.signal(m_project);
1239: }
1240:
1241: public void ensureNotExcluded(IJavaElement element,
1242: MultiChangeSignaller signaller) {
1243: if (element instanceof ICompilationUnit) {
1244: ensureNotExcluded((ICompilationUnit) element, signaller);
1245: } else if (element instanceof IType) {
1246: ensureNotExcluded((IType) element, signaller);
1247: } else if (element instanceof IPackageFragment) {
1248: ensureNotExcluded((IPackageFragment) element, signaller);
1249: } else if (element instanceof IJavaProject) {
1250: ensureNotExcluded((IJavaProject) element, signaller);
1251: }
1252: }
1253:
1254: public void ensureNotExcluded(ICompilationUnit module) {
1255: MultiChangeSignaller signaller = new MultiChangeSignaller();
1256: ensureNotExcluded(module, signaller);
1257: signaller.signal(m_project);
1258: }
1259:
1260: public void ensureNotExcluded(ICompilationUnit module,
1261: MultiChangeSignaller signaller) {
1262: if (module != null) {
1263: internalEnsureNotExcluded(module, signaller);
1264: }
1265: }
1266:
1267: public void internalEnsureNotExcluded(ICompilationUnit module) {
1268: MultiChangeSignaller signaller = new MultiChangeSignaller();
1269: internalEnsureNotExcluded(module, signaller);
1270: signaller.signal(m_project);
1271: }
1272:
1273: public void internalEnsureNotExcluded(ICompilationUnit module,
1274: MultiChangeSignaller signaller) {
1275: internalEnsureNotExcluded(module.findPrimaryType(), signaller);
1276: }
1277:
1278: public void ensureNotExcluded(IType type) {
1279: MultiChangeSignaller signaller = new MultiChangeSignaller();
1280: ensureNotExcluded(type, signaller);
1281: signaller.signal(m_project);
1282: }
1283:
1284: public void ensureNotExcluded(IType type,
1285: MultiChangeSignaller signaller) {
1286: if (type != null && isExcluded(type)) {
1287: baseEnsureNotExcluded(PatternHelper
1288: .getFullyQualifiedName(type), signaller);
1289: }
1290: }
1291:
1292: public void baseEnsureNotExcluded(IType type,
1293: MultiChangeSignaller signaller) {
1294: internalEnsureNotExcluded(type, signaller);
1295: }
1296:
1297: public void internalEnsureNotExcluded(IType type) {
1298: MultiChangeSignaller signaller = new MultiChangeSignaller();
1299: internalEnsureNotExcluded(type, signaller);
1300: signaller.signal(m_project);
1301: }
1302:
1303: public void internalEnsureNotExcluded(IType type,
1304: MultiChangeSignaller signaller) {
1305: internalEnsureNotExcluded(PatternHelper
1306: .getFullyQualifiedName(type), signaller);
1307: }
1308:
1309: public void ensureNotExcluded(IPackageFragment fragment) {
1310: MultiChangeSignaller signaller = new MultiChangeSignaller();
1311: ensureNotExcluded(fragment, signaller);
1312: signaller.signal(m_project);
1313: }
1314:
1315: public void ensureNotExcluded(IPackageFragment fragment,
1316: MultiChangeSignaller signaller) {
1317: if (fragment != null) {
1318: ensureNotExcluded(PatternHelper.getWithinPattern(fragment),
1319: signaller);
1320: }
1321: }
1322:
1323: public void internalEnsureNotExcluded(IPackageFragment fragment) {
1324: MultiChangeSignaller signaller = new MultiChangeSignaller();
1325: internalEnsureNotExcluded(fragment, signaller);
1326: signaller.signal(m_project);
1327: }
1328:
1329: public void internalEnsureNotExcluded(IPackageFragment fragment,
1330: MultiChangeSignaller signaller) {
1331: internalEnsureNotExcluded(PatternHelper
1332: .getWithinPattern(fragment), signaller);
1333: }
1334:
1335: public void ensureNotExcluded(IJavaProject javaProject) {
1336: MultiChangeSignaller signaller = new MultiChangeSignaller();
1337: ensureNotExcluded(javaProject, signaller);
1338: signaller.signal(m_project);
1339: }
1340:
1341: public void ensureNotExcluded(IJavaProject javaProject,
1342: MultiChangeSignaller signaller) {
1343: if (javaProject != null) {
1344: IPackageFragment[] fragments = getSourceFragments(javaProject);
1345: for (int i = 0; i < fragments.length; i++) {
1346: internalEnsureNotExcluded(fragments[i], signaller);
1347: }
1348:
1349: }
1350: }
1351:
1352: public void ensureNotExcluded(String classExpr) {
1353: MultiChangeSignaller signaller = new MultiChangeSignaller();
1354: ensureNotExcluded(classExpr, signaller);
1355: signaller.signal(m_project);
1356: }
1357:
1358: public void ensureNotExcluded(String classExpr,
1359: MultiChangeSignaller signaller) {
1360: if (isExcluded(classExpr)) {
1361: baseEnsureNotExcluded(classExpr, signaller);
1362: }
1363: }
1364:
1365: public void baseEnsureNotExcluded(String classExpr,
1366: MultiChangeSignaller signaller) {
1367: internalEnsureNotExcluded(classExpr, signaller);
1368: }
1369:
1370: public void internalEnsureNotExcluded(String classExpr) {
1371: MultiChangeSignaller signaller = new MultiChangeSignaller();
1372: internalEnsureNotExcluded(classExpr, signaller);
1373: signaller.signal(m_project);
1374: }
1375:
1376: public void internalEnsureNotExcluded(String classExpr,
1377: MultiChangeSignaller signaller) {
1378: InstrumentedClasses classes = getInstrumentedClasses();
1379:
1380: if (classes != null) {
1381: int size = classes.sizeOfExcludeArray();
1382:
1383: for (int i = size - 1; i >= 0; i--) {
1384: String expr = classes.getExcludeArray(i);
1385:
1386: if (m_patternHelper.matchesClass(expr, classExpr)) {
1387: classes.removeExclude(i);
1388: signaller.excludeRulesChanged = true;
1389: }
1390: }
1391: }
1392: }
1393:
1394: public static String getFullName(IField field) {
1395: IType type = field.getDeclaringType();
1396: String parentType = PatternHelper.getFullyQualifiedName(type);
1397: String fieldName = field.getElementName();
1398:
1399: return parentType + "." + fieldName;
1400: }
1401:
1402: public Boolean isRoot(IField field, Roots roots) {
1403: if (roots != null) {
1404: for (int i = 0; i < roots.sizeOfRootArray(); i++) {
1405: if (m_patternHelper.matchesField(roots.getRootArray(i),
1406: field)) {
1407: return Boolean.TRUE;
1408: }
1409: }
1410: }
1411: return null;
1412: }
1413:
1414: public boolean isRoot(IField field) {
1415: if (field == null)
1416: return false;
1417:
1418: TcConfig config = getConfig();
1419: if (config != null) {
1420: Roots roots = getRoots();
1421:
1422: if (roots != null) {
1423: Boolean isRoot = isRoot(field, roots);
1424: if (isRoot != null) {
1425: return isRoot;
1426: }
1427: }
1428:
1429: ModulesConfiguration modulesConfig = m_plugin
1430: .getModulesConfiguration(m_project);
1431: if (modulesConfig != null) {
1432: roots = modulesConfig.getApplication().getRoots();
1433: if (roots != null) {
1434: Boolean isRoot = isRoot(field, roots);
1435: if (isRoot != null) {
1436: return isRoot;
1437: }
1438: }
1439: }
1440: }
1441:
1442: return false;
1443: }
1444:
1445: public boolean isRoot(String className, String fieldName) {
1446: return isRoot(className + "." + fieldName);
1447: }
1448:
1449: public boolean isRoot(String fieldName) {
1450: return isRoot(getField(fieldName));
1451: }
1452:
1453: public void ensureRoot(IField field) {
1454: MultiChangeSignaller signaller = new MultiChangeSignaller();
1455: ensureRoot(field, signaller);
1456: signaller.signal(m_project);
1457: }
1458:
1459: public void ensureRoot(IField field, MultiChangeSignaller signaller) {
1460: if (!isRoot(field)) {
1461: IType fieldType = getFieldType(field);
1462:
1463: if (fieldType != null && !isInterface(fieldType)
1464: && !isAdaptable(fieldType)) {
1465: internalEnsureAdaptable(fieldType, signaller);
1466: }
1467:
1468: if (isTransient(field)) {
1469: ensureNotTransient(field, signaller);
1470: }
1471:
1472: internalEnsureRoot(getFullName(field), signaller);
1473: }
1474: }
1475:
1476: public IType getFieldType(IField field) {
1477: try {
1478: String sig = field.getTypeSignature();
1479: IType declaringType = field.getDeclaringType();
1480: String typeName = JdtUtils.getResolvedTypeName(sig,
1481: declaringType);
1482:
1483: if (typeName != null) {
1484: return JdtUtils.findType(m_javaProject, typeName);
1485: }
1486: } catch (JavaModelException jme) {/**/
1487: }
1488:
1489: return null;
1490: }
1491:
1492: public IField getField(String fieldName) {
1493: int lastDot = fieldName.lastIndexOf('.');
1494:
1495: if (lastDot != -1) {
1496: String declaringTypeName = fieldName.substring(0, lastDot);
1497:
1498: try {
1499: IType declaringType = JdtUtils.findType(m_javaProject,
1500: declaringTypeName);
1501:
1502: if (declaringType != null) {
1503: return declaringType.getField(fieldName
1504: .substring(lastDot + 1));
1505: }
1506: } catch (JavaModelException jme) {/**/
1507: }
1508: }
1509:
1510: return null;
1511: }
1512:
1513: public IType getFieldType(String fieldName) {
1514: IField field = getField(fieldName);
1515:
1516: if (field != null) {
1517: try {
1518: String sig = field.getTypeSignature();
1519: IType declaringType = field.getDeclaringType();
1520: String typeName = JdtUtils.getResolvedTypeName(sig,
1521: declaringType);
1522:
1523: return JdtUtils.findType(m_javaProject, typeName);
1524: } catch (JavaModelException jme) {/**/
1525: }
1526:
1527: }
1528:
1529: return null;
1530: }
1531:
1532: public void ensureRoot(String fieldName) {
1533: MultiChangeSignaller signaller = new MultiChangeSignaller();
1534: ensureRoot(fieldName, signaller);
1535: signaller.signal(m_project);
1536: }
1537:
1538: public void ensureRoot(String fieldName,
1539: MultiChangeSignaller signaller) {
1540: if (!isRoot(fieldName)) {
1541: IType fieldType = getFieldType(fieldName);
1542:
1543: if (fieldType != null && !isAdaptable(fieldType)) {
1544: ensureAdaptable(fieldType, signaller);
1545: }
1546:
1547: if (isTransient(fieldName)) {
1548: ensureNotTransient(fieldName, signaller);
1549: }
1550:
1551: internalEnsureRoot(fieldName, signaller);
1552: }
1553: }
1554:
1555: public void internalEnsureRoot(String fieldName) {
1556: MultiChangeSignaller signaller = new MultiChangeSignaller();
1557: internalEnsureRoot(fieldName, signaller);
1558: signaller.signal(m_project);
1559: }
1560:
1561: public void internalEnsureRoot(String fieldName,
1562: MultiChangeSignaller signaller) {
1563: ensureRoots().addNewRoot().setFieldName(fieldName);
1564: signaller.rootsChanged = true;
1565: }
1566:
1567: public void ensureNotRoot(IField field) {
1568: MultiChangeSignaller signaller = new MultiChangeSignaller();
1569: ensureNotRoot(field, signaller);
1570: signaller.signal(m_project);
1571: }
1572:
1573: public void ensureNotRoot(IField field,
1574: MultiChangeSignaller signaller) {
1575: if (field != null && isRoot(field)) {
1576: baseEnsureNotRoot(field, signaller);
1577: }
1578: }
1579:
1580: public void baseEnsureNotRoot(IField field,
1581: MultiChangeSignaller signaller) {
1582: internalEnsureNotRoot(field, signaller);
1583: }
1584:
1585: public void internalEnsureNotRoot(IField field) {
1586: MultiChangeSignaller signaller = new MultiChangeSignaller();
1587: internalEnsureNotRoot(field, signaller);
1588: signaller.signal(m_project);
1589: }
1590:
1591: public void internalEnsureNotRoot(IField field,
1592: MultiChangeSignaller signaller) {
1593: internalEnsureNotRoot(getFullName(field), signaller);
1594: }
1595:
1596: public void ensureNotRoot(String fieldName) {
1597: MultiChangeSignaller signaller = new MultiChangeSignaller();
1598: ensureNotRoot(fieldName, signaller);
1599: signaller.signal(m_project);
1600: }
1601:
1602: public void ensureNotRoot(String fieldName,
1603: MultiChangeSignaller signaller) {
1604: if (isRoot(fieldName)) {
1605: baseEnsureNotRoot(fieldName, signaller);
1606: }
1607: }
1608:
1609: public void baseEnsureNotRoot(String fieldName,
1610: MultiChangeSignaller signaller) {
1611: internalEnsureNotRoot(fieldName, signaller);
1612: }
1613:
1614: public void internalEnsureNotRoot(String fieldName) {
1615: MultiChangeSignaller signaller = new MultiChangeSignaller();
1616: internalEnsureNotRoot(fieldName, signaller);
1617: signaller.signal(m_project);
1618: }
1619:
1620: public void internalEnsureNotRoot(String fieldName,
1621: MultiChangeSignaller signaller) {
1622: Roots roots = getRoots();
1623:
1624: if (roots != null) {
1625: int size = roots.sizeOfRootArray();
1626:
1627: for (int i = size - 1; i >= 0; i--) {
1628: if (fieldName.equals(roots.getRootArray(i)
1629: .getFieldName())) {
1630: roots.removeRoot(i);
1631: signaller.rootsChanged = true;
1632: }
1633: }
1634:
1635: testRemoveRoots();
1636: }
1637: }
1638:
1639: public void renameRoot(String fieldName, String newFieldName) {
1640: if (isRoot(fieldName)) {
1641: internalRenameRoot(fieldName, newFieldName);
1642: m_plugin.fireRootsChanged(m_project);
1643: }
1644: }
1645:
1646: public void internalRenameRoot(String fieldName, String newFieldName) {
1647: Roots roots = getRoots();
1648:
1649: if (roots != null) {
1650: for (int i = 0; i < roots.sizeOfRootArray(); i++) {
1651: Root root = roots.getRootArray(i);
1652:
1653: if (fieldName.equals(root.getFieldName())) {
1654: root.setFieldName(newFieldName);
1655: return;
1656: }
1657: }
1658: }
1659: }
1660:
1661: public boolean isTransient(IField field) {
1662: return field != null && isTransient(getFullName(field));
1663: }
1664:
1665: public boolean isTransient(String className, String fieldName) {
1666: return isTransient(className + "." + fieldName);
1667: }
1668:
1669: private Boolean isTransient(String fieldName,
1670: TransientFields transientFields) {
1671: if (transientFields != null) {
1672: for (int i = 0; i < transientFields.sizeOfFieldNameArray(); i++) {
1673: if (fieldName.equals(transientFields
1674: .getFieldNameArray(i))) {
1675: return Boolean.TRUE;
1676: }
1677: }
1678: }
1679: return null;
1680: }
1681:
1682: public boolean isTransient(String fieldName) {
1683: TcConfig config = getConfig();
1684:
1685: if (config != null) {
1686: TransientFields transientFields = getTransientFields();
1687:
1688: if (transientFields != null) {
1689: Boolean isTransient = isTransient(fieldName,
1690: transientFields);
1691: if (isTransient != null) {
1692: return isTransient;
1693: }
1694: }
1695:
1696: ModulesConfiguration modulesConfig = m_plugin
1697: .getModulesConfiguration(m_project);
1698: if (modulesConfig != null) {
1699: transientFields = modulesConfig.getApplication()
1700: .getTransientFields();
1701: if (transientFields != null) {
1702: Boolean isTransient = isTransient(fieldName,
1703: transientFields);
1704: if (isTransient != null) {
1705: return isTransient;
1706: }
1707: }
1708: }
1709: }
1710:
1711: return false;
1712: }
1713:
1714: public void ensureTransient(IField field) {
1715: MultiChangeSignaller signaller = new MultiChangeSignaller();
1716: ensureTransient(field, signaller);
1717: signaller.signal(m_project);
1718: }
1719:
1720: public void ensureTransient(IField field,
1721: MultiChangeSignaller signaller) {
1722: if (field != null && !isTransient(field)) {
1723: if (isRoot(field)) {
1724: internalEnsureNotRoot(field, signaller);
1725: }
1726:
1727: IType declaringType = field.getDeclaringType();
1728: if (!isAdaptable(declaringType)) {
1729: internalEnsureAdaptable(declaringType, signaller);
1730: }
1731:
1732: internalEnsureTransient(getFullName(field), signaller);
1733: }
1734: }
1735:
1736: public void ensureTransient(String fieldName) {
1737: MultiChangeSignaller signaller = new MultiChangeSignaller();
1738: ensureTransient(fieldName, signaller);
1739: signaller.signal(m_project);
1740: }
1741:
1742: public void ensureTransient(String fieldName,
1743: MultiChangeSignaller signaller) {
1744: if (!isTransient(fieldName)) {
1745: IField field = getField(fieldName);
1746: if (field != null) {
1747: IType fieldType = field.getDeclaringType();
1748: if (!isAdaptable(fieldType)) {
1749: ensureAdaptable(fieldType, signaller);
1750: }
1751: }
1752:
1753: if (isRoot(fieldName)) {
1754: ensureNotRoot(fieldName, signaller);
1755: }
1756:
1757: internalEnsureTransient(fieldName, signaller);
1758: }
1759: }
1760:
1761: public void internalEnsureTransient(String fieldName) {
1762: MultiChangeSignaller signaller = new MultiChangeSignaller();
1763: internalEnsureTransient(fieldName, signaller);
1764: signaller.signal(m_project);
1765: }
1766:
1767: public void internalEnsureTransient(String fieldName,
1768: MultiChangeSignaller signaller) {
1769: ensureTransientFields().addFieldName(fieldName);
1770: signaller.transientFieldsChanged = true;
1771: }
1772:
1773: public void ensureNotTransient(IField field) {
1774: MultiChangeSignaller signaller = new MultiChangeSignaller();
1775: ensureNotTransient(field, signaller);
1776: signaller.signal(m_project);
1777: }
1778:
1779: public void ensureNotTransient(IField field,
1780: MultiChangeSignaller signaller) {
1781: if (field != null) {
1782: ensureNotTransient(getFullName(field), signaller);
1783: }
1784: }
1785:
1786: public void ensureNotTransient(String fieldName) {
1787: MultiChangeSignaller signaller = new MultiChangeSignaller();
1788: ensureNotTransient(fieldName, signaller);
1789: signaller.signal(m_project);
1790: }
1791:
1792: public void ensureNotTransient(String fieldName,
1793: MultiChangeSignaller signaller) {
1794: if (isTransient(fieldName)) {
1795: internalEnsureNotTransient(fieldName, signaller);
1796: }
1797: }
1798:
1799: public void internalEnsureNotTransient(String fieldName) {
1800: MultiChangeSignaller signaller = new MultiChangeSignaller();
1801: internalEnsureNotTransient(fieldName, signaller);
1802: signaller.signal(m_project);
1803: }
1804:
1805: public void internalEnsureNotTransient(String fieldName,
1806: MultiChangeSignaller signaller) {
1807: TransientFields transients = getTransientFields();
1808:
1809: if (transients != null) {
1810: for (int i = transients.sizeOfFieldNameArray() - 1; i >= 0; i--) {
1811: if (fieldName.equals(transients.getFieldNameArray(i))) {
1812: transients.removeFieldName(i);
1813: signaller.transientFieldsChanged = true;
1814: }
1815: }
1816:
1817: testRemoveTransientFields();
1818: }
1819: }
1820:
1821: private TransientFields getTransientFields() {
1822: DsoApplication dsoApp = getDsoApplication();
1823: return dsoApp != null ? dsoApp.getTransientFields() : null;
1824: }
1825:
1826: private TransientFields ensureTransientFields() {
1827: DsoApplication dsoApp = ensureDsoApplication();
1828: TransientFields transients = dsoApp.getTransientFields();
1829:
1830: if (transients == null) {
1831: transients = dsoApp.addNewTransientFields();
1832: }
1833:
1834: return transients;
1835: }
1836:
1837: private void testRemoveTransientFields() {
1838: DsoApplication dsoApp = getDsoApplication();
1839:
1840: if (dsoApp != null) {
1841: TransientFields transients = dsoApp.getTransientFields();
1842:
1843: if (transients != null) {
1844: if (transients.sizeOfFieldNameArray() == 0) {
1845: dsoApp.unsetTransientFields();
1846: testRemoveDsoApplication();
1847: }
1848: }
1849: }
1850: }
1851:
1852: public boolean matches(String expression, MemberInfo methodInfo) {
1853: return m_patternHelper.matchesMember(expression, methodInfo);
1854: }
1855:
1856: public boolean matches(String expression, IMethod method) {
1857: return m_patternHelper.matchesMethod(expression, method);
1858: }
1859:
1860: public boolean isDistributedMethod(MethodDeclaration methodDecl) {
1861: IMethodBinding binding = methodDecl.resolveBinding();
1862:
1863: if (binding != null
1864: && !binding.getDeclaringClass().isInterface()) {
1865: return isDistributedMethod(PatternHelper
1866: .methodDecl2IMethod(methodDecl));
1867: }
1868:
1869: return false;
1870: }
1871:
1872: public boolean isDistributedMethod(IMethod method) {
1873: MethodInfo methodInfo = m_patternHelper.getMethodInfo(method);
1874: return methodInfo != null && isDistributedMethod(methodInfo);
1875: }
1876:
1877: private Boolean isDistributedMethod(MethodInfo methodInfo,
1878: DistributedMethods distributedMethods) {
1879: if (distributedMethods != null) {
1880: for (int i = 0; i < distributedMethods
1881: .sizeOfMethodExpressionArray(); i++) {
1882: String expr = distributedMethods
1883: .getMethodExpressionArray(i).getStringValue();
1884: if (m_patternHelper.matchesMember(expr, methodInfo)) {
1885: return Boolean.TRUE;
1886: }
1887: }
1888: }
1889: return null;
1890: }
1891:
1892: public boolean isDistributedMethod(MethodInfo methodInfo) {
1893: TcConfig config = getConfig();
1894:
1895: if (config != null) {
1896: DistributedMethods distributedMethods = getDistributedMethods();
1897:
1898: if (distributedMethods != null) {
1899: Boolean isDistributedMethod = isDistributedMethod(
1900: methodInfo, distributedMethods);
1901: if (isDistributedMethod != null) {
1902: return isDistributedMethod;
1903: }
1904: }
1905:
1906: ModulesConfiguration modulesConfig = m_plugin
1907: .getModulesConfiguration(m_project);
1908: if (modulesConfig != null) {
1909: distributedMethods = modulesConfig.getApplication()
1910: .getDistributedMethods();
1911: if (distributedMethods != null) {
1912: Boolean isDistributedMethod = isDistributedMethod(
1913: methodInfo, distributedMethods);
1914: if (isDistributedMethod != null) {
1915: return isDistributedMethod;
1916: }
1917: }
1918: }
1919: }
1920:
1921: return false;
1922: }
1923:
1924: public void ensureDistributedMethod(IMethod method) {
1925: MultiChangeSignaller signaller = new MultiChangeSignaller();
1926: ensureDistributedMethod(method, signaller);
1927: signaller.signal(m_project);
1928: }
1929:
1930: public void ensureDistributedMethod(IMethod method,
1931: MultiChangeSignaller signaller) {
1932: if (!isDistributedMethod(method)) {
1933: internalEnsureDistributedMethod(method, signaller);
1934: }
1935: }
1936:
1937: public void internalEnsureDistributedMethod(IMethod method) {
1938: MultiChangeSignaller signaller = new MultiChangeSignaller();
1939: internalEnsureDistributedMethod(method, signaller);
1940: signaller.signal(m_project);
1941: }
1942:
1943: public void internalEnsureDistributedMethod(IMethod method,
1944: MultiChangeSignaller signaller) {
1945: IType declaringType = method.getDeclaringType();
1946:
1947: if (!isAdaptable(declaringType)) {
1948: internalEnsureAdaptable(declaringType, signaller);
1949: }
1950:
1951: DistributedMethods methods = ensureDistributedMethods();
1952: MethodExpression methodExpression = methods
1953: .addNewMethodExpression();
1954:
1955: try {
1956: methodExpression.setStringValue(PatternHelper
1957: .getJavadocSignature(method));
1958: } catch (JavaModelException jme) {
1959: openError("Error ensuring method '"
1960: + method.getElementName() + "' distributed", jme);
1961: return;
1962: }
1963:
1964: signaller.distributedMethodsChanged = true;
1965: }
1966:
1967: public void ensureLocalMethod(IMethod method) {
1968: MultiChangeSignaller signaller = new MultiChangeSignaller();
1969: ensureLocalMethod(method, signaller);
1970: signaller.signal(m_project);
1971: }
1972:
1973: public void ensureLocalMethod(IMethod method,
1974: MultiChangeSignaller signaller) {
1975: if (isDistributedMethod(method)) {
1976: internalEnsureLocalMethod(method, signaller);
1977: }
1978: }
1979:
1980: public void internalEnsureLocalMethod(IMethod method) {
1981: MultiChangeSignaller signaller = new MultiChangeSignaller();
1982: internalEnsureLocalMethod(method, signaller);
1983: signaller.signal(m_project);
1984: }
1985:
1986: public void internalEnsureLocalMethod(IMethod method,
1987: MultiChangeSignaller signaller) {
1988: DistributedMethods methods = getDistributedMethods();
1989:
1990: if (methods != null) {
1991: for (int i = methods.sizeOfMethodExpressionArray() - 1; i >= 0; i--) {
1992: String expr = methods.getMethodExpressionArray(i)
1993: .getStringValue();
1994:
1995: if (m_patternHelper.matchesMethod(expr, method)) {
1996: methods.removeMethodExpression(i);
1997: signaller.distributedMethodsChanged = true;
1998: }
1999: }
2000:
2001: testRemoveDistributedMethods();
2002: }
2003: }
2004:
2005: public boolean isLocked(IMethod method) {
2006: try {
2007: if (!method.getDeclaringType().isInterface()) {
2008: return isAutolocked(method) || isNameLocked(method);
2009: }
2010: } catch (JavaModelException jme) {/**/
2011: }
2012:
2013: return false;
2014: }
2015:
2016: public boolean isLocked(MethodDeclaration methodDecl) {
2017: IMethodBinding binding = methodDecl.resolveBinding();
2018:
2019: if (binding != null
2020: && !binding.getDeclaringClass().isInterface()) {
2021: return isLocked(PatternHelper
2022: .methodDecl2IMethod(methodDecl));
2023: }
2024:
2025: return false;
2026: }
2027:
2028: public boolean isAutolocked(IJavaElement element) {
2029: if (element instanceof IMethod) {
2030: return isAutolocked((IMethod) element);
2031: } else if (element instanceof IType) {
2032: return isAutolocked((IType) element);
2033: } else if (element instanceof IPackageDeclaration) {
2034: return isAutolocked((IPackageDeclaration) element);
2035: } else if (element instanceof IPackageFragment) {
2036: return isAutolocked((IPackageFragment) element);
2037: } else if (element instanceof IJavaProject) {
2038: return isAutolocked((IJavaProject) element);
2039: }
2040:
2041: return false;
2042: }
2043:
2044: public XmlObject getLock(IMethod method) {
2045: TcConfig config = getConfig();
2046:
2047: if (config != null) {
2048: MethodInfo methodInfo = m_patternHelper
2049: .getMethodInfo(method);
2050: Locks locks = getLocks();
2051:
2052: if (locks != null) {
2053: for (int i = locks.sizeOfAutolockArray() - 1; i >= 0; i--) {
2054: Autolock autolock = locks.getAutolockArray(i);
2055: String expr = autolock.getMethodExpression();
2056:
2057: if (m_patternHelper.matchesMember(expr, methodInfo)) {
2058: return autolock;
2059: }
2060: }
2061:
2062: for (int i = locks.sizeOfNamedLockArray() - 1; i >= 0; i--) {
2063: NamedLock namedLock = locks.getNamedLockArray(i);
2064: String expr = namedLock.getMethodExpression();
2065:
2066: if (m_patternHelper.matchesMember(expr, methodInfo)) {
2067: return namedLock;
2068: }
2069: }
2070: }
2071: }
2072:
2073: return null;
2074: }
2075:
2076: public boolean isAutolocked(IMethod method) {
2077: try {
2078: if (!method.getDeclaringType().isInterface()) {
2079: MethodInfo methodInfo = m_patternHelper
2080: .getMethodInfo(method);
2081: return methodInfo != null && isAutolocked(methodInfo);
2082: }
2083: } catch (JavaModelException jme) {/**/
2084: }
2085:
2086: return false;
2087: }
2088:
2089: private Boolean isAutolocked(MethodInfo methodInfo, Locks locks) {
2090: if (locks != null) {
2091: for (int i = 0; i < locks.sizeOfAutolockArray(); i++) {
2092: Autolock autolock = locks.getAutolockArray(i);
2093: String expr = autolock.getMethodExpression();
2094:
2095: if (m_patternHelper.matchesMember(expr, methodInfo)) {
2096: return Boolean.TRUE;
2097: }
2098: }
2099: }
2100: return null;
2101: }
2102:
2103: public boolean isAutolocked(MethodInfo methodInfo) {
2104: TcConfig config = getConfig();
2105:
2106: if (config != null) {
2107: Locks locks = getLocks();
2108:
2109: if (locks != null) {
2110: Boolean isAutolocked = isAutolocked(methodInfo, locks);
2111: if (isAutolocked != null) {
2112: return isAutolocked;
2113: }
2114: }
2115:
2116: ModulesConfiguration modulesConfig = m_plugin
2117: .getModulesConfiguration(m_project);
2118: if (modulesConfig != null) {
2119: locks = modulesConfig.getApplication().getLocks();
2120: if (locks != null) {
2121: Boolean isAutolocked = isAutolocked(methodInfo,
2122: locks);
2123: if (isAutolocked != null) {
2124: return isAutolocked;
2125: }
2126: }
2127: }
2128: }
2129:
2130: return false;
2131: }
2132:
2133: public boolean isAutolocked(MethodDeclaration methodDecl) {
2134: IMethodBinding binding = methodDecl.resolveBinding();
2135:
2136: if (binding != null
2137: && !binding.getDeclaringClass().isInterface()) {
2138: return isAutolocked(PatternHelper
2139: .methodDecl2IMethod(methodDecl));
2140: }
2141:
2142: return false;
2143: }
2144:
2145: // TODO: use m_patternHelper.matchesType(expr, type) here?
2146: public Boolean isAutolocked(IType type, Locks locks) {
2147: if (locks != null) {
2148: String typeExpr = PatternHelper.getExecutionPattern(type);
2149:
2150: for (int i = 0; i < locks.sizeOfAutolockArray(); i++) {
2151: Autolock autolock = locks.getAutolockArray(i);
2152: String expr = autolock.getMethodExpression();
2153:
2154: if (typeExpr.equals(expr)) {
2155: return Boolean.TRUE;
2156: }
2157: }
2158: }
2159: return null;
2160: }
2161:
2162: public boolean isAutolocked(IType type) {
2163: try {
2164: if (type.isInterface()) {
2165: return false;
2166: }
2167: } catch (JavaModelException jme) {/**/
2168: }
2169:
2170: TcConfig config = getConfig();
2171: if (config != null) {
2172: Locks locks = getLocks();
2173:
2174: if (locks != null) {
2175: Boolean isAutolocked = isAutolocked(type, locks);
2176: if (isAutolocked != null) {
2177: return isAutolocked;
2178: }
2179: }
2180:
2181: ModulesConfiguration modulesConfig = m_plugin
2182: .getModulesConfiguration(m_project);
2183: if (modulesConfig != null) {
2184: locks = modulesConfig.getApplication().getLocks();
2185: if (locks != null) {
2186: Boolean isAutolocked = isAutolocked(type, locks);
2187: if (isAutolocked != null) {
2188: return isAutolocked;
2189: }
2190: }
2191: }
2192: }
2193:
2194: return false;
2195: }
2196:
2197: public boolean isAutolocked(IPackageDeclaration packageDecl) {
2198: TcConfig config = getConfig();
2199:
2200: if (config != null) {
2201: Locks locks = getLocks();
2202:
2203: if (locks != null) {
2204: String fragExpr = PatternHelper
2205: .getExecutionPattern(packageDecl);
2206:
2207: for (int i = 0; i < locks.sizeOfAutolockArray(); i++) {
2208: Autolock autolock = locks.getAutolockArray(i);
2209: String expr = autolock.getMethodExpression();
2210:
2211: if (fragExpr.equals(expr)) {
2212: return true;
2213: }
2214: }
2215: }
2216: }
2217:
2218: return false;
2219: }
2220:
2221: public boolean isAutolocked(IPackageFragment fragment) {
2222: TcConfig config = getConfig();
2223:
2224: if (config != null) {
2225: Locks locks = getLocks();
2226:
2227: if (locks != null) {
2228: String fragExpr = PatternHelper
2229: .getExecutionPattern(fragment);
2230:
2231: for (int i = 0; i < locks.sizeOfAutolockArray(); i++) {
2232: Autolock autolock = locks.getAutolockArray(i);
2233: String expr = autolock.getMethodExpression();
2234:
2235: if (fragExpr.equals(expr)) {
2236: return true;
2237: }
2238: }
2239: }
2240: }
2241:
2242: return false;
2243: }
2244:
2245: public boolean isAutolocked(IJavaProject javaProject) {
2246: if (javaProject != null) {
2247: IPackageFragment[] fragments = getSourceFragments(javaProject);
2248:
2249: if (fragments.length > 0) {
2250: for (int i = 0; i < fragments.length; i++) {
2251: if (!isAutolocked(fragments[i])) {
2252: return false;
2253: }
2254: }
2255:
2256: return true;
2257: }
2258:
2259: }
2260:
2261: return false;
2262: }
2263:
2264: public boolean isNameLocked(IJavaElement element) {
2265: if (element instanceof IMethod) {
2266: return isNameLocked((IMethod) element);
2267: } else if (element instanceof IType) {
2268: return isNameLocked((IType) element);
2269: } else if (element instanceof IPackageDeclaration) {
2270: return isNameLocked((IPackageDeclaration) element);
2271: } else if (element instanceof IPackageFragment) {
2272: return isNameLocked((IPackageFragment) element);
2273: } else if (element instanceof IJavaProject) {
2274: return isNameLocked((IJavaProject) element);
2275: }
2276:
2277: return false;
2278: }
2279:
2280: public boolean isNameLocked(IMethod method) {
2281: try {
2282: if (!method.getDeclaringType().isInterface()) {
2283: MethodInfo methodInfo = m_patternHelper
2284: .getMethodInfo(method);
2285: return methodInfo != null && isNameLocked(methodInfo);
2286: }
2287: } catch (JavaModelException jme) {/**/
2288: }
2289:
2290: return false;
2291: }
2292:
2293: private Boolean isNameLocked(MethodInfo methodInfo, Locks locks) {
2294: if (locks != null) {
2295: for (int i = 0; i < locks.sizeOfNamedLockArray(); i++) {
2296: NamedLock namedLock = locks.getNamedLockArray(i);
2297: String expr = namedLock.getMethodExpression();
2298:
2299: if (m_patternHelper.matchesMember(expr, methodInfo)) {
2300: return Boolean.TRUE;
2301: }
2302: }
2303: }
2304: return null;
2305: }
2306:
2307: public boolean isNameLocked(MethodInfo methodInfo) {
2308: TcConfig config = getConfig();
2309:
2310: if (config != null) {
2311: Locks locks = getLocks();
2312:
2313: if (locks != null) {
2314: Boolean isNameLocked = isNameLocked(methodInfo, locks);
2315: if (isNameLocked != null) {
2316: return isNameLocked;
2317: }
2318: }
2319:
2320: ModulesConfiguration modulesConfig = m_plugin
2321: .getModulesConfiguration(m_project);
2322: if (modulesConfig != null) {
2323: locks = modulesConfig.getApplication().getLocks();
2324: if (locks != null) {
2325: Boolean isNameLocked = isNameLocked(methodInfo,
2326: locks);
2327: if (isNameLocked != null) {
2328: return isNameLocked;
2329: }
2330: }
2331: }
2332: }
2333:
2334: return false;
2335: }
2336:
2337: public boolean isNameLocked(MethodDeclaration methodDecl) {
2338: IMethodBinding binding = methodDecl.resolveBinding();
2339:
2340: if (binding != null
2341: && !binding.getDeclaringClass().isInterface()) {
2342: return isNameLocked(PatternHelper
2343: .methodDecl2IMethod(methodDecl));
2344: }
2345:
2346: return false;
2347: }
2348:
2349: private Boolean isNameLocked(IType type, Locks locks) {
2350: if (locks != null) {
2351: String typeExpr = PatternHelper.getExecutionPattern(type);
2352:
2353: for (int i = 0; i < locks.sizeOfNamedLockArray(); i++) {
2354: NamedLock namedLock = locks.getNamedLockArray(i);
2355: String expr = namedLock.getMethodExpression();
2356:
2357: if (typeExpr.equals(expr)) {
2358: return Boolean.TRUE;
2359: }
2360: }
2361: }
2362: return null;
2363: }
2364:
2365: public boolean isNameLocked(IType type) {
2366: try {
2367: if (type.isInterface()) {
2368: return false;
2369: }
2370: } catch (JavaModelException jme) {/**/
2371: }
2372:
2373: TcConfig config = getConfig();
2374: if (config != null) {
2375: Locks locks = getLocks();
2376:
2377: if (locks != null) {
2378: Boolean isNameLocked = isNameLocked(type, locks);
2379: if (isNameLocked != null) {
2380: return isNameLocked;
2381: }
2382: }
2383:
2384: ModulesConfiguration modulesConfig = m_plugin
2385: .getModulesConfiguration(m_project);
2386: if (modulesConfig != null) {
2387: locks = modulesConfig.getApplication().getLocks();
2388: if (locks != null) {
2389: Boolean isNameLocked = isNameLocked(type, locks);
2390: if (isNameLocked != null) {
2391: return isNameLocked;
2392: }
2393: }
2394: }
2395: }
2396:
2397: return false;
2398: }
2399:
2400: private Boolean isNameLocked(IPackageDeclaration packageDecl,
2401: Locks locks) {
2402: String fragExpr = PatternHelper
2403: .getExecutionPattern(packageDecl);
2404:
2405: for (int i = 0; i < locks.sizeOfNamedLockArray(); i++) {
2406: NamedLock namedLock = locks.getNamedLockArray(i);
2407: String expr = namedLock.getMethodExpression();
2408:
2409: if (fragExpr.equals(expr)) {
2410: return Boolean.TRUE;
2411: }
2412: }
2413: return null;
2414: }
2415:
2416: public boolean isNameLocked(IPackageDeclaration packageDecl) {
2417: TcConfig config = getConfig();
2418:
2419: if (config != null) {
2420: Locks locks = getLocks();
2421:
2422: if (locks != null) {
2423: Boolean isNameLocked = isNameLocked(packageDecl, locks);
2424: if (isNameLocked != null) {
2425: return isNameLocked;
2426: }
2427: }
2428:
2429: ModulesConfiguration modulesConfig = m_plugin
2430: .getModulesConfiguration(m_project);
2431: if (modulesConfig != null) {
2432: locks = modulesConfig.getApplication().getLocks();
2433: if (locks != null) {
2434: Boolean isNameLocked = isNameLocked(packageDecl,
2435: locks);
2436: if (isNameLocked != null) {
2437: return isNameLocked;
2438: }
2439: }
2440: }
2441: }
2442:
2443: return false;
2444: }
2445:
2446: private Boolean isNameLocked(IPackageFragment fragment, Locks locks) {
2447: if (locks != null) {
2448: String fragExpr = PatternHelper
2449: .getExecutionPattern(fragment);
2450:
2451: for (int i = 0; i < locks.sizeOfNamedLockArray(); i++) {
2452: NamedLock namedLock = locks.getNamedLockArray(i);
2453: String expr = namedLock.getMethodExpression();
2454:
2455: if (fragExpr.equals(expr)) {
2456: return Boolean.TRUE;
2457: }
2458: }
2459: }
2460: return null;
2461: }
2462:
2463: public boolean isNameLocked(IPackageFragment fragment) {
2464: TcConfig config = getConfig();
2465:
2466: if (config != null) {
2467: Locks locks = getLocks();
2468:
2469: if (locks != null) {
2470: Boolean isNameLocked = isNameLocked(fragment, locks);
2471: if (isNameLocked != null) {
2472: return isNameLocked;
2473: }
2474: }
2475:
2476: ModulesConfiguration modulesConfig = m_plugin
2477: .getModulesConfiguration(m_project);
2478: if (modulesConfig != null) {
2479: locks = modulesConfig.getApplication().getLocks();
2480: if (locks != null) {
2481: Boolean isNameLocked = isNameLocked(fragment, locks);
2482: if (isNameLocked != null) {
2483: return isNameLocked;
2484: }
2485: }
2486: }
2487: }
2488:
2489: return false;
2490: }
2491:
2492: public boolean isNameLocked(IJavaProject javaProject) {
2493: if (javaProject != null) {
2494: IPackageFragment[] fragments = getSourceFragments(javaProject);
2495:
2496: if (fragments.length > 0) {
2497: for (int i = 0; i < fragments.length; i++) {
2498: if (!isNameLocked(fragments[i])) {
2499: return false;
2500: }
2501: }
2502:
2503: return true;
2504: }
2505: }
2506:
2507: return false;
2508: }
2509:
2510: public void ensureNameLocked(IJavaElement element) {
2511: MultiChangeSignaller signaller = new MultiChangeSignaller();
2512: ensureNameLocked(element, element.getElementName(),
2513: LockLevel.WRITE, signaller);
2514: signaller.signal(m_project);
2515: }
2516:
2517: public void ensureNameLocked(IJavaElement element,
2518: MultiChangeSignaller signaller) {
2519: ensureNameLocked(element, element.getElementName(),
2520: LockLevel.WRITE, signaller);
2521: }
2522:
2523: public void ensureNameLocked(IJavaElement element, String name,
2524: LockLevel.Enum level) {
2525: MultiChangeSignaller signaller = new MultiChangeSignaller();
2526: ensureNameLocked(element, name, level, signaller);
2527: signaller.signal(m_project);
2528: }
2529:
2530: public void ensureNameLocked(IJavaElement element, String name,
2531: LockLevel.Enum level, MultiChangeSignaller signaller) {
2532: if (element instanceof IMethod) {
2533: ensureNameLocked((IMethod) element, name, level, signaller);
2534: } else if (element instanceof IType) {
2535: ensureNameLocked((IType) element, name, level, signaller);
2536: } else if (element instanceof IPackageDeclaration) {
2537: ensureNameLocked((IPackageDeclaration) element, name,
2538: level, signaller);
2539: } else if (element instanceof IPackageFragment) {
2540: ensureNameLocked((IPackageFragment) element, name, level,
2541: signaller);
2542: } else if (element instanceof IJavaProject) {
2543: ensureNameLocked((IJavaProject) element, name, level,
2544: signaller);
2545: }
2546: }
2547:
2548: public void ensureNameLocked(IMethod method, String name,
2549: LockLevel.Enum level) {
2550: MultiChangeSignaller signaller = new MultiChangeSignaller();
2551: ensureNameLocked(method, name, level, signaller);
2552: signaller.signal(m_project);
2553: }
2554:
2555: public void ensureNameLocked(IMethod method, String name,
2556: LockLevel.Enum level, MultiChangeSignaller signaller) {
2557: if (!isNameLocked(method)) {
2558: internalEnsureNameLocked(method, name, level, signaller);
2559: }
2560: }
2561:
2562: public NamedLock addNewNamedLock(final String name,
2563: final IMethod method, final LockLevel.Enum level,
2564: MultiChangeSignaller signaller) throws JavaModelException {
2565: return addNewNamedLock(name, PatternHelper
2566: .getJavadocSignature(method), level, signaller);
2567: }
2568:
2569: public NamedLock addNewNamedLock(final String name,
2570: final String expr, final LockLevel.Enum level,
2571: MultiChangeSignaller signaller) {
2572: Locks locks = ensureLocks();
2573: NamedLock lock = locks.addNewNamedLock();
2574:
2575: lock.setMethodExpression(expr);
2576: lock.setLockLevel(level);
2577: lock.setLockName(name);
2578: signaller.namedLocksChanged = true;
2579:
2580: for (int i = locks.sizeOfAutolockArray() - 1; i >= 0; i--) {
2581: Autolock autoLock = locks.getAutolockArray(i);
2582: if (expr.equals(autoLock.getMethodExpression())) {
2583: locks.removeAutolock(i);
2584: signaller.autolocksChanged = true;
2585: }
2586: }
2587:
2588: return lock;
2589: }
2590:
2591: public void internalEnsureNameLocked(IMethod method, String name,
2592: LockLevel.Enum level, MultiChangeSignaller signaller) {
2593: IType declaringType = method.getDeclaringType();
2594:
2595: if (!isAdaptable(declaringType)) {
2596: internalEnsureAdaptable(declaringType);
2597: signaller.includeRulesChanged = true;
2598: }
2599:
2600: try {
2601: addNewNamedLock(name, PatternHelper
2602: .getJavadocSignature(method), level, signaller);
2603: } catch (JavaModelException jme) {
2604: openError("Error ensuring method '"
2605: + method.getElementName() + "' name-locked", jme);
2606: return;
2607: }
2608: }
2609:
2610: public void ensureNameLocked(IType type, String name,
2611: LockLevel.Enum level) {
2612: MultiChangeSignaller signaller = new MultiChangeSignaller();
2613: ensureNameLocked(type, name, level, signaller);
2614: signaller.signal(m_project);
2615: }
2616:
2617: public void ensureNameLocked(IType type, String name,
2618: LockLevel.Enum level, MultiChangeSignaller signaller) {
2619: if (!isNameLocked(type)) {
2620: internalEnsureNameLocked(type, name, level, signaller);
2621: }
2622: }
2623:
2624: public void internalEnsureNameLocked(IType type, String name,
2625: LockLevel.Enum level) {
2626: MultiChangeSignaller signaller = new MultiChangeSignaller();
2627: internalEnsureNameLocked(type, name, level, signaller);
2628: signaller.signal(m_project);
2629: }
2630:
2631: public void internalEnsureNameLocked(IType type, String name,
2632: LockLevel.Enum level, MultiChangeSignaller signaller) {
2633: if (!isAdaptable(type)) {
2634: internalEnsureAdaptable(type, signaller);
2635: }
2636:
2637: addNewNamedLock(name, PatternHelper.getExecutionPattern(type),
2638: level, signaller);
2639: }
2640:
2641: public void ensureNameLocked(IPackageDeclaration packageDecl,
2642: String name, LockLevel.Enum level) {
2643: MultiChangeSignaller signaller = new MultiChangeSignaller();
2644: ensureNameLocked(packageDecl, name, level, signaller);
2645: signaller.signal(m_project);
2646: }
2647:
2648: public void ensureNameLocked(IPackageDeclaration packageDecl,
2649: String name, LockLevel.Enum level,
2650: MultiChangeSignaller signaller) {
2651: if (!isNameLocked(packageDecl)) {
2652: internalEnsureNameLocked(packageDecl, name, level,
2653: signaller);
2654: }
2655: }
2656:
2657: public void internalEnsureNameLocked(
2658: IPackageDeclaration packageDecl, String name,
2659: LockLevel.Enum level) {
2660: MultiChangeSignaller signaller = new MultiChangeSignaller();
2661: internalEnsureNameLocked(packageDecl, name, level, signaller);
2662: signaller.signal(m_project);
2663: }
2664:
2665: public void internalEnsureNameLocked(
2666: IPackageDeclaration packageDecl, String name,
2667: LockLevel.Enum level, MultiChangeSignaller signaller) {
2668: if (!isAdaptable(packageDecl)) {
2669: internalEnsureAdaptable(packageDecl, signaller);
2670: }
2671:
2672: addNewNamedLock(name, PatternHelper
2673: .getExecutionPattern(packageDecl), level, signaller);
2674: }
2675:
2676: public void ensureNameLocked(IPackageFragment fragment,
2677: String name, LockLevel.Enum level) {
2678: MultiChangeSignaller signaller = new MultiChangeSignaller();
2679: ensureNameLocked(fragment, name, level, signaller);
2680: signaller.signal(m_project);
2681: }
2682:
2683: public void ensureNameLocked(IPackageFragment fragment,
2684: String name, LockLevel.Enum level,
2685: MultiChangeSignaller signaller) {
2686: if (!isNameLocked(fragment)) {
2687: internalEnsureNameLocked(fragment, name, level, signaller);
2688: }
2689: }
2690:
2691: public void internalEnsureNameLocked(IPackageFragment fragment,
2692: String name, LockLevel.Enum level) {
2693: MultiChangeSignaller signaller = new MultiChangeSignaller();
2694: internalEnsureNameLocked(fragment, name, level, signaller);
2695: signaller.signal(m_project);
2696: }
2697:
2698: public void internalEnsureNameLocked(IPackageFragment fragment,
2699: String name, LockLevel.Enum level,
2700: MultiChangeSignaller signaller) {
2701: if (!isAdaptable(fragment)) {
2702: internalEnsureAdaptable(fragment, signaller);
2703: }
2704:
2705: addNewNamedLock(name, PatternHelper
2706: .getExecutionPattern(fragment), level, signaller);
2707: }
2708:
2709: public void ensureNameLocked(IJavaProject javaProject, String name,
2710: LockLevel.Enum level) {
2711: MultiChangeSignaller signaller = new MultiChangeSignaller();
2712: ensureNameLocked(javaProject, name, level, signaller);
2713: signaller.signal(m_project);
2714: }
2715:
2716: public void ensureNameLocked(IJavaProject javaProject, String name,
2717: LockLevel.Enum level, MultiChangeSignaller signaller) {
2718: if (javaProject != null && !isNameLocked(javaProject)) {
2719: internalEnsureNameLocked(javaProject, name, level,
2720: signaller);
2721: }
2722: }
2723:
2724: public void internalEnsureNameLocked(IJavaProject javaProject,
2725: String name, LockLevel.Enum level) {
2726: MultiChangeSignaller signaller = new MultiChangeSignaller();
2727: internalEnsureNameLocked(javaProject, name, level, signaller);
2728: signaller.signal(m_project);
2729: }
2730:
2731: public void internalEnsureNameLocked(IJavaProject javaProject,
2732: String name, LockLevel.Enum level,
2733: MultiChangeSignaller signaller) {
2734: IPackageFragment[] fragments = getSourceFragments(javaProject);
2735:
2736: for (int i = 0; i < fragments.length; i++) {
2737: if (!isNameLocked(fragments[i])) {
2738: internalEnsureNameLocked(fragments[i], name, level,
2739: signaller);
2740: }
2741: }
2742: }
2743:
2744: public void ensureAutolocked(IJavaElement element) {
2745: MultiChangeSignaller signaller = new MultiChangeSignaller();
2746: ensureAutolocked(element, signaller);
2747: signaller.signal(m_project);
2748: }
2749:
2750: public void ensureAutolocked(IJavaElement element,
2751: MultiChangeSignaller signaller) {
2752: if (element instanceof IMethod) {
2753: ensureAutolocked((IMethod) element, signaller);
2754: } else if (element instanceof IType) {
2755: ensureAutolocked((IType) element, signaller);
2756: } else if (element instanceof IPackageDeclaration) {
2757: ensureAutolocked((IPackageDeclaration) element, signaller);
2758: } else if (element instanceof IPackageFragment) {
2759: ensureAutolocked((IPackageFragment) element, signaller);
2760: } else if (element instanceof IJavaProject) {
2761: ensureAutolocked((IJavaProject) element, signaller);
2762: }
2763: }
2764:
2765: public void ensureAutolocked(IMethod method) {
2766: MultiChangeSignaller signaller = new MultiChangeSignaller();
2767: ensureAutolocked(method, signaller);
2768: signaller.signal(m_project);
2769: }
2770:
2771: public void ensureAutolocked(IMethod method,
2772: MultiChangeSignaller signaller) {
2773: if (!isAutolocked(method)) {
2774: internalEnsureAutolocked(method, LockLevel.WRITE, signaller);
2775: }
2776: }
2777:
2778: public void ensureAutolocked(IMethod method, LockLevel.Enum level,
2779: MultiChangeSignaller signaller) {
2780: if (!isAutolocked(method)) {
2781: internalEnsureAutolocked(method, level, signaller);
2782: }
2783: }
2784:
2785: public void internalEnsureAutolocked(IMethod method) {
2786: MultiChangeSignaller signaller = new MultiChangeSignaller();
2787: internalEnsureAutolocked(method, LockLevel.WRITE, signaller);
2788: signaller.signal(m_project);
2789: }
2790:
2791: public Autolock addNewAutolock(final IMethod method,
2792: final LockLevel.Enum level, MultiChangeSignaller signaller)
2793: throws JavaModelException {
2794: return addNewAutolock(
2795: PatternHelper.getJavadocSignature(method), level,
2796: signaller);
2797: }
2798:
2799: public Autolock addNewAutolock(final String expr,
2800: final LockLevel.Enum level) {
2801: MultiChangeSignaller signaller = new MultiChangeSignaller();
2802: Autolock lock = addNewAutolock(expr, level, signaller);
2803: signaller.signal(m_project);
2804: return lock;
2805: }
2806:
2807: public Autolock addNewAutolock(final String expr,
2808: final LockLevel.Enum level, MultiChangeSignaller signaller) {
2809: Locks locks = ensureLocks();
2810: Autolock lock = locks.addNewAutolock();
2811: lock.setMethodExpression(expr);
2812: lock.setLockLevel(level);
2813: signaller.autolocksChanged = true;
2814:
2815: for (int i = locks.sizeOfNamedLockArray() - 1; i >= 0; i--) {
2816: NamedLock namedLock = locks.getNamedLockArray(i);
2817: if (expr.equals(namedLock.getMethodExpression())) {
2818: locks.removeNamedLock(i);
2819: signaller.namedLocksChanged = true;
2820: }
2821: }
2822:
2823: return lock;
2824: }
2825:
2826: public void internalEnsureAutolocked(IMethod method,
2827: final LockLevel.Enum level, MultiChangeSignaller signaller) {
2828: IType declaringType = method.getDeclaringType();
2829:
2830: if (!isAdaptable(declaringType)) {
2831: internalEnsureAdaptable(declaringType, signaller);
2832: }
2833:
2834: try {
2835: addNewAutolock(PatternHelper.getJavadocSignature(method),
2836: level, signaller);
2837: } catch (JavaModelException jme) {
2838: openError("Error ensuring method '"
2839: + method.getElementName() + "' auto-locked", jme);
2840: return;
2841: }
2842: }
2843:
2844: public void ensureAutolocked(IType type) {
2845: MultiChangeSignaller signaller = new MultiChangeSignaller();
2846: ensureAutolocked(type, signaller);
2847: signaller.signal(m_project);
2848: }
2849:
2850: public void ensureAutolocked(IType type,
2851: MultiChangeSignaller signaller) {
2852: if (!isAutolocked(type)) {
2853: internalEnsureAutolocked(type, signaller);
2854: }
2855: }
2856:
2857: public void internalEnsureAutolocked(IType type) {
2858: MultiChangeSignaller signaller = new MultiChangeSignaller();
2859: internalEnsureAutolocked(type, signaller);
2860: signaller.signal(m_project);
2861: }
2862:
2863: public void internalEnsureAutolocked(IType type,
2864: MultiChangeSignaller signaller) {
2865: if (!isAdaptable(type)) {
2866: internalEnsureAdaptable(type, signaller);
2867: }
2868:
2869: addNewAutolock(PatternHelper.getExecutionPattern(type),
2870: LockLevel.WRITE, signaller);
2871: }
2872:
2873: public void ensureAutolocked(IPackageDeclaration packageDecl) {
2874: MultiChangeSignaller signaller = new MultiChangeSignaller();
2875: ensureAutolocked(packageDecl, signaller);
2876: signaller.signal(m_project);
2877: }
2878:
2879: public void ensureAutolocked(IPackageDeclaration packageDecl,
2880: MultiChangeSignaller signaller) {
2881: if (!isAutolocked(packageDecl)) {
2882: internalEnsureAutolocked(packageDecl, signaller);
2883: }
2884: }
2885:
2886: public void internalEnsureAutolocked(IPackageDeclaration packageDecl) {
2887: MultiChangeSignaller signaller = new MultiChangeSignaller();
2888: internalEnsureAutolocked(packageDecl, signaller);
2889: signaller.signal(m_project);
2890: }
2891:
2892: public void internalEnsureAutolocked(
2893: IPackageDeclaration packageDecl,
2894: MultiChangeSignaller signaller) {
2895: if (!isAdaptable(packageDecl)) {
2896: internalEnsureAdaptable(packageDecl, signaller);
2897: }
2898:
2899: addNewAutolock(PatternHelper.getExecutionPattern(packageDecl),
2900: LockLevel.WRITE, signaller);
2901: }
2902:
2903: public void ensureAutolocked(IPackageFragment fragment) {
2904: MultiChangeSignaller signaller = new MultiChangeSignaller();
2905: ensureAutolocked(fragment, signaller);
2906: signaller.signal(m_project);
2907: }
2908:
2909: public void ensureAutolocked(IPackageFragment fragment,
2910: MultiChangeSignaller signaller) {
2911: if (!isAutolocked(fragment)) {
2912: internalEnsureAutolocked(fragment, signaller);
2913: }
2914: }
2915:
2916: public void internalEnsureAutolocked(IPackageFragment fragment) {
2917: MultiChangeSignaller signaller = new MultiChangeSignaller();
2918: internalEnsureAutolocked(fragment, signaller);
2919: signaller.signal(m_project);
2920: }
2921:
2922: public void internalEnsureAutolocked(IPackageFragment fragment,
2923: MultiChangeSignaller signaller) {
2924: if (!isAdaptable(fragment)) {
2925: internalEnsureAdaptable(fragment, signaller);
2926: }
2927:
2928: addNewAutolock(PatternHelper.getExecutionPattern(fragment),
2929: LockLevel.WRITE, signaller);
2930: }
2931:
2932: public void ensureAutolocked(IJavaProject javaProject) {
2933: MultiChangeSignaller signaller = new MultiChangeSignaller();
2934: ensureAutolocked(javaProject, signaller);
2935: signaller.signal(m_project);
2936: }
2937:
2938: public void ensureAutolocked(IJavaProject javaProject,
2939: MultiChangeSignaller signaller) {
2940: if (javaProject != null && !isAutolocked(javaProject)) {
2941: internalEnsureAutolocked(javaProject, signaller);
2942: }
2943: }
2944:
2945: public void internalEnsureAutolocked(IJavaProject javaProject) {
2946: MultiChangeSignaller signaller = new MultiChangeSignaller();
2947: internalEnsureAutolocked(javaProject, signaller);
2948: signaller.signal(m_project);
2949: }
2950:
2951: public void internalEnsureAutolocked(IJavaProject javaProject,
2952: MultiChangeSignaller signaller) {
2953: if (javaProject != null) {
2954: IPackageFragment[] fragments = getSourceFragments(javaProject);
2955:
2956: for (int i = 0; i < fragments.length; i++) {
2957: if (!isAutolocked(fragments[i])) {
2958: internalEnsureAutolocked(fragments[i], signaller);
2959: }
2960: }
2961: }
2962: }
2963:
2964: public void ensureNotNameLocked(IJavaElement element) {
2965: MultiChangeSignaller signaller = new MultiChangeSignaller();
2966: ensureNotNameLocked(element, signaller);
2967: signaller.signal(m_project);
2968: }
2969:
2970: public void ensureNotNameLocked(IJavaElement element,
2971: MultiChangeSignaller signaller) {
2972: if (element instanceof IMethod) {
2973: ensureNotNameLocked((IMethod) element, signaller);
2974: } else if (element instanceof IType) {
2975: ensureNotNameLocked((IType) element, signaller);
2976: } else if (element instanceof IPackageFragment) {
2977: ensureNotNameLocked((IPackageFragment) element, signaller);
2978: } else if (element instanceof IJavaProject) {
2979: ensureNotNameLocked((IJavaProject) element, signaller);
2980: }
2981: }
2982:
2983: public void ensureNotNameLocked(IMethod method) {
2984: MultiChangeSignaller signaller = new MultiChangeSignaller();
2985: ensureNotNameLocked(method, signaller);
2986: signaller.signal(m_project);
2987: }
2988:
2989: public void ensureNotNameLocked(IMethod method,
2990: MultiChangeSignaller signaller) {
2991: MethodInfo methodInfo = m_patternHelper.getMethodInfo(method);
2992:
2993: if (methodInfo != null) {
2994: ensureNotNameLocked(methodInfo, signaller);
2995: }
2996: }
2997:
2998: public void ensureNotNameLocked(MethodInfo methodInfo) {
2999: MultiChangeSignaller signaller = new MultiChangeSignaller();
3000: ensureNotNameLocked(methodInfo, signaller);
3001: signaller.signal(m_project);
3002: }
3003:
3004: public void ensureNotNameLocked(MethodInfo methodInfo,
3005: MultiChangeSignaller signaller) {
3006: if (isNameLocked(methodInfo)) {
3007: internalEnsureNotNameLocked(methodInfo, signaller);
3008: }
3009: }
3010:
3011: public void internalEnsureNotNameLocked(MethodInfo methodInfo) {
3012: MultiChangeSignaller signaller = new MultiChangeSignaller();
3013: internalEnsureNotNameLocked(methodInfo, signaller);
3014: signaller.signal(m_project);
3015: }
3016:
3017: public void internalEnsureNotNameLocked(MethodInfo methodInfo,
3018: MultiChangeSignaller signaller) {
3019: Locks locks = getLocks();
3020:
3021: if (locks != null) {
3022: for (int i = locks.sizeOfNamedLockArray() - 1; i >= 0; i--) {
3023: String expr = locks.getNamedLockArray(i)
3024: .getMethodExpression();
3025:
3026: if (m_patternHelper.matchesMember(expr, methodInfo)) {
3027: locks.removeNamedLock(i);
3028: signaller.namedLocksChanged = true;
3029: }
3030: }
3031:
3032: testRemoveLocks();
3033: }
3034: }
3035:
3036: public void ensureNotNameLocked(IType type) {
3037: MultiChangeSignaller signaller = new MultiChangeSignaller();
3038: ensureNotNameLocked(type, signaller);
3039: signaller.signal(m_project);
3040: }
3041:
3042: public void ensureNotNameLocked(IType type,
3043: MultiChangeSignaller signaller) {
3044: if (isNameLocked(type)) {
3045: internalEnsureNotNameLocked(type, signaller);
3046: }
3047: }
3048:
3049: public void internalEnsureNotNameLocked(IType type) {
3050: MultiChangeSignaller signaller = new MultiChangeSignaller();
3051: internalEnsureNotNameLocked(type, signaller);
3052: signaller.signal(m_project);
3053: }
3054:
3055: public void internalEnsureNotNameLocked(IType type,
3056: MultiChangeSignaller signaller) {
3057: Locks locks = getLocks();
3058:
3059: if (locks != null) {
3060: String typeExpr = PatternHelper.getExecutionPattern(type);
3061:
3062: for (int i = locks.sizeOfNamedLockArray() - 1; i >= 0; i--) {
3063: String expr = locks.getNamedLockArray(i)
3064: .getMethodExpression();
3065:
3066: if (typeExpr.equals(expr)) {
3067: locks.removeNamedLock(i);
3068: signaller.namedLocksChanged = true;
3069: }
3070: }
3071:
3072: testRemoveLocks();
3073: }
3074: }
3075:
3076: public void ensureNotNameLocked(IPackageDeclaration packageDecl) {
3077: MultiChangeSignaller signaller = new MultiChangeSignaller();
3078: ensureNotNameLocked(packageDecl, signaller);
3079: signaller.signal(m_project);
3080: }
3081:
3082: public void ensureNotNameLocked(IPackageDeclaration packageDecl,
3083: MultiChangeSignaller signaller) {
3084: if (isNameLocked(packageDecl)) {
3085: internalEnsureNotNameLocked(packageDecl, signaller);
3086: }
3087: }
3088:
3089: public void internalEnsureNotNameLocked(
3090: IPackageDeclaration packageDecl) {
3091: MultiChangeSignaller signaller = new MultiChangeSignaller();
3092: internalEnsureNotNameLocked(packageDecl, signaller);
3093: signaller.signal(m_project);
3094: }
3095:
3096: public void internalEnsureNotNameLocked(
3097: IPackageDeclaration packageDecl,
3098: MultiChangeSignaller signaller) {
3099: Locks locks = getLocks();
3100:
3101: if (locks != null) {
3102: String fragExpr = PatternHelper
3103: .getExecutionPattern(packageDecl);
3104:
3105: for (int i = locks.sizeOfNamedLockArray() - 1; i >= 0; i--) {
3106: String expr = locks.getNamedLockArray(i)
3107: .getMethodExpression();
3108:
3109: if (fragExpr.equals(expr)) {
3110: locks.removeNamedLock(i);
3111: signaller.namedLocksChanged = true;
3112: }
3113: }
3114:
3115: testRemoveLocks();
3116: }
3117: }
3118:
3119: public void ensureNotNameLocked(IPackageFragment fragment) {
3120: MultiChangeSignaller signaller = new MultiChangeSignaller();
3121: ensureNotNameLocked(fragment, signaller);
3122: signaller.signal(m_project);
3123: }
3124:
3125: public void ensureNotNameLocked(IPackageFragment fragment,
3126: MultiChangeSignaller signaller) {
3127: if (isNameLocked(fragment)) {
3128: internalEnsureNotNameLocked(fragment, signaller);
3129: }
3130: }
3131:
3132: public void internalEnsureNotNameLocked(IPackageFragment fragment) {
3133: MultiChangeSignaller signaller = new MultiChangeSignaller();
3134: internalEnsureNotNameLocked(fragment, signaller);
3135: signaller.signal(m_project);
3136: }
3137:
3138: public void internalEnsureNotNameLocked(IPackageFragment fragment,
3139: MultiChangeSignaller signaller) {
3140: Locks locks = getLocks();
3141:
3142: if (locks != null) {
3143: String fragExpr = PatternHelper
3144: .getExecutionPattern(fragment);
3145:
3146: for (int i = locks.sizeOfNamedLockArray() - 1; i >= 0; i--) {
3147: String expr = locks.getNamedLockArray(i)
3148: .getMethodExpression();
3149:
3150: if (fragExpr.equals(expr)) {
3151: locks.removeNamedLock(i);
3152: signaller.namedLocksChanged = true;
3153: }
3154: }
3155:
3156: testRemoveLocks();
3157: }
3158: }
3159:
3160: public void ensureNotNameLocked(IJavaProject javaProject) {
3161: MultiChangeSignaller signaller = new MultiChangeSignaller();
3162: ensureNotNameLocked(javaProject, signaller);
3163: signaller.signal(m_project);
3164: }
3165:
3166: public void ensureNotNameLocked(IJavaProject javaProject,
3167: MultiChangeSignaller signaller) {
3168: if (javaProject != null && isNameLocked(javaProject)) {
3169: internalEnsureNotNameLocked(javaProject, signaller);
3170: }
3171: }
3172:
3173: public void internalEnsureNotNameLocked(IJavaProject javaProject) {
3174: MultiChangeSignaller signaller = new MultiChangeSignaller();
3175: internalEnsureNotNameLocked(javaProject, signaller);
3176: signaller.signal(m_project);
3177: }
3178:
3179: public void internalEnsureNotNameLocked(IJavaProject javaProject,
3180: MultiChangeSignaller signaller) {
3181: IPackageFragment[] fragments = getSourceFragments(javaProject);
3182:
3183: for (int i = 0; i < fragments.length; i++) {
3184: if (isNameLocked(fragments[i])) {
3185: internalEnsureNotNameLocked(fragments[i], signaller);
3186: }
3187: }
3188: }
3189:
3190: public void ensureNotAutolocked(IJavaElement element) {
3191: MultiChangeSignaller signaller = new MultiChangeSignaller();
3192: ensureNotAutolocked(element, signaller);
3193: signaller.signal(m_project);
3194: }
3195:
3196: public void ensureNotAutolocked(IJavaElement element,
3197: MultiChangeSignaller signaller) {
3198: if (element instanceof IMethod) {
3199: ensureNotAutolocked((IMethod) element, signaller);
3200: } else if (element instanceof IType) {
3201: ensureNotAutolocked((IType) element, signaller);
3202: } else if (element instanceof IPackageFragment) {
3203: ensureNotAutolocked((IPackageFragment) element, signaller);
3204: } else if (element instanceof IJavaProject) {
3205: ensureNotAutolocked((IJavaProject) element, signaller);
3206: }
3207: }
3208:
3209: public void ensureNotAutolocked(IMethod method) {
3210: MultiChangeSignaller signaller = new MultiChangeSignaller();
3211: ensureNotAutolocked(method, signaller);
3212: signaller.signal(m_project);
3213: }
3214:
3215: public void ensureNotAutolocked(IMethod method,
3216: MultiChangeSignaller signaller) {
3217: MethodInfo methodInfo = m_patternHelper.getMethodInfo(method);
3218:
3219: if (methodInfo != null) {
3220: ensureNotAutolocked(methodInfo, signaller);
3221: }
3222: }
3223:
3224: public void ensureNotAutolocked(MethodInfo methodInfo) {
3225: MultiChangeSignaller signaller = new MultiChangeSignaller();
3226: ensureNotAutolocked(methodInfo, signaller);
3227: signaller.signal(m_project);
3228: }
3229:
3230: public void ensureNotAutolocked(MethodInfo methodInfo,
3231: MultiChangeSignaller signaller) {
3232: if (isAutolocked(methodInfo)) {
3233: internalEnsureNotAutolocked(methodInfo, signaller);
3234: }
3235: }
3236:
3237: public void internalEnsureNotAutolocked(MethodInfo methodInfo) {
3238: MultiChangeSignaller signaller = new MultiChangeSignaller();
3239: internalEnsureNotAutolocked(methodInfo, signaller);
3240: signaller.signal(m_project);
3241: }
3242:
3243: public void internalEnsureNotAutolocked(MethodInfo methodInfo,
3244: MultiChangeSignaller signaller) {
3245: Locks locks = getLocks();
3246:
3247: if (locks != null) {
3248: for (int i = locks.sizeOfAutolockArray() - 1; i >= 0; i--) {
3249: String expr = locks.getAutolockArray(i)
3250: .getMethodExpression();
3251:
3252: if (m_patternHelper.matchesMember(expr, methodInfo)) {
3253: locks.removeAutolock(i);
3254: signaller.autolocksChanged = true;
3255: }
3256: }
3257:
3258: testRemoveLocks();
3259: }
3260: }
3261:
3262: public void ensureNotAutolocked(IType type) {
3263: MultiChangeSignaller signaller = new MultiChangeSignaller();
3264: ensureNotAutolocked(type, signaller);
3265: signaller.signal(m_project);
3266: }
3267:
3268: public void ensureNotAutolocked(IType type,
3269: MultiChangeSignaller signaller) {
3270: if (isAutolocked(type)) {
3271: internalEnsureNotAutolocked(type, signaller);
3272: }
3273: }
3274:
3275: public void internalEnsureNotAutolocked(IType type) {
3276: MultiChangeSignaller signaller = new MultiChangeSignaller();
3277: internalEnsureNotAutolocked(type, signaller);
3278: signaller.signal(m_project);
3279: }
3280:
3281: public void internalEnsureNotAutolocked(IType type,
3282: MultiChangeSignaller signaller) {
3283: Locks locks = getLocks();
3284:
3285: if (locks != null) {
3286: String typeExpr = PatternHelper.getExecutionPattern(type);
3287:
3288: for (int i = locks.sizeOfAutolockArray() - 1; i >= 0; i--) {
3289: String expr = locks.getAutolockArray(i)
3290: .getMethodExpression();
3291:
3292: if (typeExpr.equals(expr)) {
3293: locks.removeAutolock(i);
3294: signaller.autolocksChanged = true;
3295: }
3296: }
3297:
3298: testRemoveLocks();
3299: }
3300: }
3301:
3302: public void ensureNotAutolocked(IPackageDeclaration packageDecl) {
3303: MultiChangeSignaller signaller = new MultiChangeSignaller();
3304: ensureNotAutolocked(packageDecl, signaller);
3305: signaller.signal(m_project);
3306: }
3307:
3308: public void ensureNotAutolocked(IPackageDeclaration packageDecl,
3309: MultiChangeSignaller signaller) {
3310: if (isAutolocked(packageDecl)) {
3311: internalEnsureNotAutolocked(packageDecl, signaller);
3312: }
3313: }
3314:
3315: public void internalEnsureNotAutolocked(
3316: IPackageDeclaration packageDecl) {
3317: MultiChangeSignaller signaller = new MultiChangeSignaller();
3318: internalEnsureNotAutolocked(packageDecl, signaller);
3319: signaller.signal(m_project);
3320: }
3321:
3322: public void internalEnsureNotAutolocked(
3323: IPackageDeclaration packageDecl,
3324: MultiChangeSignaller signaller) {
3325: Locks locks = getLocks();
3326:
3327: if (locks != null) {
3328: String fragExpr = PatternHelper
3329: .getExecutionPattern(packageDecl);
3330:
3331: for (int i = locks.sizeOfAutolockArray() - 1; i >= 0; i--) {
3332: String expr = locks.getAutolockArray(i)
3333: .getMethodExpression();
3334:
3335: if (fragExpr.equals(expr)) {
3336: locks.removeAutolock(i);
3337: signaller.autolocksChanged = true;
3338: }
3339: }
3340:
3341: testRemoveLocks();
3342: }
3343: }
3344:
3345: public void ensureNotAutolocked(IPackageFragment fragment) {
3346: MultiChangeSignaller signaller = new MultiChangeSignaller();
3347: ensureNotAutolocked(fragment, signaller);
3348: signaller.signal(m_project);
3349: }
3350:
3351: public void ensureNotAutolocked(IPackageFragment fragment,
3352: MultiChangeSignaller signaller) {
3353: if (isAutolocked(fragment)) {
3354: internalEnsureNotAutolocked(fragment, signaller);
3355: }
3356: }
3357:
3358: public void internalEnsureNotAutolocked(IPackageFragment fragment) {
3359: MultiChangeSignaller signaller = new MultiChangeSignaller();
3360: internalEnsureNotAutolocked(fragment, signaller);
3361: signaller.signal(m_project);
3362: }
3363:
3364: public void internalEnsureNotAutolocked(IPackageFragment fragment,
3365: MultiChangeSignaller signaller) {
3366: Locks locks = getLocks();
3367:
3368: if (locks != null) {
3369: String fragExpr = PatternHelper
3370: .getExecutionPattern(fragment);
3371:
3372: for (int i = locks.sizeOfAutolockArray() - 1; i >= 0; i--) {
3373: String expr = locks.getAutolockArray(i)
3374: .getMethodExpression();
3375:
3376: if (fragExpr.equals(expr)) {
3377: locks.removeAutolock(i);
3378: signaller.autolocksChanged = true;
3379: }
3380: }
3381:
3382: testRemoveLocks();
3383: }
3384: }
3385:
3386: public void ensureNotAutolocked(IJavaProject javaProject) {
3387: MultiChangeSignaller signaller = new MultiChangeSignaller();
3388: ensureNotAutolocked(javaProject, signaller);
3389: signaller.signal(m_project);
3390: }
3391:
3392: public void ensureNotAutolocked(IJavaProject javaProject,
3393: MultiChangeSignaller signaller) {
3394: if (javaProject != null && isAutolocked(javaProject)) {
3395: internalEnsureNotAutolocked(javaProject, signaller);
3396: }
3397: }
3398:
3399: public void internalEnsureNotAutolocked(IJavaProject javaProject) {
3400: MultiChangeSignaller signaller = new MultiChangeSignaller();
3401: internalEnsureNotAutolocked(javaProject, signaller);
3402: signaller.signal(m_project);
3403: }
3404:
3405: public void internalEnsureNotAutolocked(IJavaProject javaProject,
3406: MultiChangeSignaller signaller) {
3407: IPackageFragment[] fragments = getSourceFragments(javaProject);
3408:
3409: for (int i = 0; i < fragments.length; i++) {
3410: if (isAutolocked(fragments[i])) {
3411: internalEnsureNotAutolocked(fragments[i], signaller);
3412: }
3413: }
3414: }
3415:
3416: public void ensureNotLocked(IMethod method) {
3417: MultiChangeSignaller signaller = new MultiChangeSignaller();
3418: ensureNotLocked(method, signaller);
3419: signaller.signal(m_project);
3420: }
3421:
3422: public void ensureNotLocked(IMethod method,
3423: MultiChangeSignaller signaller) {
3424: MethodInfo methodInfo = m_patternHelper.getMethodInfo(method);
3425:
3426: if (methodInfo != null) {
3427: ensureNotLocked(methodInfo, signaller);
3428: }
3429: }
3430:
3431: public void ensureNotLocked(MethodInfo methodInfo) {
3432: MultiChangeSignaller signaller = new MultiChangeSignaller();
3433: ensureNotLocked(methodInfo, signaller);
3434: signaller.signal(m_project);
3435: }
3436:
3437: public void ensureNotLocked(MethodInfo methodInfo,
3438: MultiChangeSignaller signaller) {
3439: if (methodInfo != null) {
3440: if (isAutolocked(methodInfo)) {
3441: internalEnsureNotAutolocked(methodInfo, signaller);
3442: }
3443: if (isNameLocked(methodInfo)) {
3444: internalEnsureNotNameLocked(methodInfo, signaller);
3445: }
3446: }
3447: }
3448:
3449: public void internalEnsureNotLocked(IMethod method) {
3450: MultiChangeSignaller signaller = new MultiChangeSignaller();
3451: internalEnsureNotLocked(method, signaller);
3452: signaller.signal(m_project);
3453: }
3454:
3455: public void internalEnsureNotLocked(IMethod method,
3456: MultiChangeSignaller signaller) {
3457: MethodInfo methodInfo = m_patternHelper.getMethodInfo(method);
3458:
3459: if (method != null) {
3460: internalEnsureNotLocked(methodInfo, signaller);
3461: }
3462: }
3463:
3464: public void internalEnsureNotLocked(MethodInfo methodInfo) {
3465: MultiChangeSignaller signaller = new MultiChangeSignaller();
3466: internalEnsureNotLocked(methodInfo, signaller);
3467: signaller.signal(m_project);
3468: }
3469:
3470: public void internalEnsureNotLocked(MethodInfo methodInfo,
3471: MultiChangeSignaller signaller) {
3472: if (isAutolocked(methodInfo)) {
3473: internalEnsureNotAutolocked(methodInfo, signaller);
3474: }
3475: if (isNameLocked(methodInfo)) {
3476: internalEnsureNotNameLocked(methodInfo, signaller);
3477: }
3478: }
3479:
3480: public void ensureNotLocked(IType type) {
3481: MultiChangeSignaller signaller = new MultiChangeSignaller();
3482: ensureNotLocked(type, signaller);
3483: signaller.signal(m_project);
3484: }
3485:
3486: public void ensureNotLocked(IType type,
3487: MultiChangeSignaller signaller) {
3488: if (isAutolocked(type)) {
3489: internalEnsureNotAutolocked(type, signaller);
3490: }
3491: if (isNameLocked(type)) {
3492: internalEnsureNotNameLocked(type, signaller);
3493: }
3494: }
3495:
3496: public void internalEnsureNotLocked(IType type) {
3497: MultiChangeSignaller signaller = new MultiChangeSignaller();
3498: internalEnsureNotLocked(type, signaller);
3499: signaller.signal(m_project);
3500: }
3501:
3502: public void internalEnsureNotLocked(IType type,
3503: MultiChangeSignaller signaller) {
3504: if (isAutolocked(type)) {
3505: internalEnsureNotAutolocked(type, signaller);
3506: }
3507:
3508: if (isNameLocked(type)) {
3509: internalEnsureNotNameLocked(type, signaller);
3510: }
3511: }
3512:
3513: public void ensureNotLocked(IPackageFragment fragment) {
3514: MultiChangeSignaller signaller = new MultiChangeSignaller();
3515: ensureNotLocked(fragment, signaller);
3516: signaller.signal(m_project);
3517: }
3518:
3519: public void ensureNotLocked(IPackageFragment fragment,
3520: MultiChangeSignaller signaller) {
3521: if (isAutolocked(fragment)) {
3522: internalEnsureNotAutolocked(fragment, signaller);
3523: }
3524: if (isNameLocked(fragment)) {
3525: internalEnsureNotNameLocked(fragment, signaller);
3526: }
3527: }
3528:
3529: public void internalEnsureNotLocked(IPackageDeclaration packageDecl) {
3530: MultiChangeSignaller signaller = new MultiChangeSignaller();
3531: internalEnsureNotLocked(packageDecl, signaller);
3532: signaller.signal(m_project);
3533: }
3534:
3535: public void internalEnsureNotLocked(
3536: IPackageDeclaration packageDecl,
3537: MultiChangeSignaller signaller) {
3538: if (isAutolocked(packageDecl)) {
3539: internalEnsureNotAutolocked(packageDecl, signaller);
3540: }
3541:
3542: if (isNameLocked(packageDecl)) {
3543: internalEnsureNotNameLocked(packageDecl, signaller);
3544: }
3545: }
3546:
3547: public void internalEnsureNotLocked(IPackageFragment fragment) {
3548: MultiChangeSignaller signaller = new MultiChangeSignaller();
3549: internalEnsureNotLocked(fragment, signaller);
3550: signaller.signal(m_project);
3551: }
3552:
3553: public void internalEnsureNotLocked(IPackageFragment fragment,
3554: MultiChangeSignaller signaller) {
3555: if (isAutolocked(fragment)) {
3556: internalEnsureNotAutolocked(fragment, signaller);
3557: }
3558:
3559: if (isNameLocked(fragment)) {
3560: internalEnsureNotNameLocked(fragment, signaller);
3561: }
3562: }
3563:
3564: public void ensureNotLocked(IJavaProject javaProject) {
3565: MultiChangeSignaller signaller = new MultiChangeSignaller();
3566: ensureNotLocked(javaProject, signaller);
3567: signaller.signal(m_project);
3568: }
3569:
3570: public void ensureNotLocked(IJavaProject javaProject,
3571: MultiChangeSignaller signaller) {
3572: if (javaProject != null) {
3573: IPackageFragment[] fragments = getSourceFragments(javaProject);
3574:
3575: for (int i = 0; i < fragments.length; i++) {
3576: if (isAutolocked(fragments[i])) {
3577: internalEnsureNotAutolocked(fragments[i], signaller);
3578: }
3579: if (isNameLocked(fragments[i])) {
3580: internalEnsureNotNameLocked(fragments[i], signaller);
3581: }
3582: }
3583: }
3584: }
3585:
3586: public boolean isBootJarClass(ICompilationUnit module) {
3587: return isBootJarClass(module.findPrimaryType());
3588: }
3589:
3590: public boolean isBootJarClass(IType type) {
3591: return isBootJarClass(PatternHelper.getFullyQualifiedName(type));
3592: }
3593:
3594: private Boolean isBootJarClass(String className,
3595: AdditionalBootJarClasses abjc) {
3596: if (abjc != null) {
3597: String[] includes = abjc.getIncludeArray();
3598:
3599: for (int i = 0; i < includes.length; i++) {
3600: if (m_patternHelper
3601: .matchesClass(includes[i], className)) {
3602: return Boolean.TRUE;
3603: }
3604: }
3605: }
3606: return null;
3607: }
3608:
3609: public boolean isBootJarClass(String className) {
3610: AdditionalBootJarClasses abjc = getAdditionalBootJarClasses();
3611:
3612: if (abjc != null) {
3613: Boolean isBootJarClass = isBootJarClass(className, abjc);
3614: if (isBootJarClass != null) {
3615: return isBootJarClass;
3616: }
3617: }
3618:
3619: ModulesConfiguration modulesConfig = m_plugin
3620: .getModulesConfiguration(m_project);
3621: if (modulesConfig != null) {
3622: abjc = modulesConfig.getApplication()
3623: .getAdditionalBootJarClasses();
3624: if (abjc != null) {
3625: Boolean isBootJarClass = isBootJarClass(className, abjc);
3626: if (isBootJarClass != null) {
3627: return isBootJarClass;
3628: }
3629: }
3630: }
3631:
3632: return false;
3633: }
3634:
3635: public void ensureBootJarClass(ICompilationUnit module) {
3636: MultiChangeSignaller signaller = new MultiChangeSignaller();
3637: ensureBootJarClass(module, signaller);
3638: signaller.signal(m_project);
3639: }
3640:
3641: public void ensureBootJarClass(ICompilationUnit module,
3642: MultiChangeSignaller signaller) {
3643: ensureBootJarClass(module.findPrimaryType(), signaller);
3644: }
3645:
3646: public void ensureBootJarClass(IType type) {
3647: MultiChangeSignaller signaller = new MultiChangeSignaller();
3648: ensureBootJarClass(type, signaller);
3649: signaller.signal(m_project);
3650: }
3651:
3652: public void ensureBootJarClass(IType type,
3653: MultiChangeSignaller signaller) {
3654: ensureBootJarClass(PatternHelper.getFullyQualifiedName(type),
3655: signaller);
3656: }
3657:
3658: public void internalEnsureBootJarClass(IType type) {
3659: MultiChangeSignaller signaller = new MultiChangeSignaller();
3660: internalEnsureBootJarClass(type, signaller);
3661: signaller.signal(m_project);
3662: }
3663:
3664: public void internalEnsureBootJarClass(IType type,
3665: MultiChangeSignaller signaller) {
3666: internalEnsureBootJarClass(PatternHelper
3667: .getFullyQualifiedName(type), signaller);
3668: }
3669:
3670: public void ensureBootJarClass(String className) {
3671: MultiChangeSignaller signaller = new MultiChangeSignaller();
3672: ensureBootJarClass(className, signaller);
3673: signaller.signal(m_project);
3674: }
3675:
3676: public void ensureBootJarClass(String className,
3677: MultiChangeSignaller signaller) {
3678: if (!isBootJarClass(className)) {
3679: internalEnsureBootJarClass(className, signaller);
3680: }
3681: }
3682:
3683: public void internalEnsureBootJarClass(String className) {
3684: MultiChangeSignaller signaller = new MultiChangeSignaller();
3685: internalEnsureBootJarClass(className, signaller);
3686: signaller.signal(m_project);
3687: }
3688:
3689: public void internalEnsureBootJarClass(String className,
3690: MultiChangeSignaller signaller) {
3691: ensureAdditionalBootJarClasses().addInclude(className);
3692: signaller.bootClassesChanged = true;
3693: }
3694:
3695: public void ensureNotBootJarClass(ICompilationUnit module) {
3696: MultiChangeSignaller signaller = new MultiChangeSignaller();
3697: ensureNotBootJarClass(module, signaller);
3698: signaller.signal(m_project);
3699: }
3700:
3701: public void ensureNotBootJarClass(ICompilationUnit module,
3702: MultiChangeSignaller signaller) {
3703: if (module != null) {
3704: internalEnsureNotBootJarClass(module, signaller);
3705: }
3706: }
3707:
3708: public void internalEnsureNotBootJarClass(ICompilationUnit module) {
3709: MultiChangeSignaller signaller = new MultiChangeSignaller();
3710: internalEnsureNotBootJarClass(module, signaller);
3711: signaller.signal(m_project);
3712: }
3713:
3714: public void internalEnsureNotBootJarClass(ICompilationUnit module,
3715: MultiChangeSignaller signaller) {
3716: internalEnsureNotBootJarClass(module.findPrimaryType(),
3717: signaller);
3718: }
3719:
3720: public void ensureNotBootJarClass(IType type) {
3721: MultiChangeSignaller signaller = new MultiChangeSignaller();
3722: internalEnsureNotBootJarClass(type, signaller);
3723: signaller.signal(m_project);
3724: }
3725:
3726: public void ensureNotBootJarClass(IType type,
3727: MultiChangeSignaller signaller) {
3728: if (type != null && isBootJarClass(type)) {
3729: internalEnsureNotBootJarClass(type, signaller);
3730: }
3731: }
3732:
3733: public void internalEnsureNotBootJarClass(IType type) {
3734: MultiChangeSignaller signaller = new MultiChangeSignaller();
3735: internalEnsureNotBootJarClass(type, signaller);
3736: signaller.signal(m_project);
3737: }
3738:
3739: public void internalEnsureNotBootJarClass(IType type,
3740: MultiChangeSignaller signaller) {
3741: internalEnsureNotBootJarClass(PatternHelper
3742: .getFullyQualifiedName(type), signaller);
3743: }
3744:
3745: public void ensureNotBootJarClass(String className) {
3746: MultiChangeSignaller signaller = new MultiChangeSignaller();
3747: ensureNotBootJarClass(className, signaller);
3748: signaller.signal(m_project);
3749: }
3750:
3751: public void ensureNotBootJarClass(String className,
3752: MultiChangeSignaller signaller) {
3753: if (isBootJarClass(className)) {
3754: internalEnsureNotBootJarClass(className, signaller);
3755: }
3756: }
3757:
3758: public void internalEnsureNotBootJarClass(String className) {
3759: MultiChangeSignaller signaller = new MultiChangeSignaller();
3760: internalEnsureNotBootJarClass(className, signaller);
3761: signaller.signal(m_project);
3762: }
3763:
3764: public void internalEnsureNotBootJarClass(String className,
3765: MultiChangeSignaller signaller) {
3766: AdditionalBootJarClasses classes = getAdditionalBootJarClasses();
3767:
3768: if (classes != null) {
3769: String[] includes = classes.getIncludeArray();
3770:
3771: for (int i = includes.length - 1; i >= 0; i--) {
3772: if (m_patternHelper
3773: .matchesClass(includes[i], className)) {
3774: classes.removeInclude(i);
3775: signaller.includeRulesChanged = true;
3776: }
3777: }
3778:
3779: testRemoveAdditionalBootJarClasses();
3780: }
3781: }
3782:
3783: public boolean hasBootJarClasses() {
3784: AdditionalBootJarClasses classes = getAdditionalBootJarClasses();
3785: return classes != null && classes.sizeOfIncludeArray() > 0;
3786: }
3787:
3788: public boolean hasModules() {
3789: Modules modules = getModules();
3790: return modules != null && modules.sizeOfModuleArray() > 0;
3791: }
3792:
3793: // Validation support
3794:
3795: public void validateAll() {
3796: if (getConfig() != null) {
3797: // DISABLING VALIDATING FOR ANYTHING THAT CAN TAKE A PATTERN
3798: // validateLocks();
3799: // validateInstrumentedClasses();
3800: validateRoots();
3801: validateTransientFields();
3802: validateBootJarClasses();
3803: validateModules();
3804: }
3805: }
3806:
3807: private static String LOCK_PROBLEM_MARKER = "org.terracotta.dso.LockMethodProblemMarker";
3808:
3809: private static String getRawString(XmlString xmlString) {
3810: if (xmlString == null)
3811: return null;
3812: String s = xmlString.toString();
3813: if (s != null) {
3814: s = s.substring(s.indexOf('>') + 1);
3815: int end = s.indexOf('<');
3816: if (end != -1) {
3817: s = s.substring(0, end);
3818: }
3819: }
3820: return s;
3821: }
3822:
3823: public void validateLocks() {
3824: clearConfigProblemMarkersOfType(LOCK_PROBLEM_MARKER);
3825:
3826: Locks locks = getLocks();
3827:
3828: if (locks != null) {
3829: Autolock[] autoLocks = locks.getAutolockArray();
3830: NamedLock[] namedLocks = locks.getNamedLockArray();
3831:
3832: if (autoLocks != null) {
3833: for (int i = 0; i < autoLocks.length; i++) {
3834: validateLockMethodExpression(getRawString(autoLocks[i]
3835: .xgetMethodExpression()));
3836: }
3837: }
3838:
3839: if (namedLocks != null) {
3840: for (int i = 0; i < namedLocks.length; i++) {
3841: validateLockMethodExpression(getRawString(namedLocks[i]
3842: .xgetMethodExpression()));
3843: }
3844: }
3845: }
3846: }
3847:
3848: private static String ROOT_PROBLEM_MARKER = "org.terracotta.dso.RootProblemMarker";
3849:
3850: public void validateRoots() {
3851: clearConfigProblemMarkersOfType(ROOT_PROBLEM_MARKER);
3852:
3853: Roots roots = getRoots();
3854:
3855: if (roots != null) {
3856: Root[] rootArray = roots.getRootArray();
3857:
3858: for (int i = 0; i < rootArray.length; i++) {
3859: validateRoot(rootArray[i]);
3860: }
3861: }
3862: }
3863:
3864: private static boolean isInterface(IType type) {
3865: try {
3866: return type.isInterface();
3867: } catch (JavaModelException jme) {
3868: return false;
3869: }
3870: }
3871:
3872: private static String[] PRIMITIVE_NAMES = new String[] {
3873: "java.lang.String", "java.lang.Integer",
3874: "java.lang.Boolean", "java.lang.Double",
3875: "java.lang.Character", "java.lang.Byte" };
3876:
3877: private static ArrayList<String> PRIMITIVES = new ArrayList<String>(
3878: Arrays.asList(PRIMITIVE_NAMES));
3879:
3880: private static boolean isPrimitive(IType type) {
3881: try {
3882: String name = type.getFullyQualifiedName();
3883: return PRIMITIVES.contains(name);
3884: } catch (Exception e) {
3885: return false;
3886: }
3887: }
3888:
3889: private void validateRoot(Root root) {
3890: String rootName = getRawString(root.xgetFieldName());
3891: String msg = validateField(rootName);
3892:
3893: if (msg == null) {
3894: IField field = getField(root.getFieldName());
3895: IType fieldType = getFieldType(field);
3896:
3897: if (fieldType != null && !isInterface(fieldType)
3898: && !isPrimitive(fieldType)
3899: && !isAdaptable(fieldType)
3900: && !isBootJarClass(fieldType)
3901: && !m_plugin.isBootClass(fieldType)) {
3902: String fullName = PatternHelper
3903: .getFullyQualifiedName(fieldType);
3904: msg = "Root type '" + fullName + "' not instrumented";
3905: }
3906: }
3907:
3908: if (msg != null) {
3909: reportConfigProblem(rootName, msg, ROOT_PROBLEM_MARKER);
3910: }
3911: }
3912:
3913: private static String TRANSIENT_PROBLEM_MARKER = "org.terracotta.dso.TransientProblemMarker";
3914:
3915: public void validateTransientFields() {
3916: clearConfigProblemMarkersOfType(TRANSIENT_PROBLEM_MARKER);
3917:
3918: TransientFields transientFields = getTransientFields();
3919:
3920: if (transientFields != null) {
3921: for (int i = 0; i < transientFields.sizeOfFieldNameArray(); i++) {
3922: String field = getRawString(transientFields
3923: .xgetFieldNameArray(i));
3924: validateTransientField(field);
3925: }
3926: }
3927: }
3928:
3929: private void validateTransientField(String fieldName) {
3930: String msg = validateField(fieldName);
3931:
3932: if (msg == null) {
3933: IField field = getField(fieldName);
3934: IType declaringType = field.getDeclaringType();
3935:
3936: if (declaringType != null && !isAdaptable(declaringType)
3937: && !isBootJarClass(declaringType)) {
3938: String fullName = PatternHelper
3939: .getFullyQualifiedName(declaringType);
3940: msg = "Declaring type '" + fullName
3941: + "' not instrumented";
3942: }
3943: }
3944:
3945: if (msg != null) {
3946: reportConfigProblem(fieldName, msg,
3947: TRANSIENT_PROBLEM_MARKER);
3948: }
3949: }
3950:
3951: private static String INSTRUMENTED_PROBLEM_MARKER = "org.terracotta.dso.InstrumentedProblemMarker";
3952:
3953: public void validateInstrumentedClasses() {
3954: clearConfigProblemMarkersOfType(INSTRUMENTED_PROBLEM_MARKER);
3955:
3956: InstrumentedClasses instrumentedClasses = getInstrumentedClasses();
3957:
3958: if (instrumentedClasses != null) {
3959: validateIncludes(instrumentedClasses);
3960: validateExcludes(instrumentedClasses);
3961: }
3962: }
3963:
3964: private void validateIncludes(
3965: InstrumentedClasses instrumentedClasses) {
3966: for (int i = 0; i < instrumentedClasses.sizeOfIncludeArray(); i++) {
3967: Include include = instrumentedClasses.getIncludeArray(i);
3968: String expr = getRawString(include.xgetClassExpression());
3969:
3970: validateInstrumentedTypeExpression(expr);
3971: }
3972: }
3973:
3974: private void validateExcludes(
3975: InstrumentedClasses instrumentedClasses) {
3976: for (int i = 0; i < instrumentedClasses.sizeOfExcludeArray(); i++) {
3977: String exclude = getRawString(instrumentedClasses
3978: .xgetExcludeArray(i));
3979: validateInstrumentedTypeExpression(exclude);
3980: }
3981: }
3982:
3983: private void validateInstrumentedTypeExpression(String typeExpr) {
3984: String msg = null;
3985: String expr = typeExpr != null ? typeExpr.trim() : null;
3986:
3987: if (expr != null
3988: && (expr.indexOf('*') != -1 || expr.indexOf('+') != -1)) {
3989: return;
3990: }
3991:
3992: try {
3993: if (expr != null
3994: && JdtUtils.findType(m_javaProject, expr) != null) {
3995: return;
3996: }
3997: } catch (JavaModelException jme) {/**/
3998: }
3999:
4000: if (expr != null && expr.length() > 0) {
4001: String prefix = findTypeExpressionPrefix(expr);
4002:
4003: try {
4004: IPackageFragment[] fragments = m_javaProject
4005: .getPackageFragments();
4006:
4007: for (int i = 0; i < fragments.length; i++) {
4008: IPackageFragment fragment = fragments[i];
4009:
4010: if (fragment.getKind() == IPackageFragmentRoot.K_SOURCE
4011: && fragment.getElementName().startsWith(
4012: prefix)) {
4013: ICompilationUnit[] cus = fragment
4014: .getCompilationUnits();
4015:
4016: for (int j = 0; j < cus.length; j++) {
4017: ICompilationUnit cu = cus[j];
4018: String cuType = PatternHelper
4019: .getFullyQualifiedName(cu
4020: .findPrimaryType());
4021:
4022: if (cuType.startsWith(prefix)) {
4023: IType[] types = cus[j].getAllTypes();
4024:
4025: for (int k = 0; k < types.length; k++) {
4026: IType type = types[k];
4027:
4028: if (!type.isInterface()) {
4029: if (matchesType(expr, type)) {
4030: return;
4031: }
4032: }
4033: }
4034: }
4035: }
4036: }
4037: }
4038:
4039: for (int i = 0; i < fragments.length; i++) {
4040: IPackageFragment fragment = fragments[i];
4041:
4042: if (fragment.getKind() == IPackageFragmentRoot.K_BINARY
4043: && fragment.getElementName().startsWith(
4044: prefix)) {
4045: IClassFile[] classFiles = fragment
4046: .getClassFiles();
4047:
4048: for (int j = 0; j < classFiles.length; j++) {
4049: IType type = classFiles[j].getType();
4050: String typeName = PatternHelper
4051: .getFullyQualifiedName(type);
4052: int flags = type.getFlags();
4053:
4054: if (typeName.startsWith(prefix)) {
4055: if (!type.isInterface()
4056: && !type.isAnonymous()
4057: && !type.isMember()
4058: && !type.isEnum()
4059: && !type.isAnnotation()
4060: && !Flags.isProtected(flags)
4061: && !Flags.isPrivate(flags)
4062: && !Flags.isStatic(flags)) {
4063: if (matchesType(expr, type)) {
4064: return;
4065: }
4066: }
4067: }
4068: }
4069: }
4070: }
4071:
4072: msg = "No type matches expression '" + expr + "'";
4073: } catch (JavaModelException jme) {
4074: msg = jme.getMessage();
4075: }
4076: } else {
4077: msg = "Empty AspectWerks class expression";
4078: }
4079:
4080: if (msg != null) {
4081: reportConfigProblem(typeExpr, msg,
4082: INSTRUMENTED_PROBLEM_MARKER);
4083: }
4084: }
4085:
4086: private String findTypeExpressionPrefix(String typeExpr) {
4087: String[] elems = StringUtils.split(typeExpr, '.');
4088: char[] codes = new char[] { '*', '?', '.', '$' };
4089: ArrayList<String> list = new ArrayList<String>();
4090:
4091: for (int i = 0; i < elems.length; i++) {
4092: String elem = elems[i];
4093:
4094: if (elem.length() > 0
4095: && StringUtils.containsNone(elems[i], codes)) {
4096: list.add(elem);
4097: }
4098: }
4099:
4100: return StringUtils.join(list.toArray(), '.');
4101: }
4102:
4103: private boolean matchesType(String typeExpr, IType type) {
4104: String name = PatternHelper.getFullyQualifiedName(type);
4105: int nameLen = name.length();
4106: int exprLen = typeExpr.length();
4107:
4108: if (typeExpr.equals(name)) {
4109: return true;
4110: }
4111:
4112: for (int z = 0; z < exprLen; z++) {
4113: char ec = typeExpr.charAt(z);
4114:
4115: if (z == nameLen || name.charAt(z) != ec) {
4116: if (ec == '.' || ec == '*' || ec == '?') {
4117: return m_patternHelper.matchesType(typeExpr, type);
4118: }
4119: break;
4120: }
4121: }
4122:
4123: return false;
4124: }
4125:
4126: private void validateLockMethodExpression(String methodExpr) {
4127: String msg = validateMethodExpression(methodExpr);
4128:
4129: if (msg != null) {
4130: reportConfigProblem(methodExpr, msg, LOCK_PROBLEM_MARKER);
4131: }
4132: }
4133:
4134: private static String DISTRIBUTED_METHOD_PROBLEM_MARKER = "org.terracotta.dso.DistributedMethodProblemMarker";
4135:
4136: public void validateDistributedMethods() {
4137: clearConfigProblemMarkersOfType(DISTRIBUTED_METHOD_PROBLEM_MARKER);
4138:
4139: DistributedMethods distributedMethods = getDistributedMethods();
4140:
4141: if (distributedMethods != null) {
4142: for (int i = 0; i < distributedMethods
4143: .sizeOfMethodExpressionArray(); i++) {
4144: String methodExpr = distributedMethods
4145: .getMethodExpressionArray(i).getStringValue();
4146: validateDistributedMethodExpression(methodExpr);
4147: }
4148: }
4149: }
4150:
4151: private void validateDistributedMethodExpression(String methodExpr) {
4152: String msg = validateMethodExpression(methodExpr);
4153:
4154: if (msg != null) {
4155: reportConfigProblem(methodExpr, msg,
4156: DISTRIBUTED_METHOD_PROBLEM_MARKER);
4157: }
4158: }
4159:
4160: private String validateField(String fullName) {
4161: String msg = null;
4162: int lastDotIndex;
4163:
4164: if (fullName != null) {
4165: fullName = fullName.trim();
4166: }
4167:
4168: if (fullName != null && (fullName.length() > 0)
4169: && (lastDotIndex = fullName.lastIndexOf('.')) != -1) {
4170: String className = fullName.substring(0, lastDotIndex)
4171: .replace('$', '.');
4172: String fieldName = fullName.substring(lastDotIndex + 1);
4173:
4174: try {
4175: IType type;
4176: IField field;
4177:
4178: if ((type = JdtUtils.findType(m_javaProject, className)) == null) {
4179: msg = "Class not found: " + className;
4180: } else if ((field = type.getField(fieldName)) == null
4181: || !field.exists()) {
4182: msg = "No such field: " + fieldName;
4183: }
4184: } catch (JavaModelException jme) {
4185: msg = jme.getMessage();
4186: }
4187: } else {
4188: msg = "Must be a fully-qualified field name";
4189: }
4190:
4191: return msg;
4192: }
4193:
4194: private String validateMethodExpression(String methodExpr) {
4195: String msg = null;
4196:
4197: if (methodExpr != null && methodExpr.length() > 0) {
4198: try {
4199: m_patternHelper
4200: .testValidateMethodExpression(methodExpr);
4201: } catch (Exception e) {
4202: return e.getMessage();
4203: }
4204:
4205: try {
4206: String prefix = findMethodExpressionPrefix(methodExpr);
4207:
4208: if (prefix != null && prefix.length() > 0) {
4209: try {
4210: IType type = JdtUtils.findType(m_javaProject,
4211: prefix);
4212:
4213: if (type != null) {
4214: IMethod[] methods = type.getMethods();
4215:
4216: for (int m = 0; m < methods.length; m++) {
4217: if (m_patternHelper.matchesMethod(
4218: methodExpr, methods[m])) {
4219: return null;
4220: }
4221: }
4222: }
4223: } catch (JavaModelException jme) {/**/
4224: }
4225: }
4226:
4227: IPackageFragment[] fragments = m_javaProject
4228: .getPackageFragments();
4229:
4230: for (int i = 0; i < fragments.length; i++) {
4231: IPackageFragment fragment = fragments[i];
4232:
4233: if (fragment.getKind() == IPackageFragmentRoot.K_SOURCE
4234: && fragment.getElementName().startsWith(
4235: prefix)) {
4236: ICompilationUnit[] cus = fragment
4237: .getCompilationUnits();
4238:
4239: for (int j = 0; j < cus.length; j++) {
4240: ICompilationUnit cu = cus[j];
4241: String cuType = PatternHelper
4242: .getFullyQualifiedName(cu
4243: .findPrimaryType());
4244:
4245: if (cuType.startsWith(prefix)) {
4246: IType[] types = cus[j].getAllTypes();
4247:
4248: for (int k = 0; k < types.length; k++) {
4249: IType type = types[k];
4250:
4251: if (!type.isInterface()
4252: && !type.isAnonymous()) {
4253: if (matchesMethod(methodExpr,
4254: type)) {
4255: return null;
4256: }
4257: }
4258: }
4259: }
4260: }
4261: }
4262: }
4263:
4264: for (int i = 0; i < fragments.length; i++) {
4265: IPackageFragment fragment = fragments[i];
4266:
4267: if (fragment.getKind() == IPackageFragmentRoot.K_BINARY
4268: && fragment.getElementName().startsWith(
4269: prefix)) {
4270: IClassFile[] classFiles = fragment
4271: .getClassFiles();
4272:
4273: for (int j = 0; j < classFiles.length; j++) {
4274: IType type = classFiles[j].getType();
4275: String typeName = PatternHelper
4276: .getFullyQualifiedName(type);
4277: int flags = type.getFlags();
4278:
4279: if (typeName.startsWith(prefix)) {
4280: if (!type.isInterface()
4281: && !type.isAnonymous()
4282: && !type.isMember()
4283: && !type.isEnum()
4284: && !type.isAnnotation()
4285: && !Flags.isPrivate(flags)
4286: && !Flags.isProtected(flags)
4287: && !Flags.isStatic(flags)) {
4288: if (matchesMethod(methodExpr, type)) {
4289: return null;
4290: }
4291: }
4292: }
4293: }
4294: }
4295: }
4296:
4297: msg = "No method matching expression '" + methodExpr
4298: + "'";
4299: } catch (JavaModelException jme) {
4300: msg = jme.getMessage();
4301: }
4302: } else {
4303: msg = "Must be a fully-qualified method name";
4304: }
4305:
4306: return msg;
4307: }
4308:
4309: private String findMethodExpressionPrefix(String methodExpr) {
4310: String[] comps = StringUtils.split(methodExpr);
4311: String exprBody = comps.length > 1 ? comps[1] : comps[0];
4312: String[] elems = StringUtils.split(exprBody, '.');
4313: char[] codes = new char[] { '*', '?', '(', ')', '$' };
4314: ArrayList<String> list = new ArrayList<String>();
4315:
4316: for (int i = 0; i < elems.length; i++) {
4317: String elem = elems[i];
4318:
4319: if (elem.length() > 0
4320: && StringUtils.containsNone(elems[i], codes)) {
4321: list.add(elem);
4322: } else {
4323: break;
4324: }
4325: }
4326:
4327: return StringUtils.join(list.toArray(), '.');
4328: }
4329:
4330: private boolean matchesMethod(String methodExpr, IType type) {
4331: String[] comps = StringUtils.split(methodExpr);
4332: String exprBody = comps.length > 1 ? comps[1] : comps[0];
4333: int exprBodyLen = exprBody.length();
4334: String name = PatternHelper.getFullyQualifiedName(type);
4335: int nameLen = name.length();
4336:
4337: for (int z = 0; z < exprBodyLen; z++) {
4338: char ebc = exprBody.charAt(z);
4339:
4340: if (z == nameLen || ebc != name.charAt(z)) {
4341: if (ebc == '.' || ebc == '*' || ebc == '?'
4342: || ebc == '(') {
4343: try {
4344: IMethod[] methods = type.getMethods();
4345:
4346: for (int m = 0; m < methods.length; m++) {
4347: IMethod method = methods[m];
4348:
4349: if (m_patternHelper.matchesMethod(
4350: methodExpr, method)) {
4351: return true;
4352: }
4353: }
4354: } catch (JavaModelException jme) {
4355: return false;
4356: }
4357: }
4358:
4359: return false;
4360: }
4361: }
4362:
4363: // exact match
4364: return true;
4365: }
4366:
4367: private static String BOOT_CLASS_PROBLEM_MARKER = "org.terracotta.dso.BootClassProblemMarker";
4368:
4369: public void validateBootJarClasses() {
4370: clearConfigProblemMarkersOfType(BOOT_CLASS_PROBLEM_MARKER);
4371:
4372: AdditionalBootJarClasses classes = getAdditionalBootJarClasses();
4373:
4374: if (classes != null) {
4375: for (int i = 0; i < classes.sizeOfIncludeArray(); i++) {
4376: String include = getRawString(classes
4377: .xgetIncludeArray(i));
4378: validateBootJarClass(include);
4379: }
4380: }
4381: }
4382:
4383: private void validateBootJarClass(String classExpr) {
4384: String msg = null;
4385: String expr = classExpr;
4386:
4387: if (expr != null) {
4388: expr = expr.trim();
4389: }
4390:
4391: try {
4392: if (expr != null
4393: && JdtUtils.findType(m_javaProject, expr) == null) {
4394: msg = "Cannot resolve type '" + expr + "'";
4395: }
4396: } catch (JavaModelException jme) {
4397: msg = "Cannot resolve type '" + expr + "'";
4398: }
4399:
4400: if (msg != null) {
4401: reportConfigProblem(classExpr, msg,
4402: BOOT_CLASS_PROBLEM_MARKER);
4403: }
4404: }
4405:
4406: private static String MODULE_PROBLEM_MARKER = "org.terracotta.dso.ModuleProblemMarker";
4407: private static String MODULE_REPO_PROBLEM_MARKER = "org.terracotta.dso.ModuleRepoProblemMarker";
4408:
4409: private void validateModules() {
4410: clearConfigProblemMarkersOfType(MODULE_PROBLEM_MARKER);
4411: clearConfigProblemMarkersOfType(MODULE_REPO_PROBLEM_MARKER);
4412:
4413: Modules modules = getModules();
4414: if (modules != null) {
4415: ModulesConfiguration modulesConfig = m_plugin
4416: .getModulesConfiguration(m_project);
4417:
4418: for (String repo : modules.getRepositoryArray()) {
4419: try {
4420: URL url = new URL(repo);
4421: url.openStream().close();
4422: } catch (Exception e) {
4423: reportConfigProblem(repo, e.getMessage(),
4424: MODULE_REPO_PROBLEM_MARKER);
4425: }
4426: }
4427:
4428: for (Module module : modules.getModuleArray()) {
4429: ModuleInfo moduleInfo = modulesConfig
4430: .getModuleInfo(module);
4431: if (moduleInfo != null) {
4432: BundleException error = moduleInfo.getError();
4433: if (error != null) {
4434: String text = module.getName();
4435: reportConfigProblem(text, error.getMessage(),
4436: MODULE_PROBLEM_MARKER);
4437: }
4438: }
4439: }
4440: }
4441: }
4442:
4443: private void reportConfigProblem(String configText, String msg,
4444: String markerType) {
4445: ConfigurationEditor editor = m_plugin
4446: .getConfigurationEditor(m_project);
4447:
4448: if (editor != null) {
4449: editor.applyProblemToText(configText, msg, markerType);
4450: } else {
4451: IFile file = m_plugin.getConfigurationFile(m_project);
4452: InputStream in = null;
4453:
4454: try {
4455: String text = IOUtils.toString(in = file.getContents());
4456: Document doc = new Document(text);
4457:
4458: applyProblemToText(doc, configText, msg, markerType);
4459: } catch (Exception e) {
4460: m_plugin.openError("Problem reporting config problem",
4461: e);
4462: } finally {
4463: IOUtils.closeQuietly(in);
4464: }
4465: }
4466: }
4467:
4468: public void applyProblemToText(IDocument doc, String text,
4469: String msg, String markerType) {
4470: TcPlugin plugin = TcPlugin.getDefault();
4471: FindReplaceDocumentAdapter finder = new FindReplaceDocumentAdapter(
4472: doc);
4473: IRegion region;
4474:
4475: try {
4476: text = "\\Q" + text + "\\E";
4477: if ((region = finder.find(0, text, true, true, false, true)) != null) {
4478: HashMap<String, Object> map = new HashMap<String, Object>();
4479: int start = region.getOffset();
4480: int end = start + region.getLength();
4481: int line = doc.getLineOfOffset(start) - 1;
4482:
4483: MarkerUtilities.setMessage(map, msg);
4484: MarkerUtilities.setLineNumber(map, line);
4485: MarkerUtilities.setCharStart(map, start);
4486: MarkerUtilities.setCharEnd(map, end);
4487:
4488: map.put(IMarker.PRIORITY, Integer
4489: .valueOf(IMarker.PRIORITY_HIGH));
4490: map.put(IMarker.SEVERITY, Integer
4491: .valueOf(IMarker.SEVERITY_WARNING));
4492: map.put(IMarker.LOCATION, "line " + line);
4493:
4494: IFile configFile = plugin
4495: .getConfigurationFile(m_project);
4496: MarkerUtilities.createMarker(configFile, map,
4497: markerType);
4498: }
4499: } catch (Exception e2) {
4500: plugin.openError("Problem creating marker '" + markerType
4501: + "'", e2);
4502: }
4503: }
4504:
4505: public TcConfig getConfig() {
4506: return m_plugin.getConfiguration(m_project);
4507: }
4508:
4509: private DsoApplication ensureDsoApplication() {
4510: DsoApplication dsoApp = null;
4511: TcConfig config = getConfig();
4512:
4513: if (config != null) {
4514: Application app = config.getApplication();
4515:
4516: if (app == null) {
4517: app = config.addNewApplication();
4518: }
4519:
4520: if ((dsoApp = app.getDso()) == null) {
4521: dsoApp = app.addNewDso();
4522: dsoApp.addNewInstrumentedClasses();
4523: }
4524: }
4525:
4526: return dsoApp;
4527: }
4528:
4529: private Client getClient() {
4530: TcConfig config = getConfig();
4531: return config != null ? config.getClients() : null;
4532: }
4533:
4534: private Application getApplication() {
4535: TcConfig config = getConfig();
4536: return config != null ? config.getApplication() : null;
4537: }
4538:
4539: private void testRemoveApplication() {
4540: Application app = getApplication();
4541:
4542: if (app != null) {
4543: if (!app.isSetDso()) {
4544: getConfig().unsetApplication();
4545: }
4546: }
4547: }
4548:
4549: private DsoApplication getDsoApplication() {
4550: Application app = getApplication();
4551: return app != null ? app.getDso() : null;
4552: }
4553:
4554: private void testRemoveDsoApplication() {
4555: DsoApplication dsoApp = getDsoApplication();
4556:
4557: if (dsoApp != null) {
4558: InstrumentedClasses classes = dsoApp
4559: .getInstrumentedClasses();
4560: boolean hasClasses = classes != null
4561: && (classes.sizeOfExcludeArray() > 0 || classes
4562: .sizeOfIncludeArray() > 0);
4563:
4564: if (!dsoApp.isSetAdditionalBootJarClasses()
4565: && !dsoApp.isSetDistributedMethods() && !hasClasses
4566: && !dsoApp.isSetLocks() && !dsoApp.isSetRoots()
4567: && !dsoApp.isSetTransientFields()) {
4568: getApplication().unsetDso();
4569: testRemoveApplication();
4570: }
4571: }
4572: }
4573:
4574: private Roots getRoots() {
4575: DsoApplication dsoApp = getDsoApplication();
4576: return dsoApp != null ? dsoApp.getRoots() : null;
4577: }
4578:
4579: private Roots ensureRoots() {
4580: DsoApplication dsoApp = ensureDsoApplication();
4581: Roots roots = dsoApp.getRoots();
4582:
4583: return roots != null ? roots : dsoApp.addNewRoots();
4584: }
4585:
4586: private void testRemoveRoots() {
4587: DsoApplication dsoApp = getDsoApplication();
4588:
4589: if (dsoApp != null) {
4590: Roots roots = dsoApp.getRoots();
4591:
4592: if (roots.sizeOfRootArray() == 0) {
4593: dsoApp.unsetRoots();
4594: testRemoveDsoApplication();
4595: }
4596: }
4597: }
4598:
4599: private DistributedMethods getDistributedMethods() {
4600: DsoApplication dsoApp = getDsoApplication();
4601: return dsoApp != null ? dsoApp.getDistributedMethods() : null;
4602: }
4603:
4604: private DistributedMethods ensureDistributedMethods() {
4605: DsoApplication dsoApp = ensureDsoApplication();
4606: DistributedMethods methods = dsoApp.getDistributedMethods();
4607:
4608: if (methods == null) {
4609: methods = dsoApp.addNewDistributedMethods();
4610: }
4611:
4612: return methods;
4613: }
4614:
4615: private void testRemoveDistributedMethods() {
4616: DistributedMethods methods = getDistributedMethods();
4617:
4618: if (methods != null) {
4619: if (methods.sizeOfMethodExpressionArray() == 0) {
4620: getDsoApplication().unsetDistributedMethods();
4621: testRemoveDsoApplication();
4622: }
4623: }
4624: }
4625:
4626: private Locks getLocks() {
4627: DsoApplication dsoApp = getDsoApplication();
4628: return dsoApp != null ? dsoApp.getLocks() : null;
4629: }
4630:
4631: private Locks ensureLocks() {
4632: DsoApplication dsoApp = ensureDsoApplication();
4633: Locks locks = dsoApp.getLocks();
4634:
4635: if (locks == null) {
4636: locks = dsoApp.addNewLocks();
4637: }
4638:
4639: return locks;
4640: }
4641:
4642: private void testRemoveLocks() {
4643: Locks locks = getLocks();
4644:
4645: if (locks != null) {
4646: if (locks.sizeOfAutolockArray() == 0
4647: && locks.sizeOfNamedLockArray() == 0) {
4648: getDsoApplication().unsetLocks();
4649: testRemoveDsoApplication();
4650: }
4651: }
4652: }
4653:
4654: private InstrumentedClasses getInstrumentedClasses() {
4655: DsoApplication dsoApp = getDsoApplication();
4656: return dsoApp != null ? dsoApp.getInstrumentedClasses() : null;
4657: }
4658:
4659: private InstrumentedClasses ensureInstrumentedClasses() {
4660: DsoApplication dsoApp = ensureDsoApplication();
4661: InstrumentedClasses classes = dsoApp.getInstrumentedClasses();
4662:
4663: if (classes == null) {
4664: classes = dsoApp.addNewInstrumentedClasses();
4665: }
4666:
4667: return classes;
4668: }
4669:
4670: private void testRemoveInstrumentedClasses() {
4671: InstrumentedClasses ic = getInstrumentedClasses();
4672: if (ic != null) {
4673: if (ic.sizeOfExcludeArray() == 0
4674: && ic.sizeOfIncludeArray() == 0) {
4675: getDsoApplication().unsetInstrumentedClasses();
4676: testRemoveDsoApplication();
4677: }
4678: }
4679: }
4680:
4681: private Modules getModules() {
4682: Client client = getClient();
4683: return client != null ? client.getModules() : null;
4684: }
4685:
4686: private AdditionalBootJarClasses getAdditionalBootJarClasses() {
4687: return ensureDsoApplication().getAdditionalBootJarClasses();
4688: }
4689:
4690: private AdditionalBootJarClasses ensureAdditionalBootJarClasses() {
4691: DsoApplication dsoApp = ensureDsoApplication();
4692: AdditionalBootJarClasses abjc = dsoApp
4693: .getAdditionalBootJarClasses();
4694:
4695: return abjc != null ? abjc : dsoApp
4696: .addNewAdditionalBootJarClasses();
4697: }
4698:
4699: private void testRemoveAdditionalBootJarClasses() {
4700: DsoApplication dsoApp = getDsoApplication();
4701:
4702: if (dsoApp != null) {
4703: AdditionalBootJarClasses abjc = dsoApp
4704: .getAdditionalBootJarClasses();
4705:
4706: if (abjc.sizeOfIncludeArray() == 0) {
4707: dsoApp.unsetAdditionalBootJarClasses();
4708: testRemoveDsoApplication();
4709: }
4710: }
4711: }
4712:
4713: public Servers getServers() {
4714: TcConfig config = getConfig();
4715: return config != null ? config.getServers() : null;
4716: }
4717:
4718: private static IPackageFragment[] getSourceFragments(
4719: IJavaProject javaProject) {
4720: ArrayList<IPackageFragment> list = new ArrayList<IPackageFragment>();
4721:
4722: try {
4723: IPackageFragment[] fragments = javaProject
4724: .getPackageFragments();
4725:
4726: for (int i = 0; i < fragments.length; i++) {
4727: if (isSourceFragment(fragments[i])) {
4728: list.add(fragments[i]);
4729: }
4730: }
4731: } catch (JavaModelException jme) {/**/
4732: }
4733:
4734: return list.toArray(new IPackageFragment[0]);
4735:
4736: }
4737:
4738: private static boolean isSourceFragment(IPackageFragment fragment) {
4739: try {
4740: return fragment.getKind() == IPackageFragmentRoot.K_SOURCE
4741: && hasCompilationUnits(fragment);
4742: } catch (JavaModelException jme) {
4743: return false;
4744: }
4745: }
4746:
4747: private static boolean hasCompilationUnits(IPackageFragment fragment) {
4748: try {
4749: IResource resource = fragment.getResource();
4750: int type = resource.getType();
4751: IContainer container = null;
4752:
4753: switch (type) {
4754: case IResource.PROJECT: {
4755: IProject project = (IProject) resource;
4756: String name = fragment.getElementName();
4757:
4758: if (name
4759: .equals(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH)) {
4760: container = project;
4761: } else {
4762: String path = fragment.getElementName().replace(
4763: '.', '/');
4764: container = project.getFolder(project.getLocation()
4765: .append(path));
4766: }
4767: break;
4768: }
4769: case IResource.FOLDER:
4770: container = (IFolder) resource;
4771: break;
4772: }
4773:
4774: if (container != null) {
4775: IResource[] members = container.members();
4776:
4777: for (int i = 0; i < members.length; i++) {
4778: IResource member = members[i];
4779:
4780: if (member.getType() == IResource.FILE
4781: && member.getFileExtension().equals("java")) {
4782: return true;
4783: }
4784: }
4785: }
4786: } catch (CoreException ce) {/**/
4787: }
4788:
4789: return false;
4790: }
4791:
4792: private void openError(String msg, Throwable t) {
4793: m_plugin.openError(msg, t);
4794: }
4795:
4796: public ConfigurationEditor getConfigurationEditor() {
4797: return m_plugin.getConfigurationEditor(m_project);
4798: }
4799:
4800: private void clearConfigProblemMarkersOfType(String markerType) {
4801: m_plugin.clearConfigProblemMarkersOfType(m_project, markerType);
4802: }
4803: }
|