/plugins/ant/src/com/intellij/lang/ant/dom/AntDomBasenameTask.java

https://bitbucket.org/nbargnesi/idea · Java · 44 lines · 21 code · 4 blank · 19 comment · 4 complexity · 7095adaeb8bca38b29a7e694ad5f4c82 MD5 · raw file

  1. /*
  2. * Copyright 2000-2010 JetBrains s.r.o.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.intellij.lang.ant.dom;
  17. import com.intellij.psi.PsiFileSystemItem;
  18. import com.intellij.util.xml.Attribute;
  19. import com.intellij.util.xml.Convert;
  20. import com.intellij.util.xml.GenericAttributeValue;
  21. /**
  22. * @author Eugene Zhuravlev
  23. * Date: Aug 10, 2010
  24. */
  25. public abstract class AntDomBasenameTask extends AntDomPropertyDefiningTask {
  26. @Attribute("file")
  27. @Convert(value = AntPathConverter.class)
  28. public abstract GenericAttributeValue<PsiFileSystemItem> getFile();
  29. @Attribute("suffix")
  30. public abstract GenericAttributeValue<String> getSuffix();
  31. protected String calcPropertyValue(String propertyName) {
  32. final PsiFileSystemItem item = getFile().getValue();
  33. if (item != null) {
  34. final String name = item.getName();
  35. final String suffix = getSuffix().getStringValue();
  36. return suffix != null && name.endsWith(suffix)? name.substring(0, name.length() - suffix.length()) : name;
  37. }
  38. return super.calcPropertyValue(propertyName);
  39. }
  40. }