private static boolean isSameFile(CsmOffsetableDeclaration decl1, CsmOffsetableDeclaration decl2) { if (decl1 != null && decl2 != null) { CsmFile file1 = decl1.getContainingFile(); CsmFile file2 = decl2.getContainingFile(); if (file1 != null && file2 != null) { return file1.equals(file2); } } return false; }
public static PersistentKey createKey(CsmOffsetableDeclaration decl){ CharSequence name = decl.getName(); CharSequence uniq = decl.getUniqueName(); CsmProject project = decl.getContainingFile().getProject(); if (name.length() > 0 && CharSequences.indexOf(uniq, "::::") < 0 && project != null){ // NOI18N return new PersistentKey(uniq, project, DECLARATION); } else { //System.out.println("Skip "+uniq); } // obtain UID directly without "null-check", because notificator works // in separate thread which can be run after closed project return new PersistentKey(UIDProviderIml.get(decl, false)); }
@Override public CsmScope getScope() { return getTemplateDeclaration().getScope(); }
private Instantiation(T declaration, Map<CsmTemplateParameter, CsmSpecializationParameter> mapping) { super(declaration.getContainingFile(), declaration.getStartOffset(), declaration.getEndOffset()); this.declaration = declaration; this.mapping = mapping; }
Offsets(CsmOffsetableDeclaration declaration){ startOffset = declaration.getStartOffset(); endOffset = declaration.getEndOffset(); object = declaration; } Offsets(CsmMacro macros){
private static CsmProject findProject(CsmOffsetableDeclaration decl){ CsmFile file = decl.getContainingFile(); if (file != null){ //if (file.isValid()) { return file.getProject(); //} //return null; } System.err.println("Cannot fing project for declaration "+decl.getUniqueName()); return null; }
CharSequence name = decl.getName(); CharSequence uniq = decl.getUniqueName(); CsmScope scope = decl.getScope(); if (CsmKindUtilities.isCompoundClassifier(scope) && name.length() > 0) { CsmCompoundClassifier cls = (CsmCompoundClassifier) scope; name = cls.getName(); CsmProject project = decl.getContainingFile().getProject(); if (name.length() > 0 && CharSequences.indexOf(uniq, "::::") < 0 && project != null){ // NOI18N return new PersistentKey(uniq, project, DECLARATION, getStateBit(object));
private CsmNamespaceDefinition findNamespaceDefinition(Iterator<CsmOffsetableDeclaration> it, CsmFilter filter) { while(it.hasNext()) { CsmOffsetableDeclaration decl = it.next(); if (decl.getStartOffset() > this.getStartOffset()) { break; } if (decl.getKind() == CsmDeclaration.Kind.NAMESPACE_DEFINITION) { if (this.getEndOffset() < decl.getEndOffset()) { CsmNamespaceDefinition nsdef = (CsmNamespaceDefinition) decl; CsmNamespaceDefinition inner = findNamespaceDefinition(CsmSelect.getDeclarations(nsdef, filter), filter); return (inner == null) ? nsdef : inner; } } } return null; }
int gotoLine = decl.getStartPosition().getLine(); String gotoFile = decl.getContainingFile().getName().toString(); if (first) { first = false; sb.append(','); sb.append(decl.getQualifiedName()); sb.append(' '); sb.append(gotoFile);
protected final Collection<? extends CsmObject> getEqualObjects(CsmObject csmObject) { if (CsmKindUtilities.isOffsetableDeclaration(csmObject)) { CsmOffsetableDeclaration decl = (CsmOffsetableDeclaration) csmObject; // CharSequence uniqueName = decl.getUniqueName(); CsmFile file = decl.getContainingFile(); if (file != null) { FileObject fo = file.getFileObject(); FSPath fsPath = FSPath.toFSPath(fo); CsmFile[] findFiles = CsmModelAccessor.getModel().findFiles(fsPath, false, false); Collection<CsmObject> out = new HashSet<CsmObject>(findFiles.length); out.add(csmObject); CsmSelect.CsmFilter filter = CsmSelect.getFilterBuilder().createOffsetFilter(decl.getStartOffset()+1); for (CsmFile csmFile : findFiles) { if (!file.equals(csmFile)) { Iterator<CsmOffsetableDeclaration> declarations = CsmSelect.getDeclarations(csmFile, filter); while (declarations.hasNext()) { CsmOffsetableDeclaration other = declarations.next(); if (CsmReferenceSupport.sameDeclaration(other, decl)) { out.add(other); } } } } return out; } } return Collections.singleton(csmObject); } }
private static void addDeclarationAndNested(Collection<FileElement> toAdd, CsmOffsetableDeclaration outDecl) { // TODO: what about function return value? // TODO: what about function params? // TODO: what about const/virtual attributes? // TODO: what about static? CharAndCharSequence cs = new CharAndCharSequence(outDecl.getQualifiedName(), Utils.getCsmDeclarationKindkey(outDecl.getKind())); FileElement fe = new FileElement(outDecl.getStartOffset(), cs); toAdd.add(fe); Iterator<? extends CsmOffsetableDeclaration> it = null; if (CsmKindUtilities.isNamespaceDefinition(outDecl)) { it = ((CsmNamespaceDefinition) outDecl).getDeclarations().iterator(); } else if (CsmKindUtilities.isClass(outDecl)) { CsmClass cl = (CsmClass) outDecl; it = cl.getMembers().iterator(); for (CsmInheritance inh : cl.getBaseClasses()) { CharAndCharSequence csi = new CharAndCharSequence(inh.getAncestorType().getClassifierText(), Utils.getCsmInheritanceKindKey(inh)); toAdd.add(new FileElement(inh.getStartOffset(), csi)); } } else if (CsmKindUtilities.isEnum(outDecl)) { CsmEnum en = (CsmEnum) outDecl; it = en.getEnumerators().iterator(); } if (it != null) { while (it.hasNext()) { CsmOffsetableDeclaration decl = (CsmOffsetableDeclaration) it.next(); addDeclarationAndNested(toAdd, decl); } } }
protected boolean canCreateNode(CsmOffsetableDeclaration d) { if (d.getName().length() > 0) { if( CsmKindUtilities.isClass(d) ) { CsmClass cls = (CsmClass) d; return true; } else if( d.getKind() == CsmDeclaration.Kind.VARIABLE ) { return true; } else if( d.getKind() == CsmDeclaration.Kind.FUNCTION || d.getKind() == CsmDeclaration.Kind.FUNCTION_FRIEND) { return true; } else if( d.getKind() == CsmDeclaration.Kind.FUNCTION_DEFINITION || d.getKind() == CsmDeclaration.Kind.FUNCTION_FRIEND_DEFINITION) { CsmFunctionDefinition definition = (CsmFunctionDefinition) d; CsmFunction func = definition.getDeclaration(); return true; } else if( d.getKind() == CsmDeclaration.Kind.ENUM ) { CsmEnum en = (CsmEnum) d; if( ! CsmKindUtilities.isClassMember(en) || ((CsmMember) en).getContainingClass() == null ) { return true; } else if( d.getKind() == CsmDeclaration.Kind.TYPEDEF ) { return true;
CsmFile file = decl.getContainingFile(); CsmProject project = file.getProject(); children.ensureAddNotify(); scope = decl.getScope(); } else if (CsmKindUtilities.isNamespaceDefinition(decl)){ CsmNamespace ns = ((CsmNamespaceDefinition)decl).getNamespace(); } else { path.add(decl); scope = decl.getScope();
@Override public String toString() { return declaration.getQualifiedName().toString(); }
private boolean findFunction(CharSequence name, Iterator<CsmOffsetableDeclaration> it, int offset, CsmFilter filter) { while(it.hasNext()) { CsmOffsetableDeclaration decl = it.next(); if (decl.getStartOffset() >= offset) { break; switch (decl.getKind()) { case FUNCTION: case FUNCTION_FRIEND:
/** * return all friend declarations for declaration, i.e. * class target { * friend class friendClass; * friend void friendMethod(); * }; * class friendClass{ * } * void friendMethod(){ * } * * @return friend class declaration "friendClass" for class declaration "friendClass" or * friend method declaration "friendMethod" for method definition "friendMethod" */ @Override public Collection<CsmFriend> findFriends(CsmOffsetableDeclaration decl) { if (decl.isValid()) { CsmProject prj = decl.getContainingFile().getProject(); if (prj instanceof ProjectBase) { return ((ProjectBase)prj).findFriendDeclarations(decl); } } return Collections.<CsmFriend>emptyList(); } }
public void putDeclaration(CsmOffsetableDeclaration decl) { CharSequence name = UniqueNameCache.getManager().getString(decl.getUniqueName()); CsmUID<CsmOffsetableDeclaration> uid = RepositoryUtils.put(decl); assert uid != null; if (!(uid instanceof SelfPersistent)) { String line = " ["+decl.getStartPosition().getLine()+":"+decl.getStartPosition().getColumn()+"-"+ // NOI18N decl.getEndPosition().getLine()+":"+decl.getEndPosition().getColumn()+"]"; // NOI18N new Exception("attempt to put local declaration " + decl + line).printStackTrace(System.err); // NOI18N
assert decl != null; this.document = document; this.pos = getPosition(document, decl.getStartOffset()); if (baseTemplates.isEmpty() && templateSpecializations.isEmpty()) {
@Override public CharSequence getUniqueName() { return getTemplateDeclaration().getUniqueName(); }