browserutil.cpp

来自「用bcg库编写的java IDE 源码」· C++ 代码 · 共 2,177 行 · 第 1/4 页

CPP
2,177
字号
    m_pDeclMgr->RemoveType(m_nTypePos);
}



CString CTypeDecl::FindTypeOf(CStringList& lstrNames,POSITION nPos)
{

  return _T("");
}

void CTypeDecl::PackSimilarMethods(CString strName,int,
								   CList<CMethodDecl*,CMethodDecl*>&lMethods)
{
  strName;lMethods;
}


CMethodDecl* CTypeDecl::FindMethodImpl(CList<CMethodDecl*,CMethodDecl*>&lMethods,
								   CStringList& lstrArgs)
{
  CList<CMethodDecl*,CMethodDecl*> lPossibleMethods;
  //at the end of this loop only one method should remain in the method list
  //otherwise there's an error.

  for(POSITION pos = lMethods.GetHeadPosition(); pos!=NULL;)
  {
	 POSITION nCurPos = pos;
     CMethodDecl* pMethod = lMethods.GetNext(pos);
     POSITION apos = pMethod->m_lstrInfo.GetHeadPosition();
	 bool bmacth = false;
	 bool bpossiblemacth = true;

     for(POSITION spos = lstrArgs.GetHeadPosition(); spos !=NULL;)
	 {
        CString strDerivedArg = lstrArgs.GetNext(spos);
        CString strActualArg  = pMethod->m_lstrInfo.GetNext(apos);

	    if(strDerivedArg.Compare(strActualArg) == 0)
		{
           bmacth = true;
		}
	    else
		{
          bmacth = false;
	      if((!basictype(strDerivedArg))&&(!basictype(strActualArg)))
		  {
             //if they are both not basic types and strSArg is not 
		     //a subclass of strMArg
             

		     lMethods.RemoveAt(nCurPos);
		  }
		  else
		  if(basictype(strDerivedArg)&&basictype(strActualArg))
		  {
            
		  }
		  else//this method is not a possible match
		  {
			bpossiblemacth = false;
		    lMethods.RemoveAt(nCurPos);
		  }
		}
	 }

	 if(bmacth)
	 {
       //return this method
		 return pMethod;
	 }
	 else
	 if(bpossiblemacth)
	 {

	 }
  }return NULL;
}

bool CTypeDecl::FindMethod(CStringList& lstrMethodInfo,CString& strReturn)
{
  CString strName;
  CList<CMethodDecl*,CMethodDecl*> lMethods;
  this->PackSimilarMethods(strName,lstrMethodInfo.GetCount(),lMethods);
  CMethodDecl* pMethod = FindMethodImpl(lMethods,lstrMethodInfo);
  if(pMethod !=NULL)
  {
     strReturn = pMethod->getReturnType();
	 return true;
  }
  return false;
}

void CTypeDecl::AddSubType(CTypeDecl* pType)
{
  m_lKnownSubTypes.AddTail(pType);
}

void CTypeDecl::RemoveSubType(CTypeDecl* pType)
{
  POSITION pos = m_lKnownSubTypes.Find(pType);
  m_lKnownSubTypes.RemoveAt(pos);
}
//*********************************CBlockDecl***********************************//
CBlockDecl::CBlockDecl()
{
  m_bExpanded = true;
  m_bBalance = false;
  m_pEndBrace = NULL;
}

CBlockDecl::CBlockDecl(int nStartIndex,int nStartLine,int nEndIndex,int nEndLine)
:__CBaseDecl(nStartIndex,nStartLine,nEndIndex,nEndLine)
{
  m_nDeclKind = BLOCK_DECL;m_bExpanded = true;
  m_bBalance = false;
  m_pEndBrace = NULL;
}


CBlockDecl::~CBlockDecl()
{
    for(POSITION pos = m_lMembers.GetHeadPosition(); pos !=NULL;)
	{
	 __CBaseDecl* pDecl = m_lMembers.GetNext(pos);
	 m_pDeclMgr->RemoveDecl(pDecl->getMainPos());
	 delete pDecl;
	}


    m_pDeclMgr->removeBlock(m_nStoragePos);
	if(m_pEndBrace)
	{
      m_pDeclMgr->RemoveDecl(m_pEndBrace->getMainPos());
	  m_pEndBrace->setParent(NULL);
      delete m_pEndBrace;
	}
}

POSITION CBlockDecl::skipBlock()
{
  if(m_pEndBrace)
  {
    POSITION pos = m_pEndBrace->getMainPos();
    m_pDeclMgr->getDeclList()->GetNext(pos);
    return pos;
  }
  else
  {
    if(!m_lMembers.IsEmpty())
      return m_lMembers.GetTail()->skipBlock();

    POSITION pos = m_nMainPos;
    m_pDeclMgr->getDeclList()->GetNext(pos);
    return pos;
  }
}

bool CBlockDecl::balance(){return (m_pEndBrace != NULL);}



void CBlockDecl::SetEndBrace(__CBaseDecl* pEndBrace)
{
  m_pEndBrace = pEndBrace;
}

__CBaseDecl* CBlockDecl::GetEndBrace()
{
  return m_pEndBrace;
}

void  CBlockDecl::RemoveMembers()
{
  m_lMembers.RemoveAll();
}

POSITION  CBlockDecl::AddMember(__CBaseDecl* pDecl)
{
  if((pDecl->getKind() == FIELD_DECL))
  {
    CFieldDecl* pField = (CFieldDecl*)pDecl;
	addField(pField);
  }
  else
  if((pDecl->getKind() == METHOD_DECL))
  {
     CMethodDecl* pMethod = (CMethodDecl*)pDecl;
	 addMethod(pMethod);
  }
  else
  if((pDecl->getKind() == INTERFACE_DECL)||(pDecl->getKind() == CLASS_DECL))
  {
    addType((CTypeDecl*)pDecl);
  }

  __DeclBound nNewBound = *(pDecl->GetBound());

  for(POSITION pos=m_lMembers.GetHeadPosition(); pos!=NULL;)
  {
	  POSITION cp = pos;
     __DeclBound nDeclBound = *(m_lMembers.GetNext(pos)->GetBound());
     if(nDeclBound>nNewBound)
        return m_lMembers.InsertBefore(cp,pDecl);
  }return m_lMembers.AddTail(pDecl);
}

void  CBlockDecl::removeType(POSITION pos)
{
	m_lMemberTypes.RemoveAt(pos);
}

DECL_LIST* CBlockDecl::GetMemberList(){return &m_lMembers;}


void  CBlockDecl::RemoveMember(POSITION pos)
{
  int nKind = m_lMembers.GetAt(pos)->getKind();
  if((nKind == FIELD_DECL))
  {
    CFieldDecl* pField = (CFieldDecl*)m_lMembers.GetAt(pos);
	removeField(pField->getFieldPos());
  }
  else
  if((nKind == METHOD_DECL))
  {
     CMethodDecl* pMethod = (CMethodDecl*)m_lMembers.GetAt(pos);
	 removeMethod(pMethod->getMethodPos());
  }
  else
  if((nKind == INTERFACE_DECL)||(nKind == CLASS_DECL))
  {
    CTypeDecl* pType = (CTypeDecl*)m_lMembers.GetAt(pos);
	removeType(pType->getTypePos());
  }m_lMembers.RemoveAt(pos);
}

int CBlockDecl::getMemberCount()
{
  int count = m_lMembers.GetCount();
  for(POSITION pos=m_lMembers.GetHeadPosition(); pos!=NULL;)
	count += m_lMembers.GetNext(pos)->getMemberCount();
  return count;
}

DECL_LIST* CBlockDecl::getMembers(){return &m_lMembers;}


void CBlockDecl::addType(CTypeDecl* pType)
{ 
  pType->setTypePos(m_lMemberTypes.AddTail(pType)); 
}


bool CBlockDecl::PointInDeclBlock(__DeclPoint& declPt)
{
  if(m_pEndBrace == NULL)//unbalanced braces
  {
      if(declPt.m_nLine>m_pBound->m_nEndLine)
		  return true;
	  else
	  if((declPt.m_nLine == m_pBound->m_nEndLine)&&(declPt.m_nIndex>m_pBound->m_nEndIndex))
		  return true;
  }
  else
  {   //on endline
      if(declPt.m_nLine == m_pBound->m_nEndLine)		
	  {
	    //if the block is one line
        if((m_pBound->m_nEndLine == m_pEndBrace->GetBound()->m_nEndLine)&&(m_pEndBrace->GetBound()->m_nEndLine == declPt.m_nLine))
        return ((declPt.m_nIndex>m_pBound->m_nEndIndex)&&(declPt.m_nIndex<=m_pEndBrace->GetBound()->m_nEndIndex));
        //else
		return(declPt.m_nIndex>m_pBound->m_nEndIndex);
	  }
	  else//block line
	  if(declPt.m_nLine == m_pEndBrace->GetBound()->m_nEndLine)
        return (declPt.m_nIndex<=m_pEndBrace->GetBound()->m_nEndIndex);
	  else//between
      return((declPt.m_nLine>m_pBound->m_nEndLine)&&(declPt.m_nLine<m_pEndBrace->GetBound()->m_nEndLine));
  }return false;	
  //return __CBaseDecl::PointInDeclBlock(declPt);
}



void CBlockDecl::RemoveMemsFrom(__CBaseDecl* pFrom)
{
   for(POSITION pos = pFrom->getPos();pos != NULL;)
   {
      POSITION curpos = pos;
      m_lMembers.GetNext(pos);
      m_lMembers.RemoveAt(curpos);
   }
}

__CBaseDecl* CBlockDecl::GetMemberAfter(__CBaseDecl* pDecl)
{
  POSITION pos = pDecl->getPos();m_lMembers.GetNext(pos);
  if(pos)
	  return m_lMembers.GetAt(pos);
  else
	  return NULL;
}

CTypeDecl* CBlockDecl::FindType(CStringList& lstrTypes,POSITION nStrPos)
{
  POSITION nPos = nStrPos;
  CString strName = lstrTypes.GetNext(nPos);
  for(POSITION pos = m_lMemberTypes.GetHeadPosition(); pos != NULL;)
  {
     CTypeDecl* pType = m_lMemberTypes.GetNext(pos);
	 if(pType->getDeclName().Compare(strName) == 0)
	 {
        if(nPos)
		{
           CTypeDecl* pFoundType = pType->FindType(lstrTypes,nPos);
		   if(pFoundType)return pFoundType;
		}else return pType;
	 }
  }
  if(getParent())return getParent()->FindType(lstrTypes,lstrTypes.GetHeadPosition());  
  return NULL;
}

CTypeDecl* CBlockDecl::FindFieldType(CStringList& lstrNames,POSITION nStrPos)
{
  POSITION nPos = nStrPos;
  CString strName = lstrNames.GetNext(nPos);

  for(POSITION pos = m_lFields.GetHeadPosition(); pos != NULL;)
  {
     CFieldDecl* pField = m_lFields.GetNext(pos);
	 int count = pField->getcount();
	 for(int i = 0; i<count; i++)
	 {
        if(pField->getVar(i).Compare(strName) == 0)
		{
		    CString strType = pField->getType();
            CStringList lstrType;lstrType.AddHead(strType);
            if(nPos)
			{
               CTypeDecl* pFoundType = pField->m_pDeclMgr->FindType(lstrType);
		       if(pFoundType)return pFoundType->FindFieldType(lstrNames,nPos);
			}else return pField->m_pDeclMgr->FindType(lstrType);
		}
	 }
  }
  if(getParent())return getParent()->FindFieldType(
	  lstrNames,lstrNames.GetHeadPosition());
  return NULL;
}

CFieldDecl* CBlockDecl::FindField(CStringList* lstrNames,POSITION nStrPos)
{
  POSITION nPos = nStrPos;
  CString strName = lstrNames->GetNext(nPos);

  for(POSITION pos = m_lFields.GetHeadPosition(); pos != NULL;)
  {
     CFieldDecl* pField = m_lFields.GetNext(pos);
	 int count = pField->getcount();
	 for(int i = 0; i<count; i++)
	 {
        if(pField->getVar(i).Compare(strName) == 0)
		{
		    CString strType = pField->getType();
            CStringList lstrType;lstrType.AddHead(strType);
            if(nPos)
			{
               CTypeDecl* pFoundType = pField->m_pDeclMgr->FindType(lstrType);
		       if(pFoundType)return pFoundType->FindField(lstrNames,nPos);
			}else return pField;
		}
	 }
  }
  if(m_pParent)
	return m_pParent->FindField(lstrNames,lstrNames->GetHeadPosition());  
  return NULL;
}



void CBlockDecl::addField(CFieldDecl* pField)
{
  pField->setFieldPos(m_lFields.AddTail(pField));
}

void CBlockDecl::addMethod(CMethodDecl* pMethod)
{
  pMethod->setMethodPos(m_lMethods.AddTail(pMethod));
}

void CBlockDecl::removeField(POSITION pos)
{
  m_lFields.RemoveAt(pos);
}

void CBlockDecl::removeMethod(POSITION pos)
{
  m_lMethods.RemoveAt(pos);
}


BOOL CBlockDecl::FindReturnType(CString& strMethod,CStringList& lstrArgs)
{
   for(POSITION pos = m_lMethods.GetHeadPosition(); pos != NULL;)
   {
       CMethodDecl* pMethod = m_lMethods.GetNext(pos);
	   if(pMethod->getDeclName().Compare(strMethod) == 0)
	   {
	      if(!(lstrArgs.IsEmpty()))
		  {
             if(pMethod->Match(lstrArgs))
		     {
               strMethod = pMethod->getReturnType();
			   return TRUE;
		     }
		  }else
		  {
              strMethod = pMethod->getReturnType();
			  return TRUE;
		  }
	   }
   }return FALSE;
}

//*************************CDeclManager**************************************//
IMPLEMENT_DYNCREATE(CDeclManager, CWinThread)

BEGIN_MESSAGE_MAP(CDeclManager,CWinThread)
	//{{AFX_MSG_MAP(CJavaDeclManager)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
		ON_REGISTERED_THREAD_MESSAGE(m_msgMainThreadID,OnMainThreadId)
END_MESSAGE_MAP()

CDeclManager::CDeclManager()
{
  m_pParser              = NULL;  
  m_bInitParse           = true;
  m_bValidDoc            = true;
}

CDeclManager::~CDeclManager()
{
}




void CDeclManager::OnMainThreadId(UINT nMainAppThreadID)
{
   m_nMainAppThreadID = nMainAppThreadID;
}

__CBaseDecl* CDeclManager::FindDecl(__DeclBound nBound)
{
	/*
   long nCount = m_lDecls.GetSize();
   long nLast  = nCount-1;
   long nFirst = 0;
   while(nFirst<nLast)
   {
     long nLoc = (nFirst+nLast)/2;
     __DeclBound nCurBound = *(m_lDecls[nLoc]->GetBound());
     if(nBound<nCurBound)
	     nLast  = nLoc-1;
	 else
	 if(nBound>nCurBound)
		 nFirst = nLoc+1;
	 else
	 return m_lDecls[nLoc];
   }*/return NULL;
}

CBlockDecl* CDeclManager::getParentBlock(__DeclPoint& declPt)
{
   for(POSITION pos = m_lBlockDecls.GetTailPosition(); pos !=NULL;)
   {
	 CBlockDecl *pDecl = m_lBlockDecls.GetPrev(pos);
     if(pDecl->PointInDeclBlock(declPt))
		 return pDecl;
   }return NULL;
}

__CBaseDecl* CDeclManager::FindBlock(__DeclPoint& nDeclPt)
{
	/*
   long nCount = m_lBlockDecls.GetSize();
   long nLast  = nCount-1;
   long nFirst = 0;
   if(nCount == 0)return NULL;

   
   while(nFirst<=nLast)
   {
     long nLoc = (nFirst+nLast)/2;

	 __CBaseDecl* pDecl = m_lBlockDecls[nLoc];

	 __DeclBound nBottomHalfBound = *(pDecl->GetBound());
    
	 nBottomHalfBound.setScopeEnd(m_lBlockDecls[nLast]->GetBound()->m_nScopeEndIndex,m_lBlockDecls[nLast]->GetBound()->m_nScopeEndLine);

     if(nBottomHalfBound.PointInDeclScope(nDeclPt))
	 {
        if(((nLast-nFirst) == 1)||nCount == 1)
		{
          if(m_lBlockDecls[nLast]->GetBound()->PointInDeclScope(nDeclPt))//bottom block takes higher precedence
			  return m_lBlockDecls[nLast];
		  else
			  return m_lBlockDecls[nFirst];
		}
		nFirst = nLoc;
	 }
	 else//definitely delaing with more than one block
	 {
		--nLoc;//move to block ontop,can't be the current one,because of the downward orientation
		if(nLoc < 0)return NULL;//safegaurd
	    __CBaseDecl* pDeclFirst = m_lBlockDecls[nFirst];

        __DeclBound nTopHalfBound = *(pDeclFirst->GetBound());

        
	    nTopHalfBound.setScopeEnd(m_lBlockDecls[nLoc]->GetBound()->m_nScopeEndIndex,m_lBlockDecls[nLoc]->GetBound()->m_nScopeEndLine);

		if(nTopHalfBound.PointInDeclScope(nDeclPt))
		{
           if(((nLoc-nFirst) == 1)||nLoc == 0)
		   {
              if(m_lBlockDecls[nLoc]->GetBound()->PointInDeclScope(nDeclPt))//bottom block takes higher precedence
			    return m_lBlockDecls[nLoc];
		      else
			    return m_lBlockDecls[nFirst];
		   }
		  nLast  = nLoc;
		}
		else return NULL;
	 }	 
   }*/return NULL;
}



void CDeclManager::UpdateDeclsOnInsert(__DeclBound editContext)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?