public PsiElement resolveInner() {
    final String name = getCanonicalRepresentationText();
    if (name == null) return null;

    final AntElement element = getElement();
    final AntConfigurationBase antConfig = AntConfigurationBase.getInstance(element.getProject());
    AntTarget result = null;

    if (element instanceof AntAntImpl) {
      final PsiFile psiFile = ((AntAntImpl) element).getCalledAntFile();
      if (psiFile != null) {
        AntFile antFile = AntSupport.getAntFile(psiFile);
        if (antFile != null) {
          final AntFile context = null /*antConfig.getEffectiveContextFile(antFile)*/;

          assert context != null;

          final AntProject project = context.getAntProject();
          if (project != null) {
            result = resolveTargetImpl(name, project);
          }
        }
      }
    }

    if (result == null) {
      final AntFile context = null /*antConfig.getEffectiveContextFile(element.getAntFile())*/;

      assert context != null;

      result = resolveTargetImpl(name, context.getAntProject());
    }

    return result;
  }
  @NotNull
  public Object[] getVariants() {
    final AntElement element = getElement();
    if (element instanceof AntAntImpl) {
      final PsiFile psiFile = ((AntAntImpl) element).getCalledAntFile();
      if (psiFile != null) {
        AntFile antFile;
        if (psiFile instanceof AntFile) {
          antFile = (AntFile) psiFile;
        } else {
          antFile = AntSupport.getAntFile(psiFile);
        }
        final AntProject project = (antFile == null) ? null : antFile.getAntProject();
        if (project != null) {
          return project.getTargets();
        }
      }
    }

    List<AntTarget> result = new ArrayList<AntTarget>();

    final AntProject project = element.getAntProject();
    final AntTarget[] targets = project.getTargets();
    for (final AntTarget target : targets) {
      if (target != element) {
        result.add(target);
      }
    }

    ContainerUtil.addAll(result, project.getImportedTargets());

    return result.toArray();
  }
  @NotNull
  public IntentionAction[] getFixes() {
    final String name = getCanonicalRepresentationText();
    if (name == null || name.length() == 0) return IntentionAction.EMPTY_ARRAY;

    final AntProject project = getElement().getAntProject();
    final AntFile[] importedFiles = project.getImportedFiles();
    final List<IntentionAction> result = new ArrayList<IntentionAction>(importedFiles.length + 1);
    result.add(new AntCreateTargetFix(this));
    for (final AntFile file : importedFiles) {
      if (file.isPhysical()) {
        result.add(new AntCreateTargetFix(this, file));
      }
    }
    result.add(new AntChangeContextFix());
    return result.toArray(new IntentionAction[result.size()]);
  }
 public void clearClassesCache() {
   synchronized (PsiLock.LOCK) {
     if (myMacroDefinition != null) {
       final AntFile file = getAntFile();
       for (AntTypeId id : myMacroDefinition.getNestedElements()) {
         final AntTypeDefinition nestedDef =
             file.getBaseTypeDefinition(myMacroDefinition.getNestedClassName(id));
         if (nestedDef != null) {
           file.unregisterCustomType(nestedDef);
         }
       }
       final AntStructuredElement parent = getAntProject();
       if (parent != null) {
         parent.unregisterCustomType(myMacroDefinition);
       }
       myMacroDefinition = null;
     }
   }
 }
  @SuppressWarnings({"HardCodedStringLiteral"})
  private void invalidateMacroDefinition() {
    if (!hasNameElement()) {
      myMacroDefinition = null;
      return;
    }

    final AntFile file = getAntFile();
    if (file == null) return;

    final String thisClassName = createMacroClassName(getName());
    myMacroDefinition = (AntTypeDefinitionImpl) file.getBaseTypeDefinition(thisClassName);
    final Map<String, AntAttributeType> attributes =
        (myMacroDefinition == null)
            ? new HashMap<String, AntAttributeType>()
            : myMacroDefinition.getAttributesMap();
    attributes.clear();
    final Map<AntTypeId, String> nestedElements =
        (myMacroDefinition == null)
            ? new HashMap<AntTypeId, String>()
            : myMacroDefinition.getNestedElementsMap();
    for (AntElement child : getChildren()) {
      if (child instanceof AntStructuredElement) {
        final AntStructuredElement se = (AntStructuredElement) child;
        final String name = se.getName();
        if (name != null) {
          final String tagName = se.getSourceElement().getName();
          if (tagName.equals("attribute")) {
            attributes.put(name.toLowerCase(Locale.US), AntAttributeType.STRING);
          } else if (tagName.equals("element")) {
            final String elementClassName = thisClassName + '$' + name;
            AntTypeDefinitionImpl nestedDef =
                (AntTypeDefinitionImpl) file.getBaseTypeDefinition(elementClassName);
            if (nestedDef == null) {
              final AntTypeDefinitionImpl targetDef =
                  (AntTypeDefinitionImpl) file.getTargetDefinition();
              if (targetDef != null) {
                nestedDef = new AntTypeDefinitionImpl(targetDef);
              }
            }
            if (nestedDef != null) {
              final AntTypeId typeId = new AntTypeId(name);
              nestedDef.setTypeId(typeId);
              nestedDef.setClassName(elementClassName);
              nestedDef.setIsTask(false);
              nestedDef.setDefiningElement(child);
              file.registerCustomType(nestedDef);
              nestedElements.put(typeId, nestedDef.getClassName());
            }
          }
        }
      }
    }
    final AntTypeId definedTypeId = new AntTypeId(getName());
    if (myMacroDefinition == null) {
      myMacroDefinition =
          new AntTypeDefinitionImpl(
              definedTypeId, thisClassName, true, false, attributes, nestedElements, this);
    } else {
      myMacroDefinition.setTypeId(definedTypeId);
      myMacroDefinition.setClassName(thisClassName);
      myMacroDefinition.setIsTask(true);
      myMacroDefinition.setDefiningElement(this);
    }
    final AntStructuredElement parent = getAntProject();
    if (parent != null) {
      parent.registerCustomType(myMacroDefinition);
    }
    // define itself as nested task for sequential
    final AntAllTasksContainerImpl sequential =
        PsiTreeUtil.getChildOfType(this, AntAllTasksContainerImpl.class);
    if (sequential != null) {
      sequential.registerCustomType(myMacroDefinition);
      for (final AntTypeId id : myMacroDefinition.getNestedElements()) {
        sequential.registerCustomType(
            file.getBaseTypeDefinition(myMacroDefinition.getNestedClassName(id)));
      }
    }
  }